Files
cleveragents-core/features/subplan_spawn_service.feature
T
freemo c43e1f8260
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 14s
CI / quality (pull_request) Successful in 19s
CI / build (pull_request) Successful in 14s
CI / typecheck (pull_request) Successful in 31s
CI / security (pull_request) Successful in 32s
CI / unit_tests (pull_request) Successful in 1m52s
CI / docker (pull_request) Successful in 42s
CI / integration_tests (pull_request) Successful in 2m59s
CI / coverage (pull_request) Successful in 4m14s
CI / lint (push) Successful in 15s
CI / quality (push) Successful in 16s
CI / security (push) Successful in 30s
CI / typecheck (push) Successful in 1m3s
CI / build (push) Successful in 18s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 2m27s
CI / integration_tests (push) Successful in 3m0s
CI / docker (push) Successful in 50s
CI / coverage (push) Successful in 5m8s
CI / benchmark-publish (push) Has been cancelled
CI / benchmark-regression (pull_request) Successful in 29m24s
feat(service): add subplan service and spawn workflow
Add SubplanService for building child plans from DecisionService spawn
entries and SubplanConfig. The service validates resource scopes, merge
strategies, and max_parallel bounds before spawning.

Key additions:
- SubplanService: Orchestrates child plan creation from spawn entries
- SpawnMetadata: Persisted metadata (spawn_decision_id, parent/root
  plan IDs, execution mode) for status output
- Spawn validation: Checks resource scopes, merge strategy, and
  parallelism bounds before spawning
- Documentation: subplan_service.md with spawn workflow and lifecycle

ISSUES CLOSED: #197
2026-03-02 09:41:25 -05:00

130 lines
5.0 KiB
Gherkin

@phase1 @subplan @spawn
Feature: Subplan Spawn Service
As a system orchestrating hierarchical plans
I want to spawn child plans from decision entries
And validate spawn requests before execution
So that parent plans can safely decompose work into coordinated child plans
# --- Successful spawn ---
@spawn_success
Scenario: Successfully spawn child plan from decision entry
Given a parent plan with a subplan spawn decision
And a subplan config with sequential execution mode
When the subplan service spawns child plans
Then 1 child plan status should be created
And the spawn metadata should contain the parent plan id
And the spawn metadata should contain the root plan id
And the spawn metadata should contain the execution mode
# --- Multiple entries ---
@spawn_multiple
Scenario: Spawn from multiple decision entries
Given a parent plan with 3 subplan spawn decisions
And a subplan config with parallel execution mode and max_parallel 5
When the subplan service spawns child plans
Then 3 child plan statuses should be created
And each status should have a unique subplan id
And the spawn result total_spawned should be 3
# --- Validation: resource scopes ---
@validation @resource_scope
Scenario: Validate spawn with missing resource scope
Given a parent plan with a spawn entry targeting resource "res-missing"
And available resources are "res-a" and "res-b"
And a subplan config with sequential execution mode
When the subplan service validates the spawn request
Then the validation result should be invalid
And the validation errors should mention unresolved resource
# --- Validation: merge strategy ---
@validation @merge_strategy
Scenario: Validate spawn with undefined merge strategy
Given a parent plan with a valid spawn entry
And a subplan config with no merge strategy
When the subplan service validates the spawn request
Then the validation result should be invalid
And the validation errors should mention merge strategy
# --- Validation: max_parallel ---
@validation @max_parallel
Scenario: Validate spawn exceeding max_parallel bound
Given a parent plan with 5 subplan spawn decisions
And a subplan config with parallel execution mode and max_parallel 3
When the subplan service validates the spawn request
Then the validation result should be invalid
And the validation errors should mention max_parallel
# --- Metadata persistence ---
@metadata
Scenario: Spawn metadata persisted for status output
Given a parent plan that is a subplan with root plan id "01HGZ6FE0AQDYTR4BXVQZ6RF00"
And a subplan config with sequential execution mode
And a valid spawn decision
When the subplan service spawns child plans
Then the spawn metadata root_plan_id should be "01HGZ6FE0AQDYTR4BXVQZ6RF00"
And the spawn metadata execution_mode should be "sequential"
# --- Decision type validation ---
@validation @decision_type
Scenario: Validate spawn with wrong decision type
Given a parent plan with a non-spawn decision type
And a subplan config with sequential execution mode
When the subplan service validates the spawn request
Then the validation result should be invalid
And the validation errors should mention decision type
# --- Get spawn decisions ---
@spawn_decisions
Scenario: Get spawn decisions from decision service
Given a decision service with spawn decisions for plan "01HGZ6FE0AQDYTR4BXVQZ6PN00"
When the subplan service retrieves spawn decisions
Then the returned decisions should only contain spawn types
# --- Build spawn entries ---
@build_entries
Scenario: Build spawn entries from decisions
Given a list of spawn decisions with resource refs
When the subplan service builds spawn entries
Then each entry should have action_name and target_resources
# --- Service construction ---
@construction
Scenario: SubplanService rejects None decision_service
When the subplan service is constructed with None decision_service
Then a ValueError should be raised for subplan service
# --- Spawn rejects None inputs ---
@validation @null_guard
Scenario: Spawn rejects None parent_plan
Given a valid subplan service
When spawn is called with None parent_plan
Then a spawn ValueError should be raised with message "parent_plan must not be None"
@validation @null_guard
Scenario: Spawn rejects empty spawn_entries
Given a valid subplan service
And a parent plan with identity
When spawn is called with empty spawn_entries
Then a spawn ValueError should be raised with message "spawn_entries must not be empty"
# --- Parallel spawn decision ---
@spawn_parallel
Scenario: Spawn from parallel spawn decision type
Given a parent plan with a subplan_parallel_spawn decision
And a subplan config with parallel execution mode and max_parallel 5
When the subplan service spawns child plans
Then 1 child plan status should be created
And the spawn metadata execution_mode should be "parallel"