1 parent
25a96a8c65
commit
29c08130c2
3 files changed
+146
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Self-check for the O0 spike: python3 spike/check.py"""
|
||||
import json, pathlib, subprocess, sys, tempfile
|
||||
|
||||
here = pathlib.Path(__file__).parent.resolve()
|
||||
tmp = pathlib.Path(tempfile.mkdtemp())
|
||||
repo = tmp / "repo"
|
||||
repo.mkdir()
|
||||
for c in (["init", "-q", "-b", "main"], ["-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "--allow-empty", "-m", "i"]):
|
||||
subprocess.run(["git", *c], cwd=repo, check=True)
|
||||
tele = tmp / "t.jsonl"
|
||||
hx = f"{sys.executable} {here / 'fake_hx.py'}"
|
||||
|
||||
|
||||
def run(name, body, timeout=30):
|
||||
task = tmp / f"{name}.md"
|
||||
task.write_text(f"# Task {name}\n{body}\n")
|
||||
p = subprocess.run([sys.executable, str(here / "orch.py"), str(task), "--repo", str(repo), "--hx", hx,
|
||||
"--gate", "test -f out.txt", "--timeout", str(timeout), "--telemetry", str(tele)],
|
||||
capture_output=True, text=True)
|
||||
return p.returncode, json.loads(p.stdout.splitlines()[-1])
|
||||
|
||||
|
||||
rc, r = run("ok", "write it")
|
||||
assert (rc, r["result"], r["gate_exit"]) == (0, "done", 0), r
|
||||
assert r["usage"] == {"input_tokens": 10, "output_tokens": 5}, r
|
||||
files = subprocess.run(["git", "ls-tree", "--name-only", "orch/ok"], cwd=repo, capture_output=True, text=True).stdout
|
||||
assert "out.txt" in files, files # hx's work committed on the branch
|
||||
|
||||
rc, r = run("hxfail", "FAIL")
|
||||
assert (rc, r["result"]) == (1, "hx-failed") and r["gate_exit"] is None, r
|
||||
rc, r = run("crash", "CRASH")
|
||||
assert r["result"] == "hx-failed" and r["hx_exit"] == 2, r
|
||||
rc, r = run("slow", "HANG", timeout=1)
|
||||
assert r["result"] == "timeout", r
|
||||
|
||||
# gate failure: hx writes nothing relevant because gate wants a file that never exists
|
||||
task = tmp / "gate.md"
|
||||
task.write_text("# Gate\nwrite it\n")
|
||||
p = subprocess.run([sys.executable, str(here / "orch.py"), str(task), "--repo", str(repo), "--hx", hx,
|
||||
"--gate", "test -f nope", "--telemetry", str(tele)], capture_output=True, text=True)
|
||||
assert json.loads(p.stdout)["result"] == "gate-failed", p.stdout
|
||||
|
||||
lines = [json.loads(l) for l in tele.read_text().splitlines()]
|
||||
assert [l["result"] for l in lines] == ["done", "hx-failed", "hx-failed", "timeout", "gate-failed"], lines
|
||||
print("check ok")
|
||||
Reference in new issue
Block a user