When assigned to fix an E2E bug (Phase 3), agents MUST follow this protocol integrating TDD, DDD, and Excellence Flywheel principles.
MANDATORY FIRST STEP: Before writing any code, verify existing patterns:
# Find existing patterns
grep -r "pattern_name" services/ --include="*.py" -A 5 -B 5
# Check domain models
cat services/domain/models.py | grep "DomainConcept"
# Check ADRs for architectural decisions
find docs/internal/architecture/current/adrs -name "*relevant-adr*.md"
# Check pattern library
find docs/internal/architecture/current/patterns -name "*pattern*.md"
Why: Understanding existing patterns prevents reinventing solutions and ensures consistency.
MANDATORY: Write test FIRST that reproduces the bug.
def test_bug_issue_number_description():
"""
Reproduces bug #[N]: [Brief description]
"""
# Arrange: Set up scenario that reproduces bug
# Act: Perform action that triggers bug
# Assert: Verify expected behavior (this will fail initially)
assert expected_behavior == actual_behavior
Requirements:
Evidence Required: Test failure output showing bug reproduced
MANDATORY: Check domain model before implementing fix.
# Check domain models
cat services/domain/models.py | grep -A 10 "RelevantDomainConcept"
Questions to Answer:
If Domain Model Conflict:
Evidence Required: Domain model check results, any conflicts identified
MANDATORY: Search for existing patterns before implementing.
# Find similar working code
grep -r "similar_functionality" services/ --include="*.py"
# Check pattern library
find docs/internal/architecture/current/patterns -name "*relevant-pattern*.md"
Questions to Answer:
If Pattern Found:
If No Pattern Found:
Evidence Required: Pattern search results, pattern chosen or rationale for new approach
MANDATORY: Implement smallest possible fix that solves the problem.
Principles:
Implementation Checklist:
Evidence Required: Code changes with explanation of why this fixes root cause
MANDATORY: Add tests that prevent bug from recurring.
Regression Test Requirements:
Test Quality:
Evidence Required: Regression tests written, all tests passing
MANDATORY: Document what was done and why.
Documentation Requirements:
ADR Required If:
Evidence Required: Documentation updates, ADR if required
MANDATORY: Verify fix works in original E2E scenario.
Verification Steps:
Evidence Required:
Before marking fix complete, verify:
Not Done: “It should work” / “Tests pass” / “Looks good” Done: “Here’s the test proving it works, the regression tests preventing recurrence, and the documentation updates”
1. Write failing test → Test fails ✅
2. Check domain model → No conflicts ✅
3. Find pattern → Pattern X exists ✅
4. Implement fix using Pattern X → Code written ✅
5. Test passes → Bug fixed ✅
6. Add regression tests → Tests written ✅
7. Update docs → Documentation updated ✅
8. Verify E2E → Original scenario works ✅
9. All checks pass → Fix complete ✅