From f39217f8dac8bdd1200345e770188c50e2bc4659 Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Tue, 18 Aug 2026 02:51:34 -0600 Subject: [PATCH] test(hooks): lock in check-git-clean-force.mjs's handling of prose-in-echo false positives (#2468) Investigated #2468 (a descriptive echo label mentioning "git clean" plus force-like flag characters and a dash-less "dry-run" word in prose gets misread as its own unprotected git-clean invocation). Reproduced the exact repro directly against the current end-to-end hook pipeline via runHook/ isDenied and found it does NOT reproduce: mask-quoted-text.mjs already reduces ordinary quoted prose to inert `#` characters before check-git-clean-force.mjs's segment scan ever runs, which the issue's own manual "quotes replaced by spaces" simulation did not account for. No production code change -- the fix already exists. Adds two regression tests locking in the current correct behavior so a future refactor of mask-quoted-text.mjs or check-git-clean-force.mjs can't silently reintroduce this false-positive class. Verified the tests are meaningful (not vacuously passing) by temporarily disabling mask-quoted-text.mjs's masking and confirming both new tests fail with the exact false-positive BLOCK the issue describes; restored and confirmed green. docs check acknowledged -- test-only change, no hook script modified, so the docs/examples/claude-code-hooks/ mirror needs no update. --- tests/unit/hook-guard-git-clean.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/hook-guard-git-clean.test.ts b/tests/unit/hook-guard-git-clean.test.ts index 3fed610e9..9e82df13f 100644 --- a/tests/unit/hook-guard-git-clean.test.ts +++ b/tests/unit/hook-guard-git-clean.test.ts @@ -194,6 +194,30 @@ describe('guard-git.sh does not false-positive on quoted text (#2099)', () => { ].join('\n'); expect(isDenied(command)).toBe(false); }); + + it('does not block a descriptive echo label mentioning git clean before an unrelated, properly-guarded real invocation (#2468)', () => { + // Investigated as #2468: an echo LABEL narrating what a later command + // does (a natural thing to write in a multi-line script, e.g. + // /housekeep's own dirt-discovery phase) must not be misread as its own + // unprotected git-clean invocation just because it happens to mention + // force-like flag characters and the word "dry-run" (without a leading + // dash, since it's prose, not a real flag) in quoted text. The mask + // already reduces this to inert `#` characters before verb-detection + // runs (mask-quoted-text.mjs) — confirmed not reproducible against the + // current hook end-to-end; this locks that in against regression. + const command = [ + `echo "=== gitignored dirt (git clean -fdX dry-run) ==="`, + `git clean -fdX --dry-run`, + ].join('\n'); + expect(isDenied(command)).toBe(false); + }); + + it('does not block a single-line echo whose quoted prose mentions an unprotected-looking git clean (#2468)', () => { + // Isolates the same false-positive shape without the second, real + // invocation — the prose alone, once naively unmasked, reads as + // "git clean -fdX" with no dash-prefixed dry-run token nearby. + expect(isDenied('echo "we ran git clean -fdX dry-run here"')).toBe(false); + }); }); describe('guard-git.sh mask-quoted-text.mjs', () => {