Skip to content

[worker:coverage] test(checkouts): add behavioral tests for Manager::checkout_of - #302

Merged
norrietaylor merged 1 commit into
mainfrom
chore/coverage-checkouts-checkout-of-586bc407124cab6a
Jun 3, 2026
Merged

norrietaylor merged 1 commit into
mainfrom
chore/coverage-checkouts-checkout-of-586bc407124cab6a

Conversation

@gominimal-aw-bot

@gominimal-aw-bot gominimal-aw-bot Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Adds three behavioral tests for Manager::checkout_of using a local bare-clone as the remote, so no network is required:

  • checkout_of_new_remote_returns_valid_path_and_rev — a first-time checkout of an unseen remote returns a directory that exists, contains the committed file, and reports the correct rev SHA.
  • checkout_of_same_branch_twice_uses_cache — a second call for the same GitRef::Branch returns the cached path and rev without creating a new worktree (exercises the Some(id) early-return branch).
  • checkout_of_commit_ref_reuses_branch_worktree — requesting a commit hash that matches an existing branch checkout reuses the same directory rather than allocating a new worktree (exercises the GitRef::Commit fast-path).

Also fixes run_git_bare to set the GIT_DIR environment variable explicitly, so git recognises the bare repository as intentional when safe.bareRepository = explicit is in effect (the default since git 2.49). Without this fix the worktree-add commands fail in any environment with the 2.49 default, making the production tool non-functional on modern git.

Verification

cargo fmt --all --check — no diff.

cargo clippy --workspace --all-targets — Finished 'dev' profile ... in 9m 13s (0 warnings, exit 0).

cargo test --workspace --all-targets — all tests passed (exit 0).

Closes #299

Generated by Chore-issue worker agent (side-repo-ops operator) · ● 47.5M · ◷

Summary by CodeRabbit

  • Bug Fixes

    • Resolved compatibility issue with git configurations that require explicit bare repository specification.
  • Tests

    • Added comprehensive test coverage for checkout functionality, including remote initialization, caching behavior, and commit-based worktree reuse.

Add three tests that exercise the main paths of Manager::checkout_of
using a local bare-clone as the remote, so no network is required:

- checkout_of_new_remote_returns_valid_path_and_rev: verifies that
  a first-time checkout returns an existing directory with the
  committed file present and the correct rev SHA.
- checkout_of_same_branch_twice_uses_cache: verifies that a second
  call for the same GitRef::Branch returns the cached path and rev
  without creating a new worktree.
- checkout_of_commit_ref_reuses_branch_worktree: verifies that
  requesting a commit hash matching an existing branch checkout
  reuses the same directory rather than allocating a new worktree.

Also fix run_git_bare to set GIT_DIR explicitly so git recognises
the bare repository as intentional when safe.bareRepository=explicit
is configured (the default since git 2.49).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds comprehensive test coverage for the Manager::checkout_of method in the checkouts crate, addressing a gap where this public function was exercised by no tests. The changes include a test helper function that creates local git repositories, a git environment variable fix to ensure bare repositories work correctly, and three test cases validating checkout creation, caching behavior, and commit-ref reuse.

Changes

Checkout manager test coverage and git bare repo compatibility

Layer / File(s) Summary
Git bare repository environment variable
crates/checkouts/src/repo.rs
Repo::run_git_bare now explicitly sets GIT_DIR environment variable on spawned git commands to bypass safe.bareRepository = explicit restrictions, ensuring bare repositories are recognized correctly by git subprocesses.
Checkout behavior tests and test helper
crates/checkouts/src/lib.rs
Added make_local_repo helper to initialize test git repositories with commits on specified branches. Three tests validate that checkout_of creates checkouts for new remotes, reuses cached checkout paths on repeated calls for the same ref, and reuses worktrees when requesting a commit SHA matching an existing branch checkout.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • norrietaylor

Poem

🐰 A rabbit hops through checkouts fair,
With tests that catch each hidden snare,
Git bare repos now work just right,
Cache reuse shines so bright,
Coverage gaps filled with delight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding behavioral tests for Manager::checkout_of in the checkouts crate, with appropriate context prefix.
Linked Issues check ✅ Passed All coding objectives from issue #299 are met: tests for new remote checkout, cached branch reuse, commit reuse fast-path, offline behavior, and the GIT_DIR fix for git 2.49+ compatibility.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objectives: new tests in lib.rs and the GIT_DIR fix in repo.rs for git 2.49 compatibility as described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@norrietaylor
norrietaylor merged commit 64fc3cd into main Jun 3, 2026
9 checks passed
@norrietaylor
norrietaylor deleted the chore/coverage-checkouts-checkout-of-586bc407124cab6a branch June 3, 2026 16:27
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.

agent:coverage: checkouts::Manager::checkout_of is untested (regions=133)

2 participants