Lesson Learned 041: Comprehensive Regression Tests for All Lessons

ID: LL-041 Impact: Identified through automated analysis

Date: December 15, 2025 Severity: HIGH Category: Testing, Verification, Prevention Status: IMPLEMENTED

Summary

Created comprehensive regression test suite (tests/test_lessons_learned_regression.py) that enforces ALL documented lessons learned through automated tests.

Problem Solved

Previous state:

  • 50 lessons learned documented in rag_knowledge/lessons_learned/
  • Only 2 had regression tests (LL-009, LL-024)
  • Recent failures (LL-020, LL-034, LL-035, LL-040) had NO automated prevention
  • Tests existed but didn’t cover recent incidents

Implementation

New Test File: tests/test_lessons_learned_regression.py

Coverage includes:

Lesson Test Class What It Prevents
LL-009 TestLL009SyntaxErrors Syntax errors in critical files
LL-020 TestLL020FearMultiplier Fear multiplier increasing positions
LL-024 TestLL024FStringSyntax F-string backslash errors
LL-034 TestLL034CryptoFillVerification Unverified crypto order fills
LL-035 TestLL035RAGUsageEnforcement Ignoring RAG knowledge base
LL-040 TestLL040TrendConfirmation Buying without trend/RSI confirmation

New Script: scripts/mandatory_rag_check.py

# Usage before making changes
python3 scripts/mandatory_rag_check.py "workflow failures"
python3 scripts/mandatory_rag_check.py "crypto order fill" --require-ack

Features:

  • Searches all lessons for relevant past incidents
  • Shows critical lessons first
  • Optional acknowledgment requirement
  • Creates .rag_query_acknowledged marker

CI Integration

Added to .github/workflows/comprehensive-verification.yml:

- name: Run Lessons Learned Regression Tests
  run: |
    pytest tests/test_lessons_learned_regression.py -v --tb=short

Key Tests Added

1. Fear Multiplier (LL-020)

def test_fear_multiplier_not_increasing_position():
    """Ensure extreme fear conditions don't INCREASE position size."""
    # Checks for dangerous patterns like: size_multiplier = 1.5 during fear

2. Hardcoded Fake Metrics (LL-020)

def test_no_hardcoded_fake_metrics():
    """Ensure hooks don't contain hardcoded fake performance claims."""
    # Checks for "2.18 Sharpe", "62.2% win rate" etc.

3. Crypto Fill Verification (LL-034)

def test_workflow_waits_for_fill():
    """Ensure crypto workflows wait for fill confirmation."""
    # Checks for OrderStatus.FILLED, filled_price patterns

4. RAG Usage Enforcement (LL-035)

def test_lessons_learned_exists():
    """Verify lessons learned directory has content."""
    # Ensures 30+ lessons are preserved

def test_rag_search_functionality_exists():
    """Verify RAG search capability exists."""
    # Checks for rag search files

5. Trend Confirmation (LL-040)

def test_crypto_workflow_has_ma_filter():
    """Ensure crypto strategy checks moving average before buying."""

def test_crypto_workflow_has_rsi_confirmation():
    """Ensure crypto strategy checks RSI before buying."""

Prevention Rules

  1. Every new lesson MUST have a corresponding test
  2. Run pytest tests/test_lessons_learned_regression.py before merging
  3. Use scripts/mandatory_rag_check.py before making changes
  4. CI MUST pass all regression tests before merge

Files Created/Modified

  • tests/test_lessons_learned_regression.py (NEW)
  • scripts/mandatory_rag_check.py (NEW)
  • .github/workflows/comprehensive-verification.yml (UPDATED)

Verification

# Run all regression tests
pytest tests/test_lessons_learned_regression.py -v

# Query RAG before changes
python3 scripts/mandatory_rag_check.py "import errors"
  • LL-009: CI syntax failure
  • LL-020: Pyramid buying during fear
  • LL-024: F-string syntax error
  • LL-034: Crypto order fill verification
  • LL-035: Failed to use RAG
  • LL-040: Catching falling knives

Tags

testing regression verification prevention ci automation


Created: December 15, 2025 Author: Claude (CTO)