Skip to content

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

test(mcp): use shared test module port helper

Steven Enamakel3f8b1d01b2e0
diff --git a/crates/openhuman-core/src/mcp/audit/schemas_tests.rs b/crates/openhuman-core/src/mcp/audit/schemas_tests.rs
index 09009ef23e..6fe7b1386e 100644
--- a/crates/openhuman-core/src/mcp/audit/schemas_tests.rs
+++ b/crates/openhuman-core/src/mcp/audit/schemas_tests.rs
@@ -34,13 +34,7 @@ async fn handle_list_returns_persisted_audit_records() {
let config = config_rpc::load_config_with_timeout()
.await
.expect("config");
- let backend = crate::storage::test_support::sqlite_backend().expect("test storage");
- let _storage = crate::storage::test_support::install_backend_for_test(std::sync::Arc::clone(
- &backend.backend,
- ));
- crate::modules::ops::ensure_loaded(&config, "tinymcp")
- .await
- .expect("load the staged TinyMCP test module");
+ crate::mcp::test_module_port::install(&config);
crate::mcp::audit::record_write(
&config,
crate::mcp::audit::NewMcpWriteRecord {
diff --git a/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs b/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs
index 5b93a953be..16d5eb7d0f 100644
--- a/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs
+++ b/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs
@@ -10,16 +10,16 @@ async fn call_tool_records_write_argument_rejection() {
let config = config_rpc::load_config_with_timeout()
.await
.expect("config");
- let backend = crate::storage::test_support::sqlite_backend().expect("test storage");
- let _storage = crate::storage::test_support::install_backend_for_test(std::sync::Arc::clone(
- &backend.backend,
- ));
- crate::modules::ops::ensure_loaded(&config, "tinymcp")
- .await
- .expect("load the staged TinyMCP test module");
+ crate::mcp::test_module_port::install(&config);
+ let ctx = crate::core::runtime::DispatchCtx::new(
+ crate::core::runtime::CoreContext::for_test_with_config(
+ crate::core::runtime::DomainSet::full(),
+ config.clone(),
+ ),
+ );
let err = call_tool(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ctx,
"memory.learn",
json!({ "kind": "fact" }),
"mcp:test",
@@ -91,15 +91,15 @@ async fn call_tool_validates_memory_arguments_before_dispatch() {
let config = config_rpc::load_config_with_timeout()
.await
.expect("config");
- let backend = crate::storage::test_support::sqlite_backend().expect("test storage");
- let _storage = crate::storage::test_support::install_backend_for_test(std::sync::Arc::clone(
- &backend.backend,
- ));
- crate::modules::ops::ensure_loaded(&config, "tinymcp")
- .await
- .expect("load the staged TinyMCP test module");
+ crate::mcp::test_module_port::install(&config);
+ let ctx = crate::core::runtime::DispatchCtx::new(
+ crate::core::runtime::CoreContext::for_test_with_config(
+ crate::core::runtime::DomainSet::full(),
+ config.clone(),
+ ),
+ );
let err = call_tool(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ctx,
"memory.forget",
json!({ "ids": [] }),
"mcp:test",
@@ -108,7 +108,7 @@ async fn call_tool_validates_memory_arguments_before_dispatch() {
.expect_err("empty ids rejected before any RPC");
assert!(err.message().contains("`ids`"), "got: {}", err.message());
let err = call_tool(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ctx,
"memory.recall",
json!({ "question": "q", "filter": { "x": 1 } }),
"mcp:test",
@@ -140,13 +140,8 @@ async fn call_tool_judges_the_policy_of_the_explicit_context_across_scopes() {
let mut allowing = crate::config::Config::default();
allowing.workspace_dir = tmp_allow.path().to_path_buf();
allowing.action_dir = tmp_allow.path().to_path_buf();
- let backend = crate::storage::test_support::sqlite_backend().expect("test storage");
- let _storage = crate::storage::test_support::install_backend_for_test(std::sync::Arc::clone(
- &backend.backend,
- ));
- crate::modules::ops::ensure_loaded(&allowing, "tinymcp")
- .await
- .expect("load the staged TinyMCP test module");
+ crate::mcp::test_module_port::install(&denying);
+ crate::mcp::test_module_port::install(&allowing);
let deny_core = CoreContext::for_test_with_config(DomainSet::full(), denying);
let allow_core = CoreContext::for_test_with_config(DomainSet::full(), allowing);
diff --git a/crates/openhuman-core/src/mcp/server/write_dispatch_tests.rs b/crates/openhuman-core/src/mcp/server/write_dispatch_tests.rs
index ae72ac8352..c2364480be 100644
--- a/crates/openhuman-core/src/mcp/server/write_dispatch_tests.rs
+++ b/crates/openhuman-core/src/mcp/server/write_dispatch_tests.rs
@@ -59,14 +59,7 @@ async fn audit_write_rejection_records_failure_row() {
let mut config = Config::default();
config.workspace_dir = tmp.path().join("workspace");
std::fs::create_dir_all(&config.workspace_dir).unwrap();
- config.modules.source = crate::config::schema::ModuleSourceMode::Source;
- let backend = crate::storage::test_support::sqlite_backend().expect("test storage");
- let _storage = crate::storage::test_support::install_backend_for_test(std::sync::Arc::clone(
- &backend.backend,
- ));
- crate::modules::ops::ensure_loaded(&config, "tinymcp")
- .await
- .expect("load the staged TinyMCP test module");
+ crate::mcp::test_module_port::install(&config);
let err = ToolCallError::InvalidParams("bad write request".into());
audit_write_rejection(
@@ -167,14 +160,7 @@ async fn test_dispatch_write_tool_rpc_error_records_audit_and_returns_tool_error
let mut config = Config::default();
config.workspace_dir = tmp.path().join("workspace");
std::fs::create_dir_all(&config.workspace_dir).unwrap();
- config.modules.source = crate::config::schema::ModuleSourceMode::Source;
- let backend = crate::storage::test_support::sqlite_backend().expect("test storage");
- let _storage = crate::storage::test_support::install_backend_for_test(std::sync::Arc::clone(
- &backend.backend,
- ));
- crate::modules::ops::ensure_loaded(&config, "tinymcp")
- .await
- .expect("load the staged TinyMCP test module");
+ crate::mcp::test_module_port::install(&config);
// Omit the required `text` so the handler (or the missing registration)
// yields a failure instead of a stored item.
@@ -223,14 +209,7 @@ async fn test_audit_write_success_path() {
let mut config = Config::default();
config.workspace_dir = tmp.path().join("workspace");
std::fs::create_dir_all(&config.workspace_dir).unwrap();
- config.modules.source = crate::config::schema::ModuleSourceMode::Source;
- let backend = crate::storage::test_support::sqlite_backend().expect("test storage");
- let _storage = crate::storage::test_support::install_backend_for_test(std::sync::Arc::clone(
- &backend.backend,
- ));
- crate::modules::ops::ensure_loaded(&config, "tinymcp")
- .await
- .expect("load the staged TinyMCP test module");
+ crate::mcp::test_module_port::install(&config);
audit_write(
&config,