thing-testkit: each fixture open has its own temp directory; the read-only test restores permissions on drop
All checks were successful
Portable Eve contracts and browser lowering / ubuntu-latest eve-browser-lowering (pull_request) Successful in 3m45s
Portable Eve contracts and browser lowering / ubuntu-latest eve-contracts (pull_request) Successful in 2m47s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 21:18:25 +01:00
commit e0ed7e9a1d
2 changed files with 13 additions and 4 deletions

View file

@ -84,9 +84,12 @@ impl Fixture {
/// The committed store, opened through the contract. Opening creates a lock file beside the
/// store, so this opens a copy: the fixtures directory is never written.
/// store, so this opens a copy in a directory of its own (process id and a serial), removed
/// once the store is read: the fixtures directory is never written.
pub fn open(self) -> CultCache {
let work = std::env::temp_dir().join(format!("thing-testkit-open-{}-{}", std::process::id(), self.file_name()));
static OPENS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
let serial = OPENS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let work = std::env::temp_dir().join(format!("thing-testkit-open-{}-{serial}", std::process::id()));
std::fs::create_dir_all(&work).unwrap();
let copy = work.join(self.file_name());
std::fs::copy(Self::dir().join(self.file_name()), &copy).unwrap();

View file

@ -175,13 +175,19 @@ fn loading_a_fixture_writes_nothing_in_the_fixtures_directory() {
names
};
let before = listing();
// Restores the directory's permissions even when the test panics.
struct Restore(std::fs::Permissions);
impl Drop for Restore {
fn drop(&mut self) {
let _ = std::fs::set_permissions(Fixture::dir(), self.0.clone());
}
}
let mut permissions = std::fs::metadata(Fixture::dir()).unwrap().permissions();
let writable = permissions.clone();
let _restore = Restore(permissions.clone());
permissions.set_readonly(true);
std::fs::set_permissions(Fixture::dir(), permissions).unwrap();
for fixture in Fixture::ALL {
load(fixture);
}
std::fs::set_permissions(Fixture::dir(), writable).unwrap();
assert_eq!(listing(), before);
}