@merge-conflict-abort
Feature: Plan apply aborts merge on conflict (#7250)
  Verifies that when plan apply encounters a git merge conflict,
  the merge is aborted and the project is left in a clean state.
  Also covers timeout handling and flat file copy failures.

  Scenario: Merge conflict aborts cleanly and repo stays clean for mca
    Given a temp git project with a file "config.py" for mca
    And a worktree branch with a conflicting change to "config.py" for mca
    And the user commits a different change to "config.py" on main for mca
    When I attempt to merge the worktree branch for mca
    Then the merge should fail for mca
    And the merge should be aborted for mca
    And "config.py" should not contain conflict markers for mca
    And git status should be clean for mca

  Scenario: Merge abort failure warns user about unclean state for mca
    Given a temp git project with a file "data.txt" for mca
    And a worktree branch with a conflicting change to "data.txt" for mca
    And the user commits a different change to "data.txt" on main for mca
    When I attempt to merge the worktree branch and the abort fails for mca
    Then the merge should fail for mca
    And the abort failure should be reported for mca

  Scenario: _apply_sandbox_changes returns False on merge conflict for mca
    Given a temp git project with a file "app.py" for mca
    And a worktree branch with a conflicting change to "app.py" for mca
    And the user commits a different change to "app.py" on main for mca
    When I call _apply_sandbox_changes with the conflicting project for mca
    Then _apply_sandbox_changes should return False for mca
    And "app.py" should not contain conflict markers for mca
    And git status should be clean for mca

  Scenario: _apply_sandbox_changes returns True on clean merge for mca
    Given a temp git project with a file "clean.py" for mca
    And a worktree branch with a non-conflicting change for mca
    When I call _apply_sandbox_changes with the clean project for mca
    Then _apply_sandbox_changes should return True for mca

  Scenario: Merge timeout returns False and advises manual cleanup for mca
    Given a mock subprocess that raises TimeoutExpired on merge for mca
    When I call _apply_sandbox_changes with the mocked merge for mca
    Then _apply_sandbox_changes should return False for mca
    And the timeout error message should be displayed for mca

  Scenario: Abort timeout returns False and advises manual cleanup for mca
    Given a mock subprocess that raises TimeoutExpired on abort for mca
    When I call _apply_sandbox_changes with the mocked abort for mca
    Then _apply_sandbox_changes should return False for mca
    And the abort timeout message should be displayed for mca

  Scenario: Flat file copy failure returns False for mca
    Given a temp sandbox with a file that cannot be copied for mca
    When I call _apply_sandbox_changes with the failing flat copy for mca
    Then _apply_sandbox_changes should return False for mca
