Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
test(cli): opt non-watcher serve spawns out of the wiki watcher
Vinícius Andrade823b455db0a5
diff --git a/crates/ai-memory-cli/tests/suite/autoscope_env.rs b/crates/ai-memory-cli/tests/suite/autoscope_env.rsindex 6a1207e2..3ad93ba3 100644--- a/crates/ai-memory-cli/tests/suite/autoscope_env.rs+++ b/crates/ai-memory-cli/tests/suite/autoscope_env.rs@@ -22,6 +22,26 @@ fn bin() -> &'static str {env!("CARGO_BIN_EXE_ai-memory")}+/// Logged by `start_watcher` when `serve --no-watcher` is honoured.+const WATCHER_DISABLED: &str = "watcher disabled by --no-watcher";+/// Logged by `start_watcher` when it actually installs an FSEvents/inotify+/// instance. Must not appear in these children: they do not exercise watching.+const WATCHER_STARTED: &str = "starting wiki watcher";++/// Pin that the spawned binary opted out of the wiki watcher. The disable+/// line is logged before the `[auto_scope]` mode needle these tests wait on,+/// so a successful match without it would mean the flag was ignored.+fn assert_watcher_opted_out(stderr: &str) {+ assert!(+ stderr.contains(WATCHER_DISABLED),+ "spawned serve must log that the watcher was opted out.\nstderr:\n{stderr}"+ );+ assert!(+ !stderr.contains(WATCHER_STARTED),+ "spawned serve must not install a wiki watcher.\nstderr:\n{stderr}"+ );+}+/// Spawn the binary with the given env vars and stream stderr until either/// `needle` appears in a line or `timeout` elapses. Always kills the child/// before returning. Returns `(matched_line_or_none, all_stderr_captured)`.@@ -41,6 +61,11 @@ fn spawn_and_wait_for_log("http","--bind","127.0.0.1:0",+ // None of these tests watch the wiki. The watcher is a+ // machine-global FSEvents/inotify instance; concurrent serve+ // children can exhaust it (#745). Opt out so the child never+ // takes one.+ "--no-watcher","--data-dir",]).arg(tmp.path())@@ -96,6 +121,9 @@ fn spawn_and_wait_for_log(// Pump thread terminates once stderr closes (post-kill); collect what// it captured.let all_stderr = pump.join().unwrap_or_default();+ if matched.is_some() {+ assert_watcher_opted_out(&all_stderr);+ }(matched, all_stderr)}@@ -111,6 +139,10 @@ fn spawn_and_wait_for_exit(envs: &[(&str, &str)], timeout: Duration) -> (bool, S"http","--bind","127.0.0.1:0",+ // Same opt-out as [`spawn_and_wait_for_log`]: invalid config+ // fails before the watcher is installed, but keeping the flag+ // here means every serve spawn in this file is hermetic.+ "--no-watcher","--data-dir",]).arg(tmp.path())diff --git a/crates/ai-memory-cli/tests/suite/serve_shutdown.rs b/crates/ai-memory-cli/tests/suite/serve_shutdown.rsindex f405c0a4..14e3cc1d 100644--- a/crates/ai-memory-cli/tests/suite/serve_shutdown.rs+++ b/crates/ai-memory-cli/tests/suite/serve_shutdown.rs@@ -11,6 +11,11 @@ mod slow {use std::time::{Duration, Instant};const BIN: &str = env!("CARGO_BIN_EXE_ai-memory");+ /// Logged by `start_watcher` when `serve --no-watcher` is honoured.+ const WATCHER_DISABLED: &str = "watcher disabled by --no-watcher";+ /// Logged by `start_watcher` when it actually installs an FSEvents/inotify+ /// instance. Must not appear here: this test does not exercise watching.+ const WATCHER_STARTED: &str = "starting wiki watcher";fn wait_for_exit(child: &mut Child, budget: Duration) -> Option<std::process::ExitStatus> {let deadline = Instant::now() + budget;@@ -48,8 +53,10 @@ mod slow {.arg("-c")// Explicit transport: the default is stdio today, and a test that// rides that default would quietly start testing something else if- // it ever changed.- .arg(r#"trap "" INT; exec "$1" serve --transport stdio"#)+ // it ever changed. `--no-watcher`: this test does not watch the+ // wiki; concurrent serve children can exhaust the machine-global+ // FSEvents/inotify instance (#745).+ .arg(r#"trap "" INT; exec "$1" serve --transport stdio --no-watcher"#).arg("sh").arg(BIN).env("AI_MEMORY_DATA_DIR", data_dir.path())@@ -83,18 +90,34 @@ mod slow {let deadline = Instant::now() + Duration::from_secs(60);let mut ready = false;+ let mut startup = String::new();while Instant::now() < deadline {match rx.recv_timeout(Duration::from_secs(1)) {- Ok(line) if line.contains("ready on stdio") => {- ready = true;- break;+ Ok(line) => {+ startup.push_str(&line);+ startup.push('\n');+ if line.contains("ready on stdio") {+ ready = true;+ break;+ }}- Ok(_) => {}Err(mpsc::RecvTimeoutError::Timeout) => {}Err(mpsc::RecvTimeoutError::Disconnected) => break,}}assert!(ready, "server never reported it was ready on stdio");+ // Ready is logged after the watcher decision, so this buffer+ // includes that decision. None of this test watches the wiki;+ // the watcher is a machine-global FSEvents/inotify instance+ // concurrent children can exhaust (#745).+ assert!(+ startup.contains(WATCHER_DISABLED),+ "spawned serve must log that the watcher was opted out.\nstderr:\n{startup}"+ );+ assert!(+ !startup.contains(WATCHER_STARTED),+ "spawned serve must not install a wiki watcher.\nstderr:\n{startup}"+ );let killed = Command::new("kill").args(["-INT", &child.id().to_string()])diff --git a/crates/ai-memory-cli/tests/suite/shutdown_signals.rs b/crates/ai-memory-cli/tests/suite/shutdown_signals.rsindex da132ae5..b2931dd9 100644--- a/crates/ai-memory-cli/tests/suite/shutdown_signals.rs+++ b/crates/ai-memory-cli/tests/suite/shutdown_signals.rs@@ -70,6 +70,11 @@ const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(10);const HTTP_READY: &str = "MCP HTTP server ready";const STDIO_READY: &str = "MCP server ready on stdio";+/// Logged by `start_watcher` when `serve --no-watcher` is honoured.+const WATCHER_DISABLED: &str = "watcher disabled by --no-watcher";+/// Logged by `start_watcher` when it actually installs an FSEvents/inotify+/// instance. Must not appear in these children: they do not exercise watching.+const WATCHER_STARTED: &str = "starting wiki watcher";/// The stdio arm's post-handshake shutdown log — the branch only/// [`stdio_server_exits_on_sigterm_after_initialize`] reaches.const STDIO_STOP_AFTER_HANDSHAKE: &str = "stopping the stdio transport";@@ -139,6 +144,10 @@ impl Server {// to exist so the server reaches its ready line.cmd.args(["--bind", "127.0.0.1:0"]);}+ // None of these tests watch the wiki. The watcher is a machine-global+ // FSEvents/inotify instance; concurrent serve children can exhaust it+ // (#745). Opt out so the child never takes one.+ cmd.arg("--no-watcher");cmd.arg("--data-dir").arg(data_dir.path()).env("AI_MEMORY_DATA_DIR", data_dir.path())@@ -211,6 +220,22 @@ impl Server {}}+ /// Pin that the spawned binary opted out of the wiki watcher. Ready+ /// lines are logged after the watcher decision, so `seen` already+ /// contains that decision once [`Self::wait_for`] has matched one.+ fn assert_watcher_opted_out(&self) {+ assert!(+ self.seen.contains(WATCHER_DISABLED),+ "spawned serve must log that the watcher was opted out.\nstderr:\n{}",+ self.seen+ );+ assert!(+ !self.seen.contains(WATCHER_STARTED),+ "spawned serve must not install a wiki watcher.\nstderr:\n{}",+ self.seen+ );+ }+/// Block until a stderr line contains `needle`, or the timeout expires.fn wait_for(&mut self, needle: &str, timeout: Duration) -> bool {let deadline = Instant::now() + timeout;@@ -298,6 +323,7 @@ fn http_server_exits_on_sigterm() {server.stderr());}+ server.assert_watcher_opted_out();server.signal("TERM");@@ -326,6 +352,7 @@ fn stdio_server_exits_on_sigint() {server.stderr());}+ server.assert_watcher_opted_out();// Precondition for a non-vacuous result: stdin is still open, so the// transport has no reason of its own to stop.assert!(@@ -364,6 +391,7 @@ fn stdio_server_exits_on_sigterm_after_initialize() {server.stderr());}+ server.assert_watcher_opted_out();// Precondition for a non-vacuous result: until the handshake completes,// the signal lands in the pre-handshake select the other tests cover.