Skip to content

test(recover): decouple current_or_recover test from inherited CWD - #2642

Merged
max-sixty merged 3 commits into
mainfrom
nix
May 8, 2026
Merged

max-sixty merged 3 commits into
mainfrom
nix

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Summary

Fix two nix-flake nightly check regressions — both pre-existing failures in the build sandbox where pkgs.lib.cleanSource strips .git and minimal PATH lacks standard tools. Each fixes the current "first failure"; further nix-flake test failures remain (snapshot mismatches in integration tests with implicit CWD assumptions) and are a separate scope.

  • git::recover::tests::test_current_or_recover_returns_repo_when_cwd_exists (Nightly tests failed #2632) — extracts or_recover() from current_or_recover() so the wiring can be tested with explicit Repository::current() and recovery-closure inputs. Replaces the single env-coupled assertion with three branch-coverage tests (success / recovers / propagates error).
  • output::commit_generation::tests::test_command_exists_known_command — switches command_exists from shelling out to the which/where binary (absent in the Nix build sandbox) to the which crate (already a workspace dep). Splits out command_exists_in so the positive-case test asserts against a tempdir-controlled search path instead of inherited PATH.

Why this is a fix, not a test skip

Following the rule established by the closure of #2633 and codified in running-tend: no Repository::current().is_err() else return guards. Each commit either fixes production code (command_exists no longer needs an external binary) or restructures the test so its setup doesn't depend on environment that isn't guaranteed.

Test plan

  • cargo run -- hook pre-merge --yes — 3526 tests pass, all lints clean.
  • Reproduced both original failures by running the test binary from a non-git tempdir / minimal PATH; both now pass.
  • Required CI green (test linux/macos/windows, lint, code-coverage, codecov/patch).
  • nix-flake nightly run on the branch confirms both targeted tests now pass; remaining failures (e.g. test_config_init_already_exists, test_config_show_*) are pre-existing and unrelated.

🤖 Generated with Claude Code

`test_current_or_recover_returns_repo_when_cwd_exists` asserted the
function's success branch by relying on the test binary inheriting a
git repo as its CWD. The Nix flake build sandbox strips `.git` from the
extracted source (`pkgs.lib.cleanSource`), so `Repository::current()`
errors and the assertion panics — the failure tend tried to silence in
the closed PR #2633.

Extract the success/recovery wiring into `or_recover()`, which takes the
`Repository::current()` result and the recovery closure as parameters.
Production code threads its real values through unchanged. Tests pass
explicit inputs for all three branches (success, recovery, neither),
giving better coverage than the original single-branch happy-path
check while removing the dependency on inherited CWD.

Closes #2632

Co-Authored-By: Claude <noreply@anthropic.com>
worktrunk-bot
worktrunk-bot previously approved these changes May 8, 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 fails on the panic!() line — it's defensive but unreachable. or_recover(Ok(...), ...) matches the Ok arm before recover() is invoked, so the closure body is never executed. Per CLAUDE.md ("If code is unused, remove it"), replace the panic-closure with || None. The test still validates the success branch via assert!(!recovered) and the repo-path assertion; the type-level structure of or_recover already guarantees recover() isn't called on the Ok arm, so the panic is redundant.

Comment thread src/git/recover.rs Outdated
@worktrunk-bot
worktrunk-bot dismissed their stale review May 8, 2026 06:43

codecov/patch failed — see follow-up review for fix

`command_exists` shelled out to `which` (Unix) / `where` (Windows). The
Nix flake build sandbox doesn't ship those binaries on PATH, so the
helper silently returned `false` for every command — `detect_llm_tool`
would always claim no tool was available — and
`test_command_exists_known_command` panicked because `which which`
exited non-zero.

Switch to the `which` crate (already a workspace dependency, used by
`shell_exec`, `priority`, `completion`, and `shell`) which walks PATH
directly without a child process. Splitting out `command_exists_in`
lets the positive-case test assert against a tempdir-controlled search
path instead of the inherited PATH, removing the environment-coupling
that made the original test brittle.

Co-Authored-By: Claude <noreply@anthropic.com>
worktrunk-bot
worktrunk-bot previously approved these changes May 8, 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: 1 miss in commit_generation.rs (the cfg!(windows) branch in the new test) and 1 miss in recover.rs (the previously-flagged panic!() line — open suggestion in the prior thread still stands).

Inline suggestion below for the new miss; the runtime cfg!(windows) keeps both string literals in every build, so Linux coverage marks the Windows arm uncovered. Switching to attribute cfg resolves it.

Comment thread src/output/commit_generation.rs Outdated
@worktrunk-bot
worktrunk-bot dismissed their stale review May 8, 2026 06:59

codecov/patch failed — see follow-up review for the gap

- Drop the panic-closure in `test_or_recover_uses_current_repo_without_recovering`. The success branch never invokes the recovery closure, so the body was unreachable defensive code that codecov flagged as a miss.
- Switch the bin-name selection in `test_command_exists_in_finds_binary_on_explicit_path` from runtime `cfg!(windows)` to attribute `#[cfg(...)]`. The runtime form keeps both literals in every build, so coverage marked the inactive arm uncovered.

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty
max-sixty merged commit c666968 into main May 8, 2026
26 checks passed
@max-sixty
max-sixty deleted the nix branch May 8, 2026 07:25
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