fix(#3103): only "no such process" means the owner is dead
Review found the previous commit fixed the wrong cliff. process.kill accepts a pid up to 2147483647 and throws a TypeError above it, so 2147483648 — an ordinary finite number — sailed past the finite check, threw, and was classified dead. Measured here: 2147483646 and 2147483647 raise ESRCH, 2147483648 and above raise ERR_INVALID_ARG_TYPE. The digit-length boundary the last commit pinned was a different, earlier gate, and its tests implied it was the meaningful one. The liveness helper now treats only ESRCH as dead. EPERM, a type error from an out-of-range pid, an error with no code at all — every outcome it does not recognise returns alive, because the value feeds a forced worktree removal and an unrecognised failure must never read as permission to delete. Against a build with the old catch, a lock holding 2147483648 reaps the worktree; with this one it is skipped and the directory survives. The finite check stays. It no longer carries the safety, but it still names garbage input accurately rather than reporting it as a live owner, and its comment now says that so it is not removed as redundant. The freshness verdict is split. An unreadable lock mtime and a genuinely recent lock both reported lock_too_fresh, which tells an operator to wait when waiting cannot help — the same conflation this module already separated for parse failures. The unreadable case is now lock_age_unknown. Only this module and its tests read these strings; no workflow or command consumes them. The dependency spread in the prune path is kept as it is, with a test that kills it. A caller-supplied porcelain parser displacing the default is the intended seam, not an accident: the parser is a declared member of the dependency type and the planner already prefers an injected one, so the hard-coded key restates the same default rather than guarding against override. Previously nothing exercised that line at all. Refs #3057 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -446,6 +446,17 @@ describe('#3057 W3: readConfigBaseBranch — config present but unusable', () =>
|
||||
});
|
||||
|
||||
test('config.json parses to a non-object → null for null / string / number / array', () => {
|
||||
// NOTE on the `[]` case: this documents observed behaviour only. It does
|
||||
// NOT pin the `Array.isArray(cfg)` guard in readConfigBaseBranch — that
|
||||
// guard is unreachable (and therefore unkillable) through this readFile
|
||||
// entry point. `cfg` is always the result of `JSON.parse(raw)` on a
|
||||
// string, and a JSON array can never carry a `.git` or `.base_branch`
|
||||
// own-property the way a hand-built JS array could; with the guard
|
||||
// deleted entirely, `top.git`/`top.base_branch` on an array are still
|
||||
// `undefined`, so the result is `null` either way. Verified by mutation:
|
||||
// deleting `|| Array.isArray(cfg)` from the built lib does not change any
|
||||
// output for any JSON-string input. The guard is real defense-in-depth
|
||||
// for a future non-JSON-string caller, not something this suite can pin.
|
||||
assert.strictEqual(readWith('null'), null, 'JSON null must not be treated as a config');
|
||||
assert.strictEqual(readWith('"master"'), null, 'a bare JSON string must not be treated as a config');
|
||||
assert.strictEqual(readWith('42'), null, 'a bare JSON number must not be treated as a config');
|
||||
@@ -461,7 +472,14 @@ describe('#3057 W3: readConfigBaseBranch — config present but unusable', () =>
|
||||
'a whitespace-only override must not win the precedence ladder');
|
||||
});
|
||||
|
||||
test('"git" key present but not an object → skipped, flat legacy key still consulted', () => {
|
||||
test('"git" key present but not a usable object (string/array/null) → nested lookup finds nothing, flat legacy key still consulted', () => {
|
||||
// NOTE on the `"git":[]` case: like the sibling note above, this does NOT
|
||||
// pin `!Array.isArray(gitSection)`. `gitSection` here is a JSON-parsed
|
||||
// array with no `.base_branch` own-property, so `gitSection.base_branch`
|
||||
// is `undefined` whether or not the guard runs — the flat key is
|
||||
// consulted either way. Verified by mutation: deleting
|
||||
// `&& !Array.isArray(gitSection)` from the built lib does not change this
|
||||
// output for any JSON-string input.
|
||||
assert.strictEqual(readWith('{"git":"main","base_branch":"release"}'), 'release');
|
||||
assert.strictEqual(readWith('{"git":[],"base_branch":"release"}'), 'release');
|
||||
assert.strictEqual(readWith('{"git":null,"base_branch":"release"}'), 'release');
|
||||
@@ -580,45 +598,18 @@ describe('#3057 W3: tryRemoteShow — tier-3 output that is present but not auth
|
||||
});
|
||||
|
||||
describe('#3057 W3: tryLocalBranch — non-empty stdout that names neither main nor master', () => {
|
||||
/**
|
||||
* An `execGit` stand-in whose result counts how many times `stdout` is read.
|
||||
* `tryLocalBranch` reads it once in the `!r.stdout` guard and a second time to
|
||||
* split it into lines. The read count therefore identifies WHICH null the
|
||||
* function returned: 1 read = the early guard fired; 2 reads = the guard was
|
||||
* passed and the final `return null` after the main/master checks ran.
|
||||
*/
|
||||
function countingGit(stdoutValue) {
|
||||
const state = { reads: 0 };
|
||||
const git = () => ({
|
||||
exitCode: 0,
|
||||
stderr: '',
|
||||
signal: null,
|
||||
error: null,
|
||||
timedOut: false,
|
||||
get stdout() { state.reads += 1; return stdoutValue; },
|
||||
});
|
||||
git.state = state;
|
||||
return git;
|
||||
}
|
||||
|
||||
test('stdout is exactly "\\n" → null, reached PAST the empty-stdout guard', () => {
|
||||
// This is the branch that was once deleted as "unreachable". The guard is
|
||||
// `if (r.exitCode !== 0 || !r.stdout) return null` — `"\n"` is a truthy
|
||||
// string, so the guard does NOT fire; `split('\n')` yields ["", ""], both
|
||||
// main/master checks are false, and the FINAL `return null` executes.
|
||||
// Deleting that line makes this function return `undefined`, which
|
||||
// strictEqual(null) catches. The read count proves which null we got.
|
||||
const git = countingGit('\n');
|
||||
assert.strictEqual(gitBaseBranch.tryLocalBranch('/x', git), null);
|
||||
assert.strictEqual(git.state.reads, 2,
|
||||
'stdout must be read twice: once by the guard (which passes) and once to split into lines');
|
||||
// strictEqual(null) catches.
|
||||
assert.strictEqual(gitBaseBranch.tryLocalBranch('/x', constGit({ stdout: '\n' })), null);
|
||||
});
|
||||
|
||||
test('stdout is exactly "" → null via the EARLY guard (a different arm)', () => {
|
||||
const git = countingGit('');
|
||||
assert.strictEqual(gitBaseBranch.tryLocalBranch('/x', git), null);
|
||||
assert.strictEqual(git.state.reads, 1,
|
||||
'an empty stdout must short-circuit in the guard, never reaching the line split');
|
||||
assert.strictEqual(gitBaseBranch.tryLocalBranch('/x', constGit({ stdout: '' })), null);
|
||||
});
|
||||
|
||||
// Boundary trio over the number of branch lines `git branch --list main master`
|
||||
|
||||
Reference in New Issue
Block a user