Skip to content

test: add unit tests for rate-limit artifact cleanup#33

Open
mtibbits wants to merge 1 commit into
JCSnap:mainfrom
mtibbits:test/cleanup-unit-tests
Open

test: add unit tests for rate-limit artifact cleanup#33
mtibbits wants to merge 1 commit into
JCSnap:mainfrom
mtibbits:test/cleanup-unit-tests

Conversation

@mtibbits

Copy link
Copy Markdown
Contributor

Summary

  • Adds 23 unit tests (CLN-001 through CLN-023) covering _cleanup_rate_limit_artifacts() and _do_cleanup_rate_limit_artifacts() from PR fix: clean up rate-limit artifacts on detection #32
  • Tests use tmp_path-based fake ~/.claude/ directories with Path.home() patched — no real filesystem state touched

Test coverage

Category Tests What's verified
Deletion CLN-001–004 All four artifact types (JSONL, todo, debug, telemetry) deleted correctly
Preservation CLN-005–009 Old files, large JSONL, non-empty todos, old debug, uncorrelated debug all preserved
Call-site gating CLN-010–012 Cleanup only fires on rate-limit results (not success or generic failure)
Missing dirs CLN-013 No crash when ~/.claude/ subdirectories don't exist
Per-file errors CLN-014 OSError on one file doesn't block cleanup of others
Exception safety CLN-015 Cleanup failure doesn't break _process_execution_result() pipeline
Edge cases CLN-016–023 No last_executed, resolved working dir stashing, logging, early break, YAML non-persistence, fallback resolution

Test plan

  • All 23 new tests pass (pytest tests/test_cleanup.py -v)
  • Full suite passes (565 passed, 4 skipped)

🤖 Generated with Claude Code

@mtibbits mtibbits force-pushed the test/cleanup-unit-tests branch from 3ba17c7 to e78764a Compare March 15, 2026 12:44
Covers _cleanup_rate_limit_artifacts() and _do_cleanup_rate_limit_artifacts()
from PR JCSnap#32. Uses tmp_path-based fake ~/.claude/ directories with
Path.home() patched — no real filesystem state touched.

Tests (CLN-001 through CLN-023):
- Deletion of all four artifact types (JSONL, todo, debug, telemetry)
- Preservation of old, large, non-empty, and uncorrelated files
- Cleanup only triggered on rate-limit results (not success/failure)
- Missing directories, per-file OSError isolation, top-level exception safety
- Resolved working directory stashing, YAML non-persistence, fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Matthew Tibbits <mtibbits@users.noreply.github.com>
@mtibbits mtibbits force-pushed the test/cleanup-unit-tests branch from d5f281b to a26198e Compare March 15, 2026 13:24
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.

1 participant