Aetherlight AL2a.5: delete the elaborator lane, the answer gate and the scale intent
Remove SystemCapability::Elaborator, PatchAnswer, CausalBoundary and its derivation, the AnswerRequired gate (require_answer, the answers field of AdmitPatch and PatchAdmitted, the three Answer* errors), ground_covers and the jurisdiction ground, WorldScaleIntent and its refs, JurisdictionKey, the scale deficit and the subject snapshot's qualified flag. require_play_active keeps the one rule require_answer also held: Play authors nothing in Draft. The owner now declares in Active unanswered. Tests whose subject was the lane go. Kept-lane tests that used the elaborator as setup are rewritten over the owner, Play or a consumer: the import-key and grammar door tests, the capability-admission test, the ruler re-decision tests, the confined-author retire/grant/revoke tests, the orphan-claim test, and the witness-arrival test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f17a8147f8
commit
1919828a7e
6 changed files with 846 additions and 3702 deletions
|
|
@ -171,7 +171,6 @@ pub(super) fn exercise(
|
|||
operations,
|
||||
evidence: Vec::new(),
|
||||
},
|
||||
None,
|
||||
)
|
||||
.map_err(KernelError::PatchRejected)?
|
||||
.operations
|
||||
|
|
@ -2094,7 +2093,6 @@ mod tests {
|
|||
&mut draft,
|
||||
&before,
|
||||
CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch: WorldPatch {
|
||||
declarations: vec![Declaration::Affordance(AffordanceDeclaration {
|
||||
handle: handle.clone(),
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ fn admit(kernel: &mut WorldKernel, patch: WorldPatch) -> Result<SubmitReceipt, K
|
|||
CommandId::new(),
|
||||
CallerId::Principal(owner()),
|
||||
CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch,
|
||||
},
|
||||
),
|
||||
|
|
@ -487,7 +486,6 @@ fn a_grammar_names_each_verb_once_and_has_a_schema() {
|
|||
fn submit_as(
|
||||
kernel: &mut WorldKernel,
|
||||
caller: CallerId,
|
||||
answers: Option<crate::PatchAnswer>,
|
||||
patch: WorldPatch,
|
||||
) -> Result<SubmitReceipt, KernelError> {
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
|
|
@ -496,14 +494,14 @@ fn submit_as(
|
|||
&snapshot,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::AdmitPatch { answers, patch },
|
||||
CommandBody::AdmitPatch { patch },
|
||||
),
|
||||
&crate::AuthenticatedCaller::fixture(caller),
|
||||
)
|
||||
}
|
||||
|
||||
/// A bound Draft world whose revision has moved past genesis: one owner patch
|
||||
/// that adds a dead-end place the elaborator can answer.
|
||||
/// that adds a dead-end place.
|
||||
fn advanced_grammar_world() -> (tempfile::TempDir, WorldKernel, crate::EntityId) {
|
||||
let extra = [("hail", verb(RenderPath::Conversation, &[]))];
|
||||
let (dir, kernel) = create(bound(Some(grammar_with(&extra)), "Advanced"));
|
||||
|
|
@ -539,25 +537,23 @@ fn advanced_grammar_world() -> (tempfile::TempDir, WorldKernel, crate::EntityId)
|
|||
(dir, kernel, dead_end)
|
||||
}
|
||||
|
||||
type Door = (&'static str, CallerId, Option<crate::PatchAnswer>);
|
||||
type Door = (&'static str, CallerId);
|
||||
|
||||
/// Each door refuses an outside kind and a wrong role signature, typed, and the
|
||||
/// refusal leaves the revision where it was. The owner and the consumer declare
|
||||
/// unanswered only in Draft; Play and the elaborator act in Active.
|
||||
/// in Draft and in Active; Play acts in Active.
|
||||
fn refuse_at_each_door(kernel: &mut WorldKernel, doors: Vec<Door>) {
|
||||
for (door, caller, answers) in doors {
|
||||
for (door, caller) in doors {
|
||||
let revision = kernel.state.revision;
|
||||
let kind = submit_as(
|
||||
kernel,
|
||||
caller.clone(),
|
||||
answers.clone(),
|
||||
patch_of(vec![declare("wave", "wave", &[])]),
|
||||
);
|
||||
assert_eq!(rejected(kind), not_in_grammar("wave"), "{door}");
|
||||
let roles = submit_as(
|
||||
kernel,
|
||||
caller,
|
||||
answers,
|
||||
patch_of(vec![declare("hail", "hail", &[("who", person())])]),
|
||||
);
|
||||
assert_eq!(rejected(roles), disagrees("hail"), "{door}");
|
||||
|
|
@ -570,16 +566,15 @@ fn refuse_at_each_door(kernel: &mut WorldKernel, doors: Vec<Door>) {
|
|||
|
||||
#[test]
|
||||
fn every_admission_door_refuses_outside_the_grammar_after_the_revision_has_moved() {
|
||||
let (_dir, mut kernel, dead_end) = advanced_grammar_world();
|
||||
let (_dir, mut kernel, _) = advanced_grammar_world();
|
||||
assert_eq!(kernel.state.revision, 1);
|
||||
let draft_doors = vec![
|
||||
("owner", CallerId::Principal(owner()), None),
|
||||
("owner", CallerId::Principal(owner())),
|
||||
(
|
||||
"consumer",
|
||||
CallerId::System(crate::SystemCapability::Consumer {
|
||||
consumer: crate::ConsumerId::of_name("grammar-door"),
|
||||
}),
|
||||
None,
|
||||
),
|
||||
];
|
||||
refuse_at_each_door(&mut kernel, draft_doors);
|
||||
|
|
@ -588,27 +583,9 @@ fn every_admission_door_refuses_outside_the_grammar_after_the_revision_has_moved
|
|||
kernel.state.revision > 1,
|
||||
"the world has moved past genesis"
|
||||
);
|
||||
let answer = crate::derive_boundaries(&kernel.state)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|boundary| {
|
||||
matches!(boundary, crate::CausalBoundary::UnelaboratedDestination { place, .. }
|
||||
if *place == dead_end)
|
||||
})
|
||||
.expect("the dead end is an unelaborated destination");
|
||||
let active_doors = vec![
|
||||
(
|
||||
"play",
|
||||
CallerId::System(crate::SystemCapability::Play),
|
||||
None,
|
||||
),
|
||||
(
|
||||
"elaborator",
|
||||
CallerId::System(crate::SystemCapability::Elaborator {
|
||||
jurisdiction: crate::JurisdictionKey::PlaceSubtree(dead_end),
|
||||
}),
|
||||
Some(crate::PatchAnswer::Boundary(answer)),
|
||||
),
|
||||
("owner in Active", CallerId::Principal(owner())),
|
||||
("play", CallerId::System(crate::SystemCapability::Play)),
|
||||
];
|
||||
refuse_at_each_door(&mut kernel, active_doors);
|
||||
// The same path admits what the grammar carries, so the refusals above are
|
||||
|
|
@ -616,7 +593,6 @@ fn every_admission_door_refuses_outside_the_grammar_after_the_revision_has_moved
|
|||
let receipt = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::System(crate::SystemCapability::Play),
|
||||
None,
|
||||
patch_of(vec![declare("hail", "hail", &[])]),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -682,7 +658,6 @@ fn an_effect_resolved_elsewhere_cannot_install_an_entry_outside_the_grammar() {
|
|||
&twin,
|
||||
CommandId::new(),
|
||||
&patch_of(vec![declare("probe", kind, roles)]),
|
||||
None,
|
||||
)
|
||||
.expect("the unbound twin admits any canonical kind")
|
||||
};
|
||||
|
|
@ -698,7 +673,6 @@ fn an_effect_resolved_elsewhere_cannot_install_an_entry_outside_the_grammar() {
|
|||
CommandId::new(),
|
||||
&CallerId::Principal(owner()),
|
||||
&crate::WorldEffect::PatchAdmitted {
|
||||
answers: None,
|
||||
resolved,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ use crate::patch::{
|
|||
};
|
||||
use crate::tests::{activate, auth_principal, command, creation, owner};
|
||||
use crate::{
|
||||
CallerId, CommandBody, CommandId, ConsumerId, CreateWorld, EntityId, JurisdictionKey,
|
||||
KernelError, NewController, PatchAnswer, SubjectDeclaration, SubjectKind, SubmitReceipt,
|
||||
CallerId, CommandBody, CommandId, ConsumerId, CreateWorld, EntityId, KernelError,
|
||||
NewController, SubjectDeclaration, SubjectKind, SubmitReceipt,
|
||||
SystemCapability, WorldKernel, WorldPatch,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
|
|
@ -70,7 +70,6 @@ fn patch_of(declarations: Vec<Declaration>) -> WorldPatch {
|
|||
fn submit_as(
|
||||
kernel: &mut WorldKernel,
|
||||
caller: CallerId,
|
||||
answers: Option<PatchAnswer>,
|
||||
patch: WorldPatch,
|
||||
) -> Result<SubmitReceipt, KernelError> {
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
|
|
@ -79,7 +78,7 @@ fn submit_as(
|
|||
&snapshot,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::AdmitPatch { answers, patch },
|
||||
CommandBody::AdmitPatch { patch },
|
||||
),
|
||||
&crate::AuthenticatedCaller::fixture(caller),
|
||||
)
|
||||
|
|
@ -156,7 +155,6 @@ fn one_patch_cannot_declare_two_subjects_with_one_import_key() {
|
|||
let error = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![
|
||||
mirror("first", beta.clone(), place),
|
||||
mirror("second", beta, place),
|
||||
|
|
@ -167,14 +165,13 @@ fn one_patch_cannot_declare_two_subjects_with_one_import_key() {
|
|||
}
|
||||
|
||||
/// The fixture world past genesis but still in Draft: the owner has added an
|
||||
/// unwalked place the elaborator can later answer.
|
||||
/// unwalked place.
|
||||
fn advanced_keyed_world() -> (tempfile::TempDir, WorldKernel, EntityId) {
|
||||
let (dir, mut kernel) = keyed_world();
|
||||
let place = commons(&kernel);
|
||||
submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![
|
||||
Declaration::Entity(EntityDeclaration {
|
||||
handle: DraftHandle::new("dead-end"),
|
||||
|
|
@ -204,19 +201,18 @@ fn advanced_keyed_world() -> (tempfile::TempDir, WorldKernel, EntityId) {
|
|||
}
|
||||
|
||||
/// Each door names the held key, typed, and the refusal leaves the revision
|
||||
/// where it was. The owner and the consumer declare in Draft only; Play and the
|
||||
/// elaborator act in Active.
|
||||
/// where it was. The owner and the consumer declare in Draft, and in Active
|
||||
/// too; Play acts in Active.
|
||||
fn refuse_held_key_at_each_door(
|
||||
kernel: &mut WorldKernel,
|
||||
place: EntityId,
|
||||
doors: Vec<(&str, CallerId, Option<PatchAnswer>)>,
|
||||
doors: Vec<(&str, CallerId)>,
|
||||
) {
|
||||
for (door, caller, answers) in doors {
|
||||
for (door, caller) in doors {
|
||||
let revision = kernel.state.revision;
|
||||
let result = submit_as(
|
||||
kernel,
|
||||
caller,
|
||||
answers,
|
||||
patch_of(vec![mirror("copy", Some(alpha()), place)]),
|
||||
);
|
||||
assert_eq!(rejected(result), vec![held("copy")], "{door}");
|
||||
|
|
@ -241,31 +237,17 @@ fn a_held_import_key_is_refused_at_every_door_after_the_revision_has_moved() {
|
|||
&mut kernel,
|
||||
dead_end,
|
||||
vec![
|
||||
("owner", CallerId::Principal(owner()), None),
|
||||
("consumer", consumer(), None),
|
||||
("owner", CallerId::Principal(owner())),
|
||||
("consumer", consumer()),
|
||||
],
|
||||
);
|
||||
activate(&mut kernel);
|
||||
let answer = crate::derive_boundaries(&kernel.state)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|boundary| {
|
||||
matches!(boundary, crate::CausalBoundary::UnelaboratedDestination { place, .. }
|
||||
if *place == dead_end)
|
||||
})
|
||||
.expect("the dead end is an unelaborated destination");
|
||||
refuse_held_key_at_each_door(
|
||||
&mut kernel,
|
||||
dead_end,
|
||||
vec![
|
||||
("play", CallerId::System(SystemCapability::Play), None),
|
||||
(
|
||||
"elaborator",
|
||||
CallerId::System(SystemCapability::Elaborator {
|
||||
jurisdiction: JurisdictionKey::PlaceSubtree(dead_end),
|
||||
}),
|
||||
Some(PatchAnswer::Boundary(answer.clone())),
|
||||
),
|
||||
("owner in Active", CallerId::Principal(owner())),
|
||||
("play", CallerId::System(SystemCapability::Play)),
|
||||
],
|
||||
);
|
||||
// The same doors admit an unheld key, so the refusals are the key's; and
|
||||
|
|
@ -273,10 +255,7 @@ fn a_held_import_key_is_refused_at_every_door_after_the_revision_has_moved() {
|
|||
let fresh = key("aetheria.ship", "Gamma");
|
||||
let receipt = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::System(SystemCapability::Elaborator {
|
||||
jurisdiction: JurisdictionKey::PlaceSubtree(dead_end),
|
||||
}),
|
||||
Some(PatchAnswer::Boundary(answer)),
|
||||
CallerId::Principal(owner()),
|
||||
patch_of(vec![mirror("fresh", Some(fresh.clone()), dead_end)]),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -284,7 +263,6 @@ fn a_held_import_key_is_refused_at_every_door_after_the_revision_has_moved() {
|
|||
let again = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::System(SystemCapability::Play),
|
||||
None,
|
||||
patch_of(vec![mirror("fresh-again", Some(fresh), dead_end)]),
|
||||
);
|
||||
assert_eq!(rejected(again), vec![held("fresh-again")]);
|
||||
|
|
@ -298,7 +276,6 @@ fn a_held_import_key_is_refused_in_a_later_patch() {
|
|||
let error = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror("again", Some(alpha()), place)]),
|
||||
);
|
||||
assert_eq!(rejected(error), vec![held("again")]);
|
||||
|
|
@ -321,7 +298,6 @@ fn a_retired_subjects_import_key_is_never_reissued() {
|
|||
submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
WorldPatch {
|
||||
declarations: Vec::new(),
|
||||
operations: vec![ComponentOp::Retire {
|
||||
|
|
@ -347,7 +323,6 @@ fn a_retired_subjects_import_key_is_never_reissued() {
|
|||
let error = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror("reborn", Some(alpha()), place)]),
|
||||
);
|
||||
assert_eq!(rejected(error), vec![held("reborn")]);
|
||||
|
|
@ -378,7 +353,6 @@ fn keys_that_differ_in_any_way_are_distinct_records() {
|
|||
submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(declarations),
|
||||
)
|
||||
.expect("nine distinct keys beside the held one are admitted together");
|
||||
|
|
@ -389,7 +363,6 @@ fn keys_that_differ_in_any_way_are_distinct_records() {
|
|||
let again = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror("repeat", Some(forged.clone()), place)]),
|
||||
);
|
||||
assert_eq!(rejected(again), vec![held("repeat")], "forgery {index}");
|
||||
|
|
@ -419,7 +392,6 @@ fn a_malformed_import_key_is_refused_without_echoing_it() {
|
|||
let set = rejected(submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror("bad", Some(bad.clone()), place)]),
|
||||
));
|
||||
assert_eq!(set, vec![malformed("bad")], "case {index}");
|
||||
|
|
@ -443,7 +415,6 @@ fn a_malformed_import_key_is_refused_without_echoing_it() {
|
|||
submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(declarations),
|
||||
)
|
||||
.expect("keys of exactly 200 bytes per part are admitted");
|
||||
|
|
@ -462,7 +433,6 @@ fn the_subjects_map_refuses_a_second_subject_for_one_key_even_when_resolved_else
|
|||
Some(key("aetheria.ship", "Omega")),
|
||||
place,
|
||||
)]),
|
||||
None,
|
||||
)
|
||||
.expect("the key is unheld at the revision both were resolved against")
|
||||
};
|
||||
|
|
@ -470,7 +440,6 @@ fn the_subjects_map_refuses_a_second_subject_for_one_key_even_when_resolved_else
|
|||
let mut state = kernel.state.clone();
|
||||
let before = state.subjects.len();
|
||||
let effect = |resolved| crate::WorldEffect::PatchAdmitted {
|
||||
answers: None,
|
||||
resolved,
|
||||
};
|
||||
crate::apply_effect(
|
||||
|
|
@ -558,7 +527,6 @@ fn a_record_key_is_one_canonical_spelling() {
|
|||
submit_as(
|
||||
kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror(
|
||||
handle,
|
||||
Some(key("aetheria.ship", record)),
|
||||
|
|
@ -607,7 +575,6 @@ fn a_lore_page_path_with_spaces_is_a_record_key() {
|
|||
submit_as(
|
||||
kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror(
|
||||
handle,
|
||||
Some(key("aetheria.lore", record)),
|
||||
|
|
@ -626,7 +593,6 @@ fn a_loaded_state_with_a_bad_import_key_is_refused() {
|
|||
submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror(
|
||||
"beta",
|
||||
Some(key("aetheria.ship", "Beta")),
|
||||
|
|
@ -678,7 +644,6 @@ fn admitting_a_resolved_effect_refuses_two_subjects_with_one_key() {
|
|||
mirror("first", Some(key("aetheria.ship", "Beta")), place),
|
||||
mirror("second", Some(key("aetheria.ship", "Gamma")), place),
|
||||
]),
|
||||
None,
|
||||
)
|
||||
.expect("two distinct keys resolve")
|
||||
};
|
||||
|
|
@ -714,7 +679,6 @@ fn a_decomposable_character_is_refused_in_nfd_at_every_position() {
|
|||
submit_as(
|
||||
kernel,
|
||||
CallerId::Principal(owner()),
|
||||
None,
|
||||
patch_of(vec![mirror(
|
||||
handle,
|
||||
Some(key("aetheria.lore", &record)),
|
||||
|
|
|
|||
|
|
@ -433,8 +433,8 @@ pub(super) fn verify_history(
|
|||
// Authority is re-decided here for free: `apply_committed_command`
|
||||
// re-runs `reduce` against the pre-commit state and requires effect
|
||||
// equality, then `apply_effect`, and both of those call
|
||||
// `require_patch_author` and `confine_to_jurisdiction`. A forged row
|
||||
// claiming an elaborator caller for a patch outside its jurisdiction
|
||||
// `require_patch_author` and `confine_to_ground`. A forged row
|
||||
// claiming a confined caller for a patch outside its ground
|
||||
// fails replay rather than being admitted by a reducer that trusts the
|
||||
// recorded caller. A third statement of the same rule here would be a
|
||||
// third owner of one decision.
|
||||
|
|
@ -736,23 +736,6 @@ pub(super) fn verify_state_shape(state: &WorldState) -> Result<(), JournalError>
|
|||
"an attention stamp names an unknown subject or a future minute".into(),
|
||||
));
|
||||
}
|
||||
if state
|
||||
.scale_intent
|
||||
.jurisdictions
|
||||
.keys()
|
||||
.any(|root| !is_place(root))
|
||||
|| state
|
||||
.scale_intent
|
||||
.jurisdictions
|
||||
.values()
|
||||
.map(|weight| u64::from(*weight))
|
||||
.sum::<u64>()
|
||||
> 1000
|
||||
{
|
||||
return Err(JournalError::Corrupt(
|
||||
"the scale intent names a non-place root or distributes more than the whole".into(),
|
||||
));
|
||||
}
|
||||
// The civic subgraph, in the slot the deleted `authority_scope` check
|
||||
// occupied: a jurisdiction names live ground under a canonical kind, an
|
||||
// office sits on an institution and lends something to a person who holds
|
||||
|
|
@ -1057,7 +1040,6 @@ fn kernel_error(error: KernelError) -> JournalError {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::WorldScaleIntentRef;
|
||||
use crate::patch::kernel_speak_grant;
|
||||
use crate::tests::speak_entry;
|
||||
use crate::{
|
||||
|
|
@ -1112,7 +1094,6 @@ mod tests {
|
|||
position: None,
|
||||
import_key: None,
|
||||
}),
|
||||
scale_intent: WorldScaleIntentRef::default(),
|
||||
grammar: None,
|
||||
};
|
||||
let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap();
|
||||
|
|
@ -1195,7 +1176,6 @@ mod tests {
|
|||
position: None,
|
||||
import_key: None,
|
||||
}),
|
||||
scale_intent: WorldScaleIntentRef::default(),
|
||||
grammar: None,
|
||||
};
|
||||
let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap();
|
||||
|
|
@ -1209,7 +1189,6 @@ mod tests {
|
|||
expected_revision: snapshot.revision,
|
||||
caller: CallerId::Principal(owner),
|
||||
body: CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch: WorldPatch {
|
||||
declarations: vec![
|
||||
Declaration::Entity(EntityDeclaration {
|
||||
|
|
@ -1508,7 +1487,6 @@ mod tests {
|
|||
command_id,
|
||||
CallerId::Principal(owner()),
|
||||
CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch: WorldPatch {
|
||||
declarations: Vec::new(),
|
||||
operations: vec![crate::ComponentOp::Relocate {
|
||||
|
|
@ -1672,7 +1650,6 @@ mod tests {
|
|||
position: None,
|
||||
import_key: None,
|
||||
}),
|
||||
scale_intent: WorldScaleIntentRef::default(),
|
||||
grammar: None,
|
||||
};
|
||||
let (kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap();
|
||||
|
|
@ -2193,7 +2170,6 @@ mod custody_tests {
|
|||
CommandId::new(),
|
||||
CallerId::Principal(owner()),
|
||||
CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch: WorldPatch {
|
||||
declarations: Vec::new(),
|
||||
operations: vec![ComponentOp::Transfer {
|
||||
|
|
@ -2447,7 +2423,6 @@ mod custody_tests {
|
|||
CommandId::new(),
|
||||
CallerId::Principal(owner()),
|
||||
CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch: WorldPatch {
|
||||
declarations: Vec::new(),
|
||||
operations: vec![
|
||||
|
|
@ -2736,149 +2711,4 @@ mod custody_tests {
|
|||
assert!(matches!(recover(rows, None), Err(JournalError::Corrupt(_))));
|
||||
}
|
||||
|
||||
/// Replay re-decides authority, so a stored row is not believed about who
|
||||
/// authored it. An honest elaborator commit is rewritten to claim a
|
||||
/// jurisdiction that does not cover its answer, and the history it belongs
|
||||
/// to stops recovering.
|
||||
#[test]
|
||||
fn soul_a_forged_elaborator_commit_row_fails_replay() {
|
||||
use crate::tests::{activate, submit_owner};
|
||||
use crate::{
|
||||
AuthenticatedCaller, CausalBoundary, Declaration, DraftHandle, EntityDeclaration,
|
||||
JurisdictionKey, PatchAnswer, RouteDeclaration, SystemCapability,
|
||||
};
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "Forged Authorship"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
let seed = kernel.snapshot().unwrap();
|
||||
let commons = seed.places[0].id;
|
||||
submit_owner(
|
||||
&mut kernel,
|
||||
&seed,
|
||||
CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch: WorldPatch {
|
||||
declarations: vec![
|
||||
Declaration::Entity(EntityDeclaration {
|
||||
handle: DraftHandle::new("road"),
|
||||
label: "The Unwalked Road".into(),
|
||||
kind: EntityKind::Place,
|
||||
container: Some(Ref::Existing(commons)),
|
||||
}),
|
||||
Declaration::Route(RouteDeclaration {
|
||||
handle: DraftHandle::new("lane"),
|
||||
label: "The Long Lane".into(),
|
||||
from: Ref::Existing(commons),
|
||||
to: Ref::Draft(DraftHandle::new("road")),
|
||||
access: crate::AccessKind::Public,
|
||||
cost: crate::Cost(1),
|
||||
}),
|
||||
],
|
||||
operations: Vec::new(),
|
||||
evidence: Vec::new(),
|
||||
},
|
||||
},
|
||||
);
|
||||
activate(&mut kernel);
|
||||
|
||||
let boundary = crate::derive_boundaries(&kernel.state)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|boundary| matches!(boundary, CausalBoundary::UnelaboratedDestination { .. }))
|
||||
.expect("the road is a dead end");
|
||||
let CausalBoundary::UnelaboratedDestination { place: road, .. } = boundary else {
|
||||
unreachable!("the boundary was matched above")
|
||||
};
|
||||
let caller = CallerId::System(SystemCapability::Elaborator {
|
||||
jurisdiction: JurisdictionKey::PlaceSubtree(road),
|
||||
});
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
kernel
|
||||
.submit(
|
||||
command(
|
||||
&snapshot,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::AdmitPatch {
|
||||
answers: Some(PatchAnswer::Boundary(boundary)),
|
||||
patch: WorldPatch {
|
||||
declarations: vec![Declaration::Entity(EntityDeclaration {
|
||||
handle: DraftHandle::new("shed"),
|
||||
label: "The Roadside Shed".into(),
|
||||
kind: EntityKind::Place,
|
||||
container: Some(Ref::Existing(road)),
|
||||
})],
|
||||
operations: Vec::new(),
|
||||
evidence: Vec::new(),
|
||||
},
|
||||
},
|
||||
),
|
||||
&AuthenticatedCaller::fixture(caller),
|
||||
)
|
||||
.expect("the honest elaboration commits");
|
||||
|
||||
let state_row = || {
|
||||
envelope(
|
||||
STATE_ROW,
|
||||
STATE_SCHEMA,
|
||||
kernel.state.world_id.key(),
|
||||
&kernel.state,
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
let rows_of = |commits: Vec<crate::WorldCommit>| {
|
||||
let mut rows: Vec<CultCacheEnvelope> = commits
|
||||
.iter()
|
||||
.map(|commit| {
|
||||
envelope(COMMIT_ROW, COMMIT_SCHEMA, commit.command.id().key(), commit).unwrap()
|
||||
})
|
||||
.collect();
|
||||
rows.push(state_row());
|
||||
rows
|
||||
};
|
||||
|
||||
let honest: Vec<crate::WorldCommit> =
|
||||
kernel.journal.commits.values().cloned().collect();
|
||||
recover(rows_of(honest.clone()), None).expect("the honest history replays");
|
||||
|
||||
// Rewrite only the recorded caller, to a jurisdiction that does not
|
||||
// cover the answer the same row carries.
|
||||
let mut forged_one = false;
|
||||
let forged: Vec<crate::WorldCommit> = honest
|
||||
.into_iter()
|
||||
.map(|mut commit| {
|
||||
if let crate::CommittedCommand::WorldCommand(command) = &mut commit.command
|
||||
&& matches!(
|
||||
command.caller,
|
||||
CallerId::System(SystemCapability::Elaborator { .. })
|
||||
)
|
||||
{
|
||||
command.caller = CallerId::System(SystemCapability::Elaborator {
|
||||
jurisdiction: JurisdictionKey::PlaceSubtree(commons),
|
||||
});
|
||||
// Re-seal the row, so the chain digest cannot answer for
|
||||
// the authority check. The elaborator commit is the last
|
||||
// one, so no successor's `previous_commit_digest` moves.
|
||||
commit.digest = commit_digest(&commit).unwrap();
|
||||
forged_one = true;
|
||||
}
|
||||
commit
|
||||
})
|
||||
.collect();
|
||||
assert!(forged_one, "no elaborator row was found to forge");
|
||||
let error = recover(rows_of(forged), None).expect_err("a forged authorship replayed");
|
||||
let JournalError::Corrupt(detail) = &error else {
|
||||
panic!("unexpected refusal: {error:?}");
|
||||
};
|
||||
assert!(
|
||||
!detail.contains("commit chain is not contiguous"),
|
||||
"the chain digest answered for the authority check: {detail}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -608,40 +608,6 @@ pub(crate) enum PreconditionRef {
|
|||
},
|
||||
}
|
||||
|
||||
/// The authored scale target: how many qualified subjects of each kind the
|
||||
/// world means to hold, and how that target distributes over jurisdiction
|
||||
/// roots. Written once by genesis and never mutated. Not a component of any
|
||||
/// referent, so not a `Declaration` and not a partition.
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(crate) struct WorldScaleIntent {
|
||||
/// Target qualified subjects per kind, world-wide.
|
||||
pub(crate) targets: BTreeMap<SubjectKind, u32>,
|
||||
/// Jurisdiction roots and their share, in permille. Weights distribute the
|
||||
/// target and never raise it: the sum is checked `<= 1000`.
|
||||
pub(crate) jurisdictions: BTreeMap<EntityId, u32>,
|
||||
}
|
||||
|
||||
/// The genesis-lane twin: the intent names places the same patch declares, and
|
||||
/// there is no other way to name them before they exist.
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(crate) struct WorldScaleIntentRef {
|
||||
pub(crate) targets: BTreeMap<SubjectKind, u32>,
|
||||
pub(crate) jurisdictions: BTreeMap<DraftHandle, u32>,
|
||||
}
|
||||
|
||||
/// One counted region of the scale deficit. `Uncovered` is the residual: a
|
||||
/// subject with no jurisdiction root covering it — standing nowhere, or
|
||||
/// standing somewhere outside every declared root's subtree — is counted and
|
||||
/// visible while reducing no target.
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[serde(tag = "jurisdiction", content = "root", rename_all = "snake_case")]
|
||||
pub enum JurisdictionKey {
|
||||
PlaceSubtree(EntityId),
|
||||
Uncovered,
|
||||
}
|
||||
|
||||
/// What must already be true of committed state before an invocation is
|
||||
/// admitted.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
|
|
@ -908,7 +874,7 @@ pub enum Site {
|
|||
pub(crate) struct EvidenceRef(String);
|
||||
|
||||
impl EvidenceRef {
|
||||
/// The elaborator's evidence receipts are built here, and `Deserialize`
|
||||
/// An author's evidence receipts are built here, and `Deserialize`
|
||||
/// already mints one from any string, so this constructor gates nothing.
|
||||
/// Canonical text is checked by the resolver, in the complete mismatch set.
|
||||
pub(super) fn new(value: impl Into<String>) -> Self {
|
||||
|
|
@ -1297,16 +1263,6 @@ pub(crate) enum ComponentOp {
|
|||
},
|
||||
}
|
||||
|
||||
/// What an Active `AdmitPatch` answers. Draft answers nothing; Active must
|
||||
/// answer a boundary the kernel currently derives or a jurisdiction whose
|
||||
/// deficit is nonzero, and the commit must satisfy what it answered.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(tag = "answer", rename_all = "snake_case")]
|
||||
pub enum PatchAnswer {
|
||||
Boundary(super::CausalBoundary),
|
||||
Deficit(JurisdictionKey),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct WorldPatch {
|
||||
|
|
@ -1675,13 +1631,6 @@ pub enum Mismatch {
|
|||
UnknownCommitment {
|
||||
operation: usize,
|
||||
},
|
||||
/// A scale-intent jurisdiction root that is not a declared place.
|
||||
UnknownJurisdictionRoot {
|
||||
handle: DraftHandle,
|
||||
},
|
||||
/// The permille weights sum over 1000: weights distribute the target and
|
||||
/// never raise it.
|
||||
ScaleWeightsExceedWhole,
|
||||
/// A jurisdictional author wrote outside its jurisdiction. The owner is
|
||||
/// unconfined and never sees this.
|
||||
OutsideJurisdiction {
|
||||
|
|
@ -1951,7 +1900,7 @@ pub(crate) enum ResolvedOp {
|
|||
},
|
||||
/// A visible act: the actor's own sentence, seen by everyone standing in
|
||||
/// the actor's place. Lowered only by the kernel's speech path beside
|
||||
/// `AssertClaim`, never by a patch, so no seed or elaborator can move a
|
||||
/// `AssertClaim`, never by a patch, so no author can move a
|
||||
/// person's body from outside the person. There is no audience field: a
|
||||
/// display cannot go down a channel, and the room is re-derived from live
|
||||
/// `positions` at apply, so a forged effect cannot assert a landing the
|
||||
|
|
@ -2075,10 +2024,6 @@ pub(super) struct ResolvedPatch {
|
|||
pub(super) channels: Vec<ResolvedChannel>,
|
||||
pub(super) operations: Vec<ResolvedOp>,
|
||||
pub(super) evidence: Vec<EvidenceRef>,
|
||||
/// `Some` on the genesis lane and nowhere else: `CommandBody::AdmitPatch`
|
||||
/// carries no intent, so the write-once rule is the command shape rather
|
||||
/// than a check.
|
||||
pub(super) scale_intent: Option<WorldScaleIntent>,
|
||||
}
|
||||
|
||||
impl ResolvedPatch {
|
||||
|
|
@ -3153,7 +3098,6 @@ pub(super) fn resolve_patch(
|
|||
state: &super::WorldState,
|
||||
command_id: CommandId,
|
||||
patch: &WorldPatch,
|
||||
scale_intent: Option<&WorldScaleIntentRef>,
|
||||
) -> Result<ResolvedPatch, Vec<Mismatch>> {
|
||||
let world_id = state.world_id;
|
||||
let admits_human = super::admits_human(state.revision, &state.subjects);
|
||||
|
|
@ -5004,26 +4948,6 @@ pub(super) fn resolve_patch(
|
|||
});
|
||||
}
|
||||
|
||||
if let Some(intent) = scale_intent {
|
||||
for handle in intent.jurisdictions.keys() {
|
||||
if index.get(handle) != Some(&PLACE) {
|
||||
mismatches.push(Mismatch::UnknownJurisdictionRoot {
|
||||
handle: handle.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
// Weights distribute the target and never raise it.
|
||||
if intent
|
||||
.jurisdictions
|
||||
.values()
|
||||
.map(|weight| u64::from(*weight))
|
||||
.sum::<u64>()
|
||||
> 1000
|
||||
{
|
||||
mismatches.push(Mismatch::ScaleWeightsExceedWhole);
|
||||
}
|
||||
}
|
||||
|
||||
if patch.declarations.is_empty() && patch.operations.is_empty() {
|
||||
mismatches.push(Mismatch::NoCanonicalChange);
|
||||
}
|
||||
|
|
@ -5688,21 +5612,6 @@ pub(super) fn resolve_patch(
|
|||
channels: declared_channels,
|
||||
operations,
|
||||
evidence: patch.evidence.clone(),
|
||||
scale_intent: scale_intent.map(|intent| WorldScaleIntent {
|
||||
targets: intent.targets.clone(),
|
||||
jurisdictions: intent
|
||||
.jurisdictions
|
||||
.iter()
|
||||
.map(|(handle, weight)| {
|
||||
(
|
||||
*allocated_entities
|
||||
.get(handle)
|
||||
.expect("a jurisdiction root resolved above"),
|
||||
*weight,
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -5990,7 +5899,6 @@ mod tests {
|
|||
|
||||
fn admit(patch: WorldPatch) -> CommandBody {
|
||||
CommandBody::AdmitPatch {
|
||||
answers: None,
|
||||
patch,
|
||||
}
|
||||
}
|
||||
|
|
@ -6615,46 +6523,6 @@ mod tests {
|
|||
assert_eq!(kernel.journal.commit_count(), 1);
|
||||
}
|
||||
|
||||
/// Active admits the four operations and nothing else, so it never mints a
|
||||
/// canonical ID.
|
||||
#[test]
|
||||
fn an_active_patch_that_declares_anything_is_rejected() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let mut kernel = draft_world(directory.path());
|
||||
let active = activate(&mut kernel);
|
||||
let commits_before = kernel.journal.commit_count();
|
||||
let declaring = patch_of(vec![entity(
|
||||
"rhythm-road",
|
||||
"The Rhythm Road",
|
||||
EntityKind::Place,
|
||||
)]);
|
||||
let bearing_evidence = WorldPatch {
|
||||
declarations: Vec::new(),
|
||||
operations: Vec::new(),
|
||||
evidence: vec![EvidenceRef("run-115".into())],
|
||||
};
|
||||
|
||||
for patch in [declaring, bearing_evidence] {
|
||||
let error = kernel
|
||||
.submit(
|
||||
command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
CallerId::Principal(owner()),
|
||||
admit(patch),
|
||||
),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap_err();
|
||||
// Declaring in Active is elaboration, and elaboration answers a
|
||||
// boundary. An unanswered one is refused before resolution.
|
||||
assert!(matches!(error, KernelError::AnswerRequired));
|
||||
}
|
||||
assert_eq!(kernel.journal.commit_count(), commits_before);
|
||||
assert_eq!(kernel.snapshot().unwrap(), active);
|
||||
assert_eq!(kernel.state.entities.len(), FIXTURE_ENTITIES);
|
||||
}
|
||||
|
||||
/// Three places whose containers form a cycle name themselves, and the
|
||||
/// unrelated empty label joins the same complete set.
|
||||
#[test]
|
||||
|
|
@ -6880,8 +6748,7 @@ mod tests {
|
|||
let (topology, civic, before) = civic_world(&mut kernel);
|
||||
|
||||
// `topology.walker` already exists and already stands at `yard`, so
|
||||
// this delegation patch is operations-only: no declaration, no
|
||||
// `AnswerRequired` elaboration boundary to clear.
|
||||
// this delegation patch is operations-only: no declaration.
|
||||
let delegated = submit_owner(
|
||||
&mut kernel,
|
||||
&before,
|
||||
|
|
@ -7151,8 +7018,8 @@ mod tests {
|
|||
assert_ne!(admitted, genesis_human);
|
||||
|
||||
let command_id = CommandId::new();
|
||||
let first = resolve_patch(&kernel.state, command_id, &patch, None).unwrap();
|
||||
let second = resolve_patch(&kernel.state, command_id, &patch, None).unwrap();
|
||||
let first = resolve_patch(&kernel.state, command_id, &patch).unwrap();
|
||||
let second = resolve_patch(&kernel.state, command_id, &patch).unwrap();
|
||||
assert_eq!(first, second);
|
||||
}
|
||||
|
||||
|
|
@ -7279,13 +7146,12 @@ mod tests {
|
|||
}
|
||||
|
||||
/// The `PatchAdmitted` arm is not a trusting applier. A forged effect, a
|
||||
/// replayed one, a non-owner caller, and the Active phase each die inside
|
||||
/// `apply_effect`, without the journal's reduce-equality check running.
|
||||
/// replayed one and a non-owner caller each die inside `apply_effect`,
|
||||
/// without the journal's reduce-equality check running.
|
||||
#[test]
|
||||
fn apply_effect_rejects_a_forged_stale_unauthorized_or_active_patch_effect() {
|
||||
fn apply_effect_rejects_a_forged_stale_or_unauthorized_patch_effect() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let mut kernel = draft_world(directory.path());
|
||||
let before = kernel.snapshot().unwrap();
|
||||
let kernel = draft_world(directory.path());
|
||||
let patch = patch_of(vec![
|
||||
entity("rhythm-road", "The Rhythm Road", EntityKind::Place),
|
||||
institution(
|
||||
|
|
@ -7295,10 +7161,9 @@ mod tests {
|
|||
Some(Ref::Draft(DraftHandle::new("rhythm-road"))),
|
||||
),
|
||||
]);
|
||||
let resolved = resolve_patch(&kernel.state, CommandId::new(), &patch, None).unwrap();
|
||||
let resolved = resolve_patch(&kernel.state, CommandId::new(), &patch).unwrap();
|
||||
let honest = super::super::WorldEffect::PatchAdmitted {
|
||||
resolved: resolved.clone(),
|
||||
answers: None,
|
||||
};
|
||||
|
||||
// Forged: the position names a place no partition holds, and the effect
|
||||
|
|
@ -7314,7 +7179,6 @@ mod tests {
|
|||
CommandId::issue(),
|
||||
&CallerId::Principal(owner()),
|
||||
&super::super::WorldEffect::PatchAdmitted {
|
||||
answers: None,
|
||||
resolved: forged,
|
||||
},
|
||||
)
|
||||
|
|
@ -7350,21 +7214,6 @@ mod tests {
|
|||
.unwrap_err();
|
||||
assert!(matches!(unauthorized, KernelError::Invariant(_)));
|
||||
assert_eq!(candidate, kernel.state);
|
||||
|
||||
// And an unanswered declaring effect is refused in Active before any
|
||||
// partition is touched.
|
||||
let active = activate(&mut kernel);
|
||||
assert_eq!(active.revision, before.revision + 3);
|
||||
let mut candidate = kernel.state.clone();
|
||||
let unanswered = super::super::apply_effect(
|
||||
&mut candidate,
|
||||
CommandId::issue(),
|
||||
&CallerId::Principal(owner()),
|
||||
&honest,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(matches!(unanswered, KernelError::AnswerRequired));
|
||||
assert_eq!(candidate, kernel.state);
|
||||
}
|
||||
|
||||
/// Soul falsification: the three pass-2 `Mismatch` variants that no landed
|
||||
|
|
@ -7510,9 +7359,7 @@ mod tests {
|
|||
edge_id,
|
||||
}],
|
||||
evidence: Vec::new(),
|
||||
scale_intent: None,
|
||||
},
|
||||
answers: None,
|
||||
};
|
||||
let mut candidate = kernel.state.clone();
|
||||
let error = super::super::apply_effect(
|
||||
|
|
|
|||
Loading…
Reference in a new issue