Keep canonical headlines in world state
This commit is contained in:
parent
80ad2593ff
commit
2fc3f81068
3 changed files with 56 additions and 47 deletions
|
|
@ -806,6 +806,29 @@ pub struct NewsIssue {
|
|||
pub reliability: String,
|
||||
}
|
||||
|
||||
pub fn committed_news_headline(summary: &str) -> String {
|
||||
const MAX_HEADLINE_CHARS: usize = 96;
|
||||
let summary = summary.trim();
|
||||
if summary.chars().count() <= MAX_HEADLINE_CHARS {
|
||||
return summary.to_owned();
|
||||
}
|
||||
let mut headline = summary.chars().take(MAX_HEADLINE_CHARS).collect::<String>();
|
||||
let semantic_cut = headline
|
||||
.rfind(|character: char| matches!(character, ';' | ':' | ',' | '—'))
|
||||
.filter(|cut| *cut >= MAX_HEADLINE_CHARS / 2);
|
||||
let word_cut = headline
|
||||
.rfind(char::is_whitespace)
|
||||
.filter(|cut| *cut >= MAX_HEADLINE_CHARS / 2);
|
||||
if let Some(cut) = semantic_cut.or(word_cut) {
|
||||
headline.truncate(cut);
|
||||
}
|
||||
headline = headline
|
||||
.trim_end_matches(|character: char| character.is_whitespace() || character == '.')
|
||||
.to_owned();
|
||||
headline.push('…');
|
||||
headline
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Default)]
|
||||
pub struct StrategicTickPlan {
|
||||
/// Canonical admitted strategic choices. The action arrays below are
|
||||
|
|
|
|||
|
|
@ -1340,7 +1340,7 @@ fn execute(
|
|||
id: format!("news:{}:{}", event.id, stable_channel_id(channel)),
|
||||
at: campaign.world_time,
|
||||
channel: channel.clone(),
|
||||
headline: crate::newspaper::committed_event_headline(&event.summary),
|
||||
headline: crate::domain::committed_news_headline(&event.summary),
|
||||
event_ids: vec![event.id.clone()],
|
||||
reliability: "committed public channel".into(),
|
||||
});
|
||||
|
|
@ -9417,9 +9417,27 @@ pub(crate) mod tests {
|
|||
.iter()
|
||||
.any(|event| event.kind == "gestalt_individuation")
|
||||
);
|
||||
assert!(campaign.news.iter().any(|issue| {
|
||||
issue.channel == "storm-camp broadsheet" && issue.headline.contains("Veska Rill")
|
||||
}));
|
||||
let public_individuation = campaign
|
||||
.events
|
||||
.iter()
|
||||
.find(|event| {
|
||||
event.kind == "gestalt_individuation"
|
||||
&& event
|
||||
.public_channels
|
||||
.iter()
|
||||
.any(|channel| channel == "storm-camp broadsheet")
|
||||
})
|
||||
.unwrap();
|
||||
let public_issue = campaign
|
||||
.news
|
||||
.iter()
|
||||
.find(|issue| issue.event_ids == [public_individuation.id.clone()])
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
public_issue.headline,
|
||||
crate::domain::committed_news_headline(&public_individuation.summary)
|
||||
);
|
||||
assert!(public_issue.headline.contains("Veska Rill"));
|
||||
let newspaper =
|
||||
crate::newspaper::compose_world_newspaper(&campaign, "The Underdeep Clarion", 8)
|
||||
.unwrap();
|
||||
|
|
|
|||
|
|
@ -28,29 +28,6 @@ pub struct WorldNewspaperArticle {
|
|||
pub event_ids: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn committed_event_headline(summary: &str) -> String {
|
||||
const MAX_HEADLINE_CHARS: usize = 96;
|
||||
let summary = summary.trim();
|
||||
if summary.chars().count() <= MAX_HEADLINE_CHARS {
|
||||
return summary.to_owned();
|
||||
}
|
||||
let mut headline = summary.chars().take(MAX_HEADLINE_CHARS).collect::<String>();
|
||||
let semantic_cut = headline
|
||||
.rfind(|character: char| matches!(character, ';' | ':' | ',' | '—'))
|
||||
.filter(|cut| *cut >= MAX_HEADLINE_CHARS / 2);
|
||||
let word_cut = headline
|
||||
.rfind(char::is_whitespace)
|
||||
.filter(|cut| *cut >= MAX_HEADLINE_CHARS / 2);
|
||||
if let Some(cut) = semantic_cut.or(word_cut) {
|
||||
headline.truncate(cut);
|
||||
}
|
||||
headline = headline
|
||||
.trim_end_matches(|character: char| character.is_whitespace() || character == '.')
|
||||
.to_owned();
|
||||
headline.push('…');
|
||||
headline
|
||||
}
|
||||
|
||||
pub fn compose_world_newspaper(
|
||||
campaign: &Campaign,
|
||||
title: impl Into<String>,
|
||||
|
|
@ -197,13 +174,13 @@ mod tests {
|
|||
fn newspaper_is_a_projection_of_public_committed_events() {
|
||||
let mut campaign = crate::kernel::tests::campaign();
|
||||
campaign.revision = 3;
|
||||
let summary = "The Thorn Court admits its royal seal was pawned to pay a dragon's gambling debt, then dismisses the treasurer who carried the confession into open court."
|
||||
.to_string();
|
||||
campaign.events.push(Event {
|
||||
id: "event:seal-scandal".into(),
|
||||
at: campaign.world_time,
|
||||
kind: "institution_action".into(),
|
||||
summary:
|
||||
"The Thorn Court admits its royal seal was pawned to pay a dragon's gambling debt."
|
||||
.into(),
|
||||
summary: summary.clone(),
|
||||
actor_ids: vec![],
|
||||
institution_ids: vec![],
|
||||
gestalt_ids: vec![],
|
||||
|
|
@ -214,7 +191,7 @@ mod tests {
|
|||
id: "news:seal-scandal".into(),
|
||||
at: campaign.world_time,
|
||||
channel: "court broadsheet".into(),
|
||||
headline: "CROWN SEAL PAWNED; DRAGON REFUSES COMMENT".into(),
|
||||
headline: crate::domain::committed_news_headline(&summary),
|
||||
event_ids: vec!["event:seal-scandal".into()],
|
||||
reliability: "committed public channel".into(),
|
||||
});
|
||||
|
|
@ -222,8 +199,13 @@ mod tests {
|
|||
let issue = compose_world_newspaper(&campaign, "The Underdeep Clarion", 8).unwrap();
|
||||
let markdown = render_world_newspaper_markdown(&issue);
|
||||
assert_eq!(issue.articles[0].event_ids, ["event:seal-scandal"]);
|
||||
assert!(markdown.contains("CROWN SEAL PAWNED"));
|
||||
assert!(markdown.contains("dragon's gambling debt"));
|
||||
assert_eq!(
|
||||
issue.articles[0].headline,
|
||||
crate::domain::committed_news_headline(&summary)
|
||||
);
|
||||
assert_ne!(issue.articles[0].headline, summary);
|
||||
assert_eq!(issue.articles[0].body, summary);
|
||||
assert!(markdown.contains("dismisses the treasurer"));
|
||||
assert!(markdown.contains("event:seal-scandal"));
|
||||
}
|
||||
|
||||
|
|
@ -241,18 +223,4 @@ mod tests {
|
|||
let error = compose_world_newspaper(&campaign, "The Clarion", 8).unwrap_err();
|
||||
assert!(error.to_string().contains("unknown event"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn committed_event_headline_is_a_bounded_prefix_not_a_second_story() {
|
||||
let summary = "The Mossglass Regency opens the rain-seal reliquary before the full assembly, admits that the seal is missing, and accuses three caravan clerks who disappeared before dawn.";
|
||||
let headline = committed_event_headline(summary);
|
||||
assert!(summary.starts_with(headline.trim_end_matches('…')));
|
||||
assert!(headline.ends_with('…'));
|
||||
assert!(headline.chars().count() <= 97);
|
||||
assert_ne!(headline, summary);
|
||||
assert_eq!(
|
||||
committed_event_headline("The seal is gone."),
|
||||
"The seal is gone."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue