---
phase: 19-checkout-command
plan: 02
type: execute
wave: 1
depends_on: []
files_modified:
  - tests/test_checkout.py
autonomous: true

must_haves:
  truths:
    - "Tests verify checkout <commit> works"
    - "Tests verify checkout <branch> works"
    - "Tests verify checkout <file> and checkout -- <file> work"
    - "Tests verify checkout -b <name> creates branch"
    - "Tests verify ambiguity detection and error message"
  artifacts:
    - path: "tests/test_checkout.py"
      provides: "E2E tests for all checkout requirements"
      min_lines: 100
      contains: "class TestCheckout"
  key_links:
    - from: "tests/test_checkout.py"
      to: "conftest.py"
      via: "fixtures"
      pattern: "sl_repo_with_commit"
---

<objective>
Create E2E tests for the checkout command

Purpose: Verify all 6 checkout requirements work correctly against real Sapling repos
Output: tests/test_checkout.py with comprehensive coverage of CHECKOUT-01 through CHECKOUT-06
</objective>

<execution_context>
@~/.claude/get-shit-done/workflows/execute-plan.md
@~/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/phases/19-checkout-command/19-RESEARCH.md

# Test patterns from prior phases
@tests/conftest.py - Test fixtures (sl_repo_with_commit, run_gitsl)
@tests/test_stash.py - Similar test structure pattern
</context>

<tasks>

<task type="auto">
  <name>Task 1: Create E2E test file for checkout command</name>
  <files>tests/test_checkout.py</files>
  <action>
Create tests/test_checkout.py with:

1. **Imports and markers:**
   ```python
   """E2E tests for git checkout command (CHECKOUT-01 through CHECKOUT-06)."""

   import shutil
   from pathlib import Path

   import pytest

   from conftest import run_gitsl
   from helpers.commands import run_command

   sl_available = shutil.which("sl") is not None
   pytestmark = [
       pytest.mark.skipif(not sl_available, reason="Sapling (sl) not installed"),
       pytest.mark.checkout,
   ]
   ```

2. **TestCheckoutCommit class (CHECKOUT-01):**
   - test_checkout_commit_hash: Get commit hash with sl log, checkout that hash, verify exit 0
   - test_checkout_partial_hash: Use first 7 chars of hash, verify works

3. **TestCheckoutBranch class (CHECKOUT-02):**
   - test_checkout_bookmark: Create bookmark, checkout it, verify exit 0
   - test_checkout_activates_bookmark: Verify bookmark is active after checkout

4. **TestCheckoutFile class (CHECKOUT-03, CHECKOUT-04):**
   - test_checkout_file_without_separator: Modify tracked file, checkout filename, verify restored
   - test_checkout_file_with_separator: Modify file, checkout -- filename, verify restored
   - test_checkout_commit_file: Use checkout <commit> -- <file> to restore from specific commit

5. **TestCheckoutCreateBranch class (CHECKOUT-05):**
   - test_checkout_b_creates_branch: checkout -b name, verify bookmark exists
   - test_checkout_B_updates_branch: checkout -B name on existing, verify updates (or silently succeeds)
   - test_checkout_b_with_startpoint: checkout -b name <start>, verify at correct position

6. **TestCheckoutDisambiguation class (CHECKOUT-06):**
   - test_checkout_ambiguous_errors: Create bookmark AND file with same name, verify exit 1 with "could be both" message
   - test_checkout_separator_resolves_ambiguity: Same setup, use --, verify file restored
   - test_checkout_revision_priority: When only revision matches, verify goto used
   - test_checkout_file_priority: When only file matches, verify revert used

7. **TestCheckoutErrors class:**
   - test_checkout_no_args: Verify error message when no arguments provided
   - test_checkout_invalid_target: Nonexistent ref and file gives sl error

Register marker in pytest.ini or conftest.py if needed.
  </action>
  <verify>pytest tests/test_checkout.py --collect-only shows all test classes collected</verify>
  <done>tests/test_checkout.py exists with all test classes covering CHECKOUT-01 through CHECKOUT-06</done>
</task>

<task type="auto">
  <name>Task 2: Register checkout marker and run tests</name>
  <files>tests/conftest.py (marker only if needed)</files>
  <action>
1. Check if pytest.ini or pyproject.toml has marker registration.
   - If markers are registered there, add: checkout = "Tests for git checkout command"
   - If using conftest.py for markers, add to pytest_configure if it exists

2. Run the tests:
   ```bash
   pytest tests/test_checkout.py -v
   ```

3. If any tests fail, debug and fix. Common issues:
   - Bookmark activation check may need different assertion
   - Partial hash might need specific length
   - Ambiguity test needs both bookmark AND committed file (not just untracked)

All tests should pass before marking done.
  </action>
  <verify>pytest tests/test_checkout.py -v shows all tests passing</verify>
  <done>All checkout tests pass, marker registered</done>
</task>

</tasks>

<verification>
1. Collect check: `pytest tests/test_checkout.py --collect-only`
2. Run all: `pytest tests/test_checkout.py -v`
3. Run with marker: `pytest -m checkout -v`
4. Full test suite: `pytest -v` (ensure no regressions)
</verification>

<success_criteria>
- tests/test_checkout.py exists with all test classes
- All tests pass when run against sl repo with cmd_checkout.py
- No regressions in existing test suite
- Coverage of all 6 requirements:
  - CHECKOUT-01: commit hash checkout tested
  - CHECKOUT-02: branch/bookmark checkout tested
  - CHECKOUT-03: file checkout without -- tested
  - CHECKOUT-04: file checkout with -- tested
  - CHECKOUT-05: -b branch creation tested
  - CHECKOUT-06: disambiguation and error tested
</success_criteria>

<output>
After completion, create `.planning/phases/19-checkout-command/19-02-SUMMARY.md`
</output>
