Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions src/main/updater.list-sources.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { loadUpdaterModule, warmUpdaterModule } from './updater-test-module-loader'
import { createUpdaterMainWindowFake } from './updater-main-window.fixture'
import {
FORK_RELEASE_SOURCES_LITERAL,
setReleaseSourcesLiteralForTest
} from '../shared/release-sources.fixture'
import type { ReleaseBuild } from '../shared/release-channel'
import type * as ReleaseBuildsModule from './updater-release-builds'

const { appMock, moduleFactories, resetUpdaterMocks } = await vi.hoisted(async () =>
(await import('./updater-test-harness')).createUpdaterMocks()
)
const { listReleaseBuildsMock } = vi.hoisted(() => ({ listReleaseBuildsMock: vi.fn() }))

vi.mock('electron', () => moduleFactories.electron())
vi.mock('electron-updater', () => moduleFactories.electronUpdater())
vi.mock('./electron-updater-loader', () => moduleFactories.electronUpdaterLoader())
vi.mock('@electron-toolkit/utils', () => moduleFactories.electronToolkitUtils())
vi.mock('./ipc/pty', () => moduleFactories.ipcPty())
vi.mock('./linux-update-package-type', () => moduleFactories.linuxUpdatePackageType())
vi.mock('./updater-lifecycle-diagnostics', () => moduleFactories.updaterLifecycleDiagnostics())
vi.mock('./updater-changelog', () => moduleFactories.updaterChangelog())
vi.mock('./updater-nudge', () => moduleFactories.updaterNudge())
vi.mock('./update-install-exit-watchdog', () => moduleFactories.updateInstallExitWatchdog())
vi.mock('./updater-prerelease-feed', () => moduleFactories.updaterPrereleaseFeed())
vi.mock('./local-builds/local-build-switch', () => moduleFactories.localBuildSwitch())
vi.mock('./local-builds/local-build-feed-server', () => moduleFactories.localBuildFeedServer())
// Why only the lister: the GitHub REST client has its own suite; this one is about what main
// tells the Updates section per source.
vi.mock('./updater-release-builds', async (importOriginal) => ({
...(await importOriginal<typeof ReleaseBuildsModule>()),
listReleaseBuilds: (...args: unknown[]) => listReleaseBuildsMock(...args)
}))

warmUpdaterModule()

const FORK_VERSION = '1.4.197-swaplabs.202609251710'

function build(version: string, tag: string, repo: string): ReleaseBuild {
return {
tag,
version,
channel: 'stable',
name: null,
publishedAt: null,
releaseUrl: `https://github.com/${repo}/releases/tag/${tag}`,
installerUrl: `https://github.com/${repo}/releases/download/${tag}/orca-linux.AppImage`
}
}

const UPSTREAM_BUILDS = [build('1.4.198', 'v1.4.198', 'stablyai/orca')]
const FORK_BUILDS = [build(FORK_VERSION, 'swaplabs-v1.4.197+202609251710', 'SwapLabsInc/orca')]

function listBuildsBySource(): void {
listReleaseBuildsMock.mockImplementation(
async (_channel: unknown, _platform: unknown, source: { id: string }) =>
source.id === 'swaplabs' ? FORK_BUILDS : UPSTREAM_BUILDS
)
}

describe('updater listReleaseSources', () => {
beforeEach(() => {
resetUpdaterMocks()
listReleaseBuildsMock.mockReset()
moduleFactories.linuxUpdatePackageType().isExternallyManagedLinuxInstall.mockReturnValue(false)
setReleaseSourcesLiteralForTest(FORK_RELEASE_SOURCES_LITERAL)
appMock.getVersion.mockReturnValue(FORK_VERSION)
})

afterEach(() => {
vi.restoreAllMocks()
setReleaseSourcesLiteralForTest(null)
})

function usePlatform(platform: NodeJS.Platform): void {
vi.spyOn(process, 'platform', 'get').mockReturnValue(platform)
}

it('lists every source with its newest stable build and marks the running one', async () => {
usePlatform('linux')
listBuildsBySource()
const { setupAutoUpdater, listReleaseSources } = await loadUpdaterModule()
setupAutoUpdater(createUpdaterMainWindowFake().mainWindow)

await expect(listReleaseSources()).resolves.toEqual([
{
id: 'upstream',
label: 'Orca upstream',
running: false,
install: 'in-app',
latest: UPSTREAM_BUILDS[0],
error: null
},
{
id: 'swaplabs',
label: 'SwapLabs',
running: true,
install: 'in-app',
latest: FORK_BUILDS[0],
error: null
}
])
expect(listReleaseBuildsMock).toHaveBeenCalledTimes(2)
expect(listReleaseBuildsMock).toHaveBeenCalledWith(
'stable',
'linux',
expect.objectContaining({ id: 'upstream' }),
process.arch
)
})

// Why: the button that names the action must not promise an in-app install that
// `checkForPinnedBuild` would refuse with a signature error a moment later.
it('reports a manual installer for a cross-source jump on macOS', async () => {
usePlatform('darwin')
listBuildsBySource()
const { setupAutoUpdater, listReleaseSources } = await loadUpdaterModule()
setupAutoUpdater(createUpdaterMainWindowFake().mainWindow)

const rows = await listReleaseSources()
expect(rows.map((row) => [row.id, row.install])).toEqual([
['upstream', 'manual-installer'],
['swaplabs', 'in-app']
])
})

it('reports every source as externally managed for a package-manager install', async () => {
usePlatform('linux')
listBuildsBySource()
moduleFactories.linuxUpdatePackageType().isExternallyManagedLinuxInstall.mockReturnValue(true)
const { setupAutoUpdater, listReleaseSources } = await loadUpdaterModule()
setupAutoUpdater(createUpdaterMainWindowFake().mainWindow)

const rows = await listReleaseSources()
expect(rows.map((row) => row.install)).toEqual(['externally-managed', 'externally-managed'])
})

// Why: one unreachable repository must not hide the other; the failure travels as data.
it('returns a list failure per source without rejecting the whole read', async () => {
usePlatform('linux')
listReleaseBuildsMock.mockImplementation(
async (_channel: unknown, _platform: unknown, source: { id: string }) => {
if (source.id === 'upstream') {
throw new Error('GitHub rate limit reached. Try again in about a minute.')
}
return FORK_BUILDS
}
)
const { setupAutoUpdater, listReleaseSources } = await loadUpdaterModule()
setupAutoUpdater(createUpdaterMainWindowFake().mainWindow)

const rows = await listReleaseSources()
expect(rows[0]).toMatchObject({
id: 'upstream',
latest: null,
error: 'GitHub rate limit reached. Try again in about a minute.'
})
expect(rows[1]).toMatchObject({ id: 'swaplabs', latest: FORK_BUILDS[0], error: null })
})

it('serves repeats from the shared build cache unless forced', async () => {
usePlatform('linux')
listBuildsBySource()
const { setupAutoUpdater, listReleaseSources, listAvailableReleaseBuilds } =
await loadUpdaterModule()
setupAutoUpdater(createUpdaterMainWindowFake().mainWindow)

await listReleaseSources()
await listReleaseSources()
// The dev picker's own list of the same source and channel is the same cache entry.
await listAvailableReleaseBuilds('stable', { source: 'swaplabs' })
expect(listReleaseBuildsMock).toHaveBeenCalledTimes(2)

await listReleaseSources({ force: true })
expect(listReleaseBuildsMock).toHaveBeenCalledTimes(4)
})
})
7 changes: 7 additions & 0 deletions src/main/updater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { BrowserWindow } from 'electron'
import type {
LinuxPackageInstallInstructions,
ReleaseSourceStatus,
UpdateCheckOptions,
UpdateStatus
} from '../shared/update-status-types'
Expand Down Expand Up @@ -85,6 +86,12 @@ export async function listAvailableReleaseBuilds(
return updater.listAvailableReleaseBuilds(channel, options)
}

export async function listReleaseSources(
options?: Pick<ReleaseBuildListOptions, 'force'>
): Promise<ReleaseSourceStatus[]> {
return updater.listReleaseSources(options)
}

export function dismissNudge(): void {
updater.dismissNudge()
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/updater/updater-build-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
PRIMARY_RELEASE_SOURCE,
type ReleaseSource
} from '../../shared/release-sources'
import type { ReleaseSourceStatus } from '../../shared/update-status-types'
import { compareVersions } from '../updater-fallback'
import { recordUpdaterLifecycle } from '../updater-lifecycle-diagnostics'
import {
Expand All @@ -27,6 +28,7 @@ import { listReleaseBuilds, resolveTargetBuild } from '../updater-release-builds
import { ReleaseBuildListCache, type ReleaseBuildListOptions } from '../updater-release-build-cache'
import { getReleaseTagPageUrl } from '../updater-release-urls'
import { UpdaterMenuChecks, type PinnedBuildTarget } from './updater-menu-checks'
import { listReleaseSourceStatuses } from './updater-release-sources'

/** Why a message per verdict: the dev picked this tag by hand, so the refusal must say what the release actually holds. */
function describeRefusedPinnedManifest(
Expand Down Expand Up @@ -118,6 +120,16 @@ export abstract class UpdaterBuildSelection extends UpdaterMenuChecks {
return this.releaseBuildCache.list(channel, options)
}

/** Every configured source with its newest stable build, read through the shared list cache. */
protected async listReleaseSources(
options?: Pick<ReleaseBuildListOptions, 'force'>
): Promise<ReleaseSourceStatus[]> {
return listReleaseSourceStatuses(
(source, force) => this.releaseBuildCache.list('stable', { force, source: source.id }),
options?.force === true
)
}

/**
* Why the pinned build refuses before pinning: electron-updater would otherwise take the jump all
* the way to a download and fail it with a raw signature error. Each refusal names where to get
Expand Down
69 changes: 69 additions & 0 deletions src/main/updater/updater-release-sources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { app } from 'electron'
import {
getVersionChannel,
requiresManualInstall,
type ReleaseBuild
} from '../../shared/release-channel'
import {
RELEASE_SOURCES,
getVersionReleaseSource,
type ReleaseSource,
type ReleaseSourceId
} from '../../shared/release-sources'
import type {
ReleaseSourceInstallMode,
ReleaseSourceStatus
} from '../../shared/update-status-types'
import { isExternallyManagedLinuxInstall } from '../linux-update-package-type'

/**
* Why main decides the install mode: it is the verdict `downloadUpdate` and the pinned check
* refuse by, so the button that names the action cannot promise one this host cannot make.
*/
export function resolveReleaseSourceInstallMode(
source: ReleaseSource,
runningSource: ReleaseSourceId | null
): ReleaseSourceInstallMode {
if (process.platform === 'linux' && isExternallyManagedLinuxInstall()) {
return 'externally-managed'
}
return requiresManualInstall({
platform: process.platform,
running: { source: runningSource, channel: getVersionChannel(app.getVersion()) },
target: { source: source.id, channel: 'stable' }
})
? 'manual-installer'
: 'in-app'
}

/**
* Every configured source with its newest build for this platform. List failures are
* returned per source as data, so one unreachable repository never hides the others.
* Only the stable series is listed: dev channels belong to the primary source's picker.
*/
export async function listReleaseSourceStatuses(
listStableBuilds: (source: ReleaseSource, force: boolean) => Promise<ReleaseBuild[]>,
force: boolean
): Promise<ReleaseSourceStatus[]> {
const runningSource = getVersionReleaseSource(app.getVersion())
return Promise.all(
RELEASE_SOURCES.map(async (source): Promise<ReleaseSourceStatus> => {
const status = {
id: source.id,
label: source.label,
running: source.id === runningSource,
install: resolveReleaseSourceInstallMode(source, runningSource)
}
try {
const builds = await listStableBuilds(source, force)
return { ...status, latest: builds[0] ?? null, error: null }
} catch (error) {
return {
...status,
latest: null,
error: error instanceof Error ? error.message : String(error)
}
}
})
)
}
7 changes: 7 additions & 0 deletions src/main/updater/updater-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ReleaseBuild, ReleaseChannel } from '../../shared/release-channel'
import type { ReleaseBuildListOptions } from '../updater-release-build-cache'
import type {
LinuxPackageInstallInstructions,
ReleaseSourceStatus,
UpdateCheckOptions,
UpdateStatus
} from '../../shared/update-status-types'
Expand Down Expand Up @@ -104,6 +105,12 @@ export class UpdaterSetup extends UpdaterDownloadInstall {
return super.listAvailableReleaseBuilds(channel, options)
}

async listReleaseSources(
options?: Pick<ReleaseBuildListOptions, 'force'>
): Promise<ReleaseSourceStatus[]> {
return super.listReleaseSources(options)
}

dismissNudge(): void {
super.dismissNudge()
}
Expand Down
15 changes: 14 additions & 1 deletion src/main/window/main-window-updater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { app, ipcMain } from 'electron'
import type { BrowserWindow, IpcMainInvokeEvent } from 'electron'
import type { ReleaseBuildListResult, UpdateCheckOptions } from '../../shared/update-status-types'
import type {
ReleaseBuildListResult,
ReleaseSourceStatus,
UpdateCheckOptions
} from '../../shared/update-status-types'
import { RELEASE_CHANNELS, type ReleaseChannel } from '../../shared/release-channel'
import { getReleaseSource } from '../../shared/release-sources'
import { isTrustedUIRenderer } from '../ipc/ui'
Expand All @@ -14,6 +18,7 @@ import {
getLinuxPackageInstallInstructions,
getUpdateStatus,
listAvailableReleaseBuilds,
listReleaseSources,
quitAndInstall,
setupAutoUpdater,
showLinuxPackage,
Expand Down Expand Up @@ -91,6 +96,7 @@ export function registerUpdaterHandlers(_store: Store): void {
ipcMain.removeHandler('updater:getLinuxPackageInstallInstructions')
ipcMain.removeHandler('updater:showLinuxPackage')
ipcMain.removeHandler('updater:listBuilds')
ipcMain.removeHandler('updater:listSources')

ipcMain.handle('updater:getStatus', () => getUpdateStatus())
ipcMain.handle('updater:getVersion', () => app.getVersion())
Expand Down Expand Up @@ -142,6 +148,13 @@ export function registerUpdaterHandlers(_store: Store): void {
}
}
)
// Why no per-source rejection: each source reports its own list failure as data, so the
// Updates section can still offer the sources that answered.
ipcMain.handle(
'updater:listSources',
(_event, options?: { force?: boolean }): Promise<ReleaseSourceStatus[]> =>
listReleaseSources({ force: options?.force === true })
)
}

function assertTrustedUpdaterRecoverySender(event: IpcMainInvokeEvent): void {
Expand Down
Loading
Loading