memoryd: the crate, memoryd.toml, and listening on a socket

Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
2026-09-25 16:41:44 -07:00
committed by kyle
parent 964bd99b12
commit b84b9af540
14 changed files with 657 additions and 2 deletions
+90
View File
@@ -0,0 +1,90 @@
//! `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}");
}