mirror of
https://github.com/stablyai/orca.git
synced 2026-11-06 12:07:58 +00:00
* fix(worktree-create): run create git commands at interactive tier, defer pool side jobs, bound queue wait by timeout
Creating a worktree on a busy machine stalled for minutes because the create's
own git competed for the same admission budget as everything else.
- The create path never set an admission tier, so it defaulted to 'status' and
could never use the scheduler's headroom slots. It now tags the option objects
that reach git directly: the add, the post-add listing, the base-ref probes and
the prepared-checkout finalize. The speculative warm-up and the SSH path are
unchanged.
- The prepared-pool re-arm is a full `reset --hard`; it ran mid-create and held a
general slot. `consumePreparedWorktreeCreate` now returns it as a thunk the
create runs after the startup terminal is spawned. Stale-preparation
reclamation (`worktree unlock` / `worktree remove`) drops to 'background'.
- A command's timeout only armed once its child spawned, so a saturated queue
could hold a 1s command indefinitely. Admission now takes the same deadline and
raises GitCommandTimeoutError without spawning; a caller abort still reports as
an abort.
The tier is kept off the `{ wslDistro }` routing objects: several callers test
those for emptiness to decide whether a repo has local git routing at all.
* fix(worktree-create): keep a bounded queue wait from reading as an absent base ref
The admission deadline added in the previous commit made every create-path probe's
15s/120s budget cover the queue wait. The default-base and worktree-base probes answer
`false`/`null` for any failure, so a saturated queue reported a repo that has origin/main
as having no default base and the create refused to start. Both probe families now let
`GitCommandTimeoutError` through, and the branch-name resolution loop, the push-target
configuration and the post-add listing run at the create's interactive tier so they reach
the headroom the rest of the create already uses.
Also: the deferred pool re-arm re-checks the pool inside the thunk, since `startPreparation`
replaces a map entry outright and would strand a prefetch's locked checkout with no owner;
the shared worktree scan keys on the tier so an interactive listing cannot inherit a queued
status scan's wait; and the deadline's microtask hop is gone, along with two fake-timer
`vi.waitFor` calls that jumped the clock past a 10ms budget before the grant settled.
* fix(worktree-create): preserve probe fallbacks and defer runtime replenishment
* fix(worktree-create): preserve interactive priority through prepared claims
* fix(worktree-create): prioritize CLI creation and preserve SHA probe timeouts
* fix(worktree-create): scope Git execution policy at creation boundaries
* fix(worktree-create): preserve inconclusive Git probe timeouts
* test(runtime): align creation fixtures with scoped Git execution
* test(native-chat): extract windowing layout fixture to satisfy file limit
* fix(git): restore execution-only timeouts while queued
* refactor(worktree-create): remove unrelated error-handling changes
* chore: narrow review scope and clarify preparation timing
* test(native-chat): restore fixture extraction to fix CI lint
* refactor(git): keep the admission scheduler in its original module
Reverts a move-only extraction. Inlines the single-use command-class
wrapper so the tier-resolution import fits the file's line budget.
* fix(worktrees): re-arm the prepared pool after CLI create launches terminals
The runtime create fired the pool re-arm right after materialization, so its
`reset --hard` competed with the startup agent's first git reads. Return the
thunk to the caller and fire it last, matching the desktop path.
* fix(worktrees): skip a preparation whose checkout is still running
An interactive create that claimed an in-flight preparation awaited a checkout
queued at background, so on a saturated budget it yielded to every arriving
status poller until aging promoted it. The create now misses with not_ready and
does its own add at interactive; the preparation stays armed for the next one.
Also drops the one-field policy object from the Git operation executor.
* fix(worktrees): report repo_mismatch before not_ready when selecting a preparation
The readiness filter ran before the same-repo check, so another repo's
in-flight preparation was labeled not_ready instead of repo_mismatch, hiding
the cap-thrash signal for multi-project users. The hit/miss decision is
unchanged.
* test(runtime): type the worktree-meta stub against WorktreeMeta
Main now rejects bare object parameters, and the merge picked that rule up.
* fix(worktrees): wait on in-flight preparations and re-arm the pool on failed creates
A create landing mid-checkout now claims the in-flight preparation and awaits it, as main
did. The `checkoutFinished` filter and its `not_ready` miss reason made the create skip a
prepared checkout that was seconds from done and pay a full cold add instead; on a 40k-file
repo that turned a 0.2-1.5s create into 2.4-4.3s. The preparation's own git also runs at
`status` again rather than `background`, so awaiting it does not park behind status pollers.
Only the stale reclaim stays `background`, which no create waits on.
The deferred pool re-arm now fires on every path, not just the success path. Main armed the
replacement synchronously inside the consume, so a later failure in include copy, push-target
setup, or terminal startup still left one warming. The thunk stays deferred until after
terminal startup for admission ordering, but a `finally` on the desktop create and matching
failure-path fires on the runtime create restore that guarantee. It fires exactly once.
* refactor(runtime): carry the pool re-arm in one holder
The runtime create used three mechanisms to guarantee the deferred pool re-arm fires: a
catch in the git create, a catch on materialization, and a holder fired in the managed
create's finally. The desktop create already used one holder for the same guarantee.
The holder now threads down through the create args, so the git create arms it at the point
it consumes a prepared checkout and nothing below has to handle the failure case. The thunk
already re-checks the pool before arming, so a single fire point in the outermost finally
covers every failure after the consume. Behavior is unchanged; both flipped failure-path
tests still assert exactly one fire, and each fails without the production change.
485 lines
17 KiB
TypeScript
485 lines
17 KiB
TypeScript
import { worktreeCreateGit } from '../git/worktree-create-git-executor'
|
|
import { resolveGitAdmissionTier } from '../git/command-runner/git-operation-executor'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
// Why: these tests cover the §3.3 Lifecycle rules on
|
|
// `OrcaRuntimeService.fetchRemoteWithCache` — in particular that a rejected
|
|
// fetch evicts its Map entry AND does not advance the freshness timestamp,
|
|
// and that two concurrent callers serialize on a single underlying fetch.
|
|
// They live in a dedicated file so we can mock `gitExecFileAsync` cleanly
|
|
// without disturbing the large orca-runtime.test.ts mock surface.
|
|
|
|
const gitExecFileAsyncMock = vi.hoisted(() => vi.fn())
|
|
|
|
vi.mock('../git/runner', async (importOriginal) => {
|
|
const actual = (await importOriginal()) as Record<string, unknown>
|
|
return {
|
|
...actual,
|
|
gitExecFileAsync: gitExecFileAsyncMock
|
|
}
|
|
})
|
|
|
|
// Why: orca-runtime.ts imports heavy modules (hooks, ipc/*, etc.) at top
|
|
// level. We only exercise the fetch cache, so we let those imports load
|
|
// normally — none of them trigger IO until a runtime method is called.
|
|
import { OrcaRuntimeService } from './orca-runtime'
|
|
|
|
function isFetchArgs(argv: unknown): argv is string[] {
|
|
if (!Array.isArray(argv)) {
|
|
return false
|
|
}
|
|
let commandIndex = 0
|
|
while (argv[commandIndex] === '-c' && typeof argv[commandIndex + 1] === 'string') {
|
|
commandIndex += 2
|
|
}
|
|
return argv[commandIndex] === 'fetch'
|
|
}
|
|
|
|
function fetchCallCount(): number {
|
|
return gitExecFileAsyncMock.mock.calls.filter(([argv]) => isFetchArgs(argv)).length
|
|
}
|
|
|
|
function exactBaseRefreshOptions(cwd: string): {
|
|
cwd: string
|
|
timeout: number
|
|
useConfiguredSshCommandForNetwork: boolean
|
|
} {
|
|
return { cwd, timeout: 60_000, useConfiguredSshCommandForNetwork: true }
|
|
}
|
|
|
|
function exactBaseRefreshArgs(branch = 'main'): string[] {
|
|
return [
|
|
'-c',
|
|
'maintenance.auto=false',
|
|
'-c',
|
|
'maintenance.commit-graph.auto=0',
|
|
'-c',
|
|
'gc.auto=0',
|
|
'fetch',
|
|
'--no-tags',
|
|
'origin',
|
|
`+refs/heads/${branch}:refs/remotes/origin/${branch}`
|
|
]
|
|
}
|
|
|
|
// Why (STA-1292): the broad create-path fetch must carry a timeout so a Windows
|
|
// credential-manager GUI hang can't wedge worktree creation forever.
|
|
function fullRemoteFetchOptions(cwd: string): { cwd: string; timeout: number } {
|
|
return { cwd, timeout: 60_000 }
|
|
}
|
|
|
|
function mockFetchResults(results: unknown[]): void {
|
|
let fetchIndex = 0
|
|
gitExecFileAsyncMock.mockImplementation((argv: string[]) => {
|
|
if (argv[0] === 'rev-parse') {
|
|
return Promise.reject(new Error('not a repo in cache-key test'))
|
|
}
|
|
const result = results[fetchIndex++]
|
|
return result instanceof Promise ? result : Promise.resolve(result)
|
|
})
|
|
}
|
|
|
|
describe('OrcaRuntimeService.fetchRemoteWithCache', () => {
|
|
it.each([undefined, 'Ubuntu'])(
|
|
'inherits create priority through fetch adapters on %s',
|
|
async (wslDistro) =>
|
|
worktreeCreateGit.run(async () => {
|
|
gitExecFileAsyncMock.mockImplementation(async (argv: string[]) => {
|
|
expect(resolveGitAdmissionTier()).toBe('interactive')
|
|
return {
|
|
stdout: argv[0] === 'remote' ? 'origin\n' : '/priority-repo/.git\n',
|
|
stderr: ''
|
|
}
|
|
})
|
|
const runtime = new OrcaRuntimeService()
|
|
const options = wslDistro ? { wslDistro } : {}
|
|
const base = await runtime.resolveRemoteTrackingBase(
|
|
'/priority-repo',
|
|
'origin/main',
|
|
options
|
|
)
|
|
expect(base).not.toBeNull()
|
|
if (!base) {
|
|
throw new Error('expected a remote base')
|
|
}
|
|
await expect(runtime.hasRemoteTrackingRef('/priority-repo', base, options)).resolves.toBe(
|
|
true
|
|
)
|
|
await expect(
|
|
runtime.getOrStartRemoteTrackingBaseRefresh('/priority-repo', base, options)
|
|
).resolves.toEqual({ ok: true })
|
|
expect(fetchCallCount()).toBe(1)
|
|
for (const [, execOptions] of gitExecFileAsyncMock.mock.calls) {
|
|
expect(execOptions).toMatchObject({ cwd: '/priority-repo', ...options })
|
|
}
|
|
})
|
|
)
|
|
|
|
beforeEach(() => {
|
|
gitExecFileAsyncMock.mockReset()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('evicts the in-flight Map entry on rejection so the next caller re-fetches', async () => {
|
|
// First call rejects, second call resolves. Without §3.3 Lifecycle
|
|
// `.finally()` eviction, the second caller would await the rejected
|
|
// promise forever (or throw the same error) — the regression pattern
|
|
// described in §3.3.
|
|
mockFetchResults([Promise.reject(new Error('network down')), { stdout: '', stderr: '' }])
|
|
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
await runtime.fetchRemoteWithCache('/repo/a', 'origin')
|
|
await runtime.fetchRemoteWithCache('/repo/a', 'origin')
|
|
|
|
expect(fetchCallCount()).toBe(2)
|
|
})
|
|
|
|
it('does not advance the freshness timestamp when the fetch rejects', async () => {
|
|
// A rejected fetch that wrote the timestamp would make the 30s freshness
|
|
// cache "lie" — the next caller would skip the fetch on a repo whose
|
|
// last real sync is unknown. §3.3 mandates success-only writes.
|
|
mockFetchResults([Promise.reject(new Error('boom')), { stdout: '', stderr: '' }])
|
|
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
await runtime.fetchRemoteWithCache('/repo/b', 'origin')
|
|
// Immediately call again — if the freshness window were armed we would
|
|
// short-circuit and skip the fetch. It must still dispatch a real fetch.
|
|
await runtime.fetchRemoteWithCache('/repo/b', 'origin')
|
|
|
|
expect(fetchCallCount()).toBe(2)
|
|
})
|
|
|
|
it('serializes two concurrent callers onto a single git fetch', async () => {
|
|
// Two callers hitting the same repo+remote at the same time must share
|
|
// one underlying fetch. Without the in-flight Map they would each
|
|
// dispatch an independent `git fetch`, tripling the network load in the
|
|
// worst case (renderer create + dispatch probe + CLI create).
|
|
let resolveFetch!: () => void
|
|
const pending = new Promise<{ stdout: string; stderr: string }>((resolve) => {
|
|
resolveFetch = () => resolve({ stdout: '', stderr: '' })
|
|
})
|
|
mockFetchResults([pending])
|
|
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
const first = runtime.fetchRemoteWithCache('/repo/c', 'origin')
|
|
const second = runtime.fetchRemoteWithCache('/repo/c', 'origin')
|
|
|
|
// Allow both callers to register before we resolve. Each canonicalizes the
|
|
// repo key first, so the dispatch lands several microtasks in.
|
|
for (let tick = 0; tick < 8; tick += 1) {
|
|
await Promise.resolve()
|
|
}
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
resolveFetch()
|
|
await Promise.all([first, second])
|
|
|
|
expect(fetchCallCount()).toBe(1)
|
|
})
|
|
|
|
it('skips the fetch inside the 30s freshness window after a successful fetch', async () => {
|
|
mockFetchResults([{ stdout: '', stderr: '' }])
|
|
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
await runtime.fetchRemoteWithCache('/repo/d', 'origin')
|
|
await runtime.fetchRemoteWithCache('/repo/d', 'origin')
|
|
|
|
// Second call must short-circuit on the freshness window (no new exec).
|
|
expect(fetchCallCount()).toBe(1)
|
|
})
|
|
|
|
it('bounds process-lifetime fetch cache maps for churned repo paths', async () => {
|
|
mockFetchResults(Array.from({ length: 520 }, () => ({ stdout: '', stderr: '' })))
|
|
const runtime = new OrcaRuntimeService(null)
|
|
const caches = runtime as unknown as {
|
|
canonicalFetchKeyCache: Map<string, string>
|
|
fetchLastCompletedAt: Map<string, number>
|
|
}
|
|
|
|
for (let i = 0; i < 520; i += 1) {
|
|
await runtime.fetchRemoteWithCache(`/repo/cache-${i}`, 'origin')
|
|
}
|
|
|
|
expect(caches.canonicalFetchKeyCache.size).toBeLessThanOrEqual(512)
|
|
expect(caches.fetchLastCompletedAt.size).toBeLessThanOrEqual(512)
|
|
expect(caches.canonicalFetchKeyCache.has('/repo/cache-0::origin')).toBe(false)
|
|
expect(caches.fetchLastCompletedAt.has('/repo/cache-0::origin')).toBe(false)
|
|
})
|
|
|
|
it.each([
|
|
'main',
|
|
'a'.repeat(40),
|
|
'refs/remotes/main',
|
|
'',
|
|
'origin/',
|
|
'/main',
|
|
'refs/remotes/origin/',
|
|
'refs/remotes//main'
|
|
])(
|
|
'does not launch Git for a base without both remote and branch components: %s',
|
|
async (base) => {
|
|
const runtime = new OrcaRuntimeService(null)
|
|
await expect(runtime.resolveRemoteTrackingBase('/repo/e', base)).resolves.toBeNull()
|
|
await expect(
|
|
runtime.resolveRemoteTrackingBase('/repo/e', base, { wslDistro: 'Ubuntu' })
|
|
).resolves.toBeNull()
|
|
expect(gitExecFileAsyncMock).not.toHaveBeenCalled()
|
|
}
|
|
)
|
|
|
|
it('resolves remote-tracking bases with longest configured remote matching', async () => {
|
|
gitExecFileAsyncMock.mockResolvedValue({ stdout: 'foo\nfoo/bar\norigin\n', stderr: '' })
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
await expect(runtime.resolveRemoteTrackingBase('/repo/e', 'foo/bar/main')).resolves.toEqual({
|
|
remote: 'foo/bar',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/foo/bar/main',
|
|
base: 'foo/bar/main'
|
|
})
|
|
})
|
|
|
|
it('resolves full remote-tracking refs with longest configured remote matching', async () => {
|
|
gitExecFileAsyncMock.mockResolvedValue({ stdout: 'foo\nfoo/bar\norigin\n', stderr: '' })
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
await expect(
|
|
runtime.resolveRemoteTrackingBase('/repo/e', 'refs/remotes/foo/bar/main')
|
|
).resolves.toEqual({
|
|
remote: 'foo/bar',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/foo/bar/main',
|
|
base: 'foo/bar/main'
|
|
})
|
|
})
|
|
|
|
it('refreshes a remote-tracking base with an exact no-tags refspec', async () => {
|
|
mockFetchResults([{ stdout: '', stderr: '' }])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
await runtime.getOrStartRemoteTrackingBaseRefresh('/repo/f', {
|
|
remote: 'origin',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/origin/main',
|
|
base: 'origin/main'
|
|
})
|
|
|
|
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(
|
|
exactBaseRefreshArgs(),
|
|
exactBaseRefreshOptions('/repo/f')
|
|
)
|
|
})
|
|
|
|
it('keeps automatic maintenance enabled for ordinary full remote fetches', async () => {
|
|
mockFetchResults([{ stdout: '', stderr: '' }])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
|
|
await runtime.getOrStartRemoteFetch('/repo/full-maintenance', 'origin')
|
|
|
|
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(
|
|
['fetch', 'origin'],
|
|
fullRemoteFetchOptions('/repo/full-maintenance')
|
|
)
|
|
})
|
|
|
|
it('shares an in-flight remote-tracking base refresh and reuses exact-base freshness', async () => {
|
|
let resolveFetch!: () => void
|
|
const pending = new Promise<{ stdout: string; stderr: string }>((resolve) => {
|
|
resolveFetch = () => resolve({ stdout: '', stderr: '' })
|
|
})
|
|
mockFetchResults([pending, { stdout: '', stderr: '' }])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
const base = {
|
|
remote: 'origin',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/origin/main',
|
|
base: 'origin/main'
|
|
}
|
|
|
|
const first = runtime.getOrStartRemoteTrackingBaseRefresh('/repo/g', base)
|
|
const second = runtime.getOrStartRemoteTrackingBaseRefresh('/repo/g', base)
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
resolveFetch()
|
|
await Promise.all([first, second])
|
|
await runtime.getOrStartRemoteTrackingBaseRefresh('/repo/g', base)
|
|
|
|
expect(fetchCallCount()).toBe(1)
|
|
})
|
|
|
|
it('does not advance exact-base freshness when a remote-tracking refresh fails', async () => {
|
|
mockFetchResults([Promise.reject(new Error('network down')), { stdout: '', stderr: '' }])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
const base = {
|
|
remote: 'origin',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/origin/main',
|
|
base: 'origin/main'
|
|
}
|
|
|
|
await expect(
|
|
runtime.getOrStartRemoteTrackingBaseRefresh('/repo/g-fail', base)
|
|
).resolves.toEqual({
|
|
ok: false,
|
|
errorKind: 'git_error'
|
|
})
|
|
await expect(
|
|
runtime.getOrStartRemoteTrackingBaseRefresh('/repo/g-fail', base)
|
|
).resolves.toEqual({ ok: true })
|
|
|
|
expect(fetchCallCount()).toBe(2)
|
|
})
|
|
|
|
it('does not treat a recent full remote fetch as exact-base freshness', async () => {
|
|
mockFetchResults([
|
|
{ stdout: '', stderr: '' },
|
|
{ stdout: '', stderr: '' }
|
|
])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
const base = {
|
|
remote: 'origin',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/origin/main',
|
|
base: 'origin/main'
|
|
}
|
|
|
|
await runtime.getOrStartRemoteFetch('/repo/g-full', 'origin')
|
|
await expect(
|
|
runtime.getOrStartRemoteTrackingBaseRefresh('/repo/g-full', base)
|
|
).resolves.toEqual({ ok: true })
|
|
|
|
expect(fetchCallCount()).toBe(2)
|
|
})
|
|
|
|
it('queues a full remote fetch behind an in-flight remote-tracking base refresh', async () => {
|
|
let resolveBaseFetch!: () => void
|
|
let resolveFullFetch!: () => void
|
|
const pendingBaseFetch = new Promise<{ stdout: string; stderr: string }>((resolve) => {
|
|
resolveBaseFetch = () => resolve({ stdout: '', stderr: '' })
|
|
})
|
|
const pendingFullFetch = new Promise<{ stdout: string; stderr: string }>((resolve) => {
|
|
resolveFullFetch = () => resolve({ stdout: '', stderr: '' })
|
|
})
|
|
mockFetchResults([pendingBaseFetch, pendingFullFetch])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
const base = {
|
|
remote: 'origin',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/origin/main',
|
|
base: 'origin/main'
|
|
}
|
|
|
|
const baseRefresh = runtime.getOrStartRemoteTrackingBaseRefresh('/repo/h', base)
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
const fullFetch = runtime.getOrStartRemoteFetch('/repo/h', 'origin')
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
resolveBaseFetch()
|
|
await vi.waitFor(() => expect(fetchCallCount()).toBe(2))
|
|
resolveFullFetch()
|
|
|
|
await expect(Promise.all([baseRefresh, fullFetch])).resolves.toEqual([
|
|
{ ok: true },
|
|
{ ok: true }
|
|
])
|
|
const fetchCalls = gitExecFileAsyncMock.mock.calls.filter(([argv]) => isFetchArgs(argv))
|
|
expect(fetchCalls).toEqual([
|
|
[exactBaseRefreshArgs(), exactBaseRefreshOptions('/repo/h')],
|
|
[['fetch', 'origin'], fullRemoteFetchOptions('/repo/h')]
|
|
])
|
|
})
|
|
|
|
it('runs a queued exact base refresh after an in-flight full remote fetch succeeds', async () => {
|
|
let resolveFullFetch!: () => void
|
|
let resolveBaseFetch!: () => void
|
|
const pendingFullFetch = new Promise<{ stdout: string; stderr: string }>((resolve) => {
|
|
resolveFullFetch = () => resolve({ stdout: '', stderr: '' })
|
|
})
|
|
const pendingBaseFetch = new Promise<{ stdout: string; stderr: string }>((resolve) => {
|
|
resolveBaseFetch = () => resolve({ stdout: '', stderr: '' })
|
|
})
|
|
mockFetchResults([pendingFullFetch, pendingBaseFetch])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
const base = {
|
|
remote: 'origin',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/origin/main',
|
|
base: 'origin/main'
|
|
}
|
|
|
|
const fullFetch = runtime.getOrStartRemoteFetch('/repo/i', 'origin')
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
const baseRefresh = runtime.getOrStartRemoteTrackingBaseRefresh('/repo/i', base)
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
resolveFullFetch()
|
|
await vi.waitFor(() => expect(fetchCallCount()).toBe(2))
|
|
resolveBaseFetch()
|
|
|
|
await expect(Promise.all([fullFetch, baseRefresh])).resolves.toEqual([
|
|
{ ok: true },
|
|
{ ok: true }
|
|
])
|
|
const fetchCalls = gitExecFileAsyncMock.mock.calls.filter(([argv]) => isFetchArgs(argv))
|
|
expect(fetchCalls).toEqual([
|
|
[['fetch', 'origin'], fullRemoteFetchOptions('/repo/i')],
|
|
[exactBaseRefreshArgs(), exactBaseRefreshOptions('/repo/i')]
|
|
])
|
|
})
|
|
|
|
it('runs a queued exact base refresh when an in-flight full remote fetch fails', async () => {
|
|
let rejectFullFetch!: () => void
|
|
let resolveBaseFetch!: () => void
|
|
const pendingFullFetch = new Promise<{ stdout: string; stderr: string }>((_resolve, reject) => {
|
|
rejectFullFetch = () => reject(new Error('network unavailable'))
|
|
})
|
|
const pendingBaseFetch = new Promise<{ stdout: string; stderr: string }>((resolve) => {
|
|
resolveBaseFetch = () => resolve({ stdout: '', stderr: '' })
|
|
})
|
|
mockFetchResults([pendingFullFetch, pendingBaseFetch])
|
|
const runtime = new OrcaRuntimeService(null)
|
|
const base = {
|
|
remote: 'origin',
|
|
branch: 'main',
|
|
ref: 'refs/remotes/origin/main',
|
|
base: 'origin/main'
|
|
}
|
|
|
|
const fullFetch = runtime.getOrStartRemoteFetch('/repo/i-fail', 'origin')
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
const baseRefresh = runtime.getOrStartRemoteTrackingBaseRefresh('/repo/i-fail', base)
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(fetchCallCount()).toBe(1)
|
|
|
|
rejectFullFetch()
|
|
await vi.waitFor(() => expect(fetchCallCount()).toBe(2))
|
|
resolveBaseFetch()
|
|
|
|
await expect(Promise.all([fullFetch, baseRefresh])).resolves.toEqual([
|
|
{ ok: false, errorKind: 'git_error' },
|
|
{ ok: true }
|
|
])
|
|
const fetchCalls = gitExecFileAsyncMock.mock.calls.filter(([argv]) => isFetchArgs(argv))
|
|
expect(fetchCalls).toEqual([
|
|
[['fetch', 'origin'], fullRemoteFetchOptions('/repo/i-fail')],
|
|
[exactBaseRefreshArgs(), exactBaseRefreshOptions('/repo/i-fail')]
|
|
])
|
|
})
|
|
})
|