@git-worktree-apply
Feature: Git worktree sandbox apply lifecycle (#4454)
  Verifies that the apply phase merges LLM output from a git worktree
  branch back into the project's main branch.

  Scenario: Create worktree sandbox for git-checkout resource for wt_apply
    Given a temp git project with 1 file for wt_apply
    When I create a sandbox for the project for wt_apply
    Then the sandbox path should be a directory for wt_apply
    And the sandbox path should differ from the project path for wt_apply

  Scenario: Worktree branch exists after sandbox creation for wt_apply
    Given a temp git project with 1 file for wt_apply
    When I create a sandbox for the project for wt_apply
    Then the branch "cleveragents/plan-01TEST00000000000000000099" should exist for wt_apply

  Scenario: Files written to sandbox appear on worktree branch for wt_apply
    Given a temp git project with 1 file for wt_apply
    And I create a sandbox for the project for wt_apply
    When I write "fixed.py" to the sandbox for wt_apply
    And I commit the sandbox for wt_apply
    Then "fixed.py" should exist on branch "cleveragents/plan-01TEST00000000000000000099" for wt_apply

  Scenario: Merge applies changes to main branch for wt_apply
    Given a temp git project with 1 file for wt_apply
    And I create a sandbox for the project for wt_apply
    And I write "fixed.py" to the sandbox for wt_apply
    And I commit the sandbox for wt_apply
    When I merge the sandbox branch into main for wt_apply
    Then "fixed.py" should exist in the project root for wt_apply

  Scenario: Cleanup removes worktree and branch for wt_apply
    Given a temp git project with 1 file for wt_apply
    And I create a sandbox for the project for wt_apply
    When I cleanup the sandbox for wt_apply
    Then the sandbox path should not exist for wt_apply
    And the branch "cleveragents/plan-01TEST00000000000000000099" should not exist for wt_apply

  Scenario: Fallback to flat copy for non-git directory for wt_apply
    Given a temp non-git directory with 1 file for wt_apply
    When I copy files from sandbox to project for wt_apply
    Then the project should have the copied file for wt_apply
