Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(test): update test files for agent module

Steven Enamakel0f90ec44c4cc
diff --git a/crates/openhuman-core/src/agent/agent_memory_attribution_tests.rs b/crates/openhuman-core/src/agent/agent_memory_attribution_tests.rs
deleted file mode 100644
index c00150a091..0000000000
--- a/crates/openhuman-core/src/agent/agent_memory_attribution_tests.rs
+++ /dev/null
@@ -1,157 +0,0 @@
-use super::*;
-
-// Origin-gated conversation autosave (#5312).
-//
-// `turn()` stores the user message only when the turn's text was written by a
-// person — `turn_origin::current_is_user_authored`. These cover both directions
-// of that allowlist: the two user-authored origins that were not already pinned
-// by the `WebChat` case in part 01, and the two host-written ones that must not
-// reach the user's conversation memory.
-
-/// Poll for a `user_msg:` conversation memory over the same one-second window
-/// the positive autosave test uses, and report whether one ever landed.
-///
-/// The user message is stored fire-and-forget (`tokio::spawn` in
-/// `turn/core_turn.rs`, #3610), so both directions need the *same* window or the
-/// negative tests are the weaker assertion: a broken guard whose spawned store
-/// lands after a short fixed sleep would pass them while failing in production.
-/// Returns as soon as one appears, so a genuinely broken guard fails fast
-/// instead of costing the full second.
-///
-/// Lists `CONVERSATION_RAW_NAMESPACE` explicitly rather than passing `None`.
-/// The autosave writes there (it no longer shares the default namespace), and a
-/// `None` listing comes back empty — which would make the two negative tests
-/// below pass without ever reading the store, exactly the false green this
-/// helper exists to avoid.
-async fn poll_for_stored_user_message(mem: &Arc<dyn Memory>) -> Vec<String> {
- use crate::agent::learning::transcript_ingest::CONVERSATION_RAW_NAMESPACE;
-
- let mut keys: Vec<String> = Vec::new();
- for _ in 0..50 {
- keys = mem
- .list(Some(CONVERSATION_RAW_NAMESPACE), None, None)
- .await
- .expect(
- "memory list must succeed; an empty list here would let the \
- autosave assertions below pass without reading storage",
- )
- .into_iter()
- .map(|e| e.key)
- .collect();
- if keys.iter().any(|k| k.starts_with("user_msg:")) {
- break;
- }
- tokio::time::sleep(std::time::Duration::from_millis(20)).await;
- }
- keys
-}
-
-/// `ExternalChannel` is in the user-authored allowlist alongside `WebChat`, so
-/// it needs its own positive case: a Telegram/Discord/Slack message is a person
-/// talking, and the allowlist would be half-tested if only the web thread had a
-/// stored-message assertion.
-#[tokio::test]
-async fn an_external_channel_turn_stores_the_user_message() {
- use crate::agent::turn_origin::{with_origin, AgentTurnOrigin};
-
- let (mem, _tmp) = make_retaining_memory();
- let provider = Arc::new(ScriptedProvider::new(vec![text_response("got it")]));
- let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);
-
- let origin = AgentTurnOrigin::ExternalChannel {
- channel: "telegram".into(),
- sender: Some("user-42".into()),
- reply_target: "chat-7".into(),
- message_id: "m-1".into(),
- };
- let _ = with_origin(origin, agent.turn("remember my flight is at nine"))
- .await
- .unwrap();
-
- let keys = poll_for_stored_user_message(&mem).await;
- assert!(
- keys.iter().any(|k| k.starts_with("user_msg:")),
- "a channel message is a person talking and must be stored: {keys:?}"
- );
-}
-
-/// The desktop Settings agent-chat panel calls `openhuman.agent_chat`, which
-/// scopes `DirectChat`. That is a person typing, so it stores — the origin
-/// exists precisely because `Cli` (its previous label, chosen for the approval
-/// gate) would have dropped these messages.
-#[tokio::test]
-async fn a_direct_chat_turn_stores_the_user_message() {
- use crate::agent::turn_origin::{with_origin, AgentTurnOrigin};
-
- let (mem, _tmp) = make_retaining_memory();
- let provider = Arc::new(ScriptedProvider::new(vec![text_response("noted")]));
- let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);
-
- let _ = with_origin(
- AgentTurnOrigin::DirectChat,
- agent.turn("my dog is called Pip"),
- )
- .await
- .unwrap();
-
- let keys = poll_for_stored_user_message(&mem).await;
- assert!(
- keys.iter().any(|k| k.starts_with("user_msg:")),
- "a direct-chat message is a person typing and must be stored: {keys:?}"
- );
-}
-
-/// An internal agent runs on the same config as the chat, so it inherits
-/// `auto_save` — but its "user message" is the prompt the host wrote for it.
-/// Storing that as a conversation memory puts prompt boilerplate where the
-/// user's own words belong, and it competes for slots in every later recall
-/// (#5312). A `TrustedAutomation` turn therefore saves nothing.
-#[tokio::test]
-async fn an_automation_turn_does_not_store_its_prompt_as_the_users_memory() {
- use crate::agent::turn_origin::{with_origin, AgentTurnOrigin, TrustedAutomationSource};
-
- let (mem, _tmp) = make_retaining_memory();
- let provider = Arc::new(ScriptedProvider::new(vec![text_response("goals updated")]));
- let (mut agent, _tmp2) = build_agent_with_memory(
- provider,
- vec![],
- mem.clone(),
- true, // auto_save enabled, exactly as a config-built internal agent gets it
- );
-
- let origin = AgentTurnOrigin::TrustedAutomation {
- job_id: "memory_goals:enrich:1".into(),
- source: TrustedAutomationSource::Background,
- };
- let _ = with_origin(origin, agent.turn("Maintain the existing goals list."))
- .await
- .unwrap();
-
- // The fire-and-forget store would land shortly after the turn returns, so
- // give it the same one-second window the positive tests poll for before
- // concluding it never happened.
- let keys = poll_for_stored_user_message(&mem).await;
- assert!(
- !keys.iter().any(|k| k.starts_with("user_msg:")),
- "an automation prompt must not be stored as a user message: {keys:?}"
- );
-}
-
-/// An unscoped turn is not a user turn either. `turn_origin` documents that
-/// every entry point scopes an origin and that an unlabelled one fails closed;
-/// the autosave follows the same allowlist, so a caller that forgets cannot
-/// quietly write host text into the user's memory.
-#[tokio::test]
-async fn an_unscoped_turn_stores_no_user_message() {
- let (mem, _tmp) = make_retaining_memory();
- let provider = Arc::new(ScriptedProvider::new(vec![text_response("ok")]));
- let (mut agent, _tmp2) = build_agent_with_memory(provider, vec![], mem.clone(), true);
-
- let _ = agent.turn("who wrote this?").await.unwrap();
-
- let keys = poll_for_stored_user_message(&mem).await;
- assert!(
- !keys.iter().any(|k| k.starts_with("user_msg:")),
- "an unscoped turn must not be credited to the user: {keys:?}"
- );
-}
diff --git a/crates/openhuman-core/src/agent/agent_tests.rs b/crates/openhuman-core/src/agent/agent_tests.rs
index c760f9d49d..c764f4e787 100644
--- a/crates/openhuman-core/src/agent/agent_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_tests.rs
@@ -27,7 +27,6 @@
use crate::agent::session_host::OpenHumanSessionHost;
use crate::config::AgentConfig;
use crate::inference::provider::ChatResponse;
-use crate::memory::Memory;
use anyhow::Result;
use async_trait::async_trait;
use std::sync::{Arc, Mutex};
@@ -222,65 +221,19 @@ impl Tool for CountingTool {
}
}
-/// Create an isolated memory instance with its own temp directory.
-/// The returned `TempDir` must be held alive for the duration of the test
-/// to prevent the directory (and its SQLite database) from being deleted.
-fn make_memory() -> (Arc<dyn Memory>, tempfile::TempDir) {
- // `backend: "none"` is what this fixture used to ask the engine's factory
- // for, and a no-op store is exactly what that produced — so the config is
- // gone rather than kept as an unused binding that reads like it still
- // selects something.
- let tmp = tempfile::TempDir::new().unwrap();
- let mem = crate::memory::test_support::noop_memory();
- (mem, tmp)
-}
-
-/// A memory that **retains**, for the two auto-save tests that read it back.
-///
-/// This was `make_sqlite_memory` and asked the engine's factory for a
-/// `backend = "sqlite"` store. The name went with the engine: nothing in
-/// either caller is about SQL — they write through the agent and then assert
-/// on `count()` — so what they need is a store that keeps things, and the
-/// rename says which of the two properties is load-bearing.
-fn make_retaining_memory() -> (Arc<dyn Memory>, tempfile::TempDir) {
- let tmp = tempfile::TempDir::new().unwrap();
- let mem = crate::memory::test_support::retaining_memory();
- (mem, tmp)
-}
-
/// Build an agent with an isolated temp workspace.
/// Returns `(OpenHumanSessionHost, TempDir)` — hold `_tmp` in the test to keep the dir alive.
fn build_agent_with(
provider: Arc<dyn ChatModel<()>>,
tools: Vec<Box<dyn Tool>>,
dispatcher: Box<dyn ToolDialect>,
-) -> (OpenHumanSessionHost, tempfile::TempDir) {
- let (mem, tmp) = make_memory();
- let agent = OpenHumanSessionHost::builder()
- .chat_model(provider)
- .tools(tools)
- .memory(mem)
- .tool_dispatcher(dispatcher)
- .workspace_dir(tmp.path().to_path_buf())
- .build()
- .unwrap();
- (agent, tmp)
-}
-
-fn build_agent_with_memory(
- provider: Arc<dyn ChatModel<()>>,
- tools: Vec<Box<dyn Tool>>,
- mem: Arc<dyn Memory>,
- auto_save: bool,
) -> (OpenHumanSessionHost, tempfile::TempDir) {
let tmp = tempfile::TempDir::new().unwrap();
let agent = OpenHumanSessionHost::builder()
.chat_model(provider)
.tools(tools)
- .memory(mem)
- .tool_dispatcher(Box::new(NativeDialect))
+ .tool_dispatcher(dispatcher)
.workspace_dir(tmp.path().to_path_buf())
- .auto_save(auto_save)
.build()
.unwrap();
(agent, tmp)
@@ -291,11 +244,10 @@ fn build_agent_with_config(
tools: Vec<Box<dyn Tool>>,
config: AgentConfig,
) -> (OpenHumanSessionHost, tempfile::TempDir) {
- let (mem, tmp) = make_memory();
+ let tmp = tempfile::TempDir::new().unwrap();
let agent = OpenHumanSessionHost::builder()
.chat_model(provider)
.tools(tools)
- .memory(mem)
.tool_dispatcher(Box::new(NativeDialect))
.workspace_dir(tmp.path().to_path_buf())
.config(config)
@@ -336,8 +288,6 @@ fn xml_tool_response(name: &str, args: &str) -> ChatResponse {
}
}
-#[path = "agent_memory_attribution_tests.rs"]
-mod agent_memory_attribution_tests;
#[path = "agent_turn_loop_nudge_tests.rs"]
mod agent_turn_loop_nudge_tests;
#[path = "agent_turn_loop_packed_tool_tests.rs"]
diff --git a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
index 9e18bfd6bc..580f828127 100644
--- a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
@@ -283,76 +283,6 @@ async fn history_is_not_trimmed_by_message_count() {
);
}
-// ═══════════════════════════════════════════════════════════════════════════
-// 9. Memory auto-save round-trip
-// ═══════════════════════════════════════════════════════════════════════════
-
-#[tokio::test]
-async fn auto_save_stores_messages_in_memory() {
- let (mem, _tmp) = make_retaining_memory();
- let provider = Arc::new(ScriptedProvider::new(vec![text_response(
- "I remember everything",
- )]));
-
- let (mut agent, _tmp2) = build_agent_with_memory(
- provider,
- vec![],
- mem.clone(),
- true, // auto_save enabled
- );
-
- // Scoped like a real chat turn. The autosave only stores what a person sent
- // (`turn_origin::current_is_user_authored`), and production entry points
- // scope an origin — web chat `WebChat`, channels `ExternalChannel` — so a
- // test that skipped it would be asserting a shape no caller produces.
- let _ = crate::agent::turn_origin::with_origin(
- crate::agent::turn_origin::AgentTurnOrigin::WebChat {
- thread_id: "t-autosave".into(),
- client_id: "c-autosave".into(),
- request_id: None,
- },
- agent.turn("Remember this fact"),
- )
- .await
- .unwrap();
-
- // Both user message and assistant response should be saved. The assistant
- // reply is persisted synchronously, but the user message is saved
- // fire-and-forget (tokio::spawn in turn/core.rs, #3610), so it may land a
- // moment after `turn()` returns — poll briefly instead of reading once,
- // which otherwise races on a loaded CI runner under llvm-cov instrumentation.
- let mut count = 0;
- for _ in 0..50 {
- count = mem.count().await.unwrap();
- if count >= 2 {
- break;
- }
- tokio::time::sleep(std::time::Duration::from_millis(20)).await;
- }
- assert!(
- count >= 2,
- "Expected at least 2 memory entries, got {count}"
- );
-}
-
-#[tokio::test]
-async fn auto_save_disabled_does_not_store() {
- let (mem, _tmp) = make_retaining_memory();
- let provider = Arc::new(ScriptedProvider::new(vec![text_response("hello")]));
-
- let (mut agent, _tmp2) = build_agent_with_memory(
- provider,
- vec![],
- mem.clone(),
- false, // auto_save disabled
- );
-
- let _ = agent.turn("test message").await.unwrap();
-
- let count = mem.count().await.unwrap();
- assert_eq!(count, 0, "Expected 0 memory entries with auto_save off");
-}
-
// ═══════════════════════════════════════════════════════════════════════════
// 10. Native vs XML dispatcher integration
// ═══════════════════════════════════════════════════════════════════════════