@tdd_issue @tdd_issue_11121
Feature: TDD Issue #11121 — cleanup_stale destroys git worktree branch on re-invoked execute
  As a developer
  I want to verify that _create_sandbox_for_plan does NOT delete the cleveragents/plan-<id>
  branch when the plan is already in execute/complete state
  So that plan apply can subsequently find and merge the correct artifacts

  Bug #11121: _create_sandbox_for_plan() calls GitWorktreeSandbox.cleanup_stale()
  unconditionally every time agents plan execute is invoked — including when the plan
  is already in execute/complete state (execution finished, awaiting apply). This deletes
  the cleveragents/plan-<id> git branch that holds the execution output, so when
  agents plan apply runs next it finds no branch and merges zero artifacts.

  @tdd_issue @tdd_issue_11121 @mock_only
  Scenario: cleveragents/plan-<id> branch survives a second _create_sandbox_for_plan call when plan is execute/complete
    Given a temp git repo with an execute-output branch for tdd 11121
    And a mocked plan service with the plan in execute/complete state for tdd 11121
    When I call _create_sandbox_for_plan a second time on the execute/complete plan for tdd 11121
    Then the cleveragents plan branch should still exist after the second call for tdd 11121

  @tdd_issue @tdd_issue_11121 @mock_only
  Scenario: plan apply finds non-zero artifacts after re-invoked execute on execute/complete plan
    Given a temp git repo with an execute-output branch for tdd 11121
    And a mocked plan service with the plan in execute/complete state for tdd 11121
    When I call _create_sandbox_for_plan a second time on the execute/complete plan for tdd 11121
    Then the apply sandbox changes should find at least one artifact for tdd 11121

  @tdd_issue @tdd_issue_11121 @mock_only
  Scenario: cleveragents/plan-<id> branch survives a second _create_sandbox_for_plan call when plan is execute/processing
    Given a temp git repo with an execute-output branch for tdd 11121
    And a mocked plan service with the plan in execute/processing state for tdd 11121
    When I call _create_sandbox_for_plan a second time on the execute/processing plan for tdd 11121
    Then the cleveragents plan branch should still exist after the second call for tdd 11121
