Repository navigation
fix(#963): pre-tool.sh No-Changes Guard resolves cd targets instead of silently checking the wrong directory - #966
Merged
admarble merged 4 commits intoAug 25, 2026
Conversation
…raction The guard's TARGET_DIR extraction silently mis-resolved multi-line commit commands whose cd target was quoted or a shell variable, falling through to check the hook process's own cwd instead of the command's actual cwd - stranding real, staged commits behind a false "no changes to commit" block. resolve_cd_target() scans the raw TOOL_INPUT (not the quote-stripping SEGMENTS) for the last cd line, resolves quoted/unquoted static literals, and fails open (skips the check) on anything dynamic - git itself already rejects a genuinely empty commit, so a missed check costs one harmless error, while a wrong check strands finished work. Also applied to the #901 checkout-lock guard's cd extraction (same root-cause pattern, same file).
…logy-detector describe.each false positives Gap A: resolve_cd_target() also fails open on backslash-bearing cd targets - a backslash can escape a following dollar/backtick past the literal-string check, and carries shell meaning the function never resolves. Gap B: the jq-less fallback's TOOL_INPUT extraction truncated any command at its first embedded escaped quote, so on jq-less machines the guards saw 'git commit -m \' instead of the full command. Replaced with an escape-aware sed capture plus a single-scan awk JSON-string unescaper (ordering-safe for literal backslash-n sequences). Both mirrored identically across the three hook copies; 15 new integration tests including a filtered-PATH symlink farm that makes jq genuinely unavailable. Detector: collectBuildOutputVars required '=' immediately after the name, so type-annotated table declarations hid their hooks/*.sh literals; and helpers spawning a describe.each callback parameter had no link to the table it was destructured from. Declaration matcher now tolerates a bounded type annotation, and collectDescribeEachParams propagates a build-output table's callback params. pre-tool-hook.integration.test.ts: 74/74 falsely flagged -> 3 (remainder needs call-site argument tracking; follow-up). Un-breaks tautology-detector-cli.test.ts on branches touching spawn-driven shell suites.
…-pre-tool-sh-no-changes-guard-only-re # Conflicts: # CHANGELOG.md
admarble
deleted the
feature/963-bug-hooks-pre-tool-sh-no-changes-guard-only-re
branch
August 25, 2026 12:48
5 tasks
7 of 8 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
resolve_cd_target()(new helper inpre-tool.sh) scans the raw multi-lineTOOL_INPUTfor the lastcdline, resolves quoted or unquoted static-literal targets, and fails open (skips the no-changes check) on anything dynamic (a shell variable, command substitution) or nonexistent —git commititself already rejects a genuinely empty commit, so a skipped check costs one harmless error, while checking the wrong directory silently strands finished work.cdfallback now readsHOOK_CWD(the command's actual cwd from the PreToolUse payload) instead of the hook process's own$PWD— the same field the feat(locks): per-issue locks give no mutual exclusion on the shared working tree — checkout-scoped protection #901 checkout-lock guard already used correctly._CO_CDextraction (same root-cause pattern, same file — recommended as in-scope in the/specplan rather than filing a follow-up).templates/hooks/,hooks/,.claude/hooks/).Root cause correction: the issue filed this as "only matches single-line
cd path && git commit" — that theory doesn't hold; the guard'sgrep '^cd 'already matches per-line, not just line 1. Empirically verified (see spec comment) the actual failure modes are: acd "$WT"orcd "/quoted"target keeps its quotes/variable text through extraction and fails the-dtest, and the fallback then checks the hook process's own cwd rather than the command's.Test plan
__tests__/pre-tool-hook.integration.test.ts(parametrized over all 3 hook mirrors = 36 assertions), covering: multi-line unquoted/quotedcdtargets, last-of-two-cd-lines wins, the verbatim incident shape (WT=.../cd "$WT"/git commit), a nonexistentcdtarget, the payload-cwd-vs-process-cwd fallback (varied independently per feat(locks): per-issue locks give no mutual exclusion on the shared working tree — checkout-scoped protection #901's lesson), and regression preservation (single-linecd && commit,--allow-empty).pre-tool-hook.integration.test.ts(195 pre-existing + new), 89/89 in thecheckout-locksuites (shares the sibling-site fix).npm run buildandnpm run lintclean.npm test(full suite): 5653 passed, 3 failed — see Known gap below (unrelated, pre-existing).Pre-PR AC Verification
cdtarget (quoted/unquoted) check that directory; lastcdwins when several are presentcdtarget (dynamic or nonexistent) fails open instead of checking a different directorycdfallback checks the payload'scwd, not the hook process's own cwdcd && commitstill resolves, empty commit still blocked,--amend/--allow-emptystill bypassmd5identical across all 3 files;describe.each(HOOK_COPIES)Sibling site (from spec's Open Question): the #901 checkout-lock guard had the identical
cd-extraction blind spot. Took Option A (recommended) — fixed in this PR via the sharedresolve_cd_target()helper — rather than filing a follow-up, since it was trivially co-located and strictly reduces duplication.Mutation verification
Mutation-verified: AC-1/AC-2/AC-3 — reverted
resolve_cd_target()and its two call sites to the prior single-line-only, quote-retaining extraction across all 3 mirrors; 18/21 new test cases failed (the 3 that still passed are pure regression-preservation checks for behavior the old code already got right — single-line unquotedcdand--allow-empty, which aren't meant to distinguish old from new); restored the fix, full suite green again (222/222).Gap fixes (second commit,
7dd2710e)The three gaps originally documented in the Confidence Check below are now fixed in this PR:
resolve_cd_target()now fails open on any backslash-bearingcdtarget — a\can escape a following$/backtick past the literal-string check, and carries shell meaning the function never resolves. 3 new tests (a real directory literally namedfoo\bar, clean, must not be resolved-and-blocked).TOOL_INPUTextraction truncated commands at the first embedded\". Now an escape-aware sed capture + single-scan awk JSON-string unescaper (ordering-safe: a literal\\nstays backslash+n). 12 new tests behind a filtered-PATH symlink farm that makesjqgenuinely unavailable, including a HOOK_LOG assertion distinguishing full extraction from the old truncation.src/lib/test-tautology-detector.ts—collectBuildOutputVarsmissed type-annotated declarations (const X: T = ...), and nothing linked adescribe.eachtable's callback parameters back to the table'shooks/*.shliterals.pre-tool-hook.integration.test.ts: 74/74 falsely flagged → 4 advisory-only stragglers (3 pre-existingHOOK_PAIRSblocks + the new jq-sanity test) that need call-site argument-value tracking, a structurally larger detector change deliberately left for a follow-up. The 3 previously-failingtautology-detector-cli.test.tstests now pass; full suite is 5673 passed / 0 failed.Mutation-verified: gap fixes — removed the backslash rejection from all 3 mirrors; exactly the 3 gap-A tests failed; restored, suite green. Reverted the jq-less extraction; the HOOK_LOG test failed with the exact predicted truncation (
git commit -m \); restored. Reverted both detector fixes; the 2 new detector tests failed; restored.Pre-PR Confidence Check (original, superseded by Gap fixes above)
resolve_cd_target()'s dynamic-content detection was acaseglob for$/backtick only.npm test's 3 failures inscripts/qa/tautology-detector-cli.test.tswere detector false-positives on spawn-driven shell-script suites.Closes #963
🤖 Generated with Claude Code