Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
49 changes: 49 additions & 0 deletions src/main/updater.cross-source-install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,55 @@ describe('updater cross-source install', () => {
}
})

// Why: the staged AppImage stays registered with electron-updater's quit handler; a routine check
// that unpinned it would say "latest" while quitting still installs the other source's build.
it('keeps a staged cross-source build pinned when a routine check is requested', async () => {
const platformSpy = vi.spyOn(process, 'platform', 'get').mockReturnValue('linux')
try {
asMultiSourceBuild('1.4.197')
autoUpdaterMock.checkForUpdates.mockImplementation(() => {
autoUpdaterMock.emit('checking-for-update')
autoUpdaterMock.emit('update-available', { version: FORK_VERSION })
return Promise.resolve(undefined)
})
autoUpdaterMock.downloadUpdate.mockResolvedValue(undefined)
const { mainWindow, send } = createUpdaterMainWindowFake()
const { setupAutoUpdater, checkForUpdatesFromMenu, getUpdateStatus } =
await loadUpdaterModule()
setupAutoUpdater(mainWindow, {
getLastUpdateCheckAt: () => Date.now()
})

checkForUpdatesFromMenu({ ...toSwapLabs, autoDownload: true })
await vi.waitFor(() => {
expect(send).toHaveBeenCalledWith(
'updater:status',
expect.objectContaining({ state: 'downloading', version: FORK_VERSION })
)
})
autoUpdaterMock.emit('update-downloaded', { version: FORK_VERSION })
expect(getUpdateStatus()).toMatchObject({ state: 'downloaded', version: FORK_VERSION })
send.mockClear()

checkForUpdatesFromMenu()
await new Promise((resolve) => setTimeout(resolve, 0))

expect(getUpdateStatus()).toMatchObject({
state: 'downloaded',
version: FORK_VERSION,
releaseSource: 'swaplabs'
})
expect(send).not.toHaveBeenCalledWith(
'updater:status',
expect.objectContaining({ state: 'checking' })
)
expect(autoUpdaterMock.checkForUpdates).toHaveBeenCalledTimes(1)
expect(autoUpdaterMock.allowDowngrade).toBe(true)
} finally {
platformSpy.mockRestore()
}
})

// Why: Squirrel.Mac only installs a bundle carrying the running app's signature, and Windows
// Authenticode-checks an installer against the installed app's publisher; each source signs
// with its own identity, so the download must never start.
Expand Down
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
5 changes: 5 additions & 0 deletions src/main/updater/updater-menu-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export abstract class UpdaterMenuChecks extends UpdaterScheduling {
) {
return
}
// Why: a staged pinned build stays registered with electron-updater's quit handler, so unpinning
// here would report "latest" while quitting still installs it. It is restarted into or not at all.
if (this.isPinnedBuildActive && this.currentStatus.state === 'downloaded') {
return
}
this.restoreReleaseUpdateSource()

const checkVariant = this.getUpdateCheckVariant(options)
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
Loading
Loading