Skip to content

refactor: extract generic CacheEntry to deduplicate cache read/write (#104)#116

Merged
Zious11 merged 9 commits intodevelopfrom
refactor/cache-dedup-104
Apr 2, 2026
Merged

refactor: extract generic CacheEntry to deduplicate cache read/write (#104)#116
Zious11 merged 9 commits intodevelopfrom
refactor/cache-dedup-104

Conversation

@Zious11
Copy link
Copy Markdown
Owner

@Zious11 Zious11 commented Apr 2, 2026

Summary

  • Extract Expiring trait + generic read_cache<T>/write_cache<T> to deduplicate 3 whole-file cache pairs (teams, workspace, cmdb_fields)
  • Normalize all 5 cache read functions to treat corrupt files as cache misses (Ok(None)) — previously only 2 of 5 did this
  • Add 3 new corrupt-file tests, fix with_temp_cache to prevent mutex poisoning on test panics
  • Add doc comments to keyed cache functions explaining why they're not genericized

Closes #104

Test plan

  • All 409 tests pass (cargo test)
  • Clippy clean (cargo clippy -- -D warnings)
  • Rustfmt clean (cargo fmt --all -- --check)
  • 3 new corrupt-file tests (garbage data + wrong-shape JSON) for team, workspace, project_meta
  • Public API unchanged — no caller modifications needed
  • On-disk cache format unchanged

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 2, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 97.91667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cache.rs 97.91% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the cache module to remove duplicated whole-file cache read/write logic by introducing a small Expiring trait plus generic read_cache<T> / write_cache<T> helpers, and aligns cache reads to treat JSON deserialization failures as cache misses instead of user-facing errors.

Changes:

  • Added Expiring + generic whole-file cache read/write helpers and migrated team/workspace/cmdb_fields caches to use them.
  • Normalized keyed project_meta cache to treat corrupt JSON as Ok(None) and documented why keyed caches aren’t genericized.
  • Improved cache test isolation by preventing mutex poisoning on panics and added new corrupt-cache tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/cache.rs Introduces generic cache helpers, updates cache read/write functions, hardens corrupt-cache behavior, and expands tests.
docs/superpowers/specs/2026-04-02-cache-dedup-design.md Adds a design spec describing the refactor approach and behavior changes.
docs/superpowers/plans/2026-04-02-cache-dedup.md Adds an implementation plan outlining incremental steps and validation commands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…che (#104)

Avoids swallowing permission errors and eliminates TOCTOU window
between the exists check and the read.
@Zious11 Zious11 merged commit a61d5d4 into develop Apr 2, 2026
7 checks passed
@Zious11 Zious11 deleted the refactor/cache-dedup-104 branch April 2, 2026 17:34
@Zious11 Zious11 mentioned this pull request Apr 5, 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.

refactor: extract generic CacheEntry<T> to deduplicate cache read/write functions

3 participants