#!/bin/sh set -eu root=$(cd "$(dirname "$0")/.." && pwd) tmp=$(mktemp -d) trap 'kill $srv 2>/dev/null; rm -rf "$tmp"' EXIT port=$((20000 + $$ % 20000)) python3 "$root/tests/fake_m6.py" $port & srv=$! mkdir -p "$tmp/home/.hx" "$tmp/repo/.hx" 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" cat > "$tmp/repo/.hx/mcp.json" < "$tmp/out" 2> "$tmp/err" || { cat "$tmp/err"; exit 1; } grep -q "FINISHED OK:42" "$tmp/out" || { echo "--- out"; cat "$tmp/out"; echo "--- log"; curl -s "http://127.0.0.1:$port/"; echo "--- err"; cat "$tmp/err"; exit 1; } "$root/target/debug/hx" mcp > "$tmp/st" grep -q "f: 5 tools.*lazy (index ~[0-9]* tok, eager schemas ~[0-9]* tok)" "$tmp/st" || { cat "$tmp/st"; exit 1; } printf 'fn main() {}\n' > main.rs cat > "$tmp/repo/.hx/mcp.json" < "$tmp/st2" grep -q "hx.lsp: Language server queries" "$tmp/st2" || { cat "$tmp/st2"; exit 1; } if command -v pyright-langserver >/dev/null; then printf 'x: int = "no"\n' > bad.py python3 - "$root/target/debug/hx" > "$tmp/diag" <<'PY' import json, subprocess, sys p = subprocess.Popen([sys.argv[1], "mcp-serve"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) def rpc(i, m, params): p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": i, "method": m, "params": params}) + "\n"); p.stdin.flush() while True: r = json.loads(p.stdout.readline()) if r.get("id") == i: return r rpc(1, "initialize", {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "t", "version": "0"}}) r = rpc(2, "tools/call", {"name": "lsp", "arguments": {"action": "diagnostics", "path": "bad.py"}}) print(r["result"]["content"][0]["text"]) p.stdin.close(); p.wait(timeout=30) PY grep -q 'error.*not assignable' "$tmp/diag" || { echo "--- diag"; cat "$tmp/diag"; exit 1; } fi echo "m6 e2e ok"