Repository navigation
test: write test files under a per-test temp dir, and inject the cache settings - #2894
Merged
Merged
Conversation
…e settings Tests in the CLI (`integration_test.rs`, 13 sites; `cli_commands_test.rs`, 2), the loader cache (unit tests, `cache_roundtrip_properties.rs`, `cache_env_var_test.rs`) and the price cache wrote fixed names under the shared system temp dir, so two concurrent `cargo test` runs deleted each other's files, and an early `return` left a file behind. Each now writes under a `tempfile::TempDir`, removed on drop, and the `remove_file(..).ok()` cleanups that swallowed errors are gone. The loader cache read its two environment variables directly, so the cache tests either mutated process env (`set_var` under a mutex, in a binary that opted out of `unsafe_code = deny`) or asserted the developer's env was clean. `CacheEnv` now carries the two settings as a value (`from_process`, `from_lookup`), and `cache_path_in`, `load_cache_entry_in`, `save_cache_entry_in` and `invalidate_cache_in` take it; the plain functions read the process env and delegate. The tests pass their settings in: no `set_var`, no `unsafe`, no env precondition. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Review round 1 on the temp-dir change: - price cache: `test_clear` deleted the fixed `/tmp/test-price-cache-clear.json`; it and the seven other tests with a fixed `/tmp/test-price-cache*.json` path now use a path in their own `TempDir`. - cli_commands_test: each of the 16 `NamedTempFile` ledgers is created in its own `TempDir`, so the cache `rledger check` writes next to it goes with the directory instead of piling up in TMPDIR (a run now leaves TMPDIR empty). - The loader cache test note no longer says `cache_env_var_test` mutates the process environment. - CHANGELOG: drop the blank line after the new bullet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What changed
Per-test temporary directories. Several tests wrote fixed file names under the shared system temp directory, so two concurrent
cargo testruns deleted each other's files. A run ofrustledger::integration_testfailed this way while another lane was running the same suite. A test that returned early ("Skipping: ...") also left its file behind. These tests now write under atempfile::TempDirthat is removed on drop, and theremove_file(..).ok()cleanups that swallowed their errors are gone:crates/rustledger/tests/integration_test.rscrates/rustledger/tests/cli_commands_test.rscrates/rustledger-loader/src/cache.rs(unit tests)crates/rustledger-loader/tests/cache_env_var_test.rscrates/rustledger/src/cmd/price/cache.rs(test_save_and_load_round_trip)Injected cache settings. The loader's cache read
BEANCOUNT_LOAD_CACHE_FILENAMEandBEANCOUNT_DISABLE_LOAD_CACHEstraight from the process environment. That left the cache tests two bad options.cache_env_var_testcalledset_varunder a mutex, in a binary that opted out ofunsafe_code = deny. The unit tests andcache_roundtrip_propertiesinstead asserted that the developer's environment was clean, which breaks on a machine that sets the variable (AGENTS.md: inject environmental inputs; neverset_varin parallel tests).CacheEnvcarries the two settings as a value. It is built byCacheEnv::from_process()or byCacheEnv::from_lookup(lookup), which takes an injected lookup.cache_path_in,load_cache_entry_in,save_cache_entry_inandinvalidate_cache_intake aCacheEnv. The existing functions read the process environment and delegate to them, so no caller changes.cache_env_var_testno longer mutates the environment and no longer needs#![allow(unsafe_code)]. The reading rule is still tested throughfrom_lookup: the variable names, an empty pattern counting as unset, and any disable value (including empty) disabling. No test asserts the environment any more.Why
These are concurrent-run collisions found while several lanes ran the workspace tests together under one
TMPDIR. This also follows the hermetic-test rule in AGENTS.md.How to test
Verification
integration_testbinary four times at once and thecli_commands_testbinary twice at once, all under one sharedTMPDIR. Every run passed (19 and 63 tests).cargo test --workspace --all-features --no-fail-fast,cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depsandcargo fmt --checkall pass.Not changed
invalidate_cache, the legacy-sidecar removal, and the price cache'sclear) still ignores a failedremove_file, on purpose: a missing file is the expected case there.decimal_overflow_test, the LSP tests,add_cmd,corpus_baseline's determinism check) are left as they are.🤖 Generated with Claude Code