O6: telemetry, orch report, orch eval, orch bench and eval cases (closes #7)
This commit is contained in:
1 parent
bea07e82bb
commit
015561530a
31 files changed
+809
-3
No files matched your search
@@ -8,5 +8,6 @@ cargo test -q
|
||||
cargo build -q
|
||||
python3 tests/e2e.py
|
||||
python3 spike/check.py
|
||||
./target/debug/orch bench eval --check
|
||||
|
||||
python3 tests/real_hx.py
|
||||
@@ -268,6 +268,54 @@ assert len((tmp / "g-audit.log").read_text().splitlines()) == 4
|
||||
# warning for unrestricted profiles
|
||||
assert "no `allow` list" in run("warn", "p", body="WRITE").stderr
|
||||
|
||||
# --- telemetry, report, eval, bench (O6) ---
|
||||
tel = tmp / "state/telemetry.jsonl"
|
||||
recs = [json.loads(l) for l in tel.read_text().splitlines() if l.strip()]
|
||||
assert len(recs) >= 30, len(recs)
|
||||
ok_rec = next(r for r in recs if r["task"] == "ok")
|
||||
assert (ok_rec["status"], ok_rec["profile"], ok_rec["hx_version"], ok_rec["input_tokens"], ok_rec["attempts"]) == ("done", "p", "hx 9.9.9", 100, 1), ok_rec
|
||||
assert next(r for r in recs if r["task"] == "nowrite")["status"] == "needs-human"
|
||||
assert next(r for r in recs if r["task"] == "nowrite")["attempts"] == 3
|
||||
assert any(r["status"] == "requeued" for r in recs)
|
||||
rep = subprocess.run([orch, "report"], env=env, capture_output=True, text=True).stdout
|
||||
assert "hx 9.9.9" in rep and "profile" in rep and rep.splitlines()[-1].startswith("retries"), rep
|
||||
allrow = next(l for l in rep.splitlines() if l.startswith("all"))
|
||||
assert allrow.split()[1] == str(len([r for r in recs])), (allrow, len(recs))
|
||||
# a half-written line (crash) is skipped and does not hide the next record
|
||||
with open(tel, "a") as f:
|
||||
f.write('{"ts": 1, "run": "cut')
|
||||
run("after-cut", "p", body="WRITE")
|
||||
rep2 = subprocess.run([orch, "report"], env=env, capture_output=True, text=True)
|
||||
assert "skipped 1 unreadable" in rep2.stderr and rep2.returncode == 0, rep2
|
||||
assert len(subprocess.run([orch, "report"], env=env, capture_output=True, text=True).stdout.splitlines()) == len(rep.splitlines()) # same table shape
|
||||
|
||||
# bench: the shipped eval cases, with a fake hx that solves every case but one
|
||||
ev = root / "eval"
|
||||
chk = subprocess.run([orch, "bench", str(ev), "--check"], env=env, capture_output=True, text=True)
|
||||
assert chk.returncode == 0 and chk.stdout.count("untouched=fail solved=pass") == 4, chk
|
||||
profile("bb", f'env = ["SOLVE_DIR", "SOLVE_SKIP", "FAKE_VERSION"]\ngate = "false"\nmax_retries = 0\n')
|
||||
a_out, b_out = tmp / "a.jsonl", tmp / "b.jsonl"
|
||||
benv = {**env, "SOLVE_DIR": str(ev)}
|
||||
pa = subprocess.run([orch, "bench", str(ev), "--profile", "bb", "--out", str(a_out), "--repeat", "2"], env={**benv, "FAKE_VERSION": "1.0"}, capture_output=True, text=True)
|
||||
assert pa.returncode == 0, pa # every case solved; the profile gate ("false") is replaced by the case's gate.sh
|
||||
pb = subprocess.run([orch, "bench", str(ev), "--profile", "bb", "--out", str(b_out)], env={**benv, "SOLVE_SKIP": "rename-symbol", "FAKE_VERSION": "2.0"}, capture_output=True, text=True)
|
||||
assert pb.returncode == 1, pb # one case unsolved -> bench exit 1
|
||||
ra, rb = report_load = [[json.loads(l) for l in f.read_text().splitlines() if l.strip()] for f in (a_out, b_out)]
|
||||
assert len(ra) == 8 and {r["hx_version"] for r in ra} == {"hx 1.0"} and {r["task"] for r in ra} == {"add-function", "fix-off-by-one", "fix-typo-readme", "rename-symbol"}
|
||||
assert [r["status"] for r in rb if r["task"] == "rename-symbol"] == ["needs-human"] and len(rb) == 4
|
||||
ev_out = subprocess.run([orch, "eval", str(a_out), str(b_out)], env=env, capture_output=True, text=True)
|
||||
assert ev_out.returncode == 1 and "REGRESSION" in ev_out.stdout and "-25 pp" in ev_out.stdout, ev_out
|
||||
line = next(l for l in ev_out.stdout.splitlines() if l.startswith("rename-symbol"))
|
||||
assert line.split()[1:3] == ["2/2", "0/1"], line
|
||||
ev_ok = subprocess.run([orch, "eval", str(b_out), str(a_out)], env=env, capture_output=True, text=True)
|
||||
assert ev_ok.returncode == 0 and "REGRESSION" not in ev_ok.stdout and "+25 pp" in ev_ok.stdout, ev_ok # B better than A: no failure
|
||||
# a broken case set is caught by --check
|
||||
broken = tmp / "broken"
|
||||
shutil.copytree(ev, broken)
|
||||
(broken / "add-function/solution/text.py").write_text("def slugify(s):\n return s\n")
|
||||
bad = subprocess.run([orch, "bench", str(broken), "--check"], env=env, capture_output=True, text=True)
|
||||
assert bad.returncode == 1 and "broken case" in bad.stdout, bad
|
||||
|
||||
# kill orch mid-run: status must say interrupted and hx must be dead after the next orch call
|
||||
pidfile = tmp / "hx.pid"
|
||||
p = subprocess.Popen([orch, "run", str(task("killed", "HANG")), "--repo", str(repo), "--profile", "p"],
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import json, sys, time, os
|
||||
if "--version" in sys.argv:
|
||||
print("hx " + os.environ.get("FAKE_VERSION", "9.9.9"))
|
||||
sys.exit(0)
|
||||
body = sys.argv[sys.argv.index("-p") + 1]
|
||||
e = lambda o: print(json.dumps(o), flush=True)
|
||||
e({"type": "session_start"})
|
||||
@@ -30,6 +33,12 @@ for n, l in enumerate(x for x in body.splitlines() if x.startswith("CALL ")):
|
||||
elif name == "write": open(arg, "w").write("x"); f.write("WROTE " + arg + "\n")
|
||||
else: f.write("RAN " + arg + "\n")
|
||||
e({"type": "tool_result", "id": f"c{n}", "name": name, "args": args, "content": "ok", "is_error": False})
|
||||
if os.environ.get("SOLVE_DIR"):
|
||||
# eval cases: solve by overlaying the case's solution/ unless the task title is listed in SOLVE_SKIP
|
||||
for c in (d for d in os.listdir(os.environ["SOLVE_DIR"]) if os.path.isfile(os.path.join(os.environ["SOLVE_DIR"], d, "task.md"))):
|
||||
t = open(os.path.join(os.environ["SOLVE_DIR"], c, "task.md")).read().split("\n", 2)[2].strip()
|
||||
if t == body.strip() and c not in os.environ.get("SOLVE_SKIP", "").split(","):
|
||||
subprocess.run(["cp", "-R", os.path.join(os.environ["SOLVE_DIR"], c, "solution") + "/.", "."], check=True)
|
||||
if "ENVDUMP" in body: open("env.txt", "w").write("\n".join(sorted(os.environ)))
|
||||
if "NOJSON" in body: sys.exit(1)
|
||||
if "HANG" in body:
|
||||
|
||||
@@ -46,6 +46,10 @@ try:
|
||||
# hx itself saw the block from the guard extension (or orch killed it first; either way the file was not read)
|
||||
audit = subprocess.run([orch, "audit", rid], env=env, capture_output=True, text=True).stdout
|
||||
assert '"decision":"deny"' in audit.replace(" ", ""), audit
|
||||
# telemetry carries the real `hx --version`
|
||||
tel = [json.loads(l) for l in (tmp / "state/telemetry.jsonl").read_text().splitlines() if l.strip()]
|
||||
ver = subprocess.run([str(hx), "--version"], capture_output=True, text=True).stdout.strip()
|
||||
assert ver and tel[-1]["hx_version"] == ver and tel[-1]["status"] == "needs-human", (tel, ver)
|
||||
print("real hx e2e ok:", st["reason"], "| audit by:", sorted({json.loads(l)["detail"].get("by", "guard") for l in audit.splitlines() if "decision" in l}))
|
||||
finally:
|
||||
srv.terminate()
|
||||
|
||||
Reference in new issue
Block a user