From 4518e8d449d71232fae1e06155c9aac9fc126816 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Wed, 20 May 2026 08:32:54 +0800 Subject: [PATCH] auto-sync: 2026-05-20 08:32:54 --- tests/test_e2e_v27.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_e2e_v27.py b/tests/test_e2e_v27.py index ac968ba..a8b0ab7 100644 --- a/tests/test_e2e_v27.py +++ b/tests/test_e2e_v27.py @@ -728,6 +728,34 @@ def _cleanup_project(pid: str): pass +def _poll_task(pid, tid, timeout, terminal_states=None): + """轮询任务状态直到终态或超时""" + terminal = terminal_states or ("done", "failed", "cancelled") + deadline = time.time() + timeout + last_status = None + while time.time() < deadline: + try: + resp = http_requests.get( + f"{API_BASE}/api/projects/{pid}/tasks/{tid}", timeout=10 + ) + if resp.status_code == 200: + data = resp.json() + last_status = data.get("status") + if last_status in terminal: + return data + except Exception: + pass + time.sleep(POLL_INTERVAL) + # 超时,返回最后状态 + try: + resp = http_requests.get( + f"{API_BASE}/api/projects/{pid}/tasks/{tid}", timeout=10 + ) + return resp.json() if resp.status_code == 200 else {"status": "unknown"} + except Exception: + return {"status": "unknown"} + + @pytest.mark.integration @pytest.mark.skipif(not os.environ.get("RUN_INTEGRATION"), reason="Set RUN_INTEGRATION=1 to run real agent tests")