Files
pipewright/tests/test_examples.py
T

65 lines
2.5 KiB
Python

"""The example pipelines double as integration tests (fake model, local/Docker sandboxes)."""
import json
import pytest
from pipewright import ops
def read_jsonl(path):
return [json.loads(line) for line in path.read_text().splitlines()]
def test_issue_triage(example):
d = example("issue_triage")
s = ops.run_graph(d / "graph.py")
assert s["status"] == "completed"
nodes = s["funnel"]["nodes"]
assert nodes["issues"]["out"] == {"out": 12}
assert nodes["substantive"]["out"] == {"out": 10, "rejected": 2}
assert nodes["route"]["out"] == {"urgent": 5, "features": 3, "other": 2}
urgent = read_jsonl(d / "out/urgent.jsonl")
assert {r["key"] for r in urgent} == {"gh-101", "gh-104", "gh-107", "gh-109", "gh-112"}
assert all(r["labels.category"] == "bug" for r in urgent)
# second run is fully memoized
s2 = ops.run_graph(d / "graph.py")
assert s2["funnel"]["nodes"]["classify"]["events"] == {"ok": 10, "cached": 10}
# the yaml form of the graph is equivalent
ops.export_graph(d / "graph.py", d / "graph.yaml")
s3 = ops.run_graph(d / "graph.yaml")
assert s3["funnel"]["nodes"]["classify"]["events"]["cached"] == 10
rep = ops.report(d / "graph.yaml")
html = open(rep["path"]).read()
assert "issue-triage" in html and "<svg" in html and "node-classify" in html
def _check_coding(s, d):
assert s["status"] == "completed", s["errors"]
nodes = s["funnel"]["nodes"]
assert nodes["synth"]["out"] == {"out": 4}
assert nodes["valid"]["out"] == {"out": 3, "rejected": 1}
assert nodes["probe"]["out"] == {"out": 6}
assert nodes["bucket"]["out"] == {"too_easy": 1, "learnable": 1, "too_hard": 1}
assert read_jsonl(d / "out/too_easy.jsonl")[0]["key"] == "add"
assert read_jsonl(d / "out/learnable.jsonl")[0] == {"key": "classify", "labels.pass_rate": 0.5,
"labels.rollouts": 2}
assert read_jsonl(d / "out/invalid.jsonl")[0]["key"] == "broken_max"
def test_coding_tasks_local(example):
d = example("coding_tasks")
s = ops.run_graph(d / "graph.py")
_check_coding(s, d)
s2 = ops.run_graph(d / "graph.py")
assert s2["funnel"]["nodes"]["probe"]["events"] == {"ok": 6, "cached": 6}
tr = ops.items(d / "graph.py", "probe", n=1)["items"][0]
assert "trajectory" in tr["artifacts"] and tr["labels"]["agent_status"] == "completed"
@pytest.mark.docker
def test_coding_tasks_docker(example):
d = example("coding_tasks")
s = ops.run_graph(d / "graph.py", project=d / "pipewright.docker.yaml")
_check_coding(s, d)