aetherlight: derive command, creation and world ids from content; drop committed_at; rename schemas
A command is named by sha256 over world, expected revision, caller and body; a creation by its own bytes; a world by its creation. The id fields, the random CommandId::new / WorldId::issue and WorldCommit.committed_at are gone, so equal commands commit equal bytes. Retry identity goes with them: SubmitReceipt collapses into CommitReceipt and a resubmitted command is a RevisionMismatch. Schemas are aetherlight.world_state.v1 and aetherlight.world_commit.v1; ghostlight rows stay refused. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
09a1c32560
commit
84a48f3f60
6 changed files with 400 additions and 546 deletions
|
|
@ -1015,13 +1015,13 @@ mod tests {
|
|||
};
|
||||
use crate::tests::{
|
||||
ADMIT_KIND, COMMAND_KIND, Civic, LEVY_KIND, OPENING_BALANCE, SEIZURE_GRIEVANCE, Topology,
|
||||
WARDEN_OFFICE, act, act_command, affordance_named, authority_kind, civic_world,
|
||||
WARDEN_OFFICE, act, affordance_named, authority_kind, civic_world,
|
||||
command, custody_world, grant_to, grievance, office, operations, over_place,
|
||||
over_subject, play_caller, reject_play, submit_play,
|
||||
over_subject, play_caller, reject_play, submit_play, tick_body,
|
||||
};
|
||||
use crate::{
|
||||
AffordanceKindName, AuthenticatedCaller, AuthoredSource, CommandBody, Confidence,
|
||||
Declaration, EffectSlot, EntityKind, ProposedEffect, RoleBinding, Statement, SubmitReceipt,
|
||||
Declaration, EffectSlot, EntityKind, ProposedEffect, RoleBinding, Statement, CommitReceipt,
|
||||
WorldEffect, WorldKernel, WorldPatch, WorldSnapshot, apply_effect,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
|
|
@ -1069,6 +1069,40 @@ mod tests {
|
|||
exercise(state, command_id, actor, &granted, invocation)
|
||||
}
|
||||
|
||||
/// Commit `invocation` as the first command whose derived id draws `band`.
|
||||
/// A band is a pure function of the pre-commit state and the command id,
|
||||
/// and a command's id derives from the revision it targets, so a test
|
||||
/// reaches a band by committing ordinary ticks until the id it would
|
||||
/// carry draws it.
|
||||
fn act_drawing(
|
||||
kernel: &mut WorldKernel,
|
||||
actor: SubjectId,
|
||||
invocation: &DecisionInvocation,
|
||||
band: usize,
|
||||
) -> CommitReceipt {
|
||||
for _ in 0..256 {
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
let envelope = command(
|
||||
&snapshot,
|
||||
play_caller(),
|
||||
CommandBody::Act {
|
||||
actor,
|
||||
invocation: invocation.clone(),
|
||||
},
|
||||
);
|
||||
let draws = draw_once(&kernel.state, envelope.id(), actor, invocation)
|
||||
.expect("the invocation is admissible")
|
||||
.band;
|
||||
if draws == band {
|
||||
return kernel
|
||||
.submit(envelope, &AuthenticatedCaller::verified_play())
|
||||
.expect("the invocation commits");
|
||||
}
|
||||
submit_play(kernel, &snapshot, tick_body(1));
|
||||
}
|
||||
panic!("a two-band entry reaches both bands within 256 revisions");
|
||||
}
|
||||
|
||||
fn binding(role: &str, target: Target) -> RoleBinding {
|
||||
RoleBinding {
|
||||
role: Role(role.into()),
|
||||
|
|
@ -1120,7 +1154,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn commit(&mut self, invocation: DecisionInvocation) -> SubmitReceipt {
|
||||
fn commit(&mut self, invocation: DecisionInvocation) -> CommitReceipt {
|
||||
act(&mut self.kernel, self.clerk, invocation).expect("the invocation commits")
|
||||
}
|
||||
|
||||
|
|
@ -1324,7 +1358,7 @@ mod tests {
|
|||
let clerk_before = bench.held(bench.clerk);
|
||||
let keeper_before = bench.held(bench.keeper);
|
||||
let receipt = bench.commit(bench.carry(3, bench.yard));
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
assert_eq!(bench.held(bench.clerk), clerk_before - 3);
|
||||
assert_eq!(bench.held(bench.keeper), keeper_before + 3);
|
||||
assert_eq!(
|
||||
|
|
@ -1470,7 +1504,7 @@ mod tests {
|
|||
assert!(event.effects.is_empty());
|
||||
|
||||
let receipt = bench.commit(idle);
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
assert_eq!(bench.kernel.state.holdings, holdings);
|
||||
assert_eq!(bench.kernel.state.positions, positions);
|
||||
assert_eq!(bench.kernel.state.edges, edges);
|
||||
|
|
@ -1483,7 +1517,7 @@ mod tests {
|
|||
let directory = tempfile::tempdir().unwrap();
|
||||
let mut bench = bench(directory.path(), "Lowering");
|
||||
let receipt = bench.commit(bench.carry(2, bench.yard));
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
let event = bench
|
||||
.kernel
|
||||
.state
|
||||
|
|
@ -1539,30 +1573,12 @@ mod tests {
|
|||
let mut seen: BTreeSet<usize> = BTreeSet::new();
|
||||
|
||||
for wanted in [0usize, 1] {
|
||||
// The draw is a pure function of the pre-commit revision and the
|
||||
// command id, so the command id that reaches a band is findable
|
||||
// before the envelope is built rather than hunted by retrying.
|
||||
let command_id = (0..256)
|
||||
.map(|_| CommandId::issue())
|
||||
.find(|candidate| {
|
||||
draw_once(&bench.kernel.state, *candidate, bench.clerk, &split)
|
||||
.expect("the invocation is admissible")
|
||||
.band
|
||||
== wanted
|
||||
})
|
||||
.expect("a two-band entry reaches both bands over 256 command ids");
|
||||
|
||||
// The draw is a pure function of the pre-commit state and the
|
||||
// command id; `act_drawing` finds the revision whose id reaches it.
|
||||
let before_clerk = bench.held(bench.clerk);
|
||||
let before_keeper = bench.held(bench.keeper);
|
||||
let receipt = act_command(
|
||||
&mut bench.kernel,
|
||||
command_id,
|
||||
play_caller(),
|
||||
bench.clerk,
|
||||
split.clone(),
|
||||
)
|
||||
.expect("the invocation commits");
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
let receipt = act_drawing(&mut bench.kernel, bench.clerk, &split, wanted);
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
bench.refresh();
|
||||
let event = bench
|
||||
.kernel
|
||||
|
|
@ -1743,7 +1759,7 @@ mod tests {
|
|||
},
|
||||
)
|
||||
.expect("the Speak entry commits");
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
let event = kernel.state.events.last().unwrap();
|
||||
assert_eq!(event.band, 0);
|
||||
// The two the speech lowering prepends, and nothing from a slot.
|
||||
|
|
@ -1890,7 +1906,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn commit_as(&mut self, actor: SubjectId, invocation: DecisionInvocation) -> SubmitReceipt {
|
||||
fn commit_as(&mut self, actor: SubjectId, invocation: DecisionInvocation) -> CommitReceipt {
|
||||
let receipt = act(&mut self.kernel, actor, invocation).expect("the invocation commits");
|
||||
self.refresh();
|
||||
receipt
|
||||
|
|
@ -1899,7 +1915,7 @@ mod tests {
|
|||
fn admit(&mut self, ops: Vec<ComponentOp>) {
|
||||
let before = self.kernel.snapshot().unwrap();
|
||||
let receipt = submit_play(&mut self.kernel, &before, operations(ops));
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
self.refresh();
|
||||
}
|
||||
|
||||
|
|
@ -2094,10 +2110,7 @@ mod tests {
|
|||
// The chamber is inside it, so the same act commits and the deputy can
|
||||
// then levy there.
|
||||
let inside = bench.delegate(outsider, bench.civic.chamber);
|
||||
assert!(matches!(
|
||||
bench.commit_as(treasury, inside),
|
||||
SubmitReceipt::Applied(_)
|
||||
));
|
||||
assert!(bench.commit_as(treasury, inside).resulting_revision > 0);
|
||||
assert!(
|
||||
bench
|
||||
.try_as(outsider, &bench.levy(bench.civic.farmer, 1))
|
||||
|
|
@ -2151,10 +2164,7 @@ mod tests {
|
|||
|
||||
// The treasury's own `levy` grant over the hall covers the hall, so
|
||||
// the treasury may strip its own grant, and the ledger loses it.
|
||||
assert!(matches!(
|
||||
bench.commit_as(treasury, bench.revoke(treasury, hall)),
|
||||
SubmitReceipt::Applied(_)
|
||||
));
|
||||
assert!(bench.commit_as(treasury, bench.revoke(treasury, hall)).resulting_revision > 0);
|
||||
assert!(
|
||||
!bench
|
||||
.kernel
|
||||
|
|
@ -2202,10 +2212,7 @@ mod tests {
|
|||
.map(|position| position.place),
|
||||
Some(chamber)
|
||||
);
|
||||
assert!(matches!(
|
||||
bench.commit_as(treasury, bench.deploy(farmer, passage)),
|
||||
SubmitReceipt::Applied(_)
|
||||
));
|
||||
assert!(bench.commit_as(treasury, bench.deploy(farmer, passage)).resulting_revision > 0);
|
||||
assert_eq!(
|
||||
bench
|
||||
.kernel
|
||||
|
|
@ -2235,10 +2242,7 @@ mod tests {
|
|||
);
|
||||
|
||||
let farmer = bench.civic.farmer;
|
||||
assert!(matches!(
|
||||
bench.commit_as(farmer, petition.clone()),
|
||||
SubmitReceipt::Applied(_)
|
||||
));
|
||||
assert!(bench.commit_as(farmer, petition.clone()).resulting_revision > 0);
|
||||
let event = bench
|
||||
.kernel
|
||||
.state
|
||||
|
|
@ -2351,24 +2355,8 @@ mod tests {
|
|||
|
||||
// The treasury commands the hall, and the passage has both endpoints
|
||||
// under it. The draw decides whether the interdiction lands.
|
||||
let closing = (0..256)
|
||||
.map(|_| CommandId::issue())
|
||||
.find(|candidate| {
|
||||
draw_once(&bench.kernel.state, *candidate, treasury, &sanction)
|
||||
.expect("the invocation is admissible")
|
||||
.band
|
||||
== 0
|
||||
})
|
||||
.expect("a two-band entry reaches its first band over 256 command ids");
|
||||
let receipt = act_command(
|
||||
&mut bench.kernel,
|
||||
closing,
|
||||
play_caller(),
|
||||
treasury,
|
||||
sanction,
|
||||
)
|
||||
.expect("the sanction commits");
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
let receipt = act_drawing(&mut bench.kernel, treasury, &sanction, 0);
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
bench.refresh();
|
||||
assert!(!bench.kernel.state.edges[&passage].is_open());
|
||||
|
||||
|
|
@ -2386,10 +2374,7 @@ mod tests {
|
|||
}],
|
||||
None,
|
||||
);
|
||||
assert!(matches!(
|
||||
bench.commit_as(treasury, appoint),
|
||||
SubmitReceipt::Applied(_)
|
||||
));
|
||||
assert!(bench.commit_as(treasury, appoint).resulting_revision > 0);
|
||||
assert_eq!(
|
||||
bench.kernel.state.selection[&treasury][&office("bailiff")].incumbent,
|
||||
Some(farmer)
|
||||
|
|
@ -2404,7 +2389,7 @@ mod tests {
|
|||
bench: &mut Civics,
|
||||
actor: SubjectId,
|
||||
invocation: DecisionInvocation,
|
||||
) -> Result<SubmitReceipt, KernelError> {
|
||||
) -> Result<CommitReceipt, KernelError> {
|
||||
act(&mut bench.kernel, actor, invocation)
|
||||
}
|
||||
|
||||
|
|
@ -2587,7 +2572,6 @@ mod tests {
|
|||
let caller = play_caller();
|
||||
let envelope = command(
|
||||
&bench.active,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::Act {
|
||||
actor: treasury,
|
||||
|
|
@ -2601,7 +2585,7 @@ mod tests {
|
|||
.kernel
|
||||
.submit(envelope, &AuthenticatedCaller::fixture(caller))
|
||||
.expect("the act commits");
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
bench.refresh();
|
||||
let WorldEffect::Acted { event, .. } = first else {
|
||||
panic!("an acted effect");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::patch::{
|
|||
};
|
||||
use crate::tests::{auth_principal, command, creation, owner};
|
||||
use crate::{
|
||||
CallerId, CommandBody, CommandId, CreateWorld, KernelError, SubjectKind, SubmitReceipt,
|
||||
CallerId, CommandBody, CommandId, CreateWorld, KernelError, SubjectKind, CommitReceipt,
|
||||
WorldKernel, WorldPatch,
|
||||
};
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ fn grammar_with(extra: &[(&str, GrammarVerb)]) -> GrammarBinding {
|
|||
}
|
||||
|
||||
fn bound(grammar: Option<GrammarBinding>, title: &str) -> CreateWorld {
|
||||
let mut world = creation(CommandId::new(), title);
|
||||
let mut world = creation(title);
|
||||
world.grammar = grammar;
|
||||
world
|
||||
}
|
||||
|
|
@ -96,12 +96,11 @@ fn create(world: CreateWorld) -> (tempfile::TempDir, Result<WorldKernel, KernelE
|
|||
(directory, result)
|
||||
}
|
||||
|
||||
fn admit(kernel: &mut WorldKernel, patch: WorldPatch) -> Result<SubmitReceipt, KernelError> {
|
||||
fn admit(kernel: &mut WorldKernel, patch: WorldPatch) -> Result<CommitReceipt, KernelError> {
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
kernel.submit(
|
||||
command(
|
||||
&snapshot,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
CommandBody::AdmitPatch {
|
||||
patch,
|
||||
|
|
@ -151,7 +150,7 @@ fn grammar_world_refuses_an_affordance_kind_outside_the_grammar() {
|
|||
not_in_grammar("wave")
|
||||
);
|
||||
let receipt = admit(&mut kernel, patch_of(vec![declare("hail", "hail", &[])])).unwrap();
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -203,7 +202,7 @@ fn grammar_world_refuses_a_role_signature_the_grammar_does_not_carry() {
|
|||
)]),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -235,7 +234,7 @@ fn each_grammar_referent_kind_admits_exactly_its_own_kernel_kind() {
|
|||
);
|
||||
if offered == own {
|
||||
assert!(
|
||||
matches!(result, Ok(SubmitReceipt::Applied(_))),
|
||||
matches!(result, Ok(_)),
|
||||
"{referent:?} refused its own kind"
|
||||
);
|
||||
} else {
|
||||
|
|
@ -298,7 +297,7 @@ fn unbound_world_keeps_the_open_catalog() {
|
|||
patch_of(vec![declare("beacon", "beacon", &[])]),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
assert!(snapshot.grammar.is_none());
|
||||
assert!(snapshot.affordances.len() >= 4);
|
||||
|
|
@ -487,12 +486,11 @@ fn submit_as(
|
|||
kernel: &mut WorldKernel,
|
||||
caller: CallerId,
|
||||
patch: WorldPatch,
|
||||
) -> Result<SubmitReceipt, KernelError> {
|
||||
) -> Result<CommitReceipt, KernelError> {
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
kernel.submit(
|
||||
command(
|
||||
&snapshot,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::AdmitPatch { patch },
|
||||
),
|
||||
|
|
@ -576,7 +574,7 @@ fn play_refuses_outside_the_grammar_after_the_revision_has_moved() {
|
|||
patch_of(vec![declare("hail", "hail", &[])]),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -636,7 +634,7 @@ fn an_effect_resolved_elsewhere_cannot_install_an_entry_outside_the_grammar() {
|
|||
let resolve = |kind: &str, roles: &[(&str, RefKind)]| {
|
||||
crate::patch::resolve_patch(
|
||||
&twin,
|
||||
CommandId::new(),
|
||||
CommandId::issue(),
|
||||
&patch_of(vec![declare("probe", kind, roles)]),
|
||||
)
|
||||
.expect("the unbound twin admits any canonical kind")
|
||||
|
|
@ -650,7 +648,7 @@ fn an_effect_resolved_elsewhere_cannot_install_an_entry_outside_the_grammar() {
|
|||
let catalog = state.affordance_catalog.len();
|
||||
let result = crate::apply_effect(
|
||||
&mut state,
|
||||
CommandId::new(),
|
||||
CommandId::issue(),
|
||||
&CallerId::Play,
|
||||
&crate::WorldEffect::PatchAdmitted {
|
||||
resolved,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::patch::{
|
|||
use crate::tests::{auth_principal, command, creation, owner};
|
||||
use crate::{
|
||||
CallerId, CommandBody, CommandId, CreateWorld, EntityId, KernelError,
|
||||
SubjectDeclaration, SubjectKind, SubmitReceipt,
|
||||
SubjectDeclaration, SubjectKind, CommitReceipt,
|
||||
WorldKernel, WorldPatch,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
|
|
@ -24,7 +24,7 @@ fn alpha() -> ImportKey {
|
|||
|
||||
/// The fixture genesis with its witness imported from `alpha()`.
|
||||
fn keyed_creation(title: &str) -> CreateWorld {
|
||||
let mut world = creation(CommandId::new(), title);
|
||||
let mut world = creation(title);
|
||||
for declaration in &mut world.patch.declarations {
|
||||
if let Declaration::Subject(subject) = declaration
|
||||
&& subject.handle == DraftHandle::new("persona")
|
||||
|
|
@ -71,12 +71,11 @@ fn submit_as(
|
|||
kernel: &mut WorldKernel,
|
||||
caller: CallerId,
|
||||
patch: WorldPatch,
|
||||
) -> Result<SubmitReceipt, KernelError> {
|
||||
) -> Result<CommitReceipt, KernelError> {
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
kernel.submit(
|
||||
command(
|
||||
&snapshot,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::AdmitPatch { patch },
|
||||
),
|
||||
|
|
@ -132,7 +131,7 @@ fn keys_in(kernel: &WorldKernel) -> Vec<ImportKey> {
|
|||
#[test]
|
||||
fn one_patch_cannot_declare_two_subjects_with_one_import_key() {
|
||||
// At genesis.
|
||||
let mut world = creation(CommandId::new(), "Twins");
|
||||
let mut world = creation("Twins");
|
||||
for declaration in &mut world.patch.declarations {
|
||||
if let Declaration::Subject(subject) = declaration
|
||||
&& (subject.handle == DraftHandle::new("persona")
|
||||
|
|
@ -236,7 +235,7 @@ fn a_held_import_key_is_refused_at_every_door_after_the_revision_has_moved() {
|
|||
patch_of(vec![keyed("fresh", Some(fresh.clone()), dead_end)]),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
let again = submit_as(
|
||||
&mut kernel,
|
||||
CallerId::Play,
|
||||
|
|
@ -404,7 +403,7 @@ fn the_subjects_map_refuses_a_second_subject_for_one_key_even_when_resolved_else
|
|||
let resolve = |handle: &str| {
|
||||
crate::patch::resolve_patch(
|
||||
&kernel.state,
|
||||
CommandId::new(),
|
||||
CommandId::issue(),
|
||||
&patch_of(vec![keyed(
|
||||
handle,
|
||||
Some(key("aetheria.ship", "Omega")),
|
||||
|
|
@ -421,7 +420,7 @@ fn the_subjects_map_refuses_a_second_subject_for_one_key_even_when_resolved_else
|
|||
};
|
||||
crate::apply_effect(
|
||||
&mut state,
|
||||
CommandId::new(),
|
||||
CommandId::issue(),
|
||||
&CallerId::Play,
|
||||
&effect(first),
|
||||
)
|
||||
|
|
@ -429,7 +428,7 @@ fn the_subjects_map_refuses_a_second_subject_for_one_key_even_when_resolved_else
|
|||
assert_eq!(state.subjects.len(), before + 1);
|
||||
let result = crate::apply_effect(
|
||||
&mut state,
|
||||
CommandId::new(),
|
||||
CommandId::issue(),
|
||||
&CallerId::Play,
|
||||
&effect(second),
|
||||
);
|
||||
|
|
@ -452,7 +451,7 @@ fn contains(haystack: &[u8], needle: &[u8]) -> bool {
|
|||
fn keyless_world_digests_unchanged() {
|
||||
// A subject nobody imported serialises without the field at all, so every
|
||||
// digest written before keys existed is the digest of the same bytes.
|
||||
let (_dir, kernel) = create(creation(CommandId::new(), "Keyless"));
|
||||
let (_dir, kernel) = create(creation("Keyless"));
|
||||
let kernel = kernel.unwrap();
|
||||
let state = rmp_serde::to_vec_named(&kernel.state).unwrap();
|
||||
assert!(
|
||||
|
|
@ -616,7 +615,7 @@ fn admitting_a_resolved_effect_refuses_two_subjects_with_one_key() {
|
|||
let resolve = || {
|
||||
crate::patch::resolve_patch(
|
||||
&kernel.state,
|
||||
CommandId::new(),
|
||||
CommandId::issue(),
|
||||
&patch_of(vec![
|
||||
keyed("first", Some(key("aetheria.ship", "Beta")), place),
|
||||
keyed("second", Some(key("aetheria.ship", "Gamma")), place),
|
||||
|
|
|
|||
|
|
@ -911,7 +911,7 @@ fn apply_committed_command(
|
|||
}
|
||||
apply_effect(
|
||||
state,
|
||||
command.id,
|
||||
command.id(),
|
||||
&commit.command.caller(),
|
||||
&expected_effect,
|
||||
)
|
||||
|
|
@ -983,6 +983,15 @@ mod tests {
|
|||
value: u8,
|
||||
}
|
||||
|
||||
/// The commit a forgery test rewrites: the one the test just committed.
|
||||
pub(super) fn last_commit(commits: &mut BTreeMap<CommandId, WorldCommit>) -> &mut WorldCommit {
|
||||
commits.values_mut().max_by_key(|commit| commit.resulting_revision).unwrap()
|
||||
}
|
||||
|
||||
pub(super) fn genesis_commit(commits: &mut BTreeMap<CommandId, WorldCommit>) -> &mut WorldCommit {
|
||||
commits.values_mut().min_by_key(|commit| commit.resulting_revision).unwrap()
|
||||
}
|
||||
|
||||
fn owner_patch(subject: SubjectDeclaration) -> WorldPatch {
|
||||
WorldPatch {
|
||||
declarations: vec![Declaration::Subject(subject)],
|
||||
|
|
@ -1010,7 +1019,6 @@ mod tests {
|
|||
let owner = PrincipalId::new("owner@example.test");
|
||||
let authenticated = AuthenticatedCaller::fixture(CallerId::Principal(owner.clone()));
|
||||
let creation = CreateWorld {
|
||||
id: CommandId::new(),
|
||||
owner: owner.clone(),
|
||||
title: "Before".into(),
|
||||
patch: owner_patch(SubjectDeclaration {
|
||||
|
|
@ -1025,11 +1033,9 @@ mod tests {
|
|||
};
|
||||
let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap();
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
let command_id = CommandId::new();
|
||||
kernel
|
||||
.submit(
|
||||
CommandEnvelope {
|
||||
id: command_id,
|
||||
world_id: snapshot.world_id,
|
||||
expected_revision: snapshot.revision,
|
||||
caller: CallerId::Play,
|
||||
|
|
@ -1043,7 +1049,7 @@ mod tests {
|
|||
|
||||
let mut command_forged_head = kernel.state.clone();
|
||||
let mut command_forged_commits = kernel.journal.commits.clone();
|
||||
let command_forged = command_forged_commits.get_mut(&command_id).unwrap();
|
||||
let command_forged = last_commit(&mut command_forged_commits);
|
||||
let CommittedCommand::WorldCommand(command) = &mut command_forged.command else {
|
||||
panic!("expected a world command");
|
||||
};
|
||||
|
|
@ -1060,7 +1066,7 @@ mod tests {
|
|||
|
||||
let mut caller_forged_head = kernel.state.clone();
|
||||
let mut caller_forged_commits = kernel.journal.commits.clone();
|
||||
let caller_forged = caller_forged_commits.get_mut(&command_id).unwrap();
|
||||
let caller_forged = last_commit(&mut caller_forged_commits);
|
||||
let CommittedCommand::WorldCommand(command) = &mut caller_forged.command else {
|
||||
panic!("expected a world command");
|
||||
};
|
||||
|
|
@ -1075,7 +1081,7 @@ mod tests {
|
|||
|
||||
let mut effect_forged_head = kernel.state.clone();
|
||||
let mut effect_forged_commits = kernel.journal.commits.clone();
|
||||
let effect_forged = effect_forged_commits.get_mut(&command_id).unwrap();
|
||||
let effect_forged = last_commit(&mut effect_forged_commits);
|
||||
let WorldEffect::TimeAdvanced { to, .. } = &mut effect_forged.effect else {
|
||||
panic!("expected a time effect");
|
||||
};
|
||||
|
|
@ -1096,7 +1102,6 @@ mod tests {
|
|||
let owner = PrincipalId::new("owner@example.test");
|
||||
let authenticated = AuthenticatedCaller::fixture(CallerId::Principal(owner.clone()));
|
||||
let creation = CreateWorld {
|
||||
id: CommandId::new(),
|
||||
owner: owner.clone(),
|
||||
title: "Kharad".into(),
|
||||
patch: owner_patch(SubjectDeclaration {
|
||||
|
|
@ -1111,11 +1116,9 @@ mod tests {
|
|||
};
|
||||
let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap();
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
let command_id = CommandId::new();
|
||||
kernel
|
||||
.submit(
|
||||
CommandEnvelope {
|
||||
id: command_id,
|
||||
world_id: snapshot.world_id,
|
||||
expected_revision: snapshot.revision,
|
||||
caller: CallerId::Play,
|
||||
|
|
@ -1148,7 +1151,7 @@ mod tests {
|
|||
|
||||
let mut forged_head = kernel.state.clone();
|
||||
let mut forged_commits = kernel.journal.commits.clone();
|
||||
let forged = forged_commits.get_mut(&command_id).unwrap();
|
||||
let forged = last_commit(&mut forged_commits);
|
||||
let WorldEffect::PatchAdmitted { resolved, .. } = &mut forged.effect else {
|
||||
panic!("expected an admitted patch effect");
|
||||
};
|
||||
|
|
@ -1255,7 +1258,7 @@ mod tests {
|
|||
let directory = tempfile::tempdir().unwrap();
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
directory.path().join("world.cc"),
|
||||
creation(CommandId::new(), "Clock History"),
|
||||
creation("Clock History"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -1392,18 +1395,16 @@ mod tests {
|
|||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Chronicle"),
|
||||
crate::tests::creation("Chronicle"),
|
||||
&authenticated,
|
||||
)
|
||||
.unwrap();
|
||||
let active = kernel.snapshot().unwrap();
|
||||
let command_id = CommandId::new();
|
||||
let caller = CallerId::Play;
|
||||
kernel
|
||||
.submit(
|
||||
command(
|
||||
&active,
|
||||
command_id,
|
||||
caller.clone(),
|
||||
CommandBody::AdvanceTime {
|
||||
minutes: TickMinutes::new(30).unwrap(),
|
||||
|
|
@ -1415,7 +1416,7 @@ mod tests {
|
|||
|
||||
let mut forged_head = kernel.state.clone();
|
||||
let mut forged_commits = kernel.journal.commits.clone();
|
||||
let forged = forged_commits.get_mut(&command_id).unwrap();
|
||||
let forged = last_commit(&mut forged_commits);
|
||||
let WorldEffect::TimeAdvanced { to, .. } = &mut forged.effect else {
|
||||
panic!("expected a time-advanced effect");
|
||||
};
|
||||
|
|
@ -1440,18 +1441,16 @@ mod tests {
|
|||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Kharad"),
|
||||
crate::tests::creation("Kharad"),
|
||||
&authenticated,
|
||||
)
|
||||
.unwrap();
|
||||
let topology = admit_topology(&mut kernel);
|
||||
let active = kernel.snapshot().unwrap();
|
||||
let command_id = CommandId::new();
|
||||
kernel
|
||||
.submit(
|
||||
command(
|
||||
&active,
|
||||
command_id,
|
||||
CallerId::Play,
|
||||
CommandBody::AdmitPatch {
|
||||
patch: WorldPatch {
|
||||
|
|
@ -1470,7 +1469,7 @@ mod tests {
|
|||
|
||||
let mut forged_head = kernel.state.clone();
|
||||
let mut forged_commits = kernel.journal.commits.clone();
|
||||
let forged = forged_commits.get_mut(&command_id).unwrap();
|
||||
let forged = last_commit(&mut forged_commits);
|
||||
let WorldEffect::PatchAdmitted { resolved, .. } = &mut forged.effect else {
|
||||
panic!("expected an admitted patch effect");
|
||||
};
|
||||
|
|
@ -1511,7 +1510,7 @@ mod tests {
|
|||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "ForgedDecision"),
|
||||
crate::tests::creation("ForgedDecision"),
|
||||
&authenticated,
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -1520,7 +1519,6 @@ mod tests {
|
|||
let active = kernel.snapshot().unwrap();
|
||||
let entry = affordance_named(&active, kind);
|
||||
let caller = play_caller();
|
||||
let command_id = CommandId::new();
|
||||
let role = |name: &str, target| RoleBinding {
|
||||
role: crate::Role(name.into()),
|
||||
target,
|
||||
|
|
@ -1529,7 +1527,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&active,
|
||||
command_id,
|
||||
caller.clone(),
|
||||
CommandBody::Act {
|
||||
actor: custody.holder,
|
||||
|
|
@ -1559,7 +1556,7 @@ mod tests {
|
|||
|
||||
let mut forged_head = kernel.state.clone();
|
||||
let mut forged_commits = kernel.journal.commits.clone();
|
||||
let forged = forged_commits.get_mut(&command_id).unwrap();
|
||||
let forged = last_commit(&mut forged_commits);
|
||||
let WorldEffect::Acted { event, .. } = &mut forged.effect else {
|
||||
panic!("expected an acted effect");
|
||||
};
|
||||
|
|
@ -1602,9 +1599,7 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let owner = PrincipalId::new("owner@example.test");
|
||||
let authenticated = AuthenticatedCaller::fixture(CallerId::Principal(owner.clone()));
|
||||
let creation_id = CommandId::new();
|
||||
let creation = CreateWorld {
|
||||
id: creation_id,
|
||||
owner: owner.clone(),
|
||||
title: "Admitted".into(),
|
||||
patch: owner_patch(SubjectDeclaration {
|
||||
|
|
@ -1620,7 +1615,7 @@ mod tests {
|
|||
let (kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap();
|
||||
let mut forged_head = kernel.state.clone();
|
||||
let mut forged_commits = kernel.journal.commits.clone();
|
||||
let forged = forged_commits.get_mut(&creation_id).unwrap();
|
||||
let forged = genesis_commit(&mut forged_commits);
|
||||
let CommittedCommand::CreateWorld(command) = &mut forged.command else {
|
||||
panic!("expected genesis creation command");
|
||||
};
|
||||
|
|
@ -1635,7 +1630,7 @@ mod tests {
|
|||
|
||||
let mut binding_forged_head = kernel.state.clone();
|
||||
let mut binding_forged_commits = kernel.journal.commits.clone();
|
||||
let binding_forged = binding_forged_commits.get_mut(&creation_id).unwrap();
|
||||
let binding_forged = genesis_commit(&mut binding_forged_commits);
|
||||
let WorldEffect::WorldCreated { resolved, .. } = &mut binding_forged.effect else {
|
||||
panic!("expected genesis effect");
|
||||
};
|
||||
|
|
@ -1662,7 +1657,7 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Forged Rows"),
|
||||
crate::tests::creation("Forged Rows"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -1743,7 +1738,7 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Old Store"),
|
||||
crate::tests::creation("Old Store"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -1789,14 +1784,14 @@ mod tests {
|
|||
use crate::tests::{affordance_named, civic_world, command, owner, play_caller};
|
||||
use crate::{
|
||||
DecisionInvocation, Magnitude, ProposedEffect, Quantity, Role, RoleBinding,
|
||||
SubmitReceipt, Target,
|
||||
Target,
|
||||
};
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Replayed Levy"),
|
||||
crate::tests::creation("Replayed Levy"),
|
||||
&crate::tests::auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -1804,7 +1799,6 @@ mod tests {
|
|||
let caller = play_caller();
|
||||
let envelope = command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::Act {
|
||||
actor: civic.treasury,
|
||||
|
|
@ -1846,10 +1840,8 @@ mod tests {
|
|||
assert_eq!(replayed.band, event.band);
|
||||
assert_eq!(replayed.effects, event.effects);
|
||||
assert!(matches!(
|
||||
reopened
|
||||
.submit(envelope, &AuthenticatedCaller::fixture(caller))
|
||||
.unwrap(),
|
||||
SubmitReceipt::AlreadyApplied(_)
|
||||
reopened .submit(envelope, &AuthenticatedCaller::fixture(caller)),
|
||||
Err(KernelError::RevisionMismatch { .. })
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -1869,7 +1861,7 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Forged Civics"),
|
||||
crate::tests::creation("Forged Civics"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -1977,7 +1969,7 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Pre-Authority"),
|
||||
crate::tests::creation("Pre-Authority"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2028,13 +2020,13 @@ mod tests {
|
|||
LEVY_KIND, auth_principal, civic_world, operations, over_subject, owner, reject_play,
|
||||
submit_play,
|
||||
};
|
||||
use crate::{ComponentOp, Mismatch, SubmitReceipt};
|
||||
use crate::{ComponentOp, Mismatch};
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
crate::tests::creation(CommandId::new(), "Moving Civics"),
|
||||
crate::tests::creation("Moving Civics"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2042,10 +2034,7 @@ mod tests {
|
|||
|
||||
let admit = |kernel: &mut WorldKernel, ops: Vec<ComponentOp>| {
|
||||
let before = kernel.snapshot().unwrap();
|
||||
assert!(matches!(
|
||||
submit_play(kernel, &before, operations(ops)),
|
||||
SubmitReceipt::Applied(_)
|
||||
));
|
||||
assert!(submit_play(kernel, &before, operations(ops)).resulting_revision > 0);
|
||||
verify_state_shape(&kernel.state).expect("the committed store keeps its shape");
|
||||
assert!(
|
||||
crate::overlapping_holder(&kernel.state).is_none(),
|
||||
|
|
@ -2108,9 +2097,10 @@ mod tests {
|
|||
#[cfg(test)]
|
||||
mod custody_tests {
|
||||
use super::*;
|
||||
use super::tests::last_commit;
|
||||
use crate::{
|
||||
CallerId, CommandBody, CommandId, ComponentOp, DependencyRef, EntityKind, Quantity, Ref,
|
||||
SubmitReceipt, WorldKernel, WorldPatch,
|
||||
CallerId, CommandBody, ComponentOp, DependencyRef, EntityKind, Quantity, Ref,
|
||||
WorldKernel, WorldPatch,
|
||||
tests::{admit_custody, admit_topology, auth_principal, command, creation, owner},
|
||||
};
|
||||
|
||||
|
|
@ -2123,7 +2113,7 @@ mod custody_tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) =
|
||||
WorldKernel::create(&path, creation(CommandId::new(), "Replay"), &authenticated)
|
||||
WorldKernel::create(&path, creation("Replay"), &authenticated)
|
||||
.unwrap();
|
||||
let topology = admit_topology(&mut kernel);
|
||||
let custody = admit_custody(&mut kernel, &topology);
|
||||
|
|
@ -2131,7 +2121,6 @@ mod custody_tests {
|
|||
|
||||
let envelope = command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
CommandBody::AdmitPatch {
|
||||
patch: WorldPatch {
|
||||
|
|
@ -2146,21 +2135,17 @@ mod custody_tests {
|
|||
},
|
||||
},
|
||||
);
|
||||
let SubmitReceipt::Applied(receipt) =
|
||||
kernel.submit(envelope.clone(), &crate::AuthenticatedCaller::verified_play()).unwrap()
|
||||
else {
|
||||
panic!("expected an applied transfer");
|
||||
};
|
||||
kernel.submit(envelope.clone(), &crate::AuthenticatedCaller::verified_play()).unwrap();
|
||||
let accepted = kernel.snapshot().unwrap();
|
||||
let world_id = accepted.world_id;
|
||||
drop(kernel);
|
||||
|
||||
let mut reopened = WorldKernel::open(&path, world_id).unwrap();
|
||||
assert_eq!(reopened.snapshot().unwrap(), accepted);
|
||||
assert_eq!(
|
||||
reopened.submit(envelope, &crate::AuthenticatedCaller::verified_play()).unwrap(),
|
||||
SubmitReceipt::AlreadyApplied(receipt)
|
||||
);
|
||||
assert!(matches!(
|
||||
reopened.submit(envelope, &crate::AuthenticatedCaller::verified_play()),
|
||||
Err(KernelError::RevisionMismatch { .. })
|
||||
));
|
||||
}
|
||||
|
||||
/// Replay recomputes `reduce`, so the band and the lowered operations are
|
||||
|
|
@ -2176,7 +2161,7 @@ mod custody_tests {
|
|||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "ActionReplay"),
|
||||
creation("ActionReplay"),
|
||||
&authenticated,
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2192,7 +2177,6 @@ mod custody_tests {
|
|||
};
|
||||
let envelope = command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
caller.clone(),
|
||||
CommandBody::Act {
|
||||
actor: custody.holder,
|
||||
|
|
@ -2214,12 +2198,9 @@ mod custody_tests {
|
|||
},
|
||||
);
|
||||
let authenticated_controller = AuthenticatedCaller::fixture(caller);
|
||||
let SubmitReceipt::Applied(receipt) = kernel
|
||||
kernel
|
||||
.submit(envelope.clone(), &authenticated_controller)
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("expected an applied invocation");
|
||||
};
|
||||
.unwrap();
|
||||
let accepted = kernel.snapshot().unwrap();
|
||||
let committed = kernel
|
||||
.state
|
||||
|
|
@ -2237,12 +2218,10 @@ mod custody_tests {
|
|||
reopened.state.events.last().expect("the replayed event"),
|
||||
&committed
|
||||
);
|
||||
assert_eq!(
|
||||
reopened
|
||||
.submit(envelope, &authenticated_controller)
|
||||
.unwrap(),
|
||||
SubmitReceipt::AlreadyApplied(receipt)
|
||||
);
|
||||
assert!(matches!(
|
||||
reopened .submit(envelope, &authenticated_controller),
|
||||
Err(KernelError::RevisionMismatch { .. })
|
||||
));
|
||||
}
|
||||
|
||||
/// A store written at the pass-2 schema is refused outright. There is no
|
||||
|
|
@ -2275,7 +2254,7 @@ mod custody_tests {
|
|||
let directory = tempfile::tempdir().unwrap();
|
||||
let (kernel, _) = WorldKernel::create(
|
||||
directory.path().join("world.cc"),
|
||||
creation(CommandId::new(), "Titled"),
|
||||
creation("Titled"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2302,7 +2281,7 @@ mod custody_tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "GrantRows"),
|
||||
creation("GrantRows"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2348,7 +2327,7 @@ mod custody_tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "ActedChain"),
|
||||
creation("ActedChain"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2392,13 +2371,13 @@ mod custody_tests {
|
|||
/// state row and commit row each on their own: reverting either constant
|
||||
/// to v8 would let its half of the store in.
|
||||
#[test]
|
||||
fn v9_state_and_commit_rows_are_refused() {
|
||||
fn ghostlight_state_and_commit_rows_are_refused() {
|
||||
use crate::tests::{act, auth_principal, creation, first_grant, owner, speak};
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
directory.path().join("world.cc"),
|
||||
creation(CommandId::new(), "SchemaV9"),
|
||||
creation("SchemaV9"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2415,8 +2394,8 @@ mod custody_tests {
|
|||
let state_row = |schema: &str| {
|
||||
envelope(STATE_ROW, schema, kernel.state.world_id.key(), &kernel.state).unwrap()
|
||||
};
|
||||
assert_eq!(STATE_SCHEMA, "ghostlight.world_state.consumer.v10");
|
||||
assert_eq!(COMMIT_SCHEMA, "ghostlight.world_commit.consumer.v10");
|
||||
assert_eq!(STATE_SCHEMA, "aetherlight.world_state.v1");
|
||||
assert_eq!(COMMIT_SCHEMA, "aetherlight.world_commit.v1");
|
||||
recover(
|
||||
[commit_rows(COMMIT_SCHEMA), vec![state_row(STATE_SCHEMA)]].concat(),
|
||||
None,
|
||||
|
|
@ -2425,17 +2404,17 @@ mod custody_tests {
|
|||
|
||||
for (what, rows) in [
|
||||
(
|
||||
"v9 state row",
|
||||
"ghostlight state row",
|
||||
[
|
||||
commit_rows(COMMIT_SCHEMA),
|
||||
vec![state_row("ghostlight.world_state.consumer.v9")],
|
||||
vec![state_row("ghostlight.world_state.consumer.v10")],
|
||||
]
|
||||
.concat(),
|
||||
),
|
||||
(
|
||||
"v9 commit rows",
|
||||
"ghostlight commit rows",
|
||||
[
|
||||
commit_rows("ghostlight.world_commit.consumer.v9"),
|
||||
commit_rows("ghostlight.world_commit.consumer.v10"),
|
||||
vec![state_row(STATE_SCHEMA)],
|
||||
]
|
||||
.concat(),
|
||||
|
|
@ -2462,7 +2441,7 @@ mod custody_tests {
|
|||
let directory = tempfile::tempdir().unwrap();
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
directory.path().join("world.cc"),
|
||||
creation(CommandId::new(), "SilentForgery"),
|
||||
creation("SilentForgery"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2520,7 +2499,7 @@ mod custody_tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) =
|
||||
WorldKernel::create(&path, creation(CommandId::new(), "Shape"), &authenticated)
|
||||
WorldKernel::create(&path, creation("Shape"), &authenticated)
|
||||
.unwrap();
|
||||
let topology = admit_topology(&mut kernel);
|
||||
let custody = admit_custody(&mut kernel, &topology);
|
||||
|
|
@ -2579,7 +2558,7 @@ mod custody_tests {
|
|||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "EveryOperation"),
|
||||
creation("EveryOperation"),
|
||||
&authenticated,
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2591,7 +2570,6 @@ mod custody_tests {
|
|||
|
||||
let envelope = command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
CommandBody::AdmitPatch {
|
||||
patch: WorldPatch {
|
||||
|
|
@ -2627,11 +2605,7 @@ mod custody_tests {
|
|||
},
|
||||
},
|
||||
);
|
||||
let SubmitReceipt::Applied(receipt) =
|
||||
kernel.submit(envelope.clone(), &crate::AuthenticatedCaller::verified_play()).unwrap()
|
||||
else {
|
||||
panic!("expected an applied custody patch");
|
||||
};
|
||||
kernel.submit(envelope.clone(), &crate::AuthenticatedCaller::verified_play()).unwrap();
|
||||
let accepted = kernel.snapshot().unwrap();
|
||||
let holdings = kernel.state.holdings.clone();
|
||||
let dependencies = kernel.state.dependencies.clone();
|
||||
|
|
@ -2644,10 +2618,10 @@ mod custody_tests {
|
|||
assert_eq!(reopened.state.holdings, holdings);
|
||||
assert_eq!(reopened.state.dependencies, dependencies);
|
||||
assert_eq!(reopened.state.state_digest, digest);
|
||||
assert_eq!(
|
||||
reopened.submit(envelope, &crate::AuthenticatedCaller::verified_play()).unwrap(),
|
||||
SubmitReceipt::AlreadyApplied(receipt)
|
||||
);
|
||||
assert!(matches!(
|
||||
reopened.submit(envelope, &crate::AuthenticatedCaller::verified_play()),
|
||||
Err(KernelError::RevisionMismatch { .. })
|
||||
));
|
||||
}
|
||||
|
||||
/// Soul: a dependency naming a target of the wrong kind, or no canonical
|
||||
|
|
@ -2660,7 +2634,7 @@ mod custody_tests {
|
|||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "DependencyShape"),
|
||||
creation("DependencyShape"),
|
||||
&authenticated,
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2704,7 +2678,7 @@ mod custody_tests {
|
|||
|
||||
/// A world with one routine, one past-due goal, and a commit chain that
|
||||
/// reaches them: the fixture the two clock-forgery checks below need.
|
||||
fn ticking_world(path: &std::path::Path) -> (WorldKernel, super::super::SubjectId, CommandId) {
|
||||
fn ticking_world(path: &std::path::Path) -> (WorldKernel, super::super::SubjectId) {
|
||||
use crate::tests::{auth_principal, command, operations, owner};
|
||||
use crate::{
|
||||
AuthenticatedCaller, CallerId, CommandBody, CommitmentKind, ComponentOp,
|
||||
|
|
@ -2714,7 +2688,7 @@ mod custody_tests {
|
|||
let authenticated = auth_principal(owner());
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
path,
|
||||
crate::tests::creation(CommandId::new(), "Ticking"),
|
||||
crate::tests::creation("Ticking"),
|
||||
&authenticated,
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -2725,7 +2699,6 @@ mod custody_tests {
|
|||
.submit(
|
||||
command(
|
||||
&snapshot,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
operations(vec![
|
||||
ComponentOp::CreateCommitment {
|
||||
|
|
@ -2752,14 +2725,12 @@ mod custody_tests {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let tick_id = CommandId::new();
|
||||
let caller = CallerId::Play;
|
||||
let snapshot = kernel.snapshot().unwrap();
|
||||
kernel
|
||||
.submit(
|
||||
command(
|
||||
&snapshot,
|
||||
tick_id,
|
||||
caller.clone(),
|
||||
CommandBody::AdvanceTime {
|
||||
minutes: TickMinutes::new(30).unwrap(),
|
||||
|
|
@ -2768,7 +2739,7 @@ mod custody_tests {
|
|||
&AuthenticatedCaller::fixture(caller),
|
||||
)
|
||||
.unwrap();
|
||||
(kernel, subject, tick_id)
|
||||
(kernel, subject)
|
||||
}
|
||||
|
||||
/// Soul falsification: the replay gate and the `apply_effect` gate are two
|
||||
|
|
@ -2781,11 +2752,12 @@ mod custody_tests {
|
|||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("world.cc");
|
||||
let (kernel, subject, tick_id) = ticking_world(&path);
|
||||
let (kernel, subject) = ticking_world(&path);
|
||||
let WorldEffect::TimeAdvanced { motion, .. } = &kernel
|
||||
.journal
|
||||
.commits
|
||||
.get(&tick_id)
|
||||
.values()
|
||||
.max_by_key(|commit| commit.resulting_revision)
|
||||
.expect("the tick's commit")
|
||||
.effect
|
||||
else {
|
||||
|
|
@ -2797,7 +2769,7 @@ mod custody_tests {
|
|||
let forge = |rewrite: fn(&mut crate::Motion)| {
|
||||
let mut forged_head = kernel.state.clone();
|
||||
let mut forged_commits = kernel.journal.commits.clone();
|
||||
let forged = forged_commits.get_mut(&tick_id).unwrap();
|
||||
let forged = last_commit(&mut forged_commits);
|
||||
let WorldEffect::TimeAdvanced { motion, .. } = &mut forged.effect else {
|
||||
panic!("expected a time-advanced effect");
|
||||
};
|
||||
|
|
@ -2839,7 +2811,7 @@ mod custody_tests {
|
|||
fn soul_a_zero_period_is_refused_by_the_shape_check() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("world.cc");
|
||||
let (kernel, subject, _) = ticking_world(&path);
|
||||
let (kernel, subject) = ticking_world(&path);
|
||||
|
||||
// The forgery an in-crate caller cannot write: `TickMinutes::new`
|
||||
// refuses zero, and the field is private, so the only door is serde.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -5679,7 +5679,7 @@ mod tests {
|
|||
over_place, owner, reject_play, speak_entry, submit_play,
|
||||
};
|
||||
use crate::{
|
||||
AuthenticatedCaller, CallerId, CommandBody, CommandId, KernelError, SubmitReceipt, WorldKernel,
|
||||
AuthenticatedCaller, CallerId, CommandBody, CommandId, KernelError, WorldKernel,
|
||||
};
|
||||
|
||||
fn entity(handle: &str, label: &str, kind: EntityKind) -> Declaration {
|
||||
|
|
@ -6030,7 +6030,7 @@ mod tests {
|
|||
granting("verb"),
|
||||
])),
|
||||
);
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
assert_eq!(kernel.state.affordance_catalog.len(), entries_before + 1);
|
||||
assert_eq!(kernel.state.subjects.len(), subjects_before + 1);
|
||||
let granted = kernel
|
||||
|
|
@ -6106,7 +6106,7 @@ mod tests {
|
|||
fn draft_world(directory: &std::path::Path) -> WorldKernel {
|
||||
WorldKernel::create(
|
||||
directory.join("world.cc"),
|
||||
creation(CommandId::new(), "Kharad"),
|
||||
creation("Kharad"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.expect("draft world")
|
||||
|
|
@ -6126,7 +6126,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![institution(
|
||||
&kernel,
|
||||
|
|
@ -6183,7 +6182,7 @@ mod tests {
|
|||
),
|
||||
]);
|
||||
let receipt = submit_play(&mut kernel, &before, admit(patch));
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
|
||||
let after = kernel.snapshot().unwrap();
|
||||
assert_eq!(after.revision, before.revision + 1);
|
||||
|
|
@ -6236,7 +6235,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![
|
||||
entity("rhythm-tithe", "The Rhythm Tithe", EntityKind::Resource),
|
||||
|
|
@ -6290,7 +6288,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(broken),
|
||||
),
|
||||
|
|
@ -6336,7 +6333,7 @@ mod tests {
|
|||
}),
|
||||
]);
|
||||
let receipt = submit_play(&mut kernel, &before, admit(repaired));
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
assert_eq!(kernel.state.entities.len(), 3);
|
||||
}
|
||||
|
||||
|
|
@ -6350,7 +6347,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(patch_of(Vec::new())),
|
||||
),
|
||||
|
|
@ -6377,7 +6373,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![
|
||||
contained("yard", "The Cavity Yard", "road"),
|
||||
|
|
@ -6422,7 +6417,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![
|
||||
entity("yard", "The Cavity Yard", EntityKind::Place),
|
||||
|
|
@ -6462,7 +6456,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(WorldPatch {
|
||||
declarations: vec![Declaration::Route(RouteDeclaration {
|
||||
|
|
@ -6521,7 +6514,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(operations_of(vec![ComponentOp::Relocate {
|
||||
subject: Ref::Existing(topology.walker),
|
||||
|
|
@ -6572,7 +6564,7 @@ mod tests {
|
|||
])),
|
||||
);
|
||||
assert!(
|
||||
matches!(receipt, SubmitReceipt::Applied(_)),
|
||||
receipt.resulting_revision > 0,
|
||||
"a dead institution's lend must not collide with a fresh direct grant over the same ground"
|
||||
);
|
||||
}
|
||||
|
|
@ -6609,7 +6601,7 @@ mod tests {
|
|||
])),
|
||||
);
|
||||
assert!(
|
||||
matches!(delegated, SubmitReceipt::Applied(_)),
|
||||
delegated.resulting_revision > 0,
|
||||
"expected the delegation patch to apply, got {delegated:?}"
|
||||
);
|
||||
let after_delegation = kernel.snapshot().unwrap();
|
||||
|
|
@ -6654,7 +6646,7 @@ mod tests {
|
|||
via: Ref::Existing(topology.ramp),
|
||||
}])),
|
||||
);
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert!(receipt.resulting_revision > 0);
|
||||
assert_eq!(
|
||||
kernel.state.positions.get(&topology.walker),
|
||||
Some(&Position {
|
||||
|
|
@ -6681,7 +6673,7 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "Kharad"),
|
||||
creation("Kharad"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -6689,7 +6681,6 @@ mod tests {
|
|||
let active = kernel.snapshot().unwrap();
|
||||
let envelope = command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(operations_of(vec![ComponentOp::Relocate {
|
||||
subject: Ref::Existing(topology.walker),
|
||||
|
|
@ -6712,8 +6703,8 @@ mod tests {
|
|||
})
|
||||
);
|
||||
assert!(matches!(
|
||||
reopened.submit(envelope, &AuthenticatedCaller::verified_play()).unwrap(),
|
||||
SubmitReceipt::AlreadyApplied(_)
|
||||
reopened.submit(envelope, &AuthenticatedCaller::verified_play()),
|
||||
Err(KernelError::RevisionMismatch { .. })
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -6764,14 +6755,13 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "Kharad"),
|
||||
creation("Kharad"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
let before = kernel.snapshot().unwrap();
|
||||
let envelope = command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![
|
||||
entity("rhythm-road", "The Rhythm Road", EntityKind::Place),
|
||||
|
|
@ -6793,8 +6783,8 @@ mod tests {
|
|||
let mut reopened = WorldKernel::open(&path, world_id).unwrap();
|
||||
assert_eq!(reopened.snapshot().unwrap(), committed);
|
||||
assert!(matches!(
|
||||
reopened.submit(envelope, &AuthenticatedCaller::verified_play()).unwrap(),
|
||||
SubmitReceipt::AlreadyApplied(_)
|
||||
reopened.submit(envelope, &AuthenticatedCaller::verified_play()),
|
||||
Err(KernelError::RevisionMismatch { .. })
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -6831,7 +6821,7 @@ mod tests {
|
|||
.0;
|
||||
assert_ne!(admitted, genesis_human);
|
||||
|
||||
let command_id = CommandId::new();
|
||||
let command_id = CommandId::issue();
|
||||
let first = resolve_patch(&kernel.state, command_id, &patch).unwrap();
|
||||
let second = resolve_patch(&kernel.state, command_id, &patch).unwrap();
|
||||
assert_eq!(first, second);
|
||||
|
|
@ -6846,29 +6836,26 @@ mod tests {
|
|||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "Kharad"),
|
||||
creation("Kharad"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
let before = kernel.snapshot().unwrap();
|
||||
let command_id = CommandId::new();
|
||||
let handle = DraftHandle::new("rhythm-authority");
|
||||
let envelope = command(
|
||||
&before,
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![institution(
|
||||
&kernel,
|
||||
"rhythm-authority",
|
||||
"The Rhythm Authority",
|
||||
Some(Ref::Draft(DraftHandle::new("kharad-rhythm-road"))),
|
||||
)])),
|
||||
);
|
||||
let command_id = envelope.id();
|
||||
|
||||
let error = kernel
|
||||
.submit(
|
||||
command(
|
||||
&before,
|
||||
command_id,
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![institution(
|
||||
&kernel,
|
||||
"rhythm-authority",
|
||||
"The Rhythm Authority",
|
||||
Some(Ref::Draft(DraftHandle::new("kharad-rhythm-road"))),
|
||||
)])),
|
||||
),
|
||||
&AuthenticatedCaller::verified_play(),
|
||||
)
|
||||
.submit(envelope, &AuthenticatedCaller::verified_play())
|
||||
.unwrap_err();
|
||||
assert!(matches!(error, KernelError::PatchRejected(_)));
|
||||
|
||||
|
|
@ -6920,12 +6907,12 @@ mod tests {
|
|||
let directory = tempfile::tempdir().unwrap();
|
||||
let (kernel, _) = WorldKernel::create(
|
||||
&directory.path().join("world.cc"),
|
||||
creation(CommandId::new(), "DeriveId"),
|
||||
creation("DeriveId"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
let world_id = kernel.state.world_id;
|
||||
let command_id = CommandId::new();
|
||||
let command_id = CommandId::issue();
|
||||
let handle = DraftHandle::new("a-handle");
|
||||
assert_ne!(
|
||||
derive_id(SUBJECT_NAMESPACE, world_id, command_id, &handle, None),
|
||||
|
|
@ -6968,7 +6955,7 @@ mod tests {
|
|||
Some(Ref::Draft(DraftHandle::new("rhythm-road"))),
|
||||
),
|
||||
]);
|
||||
let resolved = resolve_patch(&kernel.state, CommandId::new(), &patch).unwrap();
|
||||
let resolved = resolve_patch(&kernel.state, CommandId::issue(), &patch).unwrap();
|
||||
let honest = super::super::WorldEffect::PatchAdmitted {
|
||||
resolved: resolved.clone(),
|
||||
};
|
||||
|
|
@ -7036,7 +7023,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&before,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(patch_of(vec![
|
||||
entity("hollow", "The Hollow", EntityKind::Place),
|
||||
|
|
@ -7088,7 +7074,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(operations_of(vec![ComponentOp::Relocate {
|
||||
subject: Ref::Existing(unplaced),
|
||||
|
|
@ -7109,7 +7094,6 @@ mod tests {
|
|||
.submit(
|
||||
command(
|
||||
&active,
|
||||
CommandId::new(),
|
||||
CallerId::Play,
|
||||
admit(operations_of(vec![
|
||||
ComponentOp::OpenRoute {
|
||||
|
|
|
|||
Loading…
Reference in a new issue