aetherlight: the journal is an in-memory commit list with export and open

The redb store, the state row, health and ownership checks, verify_append and
the retry paths are gone. WorldJournal holds the commits in revision order;
export() writes { schema: aetherlight.journal.v1, commits } as canonical named
messagepack and open(bytes) decodes canonically and replays through
verify_history, which now reads the slice and returns the head state it
derives. A genesis commit must carry WorldId::of(creation id). chrono,
cultcache-rs and tempfile leave the manifest; uuid v4 is dev-only. Tests build
worlds in memory and reopen from export(); forgery tests build exports.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-20 02:35:03 +01:00
commit 94a3c67d6d
8 changed files with 612 additions and 2098 deletions

View file

@ -1039,8 +1039,8 @@ mod tests {
shutter: EdgeId,
}
fn bench(directory: &std::path::Path, title: &str) -> Bench {
let mut kernel = custody_kernel(directory, title);
fn bench(title: &str) -> Bench {
let mut kernel = custody_kernel(title);
let (topology, custody, active) = custody_world(&mut kernel);
let carry = affordance_named(&active, "carry");
Bench {
@ -1184,8 +1184,7 @@ mod tests {
#[test]
fn a_missing_present_precondition_names_itself() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Present");
let bench = bench("Present");
let before = bench.kernel.state.clone();
// The clerk stands in the yard, so a Carry bound to the gate fails the
@ -1201,8 +1200,7 @@ mod tests {
#[test]
fn spending_more_than_held_fails_the_holds_precondition() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Holds");
let bench = bench("Holds");
let greedy = bench.variant(&bench.carry(1, bench.yard), "carry_greedy");
assert_eq!(
bench.rejections(&greedy),
@ -1222,8 +1220,7 @@ mod tests {
/// spends down to one ingot-equivalent, and `carry_holds` asks for one.
#[test]
fn holding_exactly_the_threshold_satisfies_holds() {
let directory = tempfile::tempdir().unwrap();
let mut bench = bench(directory.path(), "HoldsBoundary");
let mut bench = bench("HoldsBoundary");
for _ in 0..2 {
bench.commit(bench.carry(3, bench.yard));
bench.refresh();
@ -1245,8 +1242,7 @@ mod tests {
#[test]
fn a_reachable_precondition_reads_only_open_public_routes() {
let directory = tempfile::tempdir().unwrap();
let mut bench = bench(directory.path(), "Reachable");
let mut bench = bench("Reachable");
// Yard to gate over open public routes is the ramp (12) plus the span
// (7): the shutter is closed and the toll stair is restricted. A budget
// of NEAR_REACH covers only the shutter, FAR_REACH covers the two-hop
@ -1291,8 +1287,7 @@ mod tests {
#[test]
fn an_unbound_or_miskinded_role_is_rejected_with_the_complete_set() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Roles");
let bench = bench("Roles");
let mut invocation = bench.carry(1, bench.yard);
// Drop `recipient`, add an undeclared role, and bind `resource` to a
// place: one rejection carrying all three, sorted.
@ -1321,8 +1316,7 @@ mod tests {
#[test]
fn a_duplicated_or_unknown_binding_target_is_rejected() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Bindings");
let bench = bench("Bindings");
let mut twice = bench.carry(1, bench.yard);
twice
.bindings
@ -1348,8 +1342,7 @@ mod tests {
#[test]
fn a_magnitude_over_its_slot_ceiling_is_rejected_and_within_it_commits() {
let directory = tempfile::tempdir().unwrap();
let mut bench = bench(directory.path(), "Ceiling");
let mut bench = bench("Ceiling");
assert_eq!(
bench.rejections(&bench.carry(4, bench.yard)),
vec![ActionMismatch::MagnitudeOverCeiling { slot: 0 }]
@ -1370,8 +1363,7 @@ mod tests {
#[test]
fn a_magnitude_of_the_wrong_shape_or_zero_is_rejected() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Shape");
let bench = bench("Shape");
for magnitude in [Magnitude::Cost(Cost(2)), Magnitude::None] {
let mut invocation = bench.carry(1, bench.yard);
invocation.proposed[0].magnitude = magnitude;
@ -1388,8 +1380,7 @@ mod tests {
#[test]
fn every_slot_must_be_proposed_exactly_once() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Slots");
let bench = bench("Slots");
let mut missing = bench.carry(1, bench.yard);
missing.proposed.clear();
assert_eq!(
@ -1417,8 +1408,7 @@ mod tests {
#[test]
fn speech_is_required_exactly_when_the_entry_carries_it() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Speech");
let bench = bench("Speech");
let mut spoken_carry = bench.carry(1, bench.yard);
spoken_carry.speech = Some(Statement::new("Take it.").unwrap());
assert_eq!(
@ -1450,8 +1440,7 @@ mod tests {
#[test]
fn the_same_command_id_always_selects_the_same_band() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "Bands");
let bench = bench("Bands");
// Three equally weighted bands, so the draw alone decides.
let invocation = bench.variant(&bench.carry(1, bench.yard), "carry_chance");
let draw = |command_id: CommandId, invocation: &DecisionInvocation| {
@ -1488,8 +1477,7 @@ mod tests {
#[test]
fn a_zero_effect_band_commits_nothing_but_the_event() {
let directory = tempfile::tempdir().unwrap();
let mut bench = bench(directory.path(), "EmptyBand");
let mut bench = bench("EmptyBand");
let idle = bench.variant(&bench.carry(3, bench.yard), "carry_idle");
let holdings = bench.kernel.state.holdings.clone();
@ -1514,8 +1502,7 @@ mod tests {
#[test]
fn a_committed_event_carries_the_exact_lowered_operations() {
let directory = tempfile::tempdir().unwrap();
let mut bench = bench(directory.path(), "Lowering");
let mut bench = bench("Lowering");
let receipt = bench.commit(bench.carry(2, bench.yard));
assert!(receipt.resulting_revision > 0);
let event = bench
@ -1546,8 +1533,7 @@ mod tests {
/// passes by never being taken.
#[test]
fn soul_only_the_selected_bands_effects_are_committed() {
let directory = tempfile::tempdir().unwrap();
let mut bench = bench(directory.path(), "SelectedBand");
let mut bench = bench("SelectedBand");
let split_id = affordance_named(&bench.active, "carry_split");
let split = DecisionInvocation {
affordance: split_id,
@ -1633,8 +1619,7 @@ mod tests {
/// wrong. The fixture catalog carries four such roles.
#[test]
fn soul_a_stored_role_spec_over_an_optional_subject_kind_round_trips() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "OptionalSubjectKind");
let bench = bench("OptionalSubjectKind");
let entry = bench
.kernel
.state
@ -1661,8 +1646,7 @@ mod tests {
#[test]
fn a_forged_band_or_forged_effect_does_not_apply() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "ForgedAction");
let bench = bench("ForgedAction");
let command_id = CommandId::issue();
let invocation = bench.carry(2, bench.yard);
let honest = draw_once(&bench.kernel.state, command_id, bench.clerk, &invocation).unwrap();
@ -1735,8 +1719,7 @@ mod tests {
#[test]
fn the_kernel_speak_entry_commits_its_utterance_and_no_operation() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = custody_kernel(directory.path(), "SpeakEntry");
let mut kernel = custody_kernel("SpeakEntry");
let _topology = kernel.snapshot().unwrap();
let active = kernel.snapshot().unwrap();
let speak = affordance_named(&active, "speak");
@ -1781,8 +1764,8 @@ mod tests {
civic: Civic,
}
fn civics(directory: &std::path::Path, title: &str) -> Civics {
let mut kernel = custody_kernel(directory, title);
fn civics(title: &str) -> Civics {
let mut kernel = custody_kernel(title);
let (topology, civic, active) = civic_world(&mut kernel);
Civics {
kernel,
@ -1929,8 +1912,7 @@ mod tests {
/// exact failed precondition and no allocation.
#[test]
fn an_unauthorized_actor_names_the_failed_precondition() {
let directory = tempfile::tempdir().unwrap();
let bench = civics(directory.path(), "Unauthorized");
let bench = civics("Unauthorized");
let before = bench.kernel.state.clone();
assert_eq!(
bench.rejected_as(bench.civic.farmer, &bench.levy(bench.civic.reeve, 1)),
@ -1946,8 +1928,7 @@ mod tests {
/// being authorized without any digest moving.
#[test]
fn place_jurisdiction_reaches_a_containment_subtree_and_stops_at_its_edge() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "Subtree");
let mut bench = civics("Subtree");
let treasury = bench.civic.treasury;
let farmer = bench.civic.farmer;
@ -1996,8 +1977,7 @@ mod tests {
/// it back: the act is refused at admission.
#[test]
fn office_delegation_grants_and_vacating_revokes() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "Office");
let mut bench = civics("Office");
let reeve = bench.civic.reeve;
let farmer = bench.civic.farmer;
assert!(bench.kernel.state.authority.get(&reeve).is_none());
@ -2024,8 +2004,7 @@ mod tests {
/// a catalog entry may not declare it.
#[test]
fn a_levy_cannot_be_directed_away_from_the_actor() {
let directory = tempfile::tempdir().unwrap();
let bench = civics(directory.path(), "ActorRole");
let bench = civics("ActorRole");
let mut redirected = bench.levy(bench.civic.farmer, 1);
redirected
.bindings
@ -2036,8 +2015,7 @@ mod tests {
);
// The declaration half runs at genesis, so it runs against a fresh world.
let draft_directory = tempfile::tempdir().unwrap();
let mut draft = custody_kernel(draft_directory.path(), "ReservedRole");
let mut draft = custody_kernel("ReservedRole");
let before = draft.snapshot().unwrap();
let handle = DraftHandle::new("thief");
let rejected = reject_play(
@ -2074,8 +2052,7 @@ mod tests {
/// declared ceiling passes every affordance check and dies in the ledger.
#[test]
fn an_over_levy_fails_in_the_ledger_not_in_the_contract() {
let directory = tempfile::tempdir().unwrap();
let bench = civics(directory.path(), "OverLevy");
let bench = civics("OverLevy");
let error = bench
.try_as(bench.civic.treasury, &bench.levy(bench.civic.farmer, 9))
.unwrap_err();
@ -2092,8 +2069,7 @@ mod tests {
/// does mint is still subject to disjointness.
#[test]
fn a_delegated_grant_may_not_exceed_the_granter() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "Monotone");
let mut bench = civics("Monotone");
let treasury = bench.civic.treasury;
let outsider = bench.civic.outsider;
@ -2148,8 +2124,7 @@ mod tests {
/// what it may otherwise touch.
#[test]
fn revoking_a_grant_requires_covering_authority_over_its_ground() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "RevokeEnvelope");
let mut bench = civics("RevokeEnvelope");
let treasury = bench.civic.treasury;
let farmer = bench.civic.farmer;
let hall = bench.civic.hall;
@ -2184,8 +2159,7 @@ mod tests {
/// fails the same `Authorized` precondition every other civic act reads.
#[test]
fn deploy_relocates_a_subordinate_under_command_and_refuses_one_outside_it() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "Deploy");
let mut bench = civics("Deploy");
let treasury = bench.civic.treasury;
let farmer = bench.civic.farmer;
let outsider = bench.civic.outsider;
@ -2228,8 +2202,7 @@ mod tests {
/// the forum's target, and closing the forum removes the verb's ground.
#[test]
fn a_petition_requires_standing() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "Petition");
let mut bench = civics("Petition");
let petition = bench.call(
"petition",
Vec::new(),
@ -2269,8 +2242,7 @@ mod tests {
/// same-patch grant then move resolves through the candidate shadow.
#[test]
fn a_restricted_route_admits_exactly_its_named_authority() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "Restricted");
let mut bench = civics("Restricted");
let walker = bench.topology.walker;
let step = ComponentOp::Relocate {
subject: PatchRef::Existing(walker),
@ -2332,8 +2304,7 @@ mod tests {
/// someone performs under authority rather than a declared method string.
#[test]
fn sanction_and_appoint_reach_the_reducer_under_authority() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "Institutional");
let mut bench = civics("Institutional");
let treasury = bench.civic.treasury;
let passage = bench.civic.passage;
let sanction = bench.call(
@ -2397,8 +2368,7 @@ mod tests {
/// path reaches it, and the refused act commits nothing.
#[test]
fn soul_delegation_not_monotone_reaches_the_real_command_path() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "SoulMonotone");
let mut bench = civics("SoulMonotone");
let treasury = bench.civic.treasury;
let road = bench.topology.road;
let outsider = bench.civic.outsider;
@ -2424,8 +2394,7 @@ mod tests {
/// operation succeeds the moment the key exists.
#[test]
fn soul_a_restricted_relocate_is_refused_by_the_component_writer() {
let directory = tempfile::tempdir().unwrap();
let bench = civics(directory.path(), "SoulReducerGate");
let bench = civics("SoulReducerGate");
let walker = bench.topology.walker;
let step = ResolvedOp::Relocate {
subject_id: walker,
@ -2465,8 +2434,7 @@ mod tests {
/// admission, and nothing commits.
#[test]
fn soul_a_granter_revocation_refuses_the_delegates_act() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "SoulRebind");
let mut bench = civics("SoulRebind");
let reeve = bench.civic.reeve;
let farmer = bench.civic.farmer;
let treasury = bench.civic.treasury;
@ -2497,8 +2465,7 @@ mod tests {
/// is refused.
#[test]
fn soul_a_subject_grant_inside_a_place_grant_is_a_second_source() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "SoulOverlap");
let mut bench = civics("SoulOverlap");
let treasury = bench.civic.treasury;
let farmer = bench.civic.farmer;
let hall = bench.civic.hall;
@ -2533,8 +2500,7 @@ mod tests {
/// the commit stored. No clock and no draw entropy enter.
#[test]
fn soul_reduce_is_pure_for_every_new_civic_arm() {
let directory = tempfile::tempdir().unwrap();
let mut bench = civics(directory.path(), "SoulReplay");
let mut bench = civics("SoulReplay");
let treasury = bench.civic.treasury;
let farmer = bench.civic.farmer;
let outsider = bench.civic.outsider;
@ -2610,8 +2576,7 @@ mod tests {
/// author cannot widen either without this assertion naming the change.
#[test]
fn no_component_op_kind_lowers_to_a_told_knowledge_write() {
let directory = tempfile::tempdir().unwrap();
let bench = bench(directory.path(), "AcquireKnowledgeLowering");
let bench = bench("AcquireKnowledgeLowering");
let entry = Affordance {
kind: AffordanceKindName("witness".into()),
roles: Vec::new(),

View file

@ -84,16 +84,8 @@ fn rejected(result: Result<impl Sized, KernelError>) -> Vec<Mismatch> {
}
}
/// Each call gets its own store path: kernels are created, not reopened.
fn create(world: CreateWorld) -> (tempfile::TempDir, Result<WorldKernel, KernelError>) {
let directory = tempfile::tempdir().unwrap();
let result = WorldKernel::create(
directory.path().join("world.cc"),
world,
&auth_principal(owner()),
)
.map(|(kernel, _)| kernel);
(directory, result)
fn create(world: CreateWorld) -> Result<WorldKernel, KernelError> {
WorldKernel::create(world, &auth_principal(owner())).map(|(kernel, _)| kernel)
}
fn admit(kernel: &mut WorldKernel, patch: WorldPatch) -> Result<CommitReceipt, KernelError> {
@ -135,12 +127,12 @@ fn grammar_world_refuses_an_affordance_kind_outside_the_grammar() {
// Genesis: a declared kind the binding lacks is refused.
let mut world = bound(Some(grammar_with(&[])), "Outside");
world.patch.declarations.push(declare("wave", "wave", &[]));
assert_eq!(rejected(create(world).1), not_in_grammar("wave"));
assert_eq!(rejected(create(world)), not_in_grammar("wave"));
// A later AdmitPatch: the same kind is refused, and a verb the grammar
// does carry is admitted by the same path.
let extra = [("hail", verb(RenderPath::Conversation, &[]))];
let (_dir, kernel) = create(bound(Some(grammar_with(&extra)), "Outside"));
let kernel = create(bound(Some(grammar_with(&extra)), "Outside"));
let mut kernel = kernel.unwrap();
assert_eq!(
rejected(admit(
@ -168,7 +160,7 @@ fn grammar_world_refuses_a_role_signature_the_grammar_does_not_carry() {
),
("hail", verb(RenderPath::Conversation, &[])),
];
let (_dir, kernel) = create(bound(Some(grammar_with(&extra)), "Signatures"));
let kernel = create(bound(Some(grammar_with(&extra)), "Signatures"));
let mut kernel = kernel.unwrap();
for (label, roles) in [
("renamed", vec![("whom", person()), ("where_", place())]),
@ -226,7 +218,7 @@ fn each_grammar_referent_kind_admits_exactly_its_own_kernel_kind() {
for (referent, own) in &kinds {
let extra = [("act", verb(RenderPath::ShipAction, &[("with", *referent)]))];
for (_, offered) in &kinds {
let (_dir, kernel) = create(bound(Some(grammar_with(&extra)), "Referents"));
let kernel = create(bound(Some(grammar_with(&extra)), "Referents"));
let mut kernel = kernel.unwrap();
let result = admit(
&mut kernel,
@ -257,7 +249,7 @@ fn grammar_world_without_speak_refuses_the_kernel_speak_grant() {
)
.unwrap();
assert_eq!(
rejected(create(bound(Some(no_speak), "Mute")).1),
rejected(create(bound(Some(no_speak), "Mute"))),
not_in_grammar(crate::patch::KERNEL_SPEAK_HANDLE)
);
@ -278,7 +270,7 @@ fn grammar_world_without_speak_refuses_the_kernel_speak_grant() {
)
.unwrap();
assert_eq!(
rejected(create(bound(Some(loud), "Loud")).1),
rejected(create(bound(Some(loud), "Loud"))),
disagrees(crate::patch::KERNEL_SPEAK_HANDLE)
);
}
@ -290,7 +282,7 @@ fn unbound_world_keeps_the_open_catalog() {
.patch
.declarations
.push(declare("wave", "wave", &[("at", person())]));
let (_dir, kernel) = create(world);
let kernel = create(world);
let mut kernel = kernel.unwrap();
let receipt = admit(
&mut kernel,
@ -317,7 +309,7 @@ fn a_bound_world_reports_its_grammar_and_derives_render_paths_from_it() {
let extra = [("dock", verb(RenderPath::ShipAction, &[]))];
let grammar = grammar_with(&extra);
let identity = grammar.identity();
let (_dir, kernel) = create(bound(Some(grammar), "Reports"));
let kernel = create(bound(Some(grammar), "Reports"));
let mut kernel = kernel.unwrap();
admit(&mut kernel, patch_of(vec![declare("dock", "dock", &[])])).unwrap();
let snapshot = kernel.snapshot().unwrap();
@ -339,11 +331,11 @@ fn a_bound_world_reports_its_grammar_and_derives_render_paths_from_it() {
fn a_reopened_grammar_world_still_holds_its_grammar() {
let grammar = grammar_with(&[]);
let identity = grammar.identity();
let (directory, kernel) = create(bound(Some(grammar), "Reopened"));
let kernel = create(bound(Some(grammar), "Reopened"));
let kernel = kernel.unwrap();
let world_id = kernel.snapshot().unwrap().world_id;
let exported = kernel.export().unwrap();
drop(kernel);
let mut reopened = WorldKernel::open(directory.path().join("world.cc"), world_id).unwrap();
let mut reopened = WorldKernel::open(&exported).unwrap();
assert_eq!(reopened.snapshot().unwrap().grammar, Some(identity));
assert_eq!(
rejected(admit(
@ -356,7 +348,7 @@ fn a_reopened_grammar_world_still_holds_its_grammar() {
#[test]
fn the_bound_grammar_is_part_of_the_world_state_digest() {
let (_dir, kernel) = create(bound(Some(grammar_with(&[])), "Digested"));
let kernel = create(bound(Some(grammar_with(&[])), "Digested"));
let kernel = kernel.unwrap();
let bound_digest = crate::state_digest(&kernel.state).unwrap();
let mut state = kernel.state.clone();
@ -500,9 +492,9 @@ fn submit_as(
/// A bound world whose revision has moved past genesis: one Play patch
/// that adds a dead-end place.
fn advanced_grammar_world() -> (tempfile::TempDir, WorldKernel, crate::EntityId) {
fn advanced_grammar_world() -> (WorldKernel, crate::EntityId) {
let extra = [("hail", verb(RenderPath::Conversation, &[]))];
let (dir, kernel) = create(bound(Some(grammar_with(&extra)), "Advanced"));
let kernel = create(bound(Some(grammar_with(&extra)), "Advanced"));
let mut kernel = kernel.unwrap();
let commons = *kernel.state.entities.keys().next().unwrap();
admit(
@ -532,7 +524,7 @@ fn advanced_grammar_world() -> (tempfile::TempDir, WorldKernel, crate::EntityId)
.find(|(_, record)| record.label == "The Unwalked Road")
.map(|(id, _)| id)
.unwrap();
(dir, kernel, dead_end)
(kernel, dead_end)
}
type Door = (&'static str, CallerId);
@ -563,7 +555,7 @@ fn refuse_at_each_door(kernel: &mut WorldKernel, doors: Vec<Door>) {
#[test]
fn play_refuses_outside_the_grammar_after_the_revision_has_moved() {
let (_dir, mut kernel, _) = advanced_grammar_world();
let (mut kernel, _) = advanced_grammar_world();
assert_eq!(kernel.state.revision, 1);
refuse_at_each_door(&mut kernel, vec![("play", CallerId::Play)]);
// The same path admits what the grammar carries, so the refusals above are
@ -591,7 +583,7 @@ fn a_grammar_that_binds_speak_as_anything_but_conversation_is_refused_at_bind()
.unwrap()
};
assert_eq!(
rejected(create(bound(Some(ship(&[])), "Filmed speech")).1),
rejected(create(bound(Some(ship(&[])), "Filmed speech"))),
vec![Mismatch::SpeakRenderPathDisagreesWithGrammar {
handle: DraftHandle::new(crate::patch::KERNEL_SPEAK_HANDLE),
}]
@ -604,12 +596,11 @@ fn a_grammar_that_binds_speak_as_anything_but_conversation_is_refused_at_bind()
Some(ship(&[("to", GrammarReferentKind::Person)])),
"Loud"
))
.1
),
disagrees(crate::patch::KERNEL_SPEAK_HANDLE)
);
// The control: Conversation speak binds.
assert!(create(bound(Some(grammar_with(&[])), "Spoken")).1.is_ok());
assert!(create(bound(Some(grammar_with(&[])), "Spoken")).is_ok());
}
/// `apply_effect` re-decides an effect it is handed. An effect resolved against
@ -627,7 +618,7 @@ fn an_effect_resolved_elsewhere_cannot_install_an_entry_outside_the_grammar() {
),
("hail", verb(RenderPath::Conversation, &[])),
];
let (_dir, kernel) = create(bound(Some(grammar_with(&extra)), "Forged"));
let kernel = create(bound(Some(grammar_with(&extra)), "Forged"));
let kernel = kernel.unwrap();
let mut twin = kernel.state.clone();
twin.grammar = None;

View file

@ -35,20 +35,12 @@ fn keyed_creation(title: &str) -> CreateWorld {
world
}
fn create(world: CreateWorld) -> (tempfile::TempDir, Result<WorldKernel, KernelError>) {
let directory = tempfile::tempdir().unwrap();
let result = WorldKernel::create(
directory.path().join("world.cc"),
world,
&auth_principal(owner()),
)
.map(|(kernel, _)| kernel);
(directory, result)
fn create(world: CreateWorld) -> Result<WorldKernel, KernelError> {
WorldKernel::create(world, &auth_principal(owner())).map(|(kernel, _)| kernel)
}
fn keyed_world() -> (tempfile::TempDir, WorldKernel) {
let (dir, kernel) = create(keyed_creation("Keyed"));
(dir, kernel.unwrap())
fn keyed_world() -> WorldKernel {
create(keyed_creation("Keyed")).unwrap()
}
fn rejected(result: Result<impl Sized, KernelError>) -> Vec<Mismatch> {
@ -140,11 +132,11 @@ fn one_patch_cannot_declare_two_subjects_with_one_import_key() {
subject.import_key = Some(alpha());
}
}
let (_dir, result) = create(world);
let result = create(world);
assert_eq!(rejected(result), vec![duplicate("operator")]);
// In a later patch, with the key unheld.
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let revision = kernel.state.revision;
let beta = Some(key("aetheria.ship", "Beta"));
@ -161,8 +153,8 @@ fn one_patch_cannot_declare_two_subjects_with_one_import_key() {
}
/// The fixture world past genesis: Play has added an unwalked place.
fn advanced_keyed_world() -> (tempfile::TempDir, WorldKernel, EntityId) {
let (dir, mut kernel) = keyed_world();
fn advanced_keyed_world() -> (WorldKernel, EntityId) {
let mut kernel = keyed_world();
let place = commons(&kernel);
submit_as(
&mut kernel,
@ -192,7 +184,7 @@ fn advanced_keyed_world() -> (tempfile::TempDir, WorldKernel, EntityId) {
.find(|(_, record)| record.label == "The Unwalked Road")
.map(|(id, _)| id)
.unwrap();
(dir, kernel, dead_end)
(kernel, dead_end)
}
/// Each door names the held key, typed, and the refusal leaves the revision
@ -219,7 +211,7 @@ fn refuse_held_key_at_each_door(
#[test]
fn a_held_import_key_is_refused_at_every_door_after_the_revision_has_moved() {
let (_dir, mut kernel, dead_end) = advanced_keyed_world();
let (mut kernel, dead_end) = advanced_keyed_world();
assert!(kernel.state.revision > 0, "the world has moved past genesis");
refuse_held_key_at_each_door(
&mut kernel,
@ -246,7 +238,7 @@ fn a_held_import_key_is_refused_at_every_door_after_the_revision_has_moved() {
#[test]
fn a_held_import_key_is_refused_in_a_later_patch() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let revision = kernel.state.revision;
let error = submit_as(
@ -261,7 +253,7 @@ fn a_held_import_key_is_refused_in_a_later_patch() {
#[test]
fn a_retired_subjects_import_key_is_never_reissued() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let witness = kernel
.snapshot()
@ -306,7 +298,7 @@ fn a_retired_subjects_import_key_is_never_reissued() {
#[test]
fn keys_that_differ_in_any_way_are_distinct_records() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
// Same length, case, prefix, the same concatenation split elsewhere, and
// the parts swapped: none is the held key.
@ -347,7 +339,7 @@ fn keys_that_differ_in_any_way_are_distinct_records() {
#[test]
fn a_malformed_import_key_is_refused_without_echoing_it() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let long = "x".repeat(201);
let wide = "é".repeat(101);
@ -398,7 +390,7 @@ fn a_malformed_import_key_is_refused_without_echoing_it() {
#[test]
fn the_subjects_map_refuses_a_second_subject_for_one_key_even_when_resolved_elsewhere() {
let (_dir, kernel) = keyed_world();
let kernel = keyed_world();
let place = commons(&kernel);
let resolve = |handle: &str| {
crate::patch::resolve_patch(
@ -451,7 +443,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("Keyless"));
let kernel = create(creation("Keyless"));
let kernel = kernel.unwrap();
let state = rmp_serde::to_vec_named(&kernel.state).unwrap();
assert!(
@ -459,7 +451,7 @@ fn keyless_world_digests_unchanged() {
"a keyless world grew a field"
);
// A keyed world carries it, round-trips, and digests differently.
let (_dir, keyed) = keyed_world();
let keyed = keyed_world();
let keyed_state = rmp_serde::to_vec_named(&keyed.state).unwrap();
assert!(contains(&keyed_state, b"import_key"));
let back: crate::WorldState = rmp_serde::from_slice(&keyed_state).unwrap();
@ -478,11 +470,11 @@ fn keyless_world_digests_unchanged() {
#[test]
fn a_keyed_world_reopens_with_its_keys_and_digests() {
let (dir, kernel) = keyed_world();
let kernel = keyed_world();
let snapshot = kernel.snapshot().unwrap();
let world_id = snapshot.world_id;
let exported = kernel.export().unwrap();
drop(kernel);
let reopened = WorldKernel::open(dir.path().join("world.cc"), world_id).unwrap();
let reopened = WorldKernel::open(&exported).unwrap();
let again = reopened.snapshot().unwrap();
assert_eq!(again.state_digest, snapshot.state_digest);
let keys = keys_in(&reopened);
@ -495,7 +487,7 @@ fn a_keyed_world_reopens_with_its_keys_and_digests() {
#[test]
fn a_record_key_is_one_canonical_spelling() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let nfc = "Caf\u{e9}";
let nfd = "Cafe\u{301}";
@ -544,7 +536,7 @@ fn a_record_key_is_one_canonical_spelling() {
#[test]
fn a_lore_page_path_with_spaces_is_a_record_key() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let record = "Worldbuilding/Pre-Elysium/Factions/Powers/Minor/Ewan Hart";
let declare = |kernel: &mut WorldKernel, handle: &str| {
@ -564,7 +556,7 @@ fn a_lore_page_path_with_spaces_is_a_record_key() {
#[test]
fn a_loaded_state_with_a_bad_import_key_is_refused() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
submit_as(
&mut kernel,
@ -610,7 +602,7 @@ fn a_loaded_state_with_a_bad_import_key_is_refused() {
/// effect with distinct keys, admitted by the same function.
#[test]
fn admitting_a_resolved_effect_refuses_two_subjects_with_one_key() {
let (_dir, kernel) = keyed_world();
let kernel = keyed_world();
let place = commons(&kernel);
let resolve = || {
crate::patch::resolve_patch(
@ -646,7 +638,7 @@ fn admitting_a_resolved_effect_refuses_two_subjects_with_one_key() {
/// rule cannot be a prefix, suffix or first-character check.
#[test]
fn a_decomposable_character_is_refused_in_nfd_at_every_position() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let template: Vec<char> = "Worldbuilding/Pre-Elysium/Factions/Powers/Minor/Ewan Hart"
.chars()
@ -691,7 +683,7 @@ fn a_decomposable_character_is_refused_in_nfd_at_every_position() {
#[test]
fn the_owner_door_is_closed_to_a_keyed_declaration() {
let (_dir, mut kernel) = keyed_world();
let mut kernel = keyed_world();
let place = commons(&kernel);
let revision = kernel.state.revision;
let error = submit_as(

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2382,7 +2382,7 @@ pub(super) fn kernel_speak_entry() -> Affordance {
/// Whether a stored catalog entry would still be admitted by the declaration
/// validator. One validator, two readers: the resolver rejects a bad entry, and
/// journal recovery refuses a store that already holds one.
/// opening an export refuses a chain that already holds one.
pub(super) fn entry_is_admissible(entry: &Affordance) -> bool {
let mut mismatches = Vec::new();
validate_affordance(
@ -5810,8 +5810,7 @@ mod tests {
#[test]
fn a_catalog_entry_with_a_dangling_or_noncanonical_band_is_rejected() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let slots = vec![
transfer_slot(vec!["from", "to", "goods"], Bounds::Quantity(Quantity(2))),
@ -5883,8 +5882,7 @@ mod tests {
#[test]
fn a_slot_whose_roles_do_not_match_its_operation_is_rejected() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let handle = DraftHandle::new("verb");
@ -5980,8 +5978,7 @@ mod tests {
#[test]
fn a_grant_naming_an_undeclared_affordance_is_rejected_and_the_same_patch_commits() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let entries_before = kernel.state.affordance_catalog.len();
let subjects_before = kernel.state.subjects.len();
@ -6048,8 +6045,7 @@ mod tests {
#[test]
fn two_entries_cannot_share_one_kind_name() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let slot = transfer_slot(vec!["from", "to", "goods"], Bounds::Quantity(Quantity(2)));
let rejected = reject_play(
@ -6103,10 +6099,8 @@ mod tests {
);
}
fn draft_world(directory: &std::path::Path) -> WorldKernel {
WorldKernel::create(
directory.join("world.cc"),
creation("Kharad"),
fn draft_world() -> WorldKernel {
WorldKernel::create(creation("Kharad"),
&auth_principal(owner()),
)
.expect("draft world")
@ -6117,8 +6111,7 @@ mod tests {
/// provides. Nothing commits and nothing is allocated.
#[test]
fn a_subject_declared_at_an_undeclared_place_is_rejected_and_allocates_nothing() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let commits_before = kernel.journal.commit_count();
@ -6159,8 +6152,7 @@ mod tests {
/// commit: every reference resolves to an ID the same patch allocated.
#[test]
fn a_declared_place_and_its_dependents_commit_atomically() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let commits_before = kernel.journal.commit_count();
@ -6226,8 +6218,7 @@ mod tests {
/// conversion between them and no public `Uuid` constructor.
#[test]
fn a_draft_handle_of_the_wrong_kind_is_rejected() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let commits_before = kernel.journal.commit_count();
@ -6270,8 +6261,7 @@ mod tests {
/// and repairing exactly that set is enough to commit.
#[test]
fn rejection_returns_every_failed_check_and_repairing_exactly_those_commits() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let broken = patch_of(vec![
@ -6339,8 +6329,7 @@ mod tests {
#[test]
fn an_empty_patch_is_no_canonical_change() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let error = kernel
@ -6365,8 +6354,7 @@ mod tests {
/// unrelated empty label joins the same complete set.
#[test]
fn a_containment_cycle_is_rejected_with_the_complete_set() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let error = kernel
@ -6409,8 +6397,7 @@ mod tests {
#[test]
fn a_route_endpoint_that_is_not_a_place_is_rejected() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let error = kernel
@ -6447,8 +6434,7 @@ mod tests {
/// or in an operation.
#[test]
fn an_invalid_route_cost_is_rejected_from_declaration_and_from_alter_cost() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let topology = admit_topology(&mut kernel);
let before = kernel.snapshot().unwrap();
@ -6496,8 +6482,7 @@ mod tests {
/// a route that does not start where the subject stands.
#[test]
fn relocate_without_an_open_public_route_is_rejected() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let topology = admit_topology(&mut kernel);
let active = kernel.snapshot().unwrap();
let commits_before = kernel.journal.commit_count();
@ -6545,8 +6530,7 @@ mod tests {
/// not be read as an overlap with a lend the retirement already killed.
#[test]
fn a_grant_after_retiring_the_lending_institution_is_admitted() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let (_, civic, before) = civic_world(&mut kernel);
// The office lends levy over the whole hall; grant the reeve levy
@ -6577,8 +6561,7 @@ mod tests {
/// gone, and refuses the already-applied `Retire`'s sibling operation.
#[test]
fn a_relocate_relying_only_on_a_retiring_institutions_authority_is_refused_by_the_resolver() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let (topology, civic, before) = civic_world(&mut kernel);
// `topology.walker` already exists and already stands at `yard`, so
@ -6631,8 +6614,7 @@ mod tests {
#[test]
fn relocate_moves_the_subject_and_nothing_else() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let topology = admit_topology(&mut kernel);
let active = kernel.snapshot().unwrap();
let entities_before = kernel.state.entities.clone();
@ -6669,11 +6651,7 @@ mod tests {
#[test]
fn restart_replay_after_a_relocate_is_exact() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("world.cc");
let (mut kernel, _) = WorldKernel::create(
&path,
creation("Kharad"),
let (mut kernel, _) = WorldKernel::create(creation("Kharad"),
&auth_principal(owner()),
)
.unwrap();
@ -6691,10 +6669,10 @@ mod tests {
.submit(envelope.clone(), &AuthenticatedCaller::verified_play())
.unwrap();
let committed = kernel.snapshot().unwrap();
let world_id = committed.world_id;
let exported = kernel.export().unwrap();
drop(kernel);
let mut reopened = WorldKernel::open(&path, world_id).unwrap();
let mut reopened = WorldKernel::open(&exported).unwrap();
assert_eq!(reopened.snapshot().unwrap(), committed);
assert_eq!(
reopened.state.positions.get(&topology.walker),
@ -6710,8 +6688,7 @@ mod tests {
#[test]
fn the_snapshot_exposes_places_routes_and_positions_deterministically() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let topology = admit_topology(&mut kernel);
let snapshot = kernel.snapshot().unwrap();
assert_eq!(snapshot, kernel.snapshot().unwrap());
@ -6751,11 +6728,7 @@ mod tests {
#[test]
fn restart_replay_after_a_committed_patch_is_exact() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("world.cc");
let (mut kernel, _) = WorldKernel::create(
&path,
creation("Kharad"),
let (mut kernel, _) = WorldKernel::create(creation("Kharad"),
&auth_principal(owner()),
)
.unwrap();
@ -6777,10 +6750,10 @@ mod tests {
.submit(envelope.clone(), &AuthenticatedCaller::verified_play())
.unwrap();
let committed = kernel.snapshot().unwrap();
let world_id = committed.world_id;
let exported = kernel.export().unwrap();
drop(kernel);
let mut reopened = WorldKernel::open(&path, world_id).unwrap();
let mut reopened = WorldKernel::open(&exported).unwrap();
assert_eq!(reopened.snapshot().unwrap(), committed);
assert!(matches!(
reopened.submit(envelope, &AuthenticatedCaller::verified_play()),
@ -6793,8 +6766,7 @@ mod tests {
/// re-resolved gets the same ones.
#[test]
fn genesis_and_admit_patch_share_one_allocator() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
let genesis_human = before
.subjects
@ -6827,16 +6799,12 @@ mod tests {
assert_eq!(first, second);
}
/// The durable half of "a rejected patch mints nothing": the store on disk,
/// not just the in-memory head, carries no row and no byte of any ID the
/// The durable half of "a rejected patch mints nothing": the export, not
/// just the in-memory head, carries no commit and no byte of any ID the
/// rejected patch would have allocated.
#[test]
fn a_rejected_patch_leaves_no_row_and_no_id_in_the_store() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("world.cc");
let (mut kernel, _) = WorldKernel::create(
&path,
creation("Kharad"),
fn a_rejected_patch_leaves_no_commit_and_no_id_in_the_export() {
let (mut kernel, _) = WorldKernel::create(creation("Kharad"),
&auth_principal(owner()),
)
.unwrap();
@ -6877,16 +6845,17 @@ mod tests {
),
];
let exported = kernel.export().unwrap();
drop(kernel);
let raw = std::fs::read(&path).unwrap();
let raw = &exported;
for id in would_be {
assert!(
!raw.windows(16).any(|window| window == id.as_bytes()),
"a rejected patch left {id} in the store"
"a rejected patch left {id} in the export"
);
}
let reopened = WorldKernel::open(&path, before.world_id).unwrap();
let reopened = WorldKernel::open(&exported).unwrap();
assert_eq!(reopened.snapshot().unwrap(), before);
assert_eq!(reopened.journal.commit_count(), 1);
assert_eq!(reopened.state.entities.len(), FIXTURE_ENTITIES);
@ -6904,9 +6873,7 @@ mod tests {
/// otherwise concatenate to the same string.
#[test]
fn derive_id_does_not_collide_some_empty_discriminator_with_none() {
let directory = tempfile::tempdir().unwrap();
let (kernel, _) = WorldKernel::create(
&directory.path().join("world.cc"),
creation("DeriveId"),
&auth_principal(owner()),
)
@ -6944,8 +6911,7 @@ mod tests {
/// without the journal's reduce-equality check running.
#[test]
fn apply_effect_rejects_a_forged_stale_or_unauthorized_patch_effect() {
let directory = tempfile::tempdir().unwrap();
let kernel = draft_world(directory.path());
let kernel = draft_world();
let patch = patch_of(vec![
entity("rhythm-road", "The Rhythm Road", EntityKind::Place),
institution(
@ -7014,8 +6980,7 @@ mod tests {
/// test names are each reachable from a real patch.
#[test]
fn soul_self_loop_unplaced_subject_and_no_effect_are_each_reachable() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let before = kernel.snapshot().unwrap();
// A route whose two endpoints resolve to one place.
@ -7131,8 +7096,7 @@ mod tests {
/// stand on, a closed route, or a restricted one dies at apply time.
#[test]
fn soul_a_forged_relocate_effect_is_refused_at_apply_time() {
let directory = tempfile::tempdir().unwrap();
let mut kernel = draft_world(directory.path());
let mut kernel = draft_world();
let topology = admit_topology(&mut kernel);
for edge_id in [topology.span, topology.shutter, topology.toll] {
let forged = super::super::WorldEffect::PatchAdmitted {