@@ -279,6 +279,44 @@ flask db current
279279- ** Assertions** : Use descriptive assertion messages for failures
280280- ** Mocking** : Use pytest fixtures and mocking when testing external dependencies
281281
282+ ## Test-Driven Bug Fixing (CRITICAL PATTERN)
283+
284+ When fixing failing tests, ALWAYS follow this test-driven approach:
285+
286+ ### Step 1: Reproduce the Failure FIRST
287+
288+ - ** Run the actual test** to see it fail (don't just read code)
289+ - ** Capture the exact error message** and failure output
290+ - ** Understand the failure mode** : What was expected vs. what happened?
291+
292+ ### Step 2: Debug to Understand Root Cause
293+
294+ - ** Use debugger tools** , not just code inspection:
295+ - ` pytest --pdb ` to drop into debugger on failure
296+ - Add ` import pdb; pdb.set_trace() ` at strategic points
297+ - Use print statements to trace execution flow
298+ - ** Trace the actual execution path** through the code
299+ - ** Look for MULTIPLE bugs** , not just the obvious one
300+ - Example: Session learned that a test failure involved BOTH an API bug AND a test bug
301+
302+ ### Step 3: Apply Fix(es)
303+
304+ - Fix all identified bugs (API, test, or both)
305+ - Make atomic commits (separate production code from test code changes)
306+ - Document WHY the bug existed and HOW the fix works
307+
308+ ### Step 4: Verify the Fix
309+
310+ - ** Re-run the specific test** to confirm it now passes
311+ - ** Check for regressions** : Run related tests or entire test suite
312+ - ** Don't claim "tests pass" without actually running them**
313+
314+ ### Step 5: Update Agent Instructions
315+
316+ - Document the lesson learned in this file
317+ - What pattern or pitfall should be remembered?
318+ - What verification step was missing?
319+
282320## Commit Discipline for Test Changes
283321
284322When updating tests or this agent file:
0 commit comments