Files
orca/src/relay/git-handler-utils.test.ts
T
Neil 860ee73a11 fix(git): parse sparse and cquoted paths on the SSH relay (#18389)
The relay carried its own copies of the worktree-list and unmerged-entry
porcelain parsers, and both had drifted from the desktop originals: the
relay copy had no `sparse` branch, so SSH sparse checkouts were never
marked, and it never C-quote-decoded a conflict path, so a conflicted file
with a space or non-ASCII byte was published under its raw quoted name and
probed as missing.

Move both parsers into src/shared and delete the relay copies, so there is
one implementation each. Type the relay's worktree-list plumbing on
GitWorktreeInfo instead of Record<string, unknown> so a field-copying step
can no longer silently drop a newly parsed field.

`isSparse` is a new optional field on the git.listWorktrees result
(remote-wire-compatibility Rule 1); Git <2.28 omits the porcelain line and
the field stays absent. No new git subcommand or option.

Closes #18280
2026-09-03 02:11:55 -07:00

32 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { isUnsupportedWorktreeListZError } from './git-handler-utils'
describe('isUnsupportedWorktreeListZError', () => {
it('detects an unknown-switch usage error from stderr when the exit code is absent', () => {
// Isolates the regex fallback: no numeric code, so only the stderr text
// (a runner that dropped the exit code) can classify the rejection.
const error = Object.assign(new Error('worktree list -z'), {
stderr: "error: unknown switch `z'\nusage: git worktree list [<options>]\n"
})
expect(isUnsupportedWorktreeListZError(error)).toBe(true)
})
it('detects a localized (non-English) usage error via exit code 129', () => {
// The SSH remote may run under a non-English locale where the stderr text is
// translated; the numeric exit code must still classify the -z rejection.
const error = Object.assign(new Error('worktree list -z'), {
code: 129,
stderr: 'Fehler: Unbekannter Schalter »z«\nAufruf: git worktree list [<Optionen>]\n'
})
expect(isUnsupportedWorktreeListZError(error)).toBe(true)
})
it('does not classify a fatal (exit 128) error as an unsupported -z rejection', () => {
const error = Object.assign(new Error('fatal'), {
code: 128,
stderr: 'fatal: unable to read tree\n'
})
expect(isUnsupportedWorktreeListZError(error)).toBe(false)
})
})