O3: task sources and result sinks, cmd adapter protocol (closes #4)
This commit is contained in:
1 parent
2f79b69977
commit
6e1979fe7a
10 files changed
+594
-76
No files matched your search
@@ -90,6 +90,46 @@ check(run("tokens", "k", body="TURNS=5"), "failed", "budget:tokens")
|
||||
profile("y", "yolo = true\n")
|
||||
assert run("yolo", "y", body="x").returncode != 0
|
||||
|
||||
# --- sources and sinks (O3) ---
|
||||
tasks = tmp / "tasks"
|
||||
tasks.mkdir()
|
||||
(tasks / "b-ok.md").write_text("# B ok\nWRITE\n")
|
||||
(tasks / "a-bad.md").write_text("# A bad\nFAIL\n")
|
||||
profile("d", f'repo = "{repo}"\ngate = "test -f out.txt"\n[source]\nkind = "dir"\npath = "{tasks}"\n')
|
||||
p = subprocess.run([orch, "pull", "--profile", "d"], env=env, capture_output=True, text=True)
|
||||
assert p.returncode == 1, p # one task failed
|
||||
assert (tasks / ".done/b-ok.md").exists() and (tasks / ".failed/a-bad.md").exists()
|
||||
assert not list((tasks / ".running").glob("*.md"))
|
||||
assert "-> branch orch/b-ok-" in p.stdout, p.stdout # default sink = local-branch
|
||||
p = subprocess.run([orch, "pull", "--profile", "d"], env=env, capture_output=True, text=True)
|
||||
assert p.returncode == 0 and p.stdout == "", p # nothing left
|
||||
|
||||
ad = tmp / "ad"
|
||||
ad.mkdir()
|
||||
cmd = f"{sys.executable} {root / 'tests/fake_adapter.py'}"
|
||||
profile("c", f'repo = "{repo}"\ngate = "test -f out.txt"\n[source]\nkind = "cmd"\ncommand = "{cmd}"\n[sink]\nkind = "cmd"\ncommand = "{cmd}"\n')
|
||||
aenv = {**env, "ADAPTER_DIR": str(ad), "REPO": str(repo)}
|
||||
p = subprocess.run([orch, "pull", "--profile", "c"], env=aenv, capture_output=True, text=True)
|
||||
assert p.returncode == 1, p
|
||||
calls = [json.loads(l) for l in (ad / "calls.log").read_text().splitlines()]
|
||||
ops = [(c["op"], c["in"].get("task", {}).get("id")) for c in calls]
|
||||
assert ops == [("list", None), ("claim", "t-good"), ("publish", "t-good"), ("report", "t-good"),
|
||||
("claim", "t-taken"), ("claim", "t-bad"), ("report", "t-bad")], ops # taken skipped, bad not published
|
||||
pub = next(c for c in calls if c["op"] == "publish")["in"]
|
||||
assert pub["task"]["number"] == 7, pub # adapter-private field echoed back
|
||||
assert pub["run"]["status"] == "done" and pub["run"]["branch"].startswith("orch/t-good-"), pub
|
||||
assert "-> http://example/pr/1" in p.stdout, p.stdout
|
||||
rep = [c for c in calls if c["op"] == "report"]
|
||||
assert [c["in"]["run"]["status"] for c in rep] == ["done", "failed"], rep
|
||||
|
||||
# broken adapter output: publish error never loses the run; broken list is a hard error
|
||||
(ad / "calls.log").unlink()
|
||||
p = subprocess.run([orch, "pull", "--profile", "c", "--limit", "1"], env={**aenv, "BREAK": "publish"}, capture_output=True, text=True)
|
||||
assert "publish failed" in p.stderr and "publish-failed" in p.stdout, p
|
||||
assert subprocess.run([orch, "pull", "--profile", "c"], env={**aenv, "BREAK": "list"}, capture_output=True, text=True).returncode != 0
|
||||
profile("u", '[source]\nkind = "ftp"\n')
|
||||
assert subprocess.run([orch, "pull", "--profile", "u"], env=env, capture_output=True, text=True).returncode != 0
|
||||
|
||||
# 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"],
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fake cmd adapter for tests/e2e.py. State/log in $ADAPTER_DIR. Implements the protocol in docs/cmd-protocol.md."""
|
||||
import json, os, sys
|
||||
|
||||
d = os.environ["ADAPTER_DIR"]
|
||||
op = sys.argv[1]
|
||||
data = json.load(sys.stdin)
|
||||
open(f"{d}/calls.log", "a").write(json.dumps({"op": op, "in": data}) + "\n")
|
||||
if os.environ.get("BREAK") == op:
|
||||
print("not json")
|
||||
sys.exit(0)
|
||||
if op == "list":
|
||||
out = {"tasks": [
|
||||
{"id": "t-good", "title": "Good", "body": "WRITE", "repo": os.environ["REPO"], "number": 7},
|
||||
{"id": "t-taken", "title": "Taken", "body": "WRITE", "repo": os.environ["REPO"]},
|
||||
{"id": "t-bad", "title": "Bad", "body": "FAIL", "repo": os.environ["REPO"]},
|
||||
]}
|
||||
elif op == "claim":
|
||||
out = {"claimed": data["task"]["id"] != "t-taken"}
|
||||
elif op == "publish":
|
||||
out = {"url": "http://example/pr/1"}
|
||||
else:
|
||||
out = {}
|
||||
print(json.dumps(out))
|
||||
Reference in new issue
Block a user