accept allow with claude_cli, fail closed when tool calls are unseen

This commit is contained in:
hermes committed 2026-11-14 10:22:29 +00:00
1 parent 2751bcf27b
commit 80ea84f8f6
6 files changed
+56 -46

No files matched your search

+8 -8
View File
@@ -279,14 +279,14 @@ fakecl = tmp / "claude"
fakecl.write_text("#!/bin/sh\n[ \"$1\" = --version ] && echo fake\nexit 0\n")
fakecl.chmod(0o755)
cenv = {"HX_CLAUDE_BIN": str(fakecl)} # a claude binary exists => hx would pick claude_cli
s = check(run("refuse", "sec", env=cenv, body="CALL write a.txt"), "needs-human", "policy: `allow` cannot be enforced")
assert s["attempts"] == 0 and s["hx_exit"] is None, s # hx was never started
assert "claude_cli = false" in (tmp / "state/runs" / (s["id"] + ".log")).read_text()
# explicit opt-out in the profile's hx config => direct, allowed again
(work_home / ".hx").mkdir(exist_ok=True)
(work_home / ".hx/config.toml").write_text("claude_cli = false\n")
check(run("optout", "sec", env=cenv, body="CALL write a.txt"), "done")
(work_home / ".hx/config.toml").unlink()
# claude_cli + allow: every tool claude runs must reach the guard as a tool_call (hx#182); fewer = fail closed
s = check(run("cli-seen", "sec", env=cenv, body="CLAUDE\nCALL write a.txt\nCALL bash cargo test -p x"), "done")
s = check(run("cli-deny", "sec", env=cenv, body=f"CLAUDE\nCALL read {private}/auth.json"), "needs-human", "policy:")
assert "PRIVATE-TOKEN-123" not in git_show(s["branch"], "calls.txt")
s = check(run("cli-unseen", "sec", env=cenv, body="CLAUDE UNSEEN\nCALL write a.txt"), "needs-human", "policy: claude used 1 tool(s) but hx reported 0")
assert "johannes/hx#182" in s["reason"] or "hx#182" in s["reason"], s
# no claude lines => nothing to cross-check (direct provider): unaffected
check(run("direct-ok", "sec", env=senv, body="CALL write a.txt"), "done")
# without `allow` claude_cli runs as before (recorded as claude_cli)
profile("noallow", f'home = "{work_home}"\n')
check(run("cli-ok", "noallow", env=cenv, body="WRITE"), "done")