Skip to content

Fix cache entries being lost when multiple tests share cassette#13

Closed
ab-10 wants to merge 1 commit intomainfrom
claude/fix-cassette-entries-bug-oPfSj
Closed

Fix cache entries being lost when multiple tests share cassette#13
ab-10 wants to merge 1 commit intomainfrom
claude/fix-cassette-entries-bug-oPfSj

Conversation

@ab-10
Copy link
Contributor

@ab-10 ab-10 commented Jan 27, 2026

Summary

Fixed a bug where cache entries from one test would be lost when another test using the same cassette file ran in RECORD_MODE=all. The issue occurred because each cache instance would clear existing entries instead of preserving them.

Changes

  • Cache initialization in ALL mode: Changed to load existing entries before recording, rather than clearing them. This allows multiple test instances to accumulate entries in the same cassette file.
  • Entry replacement logic: Modified put() method to replace existing entries with the same instruction and method (supporting re-recording) instead of always appending, preventing duplicates.
  • Comprehensive test coverage: Added 210 lines of unit tests covering:
    • Multiple cache instances preserving each other's entries
    • Re-recording replacing existing entries instead of duplicating
    • Different methods being treated as separate entries
    • Behavior across all record modes (ONCE, NONE, ALL)

Implementation Details

  • When RECORD_MODE=all and a cassette exists, cache._load() is now called to preserve existing entries before recording new ones
  • The put() method now checks for existing entries matching both instruction and method, replacing them in-place rather than appending
  • Entry replacement triggers an immediate save() to persist changes
  • Tests use temporary directories and proper environment variable cleanup to avoid side effects

https://claude.ai/code/session_01PXyXZNXxqTusmww6BdzqkF

When multiple tests use the same default cassette file with RECORD_MODE=all,
each test would create a new Cache instance with empty entries, causing
subsequent tests to overwrite entries from earlier tests.

Changes:
- Load existing cassette entries in ALL mode before recording (cache.py:116-120)
- Replace duplicate entries instead of appending when re-recording (cache.py:227-232)

This ensures entries from all tests are preserved while still allowing
re-recording of individual instructions.

https://claude.ai/code/session_01PXyXZNXxqTusmww6BdzqkF
@ab-10 ab-10 closed this Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants