mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
The speculative warm-up that runs while the create composer is open resolved
refs and fetched with host Git even when the project's runtime is a WSL distro,
while both the checkout preparation it feeds (`prepareWorktreeCreateForRepo`,
which already resolves `{ wslDistro }` itself) and the real create path run
inside the distro.
The concrete cost was a discarded fetch: `getCanonicalFetchKey` namespaces the
runtime's remote-fetch cache `wsl:<distro>` vs `local`, so the warm-up's fetch
landed in a namespace create never looks at, and create fetched again. On a
Windows host with no usable host-side Git the probes also failed outright, so
that cohort got no warm-up at all.
Thread the project's worktree Git options through the prefetch (resolved by a
non-throwing helper, because an optimistic warm-up must not surface a
repair-required runtime as a failure) so every probe and fetch runs where create
runs. `gitOptions` is a required argument, so a caller cannot drop the routing
silently. Host-routed calls keep their original arity, so macOS, Linux,
native-Windows-host projects, SSH repos and folder workspaces are unchanged.
Narrower than it looks: for a repo under \\wsl.localhost\<distro>\... the probes
were already routed by cwd, and for a repo on a Windows drive letter host Git
and WSL Git read the same on-disk repository, so the answers were already
correct there. What those cohorts gain is a fetch create can reuse; what they
pay is that the probes now run inside the distro (over /mnt/c for drive-letter
repos, which also newly arms the linked-worktree routing probe) and the
speculative fetch now shares create's per-remote fetch queue, as it always has
on native platforms.
Also collapse the three byte-equivalent copies of `hasLocalWorktreeBaseRef`
(create, prefetch, remote-repo create) into one in
git/worktree-base-ref-probe.ts, drop the host-only `hasLocalCommitObject` that
caused the routing bug, and add the first routing assertions on the create-path
consumers of the now-shared probe.
122 lines
4.2 KiB
TypeScript
122 lines
4.2 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import type * as WorktreeCreatePreparation from '../worktree-create-preparation'
|
|
import type { Project } from '../../shared/project-types'
|
|
import type { Repo } from '../../shared/repo-types'
|
|
import { _resetWslCachesForTests, _setWslCachesForTests } from '../wsl'
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
prefetchWorktreeCreateBase: vi.fn(),
|
|
prepareWorktreeCreateForRepo: vi.fn()
|
|
}))
|
|
|
|
vi.mock('../worktree-create-base-prefetch', () => ({
|
|
prefetchWorktreeCreateBase: mocks.prefetchWorktreeCreateBase
|
|
}))
|
|
vi.mock('../worktree-create-preparation', async (importOriginal) => ({
|
|
...(await importOriginal<typeof WorktreeCreatePreparation>()),
|
|
prepareWorktreeCreateForRepo: mocks.prepareWorktreeCreateForRepo
|
|
}))
|
|
|
|
import { OrcaRuntimeService } from './orca-runtime'
|
|
|
|
const repo: Repo = {
|
|
id: 'repo-1',
|
|
displayName: 'Repo',
|
|
path: String.raw`C:\workspace\repo`,
|
|
badgeColor: '#000000',
|
|
addedAt: 0
|
|
}
|
|
|
|
const project: Project = {
|
|
id: 'project-1',
|
|
displayName: 'Project',
|
|
badgeColor: '#000000',
|
|
sourceRepoIds: ['repo-1'],
|
|
createdAt: 0,
|
|
updatedAt: 0,
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
}
|
|
|
|
function makeStore(overrides: Partial<Project> = {}): unknown {
|
|
return {
|
|
getRepos: () => [repo],
|
|
getRepo: (id: string) => (id === repo.id ? repo : undefined),
|
|
getProjects: () => [{ ...project, ...overrides }],
|
|
getSettings: () => ({ localWindowsRuntimeDefault: { kind: 'windows-host' } })
|
|
}
|
|
}
|
|
|
|
function setPlatform(platform: NodeJS.Platform): void {
|
|
Object.defineProperty(process, 'platform', { configurable: true, value: platform })
|
|
}
|
|
|
|
const hostPlatform = process.platform
|
|
|
|
beforeEach(() => {
|
|
mocks.prefetchWorktreeCreateBase.mockReset().mockResolvedValue(undefined)
|
|
mocks.prepareWorktreeCreateForRepo.mockReset().mockResolvedValue(undefined)
|
|
})
|
|
|
|
afterEach(() => {
|
|
setPlatform(hostPlatform)
|
|
_resetWslCachesForTests()
|
|
})
|
|
|
|
// The RPC/relay prefetch is the only warm-up a remote client reaches, so it has
|
|
// to resolve the same project runtime the IPC handler does. Constructed through
|
|
// the barrel because the split chain resolves selectors in a later subclass.
|
|
describe('prefetchManagedWorktreeCreateBase (orca-runtime-get-worktree-terminal-provisioning-host)', () => {
|
|
it('warms up in the distro a WSL-routed project runs in', async () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Ubuntu'] })
|
|
setPlatform('win32')
|
|
const runtime = new OrcaRuntimeService(makeStore() as never)
|
|
|
|
await runtime.prefetchManagedWorktreeCreateBase({ repoSelector: 'repo-1' })
|
|
|
|
expect(mocks.prefetchWorktreeCreateBase).toHaveBeenCalledWith(
|
|
expect.objectContaining({ gitOptions: { wslDistro: 'Ubuntu' } })
|
|
)
|
|
})
|
|
|
|
it('warms up on host git when no project runtime routes the repo', async () => {
|
|
setPlatform('darwin')
|
|
const runtime = new OrcaRuntimeService(makeStore() as never)
|
|
|
|
await runtime.prefetchManagedWorktreeCreateBase({ repoSelector: 'repo-1' })
|
|
|
|
expect(mocks.prefetchWorktreeCreateBase).toHaveBeenCalledWith(
|
|
expect.objectContaining({ gitOptions: {} })
|
|
)
|
|
})
|
|
|
|
// A repair-required runtime must degrade to host git, not fail the warm-up.
|
|
it('does not surface a repair-required project runtime as a prefetch failure', async () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Debian'] })
|
|
setPlatform('win32')
|
|
const runtime = new OrcaRuntimeService(makeStore() as never)
|
|
|
|
await expect(
|
|
runtime.prefetchManagedWorktreeCreateBase({ repoSelector: 'repo-1' })
|
|
).resolves.toBeUndefined()
|
|
|
|
expect(mocks.prefetchWorktreeCreateBase).toHaveBeenCalledWith(
|
|
expect.objectContaining({ gitOptions: {} })
|
|
)
|
|
})
|
|
|
|
it('prepares the checkout the prefetch resolved', async () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Ubuntu'] })
|
|
setPlatform('win32')
|
|
mocks.prefetchWorktreeCreateBase.mockResolvedValue('origin/main')
|
|
const runtime = new OrcaRuntimeService(makeStore() as never)
|
|
|
|
await runtime.prefetchManagedWorktreeCreateBase({ repoSelector: 'repo-1' })
|
|
|
|
expect(mocks.prepareWorktreeCreateForRepo).toHaveBeenCalledWith(
|
|
expect.anything(),
|
|
repo,
|
|
'origin/main'
|
|
)
|
|
})
|
|
})
|