on_deny=continue (soft vs hard denies), denies counter, tokens of stopped runs

This commit is contained in:
hermes committed 2026-11-14 12:18:55 +00:00
1 parent e668eb1b0d
commit 8c76da90e8
11 files changed
+310 -87

No files matched your search

+20 -1
View File
@@ -55,7 +55,7 @@ try:
shutil.copy(root / "tests/fake_claude.py", tmp / "claude")
os.chmod(tmp / "claude", 0o755)
(home / ".hx/config.toml").write_text("claude_cli = []\n") # the profile's own home turns the provider on
cenv = '["HX_BASE_URL", "HX_CLAUDE_BIN", "FAKE_CLAUDE_READ", "FAKE_CLAUDE_LOG", "FAKE_CLAUDE_NOASK"]'
cenv = '["HX_BASE_URL", "HX_CLAUDE_BIN", "FAKE_CLAUDE_READ", "FAKE_CLAUDE_LOG", "FAKE_CLAUDE_NOASK", "FAKE_CLAUDE_BASH"]'
(cfg / "guarded.toml").write_text(f'hx = "{hx}"\nhome = "{home}"\nenv = {cenv}\nallow = ["write"]\n')
(cfg / "open.toml").write_text(f'hx = "{hx}"\nhome = "{home}"\nenv = {cenv}\n')
cenv_vars = {**env, "HX_CLAUDE_BIN": str(tmp / "claude"), "FAKE_CLAUDE_READ": str(secret), "FAKE_CLAUDE_LOG": str(tmp / "argv.log")}
@@ -100,6 +100,25 @@ try:
assert dead_run("") == "PRIVATE-TOKEN-123", "control: a dead guard without extensions-only lets the read through"
assert dead_run('permissions = "extensions-only"\n') is None, "extensions-only must deny when the guard is dead"
# on_deny = "continue" against the real hx bridge: a soft deny is answered to claude (tool does not run) and the run
# goes on; the fake claude then asks for a second tool, which is allowed
(cfg / "soft.toml").write_text(f'hx = "{hx}"\nhome = "{home}"\nenv = {cenv}\nallow = ["read"]\non_deny = "continue"\n')
cenv_vars["FAKE_CLAUDE_BASH"] = "ls"
st, seen, p = go("soft", "soft1")
del cenv_vars["FAKE_CLAUDE_BASH"]
assert st["status"] == "done" and st["denies"] == 1, (st, p.stdout, p.stderr)
# the denied `ls` never ran; the same command is allowed once the profile has `readonly`
(cfg / "soft2.toml").write_text(f'hx = "{hx}"\nhome = "{home}"\nenv = {cenv}\nallow = ["readonly"]\non_deny = "continue"\n')
cenv_vars["FAKE_CLAUDE_BASH"] = "ls"
st, seen, p = go("soft2", "soft2")
del cenv_vars["FAKE_CLAUDE_BASH"]
assert st["status"] == "done" and st["denies"] == 0, (st, p.stdout, p.stderr)
# default on_deny (stop): the same soft deny ends the run
(cfg / "stop.toml").write_text(f'hx = "{hx}"\nhome = "{home}"\nenv = {cenv}\nallow = ["read"]\n')
cenv_vars["FAKE_CLAUDE_BASH"] = "ls"
st, seen, p = go("stop", "stop1")
del cenv_vars["FAKE_CLAUDE_BASH"]
assert st["status"] == "needs-human" and st["reason"].startswith("policy:") and st["denies"] >= 1, (st, p.stdout, p.stderr)
# claude that never asks hx (flags ignored): hx still reports the tool via claude's tool result, so orch's own
# stream check sees it. The tool ran already (after the fact), but the run is not called clean.
cenv_vars["FAKE_CLAUDE_NOASK"] = "1"