Skip to content

fix(#570): pre-tool.sh regexes skip gh issue/pr body content for destructive/deployment/reset/workflow commands - #578

Merged
admarble merged 2 commits into
mainfrom
feature/570-bug-hooks-pre-tool-sh-regexes-for-destructive-depl
May 6, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/570-bug-hooks-pre-tool-sh-regexes-for-destructive-depl

Conversation

@admarble

@admarble admarble commented May 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Direct follow-up to #564 / #566. Wraps four additional regex sites in pre-tool.sh with the same ^gh (issue|pr) exclusion idiom, eliminating false-positive blocks when a gh issue|pr create|comment body merely references destructive tokens.

  • Destructive system commands (sudo, rm -rf patterns) — line ~95
  • Deployment commands (vercel, terraform, kubectl) — line ~101
  • git reset --hard outer guard — line ~130 (inner BLOCK_REASONS accumulator left untouched)
  • gh workflow run — line ~170

Applied across all three mirrored hook copies (templates/hooks/, hooks/, .claude/hooks/). Real destructive commands are still blocked at the bash command-string level — only gh issue|pr body content gets the pass.

Acceptance Criteria

Test plan

  • npx vitest run __tests__/pre-tool-hook.integration.test.ts — 72/72 passing
  • npm run build — TypeScript clean
  • All 12 wrap markers (#570 comment) present across 3 hook files

Self-dogfood

The hook fix self-validated during this PR's lifecycle: the prior QA pass was unable to post issue comments referencing the destructive tokens until .claude/hooks/pre-tool.sh was patched. Posting now works via standard gh issue comment --body.

Closes #570

…ructive/deployment/reset/workflow commands

Wraps four additional regex sites in pre-tool.sh with the same
`^gh (issue|pr) ` exclusion idiom introduced in #564 / #566:

- Destructive system commands site (line ~95)
- Deployment commands site (line ~101)
- git reset outer guard (inner BLOCK_REASONS accumulator unchanged)
- gh workflow run site

Applied across all three mirrored hook copies:
- templates/hooks/pre-tool.sh
- hooks/pre-tool.sh
- .claude/hooks/pre-tool.sh

Real destructive commands are still blocked at the bash command-string
level; only `gh issue|pr create|comment` payloads referencing these
tokens in body text are allowed through.

Adds 24 parametrized test cases (8 new tests x 3 hook copies) to
__tests__/pre-tool-hook.integration.test.ts covering allow-on-gh-body
and block-on-real-command for each of the four sites.

Closes #570
Per feedback_motivating_example_regression — examples quoted verbatim
in an issue body are mandatory test fixtures, not paraphrases. The
existing AC-1..AC-4 tests covered the spirit of each "Affected regex
sites" table row but used reworded fixtures (e.g. "never run rm -rf /
on production" vs the issue's verbatim "WARNING: never run `rm -rf /`
..."). This commit adds the EXACT strings from the #570 issue body:

- Row 1 destructive: cleanup-doc explainer payload
- Row 2 deployment: release-notes payload
- Row 3 git reset: tutorial payload (with dirty-repo fixture so the
  outer guard is actually exercised, not silently skipped via empty
  BLOCK_REASONS)
- Row 4 gh workflow: workflow-doc payload
- "Repro pattern" section: gh issue create with `rm -rf /` body

Each fixture parametrized over the 3 hook copies via the existing
describe.each(HOOK_COPIES) block = 15 net new test runs.

Test count: 72 -> 87, all passing.
@admarble
admarble merged commit c19eb2a into main May 6, 2026
8 checks passed
@admarble
admarble deleted the feature/570-bug-hooks-pre-tool-sh-regexes-for-destructive-depl branch May 6, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(hooks): pre-tool.sh regexes for destructive/deployment/reset/workflow commands also match inside quoted gh body content

1 participant