feat(events): enrich PLAN_APPLIED event with changeset statistics from PlanApplyService #1300
No reviewers
Labels
No labels
auto/needs-reevaluation
controller-managed
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cleveragents/cleveragents-core!1300
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/m6-plan-applied-enrichment"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
This PR enriches the
PLAN_APPLIEDevent emitted byPlanLifecycleServicewith rich changeset statistics (files changed, lines added/removed, resources modified, and apply duration) sourced fromPlanApplyService, fulfilling the SEC7 audit logging requirements outlined in the specification.Changes
PlanLifecycleService.complete_apply(): Extended the method signature to accept five optional keyword arguments —files_changed,lines_added,lines_removed,resources_modified, andapply_duration_seconds— all defaulting to0for full backward compatibility. These values are now included in thedetailsdict of the emittedPLAN_APPLIEDevent alongside the existingaction_name,phase, andproject_namesfields.PlanApplyService.apply_with_validation_gate(): Updated to compute changeset statistics by callingSpecChangeSet.summary()after the apply step, and to measure apply duration (from apply start to thecomplete_apply()call, capturing thepersist_apply_summaryduration). All five statistics are forwarded tocomplete_apply()so the emittedPLAN_APPLIEDevent carries the full SEC7 audit context.features/plan_applied_event_enrichment.feature: New BDD feature file with 13 scenarios covering: enrichment of thePLAN_APPLIEDevent via the lifecycle service, correct propagation of statistics from the apply service, default-zero behaviour for backward-compatible callers, and edge cases (empty changesets, zero-duration applies).Design Decisions
Option 2 chosen over Option 1: The issue offered two approaches — emitting a supplementary
PLAN_APPLY_COMPLETEDevent, or restructuring the pipeline so the lifecycle service receives apply results before emitting. Option 2 was selected because it keeps the full audit trail in a singlePLAN_APPLIEDevent, avoids event ordering complexity for downstream consumers (e.g.,AuditService), and is consistent with how other enriched lifecycle events are structured in the codebase.lines_added/lines_removedmapping: These fields map to theCREATEandDELETEentry counts fromSpecChangeSet.summary(), respectively. This is a deliberate approximation: the changeset tracks file-level operations rather than line-level diffs, and the field names are kept consistent with the SEC7 schema for audit log consumers.apply_duration_secondsmeasurement window: Duration is measured from the start of the apply step to thecomplete_apply()call, which encompasses thepersist_apply_summary()call. This captures the full observable apply latency from the lifecycle service's perspective.Backward compatibility: All new parameters to
complete_apply()default to0, ensuring no existing callers require modification.Testing
nox -s lint)nox -s typecheck)Modules Affected
src/cleveragents/application/services/plan_lifecycle_service.py—complete_apply()enriched with changeset statistics kwargssrc/cleveragents/application/services/plan_apply_service.py—apply_with_validation_gate()computes and forwards statisticsfeatures/plan_applied_event_enrichment.feature— 13 new BDD scenarios (new file)features/steps/plan_applied_event_enrichment_steps.py— step definitions (new file)Closes #716
Review claimed by reviewer pool instance reviewer-pool-1. Dispatching independent code review.
Code Review — PR #1300: feat(events): enrich PLAN_APPLIED event with changeset statistics
Summary
This PR enriches the
PLAN_APPLIEDdomain event with SEC7 audit-logging statistics (files changed, lines added/removed, resources modified, apply duration) by extendingPlanLifecycleService.complete_apply()and updatingPlanApplyService.apply_with_validation_gate()to compute and forward these statistics. It fulfills issue #716.Review Findings
✅ Specification Alignment
PLAN_APPLIEDevent) is the better design choice over Option 1 (supplementary event), avoiding event ordering complexity for downstream consumers likeAuditService.✅ API Consistency
complete_apply()uses keyword-only arguments with sensible defaults (0/0.0), maintaining full backward compatibility.files_changed,lines_added,lines_removed,resources_modified,apply_duration_seconds) are consistent with the SEC7 schema.creates→lines_addedanddeletes→lines_removedis a documented deliberate approximation.✅ Code Quality
complete_apply()call).✅ Type Safety
int,float).# type: ignore[import-untyped]on behave imports in the step file follows the established codebase pattern (1351 existing usages across step files).✅ Test Quality
apply_with_validation_gate→complete_applypropagation (5 scenarios)complete_applyimplementation with mock infrastructure, providing meaningful behavioral verification.✅ Backward Compatibility
⚠️ Minor Notes (non-blocking)
Type/label: PR should have aType/Featurelabel per CONTRIBUTING.md. Not a code issue._make_mock_plan(),_make_changeset(), and_build_lifecycle_with_capturing_bus()are defined in the step file rather thanfeatures/mocks/. These are scenario-specific fixtures rather than reusable test doubles, so this is acceptable.Decision: APPROVED ✅
The implementation is clean, well-documented, backward-compatible, and thoroughly tested. The design choice (Option 2) is sound and consistent with the codebase's event patterns. Proceeding with merge.