refactor: replace allowPrerelease workaround with generic feed URL (#365)
* fix(renderer): fix unescaped quote lint error in GeneralPane * refactor: replace allowPrerelease workaround with generic feed URL Use electron-updater's generic provider pointed at GitHub's /releases/latest/download/ so the manifest always comes from the latest stable release. This eliminates the client-side RC filtering, the GitHub releases API fallback, and the manual-download path entirely.
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
isMacQuitAndInstallInFlight,
|
||||
resetMacInstallState
|
||||
} from './updater-mac-install'
|
||||
import { compareVersions, findFallbackReleaseVersion, isPrerelease } from './updater-fallback'
|
||||
import { compareVersions } from './updater-fallback'
|
||||
|
||||
type UpdaterHandlerContext = {
|
||||
clearAvailableUpdateContext: () => void
|
||||
@@ -95,58 +95,7 @@ export function registerAutoUpdaterHandlers({
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
const wasUserInitiated = getUserInitiatedCheck()
|
||||
setUserInitiatedCheck(false)
|
||||
// RC releases are only meant to be installed by hand; the auto-updater must
|
||||
// never offer them. We need this guard because allowPrerelease is enabled on
|
||||
// electron-updater to work around a broken GitHub endpoint, which causes
|
||||
// prerelease versions to slip through its normal filter.
|
||||
//
|
||||
// When the latest GitHub release is an RC, electron-updater will pick it as
|
||||
// the available version and never report any older stable releases. We fall
|
||||
// back to the GitHub releases API (which filters out prereleases/drafts) so
|
||||
// that a stable release newer than the running version is still offered.
|
||||
if (isPrerelease(info.version)) {
|
||||
findFallbackReleaseVersion()
|
||||
.then((fallback) => {
|
||||
if (fallback) {
|
||||
setAvailableVersion(fallback.version)
|
||||
setAvailableReleaseUrl(fallback.releaseUrl)
|
||||
recordCompletedUpdateCheck()
|
||||
if (!wasUserInitiated) {
|
||||
scheduleAutomaticUpdateCheck(36 * 60 * 60 * 1000)
|
||||
}
|
||||
sendStatus({
|
||||
state: 'available',
|
||||
version: fallback.version,
|
||||
releaseUrl: fallback.releaseUrl,
|
||||
manualDownloadUrl: fallback.manualDownloadUrl
|
||||
})
|
||||
} else {
|
||||
clearAvailableUpdateContext()
|
||||
recordCompletedUpdateCheck()
|
||||
if (!wasUserInitiated) {
|
||||
scheduleAutomaticUpdateCheck(36 * 60 * 60 * 1000)
|
||||
}
|
||||
sendStatus({ state: 'not-available', userInitiated: wasUserInitiated || undefined })
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(
|
||||
'[updater] fallback lookup after RC rejection failed:',
|
||||
String(err?.message ?? err)
|
||||
)
|
||||
clearAvailableUpdateContext()
|
||||
recordCompletedUpdateCheck()
|
||||
if (!wasUserInitiated) {
|
||||
scheduleAutomaticUpdateCheck(36 * 60 * 60 * 1000)
|
||||
}
|
||||
sendStatus({ state: 'not-available', userInitiated: wasUserInitiated || undefined })
|
||||
})
|
||||
return
|
||||
}
|
||||
// Guard against showing an update that isn't actually newer than what's running.
|
||||
// With allowPrerelease enabled, electron-updater may report the current or
|
||||
// even an older version as "available". Use semver comparison so we never
|
||||
// prompt the user to "update" to a version they already have.
|
||||
if (compareVersions(info.version, app.getVersion()) <= 0) {
|
||||
clearAvailableUpdateContext()
|
||||
sendStatus({ state: 'not-available', userInitiated: wasUserInitiated || undefined })
|
||||
@@ -182,13 +131,6 @@ export function registerAutoUpdaterHandlers({
|
||||
})
|
||||
|
||||
autoUpdater.on('update-downloaded', (info) => {
|
||||
// Safety net: reject RC downloads that somehow slipped past the
|
||||
// update-available guard. RC releases are manual-install only.
|
||||
if (isPrerelease(info.version)) {
|
||||
clearAvailableUpdateContext()
|
||||
sendStatus({ state: 'not-available' })
|
||||
return
|
||||
}
|
||||
// Don't show the banner if the downloaded version isn't actually newer
|
||||
// than what's running. This catches the exact-same-version case as well
|
||||
// as stale cached updates from an older release.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { app } from 'electron'
|
||||
import type { UpdateStatus } from '../shared/types'
|
||||
|
||||
export function statusesEqual(left: UpdateStatus, right: UpdateStatus): boolean {
|
||||
@@ -13,8 +12,7 @@ export function statusesEqual(left: UpdateStatus, right: UpdateStatus): boolean
|
||||
return (
|
||||
right.state === 'available' &&
|
||||
left.version === right.version &&
|
||||
left.releaseUrl === right.releaseUrl &&
|
||||
left.manualDownloadUrl === right.manualDownloadUrl
|
||||
left.releaseUrl === right.releaseUrl
|
||||
)
|
||||
case 'downloading':
|
||||
return (
|
||||
@@ -37,27 +35,6 @@ export function statusesEqual(left: UpdateStatus, right: UpdateStatus): boolean
|
||||
}
|
||||
}
|
||||
|
||||
const RELEASES_API_URL = 'https://api.github.com/repos/stablyai/orca/releases'
|
||||
|
||||
type GitHubReleaseAsset = {
|
||||
name?: string
|
||||
browser_download_url?: string
|
||||
}
|
||||
|
||||
type GitHubRelease = {
|
||||
draft?: boolean
|
||||
prerelease?: boolean
|
||||
tag_name?: string
|
||||
html_url?: string
|
||||
assets?: GitHubReleaseAsset[]
|
||||
}
|
||||
|
||||
export type FallbackRelease = {
|
||||
version: string
|
||||
releaseUrl: string
|
||||
manualDownloadUrl: string
|
||||
}
|
||||
|
||||
export function isGitHubReleaseTransitionFailure(normalizedMessage: string): boolean {
|
||||
return (
|
||||
normalizedMessage.includes('unable to find latest version on github') ||
|
||||
@@ -104,9 +81,6 @@ function parseVersion(value: string): ParsedVersion | null {
|
||||
|
||||
return {
|
||||
core: [Number(match[1]), Number(match[2]), Number(match[3])],
|
||||
// We must preserve prerelease ordering because the updater enables
|
||||
// allowPrerelease to work around GitHub's latest endpoint. Falling back to
|
||||
// "equal" for `1.2.3-rc.1` would silently suppress valid updates.
|
||||
prerelease: match[4]?.split('.') ?? []
|
||||
}
|
||||
}
|
||||
@@ -127,18 +101,6 @@ function compareIdentifiers(left: string, right: string): number {
|
||||
return left.localeCompare(right)
|
||||
}
|
||||
|
||||
/** Returns true if the version string contains a prerelease tag (e.g. "-rc.1").
|
||||
* RC releases are only meant to be installed by hand, so the auto-updater must
|
||||
* never offer them. We need this guard because allowPrerelease is enabled on
|
||||
* electron-updater to work around a broken GitHub /releases/latest endpoint,
|
||||
* which means prerelease versions slip through its normal filter. */
|
||||
export function isPrerelease(version: string): boolean {
|
||||
const parsed = parseVersion(version)
|
||||
// Treat unparseable versions as prerelease so they are rejected early rather
|
||||
// than slipping through to downstream guards.
|
||||
return parsed === null || parsed.prerelease.length > 0
|
||||
}
|
||||
|
||||
/** Returns negative if left < right, 0 if equal, positive if left > right. */
|
||||
export function compareVersions(left: string, right: string): number {
|
||||
const leftVersion = parseVersion(left)
|
||||
@@ -185,91 +147,3 @@ export function compareVersions(left: string, right: string): number {
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function scoreAssetForCurrentPlatform(asset: GitHubReleaseAsset): number {
|
||||
const assetName = asset.name?.toLowerCase() ?? ''
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
const isDmg = assetName.endsWith('.dmg')
|
||||
const isZip = assetName.endsWith('.zip')
|
||||
if (!isDmg && !isZip) {
|
||||
return -1
|
||||
}
|
||||
|
||||
const extensionScore = isDmg ? 2 : 1
|
||||
const normalizedArch =
|
||||
process.arch === 'x64' ? 'x64' : process.arch === 'arm64' ? 'arm64' : null
|
||||
if (!normalizedArch) {
|
||||
return extensionScore
|
||||
}
|
||||
if (assetName.includes(normalizedArch)) {
|
||||
return 2 + extensionScore
|
||||
}
|
||||
if (assetName.includes('x64') || assetName.includes('arm64')) {
|
||||
return 0
|
||||
}
|
||||
return extensionScore
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
return assetName.endsWith('.exe') ? 1 : -1
|
||||
}
|
||||
|
||||
if (assetName.endsWith('.appimage')) {
|
||||
return 2
|
||||
}
|
||||
if (assetName.endsWith('.deb')) {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function getManualDownloadAssetUrl(release: GitHubRelease): string | null {
|
||||
const assets = release.assets ?? []
|
||||
const platformAsset = assets
|
||||
.map((asset) => ({ asset, score: scoreAssetForCurrentPlatform(asset) }))
|
||||
.filter(({ score }) => score >= 0)
|
||||
.sort((left, right) => right.score - left.score)[0]?.asset
|
||||
|
||||
return platformAsset?.browser_download_url ?? null
|
||||
}
|
||||
|
||||
export async function findFallbackReleaseVersion(): Promise<FallbackRelease | null> {
|
||||
const response = await fetch(RELEASES_API_URL, {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github+json',
|
||||
'User-Agent': 'Orca-Updater'
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`GitHub releases lookup failed: ${response.status}`)
|
||||
}
|
||||
|
||||
const releases = (await response.json()) as GitHubRelease[]
|
||||
const currentVersion = app.getVersion()
|
||||
|
||||
for (const release of releases) {
|
||||
if (release.draft || release.prerelease || !release.tag_name || !release.html_url) {
|
||||
continue
|
||||
}
|
||||
|
||||
const releaseVersion = release.tag_name.replace(/^v/i, '')
|
||||
if (compareVersions(releaseVersion, currentVersion) <= 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
const manualDownloadUrl = getManualDownloadAssetUrl(release)
|
||||
if (!manualDownloadUrl) {
|
||||
continue
|
||||
}
|
||||
|
||||
return {
|
||||
version: releaseVersion,
|
||||
releaseUrl: release.html_url,
|
||||
manualDownloadUrl
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1,91 +1,75 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
buildReleaseLookupResponse,
|
||||
getFallbackAssetUrl,
|
||||
releaseTagUrl
|
||||
} from './updater.test-fixtures'
|
||||
|
||||
const {
|
||||
appMock,
|
||||
browserWindowMock,
|
||||
nativeUpdaterMock,
|
||||
autoUpdaterMock,
|
||||
shellMock,
|
||||
isMock,
|
||||
killAllPtyMock
|
||||
} = vi.hoisted(() => {
|
||||
const appEventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
const eventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
const { appMock, browserWindowMock, nativeUpdaterMock, autoUpdaterMock, isMock, killAllPtyMock } =
|
||||
vi.hoisted(() => {
|
||||
const appEventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
const eventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
|
||||
const appOn = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = appEventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
appEventHandlers.set(event, handlers)
|
||||
return appMock
|
||||
})
|
||||
const appOn = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = appEventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
appEventHandlers.set(event, handlers)
|
||||
return appMock
|
||||
})
|
||||
|
||||
const on = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = eventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
eventHandlers.set(event, handlers)
|
||||
return autoUpdaterMock
|
||||
})
|
||||
const on = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = eventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
eventHandlers.set(event, handlers)
|
||||
return autoUpdaterMock
|
||||
})
|
||||
|
||||
const emit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of eventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
const emit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of eventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
appEventHandlers.clear()
|
||||
appOn.mockClear()
|
||||
eventHandlers.clear()
|
||||
on.mockClear()
|
||||
autoUpdaterMock.checkForUpdates.mockReset()
|
||||
autoUpdaterMock.downloadUpdate.mockReset()
|
||||
autoUpdaterMock.quitAndInstall.mockReset()
|
||||
}
|
||||
const reset = () => {
|
||||
appEventHandlers.clear()
|
||||
appOn.mockClear()
|
||||
eventHandlers.clear()
|
||||
on.mockClear()
|
||||
autoUpdaterMock.checkForUpdates.mockReset()
|
||||
autoUpdaterMock.downloadUpdate.mockReset()
|
||||
autoUpdaterMock.quitAndInstall.mockReset()
|
||||
}
|
||||
|
||||
const autoUpdaterMock = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: false,
|
||||
allowPrerelease: false,
|
||||
on,
|
||||
checkForUpdates: vi.fn(),
|
||||
downloadUpdate: vi.fn(),
|
||||
quitAndInstall: vi.fn(),
|
||||
emit,
|
||||
reset
|
||||
}
|
||||
const autoUpdaterMock = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: false,
|
||||
on,
|
||||
checkForUpdates: vi.fn(),
|
||||
downloadUpdate: vi.fn(),
|
||||
quitAndInstall: vi.fn(),
|
||||
setFeedURL: vi.fn(),
|
||||
emit,
|
||||
reset
|
||||
}
|
||||
|
||||
return {
|
||||
appMock: {
|
||||
isPackaged: true,
|
||||
getVersion: vi.fn(() => '1.0.51'),
|
||||
on: appOn,
|
||||
quit: vi.fn()
|
||||
},
|
||||
browserWindowMock: {
|
||||
getAllWindows: vi.fn(() => [])
|
||||
},
|
||||
nativeUpdaterMock: {
|
||||
on: vi.fn()
|
||||
},
|
||||
autoUpdaterMock,
|
||||
shellMock: {
|
||||
openExternal: vi.fn()
|
||||
},
|
||||
isMock: { dev: false },
|
||||
killAllPtyMock: vi.fn()
|
||||
}
|
||||
})
|
||||
return {
|
||||
appMock: {
|
||||
isPackaged: true,
|
||||
getVersion: vi.fn(() => '1.0.51'),
|
||||
on: appOn,
|
||||
quit: vi.fn()
|
||||
},
|
||||
browserWindowMock: {
|
||||
getAllWindows: vi.fn(() => [])
|
||||
},
|
||||
nativeUpdaterMock: {
|
||||
on: vi.fn()
|
||||
},
|
||||
autoUpdaterMock,
|
||||
isMock: { dev: false },
|
||||
killAllPtyMock: vi.fn()
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: appMock,
|
||||
BrowserWindow: browserWindowMock,
|
||||
autoUpdater: nativeUpdaterMock,
|
||||
shell: shellMock
|
||||
autoUpdater: nativeUpdaterMock
|
||||
}))
|
||||
|
||||
vi.mock('electron-updater', () => ({
|
||||
@@ -101,15 +85,12 @@ vi.mock('./ipc/pty', () => ({
|
||||
}))
|
||||
|
||||
describe('updater check failure handling', () => {
|
||||
const fallbackAssetUrl = getFallbackAssetUrl()
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
autoUpdaterMock.reset()
|
||||
nativeUpdaterMock.on.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReturnValue([])
|
||||
shellMock.openExternal.mockReset()
|
||||
appMock.getVersion.mockReset()
|
||||
appMock.getVersion.mockReturnValue('1.0.51')
|
||||
appMock.quit.mockReset()
|
||||
@@ -119,15 +100,7 @@ describe('updater check failure handling', () => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('treats GitHub release transition errors during checks as benign', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => buildReleaseLookupResponse()
|
||||
}))
|
||||
)
|
||||
|
||||
it('treats GitHub release transition errors as not-available for user-initiated checks', async () => {
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce(undefined).mockImplementationOnce(() => {
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
queueMicrotask(() => {
|
||||
@@ -147,24 +120,11 @@ describe('updater check failure handling', () => {
|
||||
const statuses = sendMock.mock.calls
|
||||
.filter(([channel]) => channel === 'updater:status')
|
||||
.map(([, status]) => status)
|
||||
expect(statuses).toContainEqual({
|
||||
state: 'available',
|
||||
version: '1.0.61',
|
||||
releaseUrl: releaseTagUrl,
|
||||
manualDownloadUrl: fallbackAssetUrl
|
||||
})
|
||||
expect(statuses).toContainEqual({ state: 'not-available', userInitiated: true })
|
||||
})
|
||||
})
|
||||
|
||||
it('treats missing latest-mac.yml during checks as a benign idle transition', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => []
|
||||
}))
|
||||
)
|
||||
|
||||
it('treats missing latest-mac.yml during user-initiated checks as not-available', async () => {
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce(undefined).mockImplementationOnce(() => {
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
queueMicrotask(() => {
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { buildReleaseLookupResponse, releaseTagUrl } from './updater.test-fixtures'
|
||||
|
||||
const { appMock, browserWindowMock, nativeUpdaterMock, autoUpdaterMock, shellMock, isMock } =
|
||||
vi.hoisted(() => {
|
||||
const eventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
|
||||
const on = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = eventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
eventHandlers.set(event, handlers)
|
||||
return autoUpdaterMock
|
||||
})
|
||||
|
||||
const emit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of eventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
}
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
eventHandlers.clear()
|
||||
on.mockClear()
|
||||
autoUpdaterMock.checkForUpdates.mockReset()
|
||||
autoUpdaterMock.downloadUpdate.mockReset()
|
||||
autoUpdaterMock.quitAndInstall.mockReset()
|
||||
}
|
||||
|
||||
const autoUpdaterMock = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: false,
|
||||
allowPrerelease: false,
|
||||
on,
|
||||
checkForUpdates: vi.fn(),
|
||||
downloadUpdate: vi.fn(),
|
||||
quitAndInstall: vi.fn(),
|
||||
emit,
|
||||
reset
|
||||
}
|
||||
|
||||
return {
|
||||
appMock: {
|
||||
isPackaged: true,
|
||||
getVersion: vi.fn(() => '1.0.51'),
|
||||
on: vi.fn(),
|
||||
quit: vi.fn()
|
||||
},
|
||||
browserWindowMock: {
|
||||
getAllWindows: vi.fn(() => [])
|
||||
},
|
||||
nativeUpdaterMock: {
|
||||
on: vi.fn()
|
||||
},
|
||||
autoUpdaterMock,
|
||||
shellMock: {
|
||||
openExternal: vi.fn()
|
||||
},
|
||||
isMock: { dev: false }
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: appMock,
|
||||
BrowserWindow: browserWindowMock,
|
||||
autoUpdater: nativeUpdaterMock,
|
||||
shell: shellMock
|
||||
}))
|
||||
|
||||
vi.mock('electron-updater', () => ({
|
||||
autoUpdater: autoUpdaterMock
|
||||
}))
|
||||
|
||||
vi.mock('@electron-toolkit/utils', () => ({
|
||||
is: isMock
|
||||
}))
|
||||
|
||||
vi.mock('./ipc/pty', () => ({
|
||||
killAllPty: vi.fn()
|
||||
}))
|
||||
|
||||
describe('updater fallback asset selection', () => {
|
||||
function mockReleaseLookupResponse(releases = buildReleaseLookupResponse()): void {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => releases
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
function mockCheckFailure(message: string): void {
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce(undefined).mockImplementationOnce(() => {
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
queueMicrotask(() => {
|
||||
autoUpdaterMock.emit('error', new Error(message))
|
||||
})
|
||||
return Promise.reject(new Error(message))
|
||||
})
|
||||
}
|
||||
|
||||
async function expectFallbackAvailable(
|
||||
sendMock: ReturnType<typeof vi.fn>,
|
||||
manualDownloadUrl: string
|
||||
): Promise<void> {
|
||||
await vi.waitFor(() => {
|
||||
expect(sendMock).toHaveBeenCalledWith('updater:status', {
|
||||
state: 'available',
|
||||
version: '1.0.61',
|
||||
releaseUrl: releaseTagUrl,
|
||||
manualDownloadUrl
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
autoUpdaterMock.reset()
|
||||
nativeUpdaterMock.on.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReturnValue([])
|
||||
shellMock.openExternal.mockReset()
|
||||
shellMock.openExternal.mockResolvedValue(true)
|
||||
appMock.getVersion.mockReset()
|
||||
appMock.getVersion.mockReturnValue('1.0.51')
|
||||
appMock.isPackaged = true
|
||||
isMock.dev = false
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it.runIf(process.platform === 'darwin')(
|
||||
'prefers the fallback asset that matches the current macOS architecture',
|
||||
async () => {
|
||||
const preferredAssetUrl =
|
||||
process.arch === 'arm64'
|
||||
? 'https://github.com/stablyai/orca/releases/download/v1.0.61/orca-macos-arm64.dmg'
|
||||
: 'https://github.com/stablyai/orca/releases/download/v1.0.61/orca-macos-x64.dmg'
|
||||
const nonPreferredAssetUrl =
|
||||
process.arch === 'arm64'
|
||||
? 'https://github.com/stablyai/orca/releases/download/v1.0.61/orca-macos-x64.dmg'
|
||||
: 'https://github.com/stablyai/orca/releases/download/v1.0.61/orca-macos-arm64.dmg'
|
||||
|
||||
mockReleaseLookupResponse([
|
||||
{
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
tag_name: 'v1.0.61',
|
||||
html_url: releaseTagUrl,
|
||||
assets: [
|
||||
{
|
||||
name: process.arch === 'arm64' ? 'orca-macos-x64.dmg' : 'orca-macos-arm64.dmg',
|
||||
browser_download_url: nonPreferredAssetUrl
|
||||
},
|
||||
{
|
||||
name: process.arch === 'arm64' ? 'orca-macos-arm64.dmg' : 'orca-macos-x64.dmg',
|
||||
browser_download_url: preferredAssetUrl
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
mockCheckFailure('Unable to find latest version on GitHub')
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await expectFallbackAvailable(sendMock, preferredAssetUrl)
|
||||
}
|
||||
)
|
||||
|
||||
it.runIf(process.platform === 'darwin')(
|
||||
'prefers the dmg over the zip for the matching macOS architecture',
|
||||
async () => {
|
||||
const matchingArch = process.arch === 'arm64' ? 'arm64' : 'x64'
|
||||
const dmgUrl = `https://github.com/stablyai/orca/releases/download/v1.0.61/orca-macos-${matchingArch}.dmg`
|
||||
const zipUrl = `https://github.com/stablyai/orca/releases/download/v1.0.61/orca-macos-${matchingArch}.zip`
|
||||
|
||||
mockReleaseLookupResponse([
|
||||
{
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
tag_name: 'v1.0.61',
|
||||
html_url: releaseTagUrl,
|
||||
assets: [
|
||||
{
|
||||
name: `orca-macos-${matchingArch}.zip`,
|
||||
browser_download_url: zipUrl
|
||||
},
|
||||
{
|
||||
name: `orca-macos-${matchingArch}.dmg`,
|
||||
browser_download_url: dmgUrl
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
mockCheckFailure('Unable to find latest version on GitHub')
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await expectFallbackAvailable(sendMock, dmgUrl)
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -1,288 +1,11 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
buildReleaseLookupResponse,
|
||||
getFallbackAssetUrl,
|
||||
releaseTagUrl
|
||||
} from './updater.test-fixtures'
|
||||
|
||||
const { appMock, browserWindowMock, nativeUpdaterMock, autoUpdaterMock, shellMock, isMock } =
|
||||
vi.hoisted(() => {
|
||||
const eventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
|
||||
const on = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = eventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
eventHandlers.set(event, handlers)
|
||||
return autoUpdaterMock
|
||||
})
|
||||
|
||||
const emit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of eventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
}
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
eventHandlers.clear()
|
||||
on.mockClear()
|
||||
autoUpdaterMock.checkForUpdates.mockReset()
|
||||
autoUpdaterMock.downloadUpdate.mockReset()
|
||||
autoUpdaterMock.quitAndInstall.mockReset()
|
||||
}
|
||||
|
||||
const autoUpdaterMock = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: false,
|
||||
allowPrerelease: false,
|
||||
on,
|
||||
checkForUpdates: vi.fn(),
|
||||
downloadUpdate: vi.fn(),
|
||||
quitAndInstall: vi.fn(),
|
||||
emit,
|
||||
reset
|
||||
}
|
||||
|
||||
return {
|
||||
appMock: {
|
||||
isPackaged: true,
|
||||
getVersion: vi.fn(() => '1.0.51'),
|
||||
on: vi.fn(),
|
||||
quit: vi.fn()
|
||||
},
|
||||
browserWindowMock: {
|
||||
getAllWindows: vi.fn(() => [])
|
||||
},
|
||||
nativeUpdaterMock: {
|
||||
on: vi.fn()
|
||||
},
|
||||
autoUpdaterMock,
|
||||
shellMock: {
|
||||
openExternal: vi.fn()
|
||||
},
|
||||
isMock: { dev: false }
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: appMock,
|
||||
BrowserWindow: browserWindowMock,
|
||||
autoUpdater: nativeUpdaterMock,
|
||||
shell: shellMock
|
||||
}))
|
||||
|
||||
vi.mock('electron-updater', () => ({
|
||||
autoUpdater: autoUpdaterMock
|
||||
}))
|
||||
|
||||
vi.mock('@electron-toolkit/utils', () => ({
|
||||
is: isMock
|
||||
}))
|
||||
|
||||
vi.mock('./ipc/pty', () => ({
|
||||
killAllPty: vi.fn()
|
||||
}))
|
||||
|
||||
describe('updater fallback', () => {
|
||||
const fallbackAssetUrl = getFallbackAssetUrl()
|
||||
const latestMacYmlError = 'Cannot find channel "latest-mac.yml" update info: HttpError: 404'
|
||||
|
||||
function mockReleaseLookupResponse(releases = buildReleaseLookupResponse()): void {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => releases
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
function mockCheckFailure(message: string): void {
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce(undefined).mockImplementationOnce(() => {
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
queueMicrotask(() => {
|
||||
autoUpdaterMock.emit('error', new Error(message))
|
||||
})
|
||||
return Promise.reject(new Error(message))
|
||||
})
|
||||
}
|
||||
|
||||
function getStatuses(sendMock: ReturnType<typeof vi.fn>): unknown[] {
|
||||
return sendMock.mock.calls
|
||||
.filter(([channel]) => channel === 'updater:status')
|
||||
.map(([, status]) => status)
|
||||
}
|
||||
|
||||
async function expectFallbackAvailable(
|
||||
sendMock: ReturnType<typeof vi.fn>,
|
||||
manualDownloadUrl = fallbackAssetUrl
|
||||
): Promise<void> {
|
||||
await vi.waitFor(() => {
|
||||
expect(getStatuses(sendMock)).toContainEqual({
|
||||
state: 'available',
|
||||
version: '1.0.61',
|
||||
releaseUrl: releaseTagUrl,
|
||||
manualDownloadUrl
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
autoUpdaterMock.reset()
|
||||
nativeUpdaterMock.on.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReturnValue([])
|
||||
shellMock.openExternal.mockReset()
|
||||
shellMock.openExternal.mockResolvedValue(true)
|
||||
appMock.getVersion.mockReset()
|
||||
appMock.getVersion.mockReturnValue('1.0.51')
|
||||
appMock.isPackaged = true
|
||||
isMock.dev = false
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('compares prerelease and build semver strings correctly', async () => {
|
||||
const { compareVersions } = await import('./updater-fallback')
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { compareVersions } from './updater-fallback'
|
||||
|
||||
describe('compareVersions', () => {
|
||||
it('compares prerelease and build semver strings correctly', () => {
|
||||
expect(compareVersions('1.0.70-rc.1', '1.0.69')).toBeGreaterThan(0)
|
||||
expect(compareVersions('1.0.70', '1.0.70-rc.1')).toBeGreaterThan(0)
|
||||
expect(compareVersions('1.0.70+build.5', '1.0.70')).toBe(0)
|
||||
expect(compareVersions('v1.0.70-beta.2', '1.0.70-beta.1')).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('identifies prerelease versions correctly', async () => {
|
||||
const { isPrerelease } = await import('./updater-fallback')
|
||||
|
||||
expect(isPrerelease('1.0.70-rc.1')).toBe(true)
|
||||
expect(isPrerelease('1.0.70-rc.0')).toBe(true)
|
||||
expect(isPrerelease('1.0.70-beta.1')).toBe(true)
|
||||
expect(isPrerelease('1.0.70-alpha.3')).toBe(true)
|
||||
expect(isPrerelease('v1.0.70-rc.1')).toBe(true)
|
||||
expect(isPrerelease('1.0.70')).toBe(false)
|
||||
expect(isPrerelease('v1.0.70')).toBe(false)
|
||||
expect(isPrerelease('1.0.70+build.5')).toBe(false)
|
||||
})
|
||||
|
||||
it('falls back to the latest stable GitHub release when GitHub reports no published versions', async () => {
|
||||
mockReleaseLookupResponse()
|
||||
mockCheckFailure('No published versions on GitHub')
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await expectFallbackAvailable(sendMock)
|
||||
})
|
||||
|
||||
it('opens the fallback download URL instead of using electron-updater', async () => {
|
||||
mockReleaseLookupResponse(buildReleaseLookupResponse().slice(1))
|
||||
mockCheckFailure(latestMacYmlError)
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu, downloadUpdate } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await expectFallbackAvailable(sendMock)
|
||||
|
||||
downloadUpdate()
|
||||
|
||||
expect(shellMock.openExternal).toHaveBeenCalledWith(fallbackAssetUrl)
|
||||
expect(autoUpdaterMock.downloadUpdate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('preserves the fallback release URL when the update becomes downloaded', async () => {
|
||||
mockReleaseLookupResponse(buildReleaseLookupResponse().slice(1))
|
||||
mockCheckFailure(latestMacYmlError)
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
autoUpdaterMock.emit('error', new Error(latestMacYmlError))
|
||||
|
||||
await expectFallbackAvailable(sendMock)
|
||||
|
||||
autoUpdaterMock.emit('update-downloaded', { version: '1.0.61' })
|
||||
if (process.platform === 'darwin') {
|
||||
const nativeDownloadedHandler = nativeUpdaterMock.on.mock.calls.find(
|
||||
([eventName]) => eventName === 'update-downloaded'
|
||||
)?.[1] as (() => void) | undefined
|
||||
expect(nativeDownloadedHandler).toBeTypeOf('function')
|
||||
nativeDownloadedHandler?.()
|
||||
}
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(sendMock).toHaveBeenCalledWith('updater:status', {
|
||||
state: 'downloaded',
|
||||
version: '1.0.61',
|
||||
releaseUrl: releaseTagUrl
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('surfaces manual download launcher failures', async () => {
|
||||
mockReleaseLookupResponse(buildReleaseLookupResponse().slice(1))
|
||||
shellMock.openExternal.mockRejectedValueOnce(new Error('launcher blocked'))
|
||||
mockCheckFailure(latestMacYmlError)
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu, downloadUpdate } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await expectFallbackAvailable(sendMock)
|
||||
|
||||
downloadUpdate()
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(sendMock).toHaveBeenCalledWith('updater:status', {
|
||||
state: 'error',
|
||||
message: 'launcher blocked',
|
||||
userInitiated: undefined
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('clears fallback release metadata before a later check reports no update', async () => {
|
||||
mockReleaseLookupResponse(buildReleaseLookupResponse().slice(1))
|
||||
mockCheckFailure(latestMacYmlError)
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await expectFallbackAvailable(sendMock)
|
||||
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
autoUpdaterMock.emit('update-not-available')
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(sendMock).toHaveBeenCalledWith('updater:status', {
|
||||
state: 'not-available',
|
||||
userInitiated: undefined
|
||||
})
|
||||
})
|
||||
|
||||
autoUpdaterMock.emit('update-downloaded', { version: '1.0.61' })
|
||||
|
||||
expect(sendMock).not.toHaveBeenCalledWith('updater:status', {
|
||||
state: 'downloaded',
|
||||
version: '1.0.61',
|
||||
releaseUrl: releaseTagUrl
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -51,11 +51,11 @@ const {
|
||||
const autoUpdaterMock = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: false,
|
||||
allowPrerelease: false,
|
||||
on,
|
||||
checkForUpdates: vi.fn(),
|
||||
downloadUpdate: vi.fn(),
|
||||
quitAndInstall: vi.fn(),
|
||||
setFeedURL: vi.fn(),
|
||||
emit,
|
||||
reset
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
export const releaseTagUrl = 'https://github.com/stablyai/orca/releases/tag/v1.0.61'
|
||||
|
||||
export const releaseDownloadUrls = {
|
||||
darwin: 'https://github.com/stablyai/orca/releases/download/v1.0.61/orca-macos-arm64.dmg',
|
||||
linux: 'https://github.com/stablyai/orca/releases/download/v1.0.61/orca-linux.AppImage',
|
||||
win32: 'https://github.com/stablyai/orca/releases/download/v1.0.61/orca-windows-setup.exe'
|
||||
} as const
|
||||
|
||||
export function getFallbackAssetUrl(): string {
|
||||
if (process.platform === 'darwin') {
|
||||
return releaseDownloadUrls.darwin
|
||||
}
|
||||
if (process.platform === 'win32') {
|
||||
return releaseDownloadUrls.win32
|
||||
}
|
||||
return releaseDownloadUrls.linux
|
||||
}
|
||||
|
||||
export function buildReleaseLookupResponse(): {
|
||||
draft: boolean
|
||||
prerelease: boolean
|
||||
tag_name: string
|
||||
html_url: string
|
||||
assets: { name: string; browser_download_url: string }[]
|
||||
}[] {
|
||||
return [
|
||||
{
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
tag_name: 'v1.0.62',
|
||||
html_url: 'https://github.com/stablyai/orca/releases/tag/v1.0.62',
|
||||
assets: []
|
||||
},
|
||||
{
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
tag_name: 'v1.0.61',
|
||||
html_url: releaseTagUrl,
|
||||
assets: [
|
||||
{
|
||||
name: 'orca-macos-arm64.dmg',
|
||||
browser_download_url: releaseDownloadUrls.darwin
|
||||
},
|
||||
{
|
||||
name: 'orca-windows-setup.exe',
|
||||
browser_download_url: releaseDownloadUrls.win32
|
||||
},
|
||||
{
|
||||
name: 'orca-linux.AppImage',
|
||||
browser_download_url: releaseDownloadUrls.linux
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+64
-183
@@ -1,96 +1,82 @@
|
||||
/* eslint-disable max-lines -- Why: the updater test suite covers event-handler interactions (RC rejection, fallback, version comparison, retry scheduling) that share mocking infrastructure and are easiest to reason about in one file. */
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const {
|
||||
appMock,
|
||||
browserWindowMock,
|
||||
nativeUpdaterMock,
|
||||
autoUpdaterMock,
|
||||
shellMock,
|
||||
isMock,
|
||||
killAllPtyMock,
|
||||
findFallbackReleaseVersionMock
|
||||
} = vi.hoisted(() => {
|
||||
const appEventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
const eventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
const { appMock, browserWindowMock, nativeUpdaterMock, autoUpdaterMock, isMock, killAllPtyMock } =
|
||||
vi.hoisted(() => {
|
||||
const appEventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
const eventHandlers = new Map<string, ((...args: unknown[]) => void)[]>()
|
||||
|
||||
const appOn = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = appEventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
appEventHandlers.set(event, handlers)
|
||||
return appMock
|
||||
})
|
||||
const appOn = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = appEventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
appEventHandlers.set(event, handlers)
|
||||
return appMock
|
||||
})
|
||||
|
||||
const appEmit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of appEventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
const appEmit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of appEventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const on = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = eventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
eventHandlers.set(event, handlers)
|
||||
return autoUpdaterMock
|
||||
})
|
||||
const on = vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
const handlers = eventHandlers.get(event) ?? []
|
||||
handlers.push(handler)
|
||||
eventHandlers.set(event, handlers)
|
||||
return autoUpdaterMock
|
||||
})
|
||||
|
||||
const emit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of eventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
const emit = (event: string, ...args: unknown[]) => {
|
||||
for (const handler of eventHandlers.get(event) ?? []) {
|
||||
handler(...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
appEventHandlers.clear()
|
||||
appOn.mockClear()
|
||||
eventHandlers.clear()
|
||||
on.mockClear()
|
||||
autoUpdaterMock.checkForUpdates.mockReset().mockResolvedValue(null)
|
||||
autoUpdaterMock.downloadUpdate.mockReset()
|
||||
autoUpdaterMock.quitAndInstall.mockReset()
|
||||
}
|
||||
const reset = () => {
|
||||
appEventHandlers.clear()
|
||||
appOn.mockClear()
|
||||
eventHandlers.clear()
|
||||
on.mockClear()
|
||||
autoUpdaterMock.checkForUpdates.mockReset().mockResolvedValue(null)
|
||||
autoUpdaterMock.downloadUpdate.mockReset()
|
||||
autoUpdaterMock.quitAndInstall.mockReset()
|
||||
}
|
||||
|
||||
const autoUpdaterMock = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: false,
|
||||
allowPrerelease: false,
|
||||
on,
|
||||
checkForUpdates: vi.fn(),
|
||||
downloadUpdate: vi.fn(),
|
||||
quitAndInstall: vi.fn(),
|
||||
emit,
|
||||
reset
|
||||
}
|
||||
const autoUpdaterMock = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: false,
|
||||
on,
|
||||
checkForUpdates: vi.fn(),
|
||||
downloadUpdate: vi.fn(),
|
||||
quitAndInstall: vi.fn(),
|
||||
setFeedURL: vi.fn(),
|
||||
emit,
|
||||
reset
|
||||
}
|
||||
|
||||
return {
|
||||
appMock: {
|
||||
isPackaged: true,
|
||||
getVersion: vi.fn(() => '1.0.51'),
|
||||
on: appOn,
|
||||
emit: appEmit,
|
||||
quit: vi.fn()
|
||||
},
|
||||
browserWindowMock: {
|
||||
getAllWindows: vi.fn(() => [])
|
||||
},
|
||||
nativeUpdaterMock: {
|
||||
on: vi.fn()
|
||||
},
|
||||
autoUpdaterMock,
|
||||
shellMock: {
|
||||
openExternal: vi.fn()
|
||||
},
|
||||
isMock: { dev: false },
|
||||
killAllPtyMock: vi.fn(),
|
||||
findFallbackReleaseVersionMock: vi.fn()
|
||||
}
|
||||
})
|
||||
return {
|
||||
appMock: {
|
||||
isPackaged: true,
|
||||
getVersion: vi.fn(() => '1.0.51'),
|
||||
on: appOn,
|
||||
emit: appEmit,
|
||||
quit: vi.fn()
|
||||
},
|
||||
browserWindowMock: {
|
||||
getAllWindows: vi.fn(() => [])
|
||||
},
|
||||
nativeUpdaterMock: {
|
||||
on: vi.fn()
|
||||
},
|
||||
autoUpdaterMock,
|
||||
isMock: { dev: false },
|
||||
killAllPtyMock: vi.fn()
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: appMock,
|
||||
BrowserWindow: browserWindowMock,
|
||||
autoUpdater: nativeUpdaterMock,
|
||||
shell: shellMock
|
||||
autoUpdater: nativeUpdaterMock
|
||||
}))
|
||||
|
||||
vi.mock('electron-updater', () => ({
|
||||
@@ -105,14 +91,6 @@ vi.mock('./ipc/pty', () => ({
|
||||
killAllPty: killAllPtyMock
|
||||
}))
|
||||
|
||||
vi.mock('./updater-fallback', async (importOriginal) => {
|
||||
const actual = (await importOriginal()) as Record<string, unknown>
|
||||
return {
|
||||
...actual,
|
||||
findFallbackReleaseVersion: findFallbackReleaseVersionMock
|
||||
}
|
||||
})
|
||||
|
||||
describe('updater', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
@@ -120,14 +98,12 @@ describe('updater', () => {
|
||||
nativeUpdaterMock.on.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReset()
|
||||
browserWindowMock.getAllWindows.mockReturnValue([])
|
||||
shellMock.openExternal.mockReset()
|
||||
appMock.getVersion.mockReset()
|
||||
appMock.getVersion.mockReturnValue('1.0.51')
|
||||
appMock.quit.mockReset()
|
||||
appMock.isPackaged = true
|
||||
isMock.dev = false
|
||||
killAllPtyMock.mockReset()
|
||||
findFallbackReleaseVersionMock.mockReset().mockResolvedValue(null)
|
||||
vi.unstubAllGlobals()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
@@ -270,101 +246,6 @@ describe('updater', () => {
|
||||
expect(setLastUpdateCheckAt).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('treats an RC version from update-available as not-available when no stable fallback exists', async () => {
|
||||
findFallbackReleaseVersionMock.mockResolvedValueOnce(null)
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce(undefined).mockImplementationOnce(() => {
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
queueMicrotask(() => {
|
||||
autoUpdaterMock.emit('update-available', { version: '1.0.52-rc.1' })
|
||||
})
|
||||
return Promise.resolve(null)
|
||||
})
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await vi.waitFor(() => {
|
||||
const statuses = sendMock.mock.calls
|
||||
.filter(([channel]) => channel === 'updater:status')
|
||||
.map(([, status]) => status)
|
||||
expect(statuses).toContainEqual(expect.objectContaining({ state: 'not-available' }))
|
||||
})
|
||||
|
||||
const statuses = sendMock.mock.calls
|
||||
.filter(([channel]) => channel === 'updater:status')
|
||||
.map(([, status]) => status)
|
||||
|
||||
expect(statuses).not.toContainEqual(expect.objectContaining({ state: 'available' }))
|
||||
})
|
||||
|
||||
it('falls back to a stable release when update-available reports an RC', async () => {
|
||||
findFallbackReleaseVersionMock.mockResolvedValueOnce({
|
||||
version: '1.0.52',
|
||||
releaseUrl: 'https://github.com/stablyai/orca/releases/tag/v1.0.52',
|
||||
manualDownloadUrl: 'https://github.com/stablyai/orca/releases/download/v1.0.52/Orca.dmg'
|
||||
})
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce(undefined).mockImplementationOnce(() => {
|
||||
autoUpdaterMock.emit('checking-for-update')
|
||||
queueMicrotask(() => {
|
||||
autoUpdaterMock.emit('update-available', { version: '1.0.53-rc.1' })
|
||||
})
|
||||
return Promise.resolve(null)
|
||||
})
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
checkForUpdatesFromMenu()
|
||||
await vi.waitFor(() => {
|
||||
const statuses = sendMock.mock.calls
|
||||
.filter(([channel]) => channel === 'updater:status')
|
||||
.map(([, status]) => status)
|
||||
expect(statuses).toContainEqual(
|
||||
expect.objectContaining({ state: 'available', version: '1.0.52' })
|
||||
)
|
||||
})
|
||||
|
||||
const statuses = sendMock.mock.calls
|
||||
.filter(([channel]) => channel === 'updater:status')
|
||||
.map(([, status]) => status)
|
||||
|
||||
// Should offer the stable fallback, not the RC
|
||||
expect(statuses).toContainEqual(
|
||||
expect.objectContaining({
|
||||
state: 'available',
|
||||
version: '1.0.52',
|
||||
releaseUrl: 'https://github.com/stablyai/orca/releases/tag/v1.0.52',
|
||||
manualDownloadUrl: 'https://github.com/stablyai/orca/releases/download/v1.0.52/Orca.dmg'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('treats an RC version from update-downloaded as not-available', async () => {
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce(undefined)
|
||||
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
|
||||
const { setupAutoUpdater } = await import('./updater')
|
||||
|
||||
setupAutoUpdater(mainWindow as never)
|
||||
autoUpdaterMock.emit('update-downloaded', { version: '1.0.52-rc.0' })
|
||||
|
||||
const statuses = sendMock.mock.calls
|
||||
.filter(([channel]) => channel === 'updater:status')
|
||||
.map(([, status]) => status)
|
||||
|
||||
expect(statuses).toContainEqual({ state: 'not-available' })
|
||||
expect(statuses).not.toContainEqual(expect.objectContaining({ state: 'downloaded' }))
|
||||
})
|
||||
|
||||
it('retries background checks sooner after a failed automatic check', async () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date('2026-04-03T12:00:00Z'))
|
||||
|
||||
+20
-54
@@ -1,4 +1,4 @@
|
||||
import { app, BrowserWindow, shell } from 'electron'
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import type { UpdateStatus } from '../shared/types'
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
import { registerAutoUpdaterHandlers } from './updater-events'
|
||||
import {
|
||||
compareVersions,
|
||||
findFallbackReleaseVersion,
|
||||
isBenignCheckFailure,
|
||||
isGitHubReleaseTransitionFailure,
|
||||
statusesEqual
|
||||
@@ -113,45 +112,15 @@ async function sendCheckFailureStatus(message: string, userInitiated?: boolean):
|
||||
|
||||
const handleFailure = async (): Promise<void> => {
|
||||
if (isBenignCheckFailure(message)) {
|
||||
if (isGitHubReleaseTransitionFailure(message.toLowerCase())) {
|
||||
try {
|
||||
const fallbackRelease = await findFallbackReleaseVersion()
|
||||
if (fallbackRelease) {
|
||||
console.warn(
|
||||
'[updater] using fallback GitHub release during release transition:',
|
||||
fallbackRelease.version
|
||||
)
|
||||
availableVersion = fallbackRelease.version
|
||||
availableReleaseUrl = fallbackRelease.releaseUrl
|
||||
persistLastUpdateCheckAt?.(Date.now())
|
||||
if (!userInitiated) {
|
||||
scheduleAutomaticUpdateCheck(AUTO_UPDATE_CHECK_INTERVAL_MS)
|
||||
}
|
||||
sendStatus({
|
||||
state: 'available',
|
||||
version: fallbackRelease.version,
|
||||
releaseUrl: fallbackRelease.releaseUrl,
|
||||
manualDownloadUrl: fallbackRelease.manualDownloadUrl
|
||||
})
|
||||
return
|
||||
}
|
||||
} catch (fallbackError) {
|
||||
console.warn(
|
||||
'[updater] fallback GitHub release lookup failed:',
|
||||
String((fallbackError as Error)?.message ?? fallbackError)
|
||||
)
|
||||
}
|
||||
|
||||
// The fallback confirmed there is no published version newer than the
|
||||
// current one (the only "newer" entry is a draft mid-release). Tell
|
||||
// the user they're up-to-date so clicking "Check for Updates" doesn't
|
||||
// appear to silently do nothing.
|
||||
if (userInitiated) {
|
||||
clearAvailableUpdateContext()
|
||||
persistLastUpdateCheckAt?.(Date.now())
|
||||
sendStatus({ state: 'not-available', userInitiated: true })
|
||||
return
|
||||
}
|
||||
// Release transition failures (missing latest.yml during publishing) and
|
||||
// network blips are transient. For user-initiated checks during a release
|
||||
// transition, show "up to date" so the action doesn't appear to silently
|
||||
// do nothing; for background checks, silently retry later.
|
||||
if (userInitiated && isGitHubReleaseTransitionFailure(message.toLowerCase())) {
|
||||
clearAvailableUpdateContext()
|
||||
persistLastUpdateCheckAt?.(Date.now())
|
||||
sendStatus({ state: 'not-available', userInitiated: true })
|
||||
return
|
||||
}
|
||||
|
||||
console.warn('[updater] benign check failure:', message)
|
||||
@@ -285,13 +254,16 @@ export function setupAutoUpdater(
|
||||
|
||||
autoUpdater.autoDownload = false
|
||||
autoUpdater.autoInstallOnAppQuit = true
|
||||
// Use allowPrerelease to bypass broken /releases/latest endpoint (returns 406)
|
||||
// and instead parse the version directly from the atom feed which works reliably.
|
||||
// RC/prerelease versions are filtered out in the update-available and
|
||||
// update-downloaded event handlers. When an RC is the latest release, the
|
||||
// update-available handler falls back to the GitHub releases API to find the
|
||||
// newest stable version so that real updates are not silently skipped.
|
||||
autoUpdater.allowPrerelease = true
|
||||
|
||||
// Use the generic provider with GitHub's /releases/latest/download/ URL so
|
||||
// electron-updater always fetches the manifest (latest-mac.yml, latest.yml,
|
||||
// latest-linux.yml) from the latest non-prerelease release. This sidesteps
|
||||
// the broken /releases/latest API endpoint (returns 406) and automatically
|
||||
// excludes RC/prerelease versions without client-side filtering.
|
||||
autoUpdater.setFeedURL({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
})
|
||||
|
||||
if (autoUpdaterInitialized) {
|
||||
return
|
||||
@@ -338,12 +310,6 @@ export function downloadUpdate(): void {
|
||||
if (currentStatus.state !== 'available') {
|
||||
return
|
||||
}
|
||||
if (currentStatus.manualDownloadUrl) {
|
||||
shell.openExternal(currentStatus.manualDownloadUrl).catch((err) => {
|
||||
sendErrorStatus(String(err?.message ?? err))
|
||||
})
|
||||
return
|
||||
}
|
||||
beginMacUpdateDownload()
|
||||
autoUpdater.downloadUpdate().catch((err) => {
|
||||
sendErrorStatus(String(err?.message ?? err))
|
||||
|
||||
@@ -363,9 +363,7 @@ export function GeneralPane({
|
||||
className="gap-2"
|
||||
>
|
||||
<Download className="size-3.5" />
|
||||
{updateStatus.manualDownloadUrl
|
||||
? `Download Update (${updateStatus.version})`
|
||||
: `Install Update (${updateStatus.version})`}
|
||||
Install Update ({updateStatus.version})
|
||||
</Button>
|
||||
) : updateStatus.state === 'downloaded' ? (
|
||||
<Button variant="default" size="sm" onClick={handleRestartToUpdate} className="gap-2">
|
||||
@@ -380,10 +378,8 @@ export function GeneralPane({
|
||||
{updateStatus.state === 'checking' && 'Checking for updates...'}
|
||||
{updateStatus.state === 'available' && (
|
||||
<>
|
||||
Version {updateStatus.version} is available.{' '}
|
||||
{updateStatus.manualDownloadUrl
|
||||
? 'Open the download to install it manually.'
|
||||
: 'Click "Install Update" to download it.'}{' '}
|
||||
Version {updateStatus.version} is available. Click "Install Update" to
|
||||
download and install it.{' '}
|
||||
<a
|
||||
href={
|
||||
updateStatus.releaseUrl ??
|
||||
|
||||
@@ -100,31 +100,6 @@ describe('createUpdateToastController', () => {
|
||||
expect(toastApi.success).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows a restart toast after manual-download updates because they still need confirmation', () => {
|
||||
const toastApi = createToastApi()
|
||||
toastApi.info.mockReturnValue('available-toast')
|
||||
const updaterApi = createUpdaterApi()
|
||||
const storeApi = createStoreApi()
|
||||
const controller = createUpdateToastController({ toastApi, updaterApi, storeApi })
|
||||
|
||||
controller.handleStatus({
|
||||
state: 'available',
|
||||
version: '1.2.3',
|
||||
manualDownloadUrl: 'https://example.com/download/1.2.3'
|
||||
})
|
||||
const infoOptions = getInfoOptions(toastApi)
|
||||
;(infoOptions.action as { onClick: () => void }).onClick()
|
||||
controller.handleStatus({ state: 'downloaded', version: '1.2.3' })
|
||||
|
||||
expect(updaterApi.download).toHaveBeenCalledTimes(1)
|
||||
expect(updaterApi.quitAndInstall).not.toHaveBeenCalled()
|
||||
expect(toastApi.success).toHaveBeenCalledWith('Version 1.2.3 is ready to install.', {
|
||||
description: expect.any(Object),
|
||||
duration: Infinity,
|
||||
action: expect.objectContaining({ label: 'Restart Now' })
|
||||
})
|
||||
})
|
||||
|
||||
it('clears stale one-click restart intent after a later check error', () => {
|
||||
const toastApi = createToastApi()
|
||||
toastApi.info.mockReturnValue('available-toast')
|
||||
|
||||
@@ -108,13 +108,7 @@ export function createUpdateToastController(deps?: {
|
||||
action: {
|
||||
label: 'Update',
|
||||
onClick: () => {
|
||||
// Why: manual-download builds still need the follow-up install
|
||||
// step, but auto-download builds should preserve the previous
|
||||
// one-click toast behavior and restart as soon as the payload
|
||||
// is ready.
|
||||
if (!status.manualDownloadUrl) {
|
||||
autoRestartAfterDownload = true
|
||||
}
|
||||
autoRestartAfterDownload = true
|
||||
void updaterApi.download()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,6 @@ export type UpdateStatus =
|
||||
state: 'available'
|
||||
version: string
|
||||
releaseUrl?: string
|
||||
manualDownloadUrl?: string
|
||||
}
|
||||
| { state: 'not-available'; userInitiated?: boolean }
|
||||
| { state: 'downloading'; percent: number; version: string }
|
||||
|
||||
Reference in New Issue
Block a user