diff --git a/src/main/runtime/fetch-remote-cache.test.ts b/src/main/runtime/fetch-remote-cache.test.ts index 1ece9c24eac..ea691434295 100644 --- a/src/main/runtime/fetch-remote-cache.test.ts +++ b/src/main/runtime/fetch-remote-cache.test.ts @@ -218,4 +218,50 @@ describe('OrcaRuntimeService.fetchRemoteWithCache', () => { [['fetch', 'origin'], { cwd: '/repo/h' }] ]) }) + + it('queues an exact base refresh behind an in-flight full remote fetch', 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]) => Array.isArray(argv) && argv[0] === 'fetch' + ) + expect(fetchCalls).toEqual([ + [['fetch', 'origin'], { cwd: '/repo/i' }], + [ + ['fetch', '--no-tags', 'origin', '+refs/heads/main:refs/remotes/origin/main'], + { cwd: '/repo/i' } + ] + ]) + }) }) diff --git a/src/main/runtime/orca-runtime.ts b/src/main/runtime/orca-runtime.ts index dec6a9226b8..5d47de27ddf 100644 --- a/src/main/runtime/orca-runtime.ts +++ b/src/main/runtime/orca-runtime.ts @@ -6038,11 +6038,6 @@ export class OrcaRuntimeService { base: RemoteTrackingBase ): Promise { const remoteKey = await this.getCanonicalFetchKey(repoPath, base.remote) - const existingRemoteFetch = this.fetchInflight.get(remoteKey) - if (existingRemoteFetch) { - return existingRemoteFetch - } - const key = await this.getCanonicalFetchKey(repoPath, `base:${base.remote}:${base.branch}`) const existing = this.fetchInflight.get(key) if (existing) {