accept allow with claude_cli, fail closed when tool calls are unseen
This commit is contained in:
1 parent
2751bcf27b
commit
80ea84f8f6
6 files changed
+56
-46
No files matched your search
+5
-18
@@ -74,26 +74,13 @@ try:
|
||||
assert seen == "PRIVATE-TOKEN-123", (seen, p.stdout, p.stderr, st)
|
||||
last = [json.loads(l) for l in (tmp / "state/telemetry.jsonl").read_text().splitlines() if l.strip()][-1]
|
||||
assert last["provider_mode"] == "claude_cli", last
|
||||
# with `allow`: refused before hx starts, so the claude binary never runs and the secret stays unread
|
||||
n_calls = len((tmp / "argv.log").read_text().splitlines())
|
||||
# with `allow` on today's hx (no tool events for claude's tools, hx#182): fail closed, never "guarded"
|
||||
st, seen, p = go("guarded", "gd")
|
||||
assert len((tmp / "argv.log").read_text().splitlines()) == n_calls, "claude binary was started despite allow"
|
||||
assert seen is None, seen
|
||||
assert st["status"] == "needs-human" and "cannot be enforced" in st["reason"], (st, p.stdout, p.stderr)
|
||||
# the escape hatch: the direct provider in the profile's hx config makes `allow` enforceable again
|
||||
(home / ".hx/config.toml").write_text("claude_cli = false\n")
|
||||
srv2 = subprocess.Popen([sys.executable, str(fake), str(port + 1), str(turns)])
|
||||
time.sleep(0.7)
|
||||
cenv_vars["HX_BASE_URL"] = f"http://127.0.0.1:{port + 1}"
|
||||
try:
|
||||
st, seen, p = go("guarded", "gd2")
|
||||
finally:
|
||||
srv2.terminate()
|
||||
assert st["status"] == "needs-human" and st["reason"].startswith("policy: ") and "cannot be enforced" not in st["reason"], (st, p.stdout)
|
||||
assert seen is None or "PRIVATE-TOKEN-123" not in seen
|
||||
assert st["status"] == "needs-human" and "could not be enforced" in st["reason"], (st, p.stdout, p.stderr)
|
||||
last = [json.loads(l) for l in (tmp / "state/telemetry.jsonl").read_text().splitlines() if l.strip()][-1]
|
||||
assert last["provider_mode"] == "direct", last
|
||||
print("claude_cli mode ok: allow refused with claude_cli, enforced with direct")
|
||||
assert last["provider_mode"] == "claude_cli", last
|
||||
# (the fake claude has already read the secret by then: this hx cannot stop it, which is what hx#182 is for)
|
||||
print("claude_cli mode ok: unseen tool use fails closed (hx#182 missing)")
|
||||
finally:
|
||||
srv.terminate()
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
Reference in new issue
Block a user