@checkpoint-wiring
Feature: CheckpointManager wired into PlanExecutor (#1253)
  Verifies that checkpoints are automatically created during
  plan execution and that last_checkpoint_id is set on the plan.

  Scenario: PlanExecutor receives CheckpointManager from CLI factory for ckpt_wire
    When I build a PlanExecutor via _get_plan_executor for ckpt_wire
    Then the executor checkpoint_manager should not be None for ckpt_wire

  Scenario: PlanExecutor reuses CheckpointManager singleton from DI container for ckpt_wire
    When I build a PlanExecutor via _get_plan_executor for ckpt_wire
    And I get CheckpointManager from the DI container for ckpt_wire
    Then the executor checkpoint_manager should be the container singleton for ckpt_wire

  Scenario: CheckpointManager is registered in DI container for ckpt_wire
    When I get CheckpointManager from the DI container for ckpt_wire
    Then the container checkpoint_manager should not be None for ckpt_wire

  Scenario: _try_create_checkpoint creates real checkpoint when manager present for ckpt_wire
    Given a PlanExecutor with a real CheckpointManager for ckpt_wire
    And a plan exists in the lifecycle service for ckpt_wire
    And a sandbox exists for the test plan for ckpt_wire
    When I call _try_create_checkpoint for ckpt_wire
    Then a SandboxCheckpoint should be returned for ckpt_wire

  Scenario: _try_create_checkpoint returns None when manager is None for ckpt_wire
    Given a PlanExecutor with no CheckpointManager for ckpt_wire
    When I call _try_create_checkpoint for ckpt_wire
    Then None should be returned for ckpt_wire

  Scenario: Checkpoint creation sets last_checkpoint_id on plan for ckpt_wire
    Given a PlanExecutor with a real CheckpointManager for ckpt_wire
    And a plan exists in the lifecycle service for ckpt_wire
    And a sandbox exists for the test plan for ckpt_wire
    When I call _try_create_checkpoint for ckpt_wire
    Then the plan last_checkpoint_id should not be None for ckpt_wire

  Scenario: Plan rollback restores sandbox from auto checkpoint for ckpt_wire
    Given a PlanExecutor with a real CheckpointManager for ckpt_wire
    And a plan exists in the lifecycle service for ckpt_wire
    And a sandbox exists for the test plan for ckpt_wire
    When I call _try_create_checkpoint for ckpt_wire
    And I mutate the sandbox file for ckpt_wire
    And I rollback to the last checkpoint via the executor for ckpt_wire
    Then rollback should succeed for ckpt_wire
    And the sandbox file should match the original contents for ckpt_wire

  Scenario: CheckpointManager takes no constructor arguments for ckpt_wire
    When I instantiate CheckpointManager with no args for ckpt_wire
    Then CheckpointManager should be created successfully for ckpt_wire

  Scenario: Writable tools and resources default to checkpointable for ckpt_wire
    When I create default capabilities for a writable resource for ckpt_wire
    And I create default capabilities for a writable tool for ckpt_wire
    Then the resource capability should be checkpointable for ckpt_wire
    And the tool capability should be checkpointable for ckpt_wire

  Scenario: Non-writable resource defaults to not checkpointable for ckpt_wire
    When I create capabilities for a non-writable resource for ckpt_wire
    Then the resource capability should not be checkpointable for ckpt_wire

  Scenario: Non-writable resource with explicit checkpointable raises error for ckpt_wire
    Then creating a non-writable resource with checkpointable True should raise ValueError for ckpt_wire
