-
Notifications
You must be signed in to change notification settings - Fork 5
Add hook script tests #18
Copy link
Copy link
Open
Labels
area: hooksClaude Code hook scriptsClaude Code hook scriptsarea: testsTest coverage and qualityTest coverage and qualitydifficulty: intermediateRequires some familiarity with the codebaseRequires some familiarity with the codebaseenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Metadata
Metadata
Assignees
Labels
area: hooksClaude Code hook scriptsClaude Code hook scriptsarea: testsTest coverage and qualityTest coverage and qualitydifficulty: intermediateRequires some familiarity with the codebaseRequires some familiarity with the codebaseenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Problem
The hook scripts in
hooks/contain meaningful logic —build_envelopeconstructs event payloads with token estimation,format_statuslinebuilds the statusline string,estimate_tokensperforms chars-to-tokens conversion — but none of this is tested. The hooks are also excluded from pyright type checking.What to do
Create
tests/test_hooks.pythat imports and tests the pure functions:build_envelope— verify truncation, token estimation, payload structureformat_statusline— verify output format with various input combinationsestimate_tokens— verify calculation matcheschars / chars_per_token_estimateget_session_alert— test with mocked HTTP responses (collector up vs down)Approach
These functions use only stdlib + httpx, so they can be imported and tested directly. The
main()functions can be tested with stdin mocking.Files to look at
hooks/post_tool_use.py—build_envelope,estimate_tokenshooks/statusline.py—format_statuslinehooks/_hook_config.py— config loading