mirror of
https://github.com/stablyai/orca.git
synced 2026-09-23 16:02:24 +00:00
* fix(worktrees): stop surfacing prunable git worktrees as live workspaces A worktree still registered in git but whose directory was deleted (git's `prunable` state) was enumerated as a normal workspace, producing repeated pty:spawn DaemonProtocolError / fs:readDir ENOENT loops and a blank pane. - Parse the `prunable` porcelain field (Git >= 2.36) in both the main and relay worktree-list parsers. - For Git < 2.36 (no `prunable` field), probe each linked worktree path for existence on the fallback line-block path, skipping locked registrations to mirror git's own prunable rules. - Omit prunable worktrees from the detected-workspace enumeration only; removal/cleanup flows keep seeing them. - Extend the real-binary compatibility contract with the 2.36 `prunable` boundary. Fixes #8389 Claude-Session: https://claude.ai/code/session_018Rg1Bpq4GGwmz613hq6RSD * fix(worktrees): pin the prunable/locked porcelain annotations to their real Git 2.31 boundary The prunable and locked annotations landed in Git 2.31, five releases before `worktree list -z` (2.36); only -z defines the capability fallback boundary. Correct the compatibility contract so a future matrix entry in the 2.31-2.35 range passes, and reword the fallback comments: on 2.31-2.35 the annotations still parse and the existence probe is a backstop; only Git <2.31 relies on it outright. * fix(worktrees): omit prunable registrations from the Space scan A prunable registration has no directory to size or reclaim, so Space rendered it as a dead "Missing" row whose checkbox stayed disabled with no prune/remove affordance (reported on macOS after a reboot cleared /private/tmp under 16 registrations). Skip prunable entries in the scan, matching the workspace enumeration; removal flows list worktrees separately and still see them. --------- Co-authored-by: kaynan <kaynan.camargo@terceiro-sky.com.br> Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
177 lines
6.3 KiB
TypeScript
177 lines
6.3 KiB
TypeScript
import { execFile } from 'node:child_process'
|
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { promisify } from 'node:util'
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
import {
|
|
isUnsupportedMergeTreeMergeBaseError,
|
|
isUnsupportedMergeTreeWriteTreeError
|
|
} from './git-merge-tree-capability'
|
|
import { isForEachRefExcludeUnsupportedError } from './git-ref-command-capabilities'
|
|
import {
|
|
hasUnsupportedRevParsePathFormatEcho,
|
|
isUnsupportedWorktreeListZError
|
|
} from './git-worktree-command-capabilities'
|
|
import { gitCredentialPromptGuardEnv } from './git-credential-prompt-env'
|
|
|
|
const execFileAsync = promisify(execFile)
|
|
const image = process.env.ORCA_GIT_COMPAT_IMAGE
|
|
const binary = process.env.ORCA_GIT_COMPAT_BINARY
|
|
const expectedVersion = process.env.ORCA_GIT_COMPAT_VERSION
|
|
const describeBinaryCompatibility = image || binary ? describe : describe.skip
|
|
|
|
type GitResult = { stdout: string; stderr: string }
|
|
|
|
describeBinaryCompatibility('real Git binary compatibility', () => {
|
|
let repoPath = ''
|
|
let version = { major: 0, minor: 0 }
|
|
|
|
async function runGit(args: string[], env?: NodeJS.ProcessEnv): Promise<GitResult> {
|
|
if (image) {
|
|
const dockerUser =
|
|
typeof process.getuid === 'function' && typeof process.getgid === 'function'
|
|
? ['--user', `${process.getuid()}:${process.getgid()}`]
|
|
: []
|
|
return execFileAsync(
|
|
'docker',
|
|
[
|
|
'run',
|
|
'--rm',
|
|
'--network=none',
|
|
...dockerUser,
|
|
...Object.entries(env ?? {}).flatMap(([key, value]) =>
|
|
value === undefined ? [] : ['--env', `${key}=${value}`]
|
|
),
|
|
'-v',
|
|
`${repoPath}:/repo`,
|
|
'-w',
|
|
'/repo',
|
|
image,
|
|
'-c',
|
|
'safe.directory=/repo',
|
|
...args
|
|
],
|
|
{ maxBuffer: 2 * 1024 * 1024 }
|
|
)
|
|
}
|
|
return execFileAsync(binary!, args, {
|
|
cwd: repoPath,
|
|
env: env ? { ...process.env, ...env } : undefined,
|
|
maxBuffer: 2 * 1024 * 1024
|
|
})
|
|
}
|
|
|
|
function supports(major: number, minor: number): boolean {
|
|
return version.major > major || (version.major === major && version.minor >= minor)
|
|
}
|
|
|
|
async function expectPreferredOrRecognizedFallback(
|
|
args: string[],
|
|
expectedSupport: boolean,
|
|
recognizesUnsupported: (error: unknown) => boolean
|
|
): Promise<void> {
|
|
try {
|
|
await runGit(args)
|
|
expect(expectedSupport).toBe(true)
|
|
} catch (error) {
|
|
expect(expectedSupport).toBe(false)
|
|
expect(recognizesUnsupported(error)).toBe(true)
|
|
}
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
repoPath = await mkdtemp(join(tmpdir(), 'orca-git-binary-compat-'))
|
|
const versionOutput = await runGit(['--version'])
|
|
expect(versionOutput.stdout).toContain(`git version ${expectedVersion}`)
|
|
const match = versionOutput.stdout.match(/git version (\d+)\.(\d+)/)
|
|
expect(match).not.toBeNull()
|
|
version = { major: Number(match![1]), minor: Number(match![2]) }
|
|
|
|
await runGit(['init', '-q'])
|
|
await runGit(['config', 'user.email', 'compatibility@example.invalid'])
|
|
await runGit(['config', 'user.name', 'Compatibility Test'])
|
|
await writeFile(join(repoPath, 'tracked.txt'), 'compatibility\n')
|
|
await runGit(['add', 'tracked.txt'])
|
|
await runGit(['commit', '-qm', 'initial'])
|
|
})
|
|
|
|
afterAll(async () => {
|
|
if (repoPath) {
|
|
await rm(repoPath, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('recognizes worktree-list and rev-parse compatibility boundaries', async () => {
|
|
await expectPreferredOrRecognizedFallback(
|
|
['worktree', 'list', '--porcelain', '-z'],
|
|
supports(2, 36),
|
|
isUnsupportedWorktreeListZError
|
|
)
|
|
await expect(runGit(['worktree', 'list', '--porcelain'])).resolves.toMatchObject({
|
|
stdout: expect.stringContaining('worktree ')
|
|
})
|
|
|
|
// Why: the `prunable` porcelain annotation landed in Git 2.31 — five
|
|
// releases before `-z` (2.36) — so only Git <2.31 emits neither and needs
|
|
// Orca's path-existence fallback (issue #8389).
|
|
await runGit(['worktree', 'add', '-b', 'compat-stale', 'stale-wt'])
|
|
await rm(join(repoPath, 'stale-wt'), { recursive: true, force: true })
|
|
const staleList = await runGit(['worktree', 'list', '--porcelain'])
|
|
expect(staleList.stdout.includes('prunable')).toBe(supports(2, 31))
|
|
|
|
const preferred = await runGit([
|
|
'rev-parse',
|
|
'--path-format=absolute',
|
|
'--show-toplevel',
|
|
'--git-common-dir'
|
|
])
|
|
expect(hasUnsupportedRevParsePathFormatEcho(preferred.stdout)).toBe(!supports(2, 31))
|
|
await expect(
|
|
runGit(['rev-parse', '--show-toplevel', '--git-common-dir'])
|
|
).resolves.toBeDefined()
|
|
})
|
|
|
|
it('recognizes ref and merge-tree compatibility boundaries', async () => {
|
|
await expectPreferredOrRecognizedFallback(
|
|
['for-each-ref', '--format=%(refname)', '--exclude=refs/remotes/**/HEAD', '--count=10'],
|
|
supports(2, 42),
|
|
isForEachRefExcludeUnsupportedError
|
|
)
|
|
await expect(
|
|
runGit(['for-each-ref', '--format=%(refname)', '--count=10'])
|
|
).resolves.toBeDefined()
|
|
|
|
await expectPreferredOrRecognizedFallback(
|
|
['merge-tree', '--write-tree', 'HEAD', 'HEAD'],
|
|
supports(2, 38),
|
|
isUnsupportedMergeTreeWriteTreeError
|
|
)
|
|
if (supports(2, 38)) {
|
|
const head = (await runGit(['rev-parse', 'HEAD'])).stdout.trim()
|
|
const legacyArgs = ['merge-tree', '--write-tree', '--name-only', '-z', '--no-messages']
|
|
await expectPreferredOrRecognizedFallback(
|
|
[...legacyArgs, '--merge-base', head, head, head],
|
|
supports(2, 40),
|
|
isUnsupportedMergeTreeMergeBaseError
|
|
)
|
|
await expect(runGit([...legacyArgs, head, head])).resolves.toBeDefined()
|
|
}
|
|
})
|
|
|
|
it('degrades indexed credential config safely at the Git 2.31 boundary', async () => {
|
|
const guardEnv = gitCredentialPromptGuardEnv({}, 'linux')
|
|
await expect(runGit(['status', '--short'], guardEnv)).resolves.toBeDefined()
|
|
|
|
try {
|
|
const result = await runGit(['config', '--get', 'credential.interactive'], guardEnv)
|
|
expect(supports(2, 31)).toBe(true)
|
|
expect(result.stdout.trim()).toBe('false')
|
|
} catch {
|
|
// Git 2.25 ignores the indexed variables rather than rejecting commands;
|
|
// the scalar prompt guards still provide the baseline fail-fast behavior.
|
|
expect(supports(2, 31)).toBe(false)
|
|
}
|
|
})
|
|
})
|