@tdd_issue @tdd_issue_1025
Feature: TDD Bug #1025 — plan correct auto-resolve fails in isolated environments
  As a developer
  I want plan correct to auto-resolve the active plan when invoked
  with a decision_id and no --plan flag
  So that the CLI works without manually specifying the plan ID

  The plan correct CLI command uses _resolve_active_plan_id() to find
  the current plan when --plan is omitted.  In isolated E2E environments
  (where CLEVERAGENTS_HOME is a temp directory), this resolution fails
  even when a plan in Execute/COMPLETE state exists in the database.

  The expected behavior is that _resolve_active_plan_id() finds the
  plan in Execute/COMPLETE state and auto-resolves it, allowing the
  correction to proceed without the explicit --plan flag.

  Bug #1025 reports that running:
    plan correct <decision_id> --mode revert --guidance "..."
  fails with "No active plan found" in isolated subprocess environments.

  These tests simulate the isolated-environment condition by providing
  divergent container instances: the main correct_decision context gets
  a container with plans, but the _resolve_active_plan_id path gets a
  container with an empty database (mimicking a fresh CLEVERAGENTS_HOME).

  The scenarios assert the expected (correct) behavior and will FAIL
  until the bug is fixed.  The @tag inverts the
  result so CI passes.

  # This test captures bug #1025 and uses @until the
  # fix is merged.

  @tdd_issue @tdd_issue_4285 @tdd_expected_fail
  Scenario: plan correct auto-resolves active plan in revert mode
    Given tpcar a container with a plan in Execute/COMPLETE and an isolated auto-resolve path
    And tpcar a CorrectionService that succeeds for the target decision in revert mode
    When tpcar I invoke plan correct with a decision_id and no --plan flag in revert mode
    Then tpcar the command should exit successfully
    And tpcar the correction should have used the auto-resolved plan

  @tdd_issue @tdd_issue_4285 @tdd_expected_fail
  Scenario: plan correct auto-resolves active plan in append mode
    Given tpcar a container with a plan in Execute/COMPLETE and an isolated auto-resolve path
    And tpcar a CorrectionService that succeeds for the target decision in append mode
    When tpcar I invoke plan correct with a decision_id and no --plan flag in append mode
    Then tpcar the command should exit successfully
    And tpcar the correction should have used the auto-resolved plan
