Feature: Subplan Model Hierarchy and Configuration As a developer I want the Plan model to support subplan hierarchies So that parent plans can decompose work into coordinated child plans # Root plan identity Scenario: Root plan has no parent and root equals self Given I create a subplan-test root plan Then the subplan-test plan should not be a subplan And the subplan-test plan should be a root plan And the subplan-test plan depth should be 0 Scenario: Root plan with explicit root_plan_id equal to plan_id Given I create a subplan-test plan with root_plan_id equal to plan_id Then the subplan-test plan should be a root plan And the subplan-test plan should not be a subplan # Child plan identity Scenario: Child plan with parent_plan_id set is a subplan Given I create a subplan-test child plan with a parent Then the subplan-test plan should be a subplan And the subplan-test plan should not be a root plan And the subplan-test plan attempt should be 1 Scenario: Root plan id propagates to nested children Given I create a subplan-test three-level hierarchy Then the subplan-test grandchild root_plan_id should match the root plan_id # Default values for new plans Scenario: New plan defaults to strategize phase and queued state Given I create a subplan-test default plan Then the subplan-test plan phase should be "strategize" And the subplan-test plan processing state should be "queued" And the subplan-test plan should not be terminal And the subplan-test plan should not be errored Scenario: New plan defaults to no automation profile Given I create a subplan-test default plan Then the subplan-test plan automation profile should be none Scenario: New plan has no subplan config by default Given I create a subplan-test default plan Then the subplan-test plan subplan_config should be none Scenario: New plan has empty subplan statuses by default Given I create a subplan-test default plan Then the subplan-test plan should have 0 subplan statuses # Subplan config storage and retrieval Scenario: Plan stores sequential subplan config Given I create a subplan-test plan with sequential subplan config Then the subplan-test plan subplan_config execution_mode should be "sequential" And the subplan-test plan subplan_config merge_strategy should be "git_three_way" And the subplan-test plan subplan_config fail_fast should be false Scenario: Plan stores parallel subplan config with custom settings Given I create a subplan-test plan with parallel subplan config Then the subplan-test plan subplan_config execution_mode should be "parallel" And the subplan-test plan subplan_config max_parallel should be 10 And the subplan-test plan subplan_config retry_failed should be true And the subplan-test plan subplan_config max_retries should be 3 Scenario: SubplanConfig defaults are sensible Given I create a subplan-test default subplan config Then the subplan-test subplan config execution_mode should be "sequential" And the subplan-test subplan config merge_strategy should be "git_three_way" And the subplan-test subplan config max_parallel should be 5 And the subplan-test subplan config fail_fast should be false And the subplan-test subplan config retry_failed should be true And the subplan-test subplan config max_retries should be 2 And the subplan-test subplan config timeout should be none # Plan hierarchy helpers Scenario: Plan with subplan statuses reports has_subplans true Given I create a subplan-test plan with one subplan status Then the subplan-test plan should have subplans Scenario: Plan without subplan statuses reports has_subplans false Given I create a subplan-test default plan Then the subplan-test plan should not have subplans Scenario: Depth returns negative one for non-root plans Given I create a subplan-test child plan with a parent Then the subplan-test plan depth should be -1 # Child plans follow same lifecycle as root plans Scenario: Child plan transitions follow standard lifecycle Then subplan-test transition from "action" to "strategize" should be valid And subplan-test transition from "strategize" to "execute" should be valid And subplan-test transition from "execute" to "apply" should be valid Scenario: Child plan invalid transitions are rejected Then subplan-test transition from "strategize" to "apply" should be invalid And subplan-test transition from "action" to "execute" should be invalid And subplan-test transition from "action" to "apply" should be invalid # Dependency guardrails Scenario: SubplanFailureHandler stops others when fail_fast is true Given I create a subplan-test fail-fast config with errored status Then the subplan-test failure handler should stop others Scenario: SubplanFailureHandler does not stop others for parallel without fail_fast Given I create a subplan-test parallel-no-fail-fast config with errored status Then the subplan-test failure handler should not stop others Scenario: SubplanFailureHandler retries retriable failure Given I create a subplan-test config with retriable timeout error Then the subplan-test failure handler should retry Scenario: SubplanFailureHandler does not retry non-retriable error Given I create a subplan-test config with non-retriable configuration error Then the subplan-test failure handler should not retry Scenario: SubplanFailureHandler does not retry when retries disabled Given I create a subplan-test config with retries disabled and retriable error Then the subplan-test failure handler should not retry Scenario: SubplanFailureHandler does not retry when max retries exceeded Given I create a subplan-test config with max retries exceeded Then the subplan-test failure handler should not retry # CLI dict rendering for subplan hierarchy Scenario: CLI dict includes parent_plan_id for child plans Given I create a subplan-test child plan with a parent And I build a subplan-test plan with the child identity Then the subplan-test cli dict should contain parent_plan_id Scenario: CLI dict includes subplan_count when subplans exist Given I create a subplan-test plan with one subplan status Then the subplan-test cli dict should contain subplan_count of 1 Scenario: CLI dict omits parent_plan_id for root plans Given I create a subplan-test root plan And I build a subplan-test plan with the root identity Then the subplan-test cli dict should not contain parent_plan_id # Validation guardrails Scenario: Invalid ULID for parent_plan_id raises validation error When I try to create a subplan-test identity with invalid parent ULID Then a validation error should be raised Scenario: SubplanConfig max_parallel below minimum raises validation error When I try to create a subplan-test config with max_parallel 0 Then a validation error should be raised Scenario: SubplanConfig max_parallel above maximum raises validation error When I try to create a subplan-test config with max_parallel 51 Then a validation error should be raised Scenario: SubplanConfig max_retries below minimum raises validation error When I try to create a subplan-test config with max_retries -1 Then a validation error should be raised