123 lines
3.7 KiB
Rust
123 lines
3.7 KiB
Rust
//! Tests for `MemoryCommand::Tiers`: identity entries and notes with recall-hit counts. Do not edit.
|
|
|
|
#[path = "support/tmp.rs"]
|
|
mod tmp;
|
|
|
|
use bxcore::{MemoryFile, Timestamp};
|
|
use memoryd::files::Store;
|
|
use memoryd::tiers;
|
|
use tmp::TempDir;
|
|
|
|
fn now() -> Timestamp {
|
|
Timestamp::parse("2026-10-03T08:00:00.000Z").unwrap()
|
|
}
|
|
|
|
struct Setup {
|
|
_dir: TempDir,
|
|
store: Store,
|
|
}
|
|
|
|
fn setup(tag: &str) -> Setup {
|
|
let dir = TempDir::new(tag);
|
|
let starter = dir.write("etc/soul.md", "Soul.\n");
|
|
let store = Store::new(&dir.path().join("memory"));
|
|
store.init(&starter).unwrap();
|
|
Setup { _dir: dir, store }
|
|
}
|
|
|
|
fn write_recall(store: &Store, line: &str) {
|
|
std::fs::create_dir_all(store.path("recalls")).unwrap();
|
|
store
|
|
.append("recalls/2026-10.jsonl", &format!("{line}\n"))
|
|
.unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn identity_entries_list_with_zero_hits() {
|
|
let s = setup("tiers-id");
|
|
s.store
|
|
.write_entries(MemoryFile::Memory, &["I like tea.".to_string()])
|
|
.unwrap();
|
|
s.store
|
|
.write_entries(MemoryFile::User, &["The owner is Kyle.".to_string()])
|
|
.unwrap();
|
|
let text = tiers::list(&s.store, now()).unwrap();
|
|
assert!(
|
|
text.contains("identity memory.md hits 0 last -"),
|
|
"{text}"
|
|
);
|
|
assert!(text.contains("I like tea."), "{text}");
|
|
assert!(text.contains("identity user.md hits 0 last -"), "{text}");
|
|
assert!(text.contains("The owner is Kyle."), "{text}");
|
|
}
|
|
|
|
#[test]
|
|
fn notes_carry_counts_from_recalls() {
|
|
let s = setup("tiers-notes");
|
|
std::fs::write(
|
|
s.store.path("notes.md"),
|
|
"§ noted 2026-09-22T18:20Z in session mm-a · private\nlaunch window moved.\n",
|
|
)
|
|
.unwrap();
|
|
write_recall(
|
|
&s.store,
|
|
r#"{"time":"2026-10-03T07:00:00.000Z","session":"mm-now","query":"launch","hits":[{"kind":"noted","session":"mm-a","epoch":0,"record":0}]}"#,
|
|
);
|
|
write_recall(
|
|
&s.store,
|
|
r#"{"time":"2026-10-03T07:30:00.000Z","session":"mm-now","query":"window","hits":[{"kind":"noted","session":"mm-a","epoch":0,"record":0}]}"#,
|
|
);
|
|
let text = tiers::list(&s.store, now()).unwrap();
|
|
assert!(
|
|
text.contains(
|
|
"note session mm-a hits 2 last 2026-10-03T07:30:00.000Z private trusted"
|
|
),
|
|
"{text}"
|
|
);
|
|
assert!(text.contains("launch window moved."), "{text}");
|
|
}
|
|
|
|
#[test]
|
|
fn untrusted_notes_are_listed_and_marked() {
|
|
let s = setup("tiers-untrusted");
|
|
std::fs::write(
|
|
s.store.path("notes.md"),
|
|
"§ noted 2026-09-22T18:20Z in session mm-c · private · untrusted\nexample.org says the launch moved.\n",
|
|
)
|
|
.unwrap();
|
|
let text = tiers::list(&s.store, now()).unwrap();
|
|
assert!(
|
|
text.contains("note session mm-c hits 0 last - private untrusted"),
|
|
"{text}"
|
|
);
|
|
assert!(
|
|
text.contains("example.org says the launch moved."),
|
|
"{text}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_recall_of_a_different_note_does_not_count() {
|
|
let s = setup("tiers-other");
|
|
std::fs::write(
|
|
s.store.path("notes.md"),
|
|
"§ noted 2026-09-22T18:20Z in session mm-a · private\nfirst note.\n§ noted 2026-09-22T18:21Z in session mm-b · private\nsecond note.\n",
|
|
)
|
|
.unwrap();
|
|
write_recall(
|
|
&s.store,
|
|
r#"{"time":"2026-10-03T07:00:00.000Z","session":"mm-now","query":"second","hits":[{"kind":"noted","session":"mm-b","epoch":0,"record":1}]}"#,
|
|
);
|
|
let text = tiers::list(&s.store, now()).unwrap();
|
|
assert!(
|
|
text.contains("note session mm-a hits 0 last - private trusted"),
|
|
"{text}"
|
|
);
|
|
assert!(
|
|
text.contains(
|
|
"note session mm-b hits 1 last 2026-10-03T07:00:00.000Z private trusted"
|
|
),
|
|
"{text}"
|
|
);
|
|
}
|