Repository navigation
fix(hook show): merge per-project user hooks into display - #2844
Conversation
`wt hook show` rendered only the global user-hooks section, so hooks under `[projects."<id>"]` in the user config were invisible even though the execution path merges them in. Both the text and JSON renderers now call the same `UserConfig::hooks(project_id)` accessor that `handle_hook` uses, so display matches what actually runs. Reported in #2826.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Fix looks right — both display paths (render_user_hooks and emit_hook_show_json) now route through UserConfig::hooks(project_id), matching the run path at src/commands/hook_commands.rs:249. The merge semantics in HooksConfig::merge_with also fold deprecated post_create into pre_start, so the deprecation handling the old &config.hooks + HooksConfig::get chain relied on is preserved.
codecov/patch is failing at 90% (9/10), with the single miss on line 430 ()?;) — the closing line of the reformatted multi-line render_user_hooks(...)?; call. The substantive new lines (function args, let user_hooks = config.hooks(project_id)) are all hit. This looks like a multi-line ? reformat artifact rather than a real coverage gap, but per CLAUDE.md it needs explicit approval before merging.
The new snapshot test covers the text path well. The JSON-path branch (emit_hook_show_json at line 502) is exercised by test_hook_show_json (which passes project_id even with no per-project hooks), but no test asserts that [projects.'<id>'.post-start] actually appears in JSON output — a regression there wouldn't be caught. Optional: extend test_hook_show_json with a per-project user hook and assert it appears with source: "user".
The merge of #2844 ("merge per-project user hooks into display") brought in a new test whose config uses `[post-start]` — canonical on main, a deprecated alias on this branch. Switch it to `post-create` (the test exercises the per-project merge, not deprecation) and regenerate the snapshot, which now shows both hooks under `post-create`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
wt hook showrendered only the global user-hooks section, so hooks defined under[projects."<id>"]in the user config were invisible — even though they actually ran when the hook fired. Both the text path (render_user_hooks) and the JSON path (emit_hook_show_json) now use the sameUserConfig::hooks(project_id)accessor that the execution path at hook_commands.rs:249 uses, so display matches what runs.Reported by @airtonix in #2826 after the project-identifier fix in #2827 landed: per-project user hooks keyed by the right identifier still didn't appear in
wt hook show. Verified locally before and after — with the bug, onlyzellij(global) appears; with the fix, bothzellij(global) andmise(per-project) appear, matching the announcement line at execution.Test plan
test_hook_show_merges_user_project_hooks— fixture writes a globalpost-startplus a[projects.'<id>'].post-start, asserts both appear underUSER HOOKSin the snapshot. Test fails onmain(onlyglobal-hookappears), passes with the fix.cargo test --test integration hook_show— 18/18 passing (no regressions in existing snapshots).cargo clippy --all-targets -- -D warnings— clean.cargo fmt --all -- --check— clean.wt hook showlists both the global and per-project user hooks, and the JSON output (--format=json) does the same.