From b1a2d05976a91df587dec6349fbeecc2a7ab52bf Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 19:03:17 +0100 Subject: [PATCH] vault tests: scope refusals and trimmed names Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight/src/vault.rs | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/crates/ghostlight/src/vault.rs b/crates/ghostlight/src/vault.rs index 7b17ab9..b312be2 100644 --- a/crates/ghostlight/src/vault.rs +++ b/crates/ghostlight/src/vault.rs @@ -1497,6 +1497,46 @@ mod tests { assert_eq!(before, std::fs::read(&file).unwrap()); } + /// A scope that is a file, or a link out of the root, is refused as Scope; + /// a scope that holds no note is refused; an empty vault with no scope is + /// an empty source. + #[test] + fn a_scope_must_be_a_directory_inside_the_root_holding_a_note() { + let vault = fixture(); + let outside = tempfile::tempdir().unwrap(); + write(outside.path(), "Leak.md", "leak\n"); + assert!(matches!( + VaultSnapshot::build(&VaultProfile { scope: "Public/index.md".into(), ..profile(vault.path()) }), + Err(VaultError::Scope(_)) + )); + #[cfg(unix)] + { + std::os::unix::fs::symlink(outside.path(), vault.path().join("Out")).unwrap(); + assert!(matches!( + VaultSnapshot::build(&VaultProfile { scope: "Out".into(), ..profile(vault.path()) }), + Err(VaultError::Scope(_)) + )); + } + let built = snapshot(vault.path()); + assert!(matches!(VaultEvidenceSource::from_snapshot(&built, "Nowhere"), Err(VaultError::Scope(_)))); + assert!(VaultEvidenceSource::from_snapshot(&built, "Spoilers").is_ok()); + let empty = tempfile::tempdir().unwrap(); + assert!(VaultEvidenceSource::from_snapshot(&snapshot(empty.path()), "").is_ok()); + assert!(matches!( + VaultEvidenceSource::from_snapshot(&snapshot(empty.path()), "Spoilers"), + Err(VaultError::Scope(_)) + )); + } + + /// A name that does not survive trimming cannot be a reference. + #[test] + fn a_note_whose_name_begins_with_a_space_is_not_admitted() { + let vault = tempfile::tempdir().unwrap(); + write(vault.path(), "Good.md", "good\n"); + write(vault.path(), " Padded.md", "padded\n"); + assert_eq!(references(&snapshot(vault.path())), ["Good.md"]); + } + fn references(snapshot: &VaultSnapshot) -> Vec<&str> { snapshot.notes.iter().map(|note| note.reference.as_str()).collect() }