Dungeon: pin evidence_of and the snapshot-id gate
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c23e5fd046
commit
2d0eafd236
2 changed files with 57 additions and 0 deletions
|
|
@ -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<Catalog>, 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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue