Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 5 additions & 2 deletions config/electron-builder.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,11 @@ module.exports = {
npmRebuild: true,
publish: {
provider: 'github',
owner: 'stablyai',
repo: devChannelRepo ?? 'orca',
// Why env overrides: a fork publishes into its own repo with the same config.
// They win over the dev-channel repo, and verify-dev-channel-packaging fails a
// dev-channel build that sets them by mistake.
owner: process.env.ORCA_PUBLISH_OWNER || 'stablyai',
repo: process.env.ORCA_PUBLISH_REPO || devChannelRepo || 'orca',
// Why draft on the main repo: `--publish always` otherwise creates a
// public GitHub release as soon as the first platform uploads, and
// /releases/latest serves a missing Windows exe. release-cut undrafts
Expand Down
13 changes: 12 additions & 1 deletion config/scripts/verify-dev-channel-packaging.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { createRequire } from 'node:module'
import { resolve } from 'node:path'
import { pathToFileURL } from 'node:url'

// Why the owner too: it is env-overridable so a fork can publish from the same config,
// and an override left set on a dev-channel job would upload into that fork's org.
const EXPECTED_OWNER = 'stablyai'

const CHANNEL_REPOS = {
hourly: 'orca-hourly',
daily: 'orca-daily',
Expand All @@ -36,6 +40,13 @@ export function collectDevChannelPackagingProblems({ channel, platform, config,
]
}

if (config.publish?.owner !== EXPECTED_OWNER) {
problems.push(
`publish.owner is "${config.publish?.owner}" but this ${channel} build must publish to "${EXPECTED_OWNER}/${expectedRepo}". ` +
'Unset ORCA_PUBLISH_OWNER for dev-channel builds.'
)
}

if (config.publish?.repo !== expectedRepo) {
problems.push(
`publish.repo is "${config.publish?.repo}" but this ${channel} build must publish to "${expectedRepo}". ` +
Expand Down Expand Up @@ -113,7 +124,7 @@ function main() {
process.exit(1)
}
console.log(
`Dev-channel packaging verified: ${channel} on ${platform} → stablyai/${CHANNEL_REPOS[channel]} @ ${config.extraMetadata?.version}`
`Dev-channel packaging verified: ${channel} on ${platform} → ${EXPECTED_OWNER}/${CHANNEL_REPOS[channel]} @ ${config.extraMetadata?.version}`
)
}

Expand Down
72 changes: 69 additions & 3 deletions config/scripts/verify-dev-channel-packaging.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,55 @@ describe('electron-builder dev-channel identity', () => {
expect(config.publish.releaseType).toBe('draft')
})

// A fork publishes from the same config into its own repository; the identity
// stays stablyai's whenever the overrides are unset.
it('takes the publish owner and repo from the environment, defaulting to stablyai/orca', () => {
const config = loadConfigWithEnv({
ORCA_PUBLISH_OWNER: 'SwapLabsInc',
ORCA_PUBLISH_REPO: 'orca',
ORCA_LOCAL_BUILD_VERSION: '1.4.197-swaplabs.202609241530'
})

expect(config.publish.owner).toBe('SwapLabsInc')
expect(config.publish.repo).toBe('orca')
expect(config.extraMetadata.version).toBe('1.4.197-swaplabs.202609241530')
expect(loadConfigWithEnv({}).publish.owner).toBe('stablyai')
expect(
loadConfigWithEnv({ ORCA_PUBLISH_OWNER: '', ORCA_PUBLISH_REPO: '' }).publish
).toMatchObject({
owner: 'stablyai',
repo: 'orca'
})
})

it('reports a dev-channel build whose publish owner was overridden', () => {
const config = loadConfigWithEnv({ ...WIN_ADHOC_ENV, ORCA_PUBLISH_OWNER: 'SwapLabsInc' })

expect(config.publish.owner).toBe('SwapLabsInc')
expect(
collectDevChannelPackagingProblems({
channel: 'adhoc',
platform: 'win32',
config,
env: WIN_ADHOC_ENV
})
).toEqual([expect.stringContaining('publish.owner is "SwapLabsInc"')])
})

it('reports a dev-channel build whose publish repo was overridden', () => {
const config = loadConfigWithEnv({ ...WIN_ADHOC_ENV, ORCA_PUBLISH_REPO: 'orca' })

expect(config.publish.repo).toBe('orca')
expect(
collectDevChannelPackagingProblems({
channel: 'adhoc',
platform: 'win32',
config,
env: WIN_ADHOC_ENV
})
).toEqual([expect.stringContaining('publish.repo is "orca"')])
})

// The whole point of the change: an unsigned build that advertised a
// publisherName would Authenticode-verify — and reject — every installer it
// ever downloaded, including its own way back to stable.
Expand Down Expand Up @@ -101,7 +150,7 @@ describe('electron-builder dev-channel identity', () => {

describe('collectDevChannelPackagingProblems', () => {
const goodWinConfig = {
publish: { repo: 'orca-adhoc', releaseType: 'prerelease' },
publish: { owner: 'stablyai', repo: 'orca-adhoc', releaseType: 'prerelease' },
extraMetadata: { version: '1.4.178-adhoc.20260819010203' },
win: { verifyUpdateCodeSignature: false }
}
Expand All @@ -120,11 +169,28 @@ describe('collectDevChannelPackagingProblems', () => {

// The failure this script exists for: a branch predating Windows dev builds
// resolves publish.repo to the main repo.
it('rejects a config whose publish owner is not stablyai', () => {
const problems = collectDevChannelPackagingProblems({
channel: 'adhoc',
platform: 'win32',
config: {
...goodWinConfig,
publish: { owner: 'SwapLabsInc', repo: 'orca-adhoc', releaseType: 'prerelease' }
},
env
})

expect(problems).toEqual([expect.stringContaining('must publish to "stablyai/orca-adhoc"')])
})

it('rejects a config that resolved the main repo', () => {
const problems = collectDevChannelPackagingProblems({
channel: 'adhoc',
platform: 'win32',
config: { ...goodWinConfig, publish: { repo: 'orca', releaseType: 'release' } },
config: {
...goodWinConfig,
publish: { owner: 'stablyai', repo: 'orca', releaseType: 'release' }
},
env
})

Expand Down Expand Up @@ -165,7 +231,7 @@ describe('collectDevChannelPackagingProblems', () => {
channel: 'adhoc',
platform: 'darwin',
config: {
publish: { repo: 'orca-adhoc', releaseType: 'prerelease' },
publish: { owner: 'stablyai', repo: 'orca-adhoc', releaseType: 'prerelease' },
extraMetadata: { version: '1.4.178-adhoc.20260819010203' },
win: { signtoolOptions: { publisherName: 'SignPath Foundation' } }
},
Expand Down
18 changes: 17 additions & 1 deletion electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import tailwindcss from '@tailwindcss/vite'
import { createBootstrapFatalExitBanner } from './config/build-plugins/bootstrap-fatal-exit-banner'
import { createPdfjsViewerAssetsPlugin } from './config/build-plugins/pdfjs-viewer-assets'
import { createPlainNodeEntryGuardPlugin } from './config/build-plugins/plain-node-entry-guard'
import { parseReleaseSources } from './src/shared/release-sources'
import packageJson from './package.json' with { type: 'json' }

const BUNDLED_MAIN_DEPENDENCIES = new Set([
Expand Down Expand Up @@ -59,6 +60,16 @@ const ORCA_DIAGNOSTICS_TOKEN_URL_LITERAL =
typeof orcaDiagnosticsTokenUrl === 'string' && orcaDiagnosticsTokenUrl.length > 0
? JSON.stringify(orcaDiagnosticsTokenUrl)
: 'null'
// Why a compile-time define, like the identity above: the registry says which
// repos a packaged app will ever update from, so a shell export must not be able
// to re-point it, and the renderer reads the same table. Parsed with the runtime's
// own parser so a malformed literal fails the build here rather than shipping an
// app that silently falls back to updating from upstream.
const orcaReleaseSources = process.env.ORCA_RELEASE_SOURCES
const ORCA_RELEASE_SOURCES_LITERAL =
typeof orcaReleaseSources === 'string' && orcaReleaseSources.trim().length > 0
? JSON.stringify(JSON.stringify(parseReleaseSources(orcaReleaseSources)))
: 'null'

function createStartupDiagnosticsBanner(chunkName: string): string {
return `
Expand Down Expand Up @@ -280,7 +291,8 @@ export const electronViteConfig: UserConfig = {
define: {
ORCA_BUILD_IDENTITY: ORCA_BUILD_IDENTITY_LITERAL,
ORCA_POSTHOG_WRITE_KEY: ORCA_POSTHOG_WRITE_KEY_LITERAL,
ORCA_DIAGNOSTICS_TOKEN_URL: ORCA_DIAGNOSTICS_TOKEN_URL_LITERAL
ORCA_DIAGNOSTICS_TOKEN_URL: ORCA_DIAGNOSTICS_TOKEN_URL_LITERAL,
ORCA_RELEASE_SOURCES: ORCA_RELEASE_SOURCES_LITERAL
},
// Why: @xterm/headless declares "exports": null in package.json, which
// prevents Vite's default resolver from finding the CJS entry. Point
Expand All @@ -302,6 +314,10 @@ export const electronViteConfig: UserConfig = {
}
},
renderer: {
// Why here too: `release-channel.ts` derives repos from the registry and the renderer imports it.
define: {
ORCA_RELEASE_SOURCES: ORCA_RELEASE_SOURCES_LITERAL
},
resolve: {
alias: {
'@renderer': resolve('src/renderer/src'),
Expand Down
3 changes: 2 additions & 1 deletion src/main/runtime/rpc/methods/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const STATUS_METHODS = [
...runtime.getStatus(),
...(pairedDeviceId ? { pairedDeviceId } : {}),
appVersion: snapshot.appVersion,
remoteUpdateSupport: snapshot.support
remoteUpdateSupport: snapshot.support,
...(snapshot.releaseSource ? { releaseSource: snapshot.releaseSource } : {})
}
}
})
Expand Down
20 changes: 20 additions & 0 deletions src/main/updater-changelog.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import {
FORK_RELEASE_SOURCES_LITERAL,
setReleaseSourcesLiteralForTest
} from '../shared/release-sources.fixture'

const fetchMock = vi.fn()

Expand Down Expand Up @@ -210,6 +214,22 @@ describe('fetchChangelog', () => {
expect(result).toBeNull()
})

it('skips the changelog for a build from another release source without fetching', async () => {
setReleaseSourcesLiteralForTest(FORK_RELEASE_SOURCES_LITERAL)
try {
vi.resetModules()
const { fetchChangelog: forkFetchChangelog } = await import('./updater-changelog')

expect(
await forkFetchChangelog('1.4.197-swaplabs.202609241530', '1.4.197-swaplabs.202609241400')
).toBeNull()
expect(fetchMock).not.toHaveBeenCalled()
} finally {
setReleaseSourcesLiteralForTest(null)
vi.resetModules()
}
})

it('returns null on non-ok HTTP response', async () => {
fetchMock.mockResolvedValue({ ok: false })

Expand Down
6 changes: 6 additions & 0 deletions src/main/updater-changelog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { net } from 'electron'
import type { ChangelogData } from '../shared/update-status-types'
import { PRIMARY_RELEASE_SOURCE, getVersionReleaseSource } from '../shared/release-sources'
import { compareVersions } from './updater-fallback'

type ChangelogEntry = {
Expand Down Expand Up @@ -42,6 +43,11 @@ export async function fetchChangelog(
incomingVersion: string,
localVersion: string
): Promise<ChangelogData | null> {
// Why: the changelog describes the primary source's releases; a fork build's
// highlight would be upstream's, for a version that is not the one on offer.
if (getVersionReleaseSource(incomingVersion) !== PRIMARY_RELEASE_SOURCE.id) {
return null
}
const res = await net.fetch('https://onorca.dev/whats-new/changelog.json', {
signal: AbortSignal.timeout(5000)
})
Expand Down
3 changes: 2 additions & 1 deletion src/main/updater-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const isPrereleaseVersion = isPrereleaseAppVersion
export const isValidVersion = isValidAppVersion

export function statusesEqual(left: UpdateStatus, right: UpdateStatus): boolean {
if (left.source !== right.source) {
if (left.source !== right.source || left.releaseSource !== right.releaseSource) {
return false
}
switch (left.state) {
Expand Down Expand Up @@ -53,6 +53,7 @@ export function statusesEqual(left: UpdateStatus, right: UpdateStatus): boolean
left.retryable === right.retryable &&
left.userInitiated === right.userInitiated &&
left.activeNudgeId === right.activeNudgeId &&
left.manualInstallUrl === right.manualInstallUrl &&
// Recovery identity fences async actions, so same-valued recaptures must reach the renderer.
left.recovery === right.recovery
)
Expand Down
3 changes: 2 additions & 1 deletion src/main/updater-linux-package-recovery-actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ vi.mock('./updater-nudge', () => ({
}))
vi.mock('./updater-prerelease-feed', () => ({
fetchNewerReleaseTagsWithReadiness: vi.fn().mockResolvedValue({ tags: [], state: 'no-newer' }),
getReleaseDownloadUrl: vi.fn(() => 'https://example.invalid/download')
getReleaseDownloadUrl: vi.fn(() => 'https://example.invalid/download'),
verifyReleaseTagManifest: vi.fn().mockResolvedValue({ kind: 'ready' })
}))
vi.mock('./update-install-exit-watchdog', () => ({
armUpdateInstallExitWatchdog: vi.fn(),
Expand Down
13 changes: 13 additions & 0 deletions src/main/updater-main-window.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { BrowserWindow } from 'electron'
import { vi, type Mock } from 'vitest'

/** Test-only: the one surface the updater touches on its main window is `webContents.send`. */
export function createUpdaterMainWindowFake(): {
mainWindow: BrowserWindow
send: Mock<(channel: string, payload: unknown) => void>
} {
const send = vi.fn<(channel: string, payload: unknown) => void>()
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the updater reads nothing but webContents.send off its main window, and every suite asserts through this spy.
const mainWindow = { webContents: { send } } as unknown as BrowserWindow
return { mainWindow, send }
}
Loading
Loading