claude_cli: tool calls on the event bus, extensions can block, permissions deny/extensions-only (#182)

This commit is contained in:
hermes committed 2026-11-13 19:38:29 +00:00
1 parent 6ebf1c3180
commit 6978aad27a
12 files changed
+297 -12

No files matched your search

+24
View File
@@ -13,4 +13,28 @@ export HOME="$tmp/home" HX_CLAUDE_BIN="$root/tests/fake_claude.py" FAKE_CLAUDE_L
grep -q "claude Bash: echo hi-from-tool" "$tmp/out" && grep -q "approve: allow" "$tmp/out" || { echo "FAIL text"; cat "$tmp/out" "$tmp/err"; exit 1; }
grep -q '"--permission-prompt-tool"' "$tmp/argv" && grep -q '"--mcp-config"' "$tmp/argv" && grep -q '"stream-json"' "$tmp/argv" || { echo "FAIL argv"; cat "$tmp/argv"; exit 1; }
grep -q "cm-ok" "$tmp/out" || { echo "FAIL codemode"; cat "$tmp/out" "$tmp/err"; exit 1; }
# bridge goes through the bus: an extension blocks a secret Read and `curl`; tool events reach NDJSON
cd "$tmp/repo"
export FAKE_ASK=1
timeout 20 "$root/target/debug/hx" -p "go" --mode json -s "$tmp/s2.jsonl" > "$tmp/o2" 2> "$tmp/e2" || { echo "FAIL ask run"; cat "$tmp/e2"; exit 1; }
python3 - "$tmp/o2" allow <<'PY' || { echo "FAIL events (no extension)"; exit 1; }
import json, sys
ev = [json.loads(l) for l in open(sys.argv[1]) if l.startswith("{")]
calls = [(e["name"], e["id"]) for e in ev if e["type"] == "tool_call"]
res = [e for e in ev if e["type"] == "tool_result"]
assert calls == [("read", "t1"), ("bash", "t2")], calls
assert [r["is_error"] for r in res] == [False, False] and "allow" in res[1]["content"], res
PY
printf 'claude_cli = []\n[lsp]\nmode = "off"\ntests = "off"\n[[extensions]]\ncommand = ["python3", "%s/tests/ext_block_all.py"]\n' "$root" > "$tmp/home/.hx/config.toml"
timeout 20 "$root/target/debug/hx" -p "go" --mode json -s "$tmp/s3.jsonl" > "$tmp/o3" 2> "$tmp/e3" || { echo "FAIL ext run"; cat "$tmp/e3"; exit 1; }
python3 - "$tmp/o3" <<'PY' || { echo "FAIL events (extension)"; cat "$tmp/e3"; exit 1; }
import json, sys
ev = [json.loads(l) for l in open(sys.argv[1]) if l.startswith("{")]
res = [e for e in ev if e["type"] == "tool_result"]
assert len(res) == 2 and all(r["is_error"] and "blocked: guard: " in r["content"] for r in res), res
PY
# a dead guard must not leave the run open under permissions = "extensions-only"
printf 'claude_cli = []\npermissions = "extensions-only"\n[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml"
timeout 20 "$root/target/debug/hx" -p "go" --mode json -s "$tmp/s4.jsonl" > "$tmp/o4" 2> "$tmp/e4" || { echo "FAIL deny run"; cat "$tmp/e4"; exit 1; }
grep -q 'extensions-only' "$tmp/o4" && ! grep -q '"content":"allow' "$tmp/o4" || { echo "FAIL extensions-only"; cat "$tmp/o4"; exit 1; }
echo "claude cli e2e ok"