Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
test(cli): keep purge preview failure endpoints reserved
Samir Hanna Verza7cba496d8e47
diff --git a/crates/ai-memory-cli/src/commands/purge_project.rs b/crates/ai-memory-cli/src/commands/purge_project.rsindex 52776fb3..27c93771 100644--- a/crates/ai-memory-cli/src/commands/purge_project.rs+++ b/crates/ai-memory-cli/src/commands/purge_project.rs@@ -593,21 +593,31 @@ mod tests {assert!(msg.starts_with("Would purge default/scratch: 3 pages, 1 sessions, 1063"));}- /// Nothing listening at all (connection refused) must classify as- /// `Unreachable`, the same as a timeout — both are silent fallbacks.+ /// A dropped connection must classify as `Unreachable`, the same as a+ /// timeout — both are silent fallbacks.#[tokio::test]- async fn run_preview_classifies_a_connection_failure_as_unreachable() {+ async fn run_preview_classifies_a_dropped_connection_as_unreachable() {let tmp = tempfile::TempDir::new().unwrap();- // Bind then drop immediately: the port is very likely free again by- // the time the request lands, and nothing else can be listening on- // it inside this test's short lifetime.+ // Own the endpoint until the request arrives; releasing a reserved+ // port first lets another concurrent test answer the preview instead.let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();let addr = listener.local_addr().unwrap();- drop(listener);+ let server = tokio::spawn(async move {+ use tokio::io::AsyncReadExt;++ let (mut stream, _) = listener.accept().await.unwrap();+ let mut request = [0; 1024];+ assert!(stream.read(&mut request).await.unwrap() > 0);+ // Close after receiving the request, without an HTTP response.+ });let config = config_for(&tmp, format!("http://{addr}"));let outcome = run_preview(&config, "/admin/purge-project", &preview_request()).await;assert!(matches!(outcome, PreviewOutcome::Unreachable));assert!(preview_message(&outcome, "default/scratch").is_none());+ tokio::time::timeout(std::time::Duration::from_secs(1), server)+ .await+ .expect("the preview must reach the fixture")+ .unwrap();}// -----------------------------------------------------------------diff --git a/crates/ai-memory-cli/src/commands/purge_session.rs b/crates/ai-memory-cli/src/commands/purge_session.rsindex 3d984906..869a53d9 100644--- a/crates/ai-memory-cli/src/commands/purge_session.rs+++ b/crates/ai-memory-cli/src/commands/purge_session.rs@@ -431,20 +431,30 @@ mod tests {assert!(msg.starts_with("Would purge session from default/scratch: 1063 observations"));}- /// Nothing listening at all (connection refused) must classify as- /// `Unreachable`, the same as a timeout — both are silent fallbacks.+ /// A dropped connection must classify as `Unreachable`, the same as a+ /// timeout — both are silent fallbacks.#[tokio::test]- async fn run_preview_classifies_a_connection_failure_as_unreachable() {+ async fn run_preview_classifies_a_dropped_connection_as_unreachable() {let tmp = tempfile::TempDir::new().unwrap();- // Bind then drop immediately: the port is very likely free again by- // the time the request lands, and nothing else can be listening on- // it inside this test's short lifetime.+ // Own the endpoint until the request arrives; releasing a reserved+ // port first lets another concurrent test answer the preview instead.let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();let addr = listener.local_addr().unwrap();- drop(listener);+ let server = tokio::spawn(async move {+ use tokio::io::AsyncReadExt;++ let (mut stream, _) = listener.accept().await.unwrap();+ let mut request = [0; 1024];+ assert!(stream.read(&mut request).await.unwrap() > 0);+ // Close after receiving the request, without an HTTP response.+ });let config = config_for(&tmp, format!("http://{addr}"));let outcome = run_preview(&config, "/admin/purge-session", &preview_request()).await;assert!(matches!(outcome, PreviewOutcome::Unreachable));assert!(preview_message(&outcome, "default/scratch").is_none());+ tokio::time::timeout(std::time::Duration::from_secs(1), server)+ .await+ .expect("the preview must reach the fixture")+ .unwrap();}}