mind-body: check tests: out-of-bounds dial pinned in-crate, store listing compared before and after

The writers refuse an out-of-bounds dial, so the DialOutOfBounds reading is
produced through the unchecked store the crate's own tests already use. The
store directory holds a second file besides control.cc, so the no-write test
compares listings rather than counting one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-12 07:39:55 +02:00
commit 94ced33419
2 changed files with 22 additions and 5 deletions

View file

@ -197,6 +197,19 @@ fn a_zero_base_cooldown_or_a_non_positive_run_cost_is_out_of_bounds() {
assert!(matches!(effective(&smallest), Effective::Released(_)));
}
#[test]
fn the_check_gate_refuses_a_released_brake_over_an_out_of_bounds_dial() {
// The writers refuse such a dial, so the store is built unchecked.
for bad in [dial("3", 3600, "1"), dial("1", 0, "1"), dial("1", 3600, "0")] {
let dir = tempfile::tempdir().unwrap();
released_store_unchecked(dir.path(), bad.clone());
let args: Vec<String> = ["--instance", "eureka", "check"].iter().map(|a| a.to_string()).collect();
let mut out = Vec::new();
let result = crate::cli::run(&args, dir.path(), "op", at(1), &mut out, &mut |_| Ok(()));
assert!(format!("{:#}", result.unwrap_err()).contains("DialOutOfBounds"), "{bad:?}");
}
}
fn released_store_unchecked(dir: &Path, bad: BurnRate) -> PathBuf {
let path = store_path(dir);
ControlWriter::open(&path).unwrap().set_brake(true, at(0), "op").unwrap();

View file

@ -189,6 +189,12 @@ fn a_root_flag_without_a_directory_or_an_instance_is_refused_and_writes_nothing(
assert!(!std::path::Path::new("/nonexistent-root-for-test").exists());
}
fn listing(dir: &std::path::Path) -> Vec<String> {
let mut names: Vec<String> = std::fs::read_dir(dir).unwrap().map(|e| e.unwrap().file_name().to_string_lossy().into_owned()).collect();
names.sort();
names
}
fn check_out(root: &std::path::Path) -> (anyhow::Result<()>, String) {
go(root, &["--instance", "eureka", "check"], "op", 0)
}
@ -207,10 +213,7 @@ fn check_refuses_every_reading_but_released() {
held(root.path(), "BrakeHeld");
go(root.path(), &["--instance", "eureka", "brake", "release"], "op", 2).0.unwrap();
held(root.path(), "DialAbsent");
go(root.path(), &["--instance", "eureka", "dial", "set", "--heat", "1000", "--base-cooldown-s", "3600", "--base-run-usd", "5"], "op", 3)
.0
.unwrap();
held(root.path(), "DialOutOfBounds");
// DialOutOfBounds cannot be written through the CLI: it is pinned in the crate's own tests.
// An undecodable store is a held reading too.
let broken = tempfile::tempdir().unwrap();
std::fs::create_dir(broken.path().join("eureka")).unwrap();
@ -242,10 +245,11 @@ fn check_writes_nothing_and_creates_no_directory() {
go(root.path(), &["--instance", "eureka", "brake", "release"], "op", 0).0.unwrap();
let file = root.path().join("eureka").join("control.cc");
let before = (std::fs::read(&file).unwrap(), std::fs::metadata(&file).unwrap().modified().unwrap());
let names_before = listing(&root.path().join("eureka"));
let _ = check_out(root.path());
let _ = check_out(root.path());
assert_eq!((std::fs::read(&file).unwrap(), std::fs::metadata(&file).unwrap().modified().unwrap()), before);
assert_eq!(std::fs::read_dir(root.path().join("eureka")).unwrap().count(), 1);
assert_eq!(listing(&root.path().join("eureka")), names_before);
}
#[test]