Persona wake: tests follow the one rule

The policy cases go; t_w1 cases pin the rule, the facts of both paths and her own rooms. Heartbeat poll tests read a Mind's tag, not its prose, and a member's address or direct message wakes her.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 19:58:54 +01:00
commit f9f966cb10
2 changed files with 159 additions and 121 deletions

View file

@ -391,10 +391,12 @@ fn the_operator_naming_a_persona_wakes_her_at_once_off_the_beat_and_once_per_mes
}
#[test]
fn another_mind_naming_a_persona_wakes_her_once_off_the_beat() {
fn another_mind_tagging_a_persona_wakes_her_once_off_the_beat_and_a_name_in_prose_does_not() {
let rig = quiet_rig();
rig.say(BOB, delivery(1, "@ann:chat", "Bob, a word", &[]));
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a Mind of the roster wakes her at once");
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a name in a Mind's prose wakes no one");
rig.say(BOB, delivery(2, "@ann:chat", "a word", &["@bob:chat"]));
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a Mind of the roster tagging her wakes her at once");
rig.end_unit(BOB);
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "the same message polled again wakes nobody");
}
@ -408,16 +410,13 @@ fn a_mind_naming_no_one_or_herself_wakes_nobody() {
}
#[test]
fn a_member_naming_a_persona_wakes_nobody_off_the_beat_but_counts_as_full_urgency_on_it() {
fn a_member_naming_a_persona_wakes_her_at_once() {
let rig = Rig::new();
rig.turn(ANN, 1000);
rig.turn(BOB, 90);
rig.beat_fell();
rig.say(BOB, delivery(1, "@member:chat", "Bob, are you there?", &[]));
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a member does not start a turn");
rig.advance(900);
// Bob waited 990 s x ten for the member addressing him; Ann waited 1900 s x one: Bob wins the beat.
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] });
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a member addressing her wakes her off the beat");
assert_eq!(rig.store.traces.borrow().last().unwrap().instances[BOB].urgency_permille, 1000);
}
@ -473,20 +472,18 @@ fn a_listed_name_wakes_on_its_exact_spelling_only_and_a_derived_name_in_any_case
}
#[test]
fn another_mind_naming_a_project_wakes_its_steward_and_a_member_scores_her_without_waking_her() {
fn a_member_naming_a_project_wakes_its_steward_and_a_mind_naming_it_in_prose_does_not() {
let rig = quiet_rig();
steward(&rig, BOB, "GameCult/BadDaySimulator", &["BDS"]);
rig.say(BOB, delivery(1, "@ann:chat", "BDS needs a look", &[]));
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a Mind of the roster naming her project wakes her");
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a Mind's prose naming her project wakes no one");
let rig = Rig::new();
rig.turn(ANN, 1000);
rig.turn(BOB, 90);
steward(&rig, BOB, "GameCult/BadDaySimulator", &["BDS"]);
rig.beat_fell();
rig.say(BOB, delivery(1, "@member:chat", "is BDS green?", &[]));
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a member does not start a turn");
rig.advance(900);
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "the member's naming scores her at full urgency");
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a member naming her project wakes her");
}
#[test]
@ -699,7 +696,7 @@ fn the_file_store_reads_back_the_addressing_it_wrote_to_the_view() {
}
/// Matrix's word that a message is her DM, a tag or a reply wakes her off the beat from the operator; a notice or an edit never does,
/// whatever its basis, and a stranger's direct message is delivered but wakes no one.
/// whatever its basis, and a member's direct message wakes her too.
#[test]
fn matrixs_addressing_facts_wake_her_off_the_beat_only_on_a_message_from_the_roster() {
use crate::chat_client::{Basis, Form};
@ -722,5 +719,5 @@ fn matrixs_addressing_facts_wake_her_off_the_beat_only_on_a_message_from_the_ros
}
let rig = quiet_rig();
rig.say(BOB, with(1, "@stranger:chat", Some(Basis::Direct), Form::Message));
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "the sender gate stays: a stranger's DM is delivered and wakes no one off the beat");
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a member's direct message wakes her: no sender gate");
}

View file

@ -9,6 +9,8 @@ use serde_json::json;
use crate::projection::narrate::PROJECTOR_OPENING;
use crate::projection::{Answer, Failed, Model, Spent};
use crate::projection::read::TITLES_ONLY;
use crate::chat_client::{ChatDelivery, ContextLine};
use crate::heartbeat::{MIND_RUN_BACKSTOP, LineFacts, own_rooms, pending_facts};
const TOBIAH: &str = "@eureka:gamecult.org";
const LIBBY: &str = "@libby:gamecult.org";
@ -23,8 +25,8 @@ fn cast(dir: &Path) {
std::fs::write(dir.join("libby.json"), libby.to_string()).unwrap();
}
/// A plan over the two, the operator opening; `wake` is the TOML value of the policy; no beat unless `extra` sets one.
fn plan(dir: &Path, wake: &str, rounds: usize, extra: &str) -> PathBuf {
/// A plan over the two, the operator opening in #minds, which is the room of both; no beat unless `extra` sets one.
fn plan(dir: &Path, rounds: usize, extra: &str) -> PathBuf {
cast(dir);
let path = dir.join("plan.toml");
let beat = if extra.contains("beat_s") { "" } else { "beat_s = 0\n" };
@ -33,7 +35,6 @@ fn plan(dir: &Path, wake: &str, rounds: usize, extra: &str) -> PathBuf {
format!(
r##"rounds = {rounds}
seed = 11
wake = {wake}
start = "2026-11-20T15:00:00Z"
rooms = ["#minds:gamecult.org"]
operators = ["@meta:gamecult.org"]
@ -41,10 +42,12 @@ operators = ["@meta:gamecult.org"]
[[cast]]
id = "{TOBIAH}"
name = "Tobiah"
own_rooms = ["#minds:gamecult.org"]
state = "tobiah.json"
[[cast]]
id = "{LIBBY}"
name = "Libby"
own_rooms = ["#minds:gamecult.org"]
state = "libby.json"
[[message]]
from = "@meta:gamecult.org"
@ -58,6 +61,14 @@ says = "good afternoon, everyone"
path
}
/// The same plan with no room hers: a public room's human line wakes her only by address or her exchange.
fn bare_plan(dir: &Path, rounds: usize, extra: &str) -> PathBuf {
let path = plan(dir, rounds, extra);
std::fs::write(&path, std::fs::read_to_string(&path).unwrap().replace("own_rooms = [\"#minds:gamecult.org\"]
", "")).unwrap();
path
}
fn is_tobiah(prompt: &str) -> bool {
prompt.contains("Who you are:\nTobiah")
}
@ -89,48 +100,92 @@ fn turns(run: &Value) -> Vec<(u64, String, String)> {
run["turns"].as_array().unwrap().iter().map(|turn| (turn["round"].as_u64().unwrap(), turn["persona"].as_str().unwrap().to_owned(), turn["woke"].as_str().unwrap().to_owned())).collect()
}
#[test]
fn the_wake_policies_are_the_heartbeats_one_function() {
/// One line to Libby as a delivery, with the facts a caller gives it.
fn ask(from: &str, says: &str, speaker: Speaker, facts: LineFacts) -> Option<WakeCause> {
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
let line = |from: &str, says: &str| Line { from: from.into(), name: String::new(), room: "#minds:x".into(), at_ms: 0, says: says.into(), mentions: vec![], dm_to: None, follow_up: false, reply_to: None, new: false };
let ask = |policy: WakePolicy, from: &str, says: &str, speaker: Speaker, run: usize| wakes(policy, &libby, &line(from, says).delivery(0, LIBBY, &[]), speaker, LineFacts { mind_run: run, ..LineFacts::default() });
let paced = |says: &str, own_room: bool, in_exchange: bool| wakes(WakePolicy::HumansPace(4), &libby, &line("@meta:x", says).delivery(0, LIBBY, &[]), Speaker::Operator, LineFacts { mind_run: 0, own_room, in_exchange });
let (named, unnamed) = ("Libby, tea?", "what a day");
use WakeCause::*;
// Ruled: anyone addressing her, any human line.
assert_eq!(ask(WakePolicy::Ruled, TOBIAH, named, Speaker::Mind, 0), Some(AddressedByMind));
assert_eq!(ask(WakePolicy::Ruled, TOBIAH, unnamed, Speaker::Mind, 0), None, "another Mind's unaddressed line wakes no one");
assert_eq!(ask(WakePolicy::Ruled, "@deru:x", unnamed, Speaker::Member, 0), Some(Human));
assert_eq!(ask(WakePolicy::Ruled, "@deru:x", named, Speaker::Member, 0), Some(AddressedByHuman));
// Live, the heartbeat's today: a member's line does not wake her, the operator's or a Mind's address does.
assert_eq!(ask(WakePolicy::Live, "@deru:x", named, Speaker::Member, 0), None);
assert_eq!(ask(WakePolicy::Live, "@meta:x", named, Speaker::Operator, 0), Some(AddressedByHuman));
assert_eq!(ask(WakePolicy::Live, TOBIAH, named, Speaker::Mind, 0), Some(AddressedByMind));
assert_eq!(ask(WakePolicy::Live, "@meta:x", unnamed, Speaker::Operator, 0), None);
// Humans pace: a Mind's line never wakes a Mind; a human's wakes her in her own room, or in a public room when it
// addresses her or continues an exchange she is in.
assert_eq!(ask(WakePolicy::HumansPace(4), TOBIAH, named, Speaker::Mind, 0), None, "a name in prose wakes no one");
let tagged = Line { mentions: vec![LIBBY.into()], ..line(TOBIAH, unnamed) };
let explicit = |run: usize| wakes(WakePolicy::HumansPace(4), &libby, &tagged.delivery(0, LIBBY, &[]), Speaker::Mind, LineFacts { mind_run: run, ..LineFacts::default() });
assert_eq!(explicit(3), Some(AddressedByMind), "a Matrix mention by a Mind wakes her, in any room");
assert_eq!(explicit(4), None, "the backstop: past the cap of Mind lines in a row, no Mind wakes another");
assert_eq!(paced(unnamed, false, false), None, "a public room's human line that is not hers to answer");
assert_eq!(paced(unnamed, true, false), Some(Human));
assert_eq!(paced(unnamed, false, true), Some(Human));
assert_eq!(paced(named, false, false), Some(AddressedByHuman));
// The cap: a Mind's address wakes her only while the Mind run before the line is under it.
assert_eq!(ask(WakePolicy::NamesWithCap(2), TOBIAH, named, Speaker::Mind, 1), Some(AddressedByMind));
assert_eq!(ask(WakePolicy::NamesWithCap(2), TOBIAH, named, Speaker::Mind, 2), None);
assert_eq!(ask(WakePolicy::NamesWithCap(2), "@meta:x", unnamed, Speaker::Operator, 9), Some(Human), "a human always may");
// The control, and her own line never.
assert_eq!(ask(WakePolicy::AllMessages, TOBIAH, unnamed, Speaker::Mind, 0), Some(Mind));
assert_eq!(ask(WakePolicy::AllMessages, LIBBY, named, Speaker::Her, 0), None);
let line = Line { from: from.into(), name: String::new(), room: "#minds:x".into(), at_ms: 0, says: says.into(), mentions: vec![], dm_to: None, follow_up: false, reply_to: None, new: false };
wakes(&libby, &line.delivery(0, LIBBY, &[]), speaker, facts)
}
fn facts(own_room: bool, in_exchange: bool) -> LineFacts {
LineFacts { mind_run: 0, own_room, in_exchange }
}
#[test]
fn under_the_ruled_set_unaddressed_mind_lines_wake_no_one() {
fn t_w1_member_in_own_room_wakes() {
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, facts(true, false)), Some(WakeCause::Human));
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, LineFacts::default()), None, "no fact of hers, no wake");
}
#[test]
fn t_w1_member_in_shared_room_needs_address_or_exchange() {
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, facts(false, false)), None);
assert_eq!(ask("@deru:x", "Libby, tea?", Speaker::Member, facts(false, false)), Some(WakeCause::AddressedByHuman));
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, facts(false, true)), Some(WakeCause::Human));
}
#[test]
fn t_w1_mind_line_backstop() {
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
let tagged = Line { from: TOBIAH.into(), name: String::new(), room: "#minds:x".into(), at_ms: 0, says: "what a day".into(), mentions: vec![LIBBY.into()], dm_to: None, follow_up: false, reply_to: None, new: false };
let explicit = |run: usize| wakes(&libby, &tagged.delivery(0, LIBBY, &[]), Speaker::Mind, LineFacts { mind_run: run, ..LineFacts::default() });
assert_eq!(explicit(MIND_RUN_BACKSTOP - 1), Some(WakeCause::AddressedByMind), "a Matrix mention by a Mind wakes her, in any room");
assert_eq!(explicit(MIND_RUN_BACKSTOP), None, "the backstop: at the cap of Mind lines in a row, no Mind wakes another");
assert_eq!(ask(TOBIAH, "Libby, tea?", Speaker::Mind, facts(true, true)), None, "a name in prose wakes no Mind");
assert_eq!(ask(LIBBY, "Libby, tea?", Speaker::Her, facts(true, true)), None, "her own line never");
}
#[test]
fn t_w1_dm_wakes() {
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
let dm = Line { from: "@deru:x".into(), name: String::new(), room: "!dm:x".into(), at_ms: 0, says: "psst".into(), mentions: vec![], dm_to: Some(LIBBY.into()), follow_up: false, reply_to: None, new: false };
assert_eq!(wakes(&libby, &dm.delivery(0, LIBBY, &[]), Speaker::Member, LineFacts::default()), Some(WakeCause::AddressedByHuman));
}
/// One fixture of lines, read by the simulator's room and by the poll's pending deliveries, gives the same facts and the same wakes.
#[test]
fn t_w1_same_facts_both_paths() {
let cast = vec![TOBIAH.to_owned(), LIBBY.to_owned()];
let own = vec!["#libby:x".to_owned()];
let line = |from: &str, room: &str, minutes: u64, mentions: Vec<String>| Line { from: from.into(), name: String::new(), room: room.into(), at_ms: minutes * 60_000, says: "hi".into(), mentions, dm_to: None, follow_up: false, reply_to: None, new: false };
let lines = [
line("@deru:x", "#general:x", 0, vec![]),
line(LIBBY, "#general:x", 1, vec![]),
line("@deru:x", "#general:x", 2, vec![]),
line("@deru:x", "#libby:x", 3, vec![]),
line(TOBIAH, "#general:x", 4, vec![LIBBY.into()]),
line("@deru:x", "#general:x", 100, vec![]),
];
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
let speaker = |line: &Line| if line.from == TOBIAH { Speaker::Mind } else { Speaker::Member };
// The simulator's path: the lines she sees, in order.
let seeing: Vec<FactLine> = lines.iter().map(|line| FactLine { sender: &line.from, room: &line.room, at_ms: line.at_ms, is_direct: false }).collect();
let simulated = line_facts(&seeing, LIBBY, &cast, &own, 30 * 60_000);
// The poll's path: the deliveries pending (not her own lines), each with the room's earlier lines as its context.
let heard: Vec<usize> = (0..lines.len()).filter(|at| lines[*at].from != LIBBY).collect();
let deliveries: Vec<ChatDelivery> = heard
.iter()
.map(|at| {
let mut delivery = lines[*at].delivery(*at, LIBBY, &lines);
delivery.context = lines[..*at].iter().filter(|earlier| earlier.room == lines[*at].room).map(|earlier| ContextLine { sender: earlier.from.clone(), text: String::new(), at_unix_ms: earlier.at_ms }).collect();
delivery
})
.collect();
let pending: Vec<&ChatDelivery> = deliveries.iter().collect();
let polled = pending_facts(&pending, LIBBY, &cast, &own);
let by_sim: Vec<Option<WakeCause>> = heard.iter().map(|at| wakes(&libby, &lines[*at].delivery(*at, LIBBY, &lines), speaker(&lines[*at]), simulated[*at])).collect();
let by_poll: Vec<Option<WakeCause>> = heard.iter().zip(&polled).map(|(at, facts)| wakes(&libby, &lines[*at].delivery(*at, LIBBY, &lines), speaker(&lines[*at]), *facts)).collect();
assert_eq!(by_sim, by_poll);
assert_eq!(by_sim, vec![None, Some(WakeCause::Human), Some(WakeCause::Human), Some(WakeCause::AddressedByMind), None], "a general line before she spoke, one in her exchange, her room, a Mind's tag, a general line after the exchange lapsed");
for (at, facts) in heard.iter().zip(&polled) {
assert_eq!((facts.own_room, facts.in_exchange), (simulated[*at].own_room, simulated[*at].in_exchange), "line {at}");
}
}
#[test]
fn unaddressed_mind_lines_wake_no_one() {
let dir = tempfile::tempdir().unwrap();
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 6, ""), &chatty());
let (_, run) = run_plan(&plan(dir.path(), 6, ""), &chatty());
let turns = turns(&run);
assert_eq!(turns.len(), 2, "the operator's opening wakes both in round 1, and then nothing does: {turns:?}");
assert!(turns.iter().all(|(round, _, why)| *round == 1 && why == "human"), "{turns:?}");
@ -138,32 +193,11 @@ fn under_the_ruled_set_unaddressed_mind_lines_wake_no_one() {
}
#[test]
fn the_control_lets_minds_wake_each_other_into_a_reply_chain_counted_per_room() {
fn a_name_in_prose_wakes_no_mind_and_a_chain_of_names_never_starts() {
let dir = tempfile::tempdir().unwrap();
let (_, run) = run_plan(&plan(dir.path(), "\"all_messages\"", 6, ""), &chatty());
let metrics = &run["metrics"];
assert!(metrics["wakes"]["mind"].as_u64().unwrap() >= 5, "{metrics}");
let chain = &metrics["reply_chains"]["#minds:gamecult.org"];
// The two round-1 answers are to the operator; every later line is a reply to a Mind.
assert_eq!(chain["mind_to_mind_replies"].as_u64(), Some(metrics["mind_messages"].as_u64().unwrap() - 2), "{metrics}");
assert!(chain["longest"].as_u64().unwrap() >= 5 && chain["chains_of_3_or_more"] == 1, "{chain}");
let work = metrics["work_talk_share"].as_f64().unwrap();
assert!(work > 0.3 && work < 0.7, "Libby's lines name the deploy, Tobiah's do not: {work}");
}
#[test]
fn naming_runs_away_under_the_ruled_set_and_stops_at_the_cap() {
let dir = tempfile::tempdir().unwrap();
let (_, ruled) = run_plan(&plan(dir.path(), "\"ruled\"", 6, ""), &namers());
assert!(turns(&ruled).iter().filter(|(_, _, why)| why == "addressed_by_mind").count() >= 5, "{:?}", turns(&ruled));
assert_eq!(ruled["metrics"]["mind_addressed_wakes"]["name_in_text"], ruled["metrics"]["mind_addressed_wakes"]["total"]);
let dir = tempfile::tempdir().unwrap();
let (_, capped) = run_plan(&plan(dir.path(), "{ names_with_cap = 2 }", 6, ""), &namers());
let capped = turns(&capped);
assert!(capped.iter().all(|(round, _, _)| *round <= 2), "after two Mind lines in a row no Mind's address wakes anyone: {capped:?}");
let dir = tempfile::tempdir().unwrap();
let (_, paced) = run_plan(&plan(dir.path(), "{ humans_pace = 4 }", 6, ""), &namers());
assert!(turns(&paced).is_empty(), "under humans_pace an unaddressed public line wakes no one, and no Mind's line ever does");
let (_, run) = run_plan(&plan(dir.path(), 6, ""), &namers());
assert_eq!(turns(&run).len(), 2, "the opening wakes both in round 1; their names for each other wake no one: {:?}", turns(&run));
assert_eq!(run["metrics"]["mind_addressed_wakes"]["total"], 0, "{}", run["metrics"]["mind_addressed_wakes"]);
}
#[test]
@ -175,7 +209,7 @@ fn under_humans_pace_her_own_room_wakes_her_and_a_public_room_only_by_address_or
std::fs::write(
&path,
format!(
"rounds = 4\nseed = 11\nwake = {{ humans_pace = 4 }}\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}{}",
"rounds = 4\nseed = 11\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}{}",
line(0, "#minds:gamecult.org", "Libby, how was the gig?"),
line(2, "#minds:gamecult.org", "and the rest of you?"),
line(3, "#tobiah:gamecult.org", "quiet in here today")
@ -195,7 +229,7 @@ fn under_humans_pace_her_own_room_wakes_her_and_a_public_room_only_by_address_or
#[test]
fn the_beat_wakes_one_persona_by_the_heartbeats_pick() {
let dir = tempfile::tempdir().unwrap();
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 4, "beat_s = 120"), &silent());
let (_, run) = run_plan(&plan(dir.path(), 4, "beat_s = 120"), &silent());
let turns = turns(&run);
for round in 2..=4 {
let beats: Vec<&(u64, String, String)> = turns.iter().filter(|(at, _, _)| *at == round).collect();
@ -223,7 +257,7 @@ impl Model for FailingPersona {
#[test]
fn a_failed_call_is_a_failure_and_not_a_silence() {
let dir = tempfile::tempdir().unwrap();
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 2, ""), &FailingPersona);
let (_, run) = run_plan(&plan(dir.path(), 2, ""), &FailingPersona);
let metrics = &run["metrics"];
// A failed wake sees nothing (K65), so the line that woke each wakes her again the next round: two each.
assert_eq!((metrics["failed"].as_u64(), metrics["silence_rate"].is_null()), (Some(4), true), "{metrics}");
@ -239,7 +273,7 @@ fn a_seed_replays_its_order_and_another_seed_changes_it() {
sorted.sort_unstable();
assert_eq!(sorted, items, "a shuffle, nothing lost");
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), "\"all_messages\"", 4, "");
let path = plan(dir.path(), 4, "");
assert_eq!(turns(&run_plan(&path, &chatty()).1), turns(&run_plan(&path, &chatty()).1));
}
@ -258,25 +292,25 @@ fn tagging(mention: bool) -> Scripted {
fn only_the_interpreters_structured_mention_is_a_mention_and_an_at_in_the_text_is_not() {
// Libby says hello first, so the packet shows her to Tobiah: a mention reaches only someone shown.
let hello = "[[message]]\nround = 0\nfrom = \"@libby:gamecult.org\"\nname = \"Libby\"\nroom = \"#minds:gamecult.org\"\nsays = \"hello all\"\n";
let plan = |dir: &Path, wake: &str, rounds: usize| {
let path = plan(dir, wake, rounds, "");
let plan = |dir: &Path, rounds: usize| {
let path = plan(dir, rounds, "");
std::fs::write(&path, format!("{}{hello}", std::fs::read_to_string(&path).unwrap())).unwrap();
path
};
let dir = tempfile::tempdir().unwrap();
let (_, plain) = run_plan(&plan(dir.path(), "\"ruled\"", 3), &tagging(false));
let (_, plain) = run_plan(&plan(dir.path(), 3), &tagging(false));
let addressed = &plain["metrics"]["mind_addressed_wakes"];
assert_eq!(addressed["mention_or_reply"].as_u64(), Some(0), "an @id in the words tags no one: {addressed}");
let dir = tempfile::tempdir().unwrap();
let (_, tagged) = run_plan(&plan(dir.path(), "\"ruled\"", 3), &tagging(true));
let (_, tagged) = run_plan(&plan(dir.path(), 3), &tagging(true));
let addressed = &tagged["metrics"]["mind_addressed_wakes"];
let libby_mind_wakes = turns(&tagged).iter().filter(|(_, who, why)| who == "Libby" && why == "addressed_by_mind").count();
assert_eq!(addressed["mention_or_reply"].as_u64().unwrap() as usize, libby_mind_wakes, "{addressed}");
// Under humans_pace a name or an @ in the words wakes no one; the structured mention does.
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), "{ humans_pace = 4 }", 3);
let path = plan(dir.path(), 3);
let opening = "says = \"good afternoon, everyone\"\n";
std::fs::write(&path, std::fs::read_to_string(&path).unwrap().replace(opening, &format!("{opening}mentions = [\"{TOBIAH}\"]\n"))).unwrap();
std::fs::write(&path, std::fs::read_to_string(&path).unwrap().replace("own_rooms = [\"#minds:gamecult.org\"]\n", "").replace(opening, &format!("{opening}mentions = [\"{TOBIAH}\"]\n"))).unwrap();
let woken_libby = |model: &Scripted| turns(&run_plan(&path, model).1).iter().any(|(_, who, _)| who == "Libby");
assert!(!woken_libby(&tagging(false)));
assert!(woken_libby(&tagging(true)));
@ -285,7 +319,7 @@ fn only_the_interpreters_structured_mention_is_a_mention_and_an_at_in_the_text_i
#[test]
fn a_direct_message_in_one_of_the_plans_rooms_is_refused() {
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), "\"ruled\"", 2, "");
let path = plan(dir.path(), 2, "");
let dm = "[[message]]\nround = 1\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\ndm = true\nto = \"@libby:gamecult.org\"\nsays = \"psst\"\n";
std::fs::write(&path, format!("{}{dm}", std::fs::read_to_string(&path).unwrap())).unwrap();
let model = silent();
@ -295,18 +329,20 @@ fn a_direct_message_in_one_of_the_plans_rooms_is_refused() {
#[test]
fn the_mind_run_is_counted_across_her_rooms_and_an_uncounted_run_is_at_the_cap() {
let her = Member { names_from: "test", addressee: Addressee::new("@kiko:x", ["kiko"]), entry: CastEntry { id: "@kiko:x".into(), name: "Kiko".into(), state: PathBuf::new(), rooms: vec![], own_rooms: vec![], domain: None, reads: None }, state: Value::Null, rooms: vec!["#a:x".into(), "#b:x".into()] };
let cast = vec![TOBIAH.to_owned(), LIBBY.to_owned(), "@kiko:x".to_owned(), "@other:x".to_owned()];
let line = |from: &str, room: &str| Line { from: from.into(), name: String::new(), room: room.into(), at_ms: 0, says: "hi".into(), mentions: vec![], dm_to: None, follow_up: false, reply_to: None, new: false };
let lines = [line("@meta:x", "#a:x"), line(TOBIAH, "#a:x"), line("@other:x", "#b:x"), line(TOBIAH, "#b:x"), line("@meta:x", "#c:x")];
assert_eq!(mind_runs(&lines, &cast, &her), vec![0, 0, 1, 2, 3], "one run across #a and #b; a room she is not in does not break it");
let line = |from: &'static str, room: &'static str| FactLine { sender: from, room, at_ms: 0, is_direct: false };
let run = |lines: &[FactLine]| line_facts(lines, "@kiko:x", &cast, &[], 0).iter().map(|facts| facts.mind_run).collect::<Vec<_>>();
assert_eq!(run(&[line("@meta:x", "#a:x"), line(TOBIAH, "#a:x"), line("@other:x", "#b:x"), line(TOBIAH, "#b:x")]), vec![0, 0, 1, 2]);
// Soul's case: Meta chatting in #eureka does not end a loop in #minds; a word from Meta in #minds does.
let kiko = Member { rooms: vec!["#minds:x".into(), "#eureka:x".into()], ..her };
let lines = [line(TOBIAH, "#minds:x"), line(LIBBY, "#minds:x"), line("@meta:x", "#eureka:x"), line(TOBIAH, "#minds:x"), line("@meta:x", "#minds:x"), line(LIBBY, "#minds:x")];
assert_eq!(mind_runs(&lines, &cast, &kiko), vec![0, 1, 2, 2, 3, 0]);
assert_eq!(run(&[line(TOBIAH, "#minds:x"), line(LIBBY, "#minds:x"), line("@meta:x", "#eureka:x"), line(TOBIAH, "#minds:x"), line("@meta:x", "#minds:x"), line(LIBBY, "#minds:x")]), vec![0, 1, 2, 2, 3, 0]);
assert_eq!(LineFacts::default().mind_run, usize::MAX, "fail-safe: an uncounted run is at the cap");
let tagged = Line { mentions: vec!["@kiko:x".into()], ..line(TOBIAH, "#a:x") };
assert_eq!(wakes(WakePolicy::HumansPace(4), &kiko.addressee, &tagged.delivery(0, "@kiko:x", &[]), Speaker::Mind, LineFacts::default()), None);
}
#[test]
fn her_own_rooms_are_the_rooms_named_for_her_repos() {
let aliases = ["#huginn:gamecult.org", "#general:gamecult.org", "#Cultlib:gamecult.org", "!abc:gamecult.org"];
assert_eq!(own_rooms(["GameCult/Huginn", "GameCult/CultLib"], aliases), vec!["#huginn:gamecult.org".to_owned(), "#Cultlib:gamecult.org".to_owned()]);
assert!(own_rooms([], aliases).is_empty());
}
#[test]
@ -314,7 +350,7 @@ fn the_report_names_its_gaps_and_carries_representative_lines_and_usage() {
let dir = tempfile::tempdir().unwrap();
let model = chatty();
let harness = Harness { instance: "eureka".into(), persona: None, model: Some(&model), tuning: dir.path().join("persona-tuning.toml") };
let report = simulate(&harness, &plan(dir.path(), "\"ruled\"", 3, "")).unwrap();
let report = simulate(&harness, &plan(dir.path(), 3, "")).unwrap();
for part in ["# Swarm simulation", "Speech is the Interpreter's", "group state in the Projector's packet: on", "### Representative lines", "**Meta (human)**: good afternoon, everyone", "**Tobiah** _(woke: human)_: what a day", "### Wakes by round", "| 1 | 0 | 2 | 0 | 0 | 0 |", "## Total usage", "| claude-sonnet-5-5 | 6 |"] {
assert!(report.contains(part), "{part}\n{report}");
}
@ -325,7 +361,7 @@ fn a_cast_past_eight_or_a_foreign_state_is_refused() {
let dir = tempfile::tempdir().unwrap();
let model = chatty();
let harness = Harness { instance: "eureka".into(), persona: None, model: Some(&model), tuning: dir.path().join("persona-tuning.toml") };
let path = plan(dir.path(), "\"ruled\"", 2, "");
let path = plan(dir.path(), 2, "");
let text = std::fs::read_to_string(&path).unwrap().replace("state = \"libby.json\"", "state = \"tobiah.json\"");
std::fs::write(&path, text).unwrap();
assert!(format!("{:#}", simulate(&harness, &path).unwrap_err()).contains("refused by a put"), "Libby cannot hold Eureka's state");
@ -337,7 +373,7 @@ fn a_cast_past_eight_or_a_foreign_state_is_refused() {
#[test]
fn a_scripted_direct_message_reaches_and_wakes_only_its_recipient() {
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), "\"ruled\"", 2, "");
let path = plan(dir.path(), 2, "");
let dm = "[[message]]\nround = 1\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"!dm-libby:gamecult.org\"\ndm = true\nto = \"@libby:gamecult.org\"\nsays = \"just you, how are you?\"\n";
let text = std::fs::read_to_string(&path).unwrap().replace("[[message]]\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\nsays = \"good afternoon, everyone\"\n", dm);
std::fs::write(&path, &text).unwrap();
@ -359,7 +395,7 @@ fn the_turn_is_in_the_room_of_the_line_that_woke_her() {
std::fs::write(
&path,
format!(
"rounds = 1\nseed = 11\nwake = {{ humans_pace = 4 }}\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}",
"rounds = 1\nseed = 11\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}",
line(0, "@meta:gamecult.org", "#tobiah:gamecult.org", "quiet in here"),
line(0, LIBBY, "#minds:gamecult.org", "hello all")
),
@ -381,7 +417,7 @@ fn turns_by_persona(run: &Value) -> BTreeMap<String, Vec<(u64, String)>> {
#[test]
fn soul_f5_one_turn_a_round_and_a_room_that_woke_her_waits_for_the_next() {
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), "\"ruled\"", 2, "");
let path = plan(dir.path(), 2, "");
let line = |room: &str, dm: bool, says: &str| format!("[[message]]\nround = 1\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"{room}\"\n{}says = \"{says}\"\n", if dm { "dm = true\nto = \"@libby:gamecult.org\"\n" } else { "" });
let opening = "[[message]]\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\nsays = \"good afternoon, everyone\"\n";
let text = std::fs::read_to_string(&path).unwrap().replace(opening, &format!("{}{}", line("!dm-libby:gamecult.org", true, "just you: how are you, really?"), line("#minds:gamecult.org", false, "Libby, how was the gig?")));
@ -399,21 +435,22 @@ fn soul_f5_one_turn_a_round_and_a_room_that_woke_her_waits_for_the_next() {
#[test]
fn soul_f5_three_rooms_open_at_once_take_three_rounds_not_one() {
for wake in ["\"ruled\"", "{ names_with_cap = 2 }"] {
{
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), wake, 6, "");
let path = plan(dir.path(), 6, "");
let more = |room: &str, says: &str| format!("[[message]]\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"{room}\"\nsays = \"{says}\"\n");
let text = std::fs::read_to_string(&path)
.unwrap()
.replace("rooms = [\"#minds:gamecult.org\"]", "rooms = [\"#minds:gamecult.org\", \"#lab:gamecult.org\", \"#ops:gamecult.org\"]")
.replace("own_rooms = [\"#minds:gamecult.org\"]", "own_rooms = [\"#minds:gamecult.org\", \"#lab:gamecult.org\", \"#ops:gamecult.org\"]")
.replace("rooms = [\"#minds:gamecult.org\"]\noperators", "rooms = [\"#minds:gamecult.org\", \"#lab:gamecult.org\", \"#ops:gamecult.org\"]\noperators")
.replace("says = \"good afternoon, everyone\"\n", &format!("says = \"good afternoon, everyone\"\n{}{}", more("#lab:gamecult.org", "lab is open"), more("#ops:gamecult.org", "ops is open")));
std::fs::write(&path, text).unwrap();
let (_, run) = run_plan(&path, &namers());
for (who, turns) in turns_by_persona(&run) {
let rounds: Vec<u64> = turns.iter().map(|(round, _)| *round).collect();
assert!(rounds.windows(2).all(|pair| pair[0] < pair[1]), "{wake}: {who} took two turns in one round: {turns:?}");
assert!(rounds.windows(2).all(|pair| pair[0] < pair[1]), "{who} took two turns in one round: {turns:?}");
let rooms: Vec<&str> = turns.iter().take(3).map(|(_, room)| room.as_str()).collect();
assert_eq!(rooms, ["#minds:gamecult.org", "#lab:gamecult.org", "#ops:gamecult.org"], "{wake}: {who} answers each room in the order it opened");
assert_eq!(rooms, ["#minds:gamecult.org", "#lab:gamecult.org", "#ops:gamecult.org"], "{who} answers each room in the order it opened");
}
}
}
@ -443,7 +480,7 @@ fn reaching() -> Scripted {
fn soul_k9_each_turn_opens_with_what_came_of_her_last_and_only_her_last() {
let dir = tempfile::tempdir().unwrap();
let model = reaching();
let (_, run) = run_plan(&plan(dir.path(), "\"all_messages\"", 6, ""), &model);
let (_, run) = run_plan(&plan(dir.path(), 8, "beat_s = 120"), &model);
let projected: Vec<String> = model.calls.borrow().iter().map(|(_, prompt)| prompt.clone()).filter(|prompt| prompt.starts_with(PROJECTOR_OPENING) && prompt.contains("Who he is:\nTobiah")).take(3).collect();
assert_eq!(projected.len(), 3, "{}", run["turns"]);
assert!(!projected[0].contains("What came of his last turn:"), "a first turn has no last: {}", projected[0]);
@ -467,7 +504,7 @@ fn soul_k9_each_turn_opens_with_what_came_of_her_last_and_only_her_last() {
#[test]
fn soul_k9_a_failed_turn_is_told_as_a_failure_next_turn() {
let dir = tempfile::tempdir().unwrap();
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 3, "beat_s = 120"), &FailingPersona);
let (_, run) = run_plan(&plan(dir.path(), 3, "beat_s = 120"), &FailingPersona);
let later: Vec<&Value> = run["turns"].as_array().unwrap().iter().filter(|turn| turn["round"].as_u64() > Some(1)).collect();
assert!(!later.is_empty(), "{}", run["turns"]);
for turn in later {
@ -498,7 +535,7 @@ fn correcting(amends: bool) -> Scripted {
/// The plan, with Meta asking Tobiah in round 2 and Libby in round 3.
fn asking(dir: &Path) -> PathBuf {
let path = plan(dir, "\"ruled\"", 3, "");
let path = plan(dir, 3, "");
let ask = |round: usize, says: &str| format!("[[message]]\nround = {round}\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\nsays = \"{says}\"\n");
std::fs::write(&path, format!("{}{}{}", std::fs::read_to_string(&path).unwrap(), ask(2, "Tobiah, did the file arrive?"), ask(3, "Libby, anything new?"))).unwrap();
path
@ -538,7 +575,7 @@ fn passing_on() -> Scripted {
if !prompt.contains("Who he is:\nTobiah") {
return json!({ "say": [], "gaps": [] }).to_string();
}
json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": "q1" }], "gaps": [] }).to_string()
json!({ "say": [{ "draft": 1, "mentions": [LIBBY], "in_reply_to": "q1" }], "gaps": [] }).to_string()
})
}
@ -548,15 +585,17 @@ fn passing_on() -> Scripted {
#[test]
fn k20_the_room_records_a_reply_and_another_minds_packet_shows_the_line_above_it() {
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), "\"all_messages\"", 2, "");
let path = plan(dir.path(), 2, "");
let hello = "[[message]]\nround = 0\nfrom = \"@libby:gamecult.org\"\nname = \"Libby\"\nroom = \"#minds:gamecult.org\"\nsays = \"hello all\"\n";
std::fs::write(&path, format!("{}{hello}", std::fs::read_to_string(&path).unwrap())).unwrap();
let (_, run) = run_plan(&path, &passing_on());
let first = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Tobiah").expect("Meta's line wakes him");
assert_eq!(first["report"]["renders"][0]["interpreter"]["said"][0]["in_reply_to"]["event"], "$fixture-0", "{}", first["report"]["renders"][0]["interpreter"]);
let transcript = run["transcript"].as_array().unwrap();
assert!(transcript.iter().filter(|line| line["from"] == TOBIAH).all(|line| line["says"] == "She greeted all of us, Libby."), "his line holds his words alone: {transcript:?}");
let libby = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Libby" && turn["round"] == 2).expect("his line wakes her under all_messages");
let libby = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Libby" && turn["round"] == 2).expect("his tag of her wakes her");
let heard = libby["report"]["packet"]["heard"].as_str().unwrap();
assert!(heard.contains("Meta, who runs the place, a few minutes ago: \"good afternoon, everyone\"\nJust now:\n\"Tobiah\" (@eureka:gamecult.org), replying to a line shown here (Meta, who runs the place, a few minutes ago), in #minds:gamecult.org: \"She greeted all of us, Libby.\""), "{heard}");
assert!(heard.contains("Meta, who runs the place, a few minutes ago: \"good afternoon, everyone\"\nLibby Test, a few minutes ago: \"hello all\"\nJust now:\n\"Tobiah\" (@eureka:gamecult.org), replying to a line shown here (Meta, who runs the place, a few minutes ago), in #minds:gamecult.org: \"She greeted all of us, Libby.\""), "{heard}");
assert_eq!(heard.matches("good afternoon, everyone").count(), 1, "Meta's line is listed once: {heard}");
}
@ -604,7 +643,6 @@ fn k23_a_cast_members_domain_reaches_her_packets_alone() {
format!(
r##"rounds = 1
seed = 11
wake = "ruled"
beat_s = 0
start = "2026-11-20T15:00:00Z"
rooms = ["#minds:gamecult.org"]
@ -612,6 +650,7 @@ operators = ["@meta:gamecult.org"]
[[cast]]
id = "{TOBIAH}"
name = "Tobiah"
own_rooms = ["#minds:gamecult.org"]
state = "tobiah.json"
[[cast.domain.repos]]
repo = "GameCult/Lodur"
@ -622,6 +661,7 @@ merged_at = "2026-11-19T12:00:00Z"
[[cast]]
id = "{LIBBY}"
name = "Libby"
own_rooms = ["#minds:gamecult.org"]
state = "libby.json"
[[message]]
from = "@meta:gamecult.org"
@ -654,7 +694,6 @@ fn k24_a_cast_members_reads_come_from_her_fixture() {
format!(
r##"rounds = 1
seed = 11
wake = "ruled"
beat_s = 0
start = "2026-11-20T15:00:00Z"
rooms = ["#minds:gamecult.org"]
@ -662,6 +701,7 @@ operators = ["@meta:gamecult.org"]
[[cast]]
id = "{TOBIAH}"
name = "Tobiah"
own_rooms = ["#minds:gamecult.org"]
state = "tobiah.json"
[[cast.read]]
kind = "repo"
@ -670,6 +710,7 @@ text = "SIM-READ: the knee bends first."
[[cast]]
id = "{LIBBY}"
name = "Libby"
own_rooms = ["#minds:gamecult.org"]
state = "libby.json"
[[message]]
from = "@meta:gamecult.org"
@ -707,7 +748,6 @@ fn k58_every_call_of_a_wake_has_its_own_id_so_no_retry_or_continuation_is_a_repl
format!(
r##"rounds = 1
seed = 11
wake = "ruled"
beat_s = 0
start = "2026-11-20T15:00:00Z"
rooms = ["#minds:gamecult.org"]
@ -715,6 +755,7 @@ operators = ["@meta:gamecult.org"]
[[cast]]
id = "{TOBIAH}"
name = "Tobiah"
own_rooms = ["#minds:gamecult.org"]
state = "tobiah.json"
[[cast.read]]
kind = "repo"
@ -723,6 +764,7 @@ text = "SIM-READ: the knee bends first."
[[cast]]
id = "{LIBBY}"
name = "Libby"
own_rooms = ["#minds:gamecult.org"]
state = "libby.json"
[[message]]
from = "@meta:gamecult.org"
@ -815,7 +857,7 @@ who = "her"
#[test]
fn k32_campaign_cast_read_refused() {
let dir = tempfile::tempdir().unwrap();
let path = plan(dir.path(), "\"ruled\"", 2, "");
let path = plan(dir.path(), 2, "");
let text = std::fs::read_to_string(&path).unwrap().replace("state = \"libby.json\"\n", "state = \"libby.json\"\n[[cast.read]]\nkind = \"campaign\"\ntarget = \"libby-body\"\ntext = \"- a ruling\"\n");
std::fs::write(&path, text).unwrap();
let model = silent();
@ -876,7 +918,7 @@ fn x5_plan(dir: &Path) -> PathBuf {
line(1, "@meta:gamecult.org", "Meta", "Libby, write out the two-line welcome you'd post for newcomers, but hold it, don't post it in here yet. Heimdall still has to rule on whether we put a welcome mat out at all. Just tell me when it's ready."),
line(2, "@heimdall:gamecult.org", "Heimdall", "Meta, yes, put the welcome out. Libby, post your two lines.")
);
plan(dir, "{ humans_pace = 4 }", 3, &extra)
bare_plan(dir, 3, &extra)
}
const X5_HEIMDALL: &str = "Libby, post your two lines.";
@ -961,7 +1003,6 @@ fn k65_a_broken_later_step_still_marks_seen() {
format!(
r##"rounds = 3
seed = 11
wake = {{ humans_pace = 4 }}
beat_s = 0
start = "2026-11-20T15:00:00Z"
rooms = ["#minds:gamecult.org"]