vault tests: scope refusals and trimmed names

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 19:03:17 +01:00
commit b1a2d05976

View file

@ -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()
}