[PR #585] test: reuse existing tests in worktree mode #589

Closed
opened 2026-03-02 04:14:03 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/git-ai-project/git-ai/pull/585

State: closed
Merged: Yes


test: reuse existing tests in worktree mode

Summary

This PR adds a lightweight way to re-run existing integration tests against a linked git worktree without rewriting the test bodies.

Key pieces:

  • Adds with_worktree_mode(...) + a thread-local WORKTREE_MODE flag in the TestRepo harness. When enabled, TestRepo::new() transparently returns a worktree-backed repo, and insta snapshots get a worktree suffix.
  • Implements a worktree-backed TestRepo::new_worktree_variant() that:
    • creates a base repo
    • ensures there’s at least one commit (worktree requirement)
    • moves the base repo off main so a worktree can check out main
    • creates a linked worktree and returns a TestRepo pointing to it
    • cleans up both base+worktree paths on drop
  • Adds reuse_tests_in_worktree!(...) macro to generate a second #[test] that calls the original test function inside with_worktree_mode.
  • Demonstrates usage by reusing tests in:
    • tests/cherry_pick.rs (all tests)
    • tests/stash_attribution.rs (all tests)
    • tests/simple_additions.rs (subset of 10 tests)

Stacked on: codex/worktree-support-complete (PR #582).

Review & Testing Checklist for Human

  • Sanity-check TestRepo::new_worktree_variant() semantics: base branch switching + worktree checkout on main is correct for all modes, and doesn’t break tests that assume current branch is main.
  • Review cleanup logic in Drop for worktree-backed repos (base/worktree deletion + git worktree remove --force): ensure it can’t delete an unintended directory and behaves well on CI.
  • Confirm the macro-generated test naming (<original>_in_worktree) won’t collide with existing tests in the crate(s) you plan to apply it to.
  • Consider CI/runtime impact: this duplicates selected tests; verify overall test runtime is still acceptable.
  • Run a representative local subset (or in CI) to confirm the reused tests actually exercise worktree paths (i.e., TestRepo::new() is being hit) and don’t silently fall back to non-worktree flows.

Notes


Open with Devin
**Original Pull Request:** https://github.com/git-ai-project/git-ai/pull/585 **State:** closed **Merged:** Yes --- # test: reuse existing tests in worktree mode ## Summary This PR adds a lightweight way to re-run existing integration tests against a linked git worktree without rewriting the test bodies. Key pieces: - Adds `with_worktree_mode(...)` + a thread-local `WORKTREE_MODE` flag in the `TestRepo` harness. When enabled, `TestRepo::new()` transparently returns a worktree-backed repo, and `insta` snapshots get a `worktree` suffix. - Implements a worktree-backed `TestRepo::new_worktree_variant()` that: - creates a base repo - ensures there’s at least one commit (worktree requirement) - moves the base repo off `main` so a worktree can check out `main` - creates a linked worktree and returns a `TestRepo` pointing to it - cleans up both base+worktree paths on drop - Adds `reuse_tests_in_worktree!(...)` macro to generate a second `#[test]` that calls the original test function inside `with_worktree_mode`. - Demonstrates usage by reusing tests in: - `tests/cherry_pick.rs` (all tests) - `tests/stash_attribution.rs` (all tests) - `tests/simple_additions.rs` (subset of 10 tests) Stacked on: `codex/worktree-support-complete` (PR #582). ## Review & Testing Checklist for Human - [ ] Sanity-check `TestRepo::new_worktree_variant()` semantics: base branch switching + worktree checkout on `main` is correct for all modes, and doesn’t break tests that assume current branch is `main`. - [ ] Review cleanup logic in `Drop` for worktree-backed repos (base/worktree deletion + `git worktree remove --force`): ensure it can’t delete an unintended directory and behaves well on CI. - [ ] Confirm the macro-generated test naming (`<original>_in_worktree`) won’t collide with existing tests in the crate(s) you plan to apply it to. - [ ] Consider CI/runtime impact: this duplicates selected tests; verify overall test runtime is still acceptable. - [ ] Run a representative local subset (or in CI) to confirm the reused tests actually exercise worktree paths (i.e., `TestRepo::new()` is being hit) and don’t silently fall back to non-worktree flows. ### Notes - Devin run: https://app.devin.ai/sessions/1044345a7d8a4379a2940713b5c02133 - Requested by: @svarlamov <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/git-ai-project/git-ai/pull/585" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
kerem 2026-03-02 04:14:03 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#589
No description provided.