Feature: M1 source-code plan lifecycle smoke tests
  As a developer working with the CleverAgents M1 milestone
  I want to verify the source-code workflow end-to-end
  So that actions, projects, resources, and plans integrate correctly

  Background:
    Given a m1 smoke test runner
    And a m1 smoke mocked lifecycle service

  # --- Fixture loading ---

  Scenario: M1 smoke load git repo fixture
    When I m1 smoke load the git repo fixture
    Then the m1 smoke git repo fixture should have a minimal repo entry
    And the m1 smoke minimal repo should contain expected files

  Scenario: M1 smoke load git checkout resource fixture
    When I m1 smoke load the git checkout resource fixture
    Then the m1 smoke git checkout fixture should have a minimal entry
    And the m1 smoke minimal checkout should have type "git-checkout"

  Scenario: M1 smoke load action YAML fixture
    When I m1 smoke load the action YAML fixture
    Then the m1 smoke action fixture should define strategy actor "openai/gpt-4"
    And the m1 smoke action fixture should define execution actor "openai/gpt-4"

  # --- Action create ---

  Scenario: M1 smoke action create from YAML config
    Given a m1 smoke temporary action config file
    When I m1 smoke invoke action create with the config
    Then the m1 smoke action create should succeed
    And the m1 smoke action output should contain "local/m1-source-review"

  # --- Project and resource link ---

  Scenario: M1 smoke create temp project and link resource
    When I m1 smoke create a temp project "local/m1-smoke-proj"
    Then the m1 smoke project creation should succeed
    And the m1 smoke project output should contain "m1-smoke-proj"

  Scenario: M1 smoke link resource to project
    Given a m1 smoke project "local/m1-smoke-proj" exists
    And a m1 smoke resource "local/m1-smoke-repo" exists
    When I m1 smoke link resource "local/m1-smoke-repo" to project "local/m1-smoke-proj"
    Then the m1 smoke link should succeed

  # --- Plan use ---

  Scenario: M1 smoke plan use creates plan in strategize phase
    Given a m1 smoke action "local/m1-source-review" exists
    When I m1 smoke invoke plan use with action "local/m1-source-review"
    Then the m1 smoke plan use should succeed
    And the m1 smoke plan should be in phase "strategize"
    And the m1 smoke captured plan id should not be empty

  Scenario: M1 smoke plan use with project argument
    Given a m1 smoke action "local/m1-source-review" exists
    When I m1 smoke invoke plan use linking project "local/m1-smoke-proj" to action "local/m1-source-review"
    Then the m1 smoke plan use should succeed

  Scenario: M1 smoke plan use with arguments
    Given a m1 smoke action "local/m1-source-review" exists
    When I m1 smoke invoke plan use passing arg "target_path=src/" to action "local/m1-source-review"
    Then the m1 smoke plan use should succeed

  # --- Plan execute ---

  Scenario: M1 smoke plan execute transitions to execute phase
    Given a m1 smoke plan exists in strategize phase
    When I m1 smoke invoke plan execute
    Then the m1 smoke plan execute should succeed
    And the m1 smoke plan should be in phase "execute"

  # --- Plan diff ---

  Scenario: M1 smoke plan diff shows changeset
    Given a m1 smoke plan exists in execute phase with changeset
    When I m1 smoke invoke plan diff
    Then the m1 smoke plan diff should succeed

  # --- Plan apply ---

  Scenario: M1 smoke plan apply transitions to applied terminal state
    Given a m1 smoke plan exists in apply phase
    When I m1 smoke invoke plan apply
    Then the m1 smoke plan apply should succeed
    And the m1 smoke plan should be in terminal state

  # --- Negative cases ---

  Scenario: M1 smoke plan use with unknown action fails
    When I m1 smoke invoke plan use with action "local/nonexistent-action"
    Then the m1 smoke plan use should fail

  Scenario: M1 smoke plan execute on non-strategize plan fails
    Given a m1 smoke plan exists in apply phase
    When I m1 smoke invoke plan execute
    Then the m1 smoke plan execute should fail

  Scenario: M1 smoke plan use with invalid actor format fails
    Given a m1 smoke action "local/m1-source-review" exists
    When I m1 smoke invoke plan use with invalid strategy actor "bad-format"
    Then the m1 smoke plan use should fail
