mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 10:37:35 +00:00
* [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>
135 lines
4.8 KiB
TypeScript
135 lines
4.8 KiB
TypeScript
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()
|
||
}
|
||
)
|
||
})
|