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.
244 lines
7.9 KiB
TypeScript
244 lines
7.9 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import type { Store } from './persistence'
|
|
import type { Project } from '../shared/project-types'
|
|
import type { Repo } from '../shared/repo-types'
|
|
import {
|
|
getLocalProjectGitExecOptions,
|
|
getWorktreeCreatePrefetchGitOptions,
|
|
getWorktreeMirrorDistro,
|
|
resolveLocalProjectRuntimeForRepo
|
|
} from './project-runtime-git-options'
|
|
import { _resetWslCachesForTests, _setWslCachesForTests } from './wsl'
|
|
|
|
function withPlatform<T>(platform: NodeJS.Platform, run: () => T): T {
|
|
const originalPlatform = process.platform
|
|
Object.defineProperty(process, 'platform', {
|
|
configurable: true,
|
|
value: platform
|
|
})
|
|
try {
|
|
return run()
|
|
} finally {
|
|
Object.defineProperty(process, 'platform', {
|
|
configurable: true,
|
|
value: originalPlatform
|
|
})
|
|
}
|
|
}
|
|
|
|
function makeRepo(overrides: Partial<Repo> = {}): Repo {
|
|
return {
|
|
id: 'repo-1',
|
|
displayName: 'Repo',
|
|
path: String.raw`C:\repo`,
|
|
badgeColor: '#000000',
|
|
addedAt: 0,
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
function makeProject(overrides: Partial<Project> = {}): Project {
|
|
return {
|
|
id: 'project-1',
|
|
displayName: 'Project',
|
|
badgeColor: '#000000',
|
|
sourceRepoIds: ['repo-1'],
|
|
createdAt: 0,
|
|
updatedAt: 0,
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
function makeStore(project: Project): Store {
|
|
return {
|
|
getProjects: () => [project],
|
|
getSettings: () => ({ localWindowsRuntimeDefault: { kind: 'windows-host' } })
|
|
} as unknown as Store
|
|
}
|
|
|
|
describe('project runtime git options', () => {
|
|
afterEach(() => {
|
|
_resetWslCachesForTests()
|
|
})
|
|
|
|
it('does not probe or repair WSL git routing before capability caches exist', () => {
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
const options = withPlatform('win32', () =>
|
|
getLocalProjectGitExecOptions(makeStore(project), makeRepo())
|
|
)
|
|
|
|
expect(options).toEqual({ cwd: String.raw`C:\repo`, wslDistro: 'Ubuntu' })
|
|
})
|
|
|
|
it('returns repair state for missing cached WSL distro before local git execution', () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Debian'] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
const runtime = withPlatform('win32', () =>
|
|
resolveLocalProjectRuntimeForRepo(makeStore(project), makeRepo())
|
|
)
|
|
|
|
expect(runtime).toEqual({
|
|
status: 'repair-required',
|
|
repair: {
|
|
projectId: 'project-1',
|
|
preferredRuntime: { kind: 'wsl', distro: 'Ubuntu' },
|
|
reason: 'wsl-distro-missing',
|
|
source: 'project-override',
|
|
cacheKey: 'project-1:repair:wsl-distro-missing:Ubuntu'
|
|
}
|
|
})
|
|
expect(() =>
|
|
withPlatform('win32', () => getLocalProjectGitExecOptions(makeStore(project), makeRepo()))
|
|
).toThrow('Project runtime requires repair before git execution: wsl-distro-missing')
|
|
})
|
|
|
|
it('returns repair state for cached WSL unavailable before local git execution', () => {
|
|
_setWslCachesForTests({ available: false, distros: [] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
expect(() =>
|
|
withPlatform('win32', () => getLocalProjectGitExecOptions(makeStore(project), makeRepo()))
|
|
).toThrow('Project runtime requires repair before git execution: wsl-unavailable')
|
|
})
|
|
|
|
it('keeps project host override on host even when cached WSL is unavailable', () => {
|
|
_setWslCachesForTests({ available: false, distros: [] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'windows-host' }
|
|
})
|
|
|
|
const options = withPlatform('win32', () =>
|
|
getLocalProjectGitExecOptions(makeStore(project), makeRepo())
|
|
)
|
|
|
|
expect(options).toEqual({ cwd: String.raw`C:\repo` })
|
|
})
|
|
|
|
it('does not apply local Windows runtime routing to SSH-owned repos', () => {
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
const runtime = withPlatform('win32', () =>
|
|
resolveLocalProjectRuntimeForRepo(
|
|
makeStore(project),
|
|
makeRepo({ connectionId: null, executionHostId: 'ssh:target-1' })
|
|
)
|
|
)
|
|
|
|
expect(runtime).toBeUndefined()
|
|
})
|
|
|
|
describe('getWorktreeMirrorDistro', () => {
|
|
it('names the distro a resolved WSL project runs in', () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Ubuntu'] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
expect(
|
|
withPlatform('win32', () => getWorktreeMirrorDistro(makeStore(project), makeRepo()))
|
|
).toBe('Ubuntu')
|
|
})
|
|
|
|
it('names no distro for a host-runtime project', () => {
|
|
const project = makeProject({ localWindowsRuntimePreference: { kind: 'windows-host' } })
|
|
|
|
expect(
|
|
withPlatform('win32', () => getWorktreeMirrorDistro(makeStore(project), makeRepo()))
|
|
).toBeUndefined()
|
|
})
|
|
|
|
// Placement must not throw where git execution does: a project awaiting
|
|
// repair still gets a worktree, on the Windows side as it always has.
|
|
it('names no distro instead of throwing when the runtime needs repair', () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Debian'] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
expect(
|
|
withPlatform('win32', () => getWorktreeMirrorDistro(makeStore(project), makeRepo()))
|
|
).toBeUndefined()
|
|
})
|
|
|
|
it('names no distro when the store cannot resolve projects', () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Ubuntu'] })
|
|
|
|
expect(withPlatform('win32', () => getWorktreeMirrorDistro({}, makeRepo()))).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('getWorktreeCreatePrefetchGitOptions', () => {
|
|
it('routes the warm-up through the distro a resolved WSL project runs in', () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Ubuntu'] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
expect(
|
|
withPlatform('win32', () =>
|
|
getWorktreeCreatePrefetchGitOptions(makeStore(project), makeRepo())
|
|
)
|
|
).toEqual({ wslDistro: 'Ubuntu' })
|
|
})
|
|
|
|
// A speculative warm-up must degrade to the host Git it used before routing
|
|
// existed, never surface the repair state git execution raises.
|
|
it('falls back to host git instead of throwing when the runtime needs repair', () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Debian'] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
expect(
|
|
withPlatform('win32', () =>
|
|
getWorktreeCreatePrefetchGitOptions(makeStore(project), makeRepo())
|
|
)
|
|
).toEqual({})
|
|
})
|
|
|
|
it('does not resolve a project runtime for folder workspaces', () => {
|
|
_setWslCachesForTests({ available: true, distros: ['Ubuntu'] })
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
const store = makeStore(project)
|
|
const getProjects = vi.fn(store.getProjects)
|
|
|
|
expect(
|
|
withPlatform('win32', () =>
|
|
getWorktreeCreatePrefetchGitOptions(
|
|
{ ...store, getProjects } as unknown as Store,
|
|
makeRepo({ kind: 'folder' })
|
|
)
|
|
)
|
|
).toEqual({})
|
|
expect(getProjects).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
it('does not apply local Windows runtime routing to runtime-owned repos', () => {
|
|
const project = makeProject({
|
|
localWindowsRuntimePreference: { kind: 'wsl', distro: 'Ubuntu' }
|
|
})
|
|
|
|
const runtime = withPlatform('win32', () =>
|
|
resolveLocalProjectRuntimeForRepo(
|
|
makeStore(project),
|
|
makeRepo({ connectionId: null, executionHostId: 'runtime:env-1' })
|
|
)
|
|
)
|
|
|
|
expect(runtime).toBeUndefined()
|
|
})
|
|
})
|