Skip to content

test(hooks): lock in check-git-clean-force.mjs's handling of prose-in-echo false positives - #2565

Merged
carlos-alm merged 1 commit into
mainfrom
fix/issue-2468
Aug 18, 2026
Merged

carlos-alm merged 1 commit into
mainfrom
fix/issue-2468

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

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, 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 into check-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 — including check-git-clean-force.mjs's — ever runs. The crude s/["'()]/ /g step 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:

  • The issue's exact multi-line repro (echo "=== gitignored dirt (git clean -fdX dry-run) ===" followed by a real, properly-guarded git clean -fdX --dry-run) does not block.
  • The gh issue create --body "..." scenario the issue describes hitting while filing itself also does not block, including with nested escaped quotes.
  • Feeding the issue's own hand-constructed "masked" text directly into 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 of mask-quoted-text.mjs or check-git-clean-force.mjs can't silently reintroduce this false-positive class un-noticed.

Test plan

  • Two new tests in tests/unit/hook-guard-git-clean.test.ts's existing "does not false-positive on quoted text" describe block, using the established runHook/isDenied end-to-end harness: the exact multi-line issue repro, and an isolated single-line variant
  • Verified the new tests are meaningful (not vacuously passing): temporarily disabled mask-quoted-text.mjs's masking (pass-through stub) and confirmed both new tests fail with the exact false-positive BLOCK the issue describes; restored and confirmed green
  • npm test (full suite) — 339 files, 5453 passed
  • npx tsc --noEmit / npm run lint — clean
  • No hook script was modified, so docs/examples/claude-code-hooks/'s byte-identical mirror requirement doesn't apply here

Closes #2468

…-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.
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds end-to-end regression coverage ensuring quoted prose mentioning a forceful git clean command is not mistaken for an executable invocation.

  • Covers a multiline command containing a descriptive label followed by a properly guarded real invocation.
  • Covers the quoted-prose case in isolation.

Confidence Score: 5/5

The 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

Filename Overview
tests/unit/hook-guard-git-clean.test.ts Adds meaningful regression tests that exercise the live hook pipeline and preserve multiline and quoted input through the masking and detection stages.

Reviews (1): Last reviewed commit: "test(hooks): lock in check-git-clean-for..." | Re-trigger Greptile

@carlos-alm
carlos-alm merged commit 6589665 into main Aug 18, 2026
27 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2468 branch August 18, 2026 09:20
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

guard-git.sh: check-git-clean-force.mjs false-positives on descriptive text inside echo strings

1 participant