Skip to content

feat(switch): suggest pr:N or mr:N for numeric branch names - #2516

Merged
max-sixty merged 5 commits into
mainfrom
hint-numbers
May 1, 2026
Merged

max-sixty merged 5 commits into
mainfrom
hint-numbers

Conversation

@max-sixty

@max-sixty max-sixty commented May 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

When wt switch <number> fails because no branch by that name exists, the hint now leads with how to switch to the matching PR/MR before mentioning --create.

Platform is detected by hostname-matching the primary remote's effective URL (so url.insteadOf rewrites are respected):

  • GitHub → wt switch pr:N
  • GitLab → wt switch mr:N
  • Unknown / opaque host → both suggestions

Non-numeric branch names keep the original hint unchanged.

Before

✗ No branch named 2474
↳ To create a new branch, run wt switch --create 2474; to list branches, run wt list --branches --remotes

After (GitHub)

✗ No branch named 2474
↳ To switch to PR #2474, run wt switch pr:2474; to create a new branch, run wt switch --create 2474; to list branches, run wt list --branches --remotes

Test plan

  • Snapshot tests cover GitHub, GitLab, and unknown-platform variants
  • Direct test for Repository::detect_ref_type covers all URL branches
  • Existing branch_not_found snapshots unchanged (non-numeric names)
  • cargo run -- hook pre-merge --yes passes (3412 tests, all lints)
  • Manual smoke test in temp repo: GitHub remote → pr:N, GitLab remote → mr:N, no remote → both

When `wt switch <number>` fails because no branch by that name exists, the
hint now leads with how to switch to the matching PR/MR before mentioning
`--create`. Platform is detected from `forge.platform` config or the
primary remote URL — GitHub shows `pr:N`, GitLab shows `mr:N`, and an
unknown platform falls back to suggesting both.

Non-numeric branch names keep the original hint unchanged.

Co-Authored-By: Claude <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hint and detection logic look correct — three new tests cover the github/gitlab/unknown branches and the snapshots show the right copy-pasteable commands.

Two things worth considering, neither blocking:

Duplication with platform_for_repo. Repository::detect_ref_type and platform_for_repo now both translate forge.platform + primary remote URL into a "GitHub or GitLab" enum, and they diverge on three details:

  1. URL alias handling — platform_for_repo resolves through effective_remote_url (honors url.insteadOf); detect_ref_type reads the raw primary_remote_parsed_url. A user with an SSH host alias gets a hint here but not in CI status, or vice versa.
  2. Case sensitivity of forge.platform — platform_for_repo parses via strum's lowercase-only EnumString, so forge.platform = "GitHub" falls through to URL detection (with a log::warn!). detect_ref_type lowercases first and matches successfully. Same config, different result.
  3. Invalid value feedback — platform_for_repo emits a warning on unrecognized strings; detect_ref_type is silent.

CiPlatform and RefType are essentially the same concept; folding the detection into one place (or having detect_ref_type delegate via platform_for_repo + a From<CiPlatform>) would avoid future drift. Not worth blocking this PR on.

unwrap_or(0) defensive default. The doc comment on pr_mr_switch_hint already establishes that branch parses as u32 (the caller guards with branch.parse::<u32>().is_ok()), so branch.parse().unwrap_or(0) is unreachable on the validated path. Inline suggestion below switches it to expect(...) so a future caller that drops the guard hits a clear panic instead of silently rendering "PR #0" alongside the original branch text.

Comment thread src/git/error.rs Resolved
Address review feedback on the numeric-branch hint:

- `detect_ref_type` now uses the primary remote's effective URL (so
  `url.insteadOf` rewrites are honored, matching `platform_for_repo`).
- `forge.platform` is matched case-sensitively against the same lowercase
  literals strum's `EnumString` accepts, so the same config value picks
  the same platform here and in CI status detection.
- Replace `unwrap_or(0)` with `expect(...)` in `pr_mr_switch_hint`: the
  caller already validates `branch.parse::<u32>().is_ok()`, so the
  fallback was unreachable; a future caller that drops the guard now
  hits a clear panic instead of rendering "PR #0".

Co-Authored-By: Claude <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes May 1, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov/patch failed: patch coverage 84.12% (53/63 lines) against project base 96.76%. The 10 missed lines are concentrated in src/git/repository/remotes.rs (9 misses, 59.09%) and src/git/error.rs (1 miss).

The miss in remotes.rs is the rewritten URL-detection path:

292        let url = self
293            .primary_remote()
294            .ok()
295            .and_then(|remote| self.effective_remote_url(&remote))?;
296        let parsed = GitRemoteUrl::parse(&url)?;

Before this commit, the equivalent was a single line — let parsed = self.primary_remote_parsed_url()?; — covered by the same end-to-end tests that exercise detect_ref_type via wt list --full (e.g. test_list_full_with_gitlab_remote). Splitting it across primary_remote().ok().and_then(closure) introduces per-expression LLVM coverage regions that codecov reports as 0 hits even though the inner branches (is_github / is_gitlab) show as covered.

Cleanest fix: extract the effective-URL lookup into a helper alongside primary_remote_parsed_url, so the call site in detect_ref_type collapses back to a single line. Sketch:

/// Like `primary_remote_parsed_url`, but resolves through `effective_remote_url`
/// so `url.insteadOf` rewrites are honored.
pub fn primary_remote_effective_parsed_url(&self) -> Option<GitRemoteUrl> {
    let remote = self.primary_remote().ok()?;
    let url = self.effective_remote_url(&remote)?;
    GitRemoteUrl::parse(&url)
}

Then detect_ref_type becomes let parsed = self.primary_remote_effective_parsed_url()?; again, mirroring the prior shape and re-using the existing test coverage.

Happy to push this change if you'd like — otherwise let me know how you'd prefer to handle it. Dismissing the prior approval since codecov/patch is a hard gate per CLAUDE.md.

@worktrunk-bot
worktrunk-bot dismissed their stale review May 1, 2026 04:03

codecov/patch failed (84.12% vs project 96.76%)

Adds direct coverage for the GitHub / GitLab / unknown-host / no-remote
branches of `Repository::detect_ref_type`, addressing the codecov/patch
gap on the new helper introduced for the numeric-branch hint.

The `forge.platform` override branch is left to the existing
`platform_for_repo` integration paths — exercising it here would require
either driving a subprocess with `WORKTRUNK_PROJECT_CONFIG_PATH` or
mutating process-global cwd, neither of which is worth the test cost.

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 2 commits April 30, 2026 21:16
Apply cargo fmt to the remote-add lines that pre-commit broke onto
multiple lines.

Co-Authored-By: Claude <[email protected]>
…in hint helper

Trims `Repository::detect_ref_type` to URL-only detection (effective URL,
respecting `url.insteadOf`). The `forge.platform` config branch is removed
because:

- It duplicated `platform_for_repo`'s precedence rules (URL alias
  resolution, case sensitivity, warning emission), inviting drift between
  the two paths.
- Driving it from a unit test required either subprocess setup or
  process-global cwd mutation, which isn't worth the test cost for a
  hint-only path.

Users with `forge.platform` set and an opaque remote host fall back to
the both-platforms hint ("PR #N or MR !N") — still useful, just less
specific.

Also threads the parsed `u32` from the `BranchNotFound` Display through
into `pr_mr_switch_hint` instead of re-parsing inside the helper, which
removes the unreachable `expect(...)` branch.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit cdb17cb into main May 1, 2026
25 checks passed
@max-sixty
max-sixty deleted the hint-numbers branch May 1, 2026 04:42
max-sixty pushed a commit that referenced this pull request May 1, 2026
… 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]>
@max-sixty max-sixty mentioned this pull request May 3, 2026
max-sixty added a commit that referenced this pull request May 3, 2026
Cuts v0.47.0. Highlights:

- **Integration detection fix** across `wt list`, `wt remove`, `wt
merge`, `wt step prune` for the local/upstream-diverged case (#2507,
#2513, #2515).
- **Faster shell-command dispatch** (~10ms per invocation, 1.49× on
trivial aliases) via event-driven signal forwarding (#2537, #2538), plus
parallel config load (#2543) and merged cold-start prewarm rev-parse
(#2541).
- **`wt switch <number>` suggests `pr:N` / `mr:N`** instead of just
`--create` (#2516).
- **Library API breaking changes**: `RefSnapshot` cutover (#2528, #2530)
and the `for-each` direct-exec change (#2465). Full list in
`CHANGELOG.md`.

See `CHANGELOG.md` for the complete entry.

> _This was written by Claude Code on behalf of @max-sixty_

---------

Co-authored-by: Claude <[email protected]>
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.

2 participants