Skip to content

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

chore(tests): consolidate duplicated rpc harness into shared module

Steven Enamakel6f5fe4a8a5d4
diff --git a/tests/in_process/agent_approval_memory_coverage_e2e.rs b/tests/in_process/agent_approval_memory_coverage_e2e.rs
index a18a55c0b7..571aa6fe9f 100644
--- a/tests/in_process/agent_approval_memory_coverage_e2e.rs
+++ b/tests/in_process/agent_approval_memory_coverage_e2e.rs
@@ -20,7 +20,7 @@
//! JSON-RPC router (`build_core_http_router`) and asserted on, so the number the
//! gate reports and the coverage that exists are the same thing.
-use crate::rpc_harness::{error_message, ok, payload};
+use crate::rpc_harness::{error_message, payload};
use crate::env_guard::EnvVarGuard;
use crate::env_guard::env_lock;
use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
diff --git a/tests/in_process/channels_default_channel_e2e.rs b/tests/in_process/channels_default_channel_e2e.rs
index f03efec479..3841884d16 100644
--- a/tests/in_process/channels_default_channel_e2e.rs
+++ b/tests/in_process/channels_default_channel_e2e.rs
@@ -52,13 +52,10 @@
use crate::rpc_harness::{rpc};
use crate::env_guard::EnvVarGuard;
use crate::env_guard::env_lock;
-use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
+use crate::rpc_auth::ensure_rpc_auth;
use std::path::Path;
use std::sync::{Arc, RwLock};
-use std::time::Duration;
-use axum::http::header::AUTHORIZATION;
-use reqwest::StatusCode;
use serde_json::{json, Value};
use tempfile::{tempdir, TempDir};
diff --git a/tests/in_process/config_auth_app_state_connectivity_e2e.rs b/tests/in_process/config_auth_app_state_connectivity_e2e.rs
index 09e1441537..0602e1a657 100644
--- a/tests/in_process/config_auth_app_state_connectivity_e2e.rs
+++ b/tests/in_process/config_auth_app_state_connectivity_e2e.rs
@@ -3,7 +3,7 @@
use crate::rpc_harness::{ok, payload, rpc, schema};
use crate::env_guard::{env_lock, EnvVarGuard};
-use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
+use crate::rpc_auth::ensure_rpc_auth;
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::sync::{
@@ -16,7 +16,6 @@ use axum::extract::{Path as AxumPath, State};
use axum::http::{header::AUTHORIZATION, HeaderMap};
use axum::routing::{delete, get, post};
use axum::{Json, Router};
-use reqwest::StatusCode;
use serde_json::{json, Value};
use tempfile::{tempdir, TempDir};
diff --git a/tests/in_process/domain_modules_e2e.rs b/tests/in_process/domain_modules_e2e.rs
index b0ffb48ac5..87e2fc7481 100644
--- a/tests/in_process/domain_modules_e2e.rs
+++ b/tests/in_process/domain_modules_e2e.rs
@@ -5,35 +5,15 @@
//! exercises cheap read/status handlers through HTTP. Mutating or networked
//! domain behavior remains covered by the focused `*_e2e.rs` suites.
+use crate::rpc_harness::{serve_rpc};
use crate::rpc_harness::{ok, payload, rpc, schema, write_min_config};
use crate::env_guard::EnvVarGuard;
use crate::env_guard::env_lock;
use crate::memory_module;
-use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
-use std::net::SocketAddr;
-use std::path::Path;
-use std::time::Duration;
-use axum::http::header::AUTHORIZATION;
-use reqwest::StatusCode;
use serde_json::{json, Value};
use tempfile::{tempdir, TempDir};
-use openhuman_rpc::server::build_core_http_router;
-
-async fn serve_rpc() -> (
- SocketAddr,
- tokio::task::JoinHandle<Result<(), std::io::Error>>,
-) {
- ensure_rpc_auth();
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
- .await
- .expect("bind rpc listener");
- let addr = listener.local_addr().expect("rpc listener addr");
- let router = build_core_http_router(false);
- let join = tokio::spawn(async move { axum::serve(listener, router).await });
- (addr, join)
-}
struct TestHarness {
_tmp: TempDir,
diff --git a/tests/in_process/memory_graph_roundtrip_e2e.rs b/tests/in_process/memory_graph_roundtrip_e2e.rs
index 4eeec44408..536c952ec7 100644
--- a/tests/in_process/memory_graph_roundtrip_e2e.rs
+++ b/tests/in_process/memory_graph_roundtrip_e2e.rs
@@ -76,13 +76,10 @@
use crate::rpc_harness::{ok, rpc};
use crate::env_guard::EnvVarGuard;
use crate::env_guard::env_lock;
-use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
+use crate::rpc_auth::ensure_rpc_auth;
use std::path::Path;
use std::sync::{Arc, OnceLock};
-use std::time::Duration;
-use axum::http::header::AUTHORIZATION;
-use reqwest::StatusCode;
use serde_json::{json, Value};
use tempfile::{tempdir, TempDir};
diff --git a/tests/in_process/worker_b_domain_e2e.rs b/tests/in_process/worker_b_domain_e2e.rs
index 302fc92fc5..851087e6ea 100644
--- a/tests/in_process/worker_b_domain_e2e.rs
+++ b/tests/in_process/worker_b_domain_e2e.rs
@@ -5,34 +5,14 @@
//! deterministic controller paths. External-service paths are asserted at
//! validation/config boundaries so the suite stays hermetic.
+use crate::rpc_harness::{serve_rpc};
use crate::rpc_harness::{ok, payload, rpc, schema, write_min_config};
use crate::env_guard::EnvVarGuard;
use crate::env_guard::env_lock;
-use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
-use std::net::SocketAddr;
-use std::path::Path;
-use std::time::Duration;
-use axum::http::header::AUTHORIZATION;
-use reqwest::StatusCode;
use serde_json::{json, Value};
use tempfile::{tempdir, TempDir};
-use openhuman_rpc::server::build_core_http_router;
-
-async fn serve_rpc() -> (
- SocketAddr,
- tokio::task::JoinHandle<Result<(), std::io::Error>>,
-) {
- ensure_rpc_auth();
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
- .await
- .expect("bind rpc listener");
- let addr = listener.local_addr().expect("rpc listener addr");
- let router = build_core_http_router(false);
- let join = tokio::spawn(async move { axum::serve(listener, router).await });
- (addr, join)
-}
struct TestHarness {
_tmp: TempDir,
diff --git a/tests/in_process/worker_c_modules_e2e.rs b/tests/in_process/worker_c_modules_e2e.rs
index 977fa031e6..c5e4a1759d 100644
--- a/tests/in_process/worker_c_modules_e2e.rs
+++ b/tests/in_process/worker_c_modules_e2e.rs
@@ -7,16 +7,14 @@
use crate::rpc_harness::{ok, rpc};
use crate::env_guard::EnvVarGuard;
use crate::env_guard::env_lock;
-use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
+use crate::rpc_auth::ensure_rpc_auth;
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
-use std::time::Duration;
use axum::extract::State;
-use axum::http::header::{AUTHORIZATION, CONTENT_TYPE};
+use axum::http::header::CONTENT_TYPE;
use axum::{response::Html, routing::get, Json, Router};
-use reqwest::StatusCode;
use serde_json::{json, Value};
use tempfile::{tempdir, TempDir};
diff --git a/tests/in_process_all.rs b/tests/in_process_all.rs
index 5ee30d12c4..baf4285558 100644
--- a/tests/in_process_all.rs
+++ b/tests/in_process_all.rs
@@ -33,6 +33,8 @@ pub mod memory_module;
pub mod noop_memory;
#[path = "support/rpc_auth.rs"]
pub mod rpc_auth;
+#[path = "support/rpc_harness.rs"]
+pub mod rpc_harness;
#[path = "support/tinyhumans_boot.rs"]
pub mod tinyhumans_boot;
diff --git a/tests/raw_coverage/inference_provider_auth_e2e.rs b/tests/raw_coverage/inference_provider_auth_e2e.rs
index 78b26a2350..c19a447113 100644
--- a/tests/raw_coverage/inference_provider_auth_e2e.rs
+++ b/tests/raw_coverage/inference_provider_auth_e2e.rs
@@ -27,7 +27,7 @@
//! Env is process-global and every aggregated suite shares one process, so
//! each case takes the **crate-wide** [`env_lock`] for its whole body.
-use crate::rpc_harness::{ok, payload};
+use crate::rpc_harness::payload;
use crate::env_guard::EnvVarGuard;
use std::net::SocketAddr;
use std::path::Path;
diff --git a/tests/raw_coverage/inference_provider_raw_coverage_e2e.rs b/tests/raw_coverage/inference_provider_raw_coverage_e2e.rs
index 33beafc86d..dc140133ff 100644
--- a/tests/raw_coverage/inference_provider_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/inference_provider_raw_coverage_e2e.rs
@@ -28,7 +28,6 @@ use openhuman_core::inference::provider::factory::{
auth_key_for_slug, create_chat_model_from_string_with_model_id, provider_for_role,
};
use openhuman_core::inference::provider::list_configured_models;
-use tinyinference_core::sanitize::sanitize_api_error;
#[derive(Clone, Default)]
struct MockState {
diff --git a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
index c02d6426e7..13fed63bcf 100644
--- a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
@@ -5,7 +5,7 @@
//! direct public API calls cover persistence/redaction/provider branches that
//! are otherwise only indirectly reachable from the controllers.
-use crate::rpc_harness::{error_message, ok, payload};
+use crate::rpc_harness::{error_message, payload};
use crate::env_guard::EnvVarGuard;
use std::path::Path;
use std::sync::{Arc, Mutex, OnceLock};
diff --git a/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rs b/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rs
index d0271a961f..59894ad8f6 100644
--- a/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rs
@@ -5,7 +5,6 @@
//! no real network, keychain, or backend session is required.
use crate::env_guard::EnvVarGuard;
-use std::path::Path;
use std::sync::{Arc, Mutex, OnceLock};
use axum::body::to_bytes;
diff --git a/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rs b/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rs
index 5cd97ac609..68390c5123 100644
--- a/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rs
@@ -3,7 +3,6 @@
use crate::env_guard::EnvVarGuard;
use std::collections::HashMap;
-use std::path::Path;
use std::sync::{Arc, Mutex, OnceLock};
use axum::body::to_bytes;
diff --git a/tests/raw_coverage_all.rs b/tests/raw_coverage_all.rs
index fdb95badcd..b913e9168e 100644
--- a/tests/raw_coverage_all.rs
+++ b/tests/raw_coverage_all.rs
@@ -15,7 +15,7 @@
// binary can read as dead once every file shares one crate root here (e.g. a
// helper only reached by a `#[cfg]`-gated test). These are coverage suites, not
// production code, so silence the noise rather than churn 76 files.
-#![allow(dead_code, unused_imports)]
+#![allow(dead_code)]
use std::sync::{Mutex, OnceLock};
@@ -53,5 +53,10 @@ pub mod tinyhumans_boot;
/// lock: suites hold [`SHARED_ENV_LOCK`] through their own `env_lock()`.
#[path = "support/env_guard.rs"]
pub mod env_guard;
+/// The RPC bearer and JSON-RPC helpers some suites share (see `support/`).
+#[path = "support/rpc_auth.rs"]
+pub mod rpc_auth;
+#[path = "support/rpc_harness.rs"]
+pub mod rpc_harness;
include!(concat!(env!("OUT_DIR"), "/raw_coverage_mods.rs"));