Files
hx/tests/m8_e2e.sh
T

47 lines
2.4 KiB
Bash

#!/bin/sh
# M8 e2e: the parent calls `task`; the child (own session, cheap model) reads a file and answers;
# only the answer reaches the parent; child usage is logged under <session>.sub/.
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"
echo "secret is 42" > "$tmp/repo/note.txt"
echo "PROJECT-RULE-XYZ" > "$tmp/repo/AGENTS.md"
cat > "$tmp/turns.json" <<'J'
[[["tool_use", {"id": "p1", "name": "Task", "input": {"prompt": "what is in note.txt?"}}]],
[["tool_use", {"id": "c1", "name": "Read", "input": {"path": "note.txt"}}]],
[["text", "note.txt says: secret is 42"]],
[["text", "Parent done."]]]
J
cd "$tmp/repo"
export HOME="$tmp/home"
port=$((20000 + $$ % 20000))
python3 "$root/tests/fake_anthropic.py" $port "$tmp/turns.json" & srv=$!
export HX_BASE_URL="http://127.0.0.1:$port"
sleep 0.5
"$root/target/debug/hx" -p "go" -s "$tmp/s.jsonl" > "$tmp/out" 2> "$tmp/err" || { echo "FAIL run"; cat "$tmp/err"; exit 1; }
grep -q "Parent done." "$tmp/out" || { echo "FAIL parent text"; cat "$tmp/out" "$tmp/err"; exit 1; }
curl -s "http://127.0.0.1:$port/log" > "$tmp/log"
python3 - "$tmp/log" "$tmp/s.jsonl" <<'PY' || { echo "FAIL requests"; exit 1; }
import json, sys
log = json.load(open(sys.argv[1]))
assert len(log) == 4, len(log)
parent, child1, child2, parent2 = [r["body"] for r in log]
assert "haiku" in child1["model"] and "sonnet" in parent["model"], (child1["model"], parent["model"])
assert child1["messages"][0]["content"][0]["text"] == "what is in note.txt?"
assert {t["name"] for t in child1["tools"]} == {"Read", "Bash", "skill"}, [t["name"] for t in child1["tools"]]
assert "Task" in {t["name"] for t in parent["tools"]}
# children get the project context (AGENTS.md) in their system prompt, like the parent
for r in (parent, child1, child2):
assert "PROJECT-RULE-XYZ" in json.dumps(r["system"]), r["model"]
# parent got only the child's answer (+ stats line), not the Read result
res = json.dumps(parent2["messages"][-1])
assert "secret is 42" in res and "[task explore" in res
PY
ls "$tmp/s.sub/001-explore.jsonl" > /dev/null || { echo "FAIL child session"; exit 1; }
"$root/target/debug/hx" stats "$tmp/s.jsonl" | grep -q "subagents (1 runs" || { echo "FAIL stats"; exit 1; }
echo "m8 e2e ok"