Repository navigation
refactor(approval): share the remove-hook approval helper across remove/merge/prune - #2709
Merged
Merged
Conversation
…er across `wt remove`, `wt merge`, and `wt step prune` `wt remove`, `wt merge`, and `wt step prune` all approve `pre-remove` against each removed worktree's own `.config/wt.toml` (with primary-worktree fallback) plus `post-remove`/`post-switch` against the primary's. The pattern was duplicated in three places — subtle enough that PR #2701 had to fix it separately for prune after #2690 fixed it for remove/merge. This adds `project_config::collect_remove_hook_commands(primary_repo, paths)` and routes all three call sites through it. `wt remove` switches from N+1 prompts (per-worktree pre-remove + final post-remove/post-switch) to one combined batch — strictly fewer prompts in practice, since approvals saved by the first prompt would have suppressed later identical ones anyway. `wt merge` keeps its bundling shape (helper returns commands; merge prepends its own pre-commit/post-commit/pre-merge/post-merge to the same batch). `wt step prune`'s docstring exception about over-approving every linked worktree is preserved at the caller. The "Which `.config/wt.toml` a hook reads" spec docstring in `hooks.rs` now points at the shared helper instead of naming the three call sites. Co-Authored-By: Claude <[email protected]>
…-helper # Conflicts: # src/commands/hooks.rs
worktrunk-bot
approved these changes
May 11, 2026
…-helper # Conflicts: # src/commands/step/prune.rs # src/main.rs
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
… errors (#2714) ## Summary Each worktree's `.config/wt.toml` now stands alone. When the worktree a hook acts on has no `.config/wt.toml`, no project hooks run — the primary worktree's config is no longer consulted as a fallback. A present-but-malformed config aborts the operation with the parse error instead of silently using a different one. ## Why The fallback (#2690, extended to `wt switch` in #2703) was an internal detail meant to keep worktrees branched off *before* a hook was added still firing the hook. But it made which file each hook actually reads ambiguous — Codex flagged this in review of #2703 (P3): a destination worktree with a malformed `.config/wt.toml` silently ran the *primary's* hooks instead of surfacing the parse error. Removing the fallback gives a cleaner model: each worktree owns its config. Users who want a hook to apply project-wide commit it on the default branch — new worktrees branched off that branch inherit it. Worktrees branched off *before* the commit no longer fire the hook silently, which was the leaky part. ## Behavior change A `pre-remove` hook added on `main` no longer fires when removing a feature worktree that predates the commit adding it. To restore that behavior, branch the feature off `main` again (or commit the hook on the feature branch itself). ## What changed - `Repository::project_config_at_ref` now returns `anyhow::Result<Option<ProjectConfig>>` — `Ok(None)` for refs with no `.config/wt.toml`, `Err` for present-but-malformed. - Dropped the fallback from `commands::project_config::collect_remove_hook_commands` (the shared helper introduced in #2709) and from `output::handlers::execute_pre_remove_hooks_if_needed`, `worktree::switch::{switch_hook_project_config, hook_repo_for_worktree, spawn_switch_background_hooks}`, and `worktree::finish::finish_after_merge`. - Updated the `commands::hooks` spec docstring — table rows lose the fallback sub-clauses; trailing paragraph drops the fallback handling. ## Tests - Unit test `project_config_at_ref_reads_committed_config` now asserts `Err` on malformed committed config (was `None`). - Added `test_switch_existing_aborts_on_malformed_destination_config` and `test_remove_aborts_on_malformed_worktree_config` for the end-to-end abort path. - Updated three tests that relied on the fallback to commit configs on the relevant branches instead: `test_switch_pr_hooks_see_pr_vars` (commits on `pr-source`), `test_merge_teardown_hooks_read_destination_worktree_config` → `..._read_acting_worktree_config` (feature carries pre-remove), `test_approval_prompt_remove_decline` (commits before creating the worktree to remove). Snapshot regenerated for the last. Co-authored-by: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
…oo (#2717) ## Summary Follow-up to #2714: the fallback removal in the shared `collect_remove_hook_commands` helper was lost in the merge-conflict resolution against #2709 (which introduced the helper) and didn't land in the squash merge. The executor (`output::handlers::execute_pre_remove_hooks_if_needed`) has no fallback, but the approval helper still falls back to the primary worktree's config — so an approval prompt can list a `pre-remove` from the primary that the executor will then silently skip. This patch carries the original change forward to the helper. Each removed worktree's `pre-remove` reads its own `.config/wt.toml`; if it has none, no project `pre-remove` runs and the primary's config is not consulted. ## Why this matters Post-#2714, `wt remove` / `wt merge` / `wt step prune` all delegate `pre-remove` approval to this helper. Without the fix the worktrunk-on-main has an executor/approval mismatch — exactly the kind of leaky abstraction #2714 set out to eliminate. ## Tests The integration tests added in #2714 (`test_remove_aborts_on_malformed_worktree_config`, `test_switch_existing_aborts_on_malformed_destination_config`) and the fallback-test fixups (commit on the relevant branch instead of relying on inheritance) already cover the helper's behavior end-to-end. Local `cargo test --test integration` runs 1704 tests, all pass. --------- Co-authored-by: Claude <[email protected]>
3 tasks done
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
…calation (#2724) ## Summary `wt step <concurrent-alias>` interrupted by Ctrl-C could exit with code 143 (SIGTERM) instead of 130 (SIGINT) under load. The race lives in `src/output/concurrent.rs`'s signal forwarder: it sends SIGINT to each child's process group, then waits 200ms before escalating to SIGTERM. Under CI load the path `signal_hook polls → killpg → child receives → forwards to sleep → sleep dies → sh dies → pgroup empty` exceeds 200ms, so wt escalates and the child dies from SIGTERM. Wt's `interrupt_exit_code()` reads the child's actual death signal and reports `128 + 15 = 143` even though the user only ever sent SIGINT. This was the cause of the `affected tests (linux, advisory)` failure on #2709 (selected `test_alias_concurrent_receives_sigint` because that PR touched `src/main.rs`, dragging in coverage of nearly every wt invocation path) — diagnosis recorded there, not a regression from the approval refactor. ## Fix Record the user's first signal in a shared `Arc<AtomicI32>` set by the signal forwarder thread. After every child has been waited on, override any per-child `ChildProcessExited::signal` whose value differs from the originating one. wt's exit code now reflects what the user pressed (130 for SIGINT) regardless of which signal the escalation chain ended up using to actually kill the child. The fix is contained to `run_concurrent_commands`. The single-step `shell_exec.rs::stream` path has the same escalation logic but isn't exercised by the failing test; if the equivalent flake shows up there, the same pattern can be applied. ## Test plan - New `test_alias_concurrent_sigint_reports_origin_after_escalation` (`tests/integration_tests/step_alias.rs:1406`) — children `trap "" INT` so SIGINT is ignored and only the SIGTERM escalation kills them. Verified to reproduce the exact CI failure mode (`unix_wait_status(36608)` = exit 143) without the fix and pass with it. - Existing `test_alias_concurrent_receives_sigint` and `test_alias_concurrent_second_sigint_kills` still pass. - `cargo run -- hook pre-merge --yes`: 3667 tests pass, lints clean. --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wt remove,wt merge, andwt step pruneall approvepre-removeagainst each removed worktree's own.config/wt.toml(with primary-worktree fallback) pluspost-remove/post-switchagainst the primary's. The pattern was duplicated in three places — subtle enough that #2701 had to fix it separately for prune after #2690 fixed it for remove/merge, and #2708 then had to fix theRepository::atErr-swallowing in three places independently. This consolidates the three call sites into one shared helper, so the next fix-this-pattern PR only has to touch one place.Changes
src/commands/project_config.rs— newcollect_remove_hook_commands(primary_repo, paths). Returns theVec<ApprovableCommand>forpre-remove(per-worktree, with primary fallback) +post-remove/post-switch(primary), deduped by template. Carries forward fix(hooks): propagate Repository::at errors in pre-remove config resolution #2708'sRepository::at(wt_path)?propagation.src/main.rs::approve_remove— replaced the per-worktreeapprove_or_skiploop with a single-batch flow.wt removeswitches from N+1 prompts to one combined batch (strictly fewer prompts in practice; approvals saved by the first prompt would have suppressed later identical ones anyway).src/commands/merge.rs::collect_merge_commands—pre-remove/post-remove/post-switchnow come from the helper; merge keeps its inlinepre-commit/post-commit/pre-merge/post-mergecollection and bundles everything into the sameapprove_command_batchcall.src/commands/step/prune.rs::approve_prune_hooks— one-line helper call. The "over-approval superset" exception remains in the local docstring.src/commands/hooks.rs— the "Which.config/wt.tomla hook reads" spec docstring now points at the shared helper.The executor
output::handlers::execute_pre_remove_hooks_if_neededstill has its own copy of the pattern (an executor-side, not approval-side, concern) — left as-is.Test plan
cargo run -- hook pre-merge --yes— 3660 tests pass; clippy clean.wt remove/wt merge/wt step pruneapproval tests cover both branches of the helper (per-worktree config vs primary fallback).