Files
boxmaker/docs/plans/M5a/files/crates/memoryd/tests/config.rs
T
kyleandClaude Opus 5.5 de1032157b Plan M5a: local memory in 15 tasks
memoryd (files, the check, edits, journal, index, recall, serving),
the memory tools and built-in grants in brokerd, the memory block in
loopd, bxctl reindex and memory, and the device checks with memoryd.

Each task was built as a reference and gated. Each was replayed on its
own at its end state (854 to 936 tests) and mutation-checked. Each
skeleton compiles and fails its tests. Every todo comment was read
beside its signature.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 15:32:54 -07:00

91 lines
3.0 KiB
Rust

//! `memoryd.toml`: defaults, paths under `home`, the starter next to the config file, and unknown
//! keys refused (M5a spec, section 11). Do not edit.
#[path = "support/tmp.rs"]
mod tmp;
use std::path::PathBuf;
use memoryd::config::Config;
use proto::DataClass;
use tmp::TempDir;
#[test]
fn defaults_and_paths_under_home() {
let config = Config::parse("[paths]\nhome = \"/srv/bx\"\n").unwrap();
assert!(!config.memory.review);
assert_eq!(config.index.max_class, DataClass::Private);
assert_eq!(
config.loop_socket(),
PathBuf::from("/srv/bx/run/loop-memory/memory.sock")
);
assert_eq!(
config.broker_socket(),
PathBuf::from("/srv/bx/run/broker-memory/memory.sock")
);
assert_eq!(
config.admin_socket(),
PathBuf::from("/srv/bx/run/owner-memory/admin.sock")
);
assert_eq!(config.memory_dir(), PathBuf::from("/srv/bx/memory"));
assert_eq!(
config.index_path(),
PathBuf::from("/srv/bx/index/memory.sqlite3")
);
assert_eq!(config.sessions_dir(), PathBuf::from("/srv/bx/sessions"));
}
#[test]
fn every_setting_can_be_given() {
let text = "[paths]\nhome = \"/h\"\n[memory]\nsoul_starter = \"/etc/bx/soul.md\"\nreview = true\n[index]\nmax_class = \"secret\"\n[sockets]\nloop = \"/r/l.sock\"\nbroker = \"/r/b.sock\"\nadmin = \"/r/a.sock\"\n";
let config = Config::parse(text).unwrap();
assert!(config.memory.review);
assert_eq!(config.index.max_class, DataClass::Secret);
assert_eq!(config.memory.soul_starter, PathBuf::from("/etc/bx/soul.md"));
assert_eq!(
(
config.loop_socket(),
config.broker_socket(),
config.admin_socket()
),
(
PathBuf::from("/r/l.sock"),
PathBuf::from("/r/b.sock"),
PathBuf::from("/r/a.sock")
)
);
}
#[test]
fn unknown_keys_are_refused_in_every_table() {
for text in [
"[paths]\nhomee = \"/h\"\n",
"[memory]\nreveiw = true\n",
"[index]\nmax = \"private\"\n",
"[sockets]\nloopd = \"/x\"\n",
"[extra]\n",
"[index]\nmax_class = \"top-secret\"\n",
] {
assert!(Config::parse(text).is_err(), "{text}");
}
}
#[test]
fn a_relative_starter_is_next_to_the_config_file() {
let dir = TempDir::new("config");
let path = dir.write("etc/memoryd.toml", "[memory]\nsoul_starter = \"soul.md\"\n");
let config = Config::load(&path).unwrap();
assert_eq!(config.memory.soul_starter, dir.path().join("etc/soul.md"));
let path = dir.write("etc/default.toml", "");
let config = Config::load(&path).unwrap();
assert_eq!(config.memory.soul_starter, dir.path().join("etc/soul.md"));
let path = dir.write(
"etc/abs.toml",
"[memory]\nsoul_starter = \"/opt/soul.md\"\n",
);
let config = Config::load(&path).unwrap();
assert_eq!(config.memory.soul_starter, PathBuf::from("/opt/soul.md"));
let missing = Config::load(&dir.path().join("nope.toml")).unwrap_err();
assert!(missing.to_string().contains("nope.toml"), "{missing}");
}