From 2d0eafd2365914a188203b5288890fcdf0dcc69c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 22:10:32 +0100 Subject: [PATCH] Dungeon: pin evidence_of and the snapshot-id gate Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight-dungeon/src/run_ahead.rs | 45 ++++++++++++++++++++++ crates/ghostlight-dungeon/src/vaults.rs | 12 ++++++ 2 files changed, 57 insertions(+) diff --git a/crates/ghostlight-dungeon/src/run_ahead.rs b/crates/ghostlight-dungeon/src/run_ahead.rs index 979e8a6..53f1bc1 100644 --- a/crates/ghostlight-dungeon/src/run_ahead.rs +++ b/crates/ghostlight-dungeon/src/run_ahead.rs @@ -54,3 +54,48 @@ pub(crate) async fn evidence_of( }, } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + begin::tests::{NoVaults, one_vault}, + catalog::{Timeline, WorldRecord, timeline_id}, + }; + use chrono::Utc; + use uuid::Uuid; + + async fn catalog_with(snapshot_id: Option<&str>) -> (tempfile::TempDir, Mutex, String) { + let directory = tempfile::tempdir().unwrap(); + let mut catalog = Catalog::open(directory.path().join("catalog.cc")).unwrap(); + let timeline = timeline_id(Uuid::new_v4()); + catalog + .mint_timeline( + Some(WorldRecord { + world_id: "w1".into(), + title: "Ashfall".into(), + owner: "alice".into(), + snapshot_id: snapshot_id.map(str::to_owned), + created_at: Utc::now(), + }), + Timeline { id: timeline.clone(), world_id: "w1".into(), parent: None }, + ) + .unwrap(); + (directory, Mutex::new(catalog), timeline) + } + + /// A timeline's elaborator reads what its world was bound to: nothing + /// for an unseeded world, the snapshot for a seeded one, and no evidence + /// (so no sweep) for a snapshot that cannot be reopened or a timeline the + /// catalog does not know. + #[tokio::test] + async fn the_evidence_of_a_timeline_is_its_bound_snapshots() { + let vaults = one_vault(); + let (_a, unseeded, timeline) = catalog_with(None).await; + assert!(evidence_of(&unseeded, &NoVaults, &timeline).await.is_some(), "an unseeded world reads none, and still sweeps"); + let (_b, seeded, timeline) = catalog_with(Some("feedface")).await; + assert!(evidence_of(&seeded, vaults.as_ref(), &timeline).await.is_some()); + assert!(evidence_of(&seeded, &NoVaults, &timeline).await.is_none(), "an unreadable snapshot is never swept blind"); + assert!(evidence_of(&seeded, vaults.as_ref(), "timeline:00000000-0000-4000-8000-000000000000").await.is_none()); + } +} diff --git a/crates/ghostlight-dungeon/src/vaults.rs b/crates/ghostlight-dungeon/src/vaults.rs index da7a99d..0b014e1 100644 --- a/crates/ghostlight-dungeon/src/vaults.rs +++ b/crates/ghostlight-dungeon/src/vaults.rs @@ -140,6 +140,18 @@ mod tests { (state, vaults, id) } + /// The id gate keeps a stored id from naming another path: a short hex + /// string and a long non-hex one are both refused before any path is built. + #[test] + fn a_stored_snapshot_id_that_is_not_an_id_is_refused_before_a_path_is_built() { + let (_state, vaults, id) = imported_avatar(); + for bad in ["abc".to_owned(), format!("../{}", &id[3..]), id.to_uppercase()] { + let error = vaults.evidence(&bad).err().expect("refused").to_string(); + assert!(error.contains("not an id"), "{bad}: {error}"); + } + assert!(vaults.evidence(&id).is_ok()); + } + #[test] fn it_lists_the_imported_profiles_and_opens_the_recorded_snapshot() { let (_state, vaults, id) = imported_avatar();