test: verify workflow run details

This commit is contained in:
2026-06-13 18:46:04 +08:00
parent dd6cbf8e90
commit 22fb065ed8
2 changed files with 26 additions and 14 deletions
@@ -75,6 +75,30 @@ def _unwrap(payload: Any) -> Any:
return payload 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: async def verify(args: argparse.Namespace) -> int:
base_url = args.base_url.rstrip("/") base_url = args.base_url.rstrip("/")
client = ApiClient(base_url=base_url, timeout=args.timeout) 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": if workflow.get("status") != "published":
raise RuntimeError(f"workflow is not published: {workflow.get('status')}") raise RuntimeError(f"workflow is not published: {workflow.get('status')}")
runs_data = _unwrap(await client.get("/api/ai/workflow/runs?page=1&pageSize=20")) run_detail = await _find_completed_issue_run(client, workflow.get("id"), args.issue)
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']}"))
execution_log = run_detail.get("execution_log") or [] execution_log = run_detail.get("execution_log") or []
if len(execution_log) < args.min_steps: if len(execution_log) < args.min_steps:
raise RuntimeError(f"execution log too short: {len(execution_log)} < {args.min_steps}") raise RuntimeError(f"execution log too short: {len(execution_log)} < {args.min_steps}")
+1 -1
View File
@@ -16,7 +16,7 @@ SEED_MULTICA_AGENTS="${SEED_MULTICA_AGENTS:-1}"
BUILD_WEB="${BUILD_WEB:-0}" BUILD_WEB="${BUILD_WEB:-0}"
VERIFY_RUNTIME="${VERIFY_RUNTIME:-1}" VERIFY_RUNTIME="${VERIFY_RUNTIME:-1}"
VERIFY_BASE_URL="${VERIFY_BASE_URL:-http://127.0.0.1:${BACKEND_PORT}}" VERIFY_BASE_URL="${VERIFY_BASE_URL:-http://127.0.0.1:${BACKEND_PORT}}"
VERIFY_USERNAME="${VERIFY_USERNAME:-superadmin}" VERIFY_USERNAME="${VERIFY_USERNAME:-zhangwei}"
VERIFY_PASSWORD="${VERIFY_PASSWORD:-123456}" VERIFY_PASSWORD="${VERIFY_PASSWORD:-123456}"
VERIFY_ATTEMPTS="${VERIFY_ATTEMPTS:-6}" VERIFY_ATTEMPTS="${VERIFY_ATTEMPTS:-6}"
VERIFY_SLEEP_SECONDS="${VERIFY_SLEEP_SECONDS:-5}" VERIFY_SLEEP_SECONDS="${VERIFY_SLEEP_SECONDS:-5}"