Files
get-shit-done/tests/bug-2431-worktree-locked-surfacing.test.cjs
Tom Boucher 5f419c0238 fix(bugs): resolve issues #2388, #2431, #2396, #2376 (#2467)
#2388 (plan-phase silently renames feature branch): add explicit Git
Branch Invariant section to plan-phase.md prohibiting branch
creation/rename/switch during planning; phase slug changes are
plan-level only and must not affect the git branch.

#2431 (worktree teardown silently swallows errors): replace
`git worktree remove --force 2>/dev/null || true` with a lock-aware
block in quick.md and execute-phase.md that detects locked worktrees,
attempts unlock+retry, and surfaces a user-visible recovery message
when removal still fails.

#2396 (hardcoded test commands bypass Makefile): add a three-tier
test command resolver (project config → Makefile/Justfile → language
sniff) in execute-phase.md, verify-phase.md, and audit-fix.md.
Makefile with a `test:` target now takes priority over npm/cargo/go.

#2376 (OpenCode @$HOME not mapped on Windows): add platform guard in
bin/install.js so OpenCode on win32 uses the absolute path instead of
`$HOME/...`, which OpenCode does not expand in @file references on
Windows.

Tests: 29 new assertions across 4 regression test files (all passing).

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-20 10:10:16 -04:00

99 lines
3.5 KiB
JavaScript

/**
* Regression test for #2431: quick.md and execute-phase.md worktree teardown
* silently accumulates locked worktrees via `2>/dev/null || true`.
*
* Fix: replace the silent-fail pattern with a lock-aware block that surfaces
* the error and provides a user-visible recovery message.
*/
'use strict';
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const QUICK_PATH = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'quick.md');
const EXECUTE_PHASE_PATH = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'execute-phase.md');
function assertNoSilentWorktreeRemove(filePath, label) {
const content = fs.readFileSync(filePath, 'utf-8');
// The old pattern: git worktree remove "$WT" --force 2>/dev/null || true
const silentRemovePattern = /git worktree remove[^\n]*--force\s+2>\/dev\/null\s*\|\|\s*true/;
assert.ok(
!silentRemovePattern.test(content),
`${label}: must not contain "git worktree remove --force 2>/dev/null || true" (silently swallows errors)`
);
}
function assertHasLockAwareBlock(filePath, label) {
const content = fs.readFileSync(filePath, 'utf-8');
// Fix must include: lock-aware detection (checking .git/worktrees/*/locked)
const hasLockCheck = content.includes('.git/worktrees/') && content.includes('locked');
assert.ok(
hasLockCheck,
`${label}: must include lock-aware detection (.git/worktrees/.../locked check)`
);
}
function assertHasWorktreeUnlock(filePath, label) {
const content = fs.readFileSync(filePath, 'utf-8');
// Fix must include a git worktree unlock attempt
assert.ok(
content.includes('git worktree unlock'),
`${label}: must include "git worktree unlock" retry attempt`
);
}
function assertHasUserVisibleWarning(filePath, label) {
const content = fs.readFileSync(filePath, 'utf-8');
// Fix must print a user-visible warning on residual worktree failure
const hasWarning = content.includes('Residual worktree') || content.includes('manual cleanup');
assert.ok(
hasWarning,
`${label}: must include user-visible warning when worktree removal fails`
);
}
describe('bug-2431: worktree teardown must surface locked-worktree errors', () => {
test('quick.md exists', () => {
assert.ok(fs.existsSync(QUICK_PATH), 'quick.md should exist');
});
test('execute-phase.md exists', () => {
assert.ok(fs.existsSync(EXECUTE_PHASE_PATH), 'execute-phase.md should exist');
});
test('quick.md: no silent worktree remove pattern', () => {
assertNoSilentWorktreeRemove(QUICK_PATH, 'quick.md');
});
test('execute-phase.md: no silent worktree remove pattern', () => {
assertNoSilentWorktreeRemove(EXECUTE_PHASE_PATH, 'execute-phase.md');
});
test('quick.md: has lock-aware detection block', () => {
assertHasLockAwareBlock(QUICK_PATH, 'quick.md');
});
test('execute-phase.md: has lock-aware detection block', () => {
assertHasLockAwareBlock(EXECUTE_PHASE_PATH, 'execute-phase.md');
});
test('quick.md: has git worktree unlock retry', () => {
assertHasWorktreeUnlock(QUICK_PATH, 'quick.md');
});
test('execute-phase.md: has git worktree unlock retry', () => {
assertHasWorktreeUnlock(EXECUTE_PHASE_PATH, 'execute-phase.md');
});
test('quick.md: has user-visible warning on residual worktree', () => {
assertHasUserVisibleWarning(QUICK_PATH, 'quick.md');
});
test('execute-phase.md: has user-visible warning on residual worktree', () => {
assertHasUserVisibleWarning(EXECUTE_PHASE_PATH, 'execute-phase.md');
});
});