use super::*;
#[test]
fn a_file_deleted_by_the_other_writer_drops_out_of_the_listing() {
let (dir, root) = tmp_root();
let store = MemoryStore::new(root.clone(), "MEMORY.md");
store
.write_memory("kept", "k", "project", "b", None)
.unwrap();
store
.write_memory("gone", "g", "project", "b", None)
.unwrap();
assert!(store.read_index().contains("(gone.md)"));
std::fs::remove_file(root.join("gone.md")).unwrap();
let listing = store.render_index().unwrap();
assert!(
!listing.contains("(gone.md)"),
"dangling row survived: {listing}"
);
assert!(
listing.contains("(kept.md)"),
"kept row must remain: {listing}"
);
drop(dir);
}
#[test]
fn the_row_description_comes_from_the_file_not_a_hand_edited_index() {
let (dir, root) = tmp_root();
let store = MemoryStore::new(root.clone(), "MEMORY.md");
store
.write_memory("fact", "frontmatter desc", "project", "body", None)
.unwrap();
std::fs::write(
root.join("MEMORY.md"),
"- [fact](fact.md) — HAND-EDITED DESC\n",
)
.unwrap();
let listing = store.render_index().unwrap();
assert!(
listing.contains("frontmatter desc"),
"disk truth must win: {listing}"
);
assert!(
!listing.contains("HAND-EDITED DESC"),
"the hand edit must not leak into the listing: {listing}"
);
drop(dir);
}
#[test]
fn a_rebuild_keeps_the_curated_human_title_but_refreshes_the_description() {
let (dir, root) = tmp_root();
let store = MemoryStore::new(root.clone(), "MEMORY.md");
store
.write_memory("beta", "old desc", "project", "body", None)
.unwrap();
std::fs::write(root.join("MEMORY.md"), "- [人类标题](beta.md) — old desc\n").unwrap();
store
.write_memory("alpha", "a", "project", "b", None)
.unwrap();
let index = store.read_index();
assert!(
index.contains("- [人类标题](beta.md)"),
"the human title must survive the rebuild: {index}"
);
assert!(index.contains("old desc"), "{index}");
assert!(index.contains("(alpha.md)"), "new file appended: {index}");
drop(dir);
}
#[test]
fn a_file_added_by_the_other_writer_appears_in_the_listing() {
let (dir, root) = tmp_root();
let store = MemoryStore::new(root.clone(), "MEMORY.md");
std::fs::create_dir_all(&root).unwrap();
std::fs::write(
root.join("foreign.md"),
"---\nname: foreign\ndescription: added by cc\nmetadata:\n type: project\n---\n\nbody\n",
)
.unwrap();
let listing = store.render_index().unwrap();
assert!(
listing.contains("(foreign.md)") && listing.contains("added by cc"),
"the other writer's file must appear: {listing}"
);
drop(dir);
}