Skip to content

[Code Quality] Add test for --clear-cache when no cache file exists (hint coverage) #607

@github-actions

Description

@github-actions

Description

PR #596 added two actionable hint messages to main.py when --clear-cache is invoked but no cache file exists:

# main.py ~line 2607-2609
else:
    print(f"... ℹ No cache file found, nothing to clear ...")
    print(f"... 💡 Hint: The cache file will be created or updated after a successful sync run without --dry-run ...")

Neither message is covered by any existing test. The current test_clear_cache_deletes_file in tests/test_disk_cache.py only covers the file-exists path (file is deleted successfully), leaving the no-file branch completely untested.

Suggested Changes

Add a new test to tests/test_disk_cache.py (or a suitable file) that:

  1. Patches cache.get_cache_dir to point at a temp directory with no blocklists.json
  2. Invokes the --clear-cache branch logic (or calls main.main() with patched sys.argv)
  3. Captures stdout with io.StringIO or capsys
  4. Asserts both messages appear:
    • "No cache file found, nothing to clear"
    • "The cache file will be created or updated after a successful sync run without --dry-run"

Files Affected

  • tests/test_disk_cache.py — add test_clear_cache_no_file_shows_hint() test

Success Criteria

  • ✅ New test exercises the else branch at main.py ~line 2607
  • ✅ Both hint messages are asserted in captured output
  • ✅ Test works in both colour (USE_COLORS=True) and no-colour modes (strip ANSI if needed)
  • ✅ All existing tests pass: uv run pytest tests/ -v

Source

Identified during task mining run §22795900937 from discussion #602 (Mar 7 QA report, PR #596 change log). The test_clear_cache_deletes_file test in test_disk_cache.py only covers the success path; the no-file hint path from PR #596 remains untested.

Priority

Low — Small, self-contained test. Completes coverage for the empty-state UX improvements from PR #596.

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/discussion-task-miner.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4
  • expires on Mar 8, 2026, 9:00 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions