mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
fix(updater): pin stable fallback before downloading (#34076)
## ELI5 Orca can remember one release's ZIP filename and later follow “latest” into a newer release where that file does not exist. Resolve “latest” once, then keep the manifest and download on that concrete release. ## What Changed - Replace the default-channel moving-feed fallback with a validated stable tag resolved from GitHub's `/releases/latest` redirect. - Reuse the existing Electron `net.request` HEAD handling and platform manifest/asset readiness probes. `net.fetch` cancels manual redirects in real Electron, so it is not used for redirect discovery. - Return a retryable check failure when a ready concrete fallback cannot be resolved, and reject fallback results belonging to an expired check. - Update existing feed expectations and installer fixtures; cover stable fallback, Atom outages, unavailable fallback, late completions, redirect validation, and platform manifest selection. ## Why The normal path already pins a tag, but Atom outages and no-newer results still installed a `/releases/latest/download` provider. That provider retains relative filenames while GitHub's redirect can move between checking and downloading. Correct release manifests alone cannot prevent the mismatch. Credit to @brennanb2025 for the original tag-pinning fix in #1797, and @nwparker for the attempt-ownership guard in #23160, which this change extends across the fallback lookup. Also reviewed @sechan-netizen's #30952 and its review thread: its release-manifest validation is a complementary safeguard and remains separate because this race reproduces with correct manifests. No commits from that PR are copied here. This PR adopts @brennanb2025's audited #34075 lint fix (splitting three files that already exceeded main's line limits), with Brennan retained as a co-author. Independent byte-level audits preserve the moved runtime bodies and test groups; the follow-up replaces five test-only assertions with typed calls and emits identical JavaScript. The standalone older PR remains unmerged after repeated daemon-test CI/order sensitivity; the combined tree here passed all CI, including that exact daemon test file (16 tests) in run 40398604134, job 121839803430. ## Linked Issue Fixes #34034 Related reports: #15921 and #22621. The controlled race matches their URL signature and retry behavior; the reporter's original feed selection cannot be established without its logs. ## Visual Proof N/A — updater feed selection only; no presentation change. Verified the HTTP behavior using the production fallback resolver and electron-updater 6.8.10 with unmodified v1.4.240/v1.4.241 manifests and a controlled local release server: | Scenario | Result | | --- | --- | | Old moving provider: read 240 manifest, advance latest to 241, download | `v1.4.241/Orca-1.4.240-arm64-mac.zip`: 404 | | Retry the old download without a new check | Same 404 | | Fresh check | Correct 241 ZIP: 200 | | Fixed fallback: resolve 240 tag, advance latest to 241, download | Correct 240 ZIP under tag 240: 200 | No installer was executed and no app window was opened. ## Testing - [x] I manually tested these changes locally - [x] Automated tests added/updated `ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2`: all 26 checks pass on the combined branch, including formatting, lint, typechecks, affected tests, and ratchets. The earlier updater-only run also passed all 20 selected checks. The controller regression run against the original implementation produces five failures with passing controls. The fixed implementation passes. Resolver tests exercise macOS arm64, Windows x64, Linux x64/arm64 manifest selection, invalid redirects, missing assets, and recovery after network failure; these platform variants use mocked transport. A separate background Electron 43.8.1 smoke on macOS arm64 uses the production resolver and real Electron networking against GitHub, resolving the ready `v1.4.241` tag. The controlled before/after reproduction also exercises the production resolver and actual GenericProvider. Neither proof exercises native installation. All non-skipped GitHub CI checks pass for combined head `c04a6ca95604e064fb4f91adb1a57ea3dcf9adf0`: all five full unit shards, relay integration, Linux/Windows package checks, macOS updater regression tests, static analysis/typechecks, and the required aggregate check. Final independent review recommends merging that exact head as low risk with no code blockers. ## AI Disclosure ## Review Independent sub-agent review found no actionable issues and rated the updater change low risk; 57 relevant tests passed independently. The prerequisite received two independent refactor audits, with identical moved runtime/test bodies and a merge-preservation gate reporting zero unexplained deletions and zero unrelated files. The five typed mock changes produce identical JavaScript. Also self-reviewed the feed-selection paths, timeout ownership, transport cleanup, and release-channel filtering. The added lookup runs only on the existing fallback path, uses HEAD for redirect discovery, retains five-second request deadlines, and reuses manifest/asset probes. No new polling, subprocess, persistent cache, or per-workspace work is introduced. Native Windows/Linux networking and installer execution were not exercised locally. Review disposition for [the DMG-only manifest comment](https://github.com/stablyai/orca/pull/34076#discussion_r4382275117): an independent executable comparison of the original and fixed implementations returned the same `ready` Atom result for a DMG-only manifest; the old fallback already handed that manifest directly to MacUpdater, which cannot select its required ZIP. This is an existing release-integrity limitation, not introduced or worsened by tag pinning. It remains outside this race fix; a complete integrity change must validate the native files list and architecture selection rather than merely finding any ZIP-like name. ## Agent skill upstream boundary - [x] Not applicable; no upstream skill source or fixtures copied. ## Notes Desktop updater implementation is shared with headless serve. No IPC/RPC contract, remote version requirement, mobile client code, filesystem path, or workspace-kind assumption changes. Existing RC/perf selection remains in place. If fallback discovery also fails, checks use the existing retry/error flow instead of launching a moving feed. ## Checklist - [x] This PR is focused on consistent release selection - [x] Problem, behavior, and mechanism explained - [x] Visual proof N/A with network verification recorded - [x] Self-reviewed for correctness, security, and performance - [x] Cross-platform, remote, mobile, and folder-workspace impact considered - [x] Required changed-code checks pass Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
This commit is contained in:
co-authored by
Brennan Benson
parent
ffc2b3fba1
commit
82ab53ba61
@@ -0,0 +1,205 @@
|
||||
import {
|
||||
labelOnlyCreateRequests,
|
||||
renameCreatedWorktreeOnFirstWork
|
||||
} from '../worktree-create-first-work-test-harness'
|
||||
import { isAutoGeneratedCreatureBranchName } from '../../shared/branch-name-from-work'
|
||||
import type { CreateWorktreeResult } from '../../shared/worktree/create-types'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { describeCreatedWorktreeMock, gitExecFileAsyncMock } from './worktrees-test-module-mocks'
|
||||
import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness'
|
||||
import type { WorktreeMeta } from '../../shared/worktree/meta-types'
|
||||
|
||||
vi.mock('../text-generation/commit-message-text-generation', () => ({
|
||||
resolveTextGenerationParams: () => ({
|
||||
ok: true,
|
||||
params: { agentId: 'claude', model: 'fixture' }
|
||||
}),
|
||||
generateBranchNameFromContext: async () => ({ success: true, slug: 'fix-auth' })
|
||||
}))
|
||||
vi.mock('../text-generation/commit-message-agent-environment', () => ({
|
||||
prepareLocalCommitMessageAgentEnv: async () => ({ ok: true })
|
||||
}))
|
||||
|
||||
vi.mock('electron', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).electronModuleMock()
|
||||
)
|
||||
vi.mock('../git/worktree', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock()
|
||||
)
|
||||
vi.mock('../git/runner', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).gitRunnerModuleMock()
|
||||
)
|
||||
vi.mock('../git/repo', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).gitRepoModuleMock()
|
||||
)
|
||||
vi.mock('../git/git-username', async (importOriginal) => ({
|
||||
...(await importOriginal<Record<string, unknown>>()),
|
||||
resolveLocalGitUsername: (await import('./worktrees-test-module-mocks'))
|
||||
.resolveLocalGitUsernameMock
|
||||
}))
|
||||
vi.mock('../github/client', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).githubClientModuleMock()
|
||||
)
|
||||
vi.mock('../source-control/hosted-review', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).hostedReviewModuleMock()
|
||||
)
|
||||
vi.mock('./worktree-symlinks', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock()
|
||||
)
|
||||
vi.mock('../hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock())
|
||||
vi.mock('../setup-runner-script-text', async (importOriginal) =>
|
||||
(await import('./worktrees-test-module-mocks')).setupRunnerScriptTextModuleMock(
|
||||
await importOriginal<Record<string, unknown>>()
|
||||
)
|
||||
)
|
||||
vi.mock('../worktree-runner-script', async (importOriginal) =>
|
||||
(await import('./worktrees-test-module-mocks')).worktreeRunnerScriptModuleMock(
|
||||
await importOriginal<Record<string, unknown>>()
|
||||
)
|
||||
)
|
||||
vi.mock('../effective-hook-config', async (importOriginal) =>
|
||||
(await import('./worktrees-test-module-mocks')).effectiveHookConfigModuleMock(
|
||||
await importOriginal<Record<string, unknown>>()
|
||||
)
|
||||
)
|
||||
vi.mock('../setup-hook-env-vars', async (importOriginal) =>
|
||||
(await import('./worktrees-test-module-mocks')).setupHookEnvVarsModuleMock(
|
||||
await importOriginal<Record<string, unknown>>()
|
||||
)
|
||||
)
|
||||
vi.mock('./worktree-logic', async (importOriginal) =>
|
||||
(await import('./worktrees-test-module-mocks')).worktreeLogicModuleMock(
|
||||
await importOriginal<Record<string, unknown>>()
|
||||
)
|
||||
)
|
||||
vi.mock('../terminal-history-deletion', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).terminalHistoryDeletionModuleMock()
|
||||
)
|
||||
vi.mock('../ports/advertised-url-watcher', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).advertisedUrlWatcherModuleMock()
|
||||
)
|
||||
vi.mock('../workspace-cleanup-scan-snapshot', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).workspaceCleanupScanSnapshotModuleMock()
|
||||
)
|
||||
vi.mock('../workspace-space-analysis-snapshot', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).workspaceSpaceAnalysisSnapshotModuleMock()
|
||||
)
|
||||
vi.mock('../workspace-cleanup-removal-snapshot-prune', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).workspaceCleanupRemovalSnapshotPruneModuleMock()
|
||||
)
|
||||
vi.mock('../runtime/worktree-teardown', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).worktreeTeardownModuleMock()
|
||||
)
|
||||
vi.mock('./pty/provider/registry', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).ptyRegistryModuleMock()
|
||||
)
|
||||
vi.mock('./pty/provider/state-cleanup', async () =>
|
||||
(await import('./worktrees-test-module-mocks')).ptyStateCleanupModuleMock()
|
||||
)
|
||||
|
||||
describe('desktop label-only creation through first work', () => {
|
||||
function expectCreatedWorktree(result: unknown): asserts result is CreateWorktreeResult {
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
worktree: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
repoId: 'repo-1',
|
||||
path: expect.any(String),
|
||||
head: expect.any(String),
|
||||
branch: expect.stringMatching(/^refs\/heads\//),
|
||||
isBare: false,
|
||||
isMainWorktree: false,
|
||||
displayName: expect.any(String),
|
||||
displayNameMode: expect.stringMatching(/^(fixed|automatic)$/),
|
||||
comment: '',
|
||||
linkedIssue: null,
|
||||
linkedPR: null,
|
||||
linkedLinearIssue: null,
|
||||
isArchived: false,
|
||||
isUnread: false,
|
||||
isPinned: false,
|
||||
sortOrder: expect.any(Number),
|
||||
lastActivityAt: expect.any(Number)
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
let savedMeta: Partial<WorktreeMeta>
|
||||
beforeEach(() => {
|
||||
setupWorktreeHandlers()
|
||||
savedMeta = {}
|
||||
store.getSettings.mockReturnValue({
|
||||
branchPrefix: 'none',
|
||||
nestWorkspaces: false,
|
||||
refreshLocalBaseRefOnWorktreeCreate: false,
|
||||
workspaceDir: '/workspace',
|
||||
autoRenameBranchFromWork: true
|
||||
})
|
||||
store.setWorktreeMeta.mockImplementation((_target, updates) => {
|
||||
savedMeta = { ...savedMeta, ...updates }
|
||||
return savedMeta
|
||||
})
|
||||
describeCreatedWorktreeMock.mockImplementation(async (_repoPath, path, branch) => ({
|
||||
path,
|
||||
branch: `refs/heads/${branch}`,
|
||||
head: 'abc123',
|
||||
isBare: false,
|
||||
isMainWorktree: false
|
||||
}))
|
||||
})
|
||||
|
||||
it.each(labelOnlyCreateRequests)(
|
||||
'creates and renames a creature branch for $name while projecting its label',
|
||||
async (request) => {
|
||||
const result = await handlers['worktrees:create'](null, {
|
||||
repoId: 'repo-1',
|
||||
...request
|
||||
})
|
||||
expectCreatedWorktree(result)
|
||||
const { worktree } = result
|
||||
const branch = worktree.branch.replace(/^refs\/heads\//, '')
|
||||
expect(isAutoGeneratedCreatureBranchName(branch)).toBe(true)
|
||||
expect(worktree.displayName).toBe(request.name)
|
||||
expect(worktree.displayNameMode).toBe(request.nameWasGenerated ? 'automatic' : 'fixed')
|
||||
const renamed = await renameCreatedWorktreeOnFirstWork(
|
||||
worktree,
|
||||
savedMeta,
|
||||
gitExecFileAsyncMock
|
||||
)
|
||||
expect(renamed).toMatchObject({
|
||||
branch: 'refs/heads/fix-auth',
|
||||
displayName: request.nameWasGenerated ? 'Fix auth' : request.name,
|
||||
displayNameMode: 'fixed'
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
it.each([
|
||||
{ branchNameOverride: 'feature/exact', enabled: true, branch: 'feature/exact' },
|
||||
{ branchNameOverride: undefined, enabled: false, branch: 'typed-label' }
|
||||
])(
|
||||
'preserves branch choice $branch (automatic=$enabled)',
|
||||
async ({ branchNameOverride, enabled, branch }) => {
|
||||
store.getSettings.mockReturnValue({
|
||||
branchPrefix: 'none',
|
||||
nestWorkspaces: false,
|
||||
refreshLocalBaseRefOnWorktreeCreate: false,
|
||||
workspaceDir: '/workspace',
|
||||
autoRenameBranchFromWork: enabled
|
||||
})
|
||||
const result = await handlers['worktrees:create'](null, {
|
||||
repoId: 'repo-1',
|
||||
name: 'typed-label',
|
||||
branchNameOverride
|
||||
})
|
||||
expectCreatedWorktree(result)
|
||||
const { worktree } = result
|
||||
expect(worktree).toMatchObject({
|
||||
branch: `refs/heads/${branch}`,
|
||||
displayName: 'typed-label',
|
||||
displayNameMode: 'fixed'
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -1,16 +1,9 @@
|
||||
import {
|
||||
labelOnlyCreateRequests,
|
||||
renameCreatedWorktreeOnFirstWork
|
||||
} from '../worktree-create-first-work-test-harness'
|
||||
import { isAutoGeneratedCreatureBranchName } from '../../shared/branch-name-from-work'
|
||||
import type { CreateWorktreeResult } from '../../shared/worktree/create-types'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { REVIEW_HEAD_FETCH_TIMEOUT_MS } from '../../shared/review-head-tracking-ref'
|
||||
import {
|
||||
handleMock,
|
||||
removeHandlerMock,
|
||||
listWorktreesMock,
|
||||
describeCreatedWorktreeMock,
|
||||
getPullRequestPushTargetMock,
|
||||
gitExecFileAsyncMock
|
||||
} from './worktrees-test-module-mocks'
|
||||
@@ -794,110 +787,3 @@ describe('registerWorktreeHandlers', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('desktop label-only creation through first work', () => {
|
||||
function expectCreatedWorktree(result: unknown): asserts result is CreateWorktreeResult {
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
worktree: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
repoId: 'repo-1',
|
||||
path: expect.any(String),
|
||||
head: expect.any(String),
|
||||
branch: expect.stringMatching(/^refs\/heads\//),
|
||||
isBare: false,
|
||||
isMainWorktree: false,
|
||||
displayName: expect.any(String),
|
||||
displayNameMode: expect.stringMatching(/^(fixed|automatic)$/),
|
||||
comment: '',
|
||||
linkedIssue: null,
|
||||
linkedPR: null,
|
||||
linkedLinearIssue: null,
|
||||
isArchived: false,
|
||||
isUnread: false,
|
||||
isPinned: false,
|
||||
sortOrder: expect.any(Number),
|
||||
lastActivityAt: expect.any(Number)
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
let savedMeta: Partial<WorktreeMeta>
|
||||
beforeEach(() => {
|
||||
setupWorktreeHandlers()
|
||||
savedMeta = {}
|
||||
store.getSettings.mockReturnValue({
|
||||
branchPrefix: 'none',
|
||||
nestWorkspaces: false,
|
||||
refreshLocalBaseRefOnWorktreeCreate: false,
|
||||
workspaceDir: '/workspace',
|
||||
autoRenameBranchFromWork: true
|
||||
})
|
||||
store.setWorktreeMeta.mockImplementation((_target, updates) => {
|
||||
savedMeta = { ...savedMeta, ...updates }
|
||||
return savedMeta
|
||||
})
|
||||
describeCreatedWorktreeMock.mockImplementation(async (_repoPath, path, branch) => ({
|
||||
path,
|
||||
branch: `refs/heads/${branch}`,
|
||||
head: 'abc123',
|
||||
isBare: false,
|
||||
isMainWorktree: false
|
||||
}))
|
||||
})
|
||||
|
||||
it.each(labelOnlyCreateRequests)(
|
||||
'creates and renames a creature branch for $name while projecting its label',
|
||||
async (request) => {
|
||||
const result = await handlers['worktrees:create'](null, {
|
||||
repoId: 'repo-1',
|
||||
...request
|
||||
})
|
||||
expectCreatedWorktree(result)
|
||||
const { worktree } = result
|
||||
const branch = worktree.branch.replace(/^refs\/heads\//, '')
|
||||
expect(isAutoGeneratedCreatureBranchName(branch)).toBe(true)
|
||||
expect(worktree.displayName).toBe(request.name)
|
||||
expect(worktree.displayNameMode).toBe(request.nameWasGenerated ? 'automatic' : 'fixed')
|
||||
const renamed = await renameCreatedWorktreeOnFirstWork(
|
||||
worktree,
|
||||
savedMeta,
|
||||
gitExecFileAsyncMock
|
||||
)
|
||||
expect(renamed).toMatchObject({
|
||||
branch: 'refs/heads/fix-auth',
|
||||
displayName: request.nameWasGenerated ? 'Fix auth' : request.name,
|
||||
displayNameMode: 'fixed'
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
it.each([
|
||||
{ branchNameOverride: 'feature/exact', enabled: true, branch: 'feature/exact' },
|
||||
{ branchNameOverride: undefined, enabled: false, branch: 'typed-label' }
|
||||
])(
|
||||
'preserves branch choice $branch (automatic=$enabled)',
|
||||
async ({ branchNameOverride, enabled, branch }) => {
|
||||
store.getSettings.mockReturnValue({
|
||||
branchPrefix: 'none',
|
||||
nestWorkspaces: false,
|
||||
refreshLocalBaseRefOnWorktreeCreate: false,
|
||||
workspaceDir: '/workspace',
|
||||
autoRenameBranchFromWork: enabled
|
||||
})
|
||||
const result = await handlers['worktrees:create'](null, {
|
||||
repoId: 'repo-1',
|
||||
name: 'typed-label',
|
||||
branchNameOverride
|
||||
})
|
||||
expectCreatedWorktree(result)
|
||||
const { worktree } = result
|
||||
expect(worktree).toMatchObject({
|
||||
branch: `refs/heads/${branch}`,
|
||||
displayName: 'typed-label',
|
||||
displayNameMode: 'fixed'
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,404 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { resolve } from 'node:path'
|
||||
import type { Store } from '../persistence'
|
||||
import type { WorktreeMeta } from '../../shared/worktree/meta-types'
|
||||
import type { HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity'
|
||||
import type { Repo } from '../../shared/repo-types'
|
||||
import type { RuntimeManagedWorktreeCreateArgs } from './runtime-managed-worktree-create-types'
|
||||
import { resolveGitAdmissionTier } from '../git/command-runner/git-operation-executor'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
git: vi.fn(),
|
||||
rearm: vi.fn(),
|
||||
routing: vi.fn<() => { wslDistro?: string }>(),
|
||||
defaultBase: vi.fn(),
|
||||
hasBase: vi.fn(),
|
||||
branchName: vi.fn(),
|
||||
canCheckout: vi.fn(),
|
||||
pathExists: vi.fn(),
|
||||
branchConflict: vi.fn(),
|
||||
githubPr: vi.fn(),
|
||||
consume: vi.fn(),
|
||||
add: vi.fn(),
|
||||
addSparse: vi.fn(),
|
||||
pushTarget: vi.fn(),
|
||||
listing: vi.fn(),
|
||||
remoteBase: vi.fn(),
|
||||
hasRemoteRef: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
fetch: vi.fn(),
|
||||
resolveShared: vi.fn<() => Promise<string[]>>(),
|
||||
resolveInclude: vi.fn<() => Promise<string[]>>(),
|
||||
copyPaths: vi.fn<() => Promise<string[]>>(),
|
||||
effectiveHooks: vi.fn(),
|
||||
created: {
|
||||
path: '',
|
||||
head: 'abc123',
|
||||
branch: 'app',
|
||||
isBare: false,
|
||||
isMainWorktree: false
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('../text-generation/commit-message-text-generation', () => ({
|
||||
resolveTextGenerationParams: () => ({
|
||||
ok: true,
|
||||
params: { agentId: 'claude', model: 'fixture' }
|
||||
}),
|
||||
generateBranchNameFromContext: async () => ({ success: true, slug: 'fix-auth' })
|
||||
}))
|
||||
vi.mock('../text-generation/commit-message-agent-environment', () => ({
|
||||
prepareLocalCommitMessageAgentEnv: async () => ({ ok: true })
|
||||
}))
|
||||
|
||||
vi.mock('../git/runner', () => ({ gitExecFileAsync: mocks.git }))
|
||||
vi.mock('../project-runtime-git-options', () => ({
|
||||
getLocalProjectGitExecOptions: () => ({ cwd: '/repo', ...mocks.routing() }),
|
||||
getLocalProjectWorktreeGitOptions: mocks.routing,
|
||||
getWorktreeMirrorDistro: () => undefined
|
||||
}))
|
||||
vi.mock('../git/repo', () => ({
|
||||
getBaseRefDefault: mocks.defaultBase,
|
||||
resolveDefaultBaseRefWithLocalGit: mocks.defaultBase,
|
||||
getBranchConflictKind: mocks.branchConflict
|
||||
}))
|
||||
vi.mock('../git/git-username', () => ({ resolveLocalGitUsername: async () => '' }))
|
||||
vi.mock('../hooks', () => ({ getEffectiveHooks: mocks.effectiveHooks }))
|
||||
vi.mock('../git/worktree-base-ref-probe', () => ({ hasLocalWorktreeBaseRef: mocks.hasBase }))
|
||||
vi.mock('./runtime-worktree-create-git', () => ({
|
||||
resolveCreateBranchName: mocks.branchName,
|
||||
canCheckoutExistingLocalBranch: mocks.canCheckout,
|
||||
getLocalGitHubPrForBranch: mocks.githubPr,
|
||||
getSelectedHostedReviewForBranch: vi.fn()
|
||||
}))
|
||||
vi.mock('./runtime-worktree-filesystem', () => ({ runtimePathExists: mocks.pathExists }))
|
||||
vi.mock('../worktree-create-preparation', () => ({ consumePreparedWorktreeCreate: mocks.consume }))
|
||||
vi.mock('../git/worktree', () => ({ addWorktree: mocks.add, addSparseWorktree: mocks.addSparse }))
|
||||
vi.mock('../ipc/worktree-remote', () => ({ configureCreatedWorktreePushTarget: mocks.pushTarget }))
|
||||
vi.mock('../ipc/created-worktree-reconciliation', () => ({ resolveCreatedWorktree: mocks.listing }))
|
||||
vi.mock('../worktree-name-retirement', () => ({
|
||||
failedWorktreeCreationNeedsRetirement: vi.fn(),
|
||||
retireGeneratedWorktreeName: vi.fn()
|
||||
}))
|
||||
vi.mock('../git/worktree-shared-directories', () => ({
|
||||
resolveWorktreeSharedDirectories: mocks.resolveShared
|
||||
}))
|
||||
vi.mock('../git/worktree-include-file', () => ({
|
||||
resolveWorktreeIncludePaths: mocks.resolveInclude
|
||||
}))
|
||||
vi.mock('../ipc/worktree-symlinks', () => ({
|
||||
createWorktreeCopiedPaths: mocks.copyPaths,
|
||||
createWorktreeLinkedPaths: vi.fn(),
|
||||
createWorktreeSharedPaths: vi.fn()
|
||||
}))
|
||||
|
||||
import { createRuntimeLocalManagedWorktree } from './runtime-local-worktree-create'
|
||||
import type { PreparationRearmHolder } from '../worktree-create-preparation'
|
||||
import {
|
||||
createWorktreeCreateTimingRecorder,
|
||||
type WorktreeCreateTimingRecorder
|
||||
} from '../worktree-create-timing'
|
||||
import type { SparsePreset } from '../../shared/worktree/create-types'
|
||||
|
||||
const worktreePath = resolve('/worktrees', 'app')
|
||||
|
||||
const pickedBranch = {
|
||||
baseBranch: 'origin/main',
|
||||
branchNameOverride: 'main',
|
||||
branchIntent: 'open-existing'
|
||||
} as const
|
||||
|
||||
const writtenMeta: Partial<WorktreeMeta>[] = []
|
||||
const WEB_PRESET: SparsePreset = {
|
||||
id: 'preset-web',
|
||||
repoId: 'repo-1',
|
||||
name: 'web',
|
||||
directories: ['apps/web', 'packages/ui'],
|
||||
createdAt: 0,
|
||||
updatedAt: 0
|
||||
}
|
||||
const readSparsePresets = vi.fn<(repoId: string) => SparsePreset[]>()
|
||||
|
||||
function createWorktree(
|
||||
request: Partial<RuntimeManagedWorktreeCreateArgs> = {},
|
||||
rearm: PreparationRearmHolder = { fire: () => {} },
|
||||
timing: WorktreeCreateTimingRecorder = createWorktreeCreateTimingRecorder(),
|
||||
repoOverrides: Partial<Repo> = {},
|
||||
autoRenameBranchFromWork = false
|
||||
) {
|
||||
const store = {
|
||||
getSettings: () => ({
|
||||
workspaceDir: '/worktrees',
|
||||
nestWorkspaces: false,
|
||||
refreshLocalBaseRefOnWorktreeCreate: false,
|
||||
branchPrefix: '',
|
||||
autoRenameBranchFromWork
|
||||
}),
|
||||
setWorktreeMeta: (_target: HostWorktreeTarget, updates: Partial<WorktreeMeta>) => {
|
||||
writtenMeta.push(updates)
|
||||
return updates
|
||||
},
|
||||
getSparsePresets: (repoId: string): SparsePreset[] => readSparsePresets(repoId)
|
||||
}
|
||||
return createRuntimeLocalManagedWorktree({
|
||||
request: { repoSelector: 'repo-1', name: 'app', baseBranch: 'main', ...request },
|
||||
repo: {
|
||||
id: 'repo-1',
|
||||
path: '/repo',
|
||||
displayName: 'Repo',
|
||||
badgeColor: '#000000',
|
||||
addedAt: 0,
|
||||
...repoOverrides
|
||||
},
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: All store methods reached by this isolated create path are supplied above.
|
||||
store: store as Store,
|
||||
createdWithAgent: undefined,
|
||||
resolveRemoteTrackingBase: mocks.remoteBase,
|
||||
hasRemoteTrackingRef: mocks.hasRemoteRef,
|
||||
// vi.fn marks returned promises handled; a fresh promise exposes unawaited fetch rejection.
|
||||
refreshRemoteTrackingBase: async (...refreshArgs) => await mocks.refresh(...refreshArgs),
|
||||
fetchRemote: async (...fetchArgs) => await mocks.fetch(...fetchArgs),
|
||||
onWorktreeMetadataPersisted: () => undefined,
|
||||
rearm,
|
||||
timing
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks()
|
||||
writtenMeta.length = 0
|
||||
mocks.created.branch = 'app'
|
||||
mocks.git.mockResolvedValue({ stdout: '', stderr: '' })
|
||||
mocks.created.path = worktreePath
|
||||
mocks.routing.mockReturnValue({})
|
||||
mocks.defaultBase.mockImplementation(async () => {
|
||||
expect(resolveGitAdmissionTier()).toBe('interactive')
|
||||
return 'main'
|
||||
})
|
||||
mocks.hasBase.mockResolvedValue(true)
|
||||
mocks.branchName.mockResolvedValue('app')
|
||||
mocks.canCheckout.mockResolvedValue(false)
|
||||
mocks.pathExists.mockResolvedValue(false)
|
||||
mocks.branchConflict.mockResolvedValue(null)
|
||||
mocks.githubPr.mockResolvedValue(null)
|
||||
mocks.consume.mockResolvedValue({ status: 'hit', result: {}, rearm: mocks.rearm })
|
||||
mocks.add.mockResolvedValue({})
|
||||
mocks.addSparse.mockResolvedValue({})
|
||||
mocks.listing.mockImplementation(async () => {
|
||||
expect(resolveGitAdmissionTier()).toBe('interactive')
|
||||
return { created: mocks.created }
|
||||
})
|
||||
mocks.remoteBase.mockImplementation(async () => {
|
||||
expect(resolveGitAdmissionTier()).toBe('interactive')
|
||||
return null
|
||||
})
|
||||
mocks.hasRemoteRef.mockResolvedValue(true)
|
||||
mocks.refresh.mockResolvedValue({ ok: true })
|
||||
mocks.fetch.mockResolvedValue(undefined)
|
||||
mocks.resolveShared.mockResolvedValue([])
|
||||
mocks.resolveInclude.mockResolvedValue(['.env'])
|
||||
mocks.copyPaths.mockResolvedValue([])
|
||||
mocks.effectiveHooks.mockReturnValue(null)
|
||||
readSparsePresets.mockReturnValue([WEB_PRESET])
|
||||
})
|
||||
|
||||
describe('runtime create PR conflict probe', () => {
|
||||
const remoteTrackingBase = {
|
||||
remote: 'origin',
|
||||
branch: 'main',
|
||||
base: 'origin/main',
|
||||
ref: 'refs/remotes/origin/main'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.branchName.mockImplementation(async (_path, override, name: string) => override ?? name)
|
||||
})
|
||||
|
||||
it.each([1, 10])(
|
||||
'keeps the selected name and source through %i occupied paths, without PR eligibility',
|
||||
async (occupied) => {
|
||||
const options = { wslDistro: 'Ubuntu' }
|
||||
mocks.routing.mockReturnValue(options)
|
||||
mocks.remoteBase.mockResolvedValue(remoteTrackingBase)
|
||||
mocks.githubPr.mockResolvedValue({ number: 42 })
|
||||
let pathChecks = 0
|
||||
mocks.pathExists.mockImplementation(async () => pathChecks++ < occupied)
|
||||
|
||||
await createWorktree({ ...pickedBranch, sparseCheckout: { directories: ['src'] } })
|
||||
|
||||
expect(mocks.remoteBase.mock.calls).toEqual([['/repo', 'origin/main', options]])
|
||||
expect(mocks.branchName).toHaveBeenCalledOnce()
|
||||
expect(mocks.branchConflict.mock.calls).toEqual([['/repo', 'main', 'origin/main', options]])
|
||||
expect(mocks.pathExists).toHaveBeenCalledTimes(occupied + 1)
|
||||
expect(mocks.githubPr).not.toHaveBeenCalled()
|
||||
expect(mocks.consume).not.toHaveBeenCalled()
|
||||
expect(mocks.addSparse).toHaveBeenCalledExactlyOnceWith(
|
||||
'/repo',
|
||||
resolve('/worktrees', `app-${occupied + 1}`),
|
||||
'main',
|
||||
['src'],
|
||||
remoteTrackingBase.base,
|
||||
false,
|
||||
expect.objectContaining({ remoteTrackingBase, ...options })
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
it.each([true, false])(
|
||||
'keeps local eligibility with picker intent (reusable: %s)',
|
||||
async (reusable) => {
|
||||
mocks.branchConflict.mockImplementation(async (_path, branch: string) =>
|
||||
branch === 'main' ? 'local' : null
|
||||
)
|
||||
mocks.canCheckout.mockImplementation(
|
||||
async (_path, branch: string) => reusable && branch === 'main'
|
||||
)
|
||||
mocks.pathExists.mockImplementation(async (path) => path === worktreePath)
|
||||
mocks.consume.mockResolvedValue({ status: 'miss', reason: 'not_prepared' })
|
||||
|
||||
await createWorktree(pickedBranch)
|
||||
|
||||
expect(mocks.add).toHaveBeenCalledWith(
|
||||
'/repo',
|
||||
resolve('/worktrees', 'app-2'),
|
||||
reusable ? 'main' : 'main-2',
|
||||
'origin/main',
|
||||
false,
|
||||
false,
|
||||
expect.objectContaining(reusable ? { checkoutExistingBranch: true } : {})
|
||||
)
|
||||
expect(mocks.githubPr.mock.calls.map(([, branch]) => branch)).toEqual(
|
||||
reusable ? [] : ['main-2']
|
||||
)
|
||||
expect(mocks.add.mock.calls[0][6].checkoutExistingBranch ?? false).toBe(reusable)
|
||||
}
|
||||
)
|
||||
|
||||
it('keeps unflagged legacy, mobile New branch and Advanced collisions on baseline allocation', async () => {
|
||||
mocks.consume.mockResolvedValue({ status: 'miss', reason: 'not_prepared' })
|
||||
mocks.branchName.mockImplementation(async (_path, override, name: string) => override ?? name)
|
||||
mocks.branchConflict.mockImplementation(async (_path, branch: string) =>
|
||||
branch === 'feature/test' ? 'remote' : null
|
||||
)
|
||||
|
||||
await createWorktree({ branchNameOverride: 'feature/test', baseBranch: 'origin/main' })
|
||||
|
||||
expect(mocks.add.mock.calls[0][2]).toBe('feature/test-2')
|
||||
})
|
||||
|
||||
it('runs the first name PR lookup while the base fetch is still in flight', async () => {
|
||||
mocks.remoteBase.mockResolvedValue(remoteTrackingBase)
|
||||
let finishFetch!: () => void
|
||||
mocks.refresh.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
finishFetch = () => resolve({ ok: true })
|
||||
})
|
||||
)
|
||||
let fetchPendingAtLookup = false
|
||||
mocks.githubPr.mockImplementation(async () => {
|
||||
fetchPendingAtLookup = mocks.refresh.mock.calls.length === 1
|
||||
finishFetch?.()
|
||||
return null
|
||||
})
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(fetchPendingAtLookup).toBe(true)
|
||||
expect(mocks.githubPr).toHaveBeenCalledWith('/repo', 'app', {})
|
||||
expect(mocks.consume).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
branch: 'app',
|
||||
options: expect.objectContaining({ remoteTrackingBase })
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('suffixes past a PR on the first name', async () => {
|
||||
mocks.githubPr.mockResolvedValueOnce({ number: 7, state: 'closed' }).mockResolvedValue(null)
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(mocks.githubPr.mock.calls.map(([, branch]) => branch)).toEqual(['app', 'app-2'])
|
||||
expect(mocks.consume).toHaveBeenCalledWith(expect.objectContaining({ branch: 'app-2' }))
|
||||
})
|
||||
|
||||
it.each([undefined, 'Ubuntu'])(
|
||||
'probes the next name for a PR once the first name collides, routed for %s',
|
||||
async (wslDistro) => {
|
||||
const routing = wslDistro ? { wslDistro } : {}
|
||||
mocks.routing.mockReturnValue(routing)
|
||||
mocks.branchConflict.mockResolvedValueOnce('local').mockResolvedValue(null)
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(mocks.githubPr).toHaveBeenCalledOnce()
|
||||
expect(mocks.githubPr).toHaveBeenCalledWith('/repo', 'app-2', routing)
|
||||
}
|
||||
)
|
||||
|
||||
it('skips a later name that already has a PR', async () => {
|
||||
mocks.branchConflict.mockResolvedValueOnce('local').mockResolvedValue(null)
|
||||
mocks.githubPr.mockResolvedValueOnce({ number: 7, state: 'closed' }).mockResolvedValue(null)
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(mocks.githubPr.mock.calls.map(([, branch]) => branch)).toEqual(['app-2', 'app-3'])
|
||||
expect(mocks.consume).toHaveBeenCalledWith(expect.objectContaining({ branch: 'app-3' }))
|
||||
})
|
||||
|
||||
it('reports the naming failure when the started base fetch also fails', async () => {
|
||||
mocks.remoteBase.mockResolvedValue(remoteTrackingBase)
|
||||
mocks.refresh.mockRejectedValue(new Error('offline'))
|
||||
mocks.branchConflict.mockResolvedValue('local')
|
||||
const unhandled = vi.fn()
|
||||
process.on('unhandledRejection', unhandled)
|
||||
try {
|
||||
await expect(createWorktree()).rejects.toThrow('Branch "app-')
|
||||
await new Promise((resolve) => setImmediate(resolve))
|
||||
expect(mocks.refresh).toHaveBeenCalledOnce()
|
||||
expect(unhandled).not.toHaveBeenCalled()
|
||||
expect(mocks.consume).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
process.off('unhandledRejection', unhandled)
|
||||
}
|
||||
})
|
||||
|
||||
it('runs the first name PR lookup while the origin fetch is still in flight', async () => {
|
||||
mocks.hasBase.mockResolvedValue(false)
|
||||
let finishFetch!: () => void
|
||||
mocks.fetch.mockReturnValue(
|
||||
new Promise<void>((resolve) => {
|
||||
finishFetch = resolve
|
||||
})
|
||||
)
|
||||
let fetchPendingAtLookup = false
|
||||
mocks.githubPr.mockImplementation(async () => {
|
||||
fetchPendingAtLookup = mocks.fetch.mock.calls.length === 1
|
||||
finishFetch?.()
|
||||
return null
|
||||
})
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(fetchPendingAtLookup).toBe(true)
|
||||
expect(mocks.fetch).toHaveBeenCalledWith('/repo', 'origin', {})
|
||||
expect(mocks.consume).toHaveBeenCalledWith(expect.objectContaining({ branch: 'app' }))
|
||||
})
|
||||
|
||||
it('reports the naming failure when the started origin fetch also fails', async () => {
|
||||
mocks.hasBase.mockResolvedValue(false)
|
||||
mocks.fetch.mockRejectedValue(new Error('offline'))
|
||||
mocks.branchConflict.mockResolvedValue('local')
|
||||
const unhandled = vi.fn()
|
||||
process.on('unhandledRejection', unhandled)
|
||||
try {
|
||||
await expect(createWorktree()).rejects.toThrow('Branch "app-')
|
||||
await new Promise((resolve) => setImmediate(resolve))
|
||||
expect(mocks.fetch).toHaveBeenCalledOnce()
|
||||
expect(unhandled).not.toHaveBeenCalled()
|
||||
expect(mocks.consume).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
process.off('unhandledRejection', unhandled)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -518,207 +518,6 @@ describe('runtime create Git priority', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('runtime create PR conflict probe', () => {
|
||||
const remoteTrackingBase = {
|
||||
remote: 'origin',
|
||||
branch: 'main',
|
||||
base: 'origin/main',
|
||||
ref: 'refs/remotes/origin/main'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.branchName.mockImplementation(async (_path, override, name: string) => override ?? name)
|
||||
})
|
||||
|
||||
it.each([1, 10])(
|
||||
'keeps the selected name and source through %i occupied paths, without PR eligibility',
|
||||
async (occupied) => {
|
||||
const options = { wslDistro: 'Ubuntu' }
|
||||
mocks.routing.mockReturnValue(options)
|
||||
mocks.remoteBase.mockResolvedValue(remoteTrackingBase)
|
||||
mocks.githubPr.mockResolvedValue({ number: 42 })
|
||||
let pathChecks = 0
|
||||
mocks.pathExists.mockImplementation(async () => pathChecks++ < occupied)
|
||||
|
||||
await createWorktree({ ...pickedBranch, sparseCheckout: { directories: ['src'] } })
|
||||
|
||||
expect(mocks.remoteBase.mock.calls).toEqual([['/repo', 'origin/main', options]])
|
||||
expect(mocks.branchName).toHaveBeenCalledOnce()
|
||||
expect(mocks.branchConflict.mock.calls).toEqual([['/repo', 'main', 'origin/main', options]])
|
||||
expect(mocks.pathExists).toHaveBeenCalledTimes(occupied + 1)
|
||||
expect(mocks.githubPr).not.toHaveBeenCalled()
|
||||
expect(mocks.consume).not.toHaveBeenCalled()
|
||||
expect(mocks.addSparse).toHaveBeenCalledExactlyOnceWith(
|
||||
'/repo',
|
||||
resolve('/worktrees', `app-${occupied + 1}`),
|
||||
'main',
|
||||
['src'],
|
||||
remoteTrackingBase.base,
|
||||
false,
|
||||
expect.objectContaining({ remoteTrackingBase, ...options })
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
it.each([true, false])(
|
||||
'keeps local eligibility with picker intent (reusable: %s)',
|
||||
async (reusable) => {
|
||||
mocks.branchConflict.mockImplementation(async (_path, branch: string) =>
|
||||
branch === 'main' ? 'local' : null
|
||||
)
|
||||
mocks.canCheckout.mockImplementation(
|
||||
async (_path, branch: string) => reusable && branch === 'main'
|
||||
)
|
||||
mocks.pathExists.mockImplementation(async (path) => path === worktreePath)
|
||||
mocks.consume.mockResolvedValue({ status: 'miss', reason: 'not_prepared' })
|
||||
|
||||
await createWorktree(pickedBranch)
|
||||
|
||||
expect(mocks.add).toHaveBeenCalledWith(
|
||||
'/repo',
|
||||
resolve('/worktrees', 'app-2'),
|
||||
reusable ? 'main' : 'main-2',
|
||||
'origin/main',
|
||||
false,
|
||||
false,
|
||||
expect.objectContaining(reusable ? { checkoutExistingBranch: true } : {})
|
||||
)
|
||||
expect(mocks.githubPr.mock.calls.map(([, branch]) => branch)).toEqual(
|
||||
reusable ? [] : ['main-2']
|
||||
)
|
||||
expect(mocks.add.mock.calls[0][6].checkoutExistingBranch ?? false).toBe(reusable)
|
||||
}
|
||||
)
|
||||
|
||||
it('keeps unflagged legacy, mobile New branch and Advanced collisions on baseline allocation', async () => {
|
||||
mocks.consume.mockResolvedValue({ status: 'miss', reason: 'not_prepared' })
|
||||
mocks.branchName.mockImplementation(async (_path, override, name: string) => override ?? name)
|
||||
mocks.branchConflict.mockImplementation(async (_path, branch: string) =>
|
||||
branch === 'feature/test' ? 'remote' : null
|
||||
)
|
||||
|
||||
await createWorktree({ branchNameOverride: 'feature/test', baseBranch: 'origin/main' })
|
||||
|
||||
expect(mocks.add.mock.calls[0][2]).toBe('feature/test-2')
|
||||
})
|
||||
|
||||
it('runs the first name PR lookup while the base fetch is still in flight', async () => {
|
||||
mocks.remoteBase.mockResolvedValue(remoteTrackingBase)
|
||||
let finishFetch!: () => void
|
||||
mocks.refresh.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
finishFetch = () => resolve({ ok: true })
|
||||
})
|
||||
)
|
||||
let fetchPendingAtLookup = false
|
||||
mocks.githubPr.mockImplementation(async () => {
|
||||
fetchPendingAtLookup = mocks.refresh.mock.calls.length === 1
|
||||
finishFetch?.()
|
||||
return null
|
||||
})
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(fetchPendingAtLookup).toBe(true)
|
||||
expect(mocks.githubPr).toHaveBeenCalledWith('/repo', 'app', {})
|
||||
expect(mocks.consume).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
branch: 'app',
|
||||
options: expect.objectContaining({ remoteTrackingBase })
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('suffixes past a PR on the first name', async () => {
|
||||
mocks.githubPr.mockResolvedValueOnce({ number: 7, state: 'closed' }).mockResolvedValue(null)
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(mocks.githubPr.mock.calls.map(([, branch]) => branch)).toEqual(['app', 'app-2'])
|
||||
expect(mocks.consume).toHaveBeenCalledWith(expect.objectContaining({ branch: 'app-2' }))
|
||||
})
|
||||
|
||||
it.each([undefined, 'Ubuntu'])(
|
||||
'probes the next name for a PR once the first name collides, routed for %s',
|
||||
async (wslDistro) => {
|
||||
const routing = wslDistro ? { wslDistro } : {}
|
||||
mocks.routing.mockReturnValue(routing)
|
||||
mocks.branchConflict.mockResolvedValueOnce('local').mockResolvedValue(null)
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(mocks.githubPr).toHaveBeenCalledOnce()
|
||||
expect(mocks.githubPr).toHaveBeenCalledWith('/repo', 'app-2', routing)
|
||||
}
|
||||
)
|
||||
|
||||
it('skips a later name that already has a PR', async () => {
|
||||
mocks.branchConflict.mockResolvedValueOnce('local').mockResolvedValue(null)
|
||||
mocks.githubPr.mockResolvedValueOnce({ number: 7, state: 'closed' }).mockResolvedValue(null)
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(mocks.githubPr.mock.calls.map(([, branch]) => branch)).toEqual(['app-2', 'app-3'])
|
||||
expect(mocks.consume).toHaveBeenCalledWith(expect.objectContaining({ branch: 'app-3' }))
|
||||
})
|
||||
|
||||
it('reports the naming failure when the started base fetch also fails', async () => {
|
||||
mocks.remoteBase.mockResolvedValue(remoteTrackingBase)
|
||||
mocks.refresh.mockRejectedValue(new Error('offline'))
|
||||
mocks.branchConflict.mockResolvedValue('local')
|
||||
const unhandled = vi.fn()
|
||||
process.on('unhandledRejection', unhandled)
|
||||
try {
|
||||
await expect(createWorktree()).rejects.toThrow('Branch "app-')
|
||||
await new Promise((resolve) => setImmediate(resolve))
|
||||
expect(mocks.refresh).toHaveBeenCalledOnce()
|
||||
expect(unhandled).not.toHaveBeenCalled()
|
||||
expect(mocks.consume).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
process.off('unhandledRejection', unhandled)
|
||||
}
|
||||
})
|
||||
|
||||
it('runs the first name PR lookup while the origin fetch is still in flight', async () => {
|
||||
mocks.hasBase.mockResolvedValue(false)
|
||||
let finishFetch!: () => void
|
||||
mocks.fetch.mockReturnValue(
|
||||
new Promise<void>((resolve) => {
|
||||
finishFetch = resolve
|
||||
})
|
||||
)
|
||||
let fetchPendingAtLookup = false
|
||||
mocks.githubPr.mockImplementation(async () => {
|
||||
fetchPendingAtLookup = mocks.fetch.mock.calls.length === 1
|
||||
finishFetch?.()
|
||||
return null
|
||||
})
|
||||
|
||||
await createWorktree()
|
||||
|
||||
expect(fetchPendingAtLookup).toBe(true)
|
||||
expect(mocks.fetch).toHaveBeenCalledWith('/repo', 'origin', {})
|
||||
expect(mocks.consume).toHaveBeenCalledWith(expect.objectContaining({ branch: 'app' }))
|
||||
})
|
||||
|
||||
it('reports the naming failure when the started origin fetch also fails', async () => {
|
||||
mocks.hasBase.mockResolvedValue(false)
|
||||
mocks.fetch.mockRejectedValue(new Error('offline'))
|
||||
mocks.branchConflict.mockResolvedValue('local')
|
||||
const unhandled = vi.fn()
|
||||
process.on('unhandledRejection', unhandled)
|
||||
try {
|
||||
await expect(createWorktree()).rejects.toThrow('Branch "app-')
|
||||
await new Promise((resolve) => setImmediate(resolve))
|
||||
expect(mocks.fetch).toHaveBeenCalledOnce()
|
||||
expect(unhandled).not.toHaveBeenCalled()
|
||||
expect(mocks.consume).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
process.off('unhandledRejection', unhandled)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('runtime create base without a tracking ref', () => {
|
||||
const originMain = {
|
||||
remote: 'origin',
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { installNetRequestFetchAdapter } from './updater-net-request.fixture'
|
||||
|
||||
const originalPlatform = process.platform
|
||||
const originalArch = process.arch
|
||||
const { netFetchMock, netRequestMock } = vi.hoisted(() => ({
|
||||
netFetchMock: vi.fn(),
|
||||
netRequestMock: vi.fn()
|
||||
}))
|
||||
vi.mock('electron', () => ({ net: { fetch: netFetchMock, request: netRequestMock } }))
|
||||
|
||||
const latestUrl = 'https://github.com/stablyai/orca/releases/latest'
|
||||
const releaseUrl = 'https://github.com/stablyai/orca/releases/download/v1.4.241'
|
||||
|
||||
function serveLatestRelease(location = '/stablyai/orca/releases/tag/v1.4.241'): void {
|
||||
netFetchMock.mockImplementation(async (url: string) => {
|
||||
if (url === latestUrl) {
|
||||
return new Response(null, { status: 302, headers: { location } })
|
||||
}
|
||||
if (url.endsWith('.yml')) {
|
||||
return new Response(
|
||||
'version: 1.4.241\nfiles:\n - url: Orca-1.4.241-arm64-mac.zip\n sha512: test\n'
|
||||
)
|
||||
}
|
||||
return new Response(null, { status: 200 })
|
||||
})
|
||||
}
|
||||
|
||||
describe('latest stable release fallback', () => {
|
||||
beforeEach(() => {
|
||||
netFetchMock.mockReset()
|
||||
netRequestMock.mockReset()
|
||||
installNetRequestFetchAdapter(netRequestMock, netFetchMock)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, 'platform', { value: originalPlatform })
|
||||
Object.defineProperty(process, 'arch', { value: originalArch })
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ platform: 'darwin', arch: 'arm64', manifest: 'latest-mac.yml' },
|
||||
{ platform: 'win32', arch: 'x64', manifest: 'latest.yml' },
|
||||
{ platform: 'linux', arch: 'x64', manifest: 'latest-linux.yml' },
|
||||
{ platform: 'linux', arch: 'arm64', manifest: 'latest-linux-arm64.yml' }
|
||||
])(
|
||||
'probes the concrete $platform/$arch release before returning its tag',
|
||||
async ({ platform, arch, manifest }) => {
|
||||
Object.defineProperty(process, 'platform', { value: platform })
|
||||
Object.defineProperty(process, 'arch', { value: arch })
|
||||
serveLatestRelease()
|
||||
const { fetchLatestStableReleaseTag } = await import('./updater-prerelease-feed')
|
||||
|
||||
await expect(fetchLatestStableReleaseTag()).resolves.toBe('v1.4.241')
|
||||
expect(netFetchMock).toHaveBeenCalledWith(
|
||||
latestUrl,
|
||||
expect.objectContaining({ method: 'HEAD', redirect: 'manual' })
|
||||
)
|
||||
expect(netFetchMock).toHaveBeenCalledWith(`${releaseUrl}/${manifest}`, expect.anything())
|
||||
expect(netFetchMock).toHaveBeenCalledWith(
|
||||
`${releaseUrl}/Orca-1.4.241-arm64-mac.zip`,
|
||||
expect.objectContaining({ method: 'HEAD' })
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
it.each([
|
||||
'https://other.example/stablyai/orca/releases/tag/v1.4.241',
|
||||
'/other/repo/releases/tag/v1.4.241',
|
||||
'/stablyai/orca/releases/tag/v1.4.242-rc.1',
|
||||
'/stablyai/orca/releases/tag/mobile-android-v0.0.59',
|
||||
'/stablyai/orca/releases/tag/%',
|
||||
'/stablyai/orca/releases/latest'
|
||||
])('rejects an invalid fallback redirect %s before probing assets', async (location) => {
|
||||
serveLatestRelease(location)
|
||||
const { fetchLatestStableReleaseTag } = await import('./updater-prerelease-feed')
|
||||
|
||||
await expect(fetchLatestStableReleaseTag()).resolves.toBeNull()
|
||||
expect(netFetchMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it.each(['manifest', 'installer'])('rejects a release with a missing %s', async (missing) => {
|
||||
Object.defineProperty(process, 'platform', { value: 'darwin' })
|
||||
serveLatestRelease()
|
||||
const respond = netFetchMock.getMockImplementation()
|
||||
netFetchMock.mockImplementation(async (url: string) => {
|
||||
if (url.endsWith(missing === 'manifest' ? '.yml' : '.zip')) {
|
||||
return new Response(null, { status: 404 })
|
||||
}
|
||||
return respond?.(url)
|
||||
})
|
||||
const { fetchLatestStableReleaseTag } = await import('./updater-prerelease-feed')
|
||||
|
||||
await expect(fetchLatestStableReleaseTag()).resolves.toBeNull()
|
||||
})
|
||||
|
||||
it('keeps a network failure retryable instead of returning a moving URL', async () => {
|
||||
netFetchMock.mockRejectedValueOnce(new Error('network unavailable'))
|
||||
const { fetchLatestStableReleaseTag } = await import('./updater-prerelease-feed')
|
||||
await expect(fetchLatestStableReleaseTag()).resolves.toBeNull()
|
||||
|
||||
serveLatestRelease('https://github.com/stablyai/orca/releases/tag/v1.4.241')
|
||||
await expect(fetchLatestStableReleaseTag()).resolves.toBe('v1.4.241')
|
||||
})
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import { vi, type Mock } from 'vitest'
|
||||
type NetFetchResponse = {
|
||||
ok?: boolean
|
||||
status?: number
|
||||
headers?: { get: (name: string) => string | null }
|
||||
}
|
||||
|
||||
export function installNetRequestFetchAdapter(netRequestMock: Mock, netFetchMock: Mock): void {
|
||||
@@ -21,7 +22,13 @@ export function installNetRequestFetchAdapter(netRequestMock: Mock, netFetchMock
|
||||
(response: NetFetchResponse) => {
|
||||
const status = response.status ?? (response.ok ? 200 : 503)
|
||||
if (options.redirect === 'manual' && status >= 300 && status < 400) {
|
||||
request.emit('redirect', status, options.method ?? 'GET', 'https://redirect.test', {})
|
||||
request.emit(
|
||||
'redirect',
|
||||
status,
|
||||
options.method ?? 'GET',
|
||||
response.headers?.get('location') ?? 'https://redirect.test',
|
||||
{}
|
||||
)
|
||||
// Electron emits an error after cancelling an unfollowed manual redirect.
|
||||
request.emit('error', new Error('Redirect was cancelled'))
|
||||
} else {
|
||||
|
||||
@@ -104,17 +104,19 @@ function getManifestAssetNames(manifestText: string): string[] {
|
||||
|
||||
type ReleaseReadiness = 'ready' | 'not-ready' | 'unavailable'
|
||||
|
||||
function getGitHubReleaseAssetReadiness(assetUrl: string): Promise<ReleaseReadiness> {
|
||||
type ReleaseHeadResponse = { statusCode: number; redirectUrl?: string }
|
||||
|
||||
function requestGitHubReleaseHead(assetUrl: string): Promise<ReleaseHeadResponse | null> {
|
||||
return new Promise((resolve) => {
|
||||
const request = net.request({ method: 'HEAD', url: assetUrl, redirect: 'manual' })
|
||||
let settled = false
|
||||
const settle = (readiness: ReleaseReadiness): void => {
|
||||
const settle = (response: ReleaseHeadResponse | null): void => {
|
||||
if (settled) {
|
||||
return
|
||||
}
|
||||
settled = true
|
||||
clearTimeout(timeout)
|
||||
resolve(readiness)
|
||||
resolve(response)
|
||||
}
|
||||
const timeout = setTimeout(() => {
|
||||
try {
|
||||
@@ -122,31 +124,35 @@ function getGitHubReleaseAssetReadiness(assetUrl: string): Promise<ReleaseReadin
|
||||
} catch {
|
||||
// The request may already have been cancelled by Electron.
|
||||
}
|
||||
settle('unavailable')
|
||||
settle(null)
|
||||
}, FETCH_TIMEOUT_MS)
|
||||
|
||||
request.on('redirect', (statusCode) => {
|
||||
request.on('redirect', (statusCode, _method, redirectUrl) => {
|
||||
// GitHub's redirect proves existence without fetching the signed storage URL.
|
||||
settle(statusCode >= 300 && statusCode < 400 ? 'ready' : 'unavailable')
|
||||
settle({ statusCode, redirectUrl })
|
||||
})
|
||||
request.on('response', (response) => {
|
||||
settle(
|
||||
response.statusCode === 404
|
||||
? 'not-ready'
|
||||
: response.statusCode >= 200 && response.statusCode < 300
|
||||
? 'ready'
|
||||
: 'unavailable'
|
||||
)
|
||||
})
|
||||
request.on('error', () => settle('unavailable'))
|
||||
request.on('response', (response) => settle({ statusCode: response.statusCode }))
|
||||
request.on('error', () => settle(null))
|
||||
try {
|
||||
request.end()
|
||||
} catch {
|
||||
settle('unavailable')
|
||||
settle(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function getGitHubReleaseAssetReadiness(assetUrl: string): Promise<ReleaseReadiness> {
|
||||
const response = await requestGitHubReleaseHead(assetUrl)
|
||||
if (!response) {
|
||||
return 'unavailable'
|
||||
}
|
||||
const ready =
|
||||
response.redirectUrl !== undefined
|
||||
? response.statusCode >= 300 && response.statusCode < 400
|
||||
: response.statusCode >= 200 && response.statusCode < 300
|
||||
return response.statusCode === 404 ? 'not-ready' : ready ? 'ready' : 'unavailable'
|
||||
}
|
||||
|
||||
async function getReleaseAssetReadiness(tag: string, assetName: string): Promise<ReleaseReadiness> {
|
||||
const isRelativeAsset = !/^https?:\/\//i.test(assetName)
|
||||
const isGitHubReleaseAsset =
|
||||
@@ -208,6 +214,30 @@ async function getPlatformManifestReadiness(tag: string): Promise<ReleaseReadine
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchLatestStableReleaseTag(): Promise<string | null> {
|
||||
try {
|
||||
// Resolve only the release-page redirect; installer redirects continue on to signed storage URLs.
|
||||
const latestUrl = 'https://github.com/stablyai/orca/releases/latest'
|
||||
const response = await requestGitHubReleaseHead(latestUrl)
|
||||
if (!response?.redirectUrl || response.statusCode < 300 || response.statusCode >= 400) {
|
||||
return null
|
||||
}
|
||||
const target = new URL(response.redirectUrl, latestUrl)
|
||||
const match = target.pathname.match(/^\/stablyai\/orca\/releases\/tag\/([^/]+)$/)
|
||||
if (target.origin !== 'https://github.com' || !match) {
|
||||
return null
|
||||
}
|
||||
const tag = decodeURIComponent(match[1])
|
||||
const version = normalizeTagToVersion(tag)
|
||||
if (!isValidVersion(version) || isPrereleaseVersion(version)) {
|
||||
return null
|
||||
}
|
||||
return (await getPlatformManifestReadiness(tag)) === 'ready' ? tag : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Concrete tags keep manifests and downloaded assets on the same release.
|
||||
type FetchNewerReleaseTagOptions = {
|
||||
includePrerelease?: boolean
|
||||
|
||||
@@ -59,6 +59,7 @@ type UpdaterModuleFactories = {
|
||||
}
|
||||
updaterPrereleaseFeed: () => {
|
||||
fetchNewerReleaseTagsWithReadiness: (...args: unknown[]) => Promise<unknown>
|
||||
fetchLatestStableReleaseTag: () => Promise<string | null>
|
||||
getReleaseDownloadUrl: (tag: string) => string
|
||||
}
|
||||
localBuildSwitch: () => { chooseLocalBuild: UpdaterSpy }
|
||||
@@ -82,6 +83,7 @@ export type UpdaterMocks = {
|
||||
armExitWatchdogMock: UpdaterSpy
|
||||
disarmExitWatchdogMock: UpdaterSpy
|
||||
fetchNewerReleaseTagsMock: UpdaterSpy
|
||||
fetchLatestStableReleaseTagMock: Mock<() => Promise<string | null>>
|
||||
chooseLocalBuildMock: UpdaterSpy
|
||||
startLocalBuildFeedMock: UpdaterSpy
|
||||
closeLocalBuildFeedMock: UpdaterSpy
|
||||
@@ -204,6 +206,7 @@ export function createUpdaterMocks(): UpdaterMocks {
|
||||
const armExitWatchdogMock = vi.fn()
|
||||
const disarmExitWatchdogMock = vi.fn()
|
||||
const fetchNewerReleaseTagsMock = vi.fn()
|
||||
const fetchLatestStableReleaseTagMock = vi.fn<() => Promise<string | null>>()
|
||||
const chooseLocalBuildMock = vi.fn()
|
||||
const startLocalBuildFeedMock = vi.fn()
|
||||
const closeLocalBuildFeedMock = vi.fn()
|
||||
@@ -234,6 +237,7 @@ export function createUpdaterMocks(): UpdaterMocks {
|
||||
disarmUpdateInstallExitWatchdog: disarmExitWatchdogMock
|
||||
}),
|
||||
updaterPrereleaseFeed: () => ({
|
||||
fetchLatestStableReleaseTag: fetchLatestStableReleaseTagMock,
|
||||
fetchNewerReleaseTagsWithReadiness: async (...args: unknown[]) => {
|
||||
const result = await fetchNewerReleaseTagsMock(...args)
|
||||
return Array.isArray(result)
|
||||
@@ -275,6 +279,7 @@ export function createUpdaterMocks(): UpdaterMocks {
|
||||
shouldApplyNudgeMock.mockReset().mockReturnValue(false)
|
||||
fetchChangelogMock.mockReset().mockResolvedValue(null)
|
||||
fetchNewerReleaseTagsMock.mockReset().mockResolvedValue([])
|
||||
fetchLatestStableReleaseTagMock.mockReset().mockResolvedValue('v1.0.51')
|
||||
chooseLocalBuildMock.mockReset()
|
||||
closeLocalBuildFeedMock.mockReset()
|
||||
startLocalBuildFeedMock.mockReset().mockResolvedValue({
|
||||
@@ -308,6 +313,7 @@ export function createUpdaterMocks(): UpdaterMocks {
|
||||
armExitWatchdogMock,
|
||||
disarmExitWatchdogMock,
|
||||
fetchNewerReleaseTagsMock,
|
||||
fetchLatestStableReleaseTagMock,
|
||||
chooseLocalBuildMock,
|
||||
startLocalBuildFeedMock,
|
||||
closeLocalBuildFeedMock,
|
||||
|
||||
@@ -219,7 +219,7 @@ describe('updater', () => {
|
||||
expect(autoUpdaterMock.disableDifferentialDownload).toBe(false)
|
||||
expect(autoUpdaterMock.setFeedURL).toHaveBeenLastCalledWith({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.0.51'
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -262,7 +262,7 @@ describe('updater', () => {
|
||||
})
|
||||
expect(autoUpdaterMock.setFeedURL).toHaveBeenLastCalledWith({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.0.51'
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -302,7 +302,7 @@ describe('updater', () => {
|
||||
})
|
||||
expect(autoUpdaterMock.setFeedURL).toHaveBeenLastCalledWith({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.0.51'
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -356,7 +356,7 @@ describe('updater', () => {
|
||||
expect(send).toHaveBeenCalledWith('updater:status', { state: 'not-available' })
|
||||
expect(autoUpdaterMock.setFeedURL).toHaveBeenLastCalledWith({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.0.51'
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -402,7 +402,7 @@ describe('updater', () => {
|
||||
})
|
||||
expect(autoUpdaterMock.setFeedURL).toHaveBeenLastCalledWith({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.0.51'
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@@ -178,10 +178,18 @@ describe('updater check failure handling', () => {
|
||||
killAllPtyMock.mockReset()
|
||||
vi.unstubAllGlobals()
|
||||
vi.useRealTimers()
|
||||
netFetchMock.mockReset().mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
text: () => Promise.resolve('<feed></feed>')
|
||||
netFetchMock.mockReset().mockImplementation(async (url: string) => {
|
||||
if (url.endsWith('/releases/latest')) {
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: { location: 'https://github.com/stablyai/orca/releases/tag/v1.0.51' }
|
||||
})
|
||||
}
|
||||
return new Response(
|
||||
url.endsWith('.atom')
|
||||
? '<feed></feed>'
|
||||
: 'version: 1.0.51\nfiles:\n - url: orca-windows-setup.exe\n'
|
||||
)
|
||||
})
|
||||
netRequestMock.mockReset()
|
||||
installNetRequestFetchAdapter(netRequestMock, netFetchMock)
|
||||
|
||||
@@ -2,8 +2,13 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { loadUpdaterModule, warmUpdaterModule } from './updater-test-module-loader'
|
||||
import { updaterMainWindow } from './updater-test-main-window'
|
||||
|
||||
const { autoUpdaterMock, fetchNewerReleaseTagsMock, moduleFactories, resetUpdaterMocks } =
|
||||
await vi.hoisted(async () => (await import('./updater-test-harness')).createUpdaterMocks())
|
||||
const {
|
||||
autoUpdaterMock,
|
||||
fetchNewerReleaseTagsMock,
|
||||
fetchLatestStableReleaseTagMock,
|
||||
moduleFactories,
|
||||
resetUpdaterMocks
|
||||
} = await vi.hoisted(async () => (await import('./updater-test-harness')).createUpdaterMocks())
|
||||
|
||||
vi.mock('electron', () => moduleFactories.electron())
|
||||
vi.mock('electron-updater', () => moduleFactories.electronUpdater())
|
||||
@@ -100,6 +105,29 @@ describe('updater feed preflight ownership', () => {
|
||||
}
|
||||
)
|
||||
|
||||
it('does not let an expired stable fallback replace a newer feed', async () => {
|
||||
let finish = (_tag: string | null): void => {}
|
||||
fetchLatestStableReleaseTagMock.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
finish = resolve
|
||||
})
|
||||
)
|
||||
const updater = await setup()
|
||||
updater.checkForUpdatesFromMenu()
|
||||
await vi.advanceTimersByTimeAsync(45_000)
|
||||
fetchNewerReleaseTagsMock.mockResolvedValueOnce({ tags: ['v3.0.0'], state: 'ready' })
|
||||
updater.checkForUpdatesFromMenu()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
autoUpdaterMock.setFeedURL.mockClear()
|
||||
|
||||
finish('v2.0.0')
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
expect(autoUpdaterMock.setFeedURL).not.toHaveBeenCalled()
|
||||
expect(autoUpdaterMock.checkForUpdates).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{
|
||||
result: { tags: ['v3.0.0'], state: 'ready' },
|
||||
@@ -107,7 +135,7 @@ describe('updater feed preflight ownership', () => {
|
||||
},
|
||||
{
|
||||
result: { tags: [], state: 'no-newer' },
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.0.51'
|
||||
}
|
||||
])('keeps the active $result.state feed choice', async ({ result, url }) => {
|
||||
fetchNewerReleaseTagsMock.mockResolvedValueOnce(result)
|
||||
|
||||
@@ -94,6 +94,14 @@ vi.mock('electron', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('electron-updater', () => ({ autoUpdater: autoUpdaterMock }))
|
||||
vi.mock('./updater-prerelease-feed', () => ({
|
||||
fetchNewerReleaseTagsWithReadiness: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ tags: ['v1.4.241'], state: 'ready' }),
|
||||
getReleaseDownloadUrl: (tag: string) =>
|
||||
`https://github.com/stablyai/orca/releases/download/${tag}`
|
||||
}))
|
||||
|
||||
vi.mock('./electron-updater-loader', () => ({
|
||||
loadElectronAutoUpdater: () => autoUpdaterMock
|
||||
}))
|
||||
|
||||
@@ -111,6 +111,14 @@ vi.mock('electron-updater', () => ({
|
||||
autoUpdater: autoUpdaterMock
|
||||
}))
|
||||
|
||||
vi.mock('./updater-prerelease-feed', () => ({
|
||||
fetchNewerReleaseTagsWithReadiness: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ tags: ['v1.4.241'], state: 'ready' }),
|
||||
getReleaseDownloadUrl: (tag: string) =>
|
||||
`https://github.com/stablyai/orca/releases/download/${tag}`
|
||||
}))
|
||||
|
||||
vi.mock('./electron-updater-loader', () => ({
|
||||
loadElectronAutoUpdater: () => autoUpdaterMock
|
||||
}))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { loadUpdaterModule, warmUpdaterModule } from './updater-test-module-loader'
|
||||
import { updaterMainWindow } from './updater-test-main-window'
|
||||
|
||||
const {
|
||||
appMock,
|
||||
@@ -7,6 +8,7 @@ const {
|
||||
fetchNudgeMock,
|
||||
shouldApplyNudgeMock,
|
||||
fetchNewerReleaseTagsMock,
|
||||
fetchLatestStableReleaseTagMock,
|
||||
moduleFactories,
|
||||
resetUpdaterMocks
|
||||
} = await vi.hoisted(async () => (await import('./updater-test-harness')).createUpdaterMocks())
|
||||
@@ -83,9 +85,10 @@ describe('updater', () => {
|
||||
expect(autoUpdaterMock.allowPrerelease).not.toBe(true)
|
||||
})
|
||||
|
||||
it('falls back to /releases/latest/download when the atom resolver returns null', async () => {
|
||||
it('pins a stable fallback when Atom has no newer prerelease', async () => {
|
||||
appMock.getVersion.mockReturnValue('1.3.19-rc.6')
|
||||
fetchNewerReleaseTagsMock.mockResolvedValue([])
|
||||
fetchLatestStableReleaseTagMock.mockResolvedValue('v1.3.19')
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValue(undefined)
|
||||
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await loadUpdaterModule()
|
||||
@@ -100,7 +103,7 @@ describe('updater', () => {
|
||||
})
|
||||
expect(autoUpdaterMock.setFeedURL).toHaveBeenLastCalledWith({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.3.19'
|
||||
})
|
||||
})
|
||||
|
||||
@@ -136,13 +139,14 @@ describe('updater', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps Atom feed outages on the existing moving-feed fallback', async () => {
|
||||
it('pins the latest stable release during an Atom feed outage', async () => {
|
||||
appMock.getVersion.mockReturnValue('1.4.141')
|
||||
fetchNewerReleaseTagsMock.mockResolvedValue({
|
||||
tags: [],
|
||||
state: 'unavailable',
|
||||
unavailableReason: 'feed'
|
||||
})
|
||||
fetchLatestStableReleaseTagMock.mockResolvedValue('v1.4.142')
|
||||
const sendMock = vi.fn()
|
||||
const mainWindow = { webContents: { send: sendMock } }
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await loadUpdaterModule()
|
||||
@@ -155,7 +159,7 @@ describe('updater', () => {
|
||||
})
|
||||
expect(autoUpdaterMock.setFeedURL).toHaveBeenLastCalledWith({
|
||||
provider: 'generic',
|
||||
url: 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
url: 'https://github.com/stablyai/orca/releases/download/v1.4.142'
|
||||
})
|
||||
expect(sendMock).not.toHaveBeenCalledWith(
|
||||
'updater:status',
|
||||
@@ -163,6 +167,28 @@ describe('updater', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('does not launch a moving feed when the stable fallback cannot be resolved', async () => {
|
||||
fetchLatestStableReleaseTagMock.mockResolvedValue(null)
|
||||
const sendMock = vi.fn()
|
||||
const { setupAutoUpdater, checkForUpdatesFromMenu } = await loadUpdaterModule()
|
||||
setupAutoUpdater(updaterMainWindow(sendMock), {
|
||||
getLastUpdateCheckAt: () => Date.now()
|
||||
})
|
||||
autoUpdaterMock.setFeedURL.mockClear()
|
||||
|
||||
checkForUpdatesFromMenu()
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(sendMock).toHaveBeenCalledWith('updater:status', {
|
||||
state: 'error',
|
||||
message: "Couldn't reach the update server. Try again in a few minutes.",
|
||||
userInitiated: true
|
||||
})
|
||||
})
|
||||
expect(autoUpdaterMock.setFeedURL).not.toHaveBeenCalled()
|
||||
expect(autoUpdaterMock.checkForUpdates).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('uses last-good concrete feed when a user-initiated check lands during publishing', async () => {
|
||||
appMock.getVersion.mockReturnValue('1.4.26')
|
||||
fetchNewerReleaseTagsMock.mockResolvedValue({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { app } from 'electron'
|
||||
import {
|
||||
fetchLatestStableReleaseTag,
|
||||
fetchNewerReleaseTagsWithReadiness,
|
||||
getReleaseDownloadUrl
|
||||
} from '../updater-prerelease-feed'
|
||||
@@ -207,10 +208,19 @@ export abstract class UpdaterReleaseFeed extends UpdaterInstallExecution {
|
||||
}
|
||||
this.clearPrereleaseFallbackContext()
|
||||
this.clearPublishingWindowLastGoodCheck()
|
||||
const url = 'https://github.com/stablyai/orca/releases/latest/download'
|
||||
console.info(
|
||||
`[updater] release feed fallback: current=${currentVersion} includePrerelease=${includePrerelease} → ${url}`
|
||||
)
|
||||
const stableTag = await fetchLatestStableReleaseTag()
|
||||
if (!this.isActiveUpdateCheckAttempt(attemptId)) {
|
||||
return 'not-available'
|
||||
}
|
||||
if (!stableTag) {
|
||||
throw new ReleaseFeedPreflightError(
|
||||
'manifest-unavailable',
|
||||
'default',
|
||||
'Unable to resolve a ready stable release on GitHub'
|
||||
)
|
||||
}
|
||||
const url = getReleaseDownloadUrl(stableTag)
|
||||
console.info(`[updater] stable fallback feed pinned: current=${currentVersion} → ${url}`)
|
||||
autoUpdater.setFeedURL({ provider: 'generic', url })
|
||||
return 'ready'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { PanelBottomClose, PanelRightClose, X } from 'lucide-react'
|
||||
import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { useAppStore } from '@/store'
|
||||
import { useStructuredChatPaneActions } from './use-structured-chat-pane-actions'
|
||||
import { NativeChatCopyOrcaSessionIdMenuItem } from './NativeChatCopyOrcaSessionIdMenuItem'
|
||||
|
||||
export function StructuredChatPaneMenuItems({
|
||||
pane,
|
||||
leadingSeparator,
|
||||
splitShortcutLabels,
|
||||
resolveOrcaSessionId
|
||||
}: {
|
||||
splitShortcutLabels?: { right: string; down: string }
|
||||
resolveOrcaSessionId?: () => Promise<string | null>
|
||||
pane: { tabId: string; worktreeId: string; groupId: string }
|
||||
leadingSeparator: boolean
|
||||
}) {
|
||||
const actions = useStructuredChatPaneActions(pane.tabId, pane.worktreeId, pane.groupId)
|
||||
const hasSplitPanes = useAppStore(
|
||||
(state) => (state.groupsByWorktree[pane.worktreeId]?.length ?? 0) > 1
|
||||
)
|
||||
return (
|
||||
<>
|
||||
{leadingSeparator ? <DropdownMenuSeparator /> : null}
|
||||
<DropdownMenuItem onSelect={actions.onSplitRight}>
|
||||
<PanelRightClose />
|
||||
{translate('auto.components.cmd.j.quick.actions.splitChatRight', 'Split Chat Right')}
|
||||
<DropdownMenuShortcut>{splitShortcutLabels?.right}</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={actions.onSplitDown}>
|
||||
<PanelBottomClose />
|
||||
{translate('auto.components.cmd.j.quick.actions.splitChatDown', 'Split Chat Down')}
|
||||
<DropdownMenuShortcut>{splitShortcutLabels?.down}</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
{resolveOrcaSessionId ? (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<NativeChatCopyOrcaSessionIdMenuItem resolveOrcaSessionId={resolveOrcaSessionId} />
|
||||
</>
|
||||
) : null}
|
||||
{hasSplitPanes && actions.canClosePane ? (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive" onSelect={actions.onClosePane}>
|
||||
<X />
|
||||
{actions.closeLabel}
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -8,16 +8,7 @@ import {
|
||||
type RefObject
|
||||
} from 'react'
|
||||
import { chatMathSelectionText } from '../sidebar/chat-markdown-math-selection'
|
||||
import {
|
||||
Clipboard,
|
||||
Copy,
|
||||
GitFork,
|
||||
Image as ImageIcon,
|
||||
PanelBottomClose,
|
||||
PanelRightClose,
|
||||
SquareTerminal,
|
||||
X
|
||||
} from 'lucide-react'
|
||||
import { Clipboard, Copy, GitFork, Image as ImageIcon, SquareTerminal } from 'lucide-react'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -35,11 +26,11 @@ import {
|
||||
import { isMacPlatform } from './native-chat-shortcut'
|
||||
import { formatOptionalPrimaryShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import { useAppStore } from '@/store'
|
||||
import { useStructuredChatPaneActions } from './use-structured-chat-pane-actions'
|
||||
import { isEditableTarget } from '@/lib/editable-target'
|
||||
import { findEditablePrimarySelectionPasteTarget } from '@/lib/primary-selection-paste'
|
||||
import { NativeChatCopyOrcaSessionIdMenuItem } from './NativeChatCopyOrcaSessionIdMenuItem'
|
||||
import { NativeChatSelectionQuote } from './NativeChatSelectionQuote'
|
||||
import { StructuredChatPaneMenuItems } from './StructuredChatPaneMenuItems'
|
||||
import { NativeChatPaneMenuItems } from './NativeChatPaneMenuItems'
|
||||
import type { NativeChatComposerHandle } from './native-chat-composer-types'
|
||||
import { AgentSessionContinuationMenuItem } from '@/components/terminal-pane/AgentSessionContinuationMenuItem'
|
||||
@@ -343,51 +334,6 @@ export function useNativeChatContextMenu({
|
||||
}
|
||||
}
|
||||
|
||||
function StructuredChatPaneMenuItems({
|
||||
pane,
|
||||
leadingSeparator,
|
||||
splitShortcutLabels,
|
||||
resolveOrcaSessionId
|
||||
}: Pick<UseNativeChatContextMenuArgs, 'splitShortcutLabels' | 'resolveOrcaSessionId'> & {
|
||||
pane: NonNullable<UseNativeChatContextMenuArgs['chatPane']>
|
||||
leadingSeparator: boolean
|
||||
}) {
|
||||
const actions = useStructuredChatPaneActions(pane.tabId, pane.worktreeId, pane.groupId)
|
||||
const hasSplitPanes = useAppStore(
|
||||
(state) => (state.groupsByWorktree[pane.worktreeId]?.length ?? 0) > 1
|
||||
)
|
||||
return (
|
||||
<>
|
||||
{leadingSeparator ? <DropdownMenuSeparator /> : null}
|
||||
<DropdownMenuItem onSelect={actions.onSplitRight}>
|
||||
<PanelRightClose />
|
||||
{translate('auto.components.cmd.j.quick.actions.splitChatRight', 'Split Chat Right')}
|
||||
<DropdownMenuShortcut>{splitShortcutLabels?.right}</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={actions.onSplitDown}>
|
||||
<PanelBottomClose />
|
||||
{translate('auto.components.cmd.j.quick.actions.splitChatDown', 'Split Chat Down')}
|
||||
<DropdownMenuShortcut>{splitShortcutLabels?.down}</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
{resolveOrcaSessionId ? (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<NativeChatCopyOrcaSessionIdMenuItem resolveOrcaSessionId={resolveOrcaSessionId} />
|
||||
</>
|
||||
) : null}
|
||||
{hasSplitPanes && actions.canClosePane ? (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive" onSelect={actions.onClosePane}>
|
||||
<X />
|
||||
{actions.closeLabel}
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function keepSelectionThroughMenuPress(event: React.PointerEvent<HTMLElement>): void {
|
||||
// Preserve selection on menu-opening presses; otherwise it collapses before contextmenu fires.
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user