Bind titled verification to its owned civic context
This commit is contained in:
parent
a0bad62f6a
commit
975ee46139
3 changed files with 205 additions and 72 deletions
|
|
@ -185,53 +185,55 @@ async fn main() -> anyhow::Result<()> {
|
|||
"updated_at":Utc::now(),
|
||||
}))?,
|
||||
)?;
|
||||
let request = strategic_locality_request(&location_name, location_id, &pressure);
|
||||
let compilation = compiler
|
||||
.compile_destination(&campaign, location_id, &request)
|
||||
.await;
|
||||
let (preview, receipts) = match compilation {
|
||||
Ok(compilation) => compilation,
|
||||
Err(error) => {
|
||||
let failure_receipts = error
|
||||
.downcast_ref::<DestinationCompilationFailure>()
|
||||
.map(|failure| failure.model_receipts.clone())
|
||||
.unwrap_or_default();
|
||||
let receipt_hashes = failure_receipts
|
||||
.iter()
|
||||
.map(|receipt| receipt.storage_key().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
let persistence_error = if failure_receipts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
store
|
||||
.persist_model_stage_receipts(&failure_receipts)
|
||||
.err()
|
||||
.map(|error| error.to_string())
|
||||
};
|
||||
std::fs::write(
|
||||
root.join(format!(
|
||||
"elaboration-{:02}-terminal-failure.json",
|
||||
index + 1
|
||||
)),
|
||||
serde_json::to_vec_pretty(&serde_json::json!({
|
||||
"schema":"ghostlight.strategic_elaboration_failure.v1",
|
||||
"location_id":location_id,
|
||||
"location_name":location_name,
|
||||
"request":request,
|
||||
"error":error.to_string(),
|
||||
"model_receipt_hashes":receipt_hashes,
|
||||
"receipt_persistence_error":&persistence_error,
|
||||
}))?,
|
||||
)?;
|
||||
if let Some(persistence_error) = persistence_error {
|
||||
return Err(anyhow::anyhow!(
|
||||
"{error}; model-receipt persistence failed: {persistence_error}"
|
||||
));
|
||||
let (elaborated, preview_path, receipts) = {
|
||||
let foundation_request =
|
||||
strategic_locality_request(&location_name, location_id, &pressure);
|
||||
let compilation = compiler
|
||||
.compile_destination(&campaign, location_id, &foundation_request)
|
||||
.await;
|
||||
let (preview, receipts) = match compilation {
|
||||
Ok(compilation) => compilation,
|
||||
Err(error) => {
|
||||
let failure_receipts = error
|
||||
.downcast_ref::<DestinationCompilationFailure>()
|
||||
.map(|failure| failure.model_receipts.clone())
|
||||
.unwrap_or_default();
|
||||
let receipt_hashes = failure_receipts
|
||||
.iter()
|
||||
.map(|receipt| receipt.storage_key().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
let persistence_error = if failure_receipts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
store
|
||||
.persist_model_stage_receipts(&failure_receipts)
|
||||
.err()
|
||||
.map(|error| error.to_string())
|
||||
};
|
||||
std::fs::write(
|
||||
root.join(format!(
|
||||
"elaboration-{:02}-terminal-failure.json",
|
||||
index + 1
|
||||
)),
|
||||
serde_json::to_vec_pretty(&serde_json::json!({
|
||||
"schema":"ghostlight.strategic_elaboration_failure.v1",
|
||||
"location_id":location_id,
|
||||
"location_name":location_name,
|
||||
"request":foundation_request,
|
||||
"error":error.to_string(),
|
||||
"model_receipt_hashes":receipt_hashes,
|
||||
"receipt_persistence_error":&persistence_error,
|
||||
}))?,
|
||||
)?;
|
||||
if let Some(persistence_error) = persistence_error {
|
||||
return Err(anyhow::anyhow!(
|
||||
"{error}; model-receipt persistence failed: {persistence_error}"
|
||||
));
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
};
|
||||
let command = match &preview {
|
||||
};
|
||||
let command = match &preview {
|
||||
ghostlight_dungeon::domain::DestinationCompilationPreview::LocalityElaboration(
|
||||
preview,
|
||||
) => WorldCommand::ElaborateLocality {
|
||||
|
|
@ -247,24 +249,26 @@ async fn main() -> anyhow::Result<()> {
|
|||
)
|
||||
}
|
||||
};
|
||||
let preview_path = root.join(format!("elaboration-{:02}-preview.json", index + 1));
|
||||
std::fs::write(
|
||||
&preview_path,
|
||||
serde_json::to_vec_pretty(&serde_json::json!({
|
||||
"location_id":location_id,
|
||||
"location_name":location_name,
|
||||
"request":request,
|
||||
"preview":&preview,
|
||||
"model_receipts":&receipts,
|
||||
}))?,
|
||||
)?;
|
||||
let committed = kernel.command(command).await?;
|
||||
let CommandResult::Committed {
|
||||
campaign: elaborated,
|
||||
..
|
||||
} = committed
|
||||
else {
|
||||
anyhow::bail!("strategic locality elaboration did not commit")
|
||||
let preview_path = root.join(format!("elaboration-{:02}-preview.json", index + 1));
|
||||
std::fs::write(
|
||||
&preview_path,
|
||||
serde_json::to_vec_pretty(&serde_json::json!({
|
||||
"location_id":location_id,
|
||||
"location_name":location_name,
|
||||
"request":foundation_request,
|
||||
"preview":&preview,
|
||||
"model_receipts":&receipts,
|
||||
}))?,
|
||||
)?;
|
||||
let committed = kernel.command(command).await?;
|
||||
let CommandResult::Committed {
|
||||
campaign: elaborated,
|
||||
..
|
||||
} = committed
|
||||
else {
|
||||
anyhow::bail!("strategic locality elaboration did not commit")
|
||||
};
|
||||
(elaborated, preview_path, receipts)
|
||||
};
|
||||
campaign = elaborated;
|
||||
let titled_wave = world_elaboration_wave_binding(&campaign, location_id)?;
|
||||
|
|
@ -272,9 +276,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
model.clone(),
|
||||
Arc::new(campaign.clone()),
|
||||
location_id.clone(),
|
||||
format!(
|
||||
"{request}\nAfter the civic foundation, add independently authored texture, material pressure, ordinary life, political leverage, secrets, active instability, and numinous meaning without rewriting the admitted apparatus."
|
||||
),
|
||||
strategic_titled_locality_request(&location_name, location_id, &pressure),
|
||||
)?);
|
||||
let titled_run = match dispatch_elaboration_wave(
|
||||
&mut titled_scheduler,
|
||||
|
|
@ -282,7 +284,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
&titled_eligible,
|
||||
titled_invocation_budget,
|
||||
titled_parallelism,
|
||||
titled_worker,
|
||||
titled_worker.clone(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
|
@ -313,7 +315,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
"schema":"ghostlight.titled_elaboration_failure.v1",
|
||||
"location_id":location_id,
|
||||
"location_name":location_name,
|
||||
"request":request,
|
||||
"request":titled_worker.task_request(),
|
||||
"wave":failure.wave,
|
||||
"schedule":failure.schedule,
|
||||
"completed_invocations":failure.completed_invocations.iter().map(|invocation|serde_json::json!({
|
||||
|
|
@ -350,7 +352,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
"schema":"ghostlight.titled_elaboration_preview.v1",
|
||||
"location_id":location_id,
|
||||
"location_name":location_name,
|
||||
"request":request,
|
||||
"request":titled_worker.task_request(),
|
||||
"wave":admission.wave(),
|
||||
"schedule":admission.schedule(),
|
||||
"accepted_operations":admission.accepted_operations(),
|
||||
|
|
@ -377,7 +379,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let verifier_receipt = match compiler
|
||||
.verify_titled_locality_elaboration(
|
||||
&campaign,
|
||||
&request,
|
||||
titled_worker.task_request(),
|
||||
description,
|
||||
candidate,
|
||||
&causal_receipt_ids,
|
||||
|
|
@ -933,6 +935,18 @@ fn strategic_locality_request(location_name: &str, location_id: &str, pressure:
|
|||
request.chars().take(500).collect()
|
||||
}
|
||||
|
||||
fn strategic_titled_locality_request(
|
||||
location_name: &str,
|
||||
location_id: &str,
|
||||
pressure: &str,
|
||||
) -> String {
|
||||
let pressure = pressure.chars().take(60).collect::<String>();
|
||||
let request = format!(
|
||||
"Deepen canonical locality {location_name:?} (ID {location_id}) after its civic foundation has been admitted. Current pressure: {pressure}. Add independently authored texture, material pressure, ordinary life, political leverage, secrets, active instability, and numinous meaning without rewriting the admitted apparatus."
|
||||
);
|
||||
request.chars().take(500).collect()
|
||||
}
|
||||
|
||||
fn strategic_world_elaboration_profile() -> ghostlight_dungeon::elaboration::WorldElaborationProfile
|
||||
{
|
||||
use ghostlight_dungeon::elaboration::{
|
||||
|
|
@ -1218,6 +1232,7 @@ fn strategic_campaign() -> ghostlight_dungeon::domain::Campaign {
|
|||
mod tests {
|
||||
use super::{
|
||||
admitted_public_channel, final_wave_field, strategic_campaign, strategic_locality_request,
|
||||
strategic_titled_locality_request,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
|
@ -1260,6 +1275,23 @@ mod tests {
|
|||
assert!(request.chars().count() <= 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn titled_elaboration_request_owns_only_the_additive_pass() {
|
||||
let request = strategic_titled_locality_request(
|
||||
"Seed Vault",
|
||||
"loc-seed-vault",
|
||||
&"an intricately witnessed constitutional crisis ".repeat(40),
|
||||
);
|
||||
|
||||
assert!(request.contains("Seed Vault"));
|
||||
assert!(request.contains("loc-seed-vault"));
|
||||
assert!(request.contains("after its civic foundation has been admitted"));
|
||||
assert!(request.contains("ordinary life, political leverage, secrets"));
|
||||
assert!(!request.contains("exactly four"));
|
||||
assert!(!request.contains("exactly six"));
|
||||
assert!(request.chars().count() <= 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn static_fixture_obeys_the_same_channel_and_knowledge_invariant() {
|
||||
let campaign = strategic_campaign();
|
||||
|
|
|
|||
|
|
@ -4717,18 +4717,39 @@ fn normalized_contains(document: &str, excerpt: &str) -> bool {
|
|||
|
||||
fn civic_context(campaign: &Campaign, location_id: &str) -> Option<serde_json::Value> {
|
||||
campaign.civic_systems.get(location_id).map(|system| {
|
||||
let political_relations = system.political_relation_ids.iter()
|
||||
.filter_map(|id|campaign.agency_relations.get(id))
|
||||
.collect::<Vec<_>>();
|
||||
let relation_subject_ids = political_relations.iter()
|
||||
.flat_map(|relation| [&relation.from_subject_id, &relation.to_subject_id])
|
||||
.collect::<BTreeSet<_>>();
|
||||
let related_institution_ids = relation_subject_ids.iter().copied()
|
||||
.filter(|id|campaign.institutions.contains_key(*id) && !system.governing_institution_ids.contains(*id))
|
||||
.collect::<BTreeSet<_>>();
|
||||
let related_population_ids = relation_subject_ids.iter().copied()
|
||||
.filter(|id|campaign.gestalts.contains_key(*id) && !system.resident_population_ids.contains(*id))
|
||||
.collect::<BTreeSet<_>>();
|
||||
let actor_ids = relation_subject_ids.iter().copied()
|
||||
.filter(|id|campaign.actors.contains_key(*id))
|
||||
.collect::<BTreeSet<_>>();
|
||||
serde_json::json!({
|
||||
"manifest":system,
|
||||
"institutions":system.governing_institution_ids.iter().filter_map(|id|campaign.institutions.get(id)).collect::<Vec<_>>(),
|
||||
"institution_profiles":system.governing_institution_ids.iter().filter_map(|id|campaign.agency_profiles.get(id)).collect::<Vec<_>>(),
|
||||
"related_institutions":related_institution_ids.iter().filter_map(|id|campaign.institutions.get(*id)).collect::<Vec<_>>(),
|
||||
"related_institution_profiles":related_institution_ids.iter().filter_map(|id|campaign.agency_profiles.get(*id)).collect::<Vec<_>>(),
|
||||
"residents":system.resident_population_ids.iter().filter_map(|id|campaign.gestalts.get(id)).collect::<Vec<_>>(),
|
||||
"resident_profiles":system.resident_population_ids.iter().filter_map(|id|campaign.agency_profiles.get(id)).collect::<Vec<_>>(),
|
||||
"related_populations":related_population_ids.iter().filter_map(|id|campaign.gestalts.get(*id)).collect::<Vec<_>>(),
|
||||
"related_population_profiles":related_population_ids.iter().filter_map(|id|campaign.agency_profiles.get(*id)).collect::<Vec<_>>(),
|
||||
"named_people":actor_ids.iter().filter_map(|id|campaign.actors.get(*id)).collect::<Vec<_>>(),
|
||||
"named_person_profiles":actor_ids.iter().filter_map(|id|campaign.agency_profiles.get(*id)).collect::<Vec<_>>(),
|
||||
"public_facts":system.public_authority_fact_ids.iter()
|
||||
.chain(system.public_selection_fact_ids.iter())
|
||||
.chain(system.public_resource_fact_ids.iter())
|
||||
.chain(system.public_redress_fact_ids.iter())
|
||||
.filter_map(|id|campaign.facts.get(id)).collect::<Vec<_>>(),
|
||||
"political_relations":system.political_relation_ids.iter().filter_map(|id|campaign.agency_relations.get(id)).collect::<Vec<_>>(),
|
||||
"political_relations":political_relations,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -6820,6 +6841,78 @@ mod tests {
|
|||
assert!(projection.get("shared_knowledge").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn civic_context_includes_non_governing_institution_relation_endpoints() {
|
||||
let mut campaign = harrow_campaign();
|
||||
for (id, name) in [
|
||||
("harrow-assembly", "Harrow Assembly"),
|
||||
("harrow-gauge-commission", "Harrow Gauge Commission"),
|
||||
] {
|
||||
campaign.institutions.insert(
|
||||
id.into(),
|
||||
crate::domain::InstitutionState {
|
||||
id: id.into(),
|
||||
name: name.into(),
|
||||
resources: vec!["public records".into()],
|
||||
goals: vec!["govern the station".into()],
|
||||
posture: "openly disputing the current works schedule".into(),
|
||||
},
|
||||
);
|
||||
}
|
||||
campaign.agency_relations.insert(
|
||||
"relation:commission-assembly".into(),
|
||||
crate::domain::AgencyRelation {
|
||||
schema: "ghostlight.agency_relation.v1".into(),
|
||||
id: "relation:commission-assembly".into(),
|
||||
from_subject_id: "harrow-gauge-commission".into(),
|
||||
to_subject_id: "harrow-assembly".into(),
|
||||
kind: AgencyRelationKind::Rivalry,
|
||||
strength: 72,
|
||||
active: true,
|
||||
evidence_receipt_ids: vec![],
|
||||
},
|
||||
);
|
||||
campaign.civic_systems.insert(
|
||||
"loc:harrow_station".into(),
|
||||
CivicSystemManifest {
|
||||
schema: "ghostlight.civic_system_manifest.v1".into(),
|
||||
version: 0,
|
||||
jurisdiction_location_id: "loc:harrow_station".into(),
|
||||
governing_institution_ids: BTreeSet::from(["harrow-assembly".into()]),
|
||||
resident_population_ids: BTreeSet::new(),
|
||||
public_authority_fact_ids: BTreeSet::new(),
|
||||
public_selection_fact_ids: BTreeSet::new(),
|
||||
public_resource_fact_ids: BTreeSet::new(),
|
||||
public_redress_fact_ids: BTreeSet::new(),
|
||||
political_relation_ids: BTreeSet::from(["relation:commission-assembly".into()]),
|
||||
semantic_verification_receipt_id: "receipt:test".into(),
|
||||
},
|
||||
);
|
||||
|
||||
let context = civic_context(&campaign, "loc:harrow_station").unwrap();
|
||||
let governing_institution_ids = context["institutions"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|institution| institution["id"].as_str().unwrap())
|
||||
.collect::<BTreeSet<_>>();
|
||||
let related_institution_ids = context["related_institutions"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|institution| institution["id"].as_str().unwrap())
|
||||
.collect::<BTreeSet<_>>();
|
||||
|
||||
assert_eq!(
|
||||
governing_institution_ids,
|
||||
BTreeSet::from(["harrow-assembly"])
|
||||
);
|
||||
assert_eq!(
|
||||
related_institution_ids,
|
||||
BTreeSet::from(["harrow-gauge-commission"])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compiler_responses_schemas_preserve_dynamic_semantics_as_records() {
|
||||
let mut schema = serde_json::to_value(schema_for!(CompiledSeed)).unwrap();
|
||||
|
|
|
|||
|
|
@ -621,6 +621,13 @@ impl ModelWorldElaborationWorker {
|
|||
})
|
||||
}
|
||||
|
||||
/// The exact semantic task shared by the worker wave, its artifacts, and
|
||||
/// the independent verifier. Callers should read this value from the
|
||||
/// prepared worker instead of retaining a second request owner.
|
||||
pub fn task_request(&self) -> &str {
|
||||
&self.request
|
||||
}
|
||||
|
||||
fn projection(&self) -> Result<String> {
|
||||
let civic = &self.campaign.civic_systems[&self.target_location_id];
|
||||
let subject_ids = civic
|
||||
|
|
@ -2205,6 +2212,7 @@ mod tests {
|
|||
"add texture",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(worker.task_request(), "add texture");
|
||||
let mut current = frozen;
|
||||
current.revision = 1;
|
||||
let invocation = ElaborationSubAgentInvocation {
|
||||
|
|
|
|||
Loading…
Reference in a new issue