Files
orca/src/main/git/git-capability-state.test.ts
T
OrcaWinandm4air 4085e1cf60 fix(memory): release stale session registries (#21734)
* fix(memory): bound session and lifecycle registries

* fix(memory): bound transient filesystem registries

* fix(memory): cap path and locale caches

* fix(memory): bound runtime recovery registries

* fix(memory): bound host mirror gap verdicts

* fix(memory): bound shell startup env cache

* fix(memory): bound gitlab host context cache

* fix(memory): release removed ssh generations

* fix(memory): expire cloud refresh replay guards

* fix(memory): release retired plugin generations

* fix(memory): bound plugin log key retention

* fix(memory): bound automation authority generations

* fix(memory): bound native chat enrichment cache

* fix(memory): bound web session tracking generations

* fix(memory): bound codex credential absence paths

* fix(memory): bound WSL canonical path cache

* fix(memory): bound sparse checkout cache

* fix(memory): bound shared directory cache

* fix(memory): bound advertised URL scan snapshots

* fix(memory): bound automation manager cache

* fix(memory): bound web session reorder intents

* fix(memory): bound web session focus intents

* fix(memory): bound web session handoffs

* fix(memory): bound automation dispatch tokens

* fix(memory): bound host mirror waiters

* fix(memory): bound retained session activity

* fix(memory): bound retained session activity

* fix(memory): bound web session close intents

* fix(memory): bound cloud session cache

* fix(memory): bound WSL home cache

* fix(memory): bound SSH capability cache

* fix(memory): bound trust grant cooldowns

* fix(memory): bound WSL auth drain state

* fix(memory): bound Linear workspace credential cache

* fix(memory): bound local Git capability cache

* fix(memory): bound WSL Git environment cache

* fix(memory): bound WSL Git environment cache

* fix(memory): bound WSL preflight cache

* fix(memory): keep hot cache entries warm

* fix(memory): preserve generation fences across eviction

* fix(memory): close remaining eviction fences

* fix(memory): align evicted upstream generations

* fix(memory): trim successful capability probes

* fix(auth): retain expired refresh replay evidence

---------

Co-authored-by: m4air <m4air@Mac.localdomain>
2026-09-20 14:41:50 -07:00

89 lines
3.3 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { SshGitProvider } from '../providers/ssh-git-provider'
import {
clearGitCapabilityStateForTests,
getLocalGitCapabilityCache,
getSshGitCapabilityCache,
withLocalGitCapabilityCacheForExecution
} from './git-capability-state'
import {
resetWslLinkedWorktreeGitRoutingForTests,
seedWslLinkedWorktreeGitRoutingForTests
} from './wsl-linked-worktree-git-routing'
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the cache keys providers by reference only and never calls a method on them.
const createProviderIdentity = (): SshGitProvider => ({}) as SshGitProvider
describe('Git capability execution-host state', () => {
beforeEach(() => {
clearGitCapabilityStateForTests()
resetWslLinkedWorktreeGitRoutingForTests()
})
it('shares native state while isolating each WSL distro', () => {
expect(getLocalGitCapabilityCache({ cwd: '/repo-a' })).toBe(
getLocalGitCapabilityCache({ cwd: '/repo-b' })
)
expect(getLocalGitCapabilityCache({ wslDistro: 'Ubuntu' })).toBe(
getLocalGitCapabilityCache({ cwd: '\\\\wsl.localhost\\Ubuntu\\home\\repo' })
)
expect(getLocalGitCapabilityCache({ wslDistro: 'Ubuntu' })).not.toBe(
getLocalGitCapabilityCache({ wslDistro: 'Debian' })
)
expect(getLocalGitCapabilityCache()).not.toBe(
getLocalGitCapabilityCache({ wslDistro: 'Ubuntu' })
)
})
it('bounds local capability entries during WSL distro churn', () => {
const first = getLocalGitCapabilityCache({ wslDistro: 'first-distro' })
first.rememberUnsupported('worktree-list-z')
for (let index = 0; index < 132; index += 1) {
getLocalGitCapabilityCache({ wslDistro: `distro-${index}` })
}
expect(
getLocalGitCapabilityCache({ wslDistro: 'first-distro' }).shouldTry('worktree-list-z')
).toBe(true)
})
it('shares one SSH provider lifetime without leaking into a replacement provider', () => {
const provider = createProviderIdentity()
const replacementProvider = createProviderIdentity()
expect(getSshGitCapabilityCache(provider)).toBe(getSshGitCapabilityCache(provider))
expect(getSshGitCapabilityCache(provider)).not.toBe(
getSshGitCapabilityCache(replacementProvider)
)
})
it('uses native capability state for a prepared host-routed WSL worktree', async () => {
const platform = vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
try {
seedWslLinkedWorktreeGitRoutingForTests(String.raw`C:\repo\linked`)
await expect(
withLocalGitCapabilityCacheForExecution(
{ cwd: String.raw`C:\repo\linked`, wslDistro: 'Ubuntu' },
async (capabilities) => capabilities
)
).resolves.toBe(getLocalGitCapabilityCache())
expect(getLocalGitCapabilityCache()).not.toBe(
getLocalGitCapabilityCache({ wslDistro: 'Ubuntu' })
)
} finally {
platform.mockRestore()
}
})
it('starts non-candidate capability work without an added async turn', async () => {
let started = false
const result = withLocalGitCapabilityCacheForExecution({ cwd: '/repo' }, async () => {
started = true
return 'done'
})
expect(started).toBe(true)
await expect(result).resolves.toBe('done')
})
})