Files
cleveragents-core/features/strategize_decision_recording.feature
HAL9000 e7fb7168b4 feat(decisions): implement decision recording hook in Strategize phase
Implement the StrategizeDecisionHook class for recording decisions during
the Strategize phase. The hook captures every decision point with question,
chosen_option, alternatives_considered, confidence_score, rationale, and
full context_snapshot (hot_context_hash, actor_state_ref, relevant_resources).

Supports four decision types: strategy_choice, resource_selection,
subplan_spawn, and invariant_enforced. Includes a DecisionRecorder protocol
port for decoupled persistence and capture_context_snapshot utility function.

Comprehensive BDD test suite with 40+ scenarios covering all decision types,
context snapshot validation, error handling, and tree structure tracking.

ISSUES CLOSED: #8522
2026-05-08 06:24:23 +00:00

158 lines
7.8 KiB
Gherkin

Feature: Decision recording hook in Strategize phase
As a strategy actor
I want to record decisions during the Strategize phase
So that every choice point is captured with full context for replay and correction
Background:
Given a strategize decision service
And a strategize decision hook for plan "01JQAAAAAAAAAAAAAAAAAAAA01"
# --- Strategy Choice Recording ---
Scenario: Record a strategy choice decision
When I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision should be recorded successfully
And the strat decision type should be "strategy_choice"
And the strat decision question should be "Which approach?"
And the strat decision chosen_option should be "Approach A"
And the strat decision phase should be "strategize"
Scenario: Record strategy choice with alternatives
When two strat alternatives "Approach B" and "Approach C"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision should have 2 alternatives considered
Scenario: Record strategy choice with confidence score
When strat confidence 0.85
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision confidence score should be 0.85
Scenario: Record strategy choice with rationale
When strat rationale "Approach A is more efficient"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision rationale should be "Approach A is more efficient"
Scenario: Record strategy choice with context snapshot
When strat context data containing "key1" "value1"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision context snapshot hash should start with "sha256:"
And the strat decision context snapshot ref should not be empty
Scenario: Record strategy choice with actor state
When strat actor state containing "reasoning" "step1"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision actor state ref should not be empty
Scenario: Record strategy choice with relevant resources
When two strat relevant resources "resource1" and "resource2"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision should have 2 relevant resources
Scenario: Record strategy choice with empty question raises error
When I try to record a strategy choice with empty question
Then a strat validation error should be raised
And the strat error should mention "question"
Scenario: Record strategy choice with empty option raises error
When I try to record a strategy choice with empty chosen_option
Then a strat validation error should be raised
And the strat error should mention "chosen_option"
# --- Resource Selection Recording ---
Scenario: Record a resource selection decision
When I record a resource selection with question "Which resources?" and option "src/main.py"
Then the strat decision should be recorded successfully
And the strat decision type should be "resource_selection"
And the strat decision question should be "Which resources?"
And the strat decision chosen_option should be "src/main.py"
Scenario: Record resource selection with alternatives
When two strat alternatives "src/test.py" and "src/utils.py"
And I record a resource selection with question "Which resources?" and option "src/main.py"
Then the strat decision should have 2 alternatives considered
Scenario: Record resource selection with confidence
When strat confidence 0.9
And I record a resource selection with question "Which resources?" and option "src/main.py"
Then the strat decision confidence score should be 0.9
# --- Subplan Spawn Recording ---
Scenario: Record a subplan spawn decision
When I record a subplan spawn with question "Should we decompose?" and option "Create subplan for feature X"
Then the strat decision should be recorded successfully
And the strat decision type should be "subplan_spawn"
And the strat decision question should be "Should we decompose?"
And the strat decision chosen_option should be "Create subplan for feature X"
Scenario: Record subplan spawn with alternatives
When two strat alternatives "Implement inline" and "Create parallel subplans"
And I record a subplan spawn with question "Should we decompose?" and option "Create subplan for feature X"
Then the strat decision should have 2 alternatives considered
Scenario: Record subplan spawn with confidence
When strat confidence 0.75
And I record a subplan spawn with question "Should we decompose?" and option "Create subplan for feature X"
Then the strat decision confidence score should be 0.75
# --- Invariant Enforcement Recording ---
Scenario: Record an invariant enforced decision
When I record an invariant enforced with question "Apply security invariant?" and option "Enforce code review"
Then the strat decision should be recorded successfully
And the strat decision type should be "invariant_enforced"
And the strat decision question should be "Apply security invariant?"
And the strat decision chosen_option should be "Enforce code review"
Scenario: Record invariant enforced with rationale
When strat rationale "Security policy requires code review"
And I record an invariant enforced with question "Apply security invariant?" and option "Enforce code review"
Then the strat decision rationale should be "Security policy requires code review"
# --- Context Snapshot Capture ---
Scenario: Context snapshot captures hot context hash
When strat context data containing "plan_id" "01JQAAAAAAAAAAAAAAAAAAAA01"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision context snapshot hash should start with "sha256:"
Scenario: Context snapshot captures actor state reference
When strat actor state containing "step" "1"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision actor state ref should start with "checkpoint:"
Scenario: Context snapshot captures relevant resources
When three strat relevant resources "res1" and "res2" and "res3"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision should have 3 relevant resources
And each strat resource should have a valid resource_id
# --- Error Handling ---
Scenario: Recording with invalid plan_id raises error
Given a strategize decision hook with empty plan_id
Then a strat validation error should be raised
And the strat error should mention "plan_id"
Scenario: Recording failure logs warning and re-raises exception
When the strat decision service fails to persist
And I try to record a strategy choice that raises an exception
Then a strat warning should be logged
And the strat exception should be re-raised
# --- Parent Decision Tracking ---
Scenario: Record decision with parent decision ID
When strat parent decision ID "01PARENT000000000000000000"
And I record a strategy choice with question "Which approach?" and option "Approach A"
Then the strat decision parent_decision_id should be "01PARENT000000000000000000"
Scenario: Record multiple decisions in tree structure
When I record a strategy choice with question "Q1" and option "A1"
And I save the first strat decision
And strat parent decision ID from the first decision
And I record a strategy choice with question "Q2" and option "A2"
Then the second strat decision parent_decision_id should match the first decision
And both strat decisions should be in the same plan