Skip to content

test(testkit): remove a test's scratch directory when it passes - #26

Merged
adammharris merged 1 commit into
mainfrom
agent/backlog-tests-leave-their-fixtures-in-temp
Nov 5, 2026
Merged

adammharris merged 1 commit into
mainfrom
agent/backlog-tests-leave-their-fixtures-in-temp

Conversation

@adammharris

Copy link
Copy Markdown
Member

What changed

  • prov_testkit::scratch returns a Scratch, a guard that derefs to Path and removes the directory on drop. A panicking thread keeps the directory, so a failing test still leaves its state to be read.
  • Every hand-written temp_dir() fixture moved onto it, about 30 files. No temp_dir() call remains outside prov-testkit.
  • Federation, Nested and peer.rs's fixture now hold the guard. Their own Drop removed the directory on failure too.
  • smoke.rs writes its backups into a scratch directory of their own instead of beside the fixture.
  • Scratch paths gain a per-process count (prov-<scope>-<tag>-<pid>-<n>). This goes beyond the task: a guard removes what it holds, so two tests sharing a path could now delete each other's directory. views.rs, for one, has two helpers building the same prov-views-cli-<tag> name.
  • The comment on scratch no longer claims a path stable across runs.

Test-only: nothing a caller of prov can observe changes, so there is no Behavioural-change: trailer.

Why

A green cargo test --workspace left 741 entries and 34 MB in the temp directory, and every run added more. On a tmpfs that is memory until the next reboot.

For review

A guard dropped early still compiles, and the test then fails or reads a missing directory. scratch(..).join("x") and a helper that returns a path derived from a guard it held both do this. The full run caught six such tests, all fixed here, and they are why linked_share and outer_and_nested now return the guard as well. The doc comment on Scratch warns about it.

A test that fails by returning Err rather than panicking would lose its directory. I searched for test functions returning Result and found none.

Closes docs/tasks/tests-leave-their-fixtures-in-temp.md, shelved under Closed tasks.

How it was verified

  • New tests in prov-testkit for the three properties; the two that needed the change failed before it, and the third, keeping a failing test's directory, passed both before and after, since nothing removed directories then.
  • ship ci: all 7 jobs passed. An earlier run failed clippy on let_and_return, fixed here.
  • TMPDIR=<empty dir> cargo test --workspace on the committed tree: 1,241 passed, 0 failed, nothing left in TMPDIR.

`prov_testkit::scratch` named its directory by process id and removed
only that path, so a green `cargo test --workspace` left 741 entries and
34 MB in the temp directory, and every run added more. Where the temp
directory is a tmpfs, that is memory until the next reboot.

`scratch` now returns a `Scratch`, a guard that derefs to `Path` and
removes the directory on drop, unless the thread is panicking, so a
failing test still leaves its state to be read. Every hand-written
`temp_dir()` fixture moved onto it, and `Federation`, `Nested` and
peer.rs's fixture hold the guard in place of a `Drop` that removed the
directory on failure too. smoke.rs's backups go in a directory of their
own rather than beside the fixture.

Paths gain a per-process count: a guard removes what it holds, so two
tests must never share one.

Closes docs/tasks/tests-leave-their-fixtures-in-temp.md, shelved under
Closed tasks.
@adammharris
adammharris merged commit 314873a into main Nov 5, 2026
8 checks passed
@adammharris
adammharris deleted the agent/backlog-tests-leave-their-fixtures-in-temp branch November 5, 2026 22:25
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.

1 participant