57 lines
2.7 KiB
Python
57 lines
2.7 KiB
Python
import json
|
|
|
|
from pipewright.cli import main
|
|
|
|
|
|
def run_cli(capsys, *args):
|
|
code = main(list(args))
|
|
out = capsys.readouterr().out
|
|
return code, json.loads(out) if "--json" in args else out
|
|
|
|
|
|
def test_cli_end_to_end(example, capsys, tmp_path):
|
|
d = example("issue_triage")
|
|
g = str(d / "graph.yaml")
|
|
assert main(["convert", str(d / "graph.py"), g]) == 0
|
|
capsys.readouterr()
|
|
code, nodes = run_cli(capsys, "nodes", "list", "--json")
|
|
assert code == 0 and any(n["type"] == "llm.label" for n in nodes)
|
|
code, desc = run_cli(capsys, "nodes", "describe", "route.expr", "--json")
|
|
assert desc["kind"] == "route" and "routes" in desc["params_schema"]["properties"]
|
|
code, chk = run_cli(capsys, "check", g, "--json")
|
|
assert code == 0 and chk["ok"]
|
|
|
|
code, prev = run_cli(capsys, "preview", g, "--upto", "heuristics", "-n", "2", "--json", "--quiet")
|
|
assert code == 0 and len(prev["items"]) == 2 and "has_traceback" in prev["items"][0]["labels"]
|
|
|
|
bad = json.dumps([{"op": "set_param", "node": "route", "path": "routes.urgent", "value": "labels.severty >"}])
|
|
code, res = run_cli(capsys, "patch", g, bad, "--json")
|
|
assert code == 1 and not res["written"]
|
|
good = json.dumps([{"op": "add_node", "id": "short", "type": "sink.jsonl", "inputs": {"in": "substantive.rejected"},
|
|
"params": {"path": "out/short.jsonl"}}])
|
|
code, res = run_cli(capsys, "patch", g, good, "--json")
|
|
assert code == 0 and res["written"]
|
|
|
|
code, run = run_cli(capsys, "run", g, "--json", "--quiet")
|
|
assert code == 0 and run["status"] == "completed"
|
|
code, fun = run_cli(capsys, "funnel", g, "--json")
|
|
assert {"from": "substantive.rejected", "to": "short.in", "items": 2} in fun["edges"]
|
|
code, st = run_cli(capsys, "status", g, "--json")
|
|
assert st["run"]["status"] == "completed" and st["usage"][0]["calls"] == 10
|
|
code, its = run_cli(capsys, "items", g, "route", "--port", "urgent", "-n", "2", "--json")
|
|
assert its["total"] == 5 and len(its["items"]) == 2
|
|
code, lin = run_cli(capsys, "lineage", g, its["items"][0]["id"][:10], "--json")
|
|
assert [x["producer"] for x in lin["lineage"]][:3] == ["classify", "heuristics", "issues"]
|
|
out = tmp_path / "x.jsonl"
|
|
code, ex = run_cli(capsys, "export", g, "classify", "-o", str(out), "--fields", "key,labels.category", "--json")
|
|
assert ex["rows"] == 10 and out.read_text().count("\n") == 10
|
|
code, rep = run_cli(capsys, "report", g, "--json")
|
|
assert rep["path"].endswith(".html")
|
|
code, err = run_cli(capsys, "check", str(tmp_path / "missing.yaml"), "--json")
|
|
assert code == 2 and "not found" in err["error"]
|
|
|
|
|
|
def test_patch_schema(capsys):
|
|
assert main(["patch", "--schema"]) == 0
|
|
assert "add_node" in capsys.readouterr().out
|