Huginn/crates/mind-body/tests/persona_bin.rs
Meta Vens 8fe9fc351b Heartbeat: no night wake until C4; stale docs and empty tests (Soul F4, F6, F7)
F4: the night wake started a plain mind-persona@ unit and traced it as
Sleep and "asleep". Deleted the night branch, Night, Config.night, the
HEARTBEAT_SLEEP_UTC and HEARTBEAT_SLEEP_MINDS settings and
HeartbeatState.last_night_at (added by this PR, never deployed, so nothing
must decode it). A wake's trace entry is her slug. Reflection and
consolidation return in C4.

F6: deleted a_flag_overrides_the_environment (asserted exit 0 with the
config discarded) and the heartbeat test that compared two identical rigs.

F7: Cargo.toml no longer says the Persona drains her chat or that launch
opens runs; heartbeat.rs no longer says Persona units read its addressing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 22:30:50 +01:00

64 lines
3 KiB
Rust

//! The `mind-persona` binary as the unit runs it: arguments `--instance`, the rest
//! from `persona.env`. The control root is a constant that does not exist where
//! this runs, so a start that is configured right ends dead at the gate (exit 0);
//! a start configured wrong ends 2 and names the setting, never a value.
use std::path::Path;
use std::process::{Command, Output};
fn run(dir: &Path, drop: &[&str], extra: &[(&str, &str)], args: &[&str]) -> Output {
let mut env = vec![
("HUGINN_ENDPOINT", "rudp://127.0.0.1:9".to_string()),
("STATE_DIRECTORY", dir.to_string_lossy().into_owned()),
("MIND_PERSONA_ROOMS", "#swarm:chat,#ops:chat".to_string()),
("MIND_PERSONA_OPERATOR", "@op:chat".to_string()),
("MIND_PERSONA_MINDS", "@eureka:chat,@libby:chat".to_string()),
("MIND_PERSONA_SELF_SENDER", "@eureka:chat".to_string()),
("MIND_PERSONA_MODEL", "claude-test-model".to_string()),
];
env.retain(|(name, _)| !drop.contains(name) && !extra.iter().any(|(set, _)| set == name));
env.extend(extra.iter().map(|(name, value)| (*name, (*value).to_string())));
Command::new(env!("CARGO_BIN_EXE_mind-persona")).args(args).env_clear().envs(env).output().unwrap()
}
/// What to drop from the environment, what to set instead, and the setting the error must name.
type Case<'a> = (&'a [&'a str], &'a [(&'a str, &'a str)], &'a str);
fn text(bytes: &[u8]) -> String {
String::from_utf8_lossy(bytes).into_owned()
}
#[test]
fn a_unit_configured_from_its_environment_alone_reaches_the_gate_and_ends_dead() {
let dir = tempfile::tempdir().unwrap();
let output = run(dir.path(), &[], &[], &["--instance", "eureka"]);
assert_eq!(output.status.code(), Some(0), "{}", text(&output.stderr));
assert!(text(&output.stdout).starts_with("dead:"), "{}", text(&output.stdout));
}
#[test]
fn a_setting_that_is_missing_or_wrong_ends_two_naming_the_setting_and_no_value() {
let dir = tempfile::tempdir().unwrap();
let cases: [Case; 4] = [
(&["MIND_PERSONA_ROOMS"], &[], "usage"),
(&["MIND_PERSONA_MINDS"], &[], "usage"),
(&["MIND_PERSONA_MODEL"], &[], "MIND_PERSONA_MODEL"),
(&[], &[("HUGINN_ENDPOINT", "canary-endpoint")], "endpoint"),
];
for (drop, extra, names) in cases {
let output = run(dir.path(), drop, extra, &["--instance", "eureka"]);
let stderr = text(&output.stderr);
assert_eq!(output.status.code(), Some(2), "{drop:?} {extra:?}: {stderr}");
assert!(stderr.contains(names), "{drop:?} {extra:?}: {stderr}");
assert!(!stderr.contains("canary-endpoint") && !stderr.contains("#ops:chat"), "no value is echoed: {stderr}");
}
}
#[test]
fn the_retired_max_turns_flag_is_refused_and_its_value_is_not_echoed() {
let dir = tempfile::tempdir().unwrap();
let output = run(dir.path(), &[], &[], &["--instance", "eureka", "--max-turns", "canary-turns"]);
let stderr = text(&output.stderr);
assert_eq!(output.status.code(), Some(2), "{stderr}");
assert!(stderr.contains("usage") && !stderr.contains("canary-turns"), "{stderr}");
}