Files
orca/src/main/git/local-git-object-quarantine.test.ts
T
OrcaWinandOrcaWin 4687e90a16 [comment audit] Continue main-process comment cleanup (#32946)
* [comment audit] Shorten daemon, hook, and emulator comments [skip ci]

* [comment audit] Shorten VM, conversation, SQLite, and theme-import comments [skip ci]

* [comment audit] Tighten Git execution and source-control comment contracts [skip ci]

* [comment audit] Clarify repository probes and maintenance comments [skip ci]

* [comment audit] Shorten status, diff-cache, and checkout comments [skip ci]

* [comment audit] Clarify worktree lifecycle and WSL routing comments [skip ci]

* [comment audit] Shorten forge identity and review-refresh comments [skip ci]

* [comment audit] Tighten hosted-review client comment contracts [skip ci]

* [comment audit] Clarify GitLab compatibility and review comments [skip ci]

* [comment audit] Tighten hook ownership and watchdog rationale [skip ci]

* [comment audit] Condense host and integration compatibility comments [skip ci]

* [comment audit] Clarify IPC authority and remote-routing rationale [skip ci]

* [comment audit] Finalize file-import and containment comment cleanup

* [comment audit] Fix stale Jira type imports blocking full CI

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 16:27:37 -07:00

135 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type * as GitObjectQuarantineModule from '../../shared/git-object-quarantine'
import type { GitObjectQuarantine, GitObjectsDirectory } from '../../shared/git-object-quarantine'
import {
createLocalGitObjectQuarantine,
inheritedLocalObjectStore,
localGitObjectsDirectory
} from './local-git-object-quarantine'
import {
resetWslLinkedWorktreeGitRoutingForTests,
seedWslLinkedWorktreeGitRoutingForTests
} from './wsl-linked-worktree-git-routing'
const { readRepoCommonDirFromGitMock } = vi.hoisted(() => ({
readRepoCommonDirFromGitMock: vi.fn()
}))
vi.mock('./worktree-list-reader', () => ({
readRepoCommonDirFromGit: readRepoCommonDirFromGitMock
}))
vi.mock('../../shared/git-object-quarantine', async (importOriginal) => ({
...(await importOriginal<typeof GitObjectQuarantineModule>()),
createGitObjectQuarantine: (
resolve: () => Promise<GitObjectsDirectory | undefined>
): GitObjectQuarantine => ({
run: async (command) => {
const objects = await resolve()
return command(
objects
? {
GIT_OBJECT_DIRECTORY: `${objects.gitPath}/scratch`,
GIT_ALTERNATE_OBJECT_DIRECTORIES: objects.gitPath
}
: undefined
)
}
})
}))
describe('localGitObjectsDirectory', () => {
it('translates a WSL Git common dir into a path the Windows host can open', () => {
expect(localGitObjectsDirectory('/home/me/repo/.git', 'Ubuntu')).toEqual({
hostPath: '\\\\wsl.localhost\\Ubuntu\\home\\me\\repo\\.git\\objects',
gitPath: '/home/me/repo/.git/objects'
})
})
it('hands WSL Git the drvfs spelling of a drive-path common dir (Git < 2.31 prints it relative)', () => {
expect(localGitObjectsDirectory('C:\\repo\\.git', 'Ubuntu')).toEqual({
hostPath: 'C:\\repo\\.git\\objects',
gitPath: '/mnt/c/repo/.git/objects'
})
expect(localGitObjectsDirectory('/mnt/c/repo/.git', 'Ubuntu')).toEqual({
hostPath: 'C:\\repo\\.git\\objects',
gitPath: '/mnt/c/repo/.git/objects'
})
})
it('uses one spelling for native Git', () => {
expect(localGitObjectsDirectory('/Users/me/repo/.git', undefined)).toEqual({
hostPath: '/Users/me/repo/.git/objects',
gitPath: '/Users/me/repo/.git/objects'
})
expect(localGitObjectsDirectory('C:\\repo\\.git', undefined)).toEqual({
hostPath: 'C:\\repo\\.git\\objects',
gitPath: 'C:\\repo\\.git\\objects'
})
})
})
describe('createLocalGitObjectQuarantine on a Windows host', () => {
const originalPlatform = process.platform
beforeEach(() => {
Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })
resetWslLinkedWorktreeGitRoutingForTests()
readRepoCommonDirFromGitMock.mockReset()
})
afterEach(() => {
Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform })
resetWslLinkedWorktreeGitRoutingForTests()
})
const envSeenBy = (repoPath: string, options: { wslDistro?: string } = {}) =>
createLocalGitObjectQuarantine(repoPath, options).run(async (env) => env)
it('runs unquarantined when a WSL-authored linked worktree routes to Windows Git', async () => {
readRepoCommonDirFromGitMock.mockResolvedValue('/mnt/c/repo/.git')
seedWslLinkedWorktreeGitRoutingForTests('C:\\wt')
await expect(envSeenBy('C:\\wt', { wslDistro: 'Ubuntu' })).resolves.toBeUndefined()
})
})
describe('inheritedLocalObjectStore', () => {
const ALTERNATES = { GIT_ALTERNATE_OBJECT_DIRECTORIES: '/shared/objects' }
it('passes native Git’s inherited alternates on and refuses an inherited object dir', () => {
expect(inheritedLocalObjectStore(undefined, ALTERNATES, 'darwin')).toEqual({
inheritedAlternates: '/shared/objects'
})
expect(
inheritedLocalObjectStore(undefined, { GIT_OBJECT_DIRECTORY: 'C:\\objects' }, 'win32')
).toBeUndefined()
})
it('ignores Windows values WSLENV does not forward, since WSL Git never saw them', () => {
expect(inheritedLocalObjectStore('Ubuntu', ALTERNATES, 'win32')).toEqual({})
expect(
inheritedLocalObjectStore(
'Ubuntu',
{ WSLENV: 'GIT_OBJECT_DIRECTORY/p:GIT_ALTERNATE_OBJECT_DIRECTORIES' },
'win32'
)
).toEqual({})
expect(
inheritedLocalObjectStore('Ubuntu', { GIT_OBJECT_DIRECTORY: 'C:\\objects' }, 'win32')
).toEqual({})
})
it.each(['GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY/p'])(
'runs unquarantined when WSLENV forwards %s to WSL Git',
(token) => {
const env = {
GIT_ALTERNATE_OBJECT_DIRECTORIES: 'C:\\shared',
GIT_OBJECT_DIRECTORY: 'C:\\objects',
WSLENV: `ORCA_X/u:${token}`
}
expect(inheritedLocalObjectStore('Ubuntu', env, 'win32')).toBeUndefined()
}
)
})