Skip to content

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

docs(harness): add README and reorganise test modules

Steven Enamakel4b6770d73bca
diff --git a/crates/openhuman-core/src/agent/harness/README.md b/crates/openhuman-core/src/agent/harness/README.md
index 48c6bb2e19..b4b81b8a42 100644
--- a/crates/openhuman-core/src/agent/harness/README.md
+++ b/crates/openhuman-core/src/agent/harness/README.md
@@ -48,7 +48,6 @@ used here (not defined here) by `agent_graph.rs` and `fork_context.rs`.
| `tool_result_artifacts/` | Wiring only: `new_tool_result_store` hands `tinyagents_harness::artifacts::tool_results` OpenHuman's redactor (`SanitizingRedactor`), `file_read`/`use_skill` names and `FileReadTool::MAX_FILE_SIZE_BYTES`. The store, `[tool_result_preview]` envelope, budgets and paged reads live in the crate. |
| `memory_context.rs`, `memory_context_safety.rs` | Working-memory and `[Cross-chat context]` lines surfaced into the prompt (capped by `WORKING_MEMORY_LIMIT`); trust-tier wrapping of recalled entries that came from connectors (`wrap_untrusted_for_agent`). The read-index, dedupe, write, update-index enforcement state machine for memory-mutating tools (issue #4116) now lives in `tinyagents_harness::middleware` (`MemoryProtocolTracker`). |
| `required_output.rs` | Pure validate/repair/synthesize primitives (issue #4117) that guarantee a required structured-output block (for example a `thoughts` JSON block) on every accepted turn. The orchestration that calls these lives on the session in `../session_host/turn/`. |
-| `parse_wire_tests.rs` | Test-only fixtures for OpenHuman's own wire vocabulary (`inference::provider::ToolCall`, native-history JSON, OpenAI function-calling payloads). The actual `<tool_call>` parsing (tags, fenced blocks, bare JSON, `<invoke>` XML, GLM grammar, p-format) moved to the vendored `tinytools_agent` crate; nothing about recovering a tool call from model text stayed here. |
| `credentials.rs` | `scrub_credentials`: regex scrubbing of credential-shaped text (key/value secrets, AWS access-key IDs, `sk-...` keys). Applied to every tool result by `CredentialScrubMiddleware` in `agent/tinyagents/middleware/credential_scrub.rs`, installed as the innermost tool wrap so nothing downstream sees the raw secret. |
## Public surface
@@ -112,9 +111,7 @@ turn lifecycle are in `../session_host/`; `run_subagent`,
## Tests
-- Unit: `harness_tests.rs`, `harness_gap_tests.rs`,
- `harness_tool_call_parsing_tests.rs`,
- `harness_tool_call_parsing_edge_case_tests.rs`, plus `*_tests.rs` files
+- Unit: `harness_tool_call_parsing_edge_case_tests.rs`, plus `*_tests.rs` files
beside each sub-module (`tool_result_artifacts/mod_tests.rs`,
`artifact_offload/artifact_offload_tests.rs`,
`archivist/{lifecycle,recap,resummarise}_tests.rs`).
diff --git a/crates/openhuman-core/src/agent/harness/harness_gap_tests.rs b/crates/openhuman-core/src/agent/harness/harness_gap_tests.rs
deleted file mode 100644
index 4f6fc61028..0000000000
--- a/crates/openhuman-core/src/agent/harness/harness_gap_tests.rs
+++ /dev/null
@@ -1,90 +0,0 @@
-//! Gap-filling unit tests for the agent harness.
-//!
-//! These tests cover paths that were missing from the existing `*_tests.rs`
-//! co-located files as identified by a coverage gap analysis:
-//!
-//! 1. Full user→LLM→tool→result→final turn cycle — now covered by the
-//! tinyagents route's tests (`crates/openhuman-core/src/agent/tinyagents/tests.rs`), which
-//! exercise `run_turn_via_tinyagents_shared` end to end.
-//! 2. `MaxIterationsExceeded` downcasts to the typed `AgentError` variant.
-//! 3. `visible_tool_names` whitelist: tools outside the set are treated as unknown.
-//! 4. `ContextGuard` surfaces `ContextExhausted` and aborts the loop.
-//! 5. `parse_tool_calls` fallback formats — covered in `tinytools-agent`'s own
-//! parse tests (`parse/test/regressions.rs`).
-//! 6. `DateTimeSection` produces an ISO-8601-like timestamp with a timezone token.
-//! 7. `parse_tool_timeout_secs` default and boundary cases.
-//! 8. Spawn-depth gate (`SpawnDepthExceeded`) is covered in
-//! `../subagent_host/ops_tests.rs` because it lives at the `run_subagent`
-//! boundary.
-//!
-//! Items that have NO underlying code and therefore cannot be tested:
-//! - Follow-up resolution ("yes"/"no" disambiguation) — not implemented.
-//! - Silence timer (SilenceTimeout, 600 s) — not implemented.
-//! - `<invoke tool=…>` XML attribute form — the parser does not parse attributes;
-//! only the tag body (JSON) is used.
-
-use crate::tools::timeout::parse_tool_timeout_secs;
-
-// ─────────────────────────────────────────────────────────────────────────────
-// Item 1 — Full turn cycle: user → LLM emits tool call → tool executes →
-// result injected → LLM produces final text.
-// ─────────────────────────────────────────────────────────────────────────────
-
-// NOTE: The `ContextGuard`/`ContextCheckResult` tests that used to live here
-// (context_guard_exhausted_after_circuit_breaker_and_95pct_utilization,
-// context_guard_update_usage_raises_window_from_response) were removed during the
-// tinyagents migration: the context reducer shell (`context/guard.rs`) was
-// deleted (commit d55ea9a5d) and the tested API no longer exists.
-
-// ─────────────────────────────────────────────────────────────────────────────
-// Item 5 (tool timeout) — parse_tool_timeout_secs defaults and boundaries.
-// Already covered in tool_timeout/mod.rs but pinned here for the gap report.
-// ─────────────────────────────────────────────────────────────────────────────
-
-#[test]
-fn tool_timeout_parse_default_and_boundaries() {
- // Default when absent.
- assert_eq!(parse_tool_timeout_secs(None), 120);
- // Default when non-numeric.
- assert_eq!(parse_tool_timeout_secs(Some("bad")), 120);
- // Boundary values.
- assert_eq!(parse_tool_timeout_secs(Some("1")), 1);
- assert_eq!(parse_tool_timeout_secs(Some("3600")), 3600);
- // Out of range → default.
- assert_eq!(parse_tool_timeout_secs(Some("0")), 120);
- assert_eq!(parse_tool_timeout_secs(Some("3601")), 120);
-}
-
-// ─────────────────────────────────────────────────────────────────────────────
-// Item 8 — Current-time grounding (#3602). The volatile timestamp now rides the
-// per-turn user message via `current_datetime_line` (so a long-lived
-// session's frozen prompt prefix can't go stale); `DateTimeSection`
-// carries only the static grounding *rule*. Pin both halves.
-// ─────────────────────────────────────────────────────────────────────────────
-
-#[test]
-fn current_datetime_line_matches_iso8601_date_and_utc_offset_pattern() {
- // The per-turn stamp is the one carrying the concrete clock — assert its
- // ISO-8601 date, UTC offset, and IANA zone (or `UTC` fallback).
- let payload = crate::agent::prompts::current_datetime_line();
-
- // Parse the concrete `YYYY-MM-DD HH:MM:SS` prefix rather than counting
- // loose digits, so a malformed layout can't slip through.
- let rest = payload
- .strip_prefix("Current Date & Time: ")
- .expect("stamp must start with the canonical prefix");
- let dt = rest
- .get(0..19)
- .expect("stamp must include YYYY-MM-DD HH:MM:SS");
- chrono::NaiveDateTime::parse_from_str(dt, "%Y-%m-%d %H:%M:%S")
- .expect("timestamp must match YYYY-MM-DD HH:MM:SS");
- assert!(
- payload.contains("UTC"),
- "stamp must contain UTC offset marker: {payload}"
- );
- let has_iana = payload.contains('/') || payload.contains(" UTC ");
- assert!(
- has_iana,
- "stamp must contain an IANA zone (slashed) or UTC fallback: {payload}"
- );
-}
diff --git a/crates/openhuman-core/src/agent/harness/harness_tests.rs b/crates/openhuman-core/src/agent/harness/harness_tests.rs
deleted file mode 100644
index 70ff6c4f31..0000000000
--- a/crates/openhuman-core/src/agent/harness/harness_tests.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-use super::parse_tests::tools_to_openai_format;
-use crate::tools;
-use std::sync::Arc;
-
-fn build_tool_instructions(tools: &[Box<dyn tinytools::Tool>]) -> String {
- let specs = tools.iter().map(|tool| tool.spec()).collect::<Vec<_>>();
- tinytools_agent::dialect::XmlDialect::instructions(&specs)
-}
-
-#[path = "harness_tool_call_parsing_tests.rs"]
-mod harness_tool_call_parsing_tests;
diff --git a/crates/openhuman-core/src/agent/harness/harness_tool_call_parsing_tests.rs b/crates/openhuman-core/src/agent/harness/harness_tool_call_parsing_tests.rs
deleted file mode 100644
index 6b918cca47..0000000000
--- a/crates/openhuman-core/src/agent/harness/harness_tool_call_parsing_tests.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-use super::*;
-
-#[test]
-fn build_tool_instructions_includes_all_tools() {
- use crate::security::SecurityPolicy;
- let security = Arc::new(SecurityPolicy::from_config(
- &crate::config::AutonomyConfig::default(),
- std::path::Path::new("/tmp"),
- std::path::Path::new("/tmp"),
- ));
- let tools = tools::ops::default_tools(security);
- let instructions = build_tool_instructions(&tools);
-
- assert!(instructions.contains("## Tool Use Protocol"));
- assert!(instructions.contains("<tool_call>"));
- assert!(instructions.contains("shell"));
- assert!(instructions.contains("file_read"));
- assert!(instructions.contains("file_write"));
-}
-
-#[test]
-fn tools_to_openai_format_produces_valid_schema() {
- use crate::security::SecurityPolicy;
- let security = Arc::new(SecurityPolicy::from_config(
- &crate::config::AutonomyConfig::default(),
- std::path::Path::new("/tmp"),
- std::path::Path::new("/tmp"),
- ));
- let tools = tools::ops::default_tools(security);
- let formatted = tools_to_openai_format(&tools);
-
- assert!(!formatted.is_empty());
- for tool_json in &formatted {
- assert_eq!(tool_json["type"], "function");
- assert!(tool_json["function"]["name"].is_string());
- assert!(tool_json["function"]["description"].is_string());
- assert!(!tool_json["function"]["name"].as_str().unwrap().is_empty());
- }
- // Verify known tools are present
- let names: Vec<&str> = formatted
- .iter()
- .filter_map(|t| t["function"]["name"].as_str())
- .collect();
- assert!(names.contains(&"shell"));
- assert!(names.contains(&"file_read"));
-}
diff --git a/crates/openhuman-core/src/agent/harness/mod.rs b/crates/openhuman-core/src/agent/harness/mod.rs
index 86ae64b5c8..742dde1728 100644
--- a/crates/openhuman-core/src/agent/harness/mod.rs
+++ b/crates/openhuman-core/src/agent/harness/mod.rs
@@ -52,12 +52,3 @@ pub(crate) use spawn_depth_context::{with_spawn_depth, MAX_SPAWN_DEPTH};
pub use task_recency_context::{current_task_recency_window, with_task_recency_window};
pub(crate) use graph::run_channel_turn_via_graph;
-
-#[cfg(test)]
-mod harness_gap_tests;
-#[cfg(test)]
-#[path = "parse_wire_tests.rs"]
-mod parse_tests;
-#[cfg(test)]
-#[path = "harness_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/agent/harness/parse_tests.rs b/crates/openhuman-core/src/agent/harness/parse_tests.rs
deleted file mode 100644
index f43d467d76..0000000000
--- a/crates/openhuman-core/src/agent/harness/parse_tests.rs
+++ /dev/null
@@ -1,128 +0,0 @@
-//! Tests for the OpenHuman-specific half of tool-call parsing.
-//!
-//! The parser tests moved with the parsers, to
-//! `tinytools_agent`. What is exercised here is the wire
-//! vocabulary that stayed: OpenHuman's `ToolCall`, its native-history JSON
-//! (including the Gemini `thought_signature` round-trip), and its OpenAI
-//! function-calling payload.
-
-use super::*;
-use async_trait::async_trait;
-use tinytools::ToolResult;
-
-struct StubTool(&'static str);
-
-#[async_trait]
-impl Tool for StubTool {
- fn name(&self) -> &str {
- self.0
- }
-
- fn description(&self) -> &str {
- "stub tool"
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- serde_json::json!({
- "type": "object",
- "properties": {
- "value": { "type": "string" }
- }
- })
- }
-
- async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
- Ok(ToolResult::success("ok"))
- }
-}
-#[test]
-fn structured_tool_call_and_history_helpers_round_trip_expected_shapes() {
- let tool_calls = vec![NativeToolCall {
- id: "call-1".into(),
- name: "echo".into(),
- arguments: "{\"value\":\"hello\"}".into(),
- extra_content: None,
- }];
-
- let parsed = parse_structured_tool_calls(&tool_calls);
- assert_eq!(parsed.len(), 1);
- assert_eq!(parsed[0].arguments, serde_json::json!({ "value": "hello" }));
-
- let native = build_native_assistant_history("done", None, &tool_calls);
- let native_json: serde_json::Value = serde_json::from_str(&native).expect("valid json");
- assert_eq!(native_json["content"], "done");
- assert_eq!(native_json["tool_calls"][0]["id"], "call-1");
- // No reasoning supplied -> field omitted entirely (non-reasoning models
- // must not gain a spurious `reasoning_content` key).
- assert!(native_json.get("reasoning_content").is_none());
-
- // DeepSeek thinking mode: reasoning must round-trip onto the tool-call
- // turn (Sentry TAURI-RUST-4KB).
- let native_reasoning =
- build_native_assistant_history("done", Some(" step-by-step thoughts "), &tool_calls);
- let reasoning_json: serde_json::Value =
- serde_json::from_str(&native_reasoning).expect("valid json");
- assert_eq!(reasoning_json["reasoning_content"], "step-by-step thoughts");
- // Whitespace-only reasoning is treated as absent.
- let native_blank = build_native_assistant_history("done", Some(" "), &tool_calls);
- let blank_json: serde_json::Value = serde_json::from_str(&native_blank).expect("valid json");
- assert!(blank_json.get("reasoning_content").is_none());
-
- let xml_history = build_assistant_history_with_tool_calls("", &tool_calls);
- assert!(xml_history.contains("<tool_call>"));
- assert!(xml_history.contains("\"name\":\"echo\""));
-}
-#[test]
-fn build_native_assistant_history_persists_per_call_extra_content() {
- let tool_calls = vec![
- NativeToolCall {
- id: "call-a".into(),
- name: "shell".into(),
- arguments: "{}".into(),
- extra_content: Some(serde_json::json!({"google":{"thought_signature":"SIG_A"}})),
- },
- NativeToolCall {
- id: "call-b".into(),
- name: "read".into(),
- arguments: "{}".into(),
- extra_content: Some(serde_json::json!({"google":{"thought_signature":"SIG_B"}})),
- },
- // A call that never had a signature must NOT gain an empty key.
- NativeToolCall {
- id: "call-c".into(),
- name: "noop".into(),
- arguments: "{}".into(),
- extra_content: None,
- },
- ];
-
- let native = build_native_assistant_history("on it", None, &tool_calls);
- let json: serde_json::Value = serde_json::from_str(&native).expect("valid json");
-
- assert_eq!(
- json.pointer("/tool_calls/0/extra_content/google/thought_signature")
- .and_then(|v| v.as_str()),
- Some("SIG_A"),
- "first parallel call's signature must be persisted"
- );
- assert_eq!(
- json.pointer("/tool_calls/1/extra_content/google/thought_signature")
- .and_then(|v| v.as_str()),
- Some("SIG_B"),
- "second parallel call's signature must be persisted (not just the first)"
- );
- assert!(
- json.pointer("/tool_calls/2/extra_content").is_none(),
- "a call without extra_content must omit the field, keeping non-Gemini history byte-identical"
- );
-}
-#[test]
-fn tools_to_openai_format_uses_tool_metadata() {
- let tools: Vec<Box<dyn Tool>> = vec![Box::new(StubTool("echo")), Box::new(StubTool("shell"))];
- let payload = tools_to_openai_format(&tools);
-
- assert_eq!(payload.len(), 2);
- assert_eq!(payload[0]["type"], "function");
- assert_eq!(payload[0]["function"]["name"], "echo");
- assert_eq!(payload[1]["function"]["description"], "stub tool");
-}
diff --git a/crates/openhuman-core/src/agent/harness/parse_wire_tests.rs b/crates/openhuman-core/src/agent/harness/parse_wire_tests.rs
deleted file mode 100644
index 39c6925745..0000000000
--- a/crates/openhuman-core/src/agent/harness/parse_wire_tests.rs
+++ /dev/null
@@ -1,145 +0,0 @@
-//! Tool-call parsing — OpenHuman's adapter over
-//! [`tinytools_agent`].
-//!
-//! The parsers themselves moved to the crate: `<tool_call>` tags in their
-//! several spellings, fenced blocks, bare JSON, Anthropic-style `<invoke>` XML,
-//! the GLM grammar, and the p-format bodies. Nothing about recovering a tool
-//! call from model text is OpenHuman-specific, so none of it stayed.
-//!
-//! What is left below speaks OpenHuman's own wire vocabulary — its
-//! `NativeToolCall`, its native-history JSON, its OpenAI
-//! function-calling payload. All of it is `#[cfg(test)]`: these are the
-//! fixtures its own tests assert against, and they never compiled into a
-//! production build even before the move.
-
-#[cfg(test)]
-use tinytools::Tool;
-#[cfg(test)]
-use tinytools_agent::dialect::NativeToolCall;
-#[cfg(test)]
-use tinytools_agent::{CallSource, ParsedToolCall};
-
-#[cfg(test)]
-pub(crate) fn parse_structured_tool_calls(tool_calls: &[NativeToolCall]) -> Vec<ParsedToolCall> {
- tool_calls
- .iter()
- .map(|call| ParsedToolCall {
- name: call.name.clone(),
- arguments: serde_json::from_str::<serde_json::Value>(&call.arguments)
- .unwrap_or_else(|_| serde_json::Value::Object(serde_json::Map::new())),
- id: Some(call.id.clone()),
- source: CallSource::Native,
- })
- .collect()
-}
-
-/// Build assistant history entry in JSON format for native tool-call APIs.
-/// `convert_messages` in the OpenRouter provider parses this JSON to reconstruct
-/// the proper `NativeMessage` with structured `tool_calls`.
-///
-/// `reasoning_content` carries the model's thinking output (when the provider
-/// surfaced it). It is persisted so the next request can replay it: DeepSeek's
-/// thinking mode rejects an `assistant` turn that carries `tool_calls` if its
-/// `reasoning_content` is not passed back (Sentry TAURI-RUST-4KB). Omitted from
-/// the JSON when empty, so non-reasoning models are unaffected.
-#[cfg(test)]
-pub(crate) fn build_native_assistant_history(
- text: &str,
- reasoning_content: Option<&str>,
- tool_calls: &[NativeToolCall],
-) -> String {
- let calls_json: Vec<serde_json::Value> = tool_calls
- .iter()
- .map(|tc| {
- let mut call = serde_json::json!({
- "id": tc.id,
- "name": tc.name,
- "arguments": tc.arguments,
- });
- // Persist Gemini's per-call `thought_signature` (TAURI-RUST-4PK /
- // 4PJ) into the stored assistant turn. PR #3553 threaded the
- // signature through the live response→request hop and the
- // stored-history *parser* (`parse_provider_tool_call_from_value`),
- // but this writer — the single sink the agent loop persists every
- // native tool-call turn through (engine/core.rs) — dropped it. On a
- // history reload the rebuilt assistant turn therefore lacked
- // `extra_content`, so the echoed `functionCall` part went out with
- // no `thought_signature` and Gemini 400'd ("Function call is
- // missing a thought_signature in functionCall parts"). Write it
- // per-part so EVERY call in a parallel/multi-call turn round-trips,
- // not just the first; `skip_serializing_if = "Option::is_none"` on
- // `extra_content` keeps the stored JSON byte-identical for every
- // provider that doesn't emit it.
- if let Some(extra) = tc.extra_content.clone() {
- if let Some(obj) = call.as_object_mut() {
- obj.insert("extra_content".to_string(), extra);
- }
- }
- call
- })
- .collect();
-
- let content = if text.trim().is_empty() {
- serde_json::Value::Null
- } else {
- serde_json::Value::String(text.trim().to_string())
- };
-
- let mut entry = serde_json::json!({
- "content": content,
- "tool_calls": calls_json,
- });
-
- if let Some(reasoning) = reasoning_content.map(str::trim).filter(|r| !r.is_empty()) {
- entry["reasoning_content"] = serde_json::Value::String(reasoning.to_string());
- }
-
- entry.to_string()
-}
-
-#[cfg(test)]
-pub(crate) fn build_assistant_history_with_tool_calls(
- text: &str,
- tool_calls: &[NativeToolCall],
-) -> String {
- let mut parts = Vec::new();
-
- if !text.trim().is_empty() {
- parts.push(text.trim().to_string());
- }
-
- for call in tool_calls {
- let arguments = serde_json::from_str::<serde_json::Value>(&call.arguments)
- .unwrap_or_else(|_| serde_json::Value::String(call.arguments.clone()));
- let payload = serde_json::json!({
- "id": call.id,
- "name": call.name,
- "arguments": arguments,
- });
- parts.push(format!("<tool_call>\n{payload}\n</tool_call>"));
- }
-
- parts.join("\n")
-}
-
-/// Convert a tool registry to OpenAI function-calling format for native tool support.
-#[cfg(test)]
-pub(crate) fn tools_to_openai_format(tools_registry: &[Box<dyn Tool>]) -> Vec<serde_json::Value> {
- tools_registry
- .iter()
- .map(|tool| {
- serde_json::json!({
- "type": "function",
- "function": {
- "name": tool.name(),
- "description": tool.description(),
- "parameters": tool.parameters_schema()
- }
- })
- })
- .collect()
-}
-
-#[cfg(test)]
-#[path = "parse_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/tools/timeout/README.md b/crates/openhuman-core/src/tools/timeout/README.md
index 64696b01b0..e4fc3b3808 100644
--- a/crates/openhuman-core/src/tools/timeout/README.md
+++ b/crates/openhuman-core/src/tools/timeout/README.md
@@ -57,7 +57,6 @@ The global timeout governs non-scripting tools only, since a hung network or MCP
- `crates/openhuman-core/src/agent/tools/delegate.rs`: bounds the delegated provider chat call with `tool_execution_timeout_secs`.
- `crates/openhuman-core/src/config/ops/agent.rs`: `apply_agent_settings` calls `set_tool_timeout_secs` after persisting; `get_agent_settings` reports `effective_timeout_secs`/`env_override`.
- `crates/openhuman-core/src/core/runtime/subscribers.rs`: `register_domain_subscribers` seeds the runtime value from config on the always-on core boot path, so channel-less or web-chat-only cores get the configured timeout too (#5027).
-- `crates/openhuman-core/src/agent/harness/harness_gap_tests.rs`: pins `parse_tool_timeout_secs` default and boundary behavior.
## Notes and gotchas