thing-testkit: Fixture::open reads a copy so the fixtures directory stays unwritten

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 21:02:15 +01:00
commit a9dcab6516
2 changed files with 14 additions and 10 deletions

View file

@ -4,6 +4,7 @@
use std::path::PathBuf;
use cultcache_rs::CultCache;
use thing_contract::*;
use crate::build::*;
@ -81,19 +82,23 @@ impl Fixture {
golden::check(&Self::dir(), self.file_name(), &bytes)
}
/// The committed store, decoded through the contract.
pub fn load(self) -> FixtureSet {
// Opening a store creates a lock file beside it, so open a copy: the fixtures directory
// is never written by a load.
let work = std::env::temp_dir().join(format!("thing-testkit-load-{}-{}", std::process::id(), self.file_name()));
/// 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.
pub fn open(self) -> CultCache {
let work = std::env::temp_dir().join(format!("thing-testkit-open-{}-{}", std::process::id(), self.file_name()));
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();
let cache = store::open(&copy);
let set = FixtureSet::new(cache.get_all().unwrap(), cache.get_all().unwrap(), cache.get_all().unwrap());
drop(cache);
let _ = std::fs::remove_dir_all(&work);
set
cache
}
/// The committed store, decoded through the contract.
pub fn load(self) -> FixtureSet {
let cache = self.open();
FixtureSet::new(cache.get_all().unwrap(), cache.get_all().unwrap(), cache.get_all().unwrap())
}
}

View file

@ -5,7 +5,6 @@
use thing_contract::*;
use thing_testkit::fixture::{Fixture, FixtureSet};
use thing_testkit::mem_state::MemState;
use thing_testkit::store;
use thing_core::port::{Address, Lookup, StatePort};
/// Decoding runs on a 16 MiB thread until the workspace pin of cultcache-rs carries
@ -31,7 +30,7 @@ fn every_fixture_round_trips_through_the_contract() {
assert_eq!(loaded, built, "{}: the store decodes to the built documents", fixture.file_name());
// Each record re-encodes to its stored payload.
let cache = store::open(&Fixture::dir().join(fixture.file_name()));
let cache = fixture.open();
for surface in &loaded.surfaces {
let stored = cache.get_envelope::<SurfaceDocument>(&surface.record_key()).unwrap().unwrap();
assert_eq!(rmp_serde::to_vec(surface).unwrap(), stored.payload);