docs: document cache fix (unlock-before-rename), atomic writes, file locking, and test hardening#78
Conversation
Owner
umpire274
commented
Nov 7, 2025
- Document the fix that releases the cache file lock before replacing the JSON store (avoids Windows "file in use" errors).
- Note atomic writes to the shared JSON cache (write to temp file + rename) and a Windows fallback (remove + rename).
- Describe advisory file locking via fs2 and the open_and_lock() helper centralizing locking logic.
- Mention the switch to anyhow::Result for richer internal error context.
- Record test hardening: unique sandbox directories per test (timestamp+pid) and making app_dir() override test-friendly (re-entrant).
- Updated README.md and CHANGELOG.md accordingly. All tests pass locally.
…test hardening & docs - Implement atomic writes for the shared JSON cache (write to a temporary file in the same directory and replace via rename). - Use advisory file locks (fs2) to protect concurrent access; added an open_and_lock() helper to centralize locking logic. - Ensure the cache file lock is released and the handle closed before attempting rename/remove (fixes Windows “file in use” errors). - Add a Windows fallback that attempts remove+rename when rename fails on older semantics. - Make app_dir() test override re-entrant (OnceLock<Mutex<Option<pathbuf>>>) and harden tests by using unique sandbox directories (timestamp+pid) and ensuring source files exist before cache writes — fixes intermittent CI/test races.</pathbuf> - Switch internal cache helper error handling to anyhow::Result for richer context. - Update docs: README.md and CHANGELOG.md to document these changes. - Add dependencies: fs2 and anyhow in Cargo.toml. - Files changed (high level): src/utils.rs, src/config.rs, test files (tests/*), README.md, CHANGELOG.md, Cargo.toml. All tests pass locally.
- Replace shared JSON cache with per-file .cache files (get_cache_path) - Remove last_quotes.json and duplicated load_last_cache - Use advisory locking via open_and_lock() for safe reads/writes - Add thread-local app_dir override (set_app_dir_for_tests) and stable thread id hashing - Remove debug prints and cleanup unused imports - Tests: cargo test --all (all green)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.