Remove dead legacy kernel ingresses
This commit is contained in:
parent
3856c4ad71
commit
12ee9f4622
4 changed files with 2 additions and 686 deletions
|
|
@ -3718,7 +3718,7 @@ pub struct WorldElaborationAdmission {
|
|||
digest: String,
|
||||
}
|
||||
|
||||
/// The only elaboration value accepted by `WorldKernel::commit_elaboration`.
|
||||
/// A finalized elaboration value ready to lower through the owning world command path.
|
||||
/// It binds the immutable admission result to an independently generated
|
||||
/// semantic-verifier receipt without letting that verifier rewrite the draft.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
|
|
@ -4215,43 +4215,6 @@ impl FinalizedWorldElaboration {
|
|||
pub fn semantic_verifier_receipt(&self) -> &crate::model::ModelStageReceipt {
|
||||
&self.semantic_verifier_receipt
|
||||
}
|
||||
|
||||
pub(crate) fn into_kernel_parts(
|
||||
self,
|
||||
campaign: &crate::domain::Campaign,
|
||||
) -> Result<(
|
||||
u64,
|
||||
crate::domain::LocalityElaboration,
|
||||
Vec<crate::model::ModelStageReceipt>,
|
||||
)> {
|
||||
if self.schema != "ghostlight.finalized_world_elaboration.v1"
|
||||
|| self.digest != finalized_world_elaboration_digest(&self)?
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"finalized world elaboration is malformed or tampered"
|
||||
));
|
||||
}
|
||||
validate_semantic_verifier_ancestry(&self.admission, &self.semantic_verifier_receipt)?;
|
||||
let mut elaboration = self.admission.valid_candidate(campaign)?;
|
||||
elaboration
|
||||
.expansion
|
||||
.civic_system
|
||||
.as_mut()
|
||||
.expect("valid locality elaboration has a civic system")
|
||||
.semantic_verification_receipt_id = self.semantic_verifier_receipt.storage_key().into();
|
||||
crate::compiler::validate_civic_admission_receipts(
|
||||
campaign,
|
||||
&elaboration.expansion,
|
||||
std::slice::from_ref(&self.semantic_verifier_receipt),
|
||||
)?;
|
||||
let mut model_stage_receipts = self.admission.model_stage_receipts.clone();
|
||||
model_stage_receipts.push(self.semantic_verifier_receipt);
|
||||
Ok((
|
||||
self.admission.expected_revision,
|
||||
elaboration,
|
||||
model_stage_receipts,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn operation_claims(operation: &WorldElaborationOperation) -> Result<Vec<String>> {
|
||||
|
|
|
|||
|
|
@ -75,11 +75,6 @@ pub enum CommandResult {
|
|||
|
||||
enum KernelInput {
|
||||
World(WorldCommand),
|
||||
Elaboration(crate::elaboration::FinalizedWorldElaboration),
|
||||
Mutation {
|
||||
authority: crate::transition::MutationAuthorityEnvelope,
|
||||
batch: crate::transition::WorldMutationBatch,
|
||||
},
|
||||
}
|
||||
|
||||
struct Request {
|
||||
|
|
@ -112,12 +107,6 @@ impl WorldKernel {
|
|||
while let Some(request) = rx.recv().await {
|
||||
let result = match request.input {
|
||||
KernelInput::World(command) => execute(&store, &mut assessments, command),
|
||||
KernelInput::Elaboration(finalized) => {
|
||||
execute_finalized_elaboration(&store, &mut assessments, finalized)
|
||||
}
|
||||
KernelInput::Mutation { authority, batch } => {
|
||||
execute_mutation_batch(&store, authority, batch)
|
||||
}
|
||||
};
|
||||
let _ = request.reply.send(result);
|
||||
}
|
||||
|
|
@ -137,104 +126,6 @@ impl WorldKernel {
|
|||
.await
|
||||
.map_err(|_| KernelError::Invalid("kernel stopped".into()))?
|
||||
}
|
||||
|
||||
pub async fn commit_mutation_batch(
|
||||
&self,
|
||||
authority: crate::transition::MutationAuthorityEnvelope,
|
||||
batch: crate::transition::WorldMutationBatch,
|
||||
) -> Result<CommandResult, KernelError> {
|
||||
let (reply, receive) = oneshot::channel();
|
||||
self.tx
|
||||
.send(Request {
|
||||
input: KernelInput::Mutation { authority, batch },
|
||||
reply,
|
||||
})
|
||||
.await
|
||||
.map_err(|_| KernelError::Invalid("kernel stopped".into()))?;
|
||||
receive
|
||||
.await
|
||||
.map_err(|_| KernelError::Invalid("kernel stopped".into()))?
|
||||
}
|
||||
|
||||
pub async fn commit_elaboration(
|
||||
&self,
|
||||
finalized: crate::elaboration::FinalizedWorldElaboration,
|
||||
) -> Result<CommandResult, KernelError> {
|
||||
let (reply, receive) = oneshot::channel();
|
||||
self.tx
|
||||
.send(Request {
|
||||
input: KernelInput::Elaboration(finalized),
|
||||
reply,
|
||||
})
|
||||
.await
|
||||
.map_err(|_| KernelError::Invalid("kernel stopped".into()))?;
|
||||
receive
|
||||
.await
|
||||
.map_err(|_| KernelError::Invalid("kernel stopped".into()))?
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_finalized_elaboration(
|
||||
store: &CampaignStore,
|
||||
assessments: &mut BTreeMap<String, ActionAssessment>,
|
||||
finalized: crate::elaboration::FinalizedWorldElaboration,
|
||||
) -> Result<CommandResult, KernelError> {
|
||||
let campaign_id = single_campaign_id(store)?;
|
||||
let (_, campaign): (_, Campaign) = store
|
||||
.load("campaign.v1", &campaign_id)
|
||||
.map_err(persist)?
|
||||
.ok_or(KernelError::NotFound)?;
|
||||
let (expected_revision, elaboration, model_stage_receipts) = finalized
|
||||
.into_kernel_parts(&campaign)
|
||||
.map_err(|error| KernelError::Invalid(error.to_string()))?;
|
||||
execute(
|
||||
store,
|
||||
assessments,
|
||||
WorldCommand::ElaborateLocality {
|
||||
expected_revision,
|
||||
elaboration,
|
||||
evidence_receipts: Vec::new(),
|
||||
canon_candidates: Vec::new(),
|
||||
model_stage_receipts,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn execute_mutation_batch(
|
||||
store: &CampaignStore,
|
||||
authority: crate::transition::MutationAuthorityEnvelope,
|
||||
batch: crate::transition::WorldMutationBatch,
|
||||
) -> Result<CommandResult, KernelError> {
|
||||
let key = batch.campaign_id.to_string();
|
||||
if store
|
||||
.load::<Campaign>("campaign.v1", &key)
|
||||
.map_err(persist)?
|
||||
.is_some()
|
||||
{
|
||||
return Err(KernelError::Invalid(
|
||||
"aggregate campaigns accept mutations only through their WorldCommand mailbox".into(),
|
||||
));
|
||||
}
|
||||
let (row, state) = store
|
||||
.load::<crate::transition::ComponentWorldState>("component_world_state.v1", &key)
|
||||
.map_err(persist)?
|
||||
.ok_or(KernelError::NotFound)?;
|
||||
let application =
|
||||
crate::transition::apply_component_world_batch(&state, &authority, &batch, Utc::now())
|
||||
.map_err(|error| KernelError::Invalid(error.to_string()))?;
|
||||
store
|
||||
.commit_world_mutation_batch(
|
||||
&row,
|
||||
&application.state,
|
||||
&authority,
|
||||
&batch,
|
||||
&application.receipt,
|
||||
)
|
||||
.map_err(persist)?;
|
||||
Ok(CommandResult::MutationCommitted {
|
||||
state: application.state,
|
||||
receipt: application.receipt,
|
||||
})
|
||||
}
|
||||
|
||||
fn execute(
|
||||
|
|
@ -5029,110 +4920,6 @@ pub(crate) mod tests {
|
|||
receipt
|
||||
}
|
||||
|
||||
fn titled_operations_for(
|
||||
elaboration: &LocalityElaboration,
|
||||
) -> Vec<(
|
||||
crate::elaboration::ElaboratorTitle,
|
||||
crate::elaboration::WorldElaborationOperation,
|
||||
)> {
|
||||
use crate::elaboration::{ElaboratorTitle::*, WorldElaborationOperation::*};
|
||||
let expansion = &elaboration.expansion;
|
||||
let mut operations = Vec::new();
|
||||
for location in &expansion.locations {
|
||||
operations.push((
|
||||
Patina,
|
||||
AddPlace {
|
||||
id: location.id.clone(),
|
||||
name: location.name.clone(),
|
||||
container_id: location.container_id.clone(),
|
||||
persistent_features: location.persistent_features.clone(),
|
||||
},
|
||||
));
|
||||
operations.extend(location.routes.iter().map(|(route_id, route)| {
|
||||
(
|
||||
Ledger,
|
||||
AddRoute {
|
||||
origin_location_id: location.id.clone(),
|
||||
route_id: route_id.clone(),
|
||||
route: route.clone(),
|
||||
},
|
||||
)
|
||||
}));
|
||||
}
|
||||
operations.extend(expansion.origin_routes.iter().map(|(route_id, route)| {
|
||||
(
|
||||
Ledger,
|
||||
AddRoute {
|
||||
origin_location_id: expansion.origin_location_id.clone(),
|
||||
route_id: route_id.clone(),
|
||||
route: route.clone(),
|
||||
},
|
||||
)
|
||||
}));
|
||||
operations.extend(
|
||||
expansion
|
||||
.facts
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|fact| (Charter, AddFact { fact })),
|
||||
);
|
||||
operations.extend(
|
||||
expansion
|
||||
.populations
|
||||
.iter()
|
||||
.cloned()
|
||||
.zip(expansion.population_profiles.iter().cloned())
|
||||
.map(|(population, profile)| {
|
||||
(
|
||||
Hearth,
|
||||
AddPopulation {
|
||||
population,
|
||||
profile,
|
||||
},
|
||||
)
|
||||
}),
|
||||
);
|
||||
operations.extend(
|
||||
expansion
|
||||
.institutions
|
||||
.iter()
|
||||
.cloned()
|
||||
.zip(expansion.institution_profiles.iter().cloned())
|
||||
.map(|(institution, profile)| {
|
||||
(
|
||||
Charter,
|
||||
AddInstitution {
|
||||
institution,
|
||||
profile,
|
||||
},
|
||||
)
|
||||
}),
|
||||
);
|
||||
operations.extend(
|
||||
expansion
|
||||
.migration_relations
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|relation| (Hearth, AddMigrationRelation { relation })),
|
||||
);
|
||||
operations.extend(
|
||||
expansion
|
||||
.local_relations
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|relation| (Tangle, AddLocalRelation { relation })),
|
||||
);
|
||||
if let Some(system) = &expansion.civic_system {
|
||||
operations.push((
|
||||
Charter,
|
||||
SetCivicSystem {
|
||||
system: system.clone(),
|
||||
},
|
||||
));
|
||||
}
|
||||
operations
|
||||
}
|
||||
|
||||
struct FixtureWorldElaborationSubAgent {
|
||||
operations: BTreeMap<
|
||||
crate::elaboration::ElaboratorTitle,
|
||||
|
|
@ -5621,161 +5408,6 @@ pub(crate) mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mailbox_commits_one_authorized_component_mutation_batch_atomically() {
|
||||
use crate::transition::*;
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = CampaignStore::open(dir.path().join("campaign.cc")).unwrap();
|
||||
let campaign_id = uuid::Uuid::new_v4();
|
||||
let campaign_subject = SubjectRef {
|
||||
kind: SubjectKind::Campaign,
|
||||
id: campaign_id.to_string(),
|
||||
};
|
||||
let state = ComponentWorldState {
|
||||
schema: "ghostlight.component_world_state.v1".into(),
|
||||
campaign_id,
|
||||
revision: 7,
|
||||
resolution_epoch: 3,
|
||||
world_time: Utc::now(),
|
||||
subjects: BTreeMap::from([(
|
||||
campaign_subject.clone(),
|
||||
TypedSubject {
|
||||
schema: "ghostlight.typed_subject.v1".into(),
|
||||
subject: campaign_subject.clone(),
|
||||
lifecycle: LifecycleStatus::Active,
|
||||
admitted_components: BTreeSet::from([WorldComponentKind::WorldTime]),
|
||||
version: 7,
|
||||
},
|
||||
)]),
|
||||
occupancy: BTreeMap::new(),
|
||||
custody: BTreeMap::new(),
|
||||
resources: BTreeMap::new(),
|
||||
capabilities: BTreeMap::new(),
|
||||
conditions: BTreeMap::new(),
|
||||
commitments: BTreeMap::new(),
|
||||
relationships: BTreeMap::new(),
|
||||
pressures: BTreeMap::new(),
|
||||
knowledge: BTreeMap::new(),
|
||||
memories: BTreeMap::new(),
|
||||
postures: BTreeMap::new(),
|
||||
memberships: BTreeMap::new(),
|
||||
population_lineages: BTreeMap::new(),
|
||||
identities: BTreeMap::new(),
|
||||
place_profiles: BTreeMap::new(),
|
||||
propositions: BTreeMap::new(),
|
||||
topology: BTreeMap::new(),
|
||||
civic_systems: BTreeMap::new(),
|
||||
};
|
||||
let initial_world_time = state.world_time;
|
||||
store.create_component_world_state(&state).unwrap();
|
||||
|
||||
let permit = MutationPermit {
|
||||
id: "permit:time".into(),
|
||||
operation: WorldMutationOperation::AdvanceWorldTime,
|
||||
subject_bindings: vec![MutationSubjectBinding {
|
||||
role: MutationSubjectRole::Subject,
|
||||
allowed_subjects: BTreeSet::from([campaign_subject.clone()]),
|
||||
}],
|
||||
string_constraints: BTreeMap::new(),
|
||||
integer_bounds: BTreeMap::from([(
|
||||
MutationIntegerRole::WorldMinutes,
|
||||
IntegerBounds {
|
||||
minimum: 30,
|
||||
maximum: 30,
|
||||
},
|
||||
)]),
|
||||
exact_mutation: None,
|
||||
maximum_uses: 1,
|
||||
};
|
||||
let mut authority = MutationAuthorityEnvelope {
|
||||
schema: "ghostlight.mutation_authority_envelope.v1".into(),
|
||||
id: "authority:time".into(),
|
||||
campaign_id,
|
||||
world_revision: 7,
|
||||
resolution_epoch: Some(3),
|
||||
procedure: MutationProcedure::Governance,
|
||||
source_subject: None,
|
||||
outcome: MutationOutcomeBinding::Deterministic,
|
||||
effect_ceiling: "Thirty minutes pass; no other component changes.".into(),
|
||||
permits: vec![permit],
|
||||
authority_receipt_ids: BTreeSet::from(["governance:time".into()]),
|
||||
expires_at: Utc::now() + Duration::minutes(5),
|
||||
digest: String::new(),
|
||||
};
|
||||
authority.digest = envelope_digest(&authority).unwrap();
|
||||
let mut batch = WorldMutationBatch {
|
||||
schema: "ghostlight.world_mutation_batch.v1".into(),
|
||||
id: "batch:time".into(),
|
||||
campaign_id,
|
||||
expected_world_revision: 7,
|
||||
expected_resolution_epoch: Some(3),
|
||||
authority_envelope_digest: authority.digest.clone(),
|
||||
source_receipt_id: "governance:time".into(),
|
||||
means_digest: None,
|
||||
intended_effect_digest: None,
|
||||
mutations: vec![PermittedWorldMutation {
|
||||
permit_id: "permit:time".into(),
|
||||
mutation: WorldMutation::AdvanceWorldTime {
|
||||
campaign: campaign_subject,
|
||||
minutes: 30,
|
||||
},
|
||||
}],
|
||||
digest: String::new(),
|
||||
};
|
||||
batch.digest = mutation_batch_digest(&batch).unwrap();
|
||||
|
||||
let kernel = WorldKernel::start(store.clone());
|
||||
let committed = kernel
|
||||
.commit_mutation_batch(authority.clone(), batch.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
let CommandResult::MutationCommitted { state, receipt } = committed else {
|
||||
panic!("component mutation did not return its typed receipt");
|
||||
};
|
||||
assert_eq!(state.revision, 8);
|
||||
assert_eq!(state.world_time, initial_world_time + Duration::minutes(30));
|
||||
assert_eq!(receipt.previous_world_revision, 7);
|
||||
assert_eq!(receipt.world_revision, 8);
|
||||
assert_eq!(store.keys("world_mutation_receipt.v1").unwrap().len(), 1);
|
||||
|
||||
assert!(
|
||||
kernel
|
||||
.commit_mutation_batch(authority.clone(), batch.clone())
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let stored = store
|
||||
.load::<ComponentWorldState>("component_world_state.v1", &campaign_id.to_string())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.1;
|
||||
assert_eq!(stored.revision, 8);
|
||||
assert_eq!(store.keys("world_mutation_receipt.v1").unwrap().len(), 1);
|
||||
|
||||
let mut aggregate = campaign();
|
||||
aggregate.id = campaign_id;
|
||||
store
|
||||
.create_unadmitted_fixture_campaign(&aggregate, &[], &[])
|
||||
.unwrap();
|
||||
let error = kernel
|
||||
.commit_mutation_batch(authority, batch)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("only through their WorldCommand mailbox")
|
||||
);
|
||||
let stored = store
|
||||
.load::<ComponentWorldState>("component_world_state.v1", &campaign_id.to_string())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.1;
|
||||
assert_eq!(stored.revision, 8);
|
||||
assert_eq!(store.keys("world_mutation_receipt.v1").unwrap().len(), 1);
|
||||
}
|
||||
|
||||
fn hierarchical_refugee_campaign() -> Campaign {
|
||||
let mut value = campaign();
|
||||
value.locations.insert(
|
||||
|
|
@ -8712,139 +8344,6 @@ pub(crate) mod tests {
|
|||
assert!(admission.candidate_diagnostic().is_some());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn titled_patina_detail_reaches_canonical_state_only_through_kernel_lowering() {
|
||||
use crate::elaboration::{admit_world_elaboration_wave, finalize_world_elaboration};
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = CampaignStore::open(dir.path().join("campaign.cc")).unwrap();
|
||||
let kernel = WorldKernel::start(store.clone());
|
||||
let seed = campaign();
|
||||
let mut expected = civic_locality_elaboration();
|
||||
expected.expansion.locations[0]
|
||||
.persistent_features
|
||||
.push("A weathered bronze duck statue locals call Harold".into());
|
||||
let operations = titled_operations_for(&expected);
|
||||
let expected_model_receipt_count = operations.len() + 1;
|
||||
let run = dispatch_titled_operations(&seed, "room", operations).await;
|
||||
let admission = admit_world_elaboration_wave(&seed, "room", run).unwrap();
|
||||
assert!(admission.rejections().is_empty());
|
||||
assert_eq!(admission.candidate(), Some(&expected));
|
||||
assert!(admission.accepted_operations().iter().any(|accepted| {
|
||||
accepted.dispatch.title == crate::elaboration::ElaboratorTitle::Patina
|
||||
&& matches!(
|
||||
&accepted.operation,
|
||||
crate::elaboration::WorldElaborationOperation::AddPlace {
|
||||
persistent_features,
|
||||
..
|
||||
} if persistent_features.iter().any(|feature| feature.contains("Harold"))
|
||||
)
|
||||
}));
|
||||
let causal_receipt_ids = admission
|
||||
.model_stage_receipts()
|
||||
.iter()
|
||||
.map(|receipt| receipt.storage_key().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
let mut verifier_candidate = expected.expansion.clone();
|
||||
let missing_ancestry = civic_verifier_receipt(&seed, &mut verifier_candidate, vec![]);
|
||||
let error =
|
||||
finalize_world_elaboration(&seed, admission.clone(), missing_ancestry).unwrap_err();
|
||||
assert!(error.to_string().contains("ancestry"));
|
||||
let verifier_receipt =
|
||||
civic_verifier_receipt(&seed, &mut verifier_candidate, causal_receipt_ids);
|
||||
let finalized = finalize_world_elaboration(&seed, admission, verifier_receipt).unwrap();
|
||||
kernel
|
||||
.command(WorldCommand::CreateCampaign {
|
||||
campaign: seed,
|
||||
evidence_receipts: vec![],
|
||||
model_stage_receipts: vec![],
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = kernel.commit_elaboration(finalized).await.unwrap();
|
||||
let CommandResult::Committed { campaign, receipt } = result else {
|
||||
panic!("expected committed titled elaboration")
|
||||
};
|
||||
|
||||
assert_eq!(receipt.command_kind, "elaborate_locality");
|
||||
assert!(
|
||||
campaign.locations["civic-quarter"]
|
||||
.persistent_features
|
||||
.iter()
|
||||
.any(|feature| feature.contains("Harold"))
|
||||
);
|
||||
assert_eq!(store.keys("world_mutation_batch.v1").unwrap().len(), 1);
|
||||
assert_eq!(
|
||||
store.keys("persona_stage_receipt.v1").unwrap().len(),
|
||||
expected_model_receipt_count
|
||||
);
|
||||
let batch = store
|
||||
.load_all::<crate::transition::WorldMutationBatch>("world_mutation_batch.v1")
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap();
|
||||
assert!(batch.mutations.iter().any(|permitted| {
|
||||
matches!(
|
||||
&permitted.mutation,
|
||||
crate::transition::WorldMutation::AdmitEntity {
|
||||
initial_profile: Some(crate::transition::AdmittedEntityProfile::Place {
|
||||
persistent_features,
|
||||
..
|
||||
}),
|
||||
..
|
||||
} if persistent_features.iter().any(|feature| feature.contains("Harold"))
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stale_finalized_elaboration_cannot_reach_the_kernel_writer() {
|
||||
use crate::elaboration::{admit_world_elaboration_wave, finalize_world_elaboration};
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = CampaignStore::open(dir.path().join("campaign.cc")).unwrap();
|
||||
let kernel = WorldKernel::start(store.clone());
|
||||
let seed = campaign();
|
||||
let expected = civic_locality_elaboration();
|
||||
let run = dispatch_titled_operations(&seed, "room", titled_operations_for(&expected)).await;
|
||||
let admission = admit_world_elaboration_wave(&seed, "room", run).unwrap();
|
||||
let causal_receipt_ids = admission
|
||||
.model_stage_receipts()
|
||||
.iter()
|
||||
.map(|receipt| receipt.storage_key().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
let mut verifier_candidate = expected.expansion.clone();
|
||||
let verifier_receipt =
|
||||
civic_verifier_receipt(&seed, &mut verifier_candidate, causal_receipt_ids);
|
||||
let finalized = finalize_world_elaboration(&seed, admission, verifier_receipt).unwrap();
|
||||
kernel
|
||||
.command(WorldCommand::CreateCampaign {
|
||||
campaign: seed.clone(),
|
||||
evidence_receipts: vec![],
|
||||
model_stage_receipts: vec![],
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
kernel
|
||||
.command(WorldCommand::Wait {
|
||||
expected_revision: 0,
|
||||
minutes: 1,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let error = kernel.commit_elaboration(finalized).await.unwrap_err();
|
||||
|
||||
assert!(error.to_string().contains("stale"));
|
||||
let stored = store
|
||||
.load::<Campaign>("campaign.v1", &seed.id.to_string())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.1;
|
||||
assert_eq!(stored.revision, 1);
|
||||
assert_eq!(stored.locations.len(), 1);
|
||||
assert_eq!(store.keys("world_mutation_batch.v1").unwrap().len(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn invalid_civic_locality_leaves_the_coarse_city_untouched() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
|
|
@ -12,9 +12,7 @@ use crate::model::ModelStageReceipt;
|
|||
use crate::session_zero::{
|
||||
CellBudgetProposal, GroupTravelProposal, PublishedSessionZeroSeed, TimeAdvanceProposal,
|
||||
};
|
||||
use crate::transition::{
|
||||
ComponentWorldState, MutationAuthorityEnvelope, WorldMutationBatch, WorldMutationReceipt,
|
||||
};
|
||||
use crate::transition::{MutationAuthorityEnvelope, WorldMutationBatch, WorldMutationReceipt};
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use chrono::Utc;
|
||||
use cultcache_legacy::{CacheBackingStore, CultCacheEnvelope, OwnedRedbMessagePackBackingStore};
|
||||
|
|
@ -131,74 +129,6 @@ impl CampaignStore {
|
|||
Ok(Some(row))
|
||||
}
|
||||
|
||||
pub fn create_component_world_state(
|
||||
&self,
|
||||
state: &ComponentWorldState,
|
||||
) -> Result<CultCacheEnvelope> {
|
||||
self.insert(
|
||||
"component_world_state.v1",
|
||||
"ghostlight.component_world_state.v1",
|
||||
&state.campaign_id.to_string(),
|
||||
state,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn commit_world_mutation_batch(
|
||||
&self,
|
||||
expected: &CultCacheEnvelope,
|
||||
next: &ComponentWorldState,
|
||||
authority: &MutationAuthorityEnvelope,
|
||||
batch: &WorldMutationBatch,
|
||||
receipt: &WorldMutationReceipt,
|
||||
) -> Result<CultCacheEnvelope> {
|
||||
if expected.r#type != "component_world_state.v1"
|
||||
|| expected.key != next.campaign_id.to_string()
|
||||
|| authority.campaign_id != next.campaign_id
|
||||
|| batch.campaign_id != next.campaign_id
|
||||
|| receipt.campaign_id != next.campaign_id
|
||||
|| receipt.world_revision != next.revision
|
||||
|| receipt.previous_world_revision.saturating_add(1) != next.revision
|
||||
|| receipt.batch_digest != batch.digest
|
||||
|| receipt.authority_envelope_digest != authority.digest
|
||||
{
|
||||
return Err(anyhow!("world mutation persistence bundle is inconsistent"));
|
||||
}
|
||||
let next_row = envelope(
|
||||
"component_world_state.v1",
|
||||
"ghostlight.component_world_state.v1",
|
||||
&next.campaign_id.to_string(),
|
||||
next,
|
||||
)?;
|
||||
let rows = vec![
|
||||
next_row.clone(),
|
||||
envelope(
|
||||
"mutation_authority_envelope.v1",
|
||||
"ghostlight.mutation_authority_envelope.v1",
|
||||
&authority.id,
|
||||
authority,
|
||||
)?,
|
||||
envelope(
|
||||
"world_mutation_batch.v1",
|
||||
"ghostlight.world_mutation_batch.v1",
|
||||
&batch.id,
|
||||
batch,
|
||||
)?,
|
||||
envelope(
|
||||
"world_mutation_receipt.v1",
|
||||
"ghostlight.world_mutation_receipt.v1",
|
||||
&receipt.id,
|
||||
receipt,
|
||||
)?,
|
||||
];
|
||||
if !self
|
||||
.inner
|
||||
.compare_and_swap_batch(std::slice::from_ref(expected), rows)?
|
||||
{
|
||||
return Err(anyhow!("stale component world snapshot"));
|
||||
}
|
||||
Ok(next_row)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn create_unadmitted_fixture_campaign(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -5285,82 +5285,6 @@ mod tests {
|
|||
assert_eq!(applied.state.revision, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn component_state_batch_and_exact_proof_rows_commit_in_one_cultcache_cas() {
|
||||
let state = component_world();
|
||||
let campaign = subject(SubjectKind::Campaign, "campaign:test");
|
||||
let permit = permit(
|
||||
"permit:time",
|
||||
WorldMutationOperation::AdvanceWorldTime,
|
||||
vec![(
|
||||
MutationSubjectRole::Subject,
|
||||
BTreeSet::from([campaign.clone()]),
|
||||
)],
|
||||
vec![],
|
||||
vec![(
|
||||
MutationIntegerRole::WorldMinutes,
|
||||
IntegerBounds {
|
||||
minimum: 30,
|
||||
maximum: 30,
|
||||
},
|
||||
)],
|
||||
);
|
||||
let envelope = envelope_for(&state, vec![permit]);
|
||||
let batch = batch_for(
|
||||
&state,
|
||||
&envelope,
|
||||
vec![(
|
||||
"permit:time",
|
||||
WorldMutation::AdvanceWorldTime {
|
||||
campaign,
|
||||
minutes: 30,
|
||||
},
|
||||
)],
|
||||
);
|
||||
let applied = apply_component_world_batch(&state, &envelope, &batch, Utc::now()).unwrap();
|
||||
let path = std::env::temp_dir().join(format!(
|
||||
"ghostlight-transition-store-{}.cc",
|
||||
Uuid::new_v4().simple()
|
||||
));
|
||||
let store = crate::persistence::CampaignStore::open(&path).unwrap();
|
||||
let expected = store.create_component_world_state(&state).unwrap();
|
||||
store
|
||||
.commit_world_mutation_batch(
|
||||
&expected,
|
||||
&applied.state,
|
||||
&envelope,
|
||||
&batch,
|
||||
&applied.receipt,
|
||||
)
|
||||
.unwrap();
|
||||
let persisted = store
|
||||
.load::<ComponentWorldState>("component_world_state.v1", &state.campaign_id.to_string())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.1;
|
||||
assert_eq!(persisted, applied.state);
|
||||
assert_eq!(
|
||||
store.keys("mutation_authority_envelope.v1").unwrap().len(),
|
||||
1
|
||||
);
|
||||
assert_eq!(store.keys("world_mutation_batch.v1").unwrap().len(), 1);
|
||||
assert_eq!(store.keys("world_mutation_receipt.v1").unwrap().len(), 1);
|
||||
assert!(
|
||||
store
|
||||
.commit_world_mutation_batch(
|
||||
&expected,
|
||||
&applied.state,
|
||||
&envelope,
|
||||
&batch,
|
||||
&applied.receipt,
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(store.keys("world_mutation_receipt.v1").unwrap().len(), 1);
|
||||
drop(store);
|
||||
std::fs::remove_file(path).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn communicated_knowledge_reaches_only_exact_recipients() {
|
||||
let state = component_world();
|
||||
|
|
|
|||
Loading…
Reference in a new issue