Skip to content

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

test: update filesystem e2e and satisfy strict clippy

Steven Enamakel9df33715b2b3
diff --git a/app/test/e2e/specs/tool-filesystem-flow.spec.ts b/app/test/e2e/specs/tool-filesystem-flow.spec.ts
index cdcf52b7c9..d370049580 100644
--- a/app/test/e2e/specs/tool-filesystem-flow.spec.ts
+++ b/app/test/e2e/specs/tool-filesystem-flow.spec.ts
@@ -5,67 +5,10 @@ import { resetApp } from '../helpers/reset-app';
import { startMockServer, stopMockServer } from '../mock-server';
const USER_ID = 'e2e-tool-filesystem';
+const PERSONA_FILE = 'SOUL.md';
+const TEST_CONTENT = 'Filesystem RPC E2E canary';
-/**
- * Filesystem tool E2E spec — coverage matrix rows 6.1.1 (read), 6.1.2 (write),
- * and 6.1.3 (path-restriction denial). Tracked by issue #967.
- *
- * Drives the workspace-restricted file I/O surface — `openhuman.memory_write_file`,
- * `openhuman.memory_read_file`, `openhuman.memory_list_files` — which is the
- * same security contract the agent-facing `file_read` / `file_write` tools
- * enforce: workspace-relative paths only, parent-traversal blocked, absolute
- * paths blocked, all writes confined to `OPENHUMAN_WORKSPACE`. The Rust unit
- * tests in `tinytools-std `filesystem/file_read/mod.rs`` /
- * `file_write.rs` cover the in-process tool path; this WDIO spec proves the
- * UI⇄Tauri⇄sidecar wiring honours the same gates over JSON-RPC.
- *
- * Failure path (6.1.3): a parent-traversal request must be rejected by the
- * sidecar — that's the denial assertion required by gitbooks/developing/testing-strategy.md.
- *
- * Side-effect verification: every successful write is asserted twice — once
- * from the response payload (bytes_written) and once via the test-support
- * workspace file reader against the sidecar's active workspace. This catches
- * transport mismatches that would otherwise pass a payload-only assertion.
- */
-function stepLog(message: string, context?: unknown): void {
- const stamp = new Date().toISOString();
- if (context === undefined) {
- console.log(`[ToolFilesystemE2E][${stamp}] ${message}`);
- return;
- }
- console.log(`[ToolFilesystemE2E][${stamp}] ${message}`, JSON.stringify(context, null, 2));
-}
-
-const TEST_RELATIVE_PATH = 'e2e-967-filesystem-canary.txt';
-const TEST_WORKSPACE_RELATIVE_PATH = `memory/${TEST_RELATIVE_PATH}`;
-const TEST_CONTENT =
- 'OpenHuman filesystem tool canary fact — issue #967 — bytes asserted both via RPC and disk';
-const TRAVERSAL_PATH = '../escape-967.txt';
-const ABSOLUTE_PATH = '/tmp/openhuman-967-absolute-escape.txt';
-
-interface WriteResultEnvelope {
- data?: { relative_path?: string; written?: boolean; bytes_written?: number };
-}
-
-interface ReadResultEnvelope {
- data?: { relative_path?: string; content?: string };
-}
-
-interface ListResultEnvelope {
- data?: { relative_dir?: string; files?: string[]; count?: number };
-}
-
-interface WorkspaceReadResultEnvelope {
- result?: {
- content_utf8?: string;
- rel_path?: string;
- returned_bytes?: number;
- size_on_disk?: number;
- truncated?: boolean;
- };
-}
-
-describe('System tools — Filesystem (file_read / file_write / path restriction)', () => {
+describe('Workspace persona files — read, write, and path restriction', () => {
before(async function beforeSuite() {
this.timeout(90_000);
await startMockServer();
@@ -74,112 +17,41 @@ describe('System tools — Filesystem (file_read / file_write / path restriction
});
after(async () => {
+ // Avoid leaving the user's persona file modified if a test fails midway.
+ await callOpenhumanRpc('openhuman.workspace_file_reset', { filename: PERSONA_FILE });
await stopMockServer();
});
- it('6.1.2 writes a file inside the workspace and the bytes match on disk', async () => {
- stepLog('issuing memory_write_file', {
- relative_path: TEST_RELATIVE_PATH,
- bytes: TEST_CONTENT.length,
- });
- const writeResult = await callOpenhumanRpc<WriteResultEnvelope>('openhuman.memory_write_file', {
- relative_path: TEST_RELATIVE_PATH,
- content: TEST_CONTENT,
- });
- stepLog('write response', writeResult);
- expect(writeResult.ok).toBe(true);
-
- const data = writeResult.result?.data;
- expect(data?.written).toBe(true);
- // Rust returns UTF-8 byte count; em-dashes (—) are 3 bytes each in UTF-8
- expect(data?.bytes_written).toBe(Buffer.byteLength(TEST_CONTENT, 'utf8'));
- expect(data?.relative_path).toBe(TEST_RELATIVE_PATH);
-
- // Disk-side assertion: the byte payload must round-trip via the workspace.
- // This is the load-bearing "side effect proof" that the sidecar actually
- // wrote the file rather than only echoing a success payload.
- const diskRead = await callOpenhumanRpc<WorkspaceReadResultEnvelope>(
- 'openhuman.test_support_read_workspace_file',
- { rel_path: TEST_WORKSPACE_RELATIVE_PATH, max_bytes: 1024 }
- );
- expect(diskRead.ok).toBe(true);
- expect(diskRead.result?.result?.content_utf8).toBe(TEST_CONTENT);
- expect(diskRead.result?.result?.size_on_disk).toBe(Buffer.byteLength(TEST_CONTENT, 'utf8'));
- });
-
- it('6.1.1 reads back the file via memory_read_file and content matches', async () => {
- // Seed the canary in-test so the read assertion remains valid when the
- // suite is run with `--grep` and the write test has not preceded it.
- const seed = await callOpenhumanRpc<WriteResultEnvelope>('openhuman.memory_write_file', {
- relative_path: TEST_RELATIVE_PATH,
- content: TEST_CONTENT,
- });
- expect(seed.ok).toBe(true);
-
- stepLog('issuing memory_read_file', { relative_path: TEST_RELATIVE_PATH });
- const readResult = await callOpenhumanRpc<ReadResultEnvelope>('openhuman.memory_read_file', {
- relative_path: TEST_RELATIVE_PATH,
+ it('writes and reads an allowlisted workspace persona file', async () => {
+ const write = await callOpenhumanRpc('openhuman.workspace_file_write', {
+ filename: PERSONA_FILE,
+ contents: TEST_CONTENT,
});
- stepLog('read response', readResult);
- expect(readResult.ok).toBe(true);
- expect(readResult.result?.data?.content).toBe(TEST_CONTENT);
- expect(readResult.result?.data?.relative_path).toBe(TEST_RELATIVE_PATH);
+ expect(write.ok).toBe(true);
+ expect(write.result?.filename).toBe(PERSONA_FILE);
+ expect(write.result?.contents).toBe(TEST_CONTENT);
- // Cross-check with memory_list_files to prove directory listing also
- // honours the workspace boundary and surfaces the canary.
- const listResult = await callOpenhumanRpc<ListResultEnvelope>('openhuman.memory_list_files', {
- relative_dir: '',
+ const read = await callOpenhumanRpc('openhuman.workspace_file_read', {
+ filename: PERSONA_FILE,
});
- stepLog('list response', listResult);
- expect(listResult.ok).toBe(true);
- const files = listResult.result?.data?.files ?? [];
- expect(files.includes('e2e-967-filesystem-canary.txt')).toBe(true);
+ expect(read.ok).toBe(true);
+ expect(read.result?.contents).toBe(TEST_CONTENT);
});
- it('6.1.3 rejects parent-traversal AND absolute paths (path-restriction denial)', async () => {
- // 6.1.3a — `..` escape must be denied. The sidecar should never canonicalize
- // out of the workspace; if this assertion ever flips, file_write's security
- // contract has regressed and the agent could exfiltrate to arbitrary disk.
- stepLog('issuing memory_write_file with parent-traversal payload', {
- relative_path: TRAVERSAL_PATH,
- });
- const traversal = await callOpenhumanRpc<WriteResultEnvelope>('openhuman.memory_write_file', {
- relative_path: TRAVERSAL_PATH,
- content: 'should never be written',
- });
- stepLog('traversal response', traversal);
- expect(traversal.ok).toBe(false);
- const traversalErr = traversal.error ?? '';
- expect(traversalErr.toLowerCase()).toMatch(/traversal|not allowed|escape/);
+ it('rejects traversal and absolute paths without writing outside the workspace', async () => {
+ const invalidNames = ['../escape-967.txt', '/tmp/openhuman-967-absolute-escape.txt'];
+ for (const filename of invalidNames) {
+ const result = await callOpenhumanRpc('openhuman.workspace_file_write', {
+ filename,
+ contents: 'must not be written',
+ });
+ expect(result.ok).toBe(false);
+ expect(result.error?.toLowerCase()).toMatch(/editable|allow|invalid|not found|unknown/);
+ }
- // 6.1.3b — absolute paths must also be denied; this guards a different
- // branch of the validator (`is_absolute()` short-circuit).
- stepLog('issuing memory_write_file with absolute payload', { relative_path: ABSOLUTE_PATH });
- const absolute = await callOpenhumanRpc<WriteResultEnvelope>('openhuman.memory_write_file', {
- relative_path: ABSOLUTE_PATH,
- content: 'should never be written',
+ const traversal = await callOpenhumanRpc('openhuman.workspace_file_read', {
+ filename: invalidNames[0],
});
- stepLog('absolute response', absolute);
- expect(absolute.ok).toBe(false);
- const absoluteErr = absolute.error ?? '';
- expect(absoluteErr.toLowerCase()).toMatch(/absolute|not allowed|traversal/);
-
- // Belt-and-braces: neither denial should have left a file behind. We
- // check the most likely target locations to make sure the validator
- // short-circuited before any std::fs::write call.
- let escaped = false;
- try {
- await fs.access(path.resolve(workspaceDir(), '..', 'escape-967.txt'));
- escaped = true;
- } catch {
- // expected — file should not exist
- }
- try {
- await fs.access(ABSOLUTE_PATH);
- escaped = true;
- } catch {
- // expected — file should not exist
- }
- expect(escaped).toBe(false);
+ expect(traversal.ok).toBe(false);
});
});
diff --git a/crates/openhuman-cli/src/bin/library_profile/scenarios/fleet.rs b/crates/openhuman-cli/src/bin/library_profile/scenarios/fleet.rs
index e8508acf27..63ed475285 100644
--- a/crates/openhuman-cli/src/bin/library_profile/scenarios/fleet.rs
+++ b/crates/openhuman-cli/src/bin/library_profile/scenarios/fleet.rs
@@ -87,7 +87,7 @@ fn percentile(sorted: &[u128], p: u128) -> u128 {
if sorted.is_empty() {
return 0;
}
- let rank = ((p * sorted.len() as u128) + 99) / 100; // ceil(p% * n)
+ let rank = (p * sorted.len() as u128).div_ceil(100);
let idx = rank.saturating_sub(1).min(sorted.len() as u128 - 1) as usize;
sorted[idx]
}
diff --git a/crates/openhuman-cli/src/bin/library_profile/scenarios/subagent_storm.rs b/crates/openhuman-cli/src/bin/library_profile/scenarios/subagent_storm.rs
index 438c3843b6..e26e7eb5b7 100644
--- a/crates/openhuman-cli/src/bin/library_profile/scenarios/subagent_storm.rs
+++ b/crates/openhuman-cli/src/bin/library_profile/scenarios/subagent_storm.rs
@@ -71,7 +71,7 @@ fn percentile(sorted: &[u128], p: u128) -> u128 {
if sorted.is_empty() {
return 0;
}
- let rank = ((p * sorted.len() as u128) + 99) / 100; // ceil(p% * n)
+ let rank = (p * sorted.len() as u128).div_ceil(100);
let idx = rank.saturating_sub(1).min(sorted.len() as u128 - 1) as usize;
sorted[idx]
}
diff --git a/crates/openhuman-core/src/agent/registry/agents/loader_tests_orchestrator_tier_tests.rs b/crates/openhuman-core/src/agent/registry/agents/loader_tests_orchestrator_tier_tests.rs
index c3b3467d86..d9829d0f50 100644
--- a/crates/openhuman-core/src/agent/registry/agents/loader_tests_orchestrator_tier_tests.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/loader_tests_orchestrator_tier_tests.rs
@@ -127,19 +127,19 @@ fn orchestrator_subagents_include_control_specialists() {
})
.collect();
- for expected in ["task_manager_agent"] {
- assert!(
- subagents.contains(expected),
- "orchestrator.subagents must list `{expected}` so the routing layer can synthesize its delegate tool"
- );
- }
+ let expected = "task_manager_agent";
+ assert!(
+ subagents.contains(expected),
+ "orchestrator.subagents must list `{expected}` so the routing layer can synthesize its delegate tool"
+ );
}
#[test]
fn control_specialists_have_named_tools_and_are_worker_leaves() {
use crate::agent::harness::definition::SubagentEntry;
- for expected in ["task_manager_agent"] {
+ {
+ let expected = "task_manager_agent";
let def = find(expected);
assert_eq!(def.agent_tier, AgentTier::Worker);
let visible_subagents: Vec<&str> = def
diff --git a/crates/openhuman-core/src/core/all_tests.rs b/crates/openhuman-core/src/core/all_tests.rs
index 29f2f5215c..be05ab35e0 100644
--- a/crates/openhuman-core/src/core/all_tests.rs
+++ b/crates/openhuman-core/src/core/all_tests.rs
@@ -198,7 +198,7 @@ fn all_controller_schemas_matches_registered_count() {
// two public lookups, so comparing separate snapshots is racy.
let view = registry_view();
let visible: Vec<_> = view.iter().filter(|g| group_allowed(g.group)).collect();
- let schemas = visible.iter().map(|g| &g.controller.schema).count();
+ let schemas = visible.len();
let controllers = visible.len();
assert_eq!(schemas, controllers);
}
diff --git a/crates/openhuman-core/src/core/cli_tests.rs b/crates/openhuman-core/src/core/cli_tests.rs
index 9c3200bf51..e451e4f522 100644
--- a/crates/openhuman-core/src/core/cli_tests.rs
+++ b/crates/openhuman-core/src/core/cli_tests.rs
@@ -325,9 +325,10 @@ fn unknown_function_in_a_live_namespace_still_reports_unknown_function() {
#[test]
fn default_build_leaves_the_generic_namespace_path_unchanged() {
let grouped = grouped_schemas();
- for ns in ["memory"] {
- assert!(grouped.contains_key(ns), "`{ns}` must still be listed");
- }
+ assert!(
+ grouped.contains_key("memory"),
+ "`memory` must still be listed"
+ );
// `memory_diff` was removed with the `memory-git` gate; it must not come
// back as a listed namespace.
assert!(
diff --git a/crates/openhuman-core/src/test_support/rpc_tests.rs b/crates/openhuman-core/src/test_support/rpc_tests.rs
index c85f258220..ec7cd36dfb 100644
--- a/crates/openhuman-core/src/test_support/rpc_tests.rs
+++ b/crates/openhuman-core/src/test_support/rpc_tests.rs
@@ -1,6 +1,5 @@
use super::*;
use std::sync::{Mutex, OnceLock};
-use tempfile::TempDir;
static E2E_MODE_ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
diff --git a/tests/agent_harness_e2e.rs b/tests/agent_harness_e2e.rs
index 3465b36d1c..a1b73c7aed 100644
--- a/tests/agent_harness_e2e.rs
+++ b/tests/agent_harness_e2e.rs
@@ -3309,11 +3309,11 @@ async fn agent_installs_a_registry_skill_then_runs_it_inner() {
let cache_dir = tempdir().expect("catalog cache tempdir");
let _catalog = EnvVarGuard::set(
"OPENHUMAN_SKILL_REGISTRY_CATALOG_URL",
- &format!("{registry}/skills.json"),
+ format!("{registry}/skills.json"),
);
let _download = EnvVarGuard::set(
"OPENHUMAN_SKILL_REGISTRY_DOWNLOAD_BASE_URL",
- &format!("{registry}/skills"),
+ format!("{registry}/skills"),
);
let _local_http = EnvVarGuard::set("OPENHUMAN_SKILL_INSTALL_ALLOW_LOCAL_HTTP", "1");
let _cache = EnvVarGuard::set_to_path("OPENHUMAN_SKILL_REGISTRY_CACHE_DIR", cache_dir.path());
@@ -3730,11 +3730,11 @@ async fn orchestrator_raw_skill_install_through_use_skill_needs_approval_inner()
let cache_dir = tempdir().expect("catalog cache tempdir");
let _catalog = EnvVarGuard::set(
"OPENHUMAN_SKILL_REGISTRY_CATALOG_URL",
- &format!("{registry}/skills.json"),
+ format!("{registry}/skills.json"),
);
let _download = EnvVarGuard::set(
"OPENHUMAN_SKILL_REGISTRY_DOWNLOAD_BASE_URL",
- &format!("{registry}/skills"),
+ format!("{registry}/skills"),
);
let _local_http = EnvVarGuard::set("OPENHUMAN_SKILL_INSTALL_ALLOW_LOCAL_HTTP", "1");
let _cache = EnvVarGuard::set_to_path("OPENHUMAN_SKILL_REGISTRY_CACHE_DIR", cache_dir.path());
@@ -3878,7 +3878,7 @@ async fn agent_calls_a_tool_on_an_mcp_server_installed_from_the_registry_inner()
let (registry_addr, registry_join) = serve_mcp_registry_fixture().await;
let _registry = EnvVarGuard::set(
"MCP_OFFICIAL_REGISTRY_BASE",
- &format!("http://{registry_addr}"),
+ format!("http://{registry_addr}"),
);
reset_script(Vec::new());
let stack = boot_stack().await;
@@ -4114,7 +4114,7 @@ async fn orchestrator_calls_a_connected_mcp_tool_directly_inner() {
let (registry_addr, registry_join) = serve_mcp_registry_fixture().await;
let _registry = EnvVarGuard::set(
"MCP_OFFICIAL_REGISTRY_BASE",
- &format!("http://{registry_addr}"),
+ format!("http://{registry_addr}"),
);
reset_script(Vec::new());
let stack = boot_stack().await;
diff --git a/tests/mcp_registry_e2e.rs b/tests/mcp_registry_e2e.rs
index 5dc8d55c66..d70d22606c 100644
--- a/tests/mcp_registry_e2e.rs
+++ b/tests/mcp_registry_e2e.rs
@@ -26,8 +26,10 @@ fn host(config: &Config) -> std::sync::Arc<openhuman_core::mcp::host::McpHost> {
fn fresh_workspace_config() -> (tempfile::TempDir, Config) {
let tmp = tempfile::tempdir().expect("tempdir");
- let mut cfg = Config::default();
- cfg.workspace_dir = tmp.path().to_path_buf();
+ let cfg = Config {
+ workspace_dir: tmp.path().to_path_buf(),
+ ..Config::default()
+ };
(tmp, cfg)
}
@@ -65,8 +67,7 @@ async fn unknown_tool_call_returns_error() {
h.dynamic()
.connect(&server.server_id)
.await
- .expect("connect")
- .tools;
+ .expect("connect");
let err = h
.dynamic()
@@ -153,8 +154,7 @@ async fn set_enabled_false_disconnects_running_server() {
h.dynamic()
.connect(&server.server_id)
.await
- .expect("connect")
- .tools;
+ .expect("connect");
let outcome = ops::mcp_clients_set_enabled(&cfg, server.server_id.clone(), false)
.await
diff --git a/tests/mcp_registry_multi_server.rs b/tests/mcp_registry_multi_server.rs
index a04aee711b..1abf213fb1 100644
--- a/tests/mcp_registry_multi_server.rs
+++ b/tests/mcp_registry_multi_server.rs
@@ -35,8 +35,10 @@ fn host(config: &Config) -> std::sync::Arc<openhuman_core::mcp::host::McpHost> {
fn fresh_workspace_config() -> (tempfile::TempDir, Config) {
let tmp = tempfile::tempdir().expect("tempdir");
- let mut cfg = Config::default();
- cfg.workspace_dir = tmp.path().to_path_buf();
+ let cfg = Config {
+ workspace_dir: tmp.path().to_path_buf(),
+ ..Config::default()
+ };
(tmp, cfg)
}
@@ -203,13 +205,11 @@ async fn tool_calls_route_to_the_correct_server() {
h.dynamic()
.connect(&server_a.server_id)
.await
- .expect("connect server_a")
- .tools;
+ .expect("connect server_a");
h.dynamic()
.connect(&server_b.server_id)
.await
- .expect("connect server_b")
- .tools;
+ .expect("connect server_b");
// Send distinct payloads to each server; verify each echoes its own input.
let result_a = h
@@ -394,8 +394,7 @@ async fn disabled_server_contributes_no_tools_to_agent_surface() {
h.dynamic()
.connect(&live.server_id)
.await
- .expect("connect live server")
- .tools;
+ .expect("connect live server");
// Attempting to connect the disabled server via ops must fail with
// a clear "disabled" message (matches mcp_registry_e2e::connect_refuses_disabled_server).
diff --git a/tests/raw_coverage/agent_orchestration_e2e.rs b/tests/raw_coverage/agent_orchestration_e2e.rs
index c515bde7f5..86d3128715 100644
--- a/tests/raw_coverage/agent_orchestration_e2e.rs
+++ b/tests/raw_coverage/agent_orchestration_e2e.rs
@@ -16,7 +16,7 @@
use crate::env_guard::EnvVarGuard;
use std::net::SocketAddr;
use std::path::Path;
-use std::sync::{Mutex, OnceLock};
+use std::sync::OnceLock;
use std::time::Duration;
use axum::http::header::AUTHORIZATION;
diff --git a/tests/raw_coverage/flows_lifecycle_e2e.rs b/tests/raw_coverage/flows_lifecycle_e2e.rs
index 6099bca2ff..81d1c7e1bd 100644
--- a/tests/raw_coverage/flows_lifecycle_e2e.rs
+++ b/tests/raw_coverage/flows_lifecycle_e2e.rs
@@ -17,7 +17,7 @@
use crate::env_guard::EnvVarGuard;
use std::net::SocketAddr;
use std::path::Path;
-use std::sync::{Mutex, OnceLock};
+use std::sync::OnceLock;
use std::time::Duration;
use axum::http::header::AUTHORIZATION;