Queue exact base refreshes during remote fetches

This commit is contained in:
Jinjing
2026-05-19 00:39:30 -07:00
parent a7f8eb7c5e
commit c053ed690a
2 changed files with 46 additions and 5 deletions
@@ -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' }
]
])
})
})
-5
View File
@@ -6038,11 +6038,6 @@ export class OrcaRuntimeService {
base: RemoteTrackingBase
): Promise<RemoteFetchResult> {
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) {