#!/bin/sh # (print mode has no prompt, so the permission bridge allows) claude_cli = [] routes Claude through the `claude` binary (fake here): streamed text arrives, argv is right. set -eu root=$(cd "$(dirname "$0")/.." && pwd) tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT mkdir -p "$tmp/home/.hx" "$tmp/repo" printf 'claude_cli = []\ncodemode = true\n[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml" chmod +x "$root/tests/fake_claude.py" cd "$tmp/repo" export HOME="$tmp/home" HX_CLAUDE_BIN="$root/tests/fake_claude.py" FAKE_CLAUDE_LOG="$tmp/argv" "$root/target/debug/hx" -p "hi" -s "$tmp/s.jsonl" > "$tmp/out" 2> "$tmp/err" || { echo "FAIL run"; cat "$tmp/err"; exit 1; } 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"