allow forces direct provider; provider_mode in telemetry; eval refuses mixed modes (closes #17)

This commit is contained in:
hermes committed 2026-11-13 19:06:13 +00:00
1 parent 374cf28aed
commit 2ff8abe7a3
8 files changed
+219 -10

No files matched your search

+38
View File
@@ -51,6 +51,44 @@ try:
ver = subprocess.run([str(hx), "--version"], capture_output=True, text=True).stdout.strip()
assert ver and tel[-1]["hx_version"] == ver and tel[-1]["status"] == "needs-human", (tel, ver)
print("real hx e2e ok:", st["reason"], "| audit by:", sorted({json.loads(l)["detail"].get("by", "guard") for l in audit.splitlines() if "decision" in l}))
# --- claude_cli mode (issue #17): the claude binary executes tools itself and hx emits no tool_call events ---
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"]'
(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")}
def go(profile_name, name):
(tmp / f"{name}.md").write_text(f"# {name}\nread the secret\n")
p = subprocess.run([orch, "run", str(tmp / f"{name}.md"), "--repo", str(repo), "--profile", profile_name],
env=cenv_vars, capture_output=True, text=True, timeout=120)
rid = p.stdout.split()[0]
st = json.loads(subprocess.run([orch, "status", rid], env=env, capture_output=True, text=True).stdout)
seen = subprocess.run(["git", "show", f"{st['branch']}:claude-read.txt"], cwd=repo, capture_output=True, text=True)
return st, seen.stdout if seen.returncode == 0 else None, p
# control: without `allow` the claude binary really runs and reads the secret (proves the test is sensitive)
st, seen, p = go("open", "ctl")
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`: orch forces the direct provider, the claude binary never starts, the guard denies the Read
n_calls = len((tmp / "argv.log").read_text().splitlines())
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", "gd")
finally:
srv2.terminate()
assert len((tmp / "argv.log").read_text().splitlines()) == n_calls, "claude binary was started despite allow"
assert seen is None or "PRIVATE-TOKEN-123" not in seen, seen
assert st["status"] == "needs-human" and st["reason"].startswith("policy:"), (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 forces direct, secret not read")
finally:
srv.terminate()
shutil.rmtree(tmp, ignore_errors=True)