hive-agent: compact tests set the harness dir like the other Bus tests
The two report_compact tests build a Bus, which resolves the events db under HYPERHIVE_HARNESS_DIR and panics when it is unset, as in the nix test sandbox. Add a test-only paths::with_harness_dir that points the variable at a temp dir under a lock, and use it in both the new tests and the existing swarm_inference Bus test, which set the variable unguarded.
This commit is contained in:
parent
2c4a3c2fa7
commit
3c03d82858
3 changed files with 69 additions and 37 deletions
|
|
@ -320,34 +320,29 @@ mod tests {
|
|||
/// persisted files, so clearing it, or a restart, finds the local value.
|
||||
#[test]
|
||||
fn the_swarm_value_is_not_persisted_over_the_local_one() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let prev = std::env::var_os("HYPERHIVE_HARNESS_DIR");
|
||||
// SAFETY: no other test in this crate reads or sets this variable.
|
||||
unsafe { std::env::set_var("HYPERHIVE_HARNESS_DIR", dir.path()) };
|
||||
let bus = Bus::new();
|
||||
bus.set_model("sonnet");
|
||||
bus.set_effort("low");
|
||||
let target = Harness {
|
||||
bus: bus.clone(),
|
||||
nix_model: None,
|
||||
nix_effort: None,
|
||||
};
|
||||
let mut o = Overridden::default();
|
||||
o.apply(&set(Some("opus"), Some(Effort::Max)), &target);
|
||||
let swarm = (bus.model(), bus.effort());
|
||||
let swarm_sources = (bus.model_source(), bus.effort_source());
|
||||
let files = (
|
||||
crate::harness_state::load_model(),
|
||||
crate::harness_state::load_effort(),
|
||||
);
|
||||
o.apply(&AgentInference::default(), &target);
|
||||
let cleared = (bus.model(), bus.effort());
|
||||
let cleared_sources = (bus.model_source(), bus.effort_source());
|
||||
match prev {
|
||||
// SAFETY: as above.
|
||||
Some(v) => unsafe { std::env::set_var("HYPERHIVE_HARNESS_DIR", v) },
|
||||
None => unsafe { std::env::remove_var("HYPERHIVE_HARNESS_DIR") },
|
||||
}
|
||||
let (swarm, swarm_sources, files, cleared, cleared_sources) =
|
||||
crate::paths::with_harness_dir(|| {
|
||||
let bus = Bus::new();
|
||||
bus.set_model("sonnet");
|
||||
bus.set_effort("low");
|
||||
let target = Harness {
|
||||
bus: bus.clone(),
|
||||
nix_model: None,
|
||||
nix_effort: None,
|
||||
};
|
||||
let mut o = Overridden::default();
|
||||
o.apply(&set(Some("opus"), Some(Effort::Max)), &target);
|
||||
let swarm = (bus.model(), bus.effort());
|
||||
let swarm_sources = (bus.model_source(), bus.effort_source());
|
||||
let files = (
|
||||
crate::harness_state::load_model(),
|
||||
crate::harness_state::load_effort(),
|
||||
);
|
||||
o.apply(&AgentInference::default(), &target);
|
||||
let cleared = (bus.model(), bus.effort());
|
||||
let cleared_sources = (bus.model_source(), bus.effort_source());
|
||||
(swarm, swarm_sources, files, cleared, cleared_sources)
|
||||
});
|
||||
assert_eq!(swarm, pair("opus", "max"));
|
||||
assert_eq!(files, (Some("sonnet".to_owned()), Some("low".to_owned())));
|
||||
assert_eq!(cleared, pair("sonnet", "low"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue