Add pwd-asserts-action_dir test for shell-family tools (unit + JSON-RPC E2E)
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.rsasserts the CWD the spawned shell sees. The existing tests atshell.rs:451-700assert allow/deny semantics but not the cwd value. grep -n pwd tests/json_rpc_e2e.rsreturns 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 siblingshell_tests.rs): set up aSecurityPolicywith a tempaction_dir, invokeShellTool::run_with_securitywith commandpwd, assert the captured stdout (trimmed) equals the canonical action dir. - Same shape for
node_exec(node -e 'console.log(process.cwd())') andnpm_exec(where applicable). - JSON-RPC E2E entry in
tests/json_rpc_e2e.rs: driveopenhuman.tools_invokewithshell+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:
shellCWD assertion —pwdstdout equalsaction_dirforShellTool. - [ ] Unit test:
node_execCWD assertion —process.cwd()equalsaction_dir. - [ ] JSON-RPC E2E —
tests/json_rpc_e2e.rsrunsshellwithpwdand asserts the action path is returned over RPC. - [ ] Regression guard — the test fails if
current_dir(action_dir)is removed frombuild_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.