openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Add pwd-asserts-action_dir test for shell-family tools (unit + JSON-RPC E2E)

Open CodeGhost21 opened this issue 6 months ago • 0 comments

Summary

Add a pwd-asserts-action_dir test for shell-family tools — a Rust unit test in shell.rs (and ideally a corresponding entry in tests/json_rpc_e2e.rs) that executes pwd and asserts the captured stdout equals security.action_dir.

Problem

#3051 acceptance criterion 6: "Rust tests: path policy blocks writes to workspace/memory/ from tools rooted at actions; shell CWD assertion. JSON-RPC or harness E2E: run shell with pwd and assert actions path."

PR #3074 covers the first half (path policy denylist tests: src/openhuman/security/policy_tests.rs:2465-2540 — is_workspace_internal_path_blocks_state_dirs, is_workspace_internal_path_blocks_state_files, is_workspace_internal_path_allows_non_internal, is_path_string_allowed_blocks_workspace_internal, action_dir_in_default_policy).

The second half is missing:

  • No test in src/openhuman/tools/impl/system/shell.rs asserts the CWD the spawned shell sees. The existing tests at shell.rs:451-700 assert allow/deny semantics but not the cwd value.
  • grep -n pwd tests/json_rpc_e2e.rs returns zero hits.

Why this matters: the implementation could regress the current_dir(action_dir) line in build_shell_command (src/openhuman/agent/host_runtime.rs:96) and no test would catch it — the deny-list tests pass even if the CWD is wrong, because the deny-list is a path-string check independent of where the child process runs. The acceptance criterion exists specifically to lock in the runtime contract.

Solution (optional)

  • Unit test in src/openhuman/tools/impl/system/shell.rs (or a sibling shell_tests.rs): set up a SecurityPolicy with a temp action_dir, invoke ShellTool::run_with_security with command pwd, assert the captured stdout (trimmed) equals the canonical action dir.
  • Same shape for node_exec (node -e 'console.log(process.cwd())') and npm_exec (where applicable).
  • JSON-RPC E2E entry in tests/json_rpc_e2e.rs: drive openhuman.tools_invoke with shell + pwd, assert the rpc response carries the action dir. Reuses the existing mock-backend harness (scripts/test-rust-with-mock.sh).

Acceptance criteria

  • [ ] Unit test: shell CWD assertion — pwd stdout equals action_dir for ShellTool.
  • [ ] Unit test: node_exec CWD assertion — process.cwd() equals action_dir.
  • [ ] JSON-RPC E2E — tests/json_rpc_e2e.rs runs shell with pwd and asserts the action path is returned over RPC.
  • [ ] Regression guard — the test fails if current_dir(action_dir) is removed from build_shell_command.
  • [ ] Diff coverage ≥ 80% — the implementing PR meets the changed-lines coverage gate (Vitest + cargo-llvm-cov, enforced by .github/workflows/pr-ci.yml).

Related

  • Parent issue: #3051
  • Implementing PR: #3074
  • Audit: this is gap #4 (criterion 6, "Tests") — verdict PARTIAL.
  • Relevant code: src/openhuman/tools/impl/system/shell.rs, src/openhuman/tools/impl/system/node_exec.rs, src/openhuman/agent/host_runtime.rs, tests/json_rpc_e2e.rs, scripts/test-rust-with-mock.sh.

CodeGhost21 avatar Jun 02 '26 21:06 CodeGhost21