Skip to content

fix(plugin-dev): assert expected hook decision - #83992

Open
RerankerGuo wants to merge 1 commit into
anthropics:mainfrom
RerankerGuo:fix/83800-assert-hook-decision
Open

fix(plugin-dev): assert expected hook decision#83992
RerankerGuo wants to merge 1 commit into
anthropics:mainfrom
RerankerGuo:fix/83800-assert-hook-decision

Conversation

@RerankerGuo

Copy link
Copy Markdown

Summary

Fixes #83800.

test-hook.sh currently treats both allow and deny outcomes as successful execution. That verifies that a hook ran, but it cannot catch a hook that allows an operation it was intended to deny.

This change adds an optional --expect allow|deny|ask flag. When provided, the tester derives the observed decision from structured hookSpecificOutput.permissionDecision, falling back to the hook exit code, and fails if the result does not match.

Calls that do not use --expect retain the existing behavior.

Changes

  • Add and validate the --expect / -e option.
  • Report the derived hook decision.
  • Fail on an expected/actual decision mismatch.
  • Document the option and an example in the script README.

Verification

  • Existing invocation with an allowing hook: passes.
  • --expect allow with an allowing hook: passes.
  • --expect deny with an allowing hook: fails with status 1.
  • --expect deny with an exit-2 hook: passes.
  • --expect ask with structured JSON output: passes.
  • Invalid expected decision: fails with a validation error.
  • bash -n plugins/plugin-dev/skills/hook-development/scripts/test-hook.sh
  • git diff --check

Scope

This PR only adds optional result assertions. It does not change hook matching, hook execution, or the legacy success criteria when no expected decision is supplied.

Add an optional --expect flag so hook tests fail when the observed allow, deny, or ask decision does not match the intended outcome.\n\nRefs anthropics#83800
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.

test-hook.sh reports success for a hook that allows what it was written to block

1 participant