proto, memoryd: no line of an entry may start with §, and headers are exact
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -144,7 +144,8 @@ impl ConsolidateEntry {
|
||||
}
|
||||
|
||||
/// Why an entry's text is not a well-formed entry: empty once trimmed, too long, or holding a line
|
||||
/// that is only the separator. `None` when it is fine.
|
||||
/// that starts with the separator, spaces aside. In `notes.md` such a line would read as a header,
|
||||
/// and a header says where an entry came from. `None` when it is fine.
|
||||
pub fn entry_problem(text: &str, max: usize) -> Option<String> {
|
||||
if text.trim().is_empty() {
|
||||
return Some("an entry cannot be empty".to_string());
|
||||
@@ -156,9 +157,9 @@ pub fn entry_problem(text: &str, max: usize) -> Option<String> {
|
||||
));
|
||||
}
|
||||
for line in text.lines() {
|
||||
if line.trim() == SEPARATOR {
|
||||
if line.trim_start().starts_with(SEPARATOR) {
|
||||
return Some(format!(
|
||||
"an entry cannot hold a line that is only {SEPARATOR}"
|
||||
"an entry cannot hold a line that starts with {SEPARATOR}"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +140,17 @@ fn entries_are_not_empty_not_too_long_and_hold_no_separator_line() {
|
||||
assert!(entry_problem(" \n\t", MAX_ENTRY).is_some());
|
||||
assert!(entry_problem("before\n§\nafter", MAX_ENTRY).is_some());
|
||||
assert!(entry_problem("before\n § \nafter", MAX_ENTRY).is_some());
|
||||
// A line that starts with the separator would read as a header in notes.md (review of
|
||||
// 2026-09-24).
|
||||
let forged = "before\n§ moved 2026-09-24T20:14Z from memory.md in session mm-s1\nafter";
|
||||
let problem = entry_problem(forged, MAX_ENTRY).unwrap();
|
||||
assert!(problem.contains("starts with §"), "{problem}");
|
||||
assert!(entry_problem("§ at the start", MAX_ENTRY).is_some());
|
||||
assert!(entry_problem("before\n §x\nafter", MAX_ENTRY).is_some());
|
||||
assert_eq!(
|
||||
entry_problem("before\nit costs 5 §\nafter", MAX_ENTRY),
|
||||
None
|
||||
);
|
||||
assert_eq!(entry_problem(&"é".repeat(MAX_ENTRY), MAX_ENTRY), None);
|
||||
assert!(entry_problem(&"é".repeat(MAX_ENTRY + 1), MAX_ENTRY).is_some());
|
||||
let note = MemoryArgs::Note {
|
||||
|
||||
Reference in New Issue
Block a user