Files
cleveragents-core/features/predictive_error_prevention.feature
freemo 583e6b7ea2
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 14s
CI / build (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 17s
CI / security (pull_request) Successful in 36s
CI / typecheck (pull_request) Successful in 54s
CI / unit_tests (pull_request) Successful in 2m39s
CI / integration_tests (pull_request) Successful in 3m10s
CI / docker (pull_request) Successful in 40s
CI / coverage (pull_request) Successful in 5m0s
CI / lint (push) Successful in 14s
CI / build (push) Successful in 15s
CI / quality (push) Successful in 16s
CI / security (push) Successful in 34s
CI / typecheck (push) Successful in 35s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 2m23s
CI / docker (push) Successful in 38s
CI / integration_tests (push) Successful in 3m8s
CI / coverage (push) Successful in 5m10s
CI / benchmark-publish (push) Successful in 16m26s
CI / benchmark-regression (pull_request) Successful in 30m12s
feat(correcting-plans): implement Predictive Error Prevention (Layer 4) with Error Pattern Database
Implement spec-mandated Layer 4 Predictive Error Prevention system:

- ErrorPattern domain model with pattern text, historical failures,
  preventive checks, frequency tracking, and keyword-based matching.
- ErrorPatternRepository with in-memory CRUD + context-matching query.
- ErrorPatternService with record_failure(), match_patterns(), and
  get_statistics() methods.
- Wire into plan execution via plan_lifecycle_service pre-execution hook.
- Add error pattern statistics to CLI diagnostics output.

Behave BDD: 11 scenarios covering recording, matching, formatting, stats.
Robot Framework: 3 integration smoke tests.
ASV benchmarks: pattern matching performance.

ISSUES CLOSED: #571
2026-03-08 21:53:21 -04:00

77 lines
4.4 KiB
Gherkin

Feature: Predictive Error Prevention — Layer 4 Error Pattern Database
As a plan executor
I want historical failure patterns to be consulted before execution
So that preventive guidance prevents recurring errors
Scenario: pep-record Recording a new failure pattern creates an entry
Given a fresh error pattern service
When I record a failure with pattern "Race condition in payment module" and failure "Payment confirmation timeout"
Then the error pattern database should contain 1 pattern
And the pattern should have frequency 1
Scenario: pep-record Recording the same pattern again increments frequency
Given a fresh error pattern service
When I record a failure with pattern "Race condition in payment module" and failure "Payment confirmation timeout"
And I record a failure with pattern "Race condition in payment module" and failure "Idempotency key collision"
Then the error pattern database should contain 1 pattern
And the pattern should have frequency 2
And the pattern should have 2 historical failures
Scenario: pep-match Matching context text against known patterns returns guidance
Given a fresh error pattern service
And a recorded pattern "Async conversion" with preventive check "Add explicit transaction boundaries"
When I match context "We need to perform async conversion in the payment module"
Then preventive guidance should contain "Add explicit transaction boundaries"
Scenario: pep-match No matching patterns returns empty guidance
Given a fresh error pattern service
And a recorded pattern "Async conversion" with preventive check "Add transaction boundaries"
When I match context "Simple refactoring of the UI component"
Then preventive guidance should be empty
Scenario: pep-format Preventive guidance formats for actor context
Given a fresh error pattern service
And a recorded pattern "Memory leak" with preventive check "Check resource cleanup"
And a recorded pattern "Memory leak" with preventive check "Verify dispose patterns"
When I match context "Fix the memory leak in the cache service"
Then the formatted guidance should contain "PREVENTIVE GUIDANCE"
And the formatted guidance should contain "Check resource cleanup"
Scenario: pep-stats Statistics report pattern counts
Given a fresh error pattern service
And a recorded pattern "Race condition" with preventive check "Add locks"
And a recorded pattern "Memory leak" with preventive check "Check cleanup"
When I request error pattern statistics
Then the statistics should show 2 total patterns
Scenario: pep-extract Keywords are automatically extracted from pattern text
Given a fresh error pattern service
When I record a failure with pattern "Race condition in payment processing module" and failure "Timeout"
Then the recorded pattern should have keywords including "race"
And the recorded pattern should have keywords including "payment"
Scenario: pep-multi Multiple patterns match and checks are deduplicated
Given a fresh error pattern service
And a recorded pattern "async conversion" with preventive check "Add transaction boundaries" and keywords "async,conversion"
And a recorded pattern "async timeout" with preventive check "Add retry logic" and keywords "async,timeout"
When I match context "Handle async conversion with proper timeout handling"
Then preventive guidance should contain "Add transaction boundaries"
And preventive guidance should contain "Add retry logic"
Scenario: pep-repo-get Repository get returns pattern by ID
Given a fresh error pattern service
When I record a failure with pattern "Test pattern" and failure "Test failure"
Then the recorded pattern can be retrieved by its ID
Scenario: pep-repo-delete Repository delete removes a pattern
Given a fresh error pattern service
When I record a failure with pattern "Deletable pattern" and failure "Will be deleted"
And I delete the last recorded pattern
Then the error pattern database should contain 0 patterns
Scenario: pep-fallback-match Pattern without keywords matches by description
Given a fresh error pattern service
And a recorded pattern with no keywords for "timeout error" with check "Add timeout handling"
When I match context "We encountered a timeout error in production"
Then preventive guidance should contain "Add timeout handling"