chore(tests): isolate deacon's shared state cache per test process#359
Merged
Conversation
deacon's workspace-state cache lives at `std::env::temp_dir()/deacon-state/` — a path shared across every process. Its on-disk `index.json` is loaded into memory once and rewritten wholesale on every `set`, so two concurrent `deacon` invocations (e.g. parallel `up`/`down` docker tests) can clobber each other's index entry (last-writer-wins). A later `down` in a fresh process then reloads an index missing its own entry and "loses" the state its `up` saved. One test (smoke_compose_edges) already worked around this by hand with a per-test `TMPDIR`; every other up/down test remained exposed. Add `support::deacon_command()`: a factory that builds the `deacon` CLI command with `TMPDIR`/`TMP`/`TEMP` redirected to a process-global `OnceLock<TempDir>`. Under nextest each test is its own process, so the home is unique per test, and a test's `up`/`down`/`exec` share it (as they must). Retrofit the 11 up/down/ exec test files that spawn the binary to use it, and drop the hand-rolled workaround. A fix product-side would mean reworking the shared DiskCache's concurrency (broad, touches the features cache too), so isolation is the correctly-scoped fix. Verified: with the helper, `deacon up` writes zero files to the shared `/tmp/deacon-state` and puts state in the isolated dir instead; fast suite (3123) green; `integration_down` + `smoke_up_idempotent` docker tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019vhr7Tcf8ybvSZSE1owqBT
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.
Summary
Kills a shared-path flaky-test class found in a sweep (finding #1). deacon's workspace-state cache lives at
std::env::temp_dir()/deacon-state/— a path shared by every process.The race
DiskCacheloadsindex.jsoninto memory once at open and rewrites the whole index on everyset(crates/core/src/state.rs→crates/core/src/cache/disk.rs). So two concurrentdeaconinvocations (e.g. parallelup/downdocker tests) each hold a stale in-memory index and clobber the other's entry — last-writer-wins. A laterdownin a fresh process reloads an index missing its own entry and "loses" the state itsupsaved. Atomic writes prevent corruption but not this lost update.smoke_compose_edges.rsalready worked around it by hand with a per-testTMPDIR; every other up/down test stayed exposed, and new ones would forget.Fix (test-side, correctly scoped)
Add
support::deacon_command()— a factory that builds thedeaconCLI command withTMPDIR/TMP/TEMPredirected to a process-globalOnceLock<TempDir>. Under nextest each test is its own process, so the home is unique per test, and a test'sup/down/execshare it (as they must). Retrofit the 11 up/down/exec test files that spawn the binary to use it, and drop the hand-rolled workaround.A product-side fix would mean reworking the shared
DiskCache's concurrency model (broad — it also backs the features cache — and risky: a naive index merge would breakdown's removals), so isolation is the proportionate fix.Verification
deacon upwrote 0 files to shared/tmp/deacon-state(stayed at 213) and put its state in the isolated dir instead.make test-nextest-fast— 3123 passed ✓cargo clippy --all-targets --all-features -- -D warnings+cargo fmt --all -- --check✓integration_down(9/9),smoke_up_idempotent(3/3, real up/down cycles) pass.Sweep notes (for the curious)
The same sweep cleared the other axes: ports (all binds use ephemeral
:0), env races (fully hardened viatemp_env), and docker names (already unique viaunique_name()/tempdir labels — a couple of latent-but-unreachable fixed image tags noted for optional defense-in-depth). The perf-ceiling flake is addressed separately in #358.🤖 Generated with Claude Code