test: verify workflow run details
This commit is contained in:
@@ -75,6 +75,30 @@ def _unwrap(payload: Any) -> Any:
|
||||
return payload
|
||||
|
||||
|
||||
async def _find_completed_issue_run(
|
||||
client: ApiClient,
|
||||
workflow_id: str,
|
||||
issue: str,
|
||||
) -> dict[str, Any]:
|
||||
runs_data = _unwrap(await client.get("/api/ai/workflow/runs?page=1&pageSize=50"))
|
||||
runs = runs_data.get("items", runs_data) if isinstance(runs_data, dict) else runs_data
|
||||
candidates = [
|
||||
run
|
||||
for run in runs
|
||||
if run.get("workflow_id") == workflow_id and run.get("status") == "completed"
|
||||
]
|
||||
issue_text = issue.lower()
|
||||
for run in candidates:
|
||||
run_detail = _unwrap(await client.get(f"/api/ai/workflow/runs/{run['id']}"))
|
||||
searchable = " ".join(
|
||||
_preview(run_detail.get(key), 2000)
|
||||
for key in ("inputs", "outputs", "execution_log")
|
||||
).lower()
|
||||
if issue_text in searchable:
|
||||
return run_detail
|
||||
raise RuntimeError(f"completed run not found for issue: {issue}")
|
||||
|
||||
|
||||
async def verify(args: argparse.Namespace) -> int:
|
||||
base_url = args.base_url.rstrip("/")
|
||||
client = ApiClient(base_url=base_url, timeout=args.timeout)
|
||||
@@ -116,19 +140,7 @@ async def verify(args: argparse.Namespace) -> int:
|
||||
if workflow.get("status") != "published":
|
||||
raise RuntimeError(f"workflow is not published: {workflow.get('status')}")
|
||||
|
||||
runs_data = _unwrap(await client.get("/api/ai/workflow/runs?page=1&pageSize=20"))
|
||||
runs = runs_data.get("items", runs_data) if isinstance(runs_data, dict) else runs_data
|
||||
matching_runs = [
|
||||
run
|
||||
for run in runs
|
||||
if run.get("workflow_id") == workflow.get("id")
|
||||
and run.get("status") == "completed"
|
||||
and args.issue.lower() in _preview(run.get("inputs"), 1000).lower()
|
||||
]
|
||||
if not matching_runs:
|
||||
raise RuntimeError(f"completed run not found for issue: {args.issue}")
|
||||
|
||||
run_detail = _unwrap(await client.get(f"/api/ai/workflow/runs/{matching_runs[0]['id']}"))
|
||||
run_detail = await _find_completed_issue_run(client, workflow.get("id"), args.issue)
|
||||
execution_log = run_detail.get("execution_log") or []
|
||||
if len(execution_log) < args.min_steps:
|
||||
raise RuntimeError(f"execution log too short: {len(execution_log)} < {args.min_steps}")
|
||||
|
||||
Reference in New Issue
Block a user