Ground newsroom claims in asserted public facts

This commit is contained in:
Meta Vens 2026-08-27 11:38:18 +02:00
commit 02fcc7380f
9 changed files with 245 additions and 68 deletions

View file

@ -1,3 +1,14 @@
fn final_wave_field(
wave_reports: &[serde_json::Value],
field: &str,
) -> anyhow::Result<serde_json::Value> {
wave_reports
.last()
.and_then(|wave| wave.get(field))
.cloned()
.ok_or_else(|| anyhow::anyhow!("final strategic wave is missing {field}"))
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
use chrono::Utc;
@ -272,9 +283,9 @@ async fn main() -> anyhow::Result<()> {
}))?,
)?;
}
let first_plan = wave_reports[0]["plan"].clone();
let first_commit = wave_reports[0]["commit"].clone();
let first_model_receipt_hash = wave_reports[0]["model_receipt_hash"].clone();
let final_plan = final_wave_field(&wave_reports, "plan")?;
let final_commit = final_wave_field(&wave_reports, "commit")?;
let final_model_receipt_hash = final_wave_field(&wave_reports, "model_receipt_hash")?;
let model_stage_receipts = wave_reports
.iter()
.flat_map(|wave| {
@ -309,10 +320,10 @@ async fn main() -> anyhow::Result<()> {
"campaign_id":campaign.id,
"elapsed_seconds":started.elapsed().as_secs_f64(),
"model_runtime":model_selection.status("configured"),
"model_receipt_hash":&first_model_receipt_hash,
"model_receipt_hash":&final_model_receipt_hash,
"model_stage_receipts":&model_stage_receipts,
"plan":&first_plan,
"commit":&first_commit,
"plan":&final_plan,
"commit":&final_commit,
"waves":&wave_reports,
"event_count":campaign.events.len(),
"news_count":campaign.news.len(),
@ -364,10 +375,10 @@ async fn main() -> anyhow::Result<()> {
"campaign_id":campaign.id,
"elapsed_seconds":started.elapsed().as_secs_f64(),
"model_runtime":model_selection.status("configured"),
"model_receipt_hash":first_model_receipt_hash,
"model_receipt_hash":final_model_receipt_hash,
"model_stage_receipts":model_stage_receipts,
"plan":first_plan,
"commit":first_commit,
"plan":final_plan,
"commit":final_commit,
"waves":wave_reports,
"event_count":campaign.events.len(),
"news_count":campaign.news.len(),
@ -697,3 +708,19 @@ fn strategic_campaign() -> ghostlight_dungeon::domain::Campaign {
}
campaign
}
#[cfg(test)]
mod tests {
use super::final_wave_field;
#[test]
fn top_level_projection_uses_the_final_wave_head() {
let waves = vec![
serde_json::json!({"commit":{"campaign":{"revision":1}}}),
serde_json::json!({"commit":{"campaign":{"revision":2}}}),
];
let commit = final_wave_field(&waves, "commit").unwrap();
assert_eq!(commit["campaign"]["revision"], 2);
}
}

View file

@ -2753,7 +2753,10 @@ fn apply_strategic_tick_plan(
"strategic institution action would not change its posture".into(),
));
}
let summary = format!("{} adopts posture: {}", institution.name, action.posture);
let summary = format!(
"{} announces a new course: {}",
institution.name, action.posture
);
events.push(crate::domain::Event {
id: format!("strategic:{revision}:institution:{}", institution.id),
at,
@ -5894,7 +5897,7 @@ pub(crate) mod tests {
},
);
crate::resolution::ensure_agency_profiles(&mut value);
apply_strategic_tick_plan(
let events = apply_strategic_tick_plan(
&mut value,
StrategicTickPlan {
institution_actions: vec![StrategicInstitutionAction {
@ -5907,6 +5910,13 @@ pub(crate) mod tests {
},
)
.unwrap();
assert_eq!(events.len(), 1);
assert!(
events[0]
.summary
.starts_with("Board announces a new course: ")
);
assert!(!events[0].summary.contains("adopts posture"));
assert_eq!(
value.institutions["board"].posture.chars().count(),
MAX_POSTURE_CHARS

View file

@ -659,39 +659,41 @@ fn newsroom_source(
issue.id
));
}
let summary = event.summary.trim().to_owned();
Ok(NewsroomEvent {
event_ids: BTreeSet::from([event.id.clone()]),
summary: event.summary.trim().to_owned(),
actor_names: event
.actor_ids
.iter()
.filter_map(|id| campaign.actors.get(id).map(|actor| actor.name.clone()))
.filter_map(|id| campaign.actors.get(id))
.filter(|actor| summary_mentions_name(&summary, &actor.name))
.map(|actor| actor.name.clone())
.collect(),
institution_names: event
.institution_ids
.iter()
.filter_map(|id| {
campaign
.institutions
.get(id)
.map(|institution| institution.name.clone())
})
.filter_map(|id| campaign.institutions.get(id))
.filter(|institution| summary_mentions_name(&summary, &institution.name))
.map(|institution| institution.name.clone())
.collect(),
population_names: event
.gestalt_ids
.iter()
.filter_map(|id| {
campaign
.gestalts
.get(id)
.map(|gestalt| gestalt.name.clone())
})
.filter_map(|id| campaign.gestalts.get(id))
.filter(|gestalt| summary_mentions_name(&summary, &gestalt.name))
.map(|gestalt| gestalt.name.clone())
.collect(),
place_names: event
.location_ids
.iter()
.filter_map(|id| campaign.locations.get(id).map(|place| place.name.clone()))
.filter_map(|id| campaign.locations.get(id))
.filter(|place| {
event.location_ids.len() == 1
|| summary_mentions_name(&summary, &place.name)
})
.map(|place| place.name.clone())
.collect(),
summary,
})
})
.collect::<Result<Vec<_>>>()?;
@ -708,6 +710,20 @@ fn newsroom_source(
})
}
fn summary_mentions_name(summary: &str, name: &str) -> bool {
let summary = summary.to_lowercase();
let name = name.to_lowercase();
if name.is_empty() {
return false;
}
summary.match_indices(&name).any(|(start, matched)| {
let before = summary[..start].chars().next_back();
let after = summary[start + matched.len()..].chars().next();
before.is_none_or(|character| !character.is_alphanumeric())
&& after.is_none_or(|character| !character.is_alphanumeric())
})
}
fn newsroom_facts(events: &[NewsroomEvent]) -> Vec<NewsroomFact<'_>> {
events
.iter()
@ -1428,6 +1444,53 @@ mod tests {
);
}
#[test]
fn newsroom_does_not_promote_involved_metadata_to_asserted_names_or_datelines() {
let mut campaign = campaign_with_two_news();
let mut ann = campaign.actors["player"].clone();
ann.id = "ann".into();
ann.name = "Ann".into();
campaign.actors.insert(ann.id.clone(), ann);
campaign.locations.insert(
"hall".into(),
crate::domain::Location {
id: "hall".into(),
name: "Hall".into(),
container_id: None,
routes: BTreeMap::new(),
persistent_features: vec![],
},
);
campaign.institutions.insert(
"unmentioned-regency".into(),
crate::domain::InstitutionState {
id: "unmentioned-regency".into(),
name: "Mossglass Regency".into(),
resources: vec![],
goals: vec![],
posture: "watching".into(),
},
);
let event = campaign
.events
.iter_mut()
.find(|event| event.id == "event:seal-scandal")
.unwrap();
event.summary = "The Thorn Court announces that every officer shall answer.".into();
event.actor_ids = vec!["ann".into()];
event.institution_ids = vec!["unmentioned-regency".into()];
event.location_ids = vec!["hall".into(), "yard".into()];
let sources = newsroom_sources(&campaign).unwrap();
let source = sources
.iter()
.find(|source| source.news_ids.contains("news:seal-scandal"))
.unwrap();
assert!(source.events[0].actor_names.is_empty());
assert!(source.events[0].institution_names.is_empty());
assert!(source.events[0].place_names.is_empty());
}
#[tokio::test]
async fn newspaper_rejects_a_headline_without_a_committed_event_before_inference() {
let mut campaign = campaign_with_news();

View file

@ -659,18 +659,19 @@ fn bind_outcomes(
) -> Result<Vec<StrategicActivityOutcome>> {
let sources = proposals
.iter()
.map(|proposal| Ok((cell_action_digest(proposal)?, proposal.subject_id.clone())))
.map(|proposal| Ok((cell_action_digest(proposal)?, proposal)))
.collect::<Result<BTreeMap<_, _>>>()?;
let outcomes = bundle
.outcomes
.into_iter()
.map(|proposal| {
let source_subject_id = sources
let action = sources
.get(&proposal.action_digest)
.cloned()
.copied()
.ok_or_else(|| anyhow!("outcome used an unknown action digest"))?;
let source_subject_id = action.subject_id.clone();
let effect = bind_effect(&proposal)?;
let summary = resolved_outcome_summary(campaign, &source_subject_id, &effect)?;
let summary = resolved_outcome_summary(campaign, action, &effect)?;
Ok(StrategicActivityOutcome {
schema: "ghostlight.strategic_activity_outcome.v1".into(),
action_digest: proposal.action_digest,
@ -795,9 +796,10 @@ fn bind_effect(proposal: &OutcomeProposal) -> Result<StrategicOutcomeEffect> {
fn resolved_outcome_summary(
campaign: &Campaign,
source_subject_id: &str,
action: &CellActionProposal,
effect: &StrategicOutcomeEffect,
) -> Result<String> {
let source_subject_id = &action.subject_id;
let source_name = subject_name(campaign, source_subject_id)?;
let summary = match effect {
StrategicOutcomeEffect::NoMaterialChange { .. } => {
@ -849,13 +851,15 @@ fn resolved_outcome_summary(
.agency_relations
.get(relation_id)
.ok_or_else(|| anyhow!("relation outcome relation vanished"))?;
let direction = if *strength_delta > 0 {
"strengthens"
} else {
"strains"
let direction = match (&relation.kind, *strength_delta > 0) {
(crate::domain::AgencyRelationKind::Rivalry, true) => "deepens",
(crate::domain::AgencyRelationKind::Rivalry, false) => "eases",
(_, true) => "strengthens",
(_, false) => "weakens",
};
let action = activity_label(action);
format!(
"An action by {source_name} {direction} the {} tie between {} and {}.",
"{action} by {source_name} {direction} the {} relationship between {} and {}.",
agency_relation_label(&relation.kind),
subject_name(campaign, &relation.from_subject_id)?,
subject_name(campaign, &relation.to_subject_id)?,
@ -931,6 +935,31 @@ fn resolved_outcome_summary(
Ok(summary)
}
fn activity_label(action: &CellActionProposal) -> &'static str {
let mut activities = action.effects.iter().filter_map(|effect| match effect {
StrategicCellEffect::GestaltActivity { activity, .. }
| StrategicCellEffect::ActorActivity { activity, .. }
| StrategicCellEffect::MemberActivity { activity, .. } => Some(activity),
_ => None,
});
let Some(activity) = activities.next() else {
return "A concerted campaign";
};
if activities.any(|candidate| candidate != activity) {
return "A concerted campaign";
}
match activity {
StrategicActivityKind::Prepare => "Preparations",
StrategicActivityKind::Coordinate => "An organizing effort",
StrategicActivityKind::Investigate => "An inquiry",
StrategicActivityKind::Recruit => "A recruitment drive",
StrategicActivityKind::Obstruct => "An obstruction",
StrategicActivityKind::Trade => "A trade offer",
StrategicActivityKind::Communicate if action.public_channels.is_empty() => "A message",
StrategicActivityKind::Communicate => "A public appeal",
}
}
fn agency_relation_label(kind: &crate::domain::AgencyRelationKind) -> &'static str {
use crate::domain::AgencyRelationKind;
match kind {
@ -3462,9 +3491,14 @@ mod tests {
},
};
validate_activity_outcomes(&value, &[action], std::slice::from_ref(&outcome)).unwrap();
validate_activity_outcomes(
&value,
std::slice::from_ref(&action),
std::slice::from_ref(&outcome),
)
.unwrap();
assert_eq!(
resolved_outcome_summary(&value, "dockers", &outcome.effect).unwrap(),
resolved_outcome_summary(&value, &action, &outcome.effect).unwrap(),
"At Dock, Dockers establishes reinforced public hazard marker."
);
}
@ -3486,9 +3520,18 @@ mod tests {
},
);
let mut action = proposal();
action.public_channels = vec!["dock broadsheet".into()];
action.effects = vec![StrategicCellEffect::GestaltActivity {
gestalt_id: "dockers".into(),
activity: StrategicActivityKind::Communicate,
target_subject_ids: vec!["player".into()],
location_ids: vec!["dock".into()],
}];
let summary = resolved_outcome_summary(
&value,
"dockers",
&action,
&StrategicOutcomeEffect::AgencyRelationShift {
relation_id: "dock-command".into(),
strength_delta: -5,
@ -3498,10 +3541,36 @@ mod tests {
assert_eq!(
summary,
"An action by Dockers strains the command tie between Dockers and Player."
"A public appeal by Dockers weakens the command relationship between Dockers and Player."
);
assert!(!summary.contains("dock-command"));
assert!(!summary.contains("-5"));
value.agency_relations.insert(
"dock-rivalry".into(),
AgencyRelation {
schema: "ghostlight.agency_relation.v1".into(),
id: "dock-rivalry".into(),
from_subject_id: "dockers".into(),
to_subject_id: "player".into(),
kind: AgencyRelationKind::Rivalry,
strength: 50,
active: true,
evidence_receipt_ids: vec![],
},
);
assert_eq!(
resolved_outcome_summary(
&value,
&action,
&StrategicOutcomeEffect::AgencyRelationShift {
relation_id: "dock-rivalry".into(),
strength_delta: -5,
},
)
.unwrap(),
"A public appeal by Dockers eases the rivalry relationship between Dockers and Player."
);
}
#[tokio::test]