1 parent
cf8268d17b
commit
a01d0cbb5b
15 files changed
+723
-3
No files matched your search
@@ -18,3 +18,4 @@ sh tests/m4_e2e.sh
|
||||
sh tests/m5_e2e.sh
|
||||
sh tests/m6_e2e.sh
|
||||
python3 tests/tui_lspinstall.py | grep -q FAIL && { echo "tui lsp install FAIL"; exit 1; } || echo "tui lsp install ok"
|
||||
sh tests/m7_e2e.sh
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
# M7 e2e: --mode json emits NDJSON events; examples/rpc_client.py drives a session over --mode rpc;
|
||||
# examples/ext_guard.py (extension) blocks a bash call and provides a tool.
|
||||
set -eu
|
||||
root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
tmp=$(mktemp -d)
|
||||
trap 'kill $srv 2>/dev/null; rm -rf "$tmp"' EXIT
|
||||
mkdir -p "$tmp/home/.hx" "$tmp/repo"
|
||||
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
|
||||
printf '[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml"
|
||||
cd "$tmp/repo"
|
||||
export HOME="$tmp/home"
|
||||
start() {
|
||||
port=$((20000 + ($$ + $1) % 20000))
|
||||
python3 "$root/tests/fake_anthropic.py" $port & srv=$!
|
||||
export HX_BASE_URL="http://127.0.0.1:$port"
|
||||
sleep 0.5
|
||||
}
|
||||
fail() { echo "FAIL: $1"; cat "$2"; exit 1; }
|
||||
|
||||
# 1) json mode: every line parses; tool_call, tool_result, text and done are present
|
||||
start 1
|
||||
"$root/target/debug/hx" -p "go" --mode json > "$tmp/json" 2> "$tmp/err" || fail "json run" "$tmp/err"
|
||||
python3 - "$tmp/json" <<'PY' || fail "ndjson schema" "$tmp/json"
|
||||
import json, sys
|
||||
ev = [json.loads(l) for l in open(sys.argv[1])]
|
||||
types = [e["type"] for e in ev]
|
||||
assert types[-1] == "done" and ev[-1]["error"] is None, ev[-1]
|
||||
for t in ["turn_start", "stream", "message", "tool_call", "tool_result", "turn_end"]:
|
||||
assert t in types, t
|
||||
assert any(e["type"] == "stream" and e["event"]["type"] == "text_delta" for e in ev)
|
||||
assert any(e["type"] == "tool_result" and "hi from hx" in e["content"] for e in ev)
|
||||
PY
|
||||
kill $srv; rm -f hello.txt
|
||||
|
||||
# 2) rpc mode driven by the example client
|
||||
start 2
|
||||
python3 "$root/examples/rpc_client.py" "$root/target/debug/hx" "go" > "$tmp/rpc" 2> "$tmp/err" || fail "rpc" "$tmp/err"
|
||||
grep -q "Done: file says hi from hx." "$tmp/rpc" || fail "rpc text" "$tmp/rpc"
|
||||
grep -q "> bash" "$tmp/rpc" || fail "rpc events" "$tmp/rpc"
|
||||
grep -q "STATE messages=6 " "$tmp/rpc" || fail "rpc state" "$tmp/rpc"
|
||||
grep -q "BUSY_CHECK claude-x" "$tmp/rpc" || fail "rpc set_model" "$tmp/rpc"
|
||||
kill $srv; rm -f hello.txt
|
||||
|
||||
# 3) extension blocks the bash call (cat) and registers its tool
|
||||
start 3
|
||||
printf '[[extensions]]\ncommand = ["python3", "%s/examples/ext_guard.py", "cat hello"]\n' "$root" >> "$tmp/home/.hx/config.toml"
|
||||
"$root/target/debug/hx" -p "go" --mode json > "$tmp/ext" 2> "$tmp/err" || fail "ext run" "$tmp/err"
|
||||
python3 - "$tmp/ext" <<'PY' || fail "ext block" "$tmp/ext"
|
||||
import json, sys
|
||||
ev = [json.loads(l) for l in open(sys.argv[1])]
|
||||
log = json.dumps(ev)
|
||||
assert "blocked: ext_guard: `cat hello` is not allowed" in log, "no block"
|
||||
bash = [e for e in ev if e["type"] == "tool_result" and e["name"] == "bash"]
|
||||
assert len(bash) == 1 and bash[0]["is_error"] and bash[0]["content"].startswith("blocked:"), bash
|
||||
PY
|
||||
curl -s "$HX_BASE_URL/" | grep -q '"name": "now"' || { echo "FAIL: ext tool not offered"; exit 1; }
|
||||
echo "m7 e2e ok"
|
||||
Reference in new issue
Block a user