Files
cleveragents-core/features/plan_applied_event_enrichment.feature
T
freemo c2097ee2ed
CI / typecheck (push) Has been cancelled
CI / benchmark-publish (push) Has been cancelled
CI / quality (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / unit_tests (push) Has been cancelled
CI / security (push) Has been cancelled
CI / build (push) Has been cancelled
CI / e2e_tests (push) Has been cancelled
CI / coverage (push) Has been cancelled
CI / status-check (push) Has been cancelled
CI / benchmark-regression (push) Has been cancelled
CI / docker (push) Has been cancelled
CI / integration_tests (push) Has been cancelled
CI / helm (push) Has been cancelled
feat(events): enrich PLAN_APPLIED event with changeset statistics from PlanApplyService
Enriches the PLAN_APPLIED domain event with SEC7 audit-logging statistics per docs/specification.md §Audit Logging (issue #716).

Changes:
- PlanLifecycleService.complete_apply() now accepts optional keyword arguments: files_changed, lines_added, lines_removed, resources_modified, apply_duration_seconds (all default to 0). These are included in the PLAN_APPLIED event details dict alongside the existing action_name, phase, and project_names fields.
- PlanApplyService.apply_with_validation_gate() computes changeset statistics from SpecChangeSet.summary() and measures apply duration, then passes all statistics to complete_apply().
- New BDD feature features/plan_applied_event_enrichment.feature with 13 scenarios.

Closes #716

Co-authored-by: Jeffrey Phillips Freeman <the@jeffreyfreeman.me>
Co-committed-by: Jeffrey Phillips Freeman <the@jeffreyfreeman.me>
2026-04-02 17:08:38 +00:00

88 lines
4.5 KiB
Gherkin

Feature: PLAN_APPLIED event enrichment with changeset statistics
As an audit log consumer
I want the PLAN_APPLIED domain event to include changeset statistics
So that audit entries contain rich context per SEC7 requirements
Background:
Given a plan applied event enrichment test environment
# -- complete_apply passes statistics to event -------------------------
Scenario: complete_apply emits PLAN_APPLIED with files_changed statistic
Given a plan in Apply/PROCESSING state
When complete_apply is called with files_changed=5
Then the emitted PLAN_APPLIED event details should include files_changed=5
Scenario: complete_apply emits PLAN_APPLIED with lines_added statistic
Given a plan in Apply/PROCESSING state
When complete_apply is called with lines_added=42
Then the emitted PLAN_APPLIED event details should include lines_added=42
Scenario: complete_apply emits PLAN_APPLIED with lines_removed statistic
Given a plan in Apply/PROCESSING state
When complete_apply is called with lines_removed=7
Then the emitted PLAN_APPLIED event details should include lines_removed=7
Scenario: complete_apply emits PLAN_APPLIED with resources_modified statistic
Given a plan in Apply/PROCESSING state
When complete_apply is called with resources_modified=3
Then the emitted PLAN_APPLIED event details should include resources_modified=3
Scenario: complete_apply emits PLAN_APPLIED with apply_duration_seconds statistic
Given a plan in Apply/PROCESSING state
When complete_apply is called with apply_duration_seconds=1.5
Then the emitted PLAN_APPLIED event details should include apply_duration_seconds=1.5
Scenario: complete_apply emits PLAN_APPLIED with all statistics combined
Given a plan in Apply/PROCESSING state
When complete_apply is called with all changeset statistics
Then the emitted PLAN_APPLIED event details should include all changeset statistics
Scenario: complete_apply emits PLAN_APPLIED with zero statistics by default
Given a plan in Apply/PROCESSING state
When complete_apply is called with no changeset statistics
Then the emitted PLAN_APPLIED event details should include files_changed=0
And the emitted PLAN_APPLIED event details should include lines_added=0
And the emitted PLAN_APPLIED event details should include lines_removed=0
And the emitted PLAN_APPLIED event details should include resources_modified=0
And the emitted PLAN_APPLIED event details should include apply_duration_seconds=0.0
Scenario: complete_apply preserves existing event details alongside statistics
Given a plan applied event enrichment test environment
Given a plan in Apply/PROCESSING state with action_name "deploy-service"
When complete_apply is called with files_changed=2
Then the emitted PLAN_APPLIED event details should include action_name "deploy-service"
And the emitted PLAN_APPLIED event details should include files_changed=2
# -- apply_with_validation_gate passes statistics through ---------------
Scenario: apply_with_validation_gate passes files_changed to complete_apply
Given a plan with changeset containing 4 entries
And the plan has no validation failures
When apply_with_validation_gate is called
Then complete_apply should be called with files_changed=4
Scenario: apply_with_validation_gate passes resources_modified to complete_apply
Given a plan with changeset containing entries for 2 distinct resources
And the plan has no validation failures
When apply_with_validation_gate is called
Then complete_apply should be called with resources_modified=2
Scenario: apply_with_validation_gate passes apply_duration_seconds to complete_apply
Given a plan with changeset containing 1 entries
And the plan has no validation failures
When apply_with_validation_gate is called
Then complete_apply should be called with a non-negative apply_duration_seconds
Scenario: apply_with_validation_gate passes lines_added from creates to complete_apply
Given a plan with changeset containing 3 CREATE entries
And the plan has no validation failures
When apply_with_validation_gate is called
Then complete_apply should be called with lines_added=3
Scenario: apply_with_validation_gate passes lines_removed from deletes to complete_apply
Given a plan with changeset containing 2 DELETE entries
And the plan has no validation failures
When apply_with_validation_gate is called
Then complete_apply should be called with lines_removed=2