Open grievances: kernel-side tests of the derived block; institutions hold no sword; Begin declares the verbs

This commit is contained in:
Meta Vens 2026-12-03 04:38:11 +01:00
commit cff9e78a46
3 changed files with 160 additions and 7 deletions

View file

@ -1074,6 +1074,7 @@ pub(crate) mod tests {
let world = host.world.snapshot().await.unwrap();
assert_eq!(world.phase, WorldPhase::Active);
assert!(world.scale_deficit.is_empty(), "an unseeded Begin states no targets");
assert!(world.affordances.iter().any(|entry| entry.entry.kind.0 == "attack"), "the verbs are declared at Begin");
assert_eq!(rig.status(&begun.timeline).await, None);
let catalog = rig.catalog.lock().await;
assert_eq!(catalog.owned_timeline("alice", &begun.timeline).unwrap().1.snapshot_id, None);

View file

@ -228,13 +228,13 @@ mod tests {
let start = snapshot(&scene).await;
let commons = start.places.iter().find(|place| place.label == "The Commons").unwrap().id;
let speak = start.affordances.iter().find(|entry| entry.entry.kind.0 == "speak").unwrap().id;
let person = |handle: &str, label: &str, position: Value| {
let subject = |handle: &str, label: &str, kind: &str, position: Value| {
(
"declare_subject",
json!({
"handle": handle,
"label": label,
"kind": "person",
"kind": kind,
"controller": {"type": "narrative_persona"},
"affordances": [existing(speak)],
"position": position,
@ -247,10 +247,11 @@ mod tests {
"declare_route",
json!({"handle": "road", "label": "The Road", "from": existing(commons), "to": {"ref": "draft", "value": "gate"}, "access": {"access": "public"}, "cost": 1}),
),
person("dorra", "Dorra Ironkettle", existing(commons)),
person("brann", "Brannoch Deepvein", existing(commons)),
person("grix", "Grix Sparkfinger", existing(commons)),
person("hilda", "Hilda Gatewright", json!({"ref": "draft", "value": "gate"})),
subject("dorra", "Dorra Ironkettle", "person", existing(commons)),
subject("brann", "Brannoch Deepvein", "person", existing(commons)),
subject("grix", "Grix Sparkfinger", "person", existing(commons)),
subject("hilda", "Hilda Gatewright", "person", json!({"ref": "draft", "value": "gate"})),
subject("watch", "The Deepgate Watch", "institution", json!({"ref": "draft", "value": "gate"})),
]);
submit(&scene, CommandBody::AdmitPatch { answers: None, patch }).await;
let drafted = snapshot(&scene).await;
@ -320,7 +321,14 @@ mod tests {
assert!(!seen.contains("Hilda"), "the gate is out of earshot and out of sight: {seen}");
assert!(grievances.contains("Korr"), "{grievances}");
assert!(grievances.contains("nothing has answered it yet"), "{grievances}");
assert!(view.contains("Dorra Ironkettle ["), "{view}");
let subjects = between(&view, "Subjects:", "
Affordances");
let watch = between(subjects, "The Deepgate Watch [", "holdings");
assert!(watch.contains("institution") && !watch.contains("attack"), "an institution is granted no sword: {watch}");
let player = between(subjects, "Korr [", "holdings");
for verb in VERBS {
assert!(player.contains(verb), "the player holds {verb}: {player}");
}
}
#[tokio::test]

View file

@ -498,3 +498,147 @@ fn the_derived_opinion_and_its_causes_reach_the_tables_view() {
assert!(line.contains("a grievance (-30)"), "{line}");
assert!(line.contains("prejudice toward the outlander (-40)"), "{line}");
}
/// An act the room saw: the same invocation as `exercise`, with the actor's own
/// words for what everyone present watched.
fn exercise_displaying(
kernel: &mut WorldKernel,
actor: SubjectId,
affordance: AffordanceId,
bindings: Vec<RoleBinding>,
display: &str,
) -> Result<SubmitReceipt, KernelError> {
let snapshot = kernel.snapshot().unwrap();
let opportunity = opportunity_for(&snapshot, actor);
let caller = CallerId::Controller(opportunity.controller_id);
kernel.submit(
command(
&snapshot,
CommandId::new(),
caller.clone(),
CommandBody::ExerciseDecision {
opportunity,
invocation: DecisionInvocation {
affordance,
bindings,
proposed: vec![ProposedEffect {
slot: 0,
magnitude: Magnitude::None,
}],
speech: None,
display: Some(Statement::new(display).unwrap()),
},
},
),
&AuthenticatedCaller::fixture(caller),
)
}
use crate::clock::FictionalMinutes;
use crate::patch::{CommitmentKind, PressureMagnitude};
const BLOW: &str = "The farmer strikes the reeve.";
/// The view's Open grievances block, alone.
fn open_grievances(kernel: &WorldKernel) -> String {
let view = crate::table_view(&kernel.snapshot().unwrap());
view.split("Open grievances")
.nth(1)
.expect("the view always carries the block")
.split("\n Persona material")
.next()
.unwrap()
.to_owned()
}
fn segment<'a>(text: &'a str, from: &str, to: &str) -> &'a str {
let start = text.find(from).unwrap_or_else(|| panic!("`{from}` missing in {text}")) + from.len();
let end = start + text[start..].find(to).unwrap_or(text.len() - start);
&text[start..end]
}
fn strike(kernel: &mut WorldKernel, clockwork: &Clockwork, delta: i16) {
grant_insult(kernel, clockwork.farmer, delta, None);
let insult = insult_id(kernel);
exercise_displaying(
kernel,
clockwork.farmer,
insult,
vec![binding("target", Target::Subject(clockwork.reeve))],
BLOW,
)
.expect("the blow commits");
}
#[test]
fn a_deed_the_room_saw_is_an_open_grievance_until_something_answers_it() {
let directory = tempfile::tempdir().unwrap();
let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Open grievances");
assert!(open_grievances(&kernel).trim().ends_with("none"));
strike(&mut kernel, &clockwork, -30);
let block = open_grievances(&kernel);
assert_eq!(block.matches("wronged").count(), 1, "one doer, no other: {block}");
assert!(block.contains("The Yard Farmer"), "{block}");
assert!(segment(&block, "wronged", ";").contains("The Yard Reeve"), "{block}");
let seen = segment(&block, "acts seen by:", "forums covering");
assert!(seen.contains("The Yard Reeve") && seen.contains(BLOW), "{seen}");
assert!(!seen.contains("The Yard Farmer"), "the doer is not their own witness: {seen}");
assert!(segment(&block, "forums covering them:", ";").contains("none"), "{block}");
assert!(segment(&block, "pressed by:", ";").contains("no one"), "{block}");
assert!(segment(&block, "reckonings sworn against them:", ";").contains("none"), "{block}");
assert!(block.contains("nothing has answered it yet"), "{block}");
// Someone leans on the doer: answered, and the pressure is named with its weight.
play_patch(
&mut kernel,
WorldPatch {
declarations: Vec::new(),
operations: vec![ComponentOp::AdvancePressure {
source: PressureSourceRef::Subject(Ref::Existing(clockwork.reeve)),
target: Ref::Existing(clockwork.farmer),
by: PressureMagnitude(30),
}],
evidence: Vec::new(),
},
)
.unwrap();
let block = open_grievances(&kernel);
let pressed = segment(&block, "pressed by:", ";");
assert!(pressed.contains("The Yard Reeve") && pressed.contains("(30)"), "{pressed}");
assert!(block.contains("answered so far") && !block.contains("nothing has answered"), "{block}");
}
#[test]
fn a_sworn_reckoning_answers_a_grievance_and_a_favour_opens_none() {
let directory = tempfile::tempdir().unwrap();
let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Reckoning");
strike(&mut kernel, &clockwork, -30);
play_patch(
&mut kernel,
WorldPatch {
declarations: Vec::new(),
operations: vec![ComponentOp::CreateCommitment {
subject: Ref::Existing(clockwork.reeve),
counterparty: Some(Ref::Existing(clockwork.farmer)),
kind: CommitmentKind::Obligation,
due: FictionalMinutes(600),
period: None,
checks: Vec::new(),
statement: Statement::new("Make the farmer answer for the blow.").unwrap(),
}],
evidence: Vec::new(),
},
)
.unwrap();
let block = open_grievances(&kernel);
let sworn = segment(&block, "reckonings sworn against them:", "answered");
assert!(sworn.contains("The Yard Reeve") && sworn.contains("Make the farmer answer"), "{sworn}");
assert!(segment(&block, "pressed by:", ";").contains("no one"), "{block}");
assert!(block.contains("answered so far"), "{block}");
let directory = tempfile::tempdir().unwrap();
let (mut kindly, clockwork, _) = clock_kernel(directory.path(), "Favour");
strike(&mut kindly, &clockwork, 20);
assert!(open_grievances(&kindly).trim().ends_with("none"), "a favour is no grievance");
}