use std::sync::Arc;
use agent_engine::runtime::memory_context::{DurableStatus, MemoryContextMode};
use agent_engine::{EngineHost, HostOpts};
async fn host_with_default_mode() -> Arc<EngineHost> {
static INIT: tokio::sync::OnceCell<()> = tokio::sync::OnceCell::const_new();
INIT.get_or_init(|| async {
let home =
std::env::temp_dir().join(format!("synaps-memory-default-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&home);
std::fs::create_dir_all(&home).unwrap();
std::fs::write(
home.join("config"),
"memory.default_mode = capture_and_recall\nmemory.default_mode_confirmed = true\n",
)
.unwrap();
agent_engine::config::set_base_dir_for_tests(home);
let h = EngineHost::boot(HostOpts {
profile: None,
no_extensions: true,
mcp_discovery: agent_engine::McpDiscovery::Inline,
})
.await
.expect("host boot");
assert!(EngineHost::install(h).is_ok(), "first install");
})
.await;
EngineHost::current().expect("installed")
}
fn mode_of(status: &DurableStatus) -> Option<MemoryContextMode> {
match status {
DurableStatus::Active { mode, .. } => Some(*mode),
DurableStatus::Off => None,
}
}
#[tokio::test]
async fn every_foreground_session_starts_in_the_confirmed_default_mode() {
let h = host_with_default_mode().await;
let fg1 = h.foreground_runtime().await.unwrap();
let fg2 = h.foreground_runtime().await.unwrap();
for fg in [&fg1, &fg2] {
assert_eq!(
mode_of(&fg.memory_context_status().durable),
Some(MemoryContextMode::CaptureAndRecall)
);
}
fg1.memory_context_disable();
assert_eq!(fg1.memory_context_status().durable, DurableStatus::Off);
assert_eq!(
mode_of(&fg2.memory_context_status().durable),
Some(MemoryContextMode::CaptureAndRecall)
);
}
#[tokio::test]
async fn workers_do_not_inherit_the_default_mode() {
let h = host_with_default_mode().await;
let w = h.worker_runtime().await.unwrap();
assert_eq!(w.memory_context_status().durable, DurableStatus::Off);
}