Repository navigation
refactor(hooks/alias): lift hook metadata to PipelineKind, unify source enum - #2521
Conversation
…ce enum
Drops `hook_type`/`display_path` from `SourcedStep` and lifts them onto
`PipelineKind::Hook { hook_type, display_path }`, mirroring `Alias { name }`.
Removes the four `.expect("...always set hook_type")` sites; the invariant
now lives on the type. Background flow threads `(CommandContext, PipelineKind,
Vec<SourcedStep>)` per pipeline.
Also collapses `AliasSource` into `HookSource` (User/Project, identical shape).
`HookSource` gains `PartialOrd`/`Ord` for the listing sort, and an updated
docstring covering dual hook+alias usage. `source.label()` is replaced with
`{source}` formatted via the existing `strum::Display`.
Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Clean refactor — the per-step Option<HookType>/Option<PathBuf> smell is gone, and the HookSource/AliasSource unification reads naturally now that they share the same trust-model wording.
One small follow-up below.
| extra_vars, | ||
| name_filters, | ||
| display_path, | ||
| display_path: _, |
There was a problem hiding this comment.
Now that display_path is destructured-and-discarded here (and prepare_and_check discards it via ..), the field on HookCommandSpec is read by exactly one caller: run_hooks_foreground reaches in for spec.display_path to build PipelineKind::Hook. The doc comment on this function (lines 109–110) still describes display_path as if it controls the announcement here, which is no longer true.
Worth either dropping display_path from HookCommandSpec entirely (run_hooks_foreground already takes ctx and could take a separate display_path: Option<&Path> param) or trimming the stale doc paragraph. Not blocking.
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch is at 92.3% (5/65 lines uncovered). Breakdown of the missed lines, all in src/commands/hooks.rs:
| Line | Code | Coverable? |
|---|---|---|
| 514 | unreachable!("background pipelines are always PipelineKind::Hook") in run_hooks_background |
No — structural |
| 666 | same unreachable!() in spawn_hook_pipeline_quiet |
No — structural |
| 632 | continue for non-Hook kind in print_background_variable_table |
No — same structural invariant |
| 635 | continue when *ht != hook_type |
Yes, via spawn_hooks_after_remove (post-remove + post-switch batch); existing fixtures don't combine them |
| 638 | continue when group.first() is None |
No — into_source_groups produces non-empty groups, and run_hooks_background filters empties |
Lines 514, 632, 638, 666 are the price of the "lift to PipelineKind" approach the PR description argues for, and the old code had the same shape on a per-step basis (if sourced.hook_type != Some(hook_type) { continue; } on what is now line 635). So this is mostly the patch surfacing structural invariants that codecov can't see through, not a real coverage gap.
Line 635 is the only honestly testable miss — a fixture that registers both post-remove and post-switch hooks and triggers spawn_hooks_after_remove with changed_directory = true. Whether that's worth a dedicated test or a codecov override is your call. Dismissing the approval so the patch check doesn't auto-clear on a refresh.
codecov/patch failed (92.3%, 5 uncovered lines) — analysis posted, deferring to author
… flakes (#2523) ## Problem [Run 25196909437](https://github.com/max-sixty/worktrunk/actions/runs/25196909437) (tend-review on PR #2512, "Add Codex support") burned ~116 minutes / $6.90 because the bot: 1. Approved the PR 2. Saw `test (windows)` fail on `test_prune_json_orphan_branch` — explicitly identified as a `step_prune` test "unrelated to this PR" 3. **Dismissed its own approval anyway** (dismissal message: *"Dismissing — `test (windows)` failed on `test_prune_json_orphan_branch`... Will retry once it completes; if the rerun is green, this is a flake and the PR is fine."*) 4. Tried `POST /repos/.../actions/jobs/<id>/rerun` → HTTP 403 *"The workflow run containing this job is already running"* 5. Wrote a background script that polled for ~90 minutes waiting for the non-required `benchmarks` job to clear so it could call `gh run rerun --failed` The dismissal-on-flake pattern is structural: given (approved review + clearly-unrelated test failure), the bot reasoned its way into "must rerun → must dismiss approval first → must wait for `benchmarks`." This contradicts the spirit of `CLAUDE.md`'s existing *"Don't wait for CI `benchmarks` before merging"* note, which only covered the merge path. This is distinct from the codecov dismissal pattern (PRs #2521, #2516, #2512, #2507) — those are correct per `CLAUDE.md`'s *"NEVER merge a PR with failing `codecov/patch` without explicit user approval"* and aren't touched here. ## Change Adds a `## PR Review: Don't Self-Dismiss Over Unrelated Test Flakes` section to `.claude/skills/running-tend/SKILL.md` (~22 lines) explaining: - Leave approval in place for unrelated flakes; post a comment instead - GitHub blocks both `--failed` and per-job rerun while *any* job in the workflow is `in_progress` - `benchmarks` routinely runs 80+ min, so the wait cascades wastefully - The codecov-dismiss pattern is unchanged ## Gates - **Evidence**: 1 occurrence (this run); structural failure with explicit reasoning chain → 1 occurrence is sufficient per `review-gates.md` - **Magnitude**: Targeted fix, ~22 lines added to a 231-line skill Co-authored-by: worktrunk-bot <[email protected]>
Background flow only ever sees hooks (aliases run in the foreground), so threading `PipelineKind` through it forced two `unreachable!()` and one defensive `continue` for the `Alias` variant that's structurally unreachable. Replace with a `BackgroundPipeline` type alias carrying `(CommandContext, HookType, Option<PathBuf>, Vec<SourcedStep>)` directly. `PipelineKind::Hook` stays for the foreground conversion at `sourced_steps_to_foreground`. Also remove the defensive `group.first().is_none()` check in `print_background_variable_table` — `into_source_groups` produces non-empty groups and `run_hooks_background` filters empties, so `group[0]` is safe. Add `test_combined_post_remove_and_post_switch_hooks_verbose` exercising the multi-hook-type filter branch in `print_background_variable_table` (previously only hit by the `wt remove` of the current worktree, which the existing non-verbose test covers without triggering the variable-table path). Co-Authored-By: Claude <[email protected]>
Two follow-ups deferred from #2474, plus a coverage refinement on review feedback.
Lift hook-only metadata onto
PipelineKind::HookSourcedStep::hook_type: Option<HookType>anddisplay_path: Option<PathBuf>were a smell — the invariant is per-pipeline, not per-step, but living onSourcedStepforced four.expect("hook pipelines always set hook_type")sites. Lifted both ontoPipelineKind::Hook { hook_type, display_path }, mirroringAlias { name }. The invariant now lives on the type, andsourced_steps_to_foregroundreads the metadata directly fromkind.Background flow doesn't need
PipelineKindat all — it only ever handles hooks (aliases run in the foreground). ThreadingPipelineKindthrough it forced twounreachable!()and one defensivecontinuefor the structurally unreachableAliasvariant. Background functions now take aBackgroundPipelinetype alias for(CommandContext, HookType, Option<PathBuf>, Vec<SourcedStep>)directly.Touches
prepare_background_pipelines,run_hooks_background,print_background_variable_table,spawn_hook_pipeline_quiet,sourced_steps_to_foreground,run_hooks_foreground, and the alias and hook-commands call sites.Unify
AliasSourceintoHookSourceAliasSourceandHookSourcewere near-identicalUser/Projectenums. RemovedAliasSource; all alias call sites now useHookSource. The shared enum gainsPartialOrd/Ordderives (needed for(name, source)listing sort) and an updated docstring covering dual hook+alias usage.source.label()becomes{source}via the existingstrum::Display.Test plan
cargo nextest run— 3261 tests pass (incl. newtest_combined_post_remove_and_post_switch_hooks_verbosecovering the multi-hook-type filter inprint_background_variable_table)pre-commit run --all-files— green🤖 Generated with Claude Code