Repository navigation
test(hooks): lock in check-git-clean-force.mjs's handling of prose-in-echo false positives - #2565
Merged
Merged
Conversation
…-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.
Contributor
Greptile SummaryAdds end-to-end regression coverage ensuring quoted prose mentioning a forceful
Confidence Score: 5/5The PR appears safe to merge because it only adds focused regression coverage and introduces no actionable defects. The new assertions invoke the real hook pipeline, preserve the relevant quoted and multiline input, and would fail if quote masking stopped protecting these prose cases. Important Files Changed
Reviews (1): Last reviewed commit: "test(hooks): lock in check-git-clean-for..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Investigated #2468: a descriptive
echolabel mentioning "git clean" plus force-like flag characters and a dash-less "dry-run" word in prose gets misread as its own unprotectedgit cleaninvocation, potentially suppressing an unrelated real invocation later in the same multi-line command block.Investigation
The issue describes guard-git.sh's quote-masking as a single crude step (
s/["'()]/ /g, replacing quote characters with spaces) and manually constructs what it believes the "masked" text looks like based on that model, then confirms that hand-constructed text blocks when piped directly intocheck-git-clean-force.mjs.Reproducing the exact repro against the actual, current, end-to-end hook pipeline (not a manual simulation) shows it does not reproduce:
mask-quoted-text.mjs(introduced by #2329, five days before this issue was filed) already reduces the contents of an ordinary quoted string to inert#characters before any verb-detection check — includingcheck-git-clean-force.mjs's — ever runs. The crudes/["'()]/ /gstep the issue describes is a separate, later cleanup pass that only strips residual delimiter punctuation around already-masked or intentionally-unmasked (exec-triggered/command-substitution) spans — by the time it runs, the prose has already been reduced to#runs, so no readable "git clean"/force-flag/dry-run text survives to strip.Confirmed via direct testing against the live hook pipeline:
echo "=== gitignored dirt (git clean -fdX dry-run) ==="followed by a real, properly-guardedgit clean -fdX --dry-run) does not block.gh issue create --body "..."scenario the issue describes hitting while filing itself also does not block, including with nested escaped quotes.check-git-clean-force.mjs(bypassing the real pipeline) does block — confirming the detector's own logic matches the issue's description, and the discrepancy is specifically that the real masking pipeline never produces that intermediate text.No production code change — the underlying fix already exists via #2329's
mask-quoted-text.mjs. This PR only adds regression coverage so a future refactor ofmask-quoted-text.mjsorcheck-git-clean-force.mjscan't silently reintroduce this false-positive class un-noticed.Test plan
tests/unit/hook-guard-git-clean.test.ts's existing "does not false-positive on quoted text" describe block, using the establishedrunHook/isDeniedend-to-end harness: the exact multi-line issue repro, and an isolated single-line variantmask-quoted-text.mjs's masking (pass-through stub) and confirmed both new tests fail with the exact false-positiveBLOCKthe issue describes; restored and confirmed greennpm test(full suite) — 339 files, 5453 passednpx tsc --noEmit/npm run lint— cleandocs/examples/claude-code-hooks/'s byte-identical mirror requirement doesn't apply hereCloses #2468