Skip to content

Add tests for Write-on-existing-file and unknown tool name paths in resolveAction#18

Merged
gregology merged 1 commit intomainfrom
test-write-existing-file-and-unknown-tool
Mar 8, 2026
Merged

Add tests for Write-on-existing-file and unknown tool name paths in resolveAction#18
gregology merged 1 commit intomainfrom
test-write-existing-file-and-unknown-tool

Conversation

@gregology
Copy link
Copy Markdown
Contributor

@gregology gregology bot commented Mar 8, 2026

Closes #17

resolveAction has three branches: the toolToAction map lookup, the Write tool special case (which checks os.Stat to pick between create and edit), and the fallback that returns ActionAll for unknown tools. Only the Write-as-create path had test coverage.

This adds two tests:

  • TestHandleClaudeHook_WriteExistingFile — Write targeting a file that already exists on disk. Verifies that os.Stat succeeds and we get ActionEdit, so edit-scoped context shows up and create-scoped context doesn't.
  • TestHandleClaudeHook_UnknownToolName — An unrecognized tool name like "UnknownTool" hits the ActionAll fallback. Verifies that entries with on: all match while entries with specific on values (like on: edit) don't.

The issue also suggested testing Write with an unresolvable path (permission denied on stat). I skipped that one — it's basically the same as the existing TestHandleClaudeHook_WriteNewFile since any os.Stat error falls through to ActionCreate. Manufacturing a reliable permission-denied scenario in a cross-platform test felt like more trouble than the coverage was worth.

Stuck with individual test functions rather than converting to table-driven. The existing tests each need slightly different setup (different AGENTS.yaml content, different file states), so a shared table would mostly just add indirection without reducing code.

Resolves #17

@gregology gregology merged commit ba7b9e4 into main Mar 8, 2026
2 checks passed
@gregology gregology deleted the test-write-existing-file-and-unknown-tool branch March 8, 2026 03:44
gregology added a commit that referenced this pull request Mar 9, 2026
…known-tool

Add tests for Write-on-existing-file and unknown tool name paths in resolveAction
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.

Write-on-existing-file path in resolveAction is untested

1 participant