From 94a3c67d6d6a5e3c78ac746197a41cd2b2f65675 Mon Sep 17 00:00:00 2001 From: soul Date: Fri, 20 Nov 2026 02:35:03 +0100 Subject: [PATCH] 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 --- native/aetherlight/Cargo.lock | 364 ------- native/aetherlight/Cargo.toml | 7 +- native/aetherlight/src/action.rs | 113 +- native/aetherlight/src/grammar/tests.rs | 51 +- native/aetherlight/src/import_key_tests.rs | 60 +- native/aetherlight/src/journal.rs | 1127 ++++---------------- native/aetherlight/src/lib.rs | 878 +++++---------- native/aetherlight/src/patch.rs | 112 +- 8 files changed, 613 insertions(+), 2099 deletions(-) diff --git a/native/aetherlight/Cargo.lock b/native/aetherlight/Cargo.lock index d79ad2fc6..494df4f1d 100644 --- a/native/aetherlight/Cargo.lock +++ b/native/aetherlight/Cargo.lock @@ -6,46 +6,22 @@ version = 4 name = "aetherlight" version = "0.1.0" dependencies = [ - "chrono", - "cultcache-rs", "rmp-serde", "serde", "serde_json", "sha2", - "tempfile", "thiserror", "unicode-normalization", "unicode-properties", "uuid", ] -[[package]] -name = "android_system_properties" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" -dependencies = [ - "libc", -] - -[[package]] -name = "anyhow" -version = "1.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" - [[package]] name = "autocfg" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" -[[package]] -name = "bitflags" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" - [[package]] name = "block-buffer" version = "0.10.4" @@ -61,42 +37,12 @@ version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" -[[package]] -name = "cc" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d" -dependencies = [ - "find-msvc-tools", - "shlex", -] - [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" -[[package]] -name = "chrono" -version = "0.4.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-traits", - "serde", - "wasm-bindgen", - "windows-link", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cpufeatures" version = "0.2.17" @@ -116,34 +62,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "cultcache-rs" -version = "0.1.0" -source = "git+https://github.com/GameCult/CultLib.git?rev=85f7024a35ea42cf9f0a0199a064526427150191#85f7024a35ea42cf9f0a0199a064526427150191" -dependencies = [ - "anyhow", - "chrono", - "cultcache-rs-derive", - "fs2", - "redb", - "rmp-serde", - "serde", - "serde_bytes", - "serde_json", - "uuid", - "windows-sys 0.59.0", -] - -[[package]] -name = "cultcache-rs-derive" -version = "0.1.0" -source = "git+https://github.com/GameCult/CultLib.git?rev=85f7024a35ea42cf9f0a0199a064526427150191#85f7024a35ea42cf9f0a0199a064526427150191" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - [[package]] name = "digest" version = "0.10.7" @@ -154,38 +72,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "errno" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" -dependencies = [ - "libc", - "windows-sys 0.61.2", -] - -[[package]] -name = "fastrand" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" - -[[package]] -name = "find-msvc-tools" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" - -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "futures-core" version = "0.3.34" @@ -231,30 +117,6 @@ dependencies = [ "r-efi", ] -[[package]] -name = "iana-time-zone" -version = "0.1.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - [[package]] name = "itoa" version = "1.0.18" @@ -278,18 +140,6 @@ version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" -[[package]] -name = "linux-raw-sys" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" - -[[package]] -name = "log" -version = "0.4.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" - [[package]] name = "memchr" version = "2.8.3" @@ -341,15 +191,6 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" -[[package]] -name = "redb" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e925444704b5f17d32bf42f5b6e2df050bceebc3dcd6e71cc73dafe8092e839" -dependencies = [ - "libc", -] - [[package]] name = "rmp" version = "0.8.15" @@ -369,19 +210,6 @@ dependencies = [ "serde", ] -[[package]] -name = "rustix" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.61.2", -] - [[package]] name = "rustversion" version = "1.0.23" @@ -398,16 +226,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde_bytes" -version = "0.11.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" -dependencies = [ - "serde", - "serde_core", -] - [[package]] name = "serde_core" version = "1.0.229" @@ -452,12 +270,6 @@ dependencies = [ "digest", ] -[[package]] -name = "shlex" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" - [[package]] name = "slab" version = "0.4.12" @@ -486,19 +298,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" -dependencies = [ - "fastrand", - "getrandom", - "once_cell", - "rustix", - "windows-sys 0.61.2", -] - [[package]] name = "thiserror" version = "2.0.20" @@ -624,169 +423,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - [[package]] name = "zmij" version = "1.0.23" diff --git a/native/aetherlight/Cargo.toml b/native/aetherlight/Cargo.toml index ec8f9d37e..49c9a5965 100644 --- a/native/aetherlight/Cargo.toml +++ b/native/aetherlight/Cargo.toml @@ -9,8 +9,6 @@ publish = false [workspace] [dependencies] -chrono = { version = "0.4", features = ["serde"] } -cultcache-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "85f7024a35ea42cf9f0a0199a064526427150191", package = "cultcache-rs" } rmp-serde = "1.3" serde = { version = "1", features = ["derive"] } serde_json = "1" @@ -18,7 +16,8 @@ sha2 = "0.10" thiserror = "2" unicode-normalization = "0.1.25" unicode-properties = "0.1.4" -uuid = { version = "1", features = ["v4", "serde"] } +uuid = { version = "1", features = ["serde"] } [dev-dependencies] -tempfile = "3" +# Test fixtures draw random ids; no shipped path does. +uuid = { version = "1", features = ["v4"] } diff --git a/native/aetherlight/src/action.rs b/native/aetherlight/src/action.rs index 64b18f413..8f61aebac 100644 --- a/native/aetherlight/src/action.rs +++ b/native/aetherlight/src/action.rs @@ -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(), diff --git a/native/aetherlight/src/grammar/tests.rs b/native/aetherlight/src/grammar/tests.rs index 3743f2a9a..c7486841e 100644 --- a/native/aetherlight/src/grammar/tests.rs +++ b/native/aetherlight/src/grammar/tests.rs @@ -84,16 +84,8 @@ fn rejected(result: Result) -> Vec { } } -/// Each call gets its own store path: kernels are created, not reopened. -fn create(world: CreateWorld) -> (tempfile::TempDir, Result) { - 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::create(world, &auth_principal(owner())).map(|(kernel, _)| kernel) } fn admit(kernel: &mut WorldKernel, patch: WorldPatch) -> Result { @@ -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) { #[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; diff --git a/native/aetherlight/src/import_key_tests.rs b/native/aetherlight/src/import_key_tests.rs index 5c5e28340..4d217c586 100644 --- a/native/aetherlight/src/import_key_tests.rs +++ b/native/aetherlight/src/import_key_tests.rs @@ -35,20 +35,12 @@ fn keyed_creation(title: &str) -> CreateWorld { world } -fn create(world: CreateWorld) -> (tempfile::TempDir, Result) { - 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::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) -> Vec { @@ -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 = "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( diff --git a/native/aetherlight/src/journal.rs b/native/aetherlight/src/journal.rs index 96efb340f..e8ba77c70 100644 --- a/native/aetherlight/src/journal.rs +++ b/native/aetherlight/src/journal.rs @@ -1,380 +1,94 @@ use super::{ - COMMIT_SCHEMA, CommandId, CommittedCommand, KernelError, STATE_SCHEMA, WorldCommit, - WorldEffect, WorldId, WorldState, apply_effect, commit_digest, reduce, state_digest, -}; -use chrono::Utc; -use cultcache_rs::{CacheBackingStore, CultCacheEnvelope, OwnedRedbMessagePackBackingStore}; -use serde::{Serialize, de::DeserializeOwned}; -use std::{ - cell::Cell, - collections::{BTreeMap, BTreeSet}, - path::Path, + COMMIT_SCHEMA, CommittedCommand, KernelError, STATE_SCHEMA, WorldCommit, WorldEffect, + WorldId, WorldState, apply_effect, commit_digest, reduce, state_digest, }; +use serde::{Deserialize, Serialize, de::DeserializeOwned}; +use std::collections::{BTreeMap, BTreeSet}; use thiserror::Error; -const STATE_ROW: &str = "world_state.elaboration.v1"; -const COMMIT_ROW: &str = "world_commit.elaboration.v1"; +pub(super) const JOURNAL_SCHEMA: &str = "aetherlight.journal.v1"; #[derive(Debug, Error)] pub(super) enum JournalError { - #[error("opened store contains another world")] - WorldMismatch, - #[error("world ownership is uncertain after command {command_id:?}; drop and reopen")] - RecoveryRequired { command_id: CommandId }, - #[error("world store path no longer names the owned database")] - OwnershipLost, - #[error("world store operation failed: {0}")] - Store(String), #[error("world journal is corrupt: {0}")] Corrupt(String), } -pub(super) enum JournalOpen { - Empty(EmptyWorldJournal), - Live { - journal: WorldJournal, - state: WorldState, - }, +/// What an export carries: the schema that names the format, and the commits in +/// revision order. Nothing else is stored, because nothing else is truth: the +/// head state is the replay of these commits. +#[derive(Serialize)] +struct ExportRef<'a> { + schema: &'a str, + commits: &'a [WorldCommit], } -pub(super) struct EmptyWorldJournal { - store: OwnedRedbMessagePackBackingStore, - #[cfg(test)] - fail_after_durable_initialize: bool, -} - -#[derive(Clone, Copy)] -enum JournalHealth { - Healthy, - RecoveryRequired(CommandId), - OwnershipLost, +#[derive(Serialize, Deserialize)] +struct Export { + schema: String, + commits: Vec, } +/// The only record of a world: its commits in revision order, genesis first. pub(super) struct WorldJournal { - store: OwnedRedbMessagePackBackingStore, - state_row: CultCacheEnvelope, - commits: BTreeMap, - health: Cell, - #[cfg(test)] - fail_after_durable_commit: bool, + commits: Vec, } impl WorldJournal { - pub(super) fn open_owner(path: &Path) -> Result { - let store = OwnedRedbMessagePackBackingStore::new(path) - .map_err(|error| JournalError::Store(error.to_string()))?; - store - .validate_path_identity() - .map_err(|_| JournalError::OwnershipLost)?; - let rows = store - .pull_all() - .map_err(|error| JournalError::Store(error.to_string()))?; - store - .validate_path_identity() - .map_err(|_| JournalError::OwnershipLost)?; - if rows.is_empty() { - return Ok(JournalOpen::Empty(EmptyWorldJournal { - store, - #[cfg(test)] - fail_after_durable_initialize: false, - })); + pub(super) fn genesis(genesis: WorldCommit) -> Self { + Self { + commits: vec![genesis], } - let (state_row, state, commits) = recover(rows, None)?; - Ok(JournalOpen::Live { - journal: Self { - store, - state_row, - commits, - health: Cell::new(JournalHealth::Healthy), - #[cfg(test)] - fail_after_durable_commit: false, - }, - state, - }) } - pub(super) fn open( - path: &Path, - expected_world_id: WorldId, - ) -> Result<(Self, WorldState), JournalError> { - let store = OwnedRedbMessagePackBackingStore::new(path) - .map_err(|error| JournalError::Store(error.to_string()))?; - store - .validate_path_identity() - .map_err(|_| JournalError::OwnershipLost)?; - let rows = store - .pull_all() - .map_err(|error| JournalError::Store(error.to_string()))?; - store - .validate_path_identity() - .map_err(|_| JournalError::OwnershipLost)?; - let (state_row, state, commits) = recover(rows, Some(expected_world_id))?; + pub(super) fn append(&mut self, commit: WorldCommit) { + self.commits.push(commit); + } + + pub(super) fn export(&self) -> Result, KernelError> { + rmp_serde::to_vec_named(&ExportRef { + schema: JOURNAL_SCHEMA, + commits: &self.commits, + }) + .map_err(|error| KernelError::Serialization(error.to_string())) + } + + /// Decode canonically, then replay: the head state is whatever the chain + /// derives, and a chain that does not verify is not a world. + pub(super) fn open(bytes: &[u8]) -> Result<(Self, WorldState), JournalError> { + let export: Export = decode(bytes)?; + if export.schema != JOURNAL_SCHEMA { + return Err(JournalError::Corrupt(format!( + "export schema {} is not {JOURNAL_SCHEMA}", + export.schema + ))); + } + let state = verify_history(&export.commits)?; Ok(( Self { - store, - state_row, - commits, - health: Cell::new(JournalHealth::Healthy), - #[cfg(test)] - fail_after_durable_commit: false, + commits: export.commits, }, state, )) } - pub(super) fn ensure_healthy(&self) -> Result<(), JournalError> { - match self.health.get() { - JournalHealth::RecoveryRequired(command_id) => { - return Err(JournalError::RecoveryRequired { command_id }); - } - JournalHealth::OwnershipLost => return Err(JournalError::OwnershipLost), - JournalHealth::Healthy => {} - } - if self.store.validate_path_identity().is_err() { - self.health.set(JournalHealth::OwnershipLost); - return Err(JournalError::OwnershipLost); - } - Ok(()) - } - - pub(super) fn commit( - &mut self, - next: &WorldState, - commit: &WorldCommit, - ) -> Result<(), JournalError> { - self.ensure_healthy()?; - let command_id = commit.command.id(); - if self.commits.contains_key(&command_id) { - return Err(JournalError::Corrupt( - "single-owner append attempted to duplicate a committed command".into(), - )); - } - let current: WorldState = decode(&self.state_row)?; - verify_append(¤t, next, commit)?; - let next_row = envelope(STATE_ROW, STATE_SCHEMA, next.world_id.key(), next)?; - let commit_row = envelope(COMMIT_ROW, COMMIT_SCHEMA, command_id.key(), commit)?; - self.health.set(JournalHealth::RecoveryRequired(command_id)); - let swapped = self.store.compare_and_swap_batch( - std::slice::from_ref(&self.state_row), - vec![next_row.clone(), commit_row], - ); - match swapped { - Ok(true) => {} - Ok(false) | Err(_) => { - return Err(JournalError::RecoveryRequired { command_id }); - } - } - #[cfg(test)] - if self.fail_after_durable_commit { - return Err(JournalError::RecoveryRequired { command_id }); - } - if self.store.validate_path_identity().is_err() { - return Err(JournalError::RecoveryRequired { command_id }); - } - self.state_row = next_row; - self.commits.insert(command_id, commit.clone()); - self.health.set(JournalHealth::Healthy); - Ok(()) - } - - pub(super) fn commit_for(&self, command_id: CommandId) -> Option<&WorldCommit> { - self.commits.get(&command_id) - } - #[cfg(test)] pub(super) fn commit_count(&self) -> usize { self.commits.len() } - /// PA.f40: a test outside this module needs the full commit map to forge - /// one commit's effect and route the forgery through `verify_history` - /// directly, the same way this module's own forgery tests already do via - /// `self.commits.clone()`. #[cfg(test)] - pub(super) fn commits_for_test(&self) -> BTreeMap { + pub(super) fn commits_for_test(&self) -> Vec { self.commits.clone() } - - #[cfg(test)] - pub(super) fn fail_after_durable_commit_for_test(&mut self) { - self.fail_after_durable_commit = true; - } } -impl EmptyWorldJournal { - #[cfg(test)] - pub(super) fn fail_after_durable_initialize_for_test(&mut self) { - self.fail_after_durable_initialize = true; - } - - pub(super) fn initialize( - self, - state: &WorldState, - genesis: &WorldCommit, - ) -> Result { - self.store - .validate_path_identity() - .map_err(|_| JournalError::OwnershipLost)?; - let mut commits = BTreeMap::new(); - let command_id = genesis.command.id(); - commits.insert(command_id, genesis.clone()); - verify_history(state, &commits)?; - let state_row = envelope(STATE_ROW, STATE_SCHEMA, state.world_id.key(), state)?; - let commit_row = envelope(COMMIT_ROW, COMMIT_SCHEMA, command_id.key(), genesis)?; - let inserted = self - .store - .append_if_snapshot_unchanged(&[], vec![state_row.clone(), commit_row]); - if !matches!(inserted, Ok(true)) { - return Err(JournalError::RecoveryRequired { command_id }); - } - #[cfg(test)] - if self.fail_after_durable_initialize { - return Err(JournalError::RecoveryRequired { command_id }); - } - if self.store.validate_path_identity().is_err() { - return Err(JournalError::RecoveryRequired { command_id }); - } - Ok(WorldJournal { - store: self.store, - state_row, - commits, - health: Cell::new(JournalHealth::Healthy), - #[cfg(test)] - fail_after_durable_commit: false, - }) - } -} - -fn recover( - rows: Vec, - expected_world_id: Option, -) -> Result< - ( - CultCacheEnvelope, - WorldState, - BTreeMap, - ), - JournalError, -> { - let mut state_rows = Vec::new(); - let mut commits = BTreeMap::new(); - for row in rows { - match row.r#type.as_str() { - STATE_ROW => { - require_schema(&row, STATE_SCHEMA)?; - state_rows.push(row); - } - COMMIT_ROW => { - require_schema(&row, COMMIT_SCHEMA)?; - let commit: WorldCommit = decode(&row)?; - let command_id = commit.command.id(); - if row.key != command_id.key() { - return Err(JournalError::Corrupt( - "commit row key does not match command ID".into(), - )); - } - if commits.insert(command_id, commit).is_some() { - return Err(JournalError::Corrupt("duplicate command commit".into())); - } - } - other => { - return Err(JournalError::Corrupt(format!( - "unadmitted row type {other}" - ))); - } - } - } - if state_rows.len() != 1 { - return Err(JournalError::Corrupt(format!( - "expected one state row, found {}", - state_rows.len() - ))); - } - let state_row = state_rows.pop().expect("length checked"); - let state: WorldState = decode(&state_row)?; - if state_row.key != state.world_id.key() { - return Err(JournalError::Corrupt( - "state row key does not match its world ID".into(), - )); - } - if expected_world_id.is_some_and(|expected| state.world_id != expected) { - return Err(JournalError::WorldMismatch); - } - verify_history(&state, &commits)?; - Ok((state_row, state, commits)) -} - -fn verify_append( - current: &WorldState, - next: &WorldState, - commit: &WorldCommit, -) -> Result<(), JournalError> { - verify_state_shape(current)?; - verify_state_shape(next)?; - if current.world_id != next.world_id - || commit.world_id != current.world_id - || commit.schema != COMMIT_SCHEMA - || commit.previous_revision != Some(current.revision) - || commit.resulting_revision != next.revision - || next.revision != current.revision.saturating_add(1) - || commit.previous_state_digest.as_deref() != Some(current.state_digest.as_str()) - || commit.resulting_state_digest != next.state_digest - || commit.previous_commit_digest != current.last_commit_digest - || next.last_commit_digest.as_deref() != Some(commit.digest.as_str()) - { - return Err(JournalError::Corrupt( - "commit does not bind the exact state transition".into(), - )); - } - if state_digest(current).map_err(kernel_error)? != current.state_digest - || state_digest(next).map_err(kernel_error)? != next.state_digest - || commit_digest(commit).map_err(kernel_error)? != commit.digest - { - return Err(JournalError::Corrupt("digest mismatch".into())); - } - let mut replay = current.clone(); - apply_committed_command(&mut replay, commit)?; - replay.revision = next.revision; - replay.state_digest = state_digest(&replay).map_err(kernel_error)?; - replay.last_commit_digest = Some(commit.digest.clone()); - if &replay != next { - return Err(JournalError::Corrupt( - "commit effect does not reproduce next state".into(), - )); - } - Ok(()) -} - -/// `pub(super)`, matching `verify_state_shape`: a Soul-style forgery test -/// outside this module routes its falsification through the same function -/// that actually judges a committed history, rather than through the -/// structural-only `verify_state_shape`. -pub(super) fn verify_history( - state: &WorldState, - commits: &BTreeMap, -) -> Result<(), JournalError> { - verify_state_shape(state)?; - if commits - .iter() - .any(|(command_id, commit)| *command_id != commit.command.id()) - { - return Err(JournalError::Corrupt( - "commit index does not derive from the persisted command".into(), - )); - } - let expected_commits = usize::try_from(state.revision) - .map_err(|_| JournalError::Corrupt("revision does not fit this runtime".into()))?; - let expected_commits = expected_commits - .checked_add(1) - .ok_or_else(|| JournalError::Corrupt("commit count overflow".into()))?; - if commits.len() != expected_commits { - return Err(JournalError::Corrupt( - "commit count does not equal genesis plus head revision".into(), - )); - } - let mut ordered: Vec<_> = commits.values().collect(); - ordered.sort_by_key(|commit| commit.resulting_revision); - let genesis = ordered +/// The one judge of a stored chain, `pub(super)` so a forgery test outside this +/// module routes through the same function that `open` does. It replays the +/// commits in revision order from genesis and returns the head state they +/// derive; position `i` must hold resulting revision `i`. +pub(super) fn verify_history(commits: &[WorldCommit]) -> Result { + let genesis = commits .first() .ok_or_else(|| JournalError::Corrupt("world has no genesis commit".into()))?; let CommittedCommand::CreateWorld(genesis_command) = &genesis.command else { @@ -388,9 +102,9 @@ pub(super) fn verify_history( )); }; if genesis.schema != COMMIT_SCHEMA - || genesis.world_id != state.world_id || genesis.previous_revision.is_some() || genesis.resulting_revision != 0 + || genesis.world_id != WorldId::of(genesis_command.id()) || genesis.previous_state_digest.is_some() || genesis.previous_commit_digest.is_some() || commit_digest(genesis).map_err(kernel_error)? != genesis.digest @@ -399,7 +113,7 @@ pub(super) fn verify_history( "genesis commit is not canonical or verifiable".into(), )); } - let mut replay = WorldState::genesis(state.world_id, genesis_command, &genesis.effect) + let mut replay = WorldState::genesis(genesis.world_id, genesis_command, &genesis.effect) .map_err(kernel_error)?; verify_state_shape(&replay)?; verify_commitments_are_future(&replay, &BTreeMap::new())?; @@ -410,9 +124,9 @@ pub(super) fn verify_history( } replay.last_commit_digest = Some(genesis.digest.clone()); - for commit in ordered.into_iter().skip(1) { + for commit in &commits[1..] { if commit.schema != COMMIT_SCHEMA - || commit.world_id != state.world_id + || commit.world_id != replay.world_id || commit.previous_revision != Some(replay.revision) || commit.resulting_revision != replay.revision.saturating_add(1) || commit.previous_state_digest.as_deref() != Some(replay.state_digest.as_str()) @@ -428,7 +142,7 @@ pub(super) fn verify_history( // Authority is re-decided here for free: `apply_committed_command` // re-runs `reduce` against the pre-commit state and requires effect // equality, then `apply_effect`, and both of those call - // `require_play`. A forged row recording the owner as the caller of + // `require_play`. A forged commit recording the owner as the caller of // a post-genesis command fails replay rather than being admitted by a // reducer that trusts the recorded caller. A third statement of the same rule here would be a // third owner of one decision. @@ -451,12 +165,8 @@ pub(super) fn verify_history( } replay.last_commit_digest = Some(commit.digest.clone()); } - if &replay != state { - return Err(JournalError::Corrupt( - "head state does not equal replayed history".into(), - )); - } - Ok(()) + verify_state_shape(&replay)?; + Ok(replay) } /// The replay-side twin of `Mismatch::CommitmentDueInThePast`: every commitment @@ -918,47 +628,13 @@ fn apply_committed_command( .map_err(kernel_error) } -fn require_schema(row: &CultCacheEnvelope, schema: &str) -> Result<(), JournalError> { - if row.schema_id.as_deref() != Some(schema) { - Err(JournalError::Corrupt(format!( - "row {}/{} has the wrong schema", - row.r#type, row.key - ))) - } else { - Ok(()) - } -} - -fn envelope( - row_type: &str, - schema: &str, - key: String, - value: &T, -) -> Result { - Ok(CultCacheEnvelope { - key, - r#type: row_type.into(), - payload: rmp_serde::to_vec_named(value) - .map_err(|error| JournalError::Store(error.to_string()))?, - stored_at: Utc::now().to_rfc3339(), - schema_id: Some(schema.into()), - }) -} - -fn decode(row: &CultCacheEnvelope) -> Result { - let value: T = rmp_serde::from_slice(&row.payload).map_err(|error| { - JournalError::Corrupt(format!( - "could not decode row {}/{}: {error}", - row.r#type, row.key - )) - })?; +fn decode(bytes: &[u8]) -> Result { + let value: T = rmp_serde::from_slice(bytes) + .map_err(|error| JournalError::Corrupt(format!("could not decode the export: {error}")))?; let canonical = rmp_serde::to_vec_named(&value) .map_err(|error| JournalError::Corrupt(error.to_string()))?; - if canonical != row.payload { - return Err(JournalError::Corrupt(format!( - "row {}/{} is not canonical", - row.r#type, row.key - ))); + if canonical != bytes { + return Err(JournalError::Corrupt("the export is not canonical".into())); } Ok(value) } @@ -983,13 +659,36 @@ mod tests { value: u8, } - /// The commit a forgery test rewrites: the one the test just committed. - pub(super) fn last_commit(commits: &mut BTreeMap) -> &mut WorldCommit { - commits.values_mut().max_by_key(|commit| commit.resulting_revision).unwrap() + /// The bytes an honest exporter writes for `commits`, whatever they claim. + pub(super) fn export_of(commits: &[WorldCommit]) -> Vec { + WorldJournal { + commits: commits.to_vec(), + } + .export() + .unwrap() } - pub(super) fn genesis_commit(commits: &mut BTreeMap) -> &mut WorldCommit { - commits.values_mut().min_by_key(|commit| commit.resulting_revision).unwrap() + /// Open a world from forged commits through the door a real export takes: + /// canonical decode, then the one replay judge. + pub(super) fn reopen(commits: &[WorldCommit]) -> Result { + WorldJournal::open(&export_of(commits)).map(|(_, state)| state) + } + + #[test] + fn decode_rejects_an_alternate_messagepack_shape() { + let bytes = rmp_serde::to_vec(&CanonicalFixture { value: 7 }).unwrap(); + assert!(decode::(&bytes).is_err()); + let canonical = rmp_serde::to_vec_named(&CanonicalFixture { value: 7 }).unwrap(); + assert!(decode::(&canonical).is_ok()); + } + + /// The commit a forgery test rewrites: the one the test just committed. + pub(super) fn last_commit(commits: &mut [WorldCommit]) -> &mut WorldCommit { + commits.iter_mut().max_by_key(|commit| commit.resulting_revision).unwrap() + } + + pub(super) fn genesis_commit(commits: &mut [WorldCommit]) -> &mut WorldCommit { + commits.iter_mut().min_by_key(|commit| commit.resulting_revision).unwrap() } fn owner_patch(subject: SubjectDeclaration) -> WorldPatch { @@ -1000,22 +699,8 @@ mod tests { } } - #[test] - fn decode_rejects_an_alternate_messagepack_shape() { - let row = CultCacheEnvelope { - key: "fixture".into(), - r#type: "fixture".into(), - payload: rmp_serde::to_vec(&CanonicalFixture { value: 7 }).unwrap(), - stored_at: Utc::now().to_rfc3339(), - schema_id: Some("fixture.v0".into()), - }; - assert!(decode::(&row).is_err()); - } - #[test] fn replay_rejects_a_forged_command_or_effect_even_with_valid_hashes() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let owner = PrincipalId::new("owner@example.test"); let authenticated = AuthenticatedCaller::fixture(CallerId::Principal(owner.clone())); let creation = CreateWorld { @@ -1031,7 +716,7 @@ mod tests { }), grammar: None, }; - let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap(); + let (mut kernel, _) = WorldKernel::create(creation, &authenticated).unwrap(); let snapshot = kernel.snapshot().unwrap(); kernel .submit( @@ -1047,7 +732,6 @@ mod tests { ) .unwrap(); - let mut command_forged_head = kernel.state.clone(); let mut command_forged_commits = kernel.journal.commits.clone(); let command_forged = last_commit(&mut command_forged_commits); let CommittedCommand::WorldCommand(command) = &mut command_forged.command else { @@ -1057,14 +741,12 @@ mod tests { minutes: crate::TickMinutes::new(2).unwrap(), }; command_forged.digest = commit_digest(command_forged).unwrap(); - command_forged_head.last_commit_digest = Some(command_forged.digest.clone()); assert!(matches!( - verify_history(&command_forged_head, &command_forged_commits), + reopen(&command_forged_commits), Err(JournalError::Corrupt(_)) )); - let mut caller_forged_head = kernel.state.clone(); let mut caller_forged_commits = kernel.journal.commits.clone(); let caller_forged = last_commit(&mut caller_forged_commits); let CommittedCommand::WorldCommand(command) = &mut caller_forged.command else { @@ -1072,14 +754,12 @@ mod tests { }; command.caller = CallerId::Principal(PrincipalId::new("attacker@example.test")); caller_forged.digest = commit_digest(caller_forged).unwrap(); - caller_forged_head.last_commit_digest = Some(caller_forged.digest.clone()); assert!(matches!( - verify_history(&caller_forged_head, &caller_forged_commits), + reopen(&caller_forged_commits), Err(JournalError::Corrupt(_)) )); - let mut effect_forged_head = kernel.state.clone(); let mut effect_forged_commits = kernel.journal.commits.clone(); let effect_forged = last_commit(&mut effect_forged_commits); let WorldEffect::TimeAdvanced { to, .. } = &mut effect_forged.effect else { @@ -1087,18 +767,15 @@ mod tests { }; *to = crate::FictionalMinutes(99); effect_forged.digest = commit_digest(effect_forged).unwrap(); - effect_forged_head.last_commit_digest = Some(effect_forged.digest.clone()); assert!(matches!( - verify_history(&effect_forged_head, &effect_forged_commits), + reopen(&effect_forged_commits), Err(JournalError::Corrupt(_)) )); } #[test] fn a_forged_patch_effect_does_not_apply() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let owner = PrincipalId::new("owner@example.test"); let authenticated = AuthenticatedCaller::fixture(CallerId::Principal(owner.clone())); let creation = CreateWorld { @@ -1114,7 +791,7 @@ mod tests { }), grammar: None, }; - let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap(); + let (mut kernel, _) = WorldKernel::create(creation, &authenticated).unwrap(); let snapshot = kernel.snapshot().unwrap(); kernel .submit( @@ -1149,7 +826,6 @@ mod tests { ) .unwrap(); - let mut forged_head = kernel.state.clone(); let mut forged_commits = kernel.journal.commits.clone(); let forged = last_commit(&mut forged_commits); let WorldEffect::PatchAdmitted { resolved, .. } = &mut forged.effect else { @@ -1159,106 +835,20 @@ mod tests { place: EntityId::issue(), }); forged.digest = commit_digest(forged).unwrap(); - forged_head.last_commit_digest = Some(forged.digest.clone()); assert!(matches!( - verify_history(&forged_head, &forged_commits), + reopen(&forged_commits), Err(JournalError::Corrupt(_)) )); } - /// A store written at the schema this pass replaced is refused outright. - /// There is no migration adapter, and the refusal is the behaviour. - #[test] - fn a_store_from_the_knowledge_schema_is_refused() { - let row = CultCacheEnvelope { - key: "state".into(), - r#type: "world_state.knowledge.v1".into(), - payload: Vec::new(), - stored_at: Utc::now().to_rfc3339(), - schema_id: Some("ghostlight.world_state.knowledge.v1".into()), - }; - let error = recover(vec![row], None).unwrap_err(); - let JournalError::Corrupt(message) = error else { - panic!("expected a corrupt store"); - }; - assert!( - message.contains("unadmitted row type"), - "unexpected refusal: {message}" - ); - } - - /// A `Witness` reaches the store through two rows — a commit carries the - /// admitted operations and the state row carries the event's effects — so - /// both schemas bumped and both prior versions are refused at open. There - /// is no migration adapter and no dual read. - #[test] - fn a_store_written_before_the_witness_schema_is_refused() { - for (row_type, schema) in [ - (STATE_ROW, "ghostlight.world_state.consumer.v1"), - (COMMIT_ROW, "ghostlight.world_commit.consumer.v1"), - ] { - let row = CultCacheEnvelope { - key: "state".into(), - r#type: row_type.into(), - payload: Vec::new(), - stored_at: Utc::now().to_rfc3339(), - schema_id: Some(schema.into()), - }; - let error = recover(vec![row], None).unwrap_err(); - let JournalError::Corrupt(message) = error else { - panic!("expected a corrupt store for {schema}"); - }; - assert!( - message.contains("has the wrong schema"), - "unexpected refusal for {schema}: {message}" - ); - } - } - - /// A store written under an older schema is refused at open: both - /// `consumer.v4` strings and the pre-cut `consumer.v6` and `consumer.v8` - /// ones. No migration, no dual read. - #[test] - fn a_store_written_under_an_older_schema_is_refused() { - for (row_type, schema) in [ - (STATE_ROW, "ghostlight.world_state.consumer.v4"), - (COMMIT_ROW, "ghostlight.world_commit.consumer.v4"), - (STATE_ROW, "ghostlight.world_state.consumer.v6"), - (COMMIT_ROW, "ghostlight.world_commit.consumer.v6"), - (STATE_ROW, "ghostlight.world_state.consumer.v8"), - (COMMIT_ROW, "ghostlight.world_commit.consumer.v8"), - (STATE_ROW, "ghostlight.world_state.consumer.v9"), - (COMMIT_ROW, "ghostlight.world_commit.consumer.v9"), - ] { - let row = CultCacheEnvelope { - key: "state".into(), - r#type: row_type.into(), - payload: Vec::new(), - stored_at: Utc::now().to_rfc3339(), - schema_id: Some(schema.into()), - }; - let error = recover(vec![row], None).unwrap_err(); - let JournalError::Corrupt(message) = error else { - panic!("expected a corrupt store for {schema}"); - }; - assert!( - message.contains("has the wrong schema"), - "unexpected refusal for {schema}: {message}" - ); - } - } - /// A world whose history includes a patch and a clock advance, both Play's, - /// reopened from its own store rows. - fn clock_history() -> (tempfile::TempDir, WorldKernel) { + /// reopened from its own export. + fn clock_history() -> WorldKernel { use crate::tests::{auth_principal, creation, owner, submit_play}; use crate::TickMinutes; - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, _) = WorldKernel::create( - directory.path().join("world.cc"), - creation("Clock History"), + let (mut kernel, _) = WorldKernel::create(creation("Clock History"), &auth_principal(owner()), ) .unwrap(); @@ -1289,40 +879,79 @@ mod tests { minutes: TickMinutes::new(30).unwrap(), }, ); - (directory, kernel) - } - - fn rows_of(state: &WorldState, commits: &[WorldCommit]) -> Vec { - let mut rows: Vec = commits - .iter() - .map(|commit| { - envelope(COMMIT_ROW, COMMIT_SCHEMA, commit.command.id().key(), commit).unwrap() - }) - .collect(); - rows.push(envelope(STATE_ROW, STATE_SCHEMA, state.world_id.key(), state).unwrap()); - rows + kernel } /// Replay re-derives Play's patch and clock advance: the honest history - /// reopens to the same state digest and reading, and the store on disk does too. + /// reopens to the same state digest and reading, and the exported bytes do too. #[test] fn a_history_with_a_patch_and_a_clock_advance_replays_exactly() { - let (directory, kernel) = clock_history(); - let honest: Vec = kernel.journal.commits.values().cloned().collect(); - let (_, replayed, commits) = - recover(rows_of(&kernel.state, &honest), None).expect("the honest history replays"); - assert_eq!(commits.len(), honest.len()); + let kernel = clock_history(); + let replayed = reopen(&kernel.journal.commits).expect("the honest history replays"); assert_eq!(replayed.state_digest, kernel.state.state_digest); assert_eq!(replayed.now, kernel.state.now); - let (world_id, digest, now) = - (kernel.state.world_id, kernel.state.state_digest.clone(), kernel.state.now); + let (digest, now) = (kernel.state.state_digest.clone(), kernel.state.now); + let exported = kernel.export().unwrap(); drop(kernel); - let reopened = WorldKernel::open(directory.path().join("world.cc"), world_id).unwrap(); + let reopened = WorldKernel::open(&exported).unwrap(); assert_eq!(reopened.state.state_digest, digest); assert_eq!(reopened.state.now, now); } + /// An export is a claim about a chain, and `open` believes none of it that + /// replay does not derive: a chain with a commit missing, repeated or out of + /// order, a Ghostlight commit or export schema, and a non-canonical + /// encoding of an honest chain are each refused. + #[test] + fn forged_exports_are_refused() { + let kernel = clock_history(); + let honest = kernel.journal.commits.clone(); + assert_eq!(honest.len(), 3, "genesis, a patch and a tick"); + reopen(&honest).expect("the honest chain opens"); + let refused = |what: &str, commits: &[WorldCommit]| { + assert!( + matches!(reopen(commits), Err(JournalError::Corrupt(_))), + "{what} was admitted" + ); + }; + + refused("a missing middle commit", &[honest[0].clone(), honest[2].clone()]); + refused("a world without genesis", &honest[1..]); + refused("a repeated commit", &[honest[0].clone(), honest[1].clone(), honest[1].clone(), honest[2].clone()]); + refused("reordered commits", &[honest[0].clone(), honest[2].clone(), honest[1].clone()]); + refused("no commits", &[]); + + let mut ghostlight = honest.clone(); + ghostlight[1].schema = "ghostlight.world_commit.consumer.v10".into(); + ghostlight[1].digest = commit_digest(&ghostlight[1]).unwrap(); + refused("a ghostlight commit schema", &ghostlight); + + let foreign = rmp_serde::to_vec_named(&ExportRef { + schema: "ghostlight.world_state.consumer.v10", + commits: &honest, + }) + .unwrap(); + assert!(matches!( + WorldJournal::open(&foreign), + Err(JournalError::Corrupt(_)) + )); + + let positional = rmp_serde::to_vec(&ExportRef { + schema: JOURNAL_SCHEMA, + commits: &honest, + }) + .unwrap(); + assert!(matches!( + WorldJournal::open(&positional), + Err(JournalError::Corrupt(_)) + )); + assert!(matches!( + WorldJournal::open(&[0xc1]), + Err(JournalError::Corrupt(_)) + )); + } + /// A stored command is not believed about who made it. The forgery re-seals /// the commit around its rewrite and the head's last commit digest names the /// re-sealed commit, so no digest can answer for the check; the control, the @@ -1332,14 +961,14 @@ mod tests { fn a_commit_forged_to_the_owner_fails_replay() { use crate::tests::owner; - let (_directory, kernel) = clock_history(); - let honest: Vec = kernel.journal.commits.values().cloned().collect(); + let kernel = clock_history(); + let honest: Vec = kernel.journal.commits.clone(); // Re-seals the rewritten commit and every later one around it, so the // chain of previous-commit digests agrees and only the caller check is // left to refuse the history. let forge = |is_row: &dyn Fn(&WorldEffect) -> bool, rewrite: &dyn Fn(&mut WorldCommit)| - -> (WorldState, Vec) { + -> Vec { let mut forged: Vec = honest.clone(); forged.sort_by_key(|commit| commit.resulting_revision); let rows: Vec = (0..forged.len()) @@ -1354,28 +983,24 @@ mod tests { } forged[index].digest = commit_digest(&forged[index]).unwrap(); } - let mut head = kernel.state.clone(); - head.last_commit_digest = forged.last().map(|commit| commit.digest.clone()); - (head, forged) + forged }; let patch_row = |effect: &WorldEffect| matches!(effect, WorldEffect::PatchAdmitted { .. }); let clock_row = |effect: &WorldEffect| matches!(effect, WorldEffect::TimeAdvanced { .. }); for is_row in [&patch_row as &dyn Fn(&WorldEffect) -> bool, &clock_row] { - let (head, control) = forge(is_row, &|_| {}); - recover(rows_of(&head, &control), None) + let control = forge(is_row, &|_| {}); + reopen(&control) .expect("a consistent re-sealed store replays"); - let (head, forged) = forge(is_row, &|commit| { + let forged = forge(is_row, &|commit| { if let CommittedCommand::WorldCommand(command) = &mut commit.command { command.caller = CallerId::Principal(owner()); } }); - let error = recover(rows_of(&head, &forged), None) + let error = reopen(&forged) .expect_err("a commit forged to the owner replayed"); - let JournalError::Corrupt(_) = error else { - panic!("unexpected refusal: {error:?}"); - }; + let JournalError::Corrupt(_) = error; } } @@ -1390,12 +1015,8 @@ mod tests { TickMinutes, }; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("Chronicle"), + let (mut kernel, _) = WorldKernel::create(crate::tests::creation("Chronicle"), &authenticated, ) .unwrap(); @@ -1414,7 +1035,6 @@ mod tests { ) .unwrap(); - let mut forged_head = kernel.state.clone(); let mut forged_commits = kernel.journal.commits.clone(); let forged = last_commit(&mut forged_commits); let WorldEffect::TimeAdvanced { to, .. } = &mut forged.effect else { @@ -1422,10 +1042,9 @@ mod tests { }; *to = FictionalMinutes(31); forged.digest = commit_digest(forged).unwrap(); - forged_head.last_commit_digest = Some(forged.digest.clone()); assert!(matches!( - verify_history(&forged_head, &forged_commits), + reopen(&forged_commits), Err(JournalError::Corrupt(_)) )); } @@ -1436,12 +1055,8 @@ mod tests { fn a_forged_relocate_effect_does_not_apply() { use crate::tests::{admit_topology, auth_principal, command, owner}; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("Kharad"), + let (mut kernel, _) = WorldKernel::create(crate::tests::creation("Kharad"), &authenticated, ) .unwrap(); @@ -1467,7 +1082,6 @@ mod tests { ) .unwrap(); - let mut forged_head = kernel.state.clone(); let mut forged_commits = kernel.journal.commits.clone(); let forged = last_commit(&mut forged_commits); let WorldEffect::PatchAdmitted { resolved, .. } = &mut forged.effect else { @@ -1479,10 +1093,9 @@ mod tests { }; *subject_id = crate::SubjectId::issue(); forged.digest = commit_digest(forged).unwrap(); - forged_head.last_commit_digest = Some(forged.digest.clone()); assert!(matches!( - verify_history(&forged_head, &forged_commits), + reopen(&forged_commits), Err(JournalError::Corrupt(_)) )); } @@ -1505,12 +1118,8 @@ mod tests { }; let forge = |kind: &str, mutate: &dyn Fn(&mut crate::DecisionEvent)| { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("ForgedDecision"), + let (mut kernel, _) = WorldKernel::create(crate::tests::creation("ForgedDecision"), &authenticated, ) .unwrap(); @@ -1552,35 +1161,29 @@ mod tests { .unwrap(); // The honest journal recovers. - assert!(verify_history(&kernel.state, &kernel.journal.commits).is_ok()); + assert!(reopen(&kernel.journal.commits).is_ok()); - let mut forged_head = kernel.state.clone(); let mut forged_commits = kernel.journal.commits.clone(); let forged = last_commit(&mut forged_commits); let WorldEffect::Acted { event, .. } = &mut forged.effect else { panic!("expected an acted effect"); }; mutate(event); - let forged_event = event.clone(); - *forged_head.events.last_mut().unwrap() = forged_event; forged.digest = commit_digest(forged).unwrap(); - forged_head.last_commit_digest = Some(forged.digest.clone()); - forged_head.state_digest = String::new(); - forged_head.state_digest = crate::state_digest(&forged_head).unwrap(); - (forged_head, forged_commits) + forged_commits }; // A band the seed did not draw, held inside a chain that verifies. - let (head, commits) = forge("carry_chance", &|event| { + let commits = forge("carry_chance", &|event| { event.band = (event.band + 1) % 3; }); assert!(matches!( - verify_history(&head, &commits), + reopen(&commits), Err(JournalError::Corrupt(_)) )); // A magnitude the ceiling admitted but the lowering never produced. - let (head, commits) = forge("carry", &|event| { + let commits = forge("carry", &|event| { let Some(crate::ResolvedOp::Transfer { qty, .. }) = event.effects.first_mut() else { panic!("expected a lowered transfer"); @@ -1588,15 +1191,13 @@ mod tests { *qty = Quantity(1); }); assert!(matches!( - verify_history(&head, &commits), + reopen(&commits), Err(JournalError::Corrupt(_)) )); } #[test] fn replay_rejects_genesis_that_does_not_derive_from_its_creation_command() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let owner = PrincipalId::new("owner@example.test"); let authenticated = AuthenticatedCaller::fixture(CallerId::Principal(owner.clone())); let creation = CreateWorld { @@ -1612,8 +1213,7 @@ mod tests { }), grammar: None, }; - let (kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap(); - let mut forged_head = kernel.state.clone(); + let (kernel, _) = WorldKernel::create(creation, &authenticated).unwrap(); let mut forged_commits = kernel.journal.commits.clone(); let forged = genesis_commit(&mut forged_commits); let CommittedCommand::CreateWorld(command) = &mut forged.command else { @@ -1621,14 +1221,12 @@ mod tests { }; command.title = "Different command".into(); forged.digest = commit_digest(forged).unwrap(); - forged_head.last_commit_digest = Some(forged.digest.clone()); assert!(matches!( - verify_history(&forged_head, &forged_commits), + reopen(&forged_commits), Err(JournalError::Corrupt(_)) )); - let mut binding_forged_head = kernel.state.clone(); let mut binding_forged_commits = kernel.journal.commits.clone(); let binding_forged = genesis_commit(&mut binding_forged_commits); let WorldEffect::WorldCreated { resolved, .. } = &mut binding_forged.effect else { @@ -1636,48 +1234,30 @@ mod tests { }; resolved.subjects[0].subject.label = "Not the creation subject".into(); binding_forged.digest = commit_digest(binding_forged).unwrap(); - binding_forged_head.last_commit_digest = Some(binding_forged.digest.clone()); assert!(matches!( - verify_history(&binding_forged_head, &binding_forged_commits), + reopen(&binding_forged_commits), Err(JournalError::Corrupt(_)) )); } /// Soul falsification: the extended replay shape check is not decoration. - /// A forged store row carrying a self-loop, a cost out of range, a + /// A forged state carrying a self-loop, a cost out of range, a /// non-place endpoint, or a position on a non-place is refused by - /// `recover`, which is the path `WorldJournal::open` takes. + /// `verify_state_shape`, which `WorldJournal::open` runs on the replayed head. #[test] - fn soul_forged_topology_store_rows_are_refused_on_recover() { + fn soul_forged_topology_states_are_refused_by_the_shape_check() { use crate::patch::{AccessKind, Cost, EdgeRecord, MAX_ROUTE_COST}; use crate::tests::{admit_topology, auth_principal, owner}; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("Forged Rows"), + let (mut kernel, _) = WorldKernel::create(crate::tests::creation("Forged Rows"), &auth_principal(owner()), ) .unwrap(); let topology = admit_topology(&mut kernel); - let commits: Vec = kernel - .journal - .commits - .values() - .map(|commit| { - envelope(COMMIT_ROW, COMMIT_SCHEMA, commit.command.id().key(), commit).unwrap() - }) - .collect(); - let rows_for = |state: &WorldState, row_type: &str| { - let mut rows = commits.clone(); - rows.push(envelope(row_type, STATE_SCHEMA, state.world_id.key(), state).unwrap()); - rows - }; - // The honest state recovers. - assert!(recover(rows_for(&kernel.state, STATE_ROW), None).is_ok()); + assert!(verify_state_shape(&kernel.state).is_ok()); + assert!(reopen(&kernel.journal.commits).is_ok()); let self_loop = { let mut state = kernel.state.clone(); @@ -1720,7 +1300,7 @@ mod tests { state }; for forged in [self_loop, bad_cost, non_place_endpoint, stray_position] { - let error = recover(rows_for(&forged, STATE_ROW), None).unwrap_err(); + let error = verify_state_shape(&forged).unwrap_err(); assert!( matches!(error, JournalError::Corrupt(_)), "a forged topology row recovered: {error:?}" @@ -1728,54 +1308,6 @@ mod tests { } } - /// Soul falsification: a store written before the topology partitions is - /// refused outright, with no migration adapter in the path. - #[test] - fn soul_a_pre_topology_store_row_is_refused() { - use crate::tests::{admit_topology, auth_principal, owner}; - - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("Old Store"), - &auth_principal(owner()), - ) - .unwrap(); - admit_topology(&mut kernel); - let mut rows: Vec = kernel - .journal - .commits - .values() - .map(|commit| { - envelope( - "world_commit.foundation.v2", - COMMIT_SCHEMA, - commit.command.id().key(), - commit, - ) - .unwrap() - }) - .collect(); - rows.push( - envelope( - "world_state.foundation.v1", - STATE_SCHEMA, - kernel.state.world_id.key(), - &kernel.state, - ) - .unwrap(), - ); - let error = recover(rows, None).unwrap_err(); - let JournalError::Corrupt(message) = error else { - panic!("expected a corrupt store, got {error:?}"); - }; - assert!( - message.contains("unadmitted row type"), - "unexpected refusal: {message}" - ); - } - /// A committed levy survives a restart exactly: the snapshot, the band, the /// lowered effects, and the re-derived authority verdict all come back, and /// the same envelope is already applied. @@ -1787,11 +1319,7 @@ mod tests { Target, }; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("Replayed Levy"), + let (mut kernel, _) = WorldKernel::create(crate::tests::creation("Replayed Levy"), &crate::tests::auth_principal(owner()), ) .unwrap(); @@ -1831,23 +1359,23 @@ mod tests { .unwrap(); let committed = kernel.snapshot().unwrap(); let event = kernel.state.events.last().expect("the levy event").clone(); - 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); let replayed = reopened.state.events.last().expect("the replayed event"); assert_eq!(replayed.band, event.band); assert_eq!(replayed.effects, event.effects); assert!(matches!( - reopened .submit(envelope, &AuthenticatedCaller::fixture(caller)), + reopened.submit(envelope, &AuthenticatedCaller::fixture(caller)), Err(KernelError::RevisionMismatch { .. }) )); } /// Soul falsification: the civic shape checks are not decoration. A forged - /// store row that widens a jurisdiction, doubles an incumbency, seats an - /// institution, or empties a delegation is refused by `recover`. + /// state that widens a jurisdiction, doubles an incumbency, seats an + /// institution, or empties a delegation is refused by the shape check. #[test] fn a_forged_authority_or_incumbency_is_corrupt() { use crate::tests::{ @@ -1857,29 +1385,13 @@ mod tests { use crate::{AuthorityGrant, AuthorityTarget, Office}; use std::collections::BTreeSet; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("Forged Civics"), + let (mut kernel, _) = WorldKernel::create(crate::tests::creation("Forged Civics"), &auth_principal(owner()), ) .unwrap(); let (topology, civic, _) = civic_world(&mut kernel); - let commits: Vec = kernel - .journal - .commits - .values() - .map(|commit| { - envelope(COMMIT_ROW, COMMIT_SCHEMA, commit.command.id().key(), commit).unwrap() - }) - .collect(); - let rows_for = |state: &WorldState| { - let mut rows = commits.clone(); - rows.push(envelope(STATE_ROW, STATE_SCHEMA, state.world_id.key(), state).unwrap()); - rows - }; - assert!(recover(rows_for(&kernel.state), None).is_ok()); + assert!(verify_state_shape(&kernel.state).is_ok()); + assert!(reopen(&kernel.journal.commits).is_ok()); let widened = { let mut state = kernel.state.clone(); @@ -1951,7 +1463,7 @@ mod tests { inert_office, office_on_person, ] { - let error = recover(rows_for(&forged), None).unwrap_err(); + let error = verify_state_shape(&forged).unwrap_err(); assert!( matches!(error, JournalError::Corrupt(_)), "a forged civic row recovered: {error:?}" @@ -1959,54 +1471,6 @@ mod tests { } } - /// Soul falsification: a store written before the civic partitions is - /// refused outright, with no migration adapter in the path. - #[test] - fn a_store_from_the_previous_schema_is_refused() { - use crate::tests::{auth_principal, civic_world, owner}; - - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - crate::tests::creation("Pre-Authority"), - &auth_principal(owner()), - ) - .unwrap(); - civic_world(&mut kernel); - let mut rows: Vec = kernel - .journal - .commits - .values() - .map(|commit| { - envelope( - "world_commit.affordance.v1", - COMMIT_SCHEMA, - commit.command.id().key(), - commit, - ) - .unwrap() - }) - .collect(); - rows.push( - envelope( - "world_state.affordance.v1", - STATE_SCHEMA, - kernel.state.world_id.key(), - &kernel.state, - ) - .unwrap(), - ); - let error = recover(rows, None).unwrap_err(); - let JournalError::Corrupt(message) = error else { - panic!("expected a corrupt store, got {error:?}"); - }; - assert!( - message.contains("unadmitted row type"), - "unexpected refusal: {message}" - ); - } - /// Soul falsification of the structural-overlap decision, updated for the /// admission-time covering check: a `Subject` grant naming ground a /// `PlaceSubtree` grant already covers is refused on arrival, but nothing @@ -2022,11 +1486,7 @@ mod tests { }; 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("Moving Civics"), + let (mut kernel, _) = WorldKernel::create(crate::tests::creation("Moving Civics"), &auth_principal(owner()), ) .unwrap(); @@ -2088,8 +1548,9 @@ mod tests { // The whole history replays, and the reopened world is identical. let committed = kernel.snapshot().unwrap(); + let exported = kernel.export().unwrap(); drop(kernel); - let reopened = WorldKernel::open(&path, committed.world_id).unwrap(); + let reopened = WorldKernel::open(&exported).unwrap(); assert_eq!(reopened.snapshot().unwrap(), committed); } } @@ -2097,7 +1558,7 @@ mod tests { #[cfg(test)] mod custody_tests { use super::*; - use super::tests::last_commit; + use super::tests::{last_commit, reopen}; use crate::{ CallerId, CommandBody, ComponentOp, DependencyRef, EntityKind, Quantity, Ref, WorldKernel, WorldPatch, @@ -2109,11 +1570,9 @@ mod custody_tests { /// envelope is idempotent. #[test] fn restart_replay_after_a_transfer_is_exact() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); let (mut kernel, _) = - WorldKernel::create(&path, creation("Replay"), &authenticated) + WorldKernel::create(creation("Replay"), &authenticated) .unwrap(); let topology = admit_topology(&mut kernel); let custody = admit_custody(&mut kernel, &topology); @@ -2137,10 +1596,10 @@ mod custody_tests { ); kernel.submit(envelope.clone(), &crate::AuthenticatedCaller::verified_play()).unwrap(); let accepted = kernel.snapshot().unwrap(); - let world_id = accepted.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(), accepted); assert!(matches!( reopened.submit(envelope, &crate::AuthenticatedCaller::verified_play()), @@ -2156,12 +1615,8 @@ mod custody_tests { use crate::tests::{affordance_named, play_caller}; use crate::{AuthenticatedCaller, Magnitude, ProposedEffect, RoleBinding, Target}; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("ActionReplay"), + let (mut kernel, _) = WorldKernel::create(creation("ActionReplay"), &authenticated, ) .unwrap(); @@ -2209,52 +1664,28 @@ mod custody_tests { .expect("the committed event") .clone(); assert!(!committed.effects.is_empty()); - let world_id = accepted.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(), accepted); assert_eq!( reopened.state.events.last().expect("the replayed event"), &committed ); assert!(matches!( - reopened .submit(envelope, &authenticated_controller), + reopened.submit(envelope, &authenticated_controller), Err(KernelError::RevisionMismatch { .. }) )); } - /// A store written at the pass-2 schema is refused outright. There is no - /// migration adapter, and the refusal is the behaviour. - #[test] - fn a_store_from_the_previous_schema_is_refused() { - let row = CultCacheEnvelope { - key: "state".into(), - r#type: "world_state.topology.v1".into(), - payload: Vec::new(), - stored_at: Utc::now().to_rfc3339(), - schema_id: Some("ghostlight.world_state.topology.v1".into()), - }; - let error = recover(vec![row], None).unwrap_err(); - let JournalError::Corrupt(message) = error else { - panic!("expected a corrupt store"); - }; - assert!( - message.contains("unadmitted row type"), - "unexpected refusal: {message}" - ); - } - /// The title clause of the shape check refuses an empty title and a /// noncanonical one, each on its own. #[test] fn a_forged_empty_or_padded_title_is_corrupt() { use crate::tests::{auth_principal, creation, owner}; - let directory = tempfile::tempdir().unwrap(); - let (kernel, _) = WorldKernel::create( - directory.path().join("world.cc"), - creation("Titled"), + let (kernel, _) = WorldKernel::create(creation("Titled"), &auth_principal(owner()), ) .unwrap(); @@ -2277,11 +1708,7 @@ mod custody_tests { use crate::tests::{auth_principal, creation, owner}; use crate::{AffordanceId, SubjectId}; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (kernel, _) = WorldKernel::create( - &path, - creation("GrantRows"), + let (kernel, _) = WorldKernel::create(creation("GrantRows"), &auth_principal(owner()), ) .unwrap(); @@ -2323,11 +1750,7 @@ mod custody_tests { act, auth_principal, creation, first_grant, owner, speak, }; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("ActedChain"), + let (mut kernel, _) = WorldKernel::create(creation("ActedChain"), &auth_principal(owner()), ) .unwrap(); @@ -2346,9 +1769,9 @@ mod custody_tests { ) .unwrap(); let accepted = kernel.snapshot().unwrap(); - let world_id = accepted.world_id; + let exported = kernel.export().unwrap(); drop(kernel); - let reopened = WorldKernel::open(&path, world_id).expect("the acted chain recovers"); + let reopened = WorldKernel::open(&exported).expect("the acted chain recovers"); assert_eq!(reopened.snapshot().unwrap(), accepted); verify_state_shape(&reopened.state).expect("an honest event passes the shape check"); @@ -2367,67 +1790,6 @@ mod custody_tests { ); } - /// Stores written at the previous schema ids (v8) are refused outright, - /// state row and commit row each on their own: reverting either constant - /// to v8 would let its half of the store in. - #[test] - 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("SchemaV9"), - &auth_principal(owner()), - ) - .unwrap(); - let active = kernel.snapshot().unwrap(); - let actor = active.subjects[0].id; - act(&mut kernel, actor, speak(first_grant(&active, actor), "Counted.")).unwrap(); - let commits: Vec = kernel.journal.commits.values().cloned().collect(); - let commit_rows = |schema: &str| -> Vec { - commits - .iter() - .map(|commit| envelope(COMMIT_ROW, schema, commit.command.id().key(), commit).unwrap()) - .collect() - }; - let state_row = |schema: &str| { - envelope(STATE_ROW, schema, kernel.state.world_id.key(), &kernel.state).unwrap() - }; - 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, - ) - .expect("the current schema ids recover"); - - for (what, rows) in [ - ( - "ghostlight state row", - [ - commit_rows(COMMIT_SCHEMA), - vec![state_row("ghostlight.world_state.consumer.v10")], - ] - .concat(), - ), - ( - "ghostlight commit rows", - [ - commit_rows("ghostlight.world_commit.consumer.v10"), - vec![state_row(STATE_SCHEMA)], - ] - .concat(), - ), - ] { - let error = recover(rows, None).unwrap_err(); - let JournalError::Corrupt(message) = error else { - panic!("{what}: expected a corrupt store, got {error:?}"); - }; - assert!(message.contains("wrong schema"), "{what}: {message}"); - } - } - /// The event shape check holds for a silent act too: a non-speech event /// whose actor is no subject is corrupt, with no minted claim to catch it. #[test] @@ -2438,10 +1800,7 @@ mod custody_tests { }; use crate::{DecisionInvocation, Magnitude, ProposedEffect, Quantity, Role, RoleBinding, Target}; - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, _) = WorldKernel::create( - directory.path().join("world.cc"), - creation("SilentForgery"), + let (mut kernel, _) = WorldKernel::create(creation("SilentForgery"), &auth_principal(owner()), ) .unwrap(); @@ -2495,11 +1854,9 @@ mod custody_tests { /// falsification. #[test] fn a_zero_or_dangling_holding_is_corrupt() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); let (mut kernel, _) = - WorldKernel::create(&path, creation("Shape"), &authenticated) + WorldKernel::create(creation("Shape"), &authenticated) .unwrap(); let topology = admit_topology(&mut kernel); let custody = admit_custody(&mut kernel, &topology); @@ -2553,12 +1910,8 @@ mod custody_tests { /// envelope is idempotent, and the whole chain still verifies. #[test] fn soul_replay_is_exact_after_every_custody_operation() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("EveryOperation"), + let (mut kernel, _) = WorldKernel::create(creation("EveryOperation"), &authenticated, ) .unwrap(); @@ -2610,10 +1963,10 @@ mod custody_tests { let holdings = kernel.state.holdings.clone(); let dependencies = kernel.state.dependencies.clone(); let digest = kernel.state.state_digest.clone(); - let world_id = accepted.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(), accepted); assert_eq!(reopened.state.holdings, holdings); assert_eq!(reopened.state.dependencies, dependencies); @@ -2629,12 +1982,8 @@ mod custody_tests { /// referential integrity the operation arm enforces at admission. #[test] fn soul_a_dependency_on_an_absent_or_wrong_kind_target_is_corrupt() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let authenticated = auth_principal(owner()); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("DependencyShape"), + let (mut kernel, _) = WorldKernel::create(creation("DependencyShape"), &authenticated, ) .unwrap(); @@ -2678,7 +2027,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) { + fn ticking_world() -> (WorldKernel, super::super::SubjectId) { use crate::tests::{auth_principal, command, operations, owner}; use crate::{ AuthenticatedCaller, CallerId, CommandBody, CommitmentKind, ComponentOp, @@ -2687,7 +2036,6 @@ mod custody_tests { let authenticated = auth_principal(owner()); let (mut kernel, _) = WorldKernel::create( - path, crate::tests::creation("Ticking"), &authenticated, ) @@ -2750,13 +2098,11 @@ mod custody_tests { fn soul_a_forged_tick_motion_does_not_replay() { use crate::{FictionalMinutes, PressureMagnitude, PressureSource}; - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (kernel, subject) = ticking_world(&path); + let (kernel, subject) = ticking_world(); let WorldEffect::TimeAdvanced { motion, .. } = &kernel .journal .commits - .values() + .iter() .max_by_key(|commit| commit.resulting_revision) .expect("the tick's commit") .effect @@ -2767,7 +2113,6 @@ mod custody_tests { assert!(!motion.pressed.is_empty(), "the past-due goal pressed"); let forge = |rewrite: fn(&mut crate::Motion)| { - let mut forged_head = kernel.state.clone(); let mut forged_commits = kernel.journal.commits.clone(); let forged = last_commit(&mut forged_commits); let WorldEffect::TimeAdvanced { motion, .. } = &mut forged.effect else { @@ -2775,8 +2120,7 @@ mod custody_tests { }; rewrite(motion); forged.digest = commit_digest(forged).unwrap(); - forged_head.last_commit_digest = Some(forged.digest.clone()); - verify_history(&forged_head, &forged_commits) + reopen(&forged_commits) }; let rewrites: [fn(&mut crate::Motion); 4] = [ @@ -2809,9 +2153,7 @@ mod custody_tests { /// constructor enforces, so the forged row is refused directly. #[test] 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(); // The forgery an in-crate caller cannot write: `TickMinutes::new` // refuses zero, and the field is private, so the only door is serde. @@ -2838,19 +2180,6 @@ mod custody_tests { matches!(verify_state_shape(&forged), Err(JournalError::Corrupt(_))), "verify_state_shape admitted a period outside 1..=MAX_ROUTE_COST" ); - - // The commit chain refuses it too. - let commits: Vec = kernel - .journal - .commits - .values() - .map(|commit| { - envelope(COMMIT_ROW, COMMIT_SCHEMA, commit.command.id().key(), commit).unwrap() - }) - .collect(); - let mut rows = commits; - rows.push(envelope(STATE_ROW, STATE_SCHEMA, forged.world_id.key(), &forged).unwrap()); - assert!(matches!(recover(rows, None), Err(JournalError::Corrupt(_)))); } } diff --git a/native/aetherlight/src/lib.rs b/native/aetherlight/src/lib.rs index ce2483ab9..0647e8db3 100644 --- a/native/aetherlight/src/lib.rs +++ b/native/aetherlight/src/lib.rs @@ -1,8 +1,10 @@ //! The Aetherlight world library, a fork of Ghostlight c43eb54 (see `PROVENANCE.md`). //! //! The world owner is one deterministic authority: authenticated commands enter, -//! one reducer decides, and one journal atomically commits the resulting state. -//! The fork keeps only that synchronous kernel: no async runtime, no network, no +//! one reducer decides, and the journal, an in-memory list of commits, records +//! each result. The journal exports as bytes, and opening those bytes replays +//! the chain from genesis: the head state is whatever the replay derives. +//! The fork keeps only that single-threaded kernel: no async runtime, no network, no //! model controllers and no ports. A decision arrives as an invocation the caller //! built, a player or a brain; nothing in this crate composes one. //! @@ -97,8 +99,6 @@ use patch::{EdgeRecord, EntityRecord, LedgerDelta, ResolvedOp, ResolvedPatch}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::collections::{BTreeMap, BTreeSet}; -#[cfg(test)] -use std::path::Path; use thiserror::Error; use uuid::Uuid; @@ -848,52 +848,18 @@ pub enum KernelError { AffordanceDenied, #[error("expected revision {expected}, current revision {actual}")] RevisionMismatch { expected: u64, actual: u64 }, - #[error("world creation ID was reused with different content")] - CreationConflict, - #[error("world creation target already contains another world")] - CreationTargetOccupied, - #[error("world has not been created")] - WorldNotCreated, - #[error("opened store contains another world")] - OpenedWorldMismatch, - #[error("world ownership is uncertain after command {command_id:?}; drop and reopen")] - RecoveryRequired { command_id: CommandId }, - #[error("world store path no longer names the owned database; drop and reopen explicitly")] - OwnershipLost, #[error("canonical serialization failed: {0}")] Serialization(String), - #[error("world store operation failed: {0}")] - Store(String), #[error("world journal is corrupt: {0}")] CorruptJournal(String), #[error("private reducer invariant failed: {0}")] Invariant(String), } -impl KernelError { - fn requires_owner_restart(&self) -> bool { - matches!( - self, - Self::RecoveryRequired { .. } - | Self::OwnershipLost - | Self::Store(_) - | Self::CorruptJournal(_) - | Self::Invariant(_) - ) - } -} - impl From for KernelError { fn from(error: journal::JournalError) -> Self { - match error { - journal::JournalError::WorldMismatch => Self::OpenedWorldMismatch, - journal::JournalError::RecoveryRequired { command_id } => { - Self::RecoveryRequired { command_id } - } - journal::JournalError::OwnershipLost => Self::OwnershipLost, - journal::JournalError::Store(detail) => Self::Store(detail), - journal::JournalError::Corrupt(detail) => Self::CorruptJournal(detail), - } + let journal::JournalError::Corrupt(detail) = error; + Self::CorruptJournal(detail) } } @@ -947,10 +913,7 @@ fn prepare_creation( } impl WorldKernel { - fn initialize( - empty: journal::EmptyWorldJournal, - prepared: PreparedCreation, - ) -> Result<(Self, CreationReceipt), KernelError> { + fn initialize(prepared: PreparedCreation) -> Result<(Self, CreationReceipt), KernelError> { let world_id = prepared.world_id; let effect = WorldEffect::WorldCreated { owner: prepared.owner, @@ -973,48 +936,28 @@ impl WorldKernel { genesis.digest = commit_digest(&genesis)?; state.last_commit_digest = Some(genesis.digest.clone()); let receipt = CreationReceipt::from_commit(&genesis)?; - let journal = empty.initialize(&state, &genesis)?; + let journal = journal::WorldJournal::genesis(genesis); Ok((Self { state, journal }, receipt)) } - fn retry_creation(&self, prepared: &PreparedCreation) -> Result { - self.journal.ensure_healthy()?; - let Some(commit) = self.journal.commit_for(prepared.command.id()) else { - return Err(KernelError::CreationTargetOccupied); - }; - if commit.command != CommittedCommand::CreateWorld(prepared.command.clone()) - || !matches!(&commit.effect, WorldEffect::WorldCreated { .. }) - { - return Err(KernelError::CreationConflict); - } - CreationReceipt::from_commit(commit) - } - - #[cfg(test)] fn create( - path: impl AsRef, input: CreateWorld, authenticated: &AuthenticatedCaller, ) -> Result<(Self, CreationReceipt), KernelError> { - let prepared = prepare_creation(input, authenticated)?; - match journal::WorldJournal::open_owner(path.as_ref())? { - journal::JournalOpen::Empty(empty) => Self::initialize(empty, prepared), - journal::JournalOpen::Live { journal, state } => { - let kernel = Self { state, journal }; - let receipt = kernel.retry_creation(&prepared)?; - Ok((kernel, receipt)) - } - } + Self::initialize(prepare_creation(input, authenticated)?) } - #[cfg(test)] - fn open(path: impl AsRef, expected_world_id: WorldId) -> Result { - let (journal, state) = journal::WorldJournal::open(path.as_ref(), expected_world_id)?; + /// The world an export derives: its head state is the replay of its commits. + fn open(bytes: &[u8]) -> Result { + let (journal, state) = journal::WorldJournal::open(bytes)?; Ok(Self { state, journal }) } + fn export(&self) -> Result, KernelError> { + self.journal.export() + } + fn snapshot(&self) -> Result { - self.journal.ensure_healthy()?; snapshot(&self.state) } @@ -1023,7 +966,6 @@ impl WorldKernel { command: CommandEnvelope, authenticated: &AuthenticatedCaller, ) -> Result { - self.journal.ensure_healthy()?; let command_id = command.id(); if command.world_id != self.state.world_id { return Err(KernelError::WorldMismatch); @@ -1062,9 +1004,10 @@ impl WorldKernel { commit.digest = commit_digest(&commit)?; candidate.last_commit_digest = Some(commit.digest.clone()); - self.journal.commit(&candidate, &commit)?; + let receipt = CommitReceipt::from(&commit); + self.journal.append(commit); self.state = candidate; - Ok(CommitReceipt::from(&commit)) + Ok(receipt) } } @@ -4669,57 +4612,63 @@ mod tests { #[test] fn create_submit_restart_and_replay_are_exact() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); let creation = creation("First"); let (mut kernel, creation_receipt) = - WorldKernel::create(&path, creation.clone(), &auth_principal(owner())).unwrap(); + WorldKernel::create(creation.clone(), &auth_principal(owner())).unwrap(); let active = kernel.snapshot().unwrap(); let operator = subject_by_label(&kernel.state, "The Council"); - let caller = play_caller(); let command = command( &active, - caller.clone(), + play_caller(), CommandBody::Act { actor: operator, invocation: speak(first_grant(&active, operator), "The vote carries."), }, ); kernel - .submit( - command.clone(), - &AuthenticatedCaller::fixture(caller.clone()), - ) + .submit(command.clone(), &AuthenticatedCaller::verified_play()) .unwrap(); let accepted = kernel.snapshot().unwrap(); - drop(kernel); + let exported = kernel.export().unwrap(); - let (mut reopened, retried_creation_receipt) = - WorldKernel::create(&path, creation, &auth_principal(owner())).unwrap(); - assert_eq!(retried_creation_receipt, creation_receipt); + // The same creation names the same world, with the same receipt. + let (_, retried) = WorldKernel::create(creation, &auth_principal(owner())).unwrap(); + assert_eq!(retried, creation_receipt); + + // The export is the whole world: its reopening is equal, re-exports + // byte for byte, and the applied command is stale in it. + let mut reopened = WorldKernel::open(&exported).unwrap(); assert_eq!(reopened.snapshot().unwrap(), accepted); + assert_eq!(reopened.export().unwrap(), exported); assert!(matches!( - reopened .submit(command, &AuthenticatedCaller::fixture(caller)), + reopened.submit(command, &AuthenticatedCaller::verified_play()), Err(KernelError::RevisionMismatch { .. }) )); - drop(reopened); - let reopened = WorldKernel::open(&path, accepted.world_id).unwrap(); - assert_eq!(reopened.snapshot().unwrap(), accepted); + + // The next command gives equal receipts and equal worlds on both. + let next = play_command(&accepted, tick_body(1)); + let original_receipt = kernel + .submit(next.clone(), &AuthenticatedCaller::verified_play()) + .unwrap(); + let reopened_receipt = reopened + .submit(next, &AuthenticatedCaller::verified_play()) + .unwrap(); + assert_eq!(original_receipt, reopened_receipt); + assert_eq!(kernel.snapshot().unwrap(), reopened.snapshot().unwrap()); + assert_eq!(kernel.export().unwrap(), reopened.export().unwrap()); } #[test] - fn stale_commands_do_not_commit() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("Still"), + fn a_stale_command_is_a_revision_mismatch() { + let (mut kernel, _) = WorldKernel::create(creation("Still"), &auth_principal(owner()), ) .unwrap(); let genesis = kernel.snapshot().unwrap(); assert!(submit_play(&mut kernel, &genesis, tick_body(1)).resulting_revision > 0); let after = kernel.snapshot().unwrap(); + // The very command that was applied, resubmitted: there is no retry + // identity, so it is stale like any other. let stale = play_command(&genesis, tick_body(1)); assert!(matches!( kernel.submit(stale, &AuthenticatedCaller::verified_play()), @@ -4731,17 +4680,15 @@ mod tests { #[test] fn ids_are_derived_from_the_command() { - let dir = tempfile::tempdir().unwrap(); - let create = |name: &str, title: &str| { - WorldKernel::create(dir.path().join(name), creation(title), &auth_principal(owner())) - .unwrap() + let create = |title: &str| { + WorldKernel::create(creation(title), &auth_principal(owner())).unwrap() }; - let (mut kernel, receipt) = create("a.cc", "Same"); - let (twin, twin_receipt) = create("b.cc", "Same"); + let (mut kernel, receipt) = create("Same"); + let (twin, twin_receipt) = create("Same"); assert_eq!(receipt, twin_receipt); assert_eq!(kernel.state.world_id, twin.state.world_id); assert_eq!(receipt.world_id, WorldId::of(receipt.command_id)); - let (other, _) = create("c.cc", "Other"); + let (other, _) = create("Other"); assert_ne!(kernel.state.world_id, other.state.world_id); // The same patch at two revisions is two commands, so the entity it @@ -4778,12 +4725,10 @@ mod tests { #[test] fn invalid_seed_never_allocates_a_world() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); let mut invalid = creation("Nope"); invalid.patch.declarations[3] = invalid.patch.declarations[2].clone(); let Err(KernelError::PatchRejected(rejected)) = - WorldKernel::create(&path, invalid, &auth_principal(owner())) + WorldKernel::create(invalid, &auth_principal(owner())) else { panic!("expected a rejected creation patch"); }; @@ -4794,137 +4739,16 @@ mod tests { }] ); assert!( - WorldKernel::create( - &path, - creation("Valid"), + WorldKernel::create(creation("Valid"), &auth_principal(owner()) ) .is_ok() ); } - #[test] - fn a_second_live_owner_is_refused() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); - let creation = creation("Held"); - let (kernel, _) = - WorldKernel::create(&path, creation.clone(), &auth_principal(owner())).unwrap(); - let world_id = kernel.snapshot().unwrap().world_id; - assert!(matches!( - WorldKernel::open(&path, world_id), - Err(KernelError::Store(_)) - )); - assert!(matches!( - WorldKernel::create(&path, creation.clone(), &auth_principal(owner())), - Err(KernelError::Store(_)) - )); - drop(kernel); - let kernel = WorldKernel::open(&path, world_id).unwrap(); - drop(kernel); - assert!(matches!( - WorldKernel::open(&path, WorldId::of(CommandId::issue())), - Err(KernelError::OpenedWorldMismatch) - )); - } - - #[test] - fn lost_post_commit_ack_poisons_until_reopen_and_exact_retry() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("Certain"), - &auth_principal(owner()), - ) - .unwrap(); - let genesis = kernel.snapshot().unwrap(); - let attempted = play_command(&genesis, tick_body(1)); - let uncertain = attempted.id(); - kernel.journal.fail_after_durable_commit_for_test(); - assert!(matches!( - kernel.submit(attempted.clone(), &AuthenticatedCaller::verified_play()), - Err(KernelError::RecoveryRequired { command_id }) if command_id == uncertain - )); - assert!(matches!( - kernel.snapshot(), - Err(KernelError::RecoveryRequired { command_id }) if command_id == uncertain - )); - drop(kernel); - - let mut reopened = WorldKernel::open(&path, genesis.world_id).unwrap(); - let durable = reopened.snapshot().unwrap(); - assert_eq!(durable.revision, 1); - assert!(matches!( - reopened .submit(attempted, &AuthenticatedCaller::verified_play()), - Err(KernelError::RevisionMismatch { .. }) - )); - } - - #[test] - fn lost_genesis_ack_reopens_as_the_same_world_and_exact_receipt() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); - let input = creation("Durable Genesis"); - let command_id = input.id(); - let authenticated = auth_principal(owner()); - let mut empty = match journal::WorldJournal::open_owner(&path).unwrap() { - journal::JournalOpen::Empty(empty) => empty, - journal::JournalOpen::Live { .. } => panic!("fixture store must be empty"), - }; - empty.fail_after_durable_initialize_for_test(); - let prepared = prepare_creation(input.clone(), &authenticated).unwrap(); - assert!(matches!( - WorldKernel::initialize(empty, prepared), - Err(KernelError::RecoveryRequired { command_id: uncertain }) - if uncertain == command_id - )); - - let (reopened, receipt) = WorldKernel::create(&path, input, &authenticated).unwrap(); - let snapshot = reopened.snapshot().unwrap(); - assert_eq!(receipt.command_id, command_id); - assert_eq!(receipt.world_id, snapshot.world_id); - assert_eq!(snapshot.revision, 0); - assert_eq!(snapshot.title, "Durable Genesis"); - } - - #[test] - fn replacing_the_store_path_revokes_the_live_owner() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); - let displaced = dir.path().join("displaced.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("Pinned"), - &auth_principal(owner()), - ) - .unwrap(); - let snapshot = kernel.snapshot().unwrap(); - std::fs::rename(&path, &displaced).unwrap(); - std::fs::File::create(&path).unwrap(); - assert!(matches!(kernel.snapshot(), Err(KernelError::OwnershipLost))); - assert!(matches!( - kernel.submit( - play_command(&snapshot, tick_body(1)), - &AuthenticatedCaller::verified_play() - ), - Err(KernelError::OwnershipLost) - )); - std::fs::remove_file(&path).unwrap(); - std::fs::rename(&displaced, &path).unwrap(); - assert!(matches!(kernel.snapshot(), Err(KernelError::OwnershipLost))); - drop(kernel); - let reopened = WorldKernel::open(&path, snapshot.world_id).unwrap(); - assert_eq!(reopened.snapshot().unwrap(), snapshot); - } - #[test] fn sealed_authentication_cannot_be_replaced_by_a_command_claim() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("world.cc"); - let (mut kernel, _) = WorldKernel::create( - &path, - creation("Owned"), + let (mut kernel, _) = WorldKernel::create(creation("Owned"), &auth_principal(owner()), ) .unwrap(); @@ -4946,10 +4770,7 @@ mod tests { /// that moves the world, not a hand-edited state. #[test] fn soul_scope_components_exclude_revision_and_everything_outside_the_scope() { - let dir = tempfile::tempdir().unwrap(); - let (mut kernel, _) = WorldKernel::create( - dir.path().join("world.cc"), - creation("Preimage"), + let (mut kernel, _) = WorldKernel::create(creation("Preimage"), &auth_principal(owner()), ) .unwrap(); @@ -5068,10 +4889,7 @@ mod tests { /// one that does not. #[test] fn act_needs_the_actors_grant() { - let dir = tempfile::tempdir().unwrap(); - let (mut kernel, _) = WorldKernel::create( - dir.path().join("world.cc"), - creation("SharedCatalogIds"), + let (mut kernel, _) = WorldKernel::create(creation("SharedCatalogIds"), &auth_principal(owner()), ) .unwrap(); @@ -5130,10 +4948,7 @@ mod tests { #[test] fn a_distant_route_closing_leaves_the_actors_scope_alone_and_its_act_commits() { - let dir = tempfile::tempdir().unwrap(); - let (mut kernel, _) = WorldKernel::create( - dir.path().join("world.cc"), - creation("BindingAndAdmission"), + let (mut kernel, _) = WorldKernel::create(creation("BindingAndAdmission"), &auth_principal(owner()), ) .unwrap(); @@ -5179,8 +4994,7 @@ mod tests { /// office, not one subject with two controllers. #[test] fn an_institution_and_its_voice_are_two_subjects_joined_by_an_office() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "Two"); + let mut kernel = crate::custody_tests::custody_kernel("Two"); let (_, civic, _) = civic_world(&mut kernel); @@ -5209,8 +5023,7 @@ mod tests { /// total unchanged, and no other partition touched. #[test] fn a_levy_round_trips_from_catalog_to_conservation() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "Levy"); + let mut kernel = crate::custody_tests::custody_kernel("Levy"); let (_, civic, active) = civic_world(&mut kernel); let before_total: u64 = kernel .state @@ -5293,8 +5106,7 @@ mod tests { /// that stops the two-subject shape from collapsing back into one. #[test] fn office_admission_is_person_and_institution_shaped() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "Offices"); + let mut kernel = crate::custody_tests::custody_kernel("Offices"); let (_, civic, _) = civic_world(&mut kernel); let refuse = |kernel: &mut WorldKernel, ops: Vec| { let before = kernel.snapshot().unwrap(); @@ -5343,8 +5155,7 @@ mod tests { /// authority is refused, overlap between subjects is layered government. #[test] fn overlapping_jurisdiction_within_one_subject_is_rejected() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "Overlap"); + let mut kernel = crate::custody_tests::custody_kernel("Overlap"); let (_, civic, _) = civic_world(&mut kernel); let refuse = |kernel: &mut WorldKernel, ops: Vec| { let before = kernel.snapshot().unwrap(); @@ -5401,8 +5212,7 @@ mod tests { /// allocation, and repairing exactly those failures commits. #[test] fn civic_operations_are_rejected_with_the_complete_set() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "CivicSet"); + let mut kernel = crate::custody_tests::custody_kernel("CivicSet"); let (_, civic, _) = civic_world(&mut kernel); let before = kernel.snapshot().unwrap(); let broken = vec![ @@ -5471,9 +5281,8 @@ mod tests { /// A civic operation that changes nothing is not a canonical change. #[test] fn an_idempotent_civic_operation_is_no_change() { - let directory = tempfile::tempdir().unwrap(); let mut kernel = - crate::custody_tests::custody_kernel(directory.path(), "Idempotent"); + crate::custody_tests::custody_kernel("Idempotent"); let (_, civic, _) = civic_world(&mut kernel); for operation in [ grant_to(civic.treasury, LEVY_KIND, over_place(civic.hall)), @@ -5508,8 +5317,7 @@ mod tests { /// world the actor reaches. #[test] fn scope_components_read_authority_and_delegation_but_not_occupancy() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "Digest"); + let mut kernel = crate::custody_tests::custody_kernel("Digest"); let (topology, civic, _) = civic_world(&mut kernel); let digest_of = |kernel: &WorldKernel, subject_id| { scope_components(&kernel.state, subject_id) @@ -5597,8 +5405,7 @@ mod tests { /// grants. #[test] fn a_forum_is_visible_only_to_its_standing() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "Redress"); + let mut kernel = crate::custody_tests::custody_kernel("Redress"); let (_, civic, active) = civic_world(&mut kernel); let of = |subject_id: SubjectId| { active @@ -5648,8 +5455,7 @@ mod tests { /// cannot declare a restricted room and walk anyone into it in one batch. #[test] fn a_same_patch_destination_is_covered_by_no_grant() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "DraftDoor"); + let mut kernel = crate::custody_tests::custody_kernel("DraftDoor"); let topology = admit_topology(&mut kernel); let before = kernel.snapshot().unwrap(); let patch = WorldPatch { @@ -5707,8 +5513,7 @@ mod tests { /// the one site that turns an office into effective authority. #[test] fn a_retired_institution_lends_no_authority_to_its_office_holder() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = crate::custody_tests::custody_kernel(directory.path(), "RetiredLends"); + let mut kernel = crate::custody_tests::custody_kernel("RetiredLends"); let (_, civic, before) = civic_world(&mut kernel); let over_hall = AuthorityGrant { kind: authority_kind(LEVY_KIND), @@ -5754,10 +5559,8 @@ mod custody_tests { }; use super::*; - pub(crate) fn custody_kernel(path: &Path, title: &str) -> WorldKernel { - WorldKernel::create( - path.join("world.cc"), - creation(title), + pub(crate) fn custody_kernel(title: &str) -> WorldKernel { + WorldKernel::create(creation(title), &auth_principal(owner()), ) .expect("a created world") @@ -5779,8 +5582,7 @@ mod custody_tests { /// the conservation equation itself is falsified directly beside it. #[test] fn a_non_conserving_transfer_effect_does_not_apply() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Forged"); + let mut kernel = custody_kernel("Forged"); let (_, custody, _) = custody_world(&mut kernel); let before = kernel.state.holdings.clone(); @@ -5840,8 +5642,7 @@ mod custody_tests { /// patch's own evidence list mints nothing and allocates no ID. #[test] fn an_admit_without_evidence_is_rejected() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Unevidenced"); + let mut kernel = custody_kernel("Unevidenced"); let topology = admit_topology(&mut kernel); let speak = speak_entry(&kernel); let before = kernel.snapshot().unwrap(); @@ -5890,8 +5691,7 @@ mod custody_tests { #[test] fn a_transfer_moves_the_exact_quantity_and_nothing_else() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Transfer"); + let mut kernel = custody_kernel("Transfer"); let (_, custody, active) = custody_world(&mut kernel); let entities = kernel.state.entities.clone(); let edges = kernel.state.edges.clone(); @@ -5920,8 +5720,7 @@ mod custody_tests { /// resource key and emptying a holder removes the holder key. #[test] fn consume_reduces_the_holding_and_emptying_removes_the_key() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Consume"); + let mut kernel = custody_kernel("Consume"); let (_, custody, active) = custody_world(&mut kernel); let after_three = submit_play( @@ -5959,8 +5758,7 @@ mod custody_tests { #[test] fn a_transform_conserves_one_for_one() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Transform"); + let mut kernel = custody_kernel("Transform"); let (_, custody, active) = custody_world(&mut kernel); submit_play( @@ -5982,8 +5780,7 @@ mod custody_tests { #[test] fn spending_more_than_held_is_rejected_with_insufficient_custody() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Insufficient"); + let mut kernel = custody_kernel("Insufficient"); let (_, custody, _) = custody_world(&mut kernel); let too_much = Quantity(OPENING_BALANCE + 1); let attempts = [ @@ -6023,8 +5820,7 @@ mod custody_tests { /// zero entry anywhere in the snapshot. #[test] fn an_absent_holding_is_zero() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Absent"); + let mut kernel = custody_kernel("Absent"); let (_, custody, active) = custody_world(&mut kernel); let mismatches = reject_play( @@ -6052,8 +5848,7 @@ mod custody_tests { #[test] fn a_zero_quantity_operation_is_rejected() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Zero"); + let mut kernel = custody_kernel("Zero"); let topology = admit_topology(&mut kernel); let custody = admit_custody(&mut kernel, &topology); @@ -6101,8 +5896,7 @@ mod custody_tests { #[test] fn dependency_bind_and_release_round_trip() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Dependency"); + let mut kernel = custody_kernel("Dependency"); let (_, custody, active) = custody_world(&mut kernel); let before = kernel.state.dependencies.clone(); @@ -6136,8 +5930,7 @@ mod custody_tests { /// already owns; a subject bound to itself is `SelfDependency`. #[test] fn a_duplicate_dependency_bind_is_rejected_as_no_effect() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Duplicate"); + let mut kernel = custody_kernel("Duplicate"); let (_, custody, active) = custody_world(&mut kernel); let bind = ComponentOp::Bind { @@ -6180,8 +5973,7 @@ mod custody_tests { /// components; nothing rejects it and nothing fires from it. #[test] fn a_dependency_on_a_closed_route_is_representable_and_visible() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Closed"); + let mut kernel = custody_kernel("Closed"); let (topology, custody, active) = custody_world(&mut kernel); assert!(!kernel.state.edges[&topology.shutter].is_open()); @@ -6211,8 +6003,7 @@ mod custody_tests { /// only its own: a counterparty's churn does not move it. #[test] fn scope_components_read_holdings_and_dependencies() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "ScopeCustody"); + let mut kernel = custody_kernel("ScopeCustody"); let topology = admit_topology(&mut kernel); let custody = admit_custody(&mut kernel, &topology); let scope = custody.holder; @@ -6250,8 +6041,7 @@ mod custody_tests { /// consumed - spent`, and no third resource moves. #[test] fn soul_a_mixed_patch_conserves_every_resource_it_touches() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "MixedLedger"); + let mut kernel = custody_kernel("MixedLedger"); let (_, custody, active) = custody_world(&mut kernel); // The opening balance was created by `Admit` alone: before is zero, @@ -6318,8 +6108,7 @@ mod custody_tests { /// records: the apply-side call is unreachable from the current closed set. #[test] fn soul_a_forged_sequence_dies_at_the_per_operation_check_not_the_ledger() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "ForgedSequence"); + let mut kernel = custody_kernel("ForgedSequence"); let (_, custody, _) = custody_world(&mut kernel); let before = kernel.state.holdings.clone(); @@ -6436,8 +6225,7 @@ mod custody_tests { /// whose sum exceeds `u64::MAX` mint nothing and allocate no ID. #[test] fn soul_a_holding_cannot_overflow_silently() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "Overflow"); + let mut kernel = custody_kernel("Overflow"); let topology = admit_topology(&mut kernel); let speak = speak_entry(&kernel); let before = kernel.snapshot().unwrap(); @@ -6490,8 +6278,7 @@ mod custody_tests { /// no unrelated subject's, whose act still commits at the later revision. #[test] fn soul_an_incoming_transfer_changes_only_the_counterpartys_scope() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = custody_kernel(directory.path(), "IncomingScope"); + let mut kernel = custody_kernel("IncomingScope"); let (topology, custody, active) = custody_world(&mut kernel); let receiver_before = scope_components(&kernel.state, custody.counterparty); let bystander_before = scope_components(&kernel.state, topology.walker); @@ -6541,12 +6328,9 @@ mod knowledge_tests { owner, reject_play, speech_world, spoken, submit_play, }; use super::*; - use std::path::Path; - fn speech_kernel(path: &Path, title: &str) -> (WorldKernel, Speech, WorldSnapshot) { - let mut kernel = WorldKernel::create( - path.join("world.cc"), - creation(title), + fn speech_kernel(title: &str) -> (WorldKernel, Speech, WorldSnapshot) { + let mut kernel = WorldKernel::create(creation(title), &auth_principal(owner()), ) .expect("a created world") @@ -6619,8 +6403,7 @@ mod knowledge_tests { /// accessible fact, and a rejected citation allocates nothing. #[test] fn knowledge_citing_an_inaccessible_fact_is_rejected() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Inaccessible"); + let (mut kernel, speech, active) = speech_kernel("Inaccessible"); let before = kernel.state.clone(); assert_eq!( @@ -6677,10 +6460,7 @@ mod knowledge_tests { /// canon needs its receipt in the same patch, a claim needs a live asserter. #[test] fn a_canonical_fact_needs_evidence_and_a_claim_needs_an_asserter() { - let directory = tempfile::tempdir().unwrap(); - let mut draft = WorldKernel::create( - directory.path().join("world.cc"), - creation("Standing"), + let mut draft = WorldKernel::create(creation("Standing"), &auth_principal(owner()), ) .expect("a draft world") @@ -6754,8 +6534,7 @@ mod knowledge_tests { /// never evaluated. #[test] fn evidenced_knowledge_of_a_claim_is_rejected() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, _) = speech_kernel(directory.path(), "Evidenced"); + let (mut kernel, speech, _) = speech_kernel("Evidenced"); utter(&mut kernel, speech.speaker, say( speech.proclaim, @@ -6804,8 +6583,7 @@ mod knowledge_tests { /// the exact room, and the utterance lands in `facts` and nowhere else. #[test] fn speak_fans_out_to_the_audience_and_not_beyond() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "FanOut"); + let (mut kernel, speech, active) = speech_kernel("FanOut"); utter(&mut kernel, speech.speaker, say( speech.whisper, @@ -6847,8 +6625,7 @@ mod knowledge_tests { /// subtree, through the same containment walk a jurisdiction uses. #[test] fn co_location_reach_is_the_exact_place_and_a_channel_place_is_the_subtree() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, _) = speech_kernel(directory.path(), "Reach"); + let (mut kernel, speech, _) = speech_kernel("Reach"); utter(&mut kernel, speech.speaker, say( speech.proclaim, @@ -6901,8 +6678,7 @@ mod knowledge_tests { /// nothing. #[test] fn speaking_into_an_empty_room_commits_the_claim_and_lands_nothing() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, _) = speech_kernel(directory.path(), "EmptyRoom"); + let (mut kernel, speech, _) = speech_kernel("EmptyRoom"); let knowledge_before = kernel.state.knowledge.clone(); utter(&mut kernel, speech.bystander, say( @@ -6953,8 +6729,7 @@ mod knowledge_tests { /// and still folds its arms only before the hall. #[test] fn a_display_is_seen_by_the_room_and_by_no_one_else() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Display"); + let (mut kernel, speech, active) = speech_kernel("Display"); utter(&mut kernel, speech.speaker, show( speech.proclaim, @@ -7009,8 +6784,7 @@ mod knowledge_tests { /// and lands nothing, as speaking alone does. #[test] fn a_silent_display_addresses_the_room_through_the_speak_entry() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Silent"); + let (mut kernel, speech, active) = speech_kernel("Silent"); let speak = affordance_named(&active, "speak"); utter(&mut kernel, speech.speaker, show(speak, Vec::new(), None, "I nod toward the stair."), @@ -7041,8 +6815,7 @@ mod knowledge_tests { /// fails the entry's own `NoAudience`. None of them mints anything. #[test] fn a_display_is_refused_when_empty_placeless_or_when_nothing_is_addressed() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Refused"); + let (mut kernel, speech, active) = speech_kernel("Refused"); let speak = affordance_named(&active, "speak"); let mut padded = show(speak, Vec::new(), None, "placeholder"); padded.display = Some(serde_json::from_str::("\" \"").unwrap()); @@ -7075,12 +6848,8 @@ mod knowledge_tests { /// the journal exactly, through the same path as speech. #[test] fn restart_replay_after_a_display_is_exact() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (speech, world_id, expected) = { - let mut kernel = WorldKernel::create( - &path, - creation("ReplayDisplay"), + let (speech, exported, expected) = { + let mut kernel = WorldKernel::create(creation("ReplayDisplay"), &auth_principal(owner()), ) .expect("a created world") @@ -7095,9 +6864,9 @@ mod knowledge_tests { show(speak, Vec::new(), None, "I look away."), ) .expect("the silent act commits"); - (speech, kernel.state.world_id, kernel.state.clone()) + (speech, kernel.export().unwrap(), kernel.state.clone()) }; - let reopened = WorldKernel::open(&path, world_id).expect("the store replays"); + let reopened = WorldKernel::open(&exported).expect("the export replays"); assert_eq!(reopened.state, expected); assert!(reopened.state.knowledge[&speech.listener] .values() @@ -7121,8 +6890,7 @@ mod knowledge_tests { /// same invocation to exactly one named failure. #[test] fn a_channel_controller_may_speak_outside_its_own_reach() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Controller"); + let (mut kernel, speech, active) = speech_kernel("Controller"); submit_play( &mut kernel, &active, @@ -7161,8 +6929,7 @@ mod knowledge_tests { /// audience receives the telling, not only the addressed subject. #[test] fn an_addressed_subject_outside_the_audience_names_itself() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Addressing"); + let (mut kernel, speech, active) = speech_kernel("Addressing"); let whisper = || { say( speech.whisper, @@ -7197,8 +6964,7 @@ mod knowledge_tests { /// rather than storing a zero. #[test] fn knows_fails_below_its_confidence_and_forget_removes() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Knows"); + let (mut kernel, speech, active) = speech_kernel("Knows"); let recant = || DecisionInvocation { affordance: speech.recant, bindings: vec![binding("fact", Target::Entity(speech.flood))], @@ -7263,8 +7029,7 @@ mod knowledge_tests { /// credence. #[test] fn a_telling_never_overwrites_a_holder() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "NoOverwrite"); + let (mut kernel, speech, active) = speech_kernel("NoOverwrite"); submit_play( &mut kernel, &active, @@ -7304,8 +7069,7 @@ mod knowledge_tests { /// channel's reach, and a speaker outside it is not speaking. #[test] fn communicating_from_outside_the_audience_is_rejected() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "OutsideAudience"); + let (mut kernel, speech, active) = speech_kernel("OutsideAudience"); assert_eq!( reject_play( &mut kernel, @@ -7338,8 +7102,7 @@ mod knowledge_tests { /// directly with the recorded world, command, handle, and discriminator. #[test] fn every_canonical_id_comes_from_one_of_two_sites() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "Allocation"); + let (mut kernel, speech, active) = speech_kernel("Allocation"); let world_id = kernel.state.world_id; let caller = play_caller(); let entities_before = kernel.state.entities.len(); @@ -7385,12 +7148,8 @@ mod knowledge_tests { /// state. #[test] fn restart_replay_after_speech_is_exact() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (speech, world_id, expected) = { - let mut kernel = WorldKernel::create( - &path, - creation("ReplaySpeech"), + let (speech, exported, expected) = { + let mut kernel = WorldKernel::create(creation("ReplaySpeech"), &auth_principal(owner()), ) .expect("a created world") @@ -7422,11 +7181,11 @@ mod knowledge_tests { to: AudienceRef::Channel(Ref::Existing(speech.horn)), }]), ); - let world_id = kernel.state.world_id; - (speech, world_id, kernel.state.clone()) + let exported = kernel.export().unwrap(); + (speech, exported, kernel.state.clone()) }; - let reopened = WorldKernel::open(&path, world_id).expect("the store replays"); + let reopened = WorldKernel::open(&exported).expect("the export replays"); assert_eq!(reopened.state.facts, expected.facts); assert_eq!(reopened.state.channels, expected.channels); assert_eq!(reopened.state.knowledge, expected.knowledge); @@ -7440,8 +7199,7 @@ mod knowledge_tests { /// recipients. #[test] fn a_forged_claim_or_forged_recipient_does_not_apply() { - let directory = tempfile::tempdir().unwrap(); - let (kernel, speech, _) = speech_kernel(directory.path(), "Forgery"); + let (kernel, speech, _) = speech_kernel("Forgery"); let command_id = CommandId::issue(); let caller = play_caller(); let invocation = say( @@ -7516,8 +7274,7 @@ mod knowledge_tests { /// alone, and a reach change moves only the controller's scope. #[test] fn a_telling_moves_only_the_listeners_scope() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, _) = speech_kernel(directory.path(), "ScopeMove"); + let (mut kernel, speech, _) = speech_kernel("ScopeMove"); let digest = |kernel: &WorldKernel, subject: SubjectId| { scope_components(&kernel.state, subject) }; @@ -7556,10 +7313,7 @@ mod knowledge_tests { /// and two is unchoosable. Each rejection allocates no `AffordanceId`. #[test] fn a_speech_carrying_entry_must_declare_exactly_one_audience() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = WorldKernel::create( - directory.path().join("world.cc"), - creation("SpeechAudience"), + let mut kernel = WorldKernel::create(creation("SpeechAudience"), &auth_principal(owner()), ) .expect("a draft world") @@ -7615,11 +7369,8 @@ mod knowledge_tests { /// canonical fact and one that plainly negates it commit identically. #[test] fn the_kernel_never_compares_two_statements() { - let directory = tempfile::tempdir().unwrap(); let run = |name: &str, text: &str| { - let room = directory.path().join(name); - std::fs::create_dir_all(&room).unwrap(); - let (mut kernel, speech, _) = speech_kernel(&room, name); + let (mut kernel, speech, _) = speech_kernel(name); let receipt = utter(&mut kernel, speech.speaker, say( speech.whisper, @@ -7664,12 +7415,9 @@ mod soul_knowledge_tests { owner, speech_world, submit_play, }; use super::*; - use std::path::Path; - fn speech_kernel(path: &Path, title: &str) -> (WorldKernel, Speech, WorldSnapshot) { - let mut kernel = WorldKernel::create( - path.join("world.cc"), - creation(title), + fn speech_kernel(title: &str) -> (WorldKernel, Speech, WorldSnapshot) { + let mut kernel = WorldKernel::create(creation(title), &auth_principal(owner()), ) .expect("a created world") @@ -7733,8 +7481,7 @@ mod soul_knowledge_tests { /// its own or another subject's. #[test] fn soul_a_channel_controller_hears_what_it_is_out_of_reach_of() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "ControllerHears"); + let (mut kernel, speech, active) = speech_kernel("ControllerHears"); // The horn now reaches exactly one subject. The speaker controls it and // is not in that set. submit_play( @@ -7808,8 +7555,7 @@ mod soul_knowledge_tests { /// replay to be caught later. #[test] fn soul_a_refused_utterance_dies_at_the_gate_and_allocates_nothing() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "GateNotReplay"); + let (mut kernel, speech, active) = speech_kernel("GateNotReplay"); let speak = affordance_named(&active, "speak"); let before = kernel.state.clone(); @@ -7867,8 +7613,7 @@ mod soul_knowledge_tests { /// by `apply_effect` itself, so replay is never the first reader to notice. #[test] fn soul_a_forged_wider_audience_does_not_apply() { - let directory = tempfile::tempdir().unwrap(); - let (kernel, speech, _) = speech_kernel(directory.path(), "WiderAudience"); + let (kernel, speech, _) = speech_kernel("WiderAudience"); let command_id = CommandId::issue(); let caller = play_caller(); let invocation = say( @@ -7940,8 +7685,7 @@ mod soul_knowledge_tests { /// by a speaker who is in the room applies. #[test] fn a_telling_by_a_speaker_outside_its_audience_does_not_apply() { - let directory = tempfile::tempdir().unwrap(); - let (kernel, speech, _) = speech_kernel(directory.path(), "OutsideAudience"); + let (kernel, speech, _) = speech_kernel("OutsideAudience"); let resolves_to = kernel.state.revision + 1; let mut candidate = kernel.state.clone(); @@ -7979,8 +7723,7 @@ mod soul_knowledge_tests { /// survives an utterance nobody heard. #[test] fn soul_speech_that_lands_nothing_moves_no_digest_including_the_speakers() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "NoDigestMove"); + let (mut kernel, speech, active) = speech_kernel("NoDigestMove"); let speak = affordance_named(&active, "speak"); let everyone = [ speech.speaker, @@ -8020,8 +7763,7 @@ mod soul_knowledge_tests { /// what the subject ends up holding. #[test] fn soul_a_same_patch_telling_then_forget_fails_closed_only() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "SamePatchOrder"); + let (mut kernel, speech, active) = speech_kernel("SamePatchOrder"); let tell = ComponentOp::Communicate { speaker: Ref::Existing(speech.speaker), fact: Ref::Existing(speech.flood), @@ -8086,9 +7828,7 @@ mod soul_knowledge_tests { /// claim is a valid shape and its store reopens. #[test] fn an_orphan_claim_is_a_valid_shape_and_reopens() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "OrphanClaim"); + let (mut kernel, speech, active) = speech_kernel("OrphanClaim"); // The Draft-declared fact is an orphan by construction: no event names // it. Reopening runs the shape verifier over the replayed state. assert!(kernel.state.facts.contains_key(&speech.flood)); @@ -8099,7 +7839,6 @@ mod soul_knowledge_tests { .iter() .all(|event| event.speech.is_none()) ); - let world_id = kernel.state.world_id; let before = kernel.state.clone(); let receipt = kernel @@ -8128,8 +7867,9 @@ mod soul_knowledge_tests { assert!(receipt.resulting_revision > 0); assert_eq!(kernel.state.facts.len(), before.facts.len() + 1); let facts = kernel.state.facts.clone(); + let exported = kernel.export().unwrap(); drop(kernel); - let replayed = WorldKernel::open(&path, world_id).expect("the orphan store is healthy"); + let replayed = WorldKernel::open(&exported).expect("the orphan store is healthy"); assert_eq!(replayed.state.facts, facts); } @@ -8139,10 +7879,8 @@ mod soul_knowledge_tests { /// from the journal, and reopening again reproduces the same state. #[test] fn soul_replay_is_exact_across_every_new_arm() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (world_id, expected) = { - let (mut kernel, speech, _) = speech_kernel(directory.path(), "ReplayArms"); + let (exported, expected) = { + let (mut kernel, speech, _) = speech_kernel("ReplayArms"); utter(&mut kernel, speech.speaker, say( speech.proclaim, @@ -8188,11 +7926,11 @@ mod soul_knowledge_tests { ); assert!(!kernel.state.knowledge.is_empty()); assert!(!kernel.state.facts.is_empty()); - (kernel.state.world_id, kernel.state.clone()) + (kernel.export().unwrap(), kernel.state.clone()) }; for _ in 0..2 { - let replayed = WorldKernel::open(&path, world_id).expect("the store replays"); + let replayed = WorldKernel::open(&exported).expect("the export replays"); assert_eq!(replayed.state.facts, expected.facts); assert_eq!(replayed.state.channels, expected.channels); assert_eq!(replayed.state.knowledge, expected.knowledge); @@ -8212,8 +7950,7 @@ mod soul_knowledge_tests { /// a subject-facing surface. #[test] fn soul_the_utterance_is_stored_in_facts_and_in_the_committed_effect() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, speech, active) = speech_kernel(directory.path(), "OneHome"); + let (mut kernel, speech, active) = speech_kernel("OneHome"); let speak = affordance_named(&active, "speak"); let text = "A statement that appears nowhere else."; utter(&mut kernel, speech.speaker, @@ -8329,10 +8066,8 @@ mod witness_tests { } } - fn nesting_kernel(path: &Path, title: &str) -> (WorldKernel, Nesting, WorldSnapshot) { - let mut kernel = WorldKernel::create( - path.join("world.cc"), - creation(title), + fn nesting_kernel(title: &str) -> (WorldKernel, Nesting, WorldSnapshot) { + let mut kernel = WorldKernel::create(creation(title), &auth_principal(owner()), ) .expect("a created world") @@ -8484,8 +8219,7 @@ mod witness_tests { /// beside it, and a wider place reaches the wider set. #[test] fn a_witness_reaches_every_subject_under_the_place_and_no_other() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Reach"); + let (mut kernel, world, active) = nesting_kernel("Reach"); submit_play( &mut kernel, &active, @@ -8545,8 +8279,7 @@ mod witness_tests { /// mind by repeating itself. #[test] fn a_witness_never_overwrites_a_holder() { - let directory = tempfile::tempdir().unwrap(); - let (kernel, world, _) = nesting_kernel(directory.path(), "Holder"); + let (kernel, world, _) = nesting_kernel("Holder"); // `Told` has exactly one writer, so the holder's row is planted at the // layer that can hold one and the witness is applied beside it. let held = Knowledge { @@ -8592,8 +8325,7 @@ mod witness_tests { /// every stander already holds the fact. #[test] fn a_witness_over_nobody_is_refused_at_resolve_and_at_apply() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Nobody"); + let (mut kernel, world, active) = nesting_kernel("Nobody"); let forged = |place: EntityId, state: &WorldState| { let resolves_to = state.revision + 1; let mut state = state.clone(); @@ -8682,8 +8414,7 @@ mod witness_tests { /// layer and the apply layer agree on both. #[test] fn a_mid_patch_relocation_into_the_subtree_counts() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Relocation"); + let (mut kernel, world, active) = nesting_kernel("Relocation"); // The village's own standers already hold it, so the relocated coaster // is the only candidate recipient left. submit_play( @@ -8752,8 +8483,7 @@ mod witness_tests { /// moves exactly the components of the subjects that learned something. #[test] fn a_witness_moves_every_recipients_scope_components_and_nobody_elses() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Digest"); + let (mut kernel, world, active) = nesting_kernel("Digest"); submit_play( &mut kernel, &active, @@ -8791,8 +8521,7 @@ mod witness_tests { /// place position binds a subject is refused before it is ever declared. #[test] fn a_witness_affordance_lowers_with_no_speaker() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Affordance"); + let (mut kernel, world, active) = nesting_kernel("Affordance"); let beacon = *active .subjects .iter() @@ -8884,8 +8613,7 @@ mod witness_tests { /// wrote pass the shape check with no clause of their own. #[test] fn a_world_with_a_witness_replays() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Replay"); + let (mut kernel, world, active) = nesting_kernel("Replay"); submit_play( &mut kernel, &active, @@ -8896,11 +8624,11 @@ mod witness_tests { )]), ); assert!(journal::verify_state_shape(&kernel.state).is_ok()); - let world_id = kernel.state.world_id; let committed = kernel.state.clone(); + let exported = kernel.export().unwrap(); drop(kernel); let reopened = - WorldKernel::open(directory.path().join("world.cc"), world_id).expect("it replays"); + WorldKernel::open(&exported).expect("it replays"); assert_eq!(reopened.state, committed); assert_eq!( knows(&reopened, world.villager, world.asteroid), @@ -8916,8 +8644,6 @@ mod witness_tests { /// state it was written into. #[test] fn a_genesis_seeded_knowledge_row_is_acquired_at_revision_zero() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let mut creation = creation("PAf49Genesis"); creation.patch.declarations.push(Declaration::Fact(FactDeclaration { handle: DraftHandle::new("founding"), @@ -8933,7 +8659,7 @@ mod witness_tests { source: AuthoredSource::Witnessed, confidence: Confidence::Certain, }); - let (kernel, _) = WorldKernel::create(&path, creation, &auth_principal(owner())).unwrap(); + let (kernel, _) = WorldKernel::create(creation, &auth_principal(owner())).unwrap(); assert_eq!(kernel.state.revision, 0); let human = *kernel .state @@ -8961,8 +8687,7 @@ mod witness_tests { /// resolves to, one past the state it was applied against. #[test] fn a_later_commits_knowledge_row_is_acquired_at_that_commits_revision() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "PAf49Later"); + let (mut kernel, world, active) = nesting_kernel("PAf49Later"); submit_play( &mut kernel, &active, @@ -8986,8 +8711,7 @@ mod witness_tests { /// replay silently. #[test] fn a_shape_check_refuses_a_knowledge_row_forged_ahead_of_the_world_revision() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "PAf49Shape"); + let (mut kernel, world, active) = nesting_kernel("PAf49Shape"); submit_play( &mut kernel, &active, @@ -9016,8 +8740,7 @@ mod witness_tests { /// it. #[test] fn soul_a_place_reach_fan_out_and_a_witness_select_the_same_subjects() { - let directory = tempfile::tempdir().unwrap(); - let (kernel, world, _) = nesting_kernel(directory.path(), "One owner"); + let (kernel, world, _) = nesting_kernel("One owner"); let mut state = kernel.state.clone(); // One holder, so the already-holds half of the selection is exercised // and not merely the subtree half. @@ -9069,8 +8792,7 @@ mod witness_tests { /// world's widest. #[test] fn soul_under_place_covers_itself_and_below_and_never_the_placeless() { - let directory = tempfile::tempdir().unwrap(); - let (kernel, world, _) = nesting_kernel(directory.path(), "Nesting"); + let (kernel, world, _) = nesting_kernel("Nesting"); let under = |root: EntityId| under_place(&kernel.state, root); // The village holds its two standers and nobody else. assert_eq!( @@ -9156,8 +8878,7 @@ mod witness_tests { /// by both. #[test] fn soul_a_subject_declared_and_placed_in_one_patch_is_a_recipient_at_both_layers() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Draft stander"); + let (mut kernel, world, active) = nesting_kernel("Draft stander"); submit_play( &mut kernel, &active, @@ -9268,8 +8989,7 @@ mod witness_tests { /// reaching nobody. #[test] fn soul_a_forget_before_a_witness_agrees_at_both_layers() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Forget first"); + let (mut kernel, world, active) = nesting_kernel("Forget first"); submit_play( &mut kernel, &active, @@ -9328,8 +9048,7 @@ mod witness_tests { /// row, so no attributable line can be built from it. #[test] fn soul_a_witness_moves_only_knows_and_writes_no_spoken_row() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, world, active) = nesting_kernel(directory.path(), "Anonymous"); + let (mut kernel, world, active) = nesting_kernel("Anonymous"); let before = scope_components(&kernel.state, world.villager); submit_play( &mut kernel, @@ -9377,7 +9096,6 @@ mod clock_tests { speech_world, submit_play, }; use super::*; - use std::path::Path; /// The canonical IDs of the clock fixture: a hall containing a yard, a /// dead end reached by exactly one route, three subjects, a resource, and @@ -9403,10 +9121,8 @@ mod clock_tests { TickMinutes::new(value).expect("a valid span") } - fn clock_kernel(path: &Path, title: &str) -> (WorldKernel, Clockwork, WorldSnapshot) { - let mut kernel = WorldKernel::create( - path.join("world.cc"), - creation(title), + fn clock_kernel(title: &str) -> (WorldKernel, Clockwork, WorldSnapshot) { + let mut kernel = WorldKernel::create(creation(title), &auth_principal(owner()), ) .expect("a created world") @@ -9713,8 +9429,7 @@ mod clock_tests { /// its subject, and the pressure grows with the next tick. #[test] fn a_defaulted_commitment_advances_pressure_one_step_per_tick() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Default"); + let (mut kernel, clockwork, _) = clock_kernel("Default"); let sourced = PressureSource::Commitment { subject: clockwork.farmer, key: clockwork.obligation, @@ -9736,8 +9451,7 @@ mod clock_tests { /// and a blocked one neither rolls nor presses. #[test] fn a_due_routine_auto_fulfils_and_a_blocked_one_does_not() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, active) = clock_kernel(directory.path(), "Routine"); + let (mut kernel, clockwork, active) = clock_kernel("Routine"); let holdings = kernel.state.holdings.clone(); let positions = kernel.state.positions.clone(); let edges = kernel.state.edges.clone(); @@ -9804,8 +9518,7 @@ mod clock_tests { /// canonical change. #[test] fn a_tick_with_nothing_due_moves_only_the_clock() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, _, _) = clock_kernel(directory.path(), "Quiet"); + let (mut kernel, _, _) = clock_kernel("Quiet"); let before = kernel.state.clone(); tick(&mut kernel, 1).expect("the tick commits"); @@ -9826,8 +9539,7 @@ mod clock_tests { /// does. #[test] fn an_unavailable_dependency_presses_its_depender() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Dependency"); + let (mut kernel, clockwork, _) = clock_kernel("Dependency"); let sourced = PressureSource::Dependency(DependencyTarget::Route(clockwork.gate)); tick(&mut kernel, 1).expect("the tick commits"); @@ -9876,8 +9588,7 @@ mod clock_tests { /// The clock moves through exactly one command body. #[test] fn time_advances_only_through_advance_time() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "OnlyTick"); + let (mut kernel, clockwork, _) = clock_kernel("OnlyTick"); tick(&mut kernel, 5).expect("the tick commits"); let now = kernel.state.now; @@ -9904,10 +9615,7 @@ mod clock_tests { /// Who may tick, when, and how far. #[test] fn advance_time_negatives() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = WorldKernel::create( - directory.path().join("world.cc"), - creation("Negatives"), + let mut kernel = WorldKernel::create(creation("Negatives"), &auth_principal(owner()), ) .expect("a created world") @@ -9971,8 +9679,7 @@ mod clock_tests { /// magnitude, or clock reading is one comparison. #[test] fn a_forged_motion_does_not_apply() { - let directory = tempfile::tempdir().unwrap(); - let (kernel, clockwork, _) = clock_kernel(directory.path(), "Forged"); + let (kernel, clockwork, _) = clock_kernel("Forged"); let to = FictionalMinutes(120); let honest = clock::derive_motion(&kernel.state, to); assert!(!honest.fulfilled.is_empty() || !honest.pressed.is_empty()); @@ -10059,10 +9766,7 @@ mod clock_tests { /// Replay across a tick is exact, and every envelope is idempotent. #[test] fn restart_replay_across_a_tick_is_exact() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Replay"); - let world_id = kernel.state.world_id; + let (mut kernel, clockwork, _) = clock_kernel("Replay"); exercise( &mut kernel, @@ -10100,8 +9804,9 @@ mod clock_tests { let before = kernel.state.clone(); let before_snapshot = kernel.snapshot().unwrap(); + let exported = kernel.export().unwrap(); drop(kernel); - let mut replayed = WorldKernel::open(&path, world_id).expect("the store replays"); + let mut replayed = WorldKernel::open(&exported).expect("the export replays"); assert_eq!(replayed.state, before); assert_eq!(replayed.snapshot().unwrap(), before_snapshot); assert!(matches!( @@ -10113,8 +9818,7 @@ mod clock_tests { /// Every commitment shape check, in one complete sorted set. #[test] fn commitment_declaration_negatives() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, active) = clock_kernel(directory.path(), "Shapes"); + let (mut kernel, clockwork, active) = clock_kernel("Shapes"); let before = kernel.state.clone(); let create = |kind: CommitmentKind, counterparty: Option, @@ -10243,8 +9947,7 @@ mod clock_tests { /// treasury and the reeve did not. #[test] fn committed_reads_the_actors_own_commitments() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Committed"); + let (mut kernel, clockwork, _) = clock_kernel("Committed"); // The reeve promised the treasury nothing. let error = exercise( @@ -10281,8 +9984,7 @@ mod clock_tests { /// it is refused and nothing commits. #[test] fn a_discharged_commitment_refuses_the_act_that_needs_it() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "DischargeThenAct"); + let (mut kernel, clockwork, _) = clock_kernel("DischargeThenAct"); let snapshot = kernel.snapshot().unwrap(); submit_play( &mut kernel, @@ -10317,8 +10019,7 @@ mod clock_tests { /// half while the kind half holds. #[test] fn committed_requires_the_named_counterparty() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "CommittedCounterparty"); + let (mut kernel, clockwork, _) = clock_kernel("CommittedCounterparty"); let error = exercise( &mut kernel, clockwork.farmer, @@ -10338,8 +10039,7 @@ mod clock_tests { /// half fails. The farmer's own obligation to the same treasury still passes. #[test] fn committed_requires_the_named_kind() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "CommittedKind"); + let (mut kernel, clockwork, _) = clock_kernel("CommittedKind"); let snapshot = kernel.snapshot().unwrap(); submit_play( &mut kernel, @@ -10388,8 +10088,7 @@ mod clock_tests { /// that fulfils a routine moves exactly that subject's. #[test] fn a_pressure_tick_moves_no_scope_components_and_a_routine_tick_moves_one() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Digests"); + let (mut kernel, clockwork, _) = clock_kernel("Digests"); let digests = |kernel: &WorldKernel| -> BTreeMap { kernel .state @@ -10446,8 +10145,7 @@ mod clock_tests { /// and zero is spelled by absence at both ends. #[test] fn soul_pressure_saturates_and_never_underflows() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Saturate"); + let (mut kernel, clockwork, _) = clock_kernel("Saturate"); let sourced = PressureSource::Commitment { subject: clockwork.farmer, key: clockwork.obligation, @@ -10513,8 +10211,7 @@ mod clock_tests { /// the clock and not one subject's components. #[test] fn soul_a_clock_only_tick_moves_no_scope_components() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, _, _) = clock_kernel(directory.path(), "ClockOnly"); + let (mut kernel, _, _) = clock_kernel("ClockOnly"); let digests = |kernel: &WorldKernel| -> BTreeMap { kernel .state @@ -10540,8 +10237,6 @@ mod clock_tests { /// fact or one operation fails here. #[test] fn genesis_may_not_rule_or_mint() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let mut input = creation("RulesAndMints"); for handle in ["first-rule", "second-rule"] { input @@ -10565,7 +10260,7 @@ mod clock_tests { qty: Quantity(4), }); } - let Err(error) = WorldKernel::create(&path, input, &auth_principal(owner())) else { + let Err(error) = WorldKernel::create(input, &auth_principal(owner())) else { panic!("a genesis patch that rules and mints was admitted"); }; let KernelError::PatchRejected(set) = error else { @@ -10581,7 +10276,6 @@ mod clock_tests { offender(patch::Site::Operation(1)), ] ); - assert!(!path.exists(), "a refused genesis wrote a world file"); } /// `prepare_creation` and `WorldState::genesis` both forbid rulings at @@ -10589,8 +10283,6 @@ mod clock_tests { /// a world is ever written. #[test] fn a_genesis_patch_carrying_a_ruled_fact_is_refused() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let mut input = creation("RuledGenesis"); input .patch @@ -10601,7 +10293,7 @@ mod clock_tests { statement: Statement::new("Stated by the table.").unwrap(), standing: FactStandingRef::Ruled, })); - let Err(error) = WorldKernel::create(&path, input, &auth_principal(owner())) else { + let Err(error) = WorldKernel::create(input, &auth_principal(owner())) else { panic!("a genesis patch carrying a Ruled fact was admitted"); }; assert!( @@ -10611,15 +10303,12 @@ mod clock_tests { })), "{error:?}" ); - assert!(!path.exists(), "a refused genesis wrote a world file"); } /// The `Mint` half: a creation patch that carries a `Mint` is refused the /// same way. #[test] fn a_genesis_patch_carrying_a_mint_is_refused() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); let mut input = creation("MintGenesis"); input .patch @@ -10630,7 +10319,7 @@ mod clock_tests { resource: Ref::Draft(DraftHandle::new("loot")), qty: Quantity(4), }); - let Err(error) = WorldKernel::create(&path, input, &auth_principal(owner())) else { + let Err(error) = WorldKernel::create(input, &auth_principal(owner())) else { panic!("a genesis patch carrying a Mint was admitted"); }; assert!( @@ -10640,7 +10329,6 @@ mod clock_tests { })), "{error:?}" ); - assert!(!path.exists(), "a refused genesis wrote a world file"); } /// `WorldState::genesis` re-decides `forbid_rulings_at_genesis` on its own @@ -10706,8 +10394,7 @@ mod clock_tests { /// Soul falsification: a discharge names one subject's own live key. #[test] fn soul_discharging_a_foreign_or_already_discharged_commitment_is_refused() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Discharge"); + let (mut kernel, clockwork, _) = clock_kernel("Discharge"); // The farmer's obligation, claimed by the reeve. let snapshot = kernel.snapshot().unwrap(); @@ -10751,8 +10438,7 @@ mod clock_tests { /// whatever the span, and a non-routine cannot carry checks. #[test] fn soul_a_routine_re_arms_exactly_one_period_per_command() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Rearm"); + let (mut kernel, clockwork, _) = clock_kernel("Rearm"); let period = u64::from( kernel.state.commitments[&clockwork.farmer][&clockwork.routine] .period @@ -10801,8 +10487,7 @@ mod clock_tests { /// failing dependency at once. #[test] fn soul_derive_motion_is_pure_and_the_tick_replays_exactly() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Pure"); + let (mut kernel, clockwork, _) = clock_kernel("Pure"); let snapshot = kernel.snapshot().unwrap(); submit_play( &mut kernel, @@ -10888,8 +10573,7 @@ mod clock_tests { /// it because no partition holds one. #[test] fn mismatch_never_appears_in_a_world_commit() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "Separation"); + let (mut kernel, clockwork, _) = clock_kernel("Separation"); submit_as( &mut kernel, play_caller(), @@ -10942,8 +10626,7 @@ mod clock_tests { /// Active with no answer. #[test] fn the_play_authority_declares_in_active_without_an_answer() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayDeclares"); + let (mut kernel, clockwork, _) = clock_kernel("PlayDeclares"); let receipt = submit_as( &mut kernel, play_caller(), @@ -10960,8 +10643,7 @@ mod clock_tests { /// a confined author cannot do. #[test] fn the_play_authority_is_unconfined() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayUnconfined"); + let (mut kernel, clockwork, _) = clock_kernel("PlayUnconfined"); submit_as( &mut kernel, play_caller(), @@ -10975,8 +10657,7 @@ mod clock_tests { /// Invariant 5: the play authority advances time, the clock's precedent. #[test] fn the_play_authority_advances_time() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, _clockwork, active) = clock_kernel(directory.path(), "PlayClock"); + let (mut kernel, _clockwork, active) = clock_kernel("PlayClock"); let receipt = submit_as( &mut kernel, play_caller(), @@ -10992,8 +10673,7 @@ mod clock_tests { /// P3.4: a ruled fact is world truth to every subject that knows it. #[test] fn the_play_authority_rules_a_fact_and_a_witness_knows_it_as_canon() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayRules"); + let (mut kernel, clockwork, _) = clock_kernel("PlayRules"); let mut patch = ruled_fact_patch("verdict"); patch.operations.push(ComponentOp::AcquireKnowledge { subject: Ref::Existing(clockwork.reeve), @@ -11036,10 +10716,8 @@ mod clock_tests { /// P3.5: minted quantity balances the ledger, and replay reproduces it. #[test] fn the_play_authority_mints_and_the_ledger_balances() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (world_id, reeve, grain) = { - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayMints"); + let (exported, reeve, grain) = { + let (mut kernel, clockwork, _) = clock_kernel("PlayMints"); let grain = resource_named(&kernel, "Winter Grain"); let before = held(&kernel.state, clockwork.reeve, grain); assert_eq!(before, 0); @@ -11061,9 +10739,9 @@ mod clock_tests { .expect("the play authority mints"); let after = held(&kernel.state, clockwork.reeve, grain); assert_eq!(before + 7, after); - (kernel.state.world_id, clockwork.reeve, grain) + (kernel.export().unwrap(), clockwork.reeve, grain) }; - let replayed = WorldKernel::open(&path, world_id).expect("the minted store replays"); + let replayed = WorldKernel::open(&exported).expect("the minted export replays"); assert_eq!(held(&replayed.state, reeve, grain), 7); } @@ -11072,8 +10750,7 @@ mod clock_tests { /// such an assertion. #[test] fn a_ruled_fact_cannot_be_known_evidenced() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayEvidenced"); + let (mut kernel, clockwork, _) = clock_kernel("PlayEvidenced"); let mut patch = ruled_fact_patch("verdict"); patch.operations.push(ComponentOp::AcquireKnowledge { subject: Ref::Existing(clockwork.reeve), @@ -11101,8 +10778,7 @@ mod clock_tests { /// receipts, so its `Admit` is refused without one. #[test] fn the_evidence_gate_holds_for_play() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayEvidenceGate"); + let (mut kernel, clockwork, _) = clock_kernel("PlayEvidenceGate"); let grain = resource_named(&kernel, "Winter Grain"); // Without a receipt: `Play`'s `Admit` is refused exactly as anyone's. @@ -11154,10 +10830,8 @@ mod clock_tests { /// reproduces both across the digest. #[test] fn a_journal_holding_a_ruled_fact_and_a_mint_replays() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (world_id, expected) = { - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayReplay"); + let (exported, expected) = { + let (mut kernel, clockwork, _) = clock_kernel("PlayReplay"); let grain = resource_named(&kernel, "Winter Grain"); let mut patch = ruled_fact_patch("verdict"); patch.operations.push(ComponentOp::Mint { @@ -11173,13 +10847,14 @@ mod clock_tests { }, ) .expect("the play authority rules and mints in one patch"); - (kernel.state.world_id, kernel.snapshot().unwrap()) + (kernel.export().unwrap(), kernel.snapshot().unwrap()) }; - let replayed = WorldKernel::open(&path, world_id).expect("the store replays"); + let replayed = WorldKernel::open(&exported).expect("the export replays"); assert_eq!(replayed.snapshot().unwrap(), expected); + let exported = replayed.export().unwrap(); drop(replayed); let replayed_again = - WorldKernel::open(&path, world_id).expect("the store replays a second time"); + WorldKernel::open(&exported).expect("the export replays a second time"); assert_eq!(replayed_again.snapshot().unwrap(), expected); } @@ -11210,10 +10885,8 @@ mod clock_tests { /// grants and `retired` both survive the round trip. #[test] fn a_retired_subject_holds_no_grants_across_a_replay() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (world_id, reeve) = { - let (mut kernel, clockwork, active) = clock_kernel(directory.path(), "RetireReplay"); + let (exported, reeve) = { + let (mut kernel, clockwork, active) = clock_kernel("RetireReplay"); assert!( !active .subjects @@ -11225,9 +10898,9 @@ mod clock_tests { "the reeve holds grants before retirement" ); play_retires(&mut kernel, clockwork.reeve).expect("play retires the reeve"); - (kernel.state.world_id, clockwork.reeve) + (kernel.export().unwrap(), clockwork.reeve) }; - let replayed = WorldKernel::open(&path, world_id).expect("the store replays"); + let replayed = WorldKernel::open(&exported).expect("the export replays"); let snapshot = replayed.snapshot().unwrap(); let subject = snapshot .subjects @@ -11242,8 +10915,7 @@ mod clock_tests { /// removed its grants. #[test] fn a_retired_subject_cannot_act() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "RetireCannotAct"); + let (mut kernel, clockwork, _) = clock_kernel("RetireCannotAct"); play_retires(&mut kernel, clockwork.reeve).expect("play retires the reeve"); let error = exercise( &mut kernel, @@ -11260,8 +10932,7 @@ mod clock_tests { /// does. #[test] fn a_retired_subject_hears_nothing() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "RetireHearsNothing"); + let (mut kernel, clockwork, _) = clock_kernel("RetireHearsNothing"); play_retires(&mut kernel, clockwork.reeve).expect("play retires the reeve"); let mut patch = ruled_fact_patch("news"); patch.operations.push(ComponentOp::Witness { @@ -11296,8 +10967,7 @@ mod clock_tests { /// retirement untouched. #[test] fn a_retired_subject_keeps_its_history() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "RetireKeepsHistory"); + let (mut kernel, clockwork, _) = clock_kernel("RetireKeepsHistory"); let before_holdings = kernel.state.holdings.get(&clockwork.farmer).cloned(); let before_commitments = kernel.state.commitments.get(&clockwork.farmer).cloned(); assert!(before_holdings.is_some()); @@ -11317,8 +10987,7 @@ mod clock_tests { /// P4.1: retiring twice is `NoOperationEffect`, not a second retirement. #[test] fn retiring_twice_is_no_effect() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "RetireTwice"); + let (mut kernel, clockwork, _) = clock_kernel("RetireTwice"); play_retires(&mut kernel, clockwork.reeve).expect("the first retirement commits"); let error = play_retires(&mut kernel, clockwork.reeve).unwrap_err(); assert!( @@ -11358,10 +11027,7 @@ mod clock_tests { /// verb the same way any owner-authored `GrantAffordance` does. #[test] fn the_seed_grants_the_player_a_verb_in_draft() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = WorldKernel::create( - directory.path().join("world.cc"), - creation("SeedGrantsDraft"), + let mut kernel = WorldKernel::create(creation("SeedGrantsDraft"), &auth_principal(owner()), ) .expect("a created world") @@ -11405,8 +11071,7 @@ mod clock_tests { /// P5.1: Play grants and revokes a verb in Active. #[test] fn the_play_authority_grants_and_revokes_in_active() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PlayGrantRevoke"); + let (mut kernel, clockwork, _) = clock_kernel("PlayGrantRevoke"); submit_as( &mut kernel, play_caller(), @@ -11473,14 +11138,12 @@ mod clock_tests { /// PA.f31: `verify_state_shape` no longer judges a `DecisionEvent` against /// the subject's *present* controller identity. Retiring a subject that /// has acted commits, and the history survives a full reopen-and-replay - /// (`recover` -> `verify_history` -> `verify_state_shape` for every + /// (`open` -> `verify_history` -> `verify_state_shape` for every /// commit, per the caller census in the report). #[test] fn retiring_a_subject_that_acted_survives_reopen_and_replay() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let world_id = { - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf31RetireActed"); + let exported = { + let (mut kernel, clockwork, _) = clock_kernel("PAf31RetireActed"); exercise( &mut kernel, clockwork.reeve, @@ -11490,9 +11153,9 @@ mod clock_tests { .expect("the threat commits"); play_retires(&mut kernel, clockwork.reeve) .expect("a subject with history can be retired"); - kernel.state.world_id + kernel.export().unwrap() }; - let reopened = WorldKernel::open(&path, world_id).expect("the store replays"); + let reopened = WorldKernel::open(&exported).expect("the export replays"); let retired = reopened .snapshot() .unwrap() @@ -11510,10 +11173,8 @@ mod clock_tests { /// against the present-day grant set. #[test] fn revoking_a_used_verb_survives_reopen_and_replay() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let world_id = { - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf31RevokeUsed"); + let exported = { + let (mut kernel, clockwork, _) = clock_kernel("PAf31RevokeUsed"); exercise( &mut kernel, clockwork.reeve, @@ -11530,9 +11191,9 @@ mod clock_tests { affordance: Ref::Existing(clockwork.threaten), }]), ); - kernel.state.world_id + kernel.export().unwrap() }; - let reopened = WorldKernel::open(&path, world_id).expect("the store replays"); + let reopened = WorldKernel::open(&exported).expect("the export replays"); assert_eq!(reopened.state.events.len(), 1); } @@ -11543,16 +11204,14 @@ mod clock_tests { /// controller roster in Active. #[test] fn retiring_the_human_in_active_survives_reopen_and_replay() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (world_id, human) = { - let (mut kernel, clockwork, active) = clock_kernel(directory.path(), "PAf32ActiveRetire"); + let (exported, human) = { + let (mut kernel, clockwork, active) = clock_kernel("PAf32ActiveRetire"); let _ = &clockwork; let human = human_subject(&active); play_retires(&mut kernel, human).expect("play retires the human subject"); - (kernel.state.world_id, human) + (kernel.export().unwrap(), human) }; - let reopened = WorldKernel::open(&path, world_id).expect("the store replays"); + let reopened = WorldKernel::open(&exported).expect("the export replays"); let retired = reopened .snapshot() .unwrap() @@ -11570,8 +11229,7 @@ mod clock_tests { /// knowledge from a telling into that channel. #[test] fn channel_audience_excludes_a_retired_member() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf33Audience"); + let (mut kernel, clockwork, _) = clock_kernel("PAf33Audience"); play_retires(&mut kernel, clockwork.reeve).expect("retire"); let mut patch = ruled_fact_patch("news"); patch.declarations.push(Declaration::Channel(ChannelDeclaration { @@ -11604,8 +11262,7 @@ mod clock_tests { /// controller. #[test] fn a_retired_subject_cannot_speak_through_a_channel() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf33RetiredSpeaks"); + let (mut kernel, clockwork, _) = clock_kernel("PAf33RetiredSpeaks"); let mut declare = ruled_fact_patch("wire-decl"); declare.declarations.push(Declaration::Channel(ChannelDeclaration { handle: DraftHandle::new("wire"), @@ -11640,10 +11297,7 @@ mod clock_tests { /// respects — one statement of reach, one fix. #[test] fn a_retired_subject_is_unreachable_through_can_reach() { - let directory = tempfile::tempdir().unwrap(); - let mut kernel = WorldKernel::create( - directory.path().join("world.cc"), - creation("PAf33CanReach"), + let mut kernel = WorldKernel::create(creation("PAf33CanReach"), &auth_principal(owner()), ) .expect("a created world") @@ -11676,8 +11330,7 @@ mod clock_tests { /// PA.f34: `AcquireKnowledge` refuses a retired subject. #[test] fn a_retired_subject_cannot_acquire_knowledge() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf34Acquire"); + let (mut kernel, clockwork, _) = clock_kernel("PAf34Acquire"); play_retires(&mut kernel, clockwork.reeve).expect("retire"); let mut patch = ruled_fact_patch("news"); patch.operations.push(ComponentOp::AcquireKnowledge { @@ -11698,8 +11351,7 @@ mod clock_tests { /// PA.f34: `Forget` refuses a retired subject. #[test] fn a_retired_subject_cannot_forget() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf34Forget"); + let (mut kernel, clockwork, _) = clock_kernel("PAf34Forget"); let mut declare = ruled_fact_patch("news"); declare.operations.push(ComponentOp::AcquireKnowledge { subject: Ref::Existing(clockwork.reeve), @@ -11726,8 +11378,7 @@ mod clock_tests { /// PA.f34: `InstallIncumbent` refuses a retired subject as incumbent. #[test] fn a_retired_subject_cannot_take_office() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf34Office"); + let (mut kernel, clockwork, _) = clock_kernel("PAf34Office"); play_retires(&mut kernel, clockwork.farmer).expect("retire"); let before = kernel.snapshot().unwrap(); let error = reject_play( @@ -11753,8 +11404,7 @@ mod clock_tests { /// still be looted after it stops acting. #[test] fn holdings_are_still_transferable_from_a_retired_holder() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf34Loot"); + let (mut kernel, clockwork, _) = clock_kernel("PAf34Loot"); play_retires(&mut kernel, clockwork.farmer).expect("retire"); let before = kernel.snapshot().unwrap(); let grain = *kernel @@ -11788,8 +11438,7 @@ mod clock_tests { /// retired subject. #[test] fn retiring_then_relocating_in_one_patch_is_rejected() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf35RetireRelocate"); + let (mut kernel, clockwork, _) = clock_kernel("PAf35RetireRelocate"); let stair = *kernel .state .edges @@ -11818,8 +11467,7 @@ mod clock_tests { /// re-resolving. #[test] fn retiring_the_same_subject_twice_in_one_patch_is_a_noop_the_second_time() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf35DoubleRetire"); + let (mut kernel, clockwork, _) = clock_kernel("PAf35DoubleRetire"); let before = kernel.snapshot().unwrap(); let error = reject_play( &mut kernel, @@ -11839,8 +11487,7 @@ mod clock_tests { /// office incumbent draws. #[test] fn a_retired_subject_cannot_be_a_promisor() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf37Promisor"); + let (mut kernel, clockwork, _) = clock_kernel("PAf37Promisor"); play_retires(&mut kernel, clockwork.farmer).expect("retire"); let before = kernel.snapshot().unwrap(); let error = reject_play( @@ -11868,8 +11515,7 @@ mod clock_tests { /// they were the moment it retired. #[test] fn after_retirement_a_tick_moves_none_of_the_retired_subjects_commitments() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf37Frozen"); + let (mut kernel, clockwork, _) = clock_kernel("PAf37Frozen"); let snapshot = kernel.snapshot().unwrap(); submit_play( &mut kernel, @@ -11937,8 +11583,7 @@ mod clock_tests { /// exercises, since the farmer it retires holds no dependency. #[test] fn after_retirement_a_tick_moves_none_of_the_retired_subjects_goal_or_dependency() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf37FrozenDep"); + let (mut kernel, clockwork, _) = clock_kernel("PAf37FrozenDep"); let snapshot = kernel.snapshot().unwrap(); submit_play( &mut kernel, @@ -11993,20 +11638,18 @@ mod clock_tests { /// every other retirement effect in this batch does. #[test] fn a_retired_subjects_frozen_commitments_survive_reopen_and_replay() { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (world_id, farmer, routine, obligation) = { - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf37Replay"); + let (exported, farmer, routine, obligation) = { + let (mut kernel, clockwork, _) = clock_kernel("PAf37Replay"); play_retires(&mut kernel, clockwork.farmer).expect("retire the farmer"); tick(&mut kernel, ROUTINE_DUE as u32 + LATE_DUE as u32).expect("the tick commits"); ( - kernel.state.world_id, + kernel.export().unwrap(), clockwork.farmer, clockwork.routine, clockwork.obligation, ) }; - let reopened = WorldKernel::open(&path, world_id).expect("the store replays"); + let reopened = WorldKernel::open(&exported).expect("the export replays"); assert_eq!( due(&reopened, farmer, routine), FictionalMinutes(ROUTINE_DUE), @@ -12036,8 +11679,7 @@ mod clock_tests { /// too. #[test] fn a_retired_subject_cannot_acquire_evidenced_knowledge() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf39Evidenced"); + let (mut kernel, clockwork, _) = clock_kernel("PAf39Evidenced"); play_retires(&mut kernel, clockwork.farmer).expect("retire"); let patch = WorldPatch { declarations: vec![Declaration::Fact(FactDeclaration { @@ -12077,8 +11719,7 @@ mod clock_tests { /// and kills a mutation that removes `audience()`'s retired filter. #[test] fn a_retired_placeless_subject_is_unreachable_through_a_subjects_channel() { - let directory = tempfile::tempdir().unwrap(); - let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "PAf39S2"); + let (mut kernel, clockwork, _) = clock_kernel("PAf39S2"); let speak = super::tests::speak_entry(&kernel); submit_as( &mut kernel, @@ -12198,16 +11839,12 @@ mod agency_tests { }; use super::*; - fn world(title: &str) -> (tempfile::TempDir, std::path::PathBuf, WorldKernel) { - let directory = tempfile::tempdir().unwrap(); - let path = directory.path().join("world.cc"); - let (kernel, _) = WorldKernel::create( - &path, - creation(title), + fn world(title: &str) -> WorldKernel { + let (kernel, _) = WorldKernel::create(creation(title), &auth_principal(owner()), ) .unwrap(); - (directory, path, kernel) + kernel } fn declare_place_patch(handle: &str) -> WorldPatch { @@ -12225,7 +11862,7 @@ mod agency_tests { #[test] fn after_genesis_only_play_writes() { - let (_directory, _path, mut kernel) = world("PlayOnly"); + let mut kernel = world("PlayOnly"); let snapshot = kernel.snapshot().unwrap(); let human = subject_by_label(&kernel.state, "The Human"); let persona = subject_by_label(&kernel.state, "The Witness"); @@ -12302,7 +11939,7 @@ mod agency_tests { #[test] fn apply_effect_re_decides_play() { - let (_directory, _path, kernel) = world("ReDecide"); + let kernel = world("ReDecide"); let state = &kernel.state; let command_id = CommandId::issue(); let human = subject_by_label(state, "The Human"); @@ -12357,7 +11994,7 @@ mod agency_tests { /// grant for, both come back Unauthorized. #[test] fn a_non_play_caller_is_refused_before_the_world_is_read() { - let (_directory, _path, mut kernel) = world("Blind"); + let mut kernel = world("Blind"); let snapshot = kernel.snapshot().unwrap(); let persona = subject_by_label(&kernel.state, "The Witness"); let ungranted = affordance_named(&snapshot, "convene"); @@ -12391,18 +12028,19 @@ mod agency_tests { #[test] fn a_world_is_born_active() { - let (_directory, path, mut kernel) = world("BornActive"); + let mut kernel = world("BornActive"); let snapshot = kernel.snapshot().unwrap(); assert_eq!(snapshot.revision, 0); let human = subject_by_label(&kernel.state, "The Human"); act(&mut kernel, human, speak(first_grant(&snapshot, human), "At once.")).unwrap(); let accepted = kernel.snapshot().unwrap(); assert_eq!(accepted.revision, 1); + let exported = kernel.export().unwrap(); drop(kernel); - let reopened = WorldKernel::open(&path, accepted.world_id).unwrap(); + let reopened = WorldKernel::open(&exported).unwrap(); assert_eq!(reopened.snapshot().unwrap(), accepted); - let (_other, _path, mut kernel) = world("BornActiveClock"); + let mut kernel = world("BornActiveClock"); let genesis = kernel.snapshot().unwrap(); submit_play(&mut kernel, &genesis, tick_body(1)); assert_eq!(kernel.snapshot().unwrap().revision, 1); @@ -12443,7 +12081,7 @@ mod agency_tests { /// Retire sets the flag `is_retired` reads, and nothing else retires. #[test] fn retirement_lives_on_the_subject() { - let (_directory, path, mut kernel) = world("RetireFlag"); + let mut kernel = world("RetireFlag"); let snapshot = kernel.snapshot().unwrap(); let persona = subject_by_label(&kernel.state, "The Witness"); assert!(!is_retired(&kernel.state, persona)); @@ -12460,8 +12098,9 @@ mod agency_tests { assert!(!kernel.state.affordance_grants.contains_key(&persona)); let after = kernel.snapshot().unwrap(); assert!(after.subjects.iter().find(|s| s.id == persona).unwrap().retired); + let exported = kernel.export().unwrap(); drop(kernel); - let reopened = WorldKernel::open(&path, after.world_id).unwrap(); + let reopened = WorldKernel::open(&exported).unwrap(); assert!(is_retired(&reopened.state, persona)); assert_eq!(reopened.snapshot().unwrap(), after); } @@ -12490,7 +12129,7 @@ mod agency_tests { #[test] fn a_revoke_may_leave_a_subject_with_no_verbs() { - let (_directory, path, mut kernel) = world("Mute"); + let mut kernel = world("Mute"); let snapshot = kernel.snapshot().unwrap(); let persona = subject_by_label(&kernel.state, "The Witness"); let only = first_grant(&snapshot, persona); @@ -12513,9 +12152,10 @@ mod agency_tests { assert!(matches!(error, KernelError::AffordanceDenied), "{error:?}"); journal::verify_state_shape(&kernel.state).expect("a mute subject is a legal shape"); let accepted = kernel.snapshot().unwrap(); + let exported = kernel.export().unwrap(); drop(kernel); assert_eq!( - WorldKernel::open(&path, accepted.world_id) + WorldKernel::open(&exported) .unwrap() .snapshot() .unwrap(), @@ -12535,12 +12175,9 @@ mod agency_tests { import_key: None, }) }; - let directory = tempfile::tempdir().unwrap(); let mut input = creation("Mutes"); input.patch.declarations.push(mute("born-mute")); - let (mut kernel, _) = WorldKernel::create( - directory.path().join("world.cc"), - input, + let (mut kernel, _) = WorldKernel::create(input, &auth_principal(owner()), ) .unwrap(); @@ -12585,7 +12222,7 @@ mod agency_tests { #[test] fn a_retired_subject_takes_no_grant() { - let (_directory, _path, mut kernel) = world("RetiredGrants"); + let mut kernel = world("RetiredGrants"); let snapshot = kernel.snapshot().unwrap(); let persona = subject_by_label(&kernel.state, "The Witness"); let convene = affordance_named(&snapshot, "convene"); @@ -12622,7 +12259,7 @@ mod agency_tests { #[test] fn retire_applies_to_every_subject() { - let (_directory, path, mut kernel) = world("RetireAll"); + let mut kernel = world("RetireAll"); let snapshot = kernel.snapshot().unwrap(); let everyone = ["The Human", "The Witness", "The Council"] .map(|label| subject_by_label(&kernel.state, label)); @@ -12646,9 +12283,10 @@ mod agency_tests { assert!(subject.position.is_none()); } assert!(kernel.state.affordance_grants.is_empty()); + let exported = kernel.export().unwrap(); drop(kernel); assert_eq!( - WorldKernel::open(&path, after.world_id) + WorldKernel::open(&exported) .unwrap() .snapshot() .unwrap(), @@ -12661,7 +12299,7 @@ mod agency_tests { /// at apply rather than leaving a grant row the shape check calls corrupt. #[test] fn apply_refuses_a_grant_to_a_retired_subject() { - let (_directory, _path, mut kernel) = world("ForgedGrant"); + let mut kernel = world("ForgedGrant"); let snapshot = kernel.snapshot().unwrap(); let persona = subject_by_label(&kernel.state, "The Witness"); let convene = affordance_named(&snapshot, "convene"); diff --git a/native/aetherlight/src/patch.rs b/native/aetherlight/src/patch.rs index cbdc5477d..7e585682e 100644 --- a/native/aetherlight/src/patch.rs +++ b/native/aetherlight/src/patch.rs @@ -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 {