use super::*;
fn write_legacy_fixture(root: &std::path::Path) {
std::fs::create_dir_all(root).unwrap();
for i in 0..153 {
let name = format!("legacy-{i:03}");
let desc = if i >= 150 {
"L".repeat(150)
} else {
format!("legacy note {i:03}")
};
let file = format!(
"---\nname: {name}\ndescription: {desc}\nmetadata:\n node_type: memory\n type: project\n---\n\nbody\n"
);
std::fs::write(root.join(format!("{name}.md")), file).unwrap();
}
}
#[test]
fn a_153_entry_legacy_fixture_loads_untouched_and_touching_applies_new_rules() {
let (dir, root) = tmp_root();
write_legacy_fixture(&root);
let store = MemoryStore::new(root.clone(), "MEMORY.md");
let entries = store.list_memories();
assert_eq!(entries.len(), 153, "every legacy entry must load");
let listing = store.render_index().unwrap();
assert!(
listing.contains("legacy-150"),
"over-long entry must list: {listing}"
);
match store
.write_memory("legacy-150", &"H".repeat(141), "project", "new body", None)
.unwrap()
{
WriteOutcome::Rejected(rej) => assert_eq!(rej.rule, "hook_max_chars"),
other => panic!("touching with an over-long hook must be refused: {other:?}"),
}
let outcome = store
.write_memory(
"legacy-150",
"now fits the hook budget",
"project",
"new body",
None,
)
.unwrap();
assert!(
matches!(outcome, WriteOutcome::Written { created: false }),
"a compliant touch must land: {outcome:?}"
);
drop(dir);
}