sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -146,6 +146,20 @@ async def test_waves_researcher_before_writer_and_text_does_not_complete() -> No
|
||||
assert "session.snapshot" in types
|
||||
assert "message.created" in types
|
||||
assert "message.delta" in types
|
||||
research_statuses = [
|
||||
item["data"]["status"]
|
||||
for item in events
|
||||
if item["type"] == "node.status.changed" and item["data"].get("node_id") == "research"
|
||||
]
|
||||
assert research_statuses == ["queued", "running", "validating", "completed"]
|
||||
running_index = next(
|
||||
index
|
||||
for index, item in enumerate(events)
|
||||
if item["type"] == "node.status.changed"
|
||||
and item["data"].get("node_id") == "research"
|
||||
and item["data"].get("status") == "running"
|
||||
)
|
||||
assert running_index < types.index("message.created")
|
||||
advice = [item for item in events if item["type"] == "heartbeat" and (item.get("data") or {}).get("kind") == "coordinator_advice"]
|
||||
assert advice
|
||||
assert advice[0]["data"]["ignored"] is True
|
||||
@@ -155,6 +169,89 @@ async def test_waves_researcher_before_writer_and_text_does_not_complete() -> No
|
||||
assert phases[f"{run_id}-research-attempt1"] != phases[f"{run_id}-write-attempt1"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_command_rework_cascades_downstream_and_reruns_in_order() -> None:
|
||||
"""P0.3 指定重跑级联:重跑 research 后 write 被级联 superseded 并按依赖序重跑。"""
|
||||
|
||||
store = MemoryReportCollaborationStore()
|
||||
run_id = await _boot(store)
|
||||
kernel = ScriptedMemberKernel()
|
||||
kernel.enqueue("research", TaskResult(kind="artifact_draft", artifact_type="EvidenceBundle", artifact_draft=_evidence()))
|
||||
kernel.enqueue("write", TaskResult(kind="artifact_draft", artifact_type="ReportSectionDraft", artifact_draft=_draft()))
|
||||
executor = WaveExecutor(store, kernel)
|
||||
assert await executor.run_until_idle(run_id) == "completed"
|
||||
|
||||
ledger = TaskLedger(store)
|
||||
changed = await ledger.apply_command_rework(
|
||||
run_id,
|
||||
command_id="cmd-cascade-1",
|
||||
instruction="重新查,重点看价格战",
|
||||
node_ids=["research"],
|
||||
cascade_downstream=True,
|
||||
)
|
||||
assert set(changed) == {"research", "write"}
|
||||
|
||||
nodes = await store.list_node_runs(run_id)
|
||||
by_node: dict[str, list[dict]] = {}
|
||||
for item in nodes:
|
||||
by_node.setdefault(item["node_id"], []).append(item)
|
||||
research_attempts = {item["attempt"]: item["status"] for item in by_node["research"]}
|
||||
write_attempts = {item["attempt"]: item["status"] for item in by_node["write"]}
|
||||
assert research_attempts[1] == "superseded" and research_attempts[2] == "planned"
|
||||
assert write_attempts[1] == "superseded" and write_attempts[2] == "planned"
|
||||
events = [item for item in await store.list_events(run_id) if item["type"] == "node.status.changed"]
|
||||
cascade_events = [item for item in events if (item.get("data") or {}).get("reason") == "downstream_cascade"]
|
||||
assert cascade_events and cascade_events[0]["data"]["node_id"] == "write"
|
||||
|
||||
kernel2 = ScriptedMemberKernel()
|
||||
kernel2.enqueue("research", TaskResult(kind="artifact_draft", artifact_type="EvidenceBundle", artifact_draft=_evidence("价格战证据")))
|
||||
kernel2.enqueue("write", TaskResult(kind="artifact_draft", artifact_type="ReportSectionDraft", artifact_draft=_draft()))
|
||||
executor2 = WaveExecutor(store, kernel2)
|
||||
assert await executor2.run_until_idle(run_id) == "completed"
|
||||
assert executor2.dispatched == ["research", "write"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_exhausted_interrupted_node_fails_run_instead_of_zombie() -> None:
|
||||
"""P0.2 僵尸 run 守卫:attempt 耗尽的 interrupted 节点应让 run 进入 failed。"""
|
||||
|
||||
store = MemoryReportCollaborationStore()
|
||||
run_id = await _boot(store, _plan(max_attempts=2))
|
||||
# 模拟两次崩溃被 recovery 打断后 attempt 耗尽:research attempt2 interrupted。
|
||||
nodes = await store.list_node_runs(run_id)
|
||||
research = next(item for item in nodes if item["node_id"] == "research")
|
||||
research["attempt"] = 2
|
||||
research["status"] = "interrupted"
|
||||
research["error"] = "lease_reclaimed"
|
||||
await store.save_node_run(research)
|
||||
write = next(item for item in nodes if item["node_id"] == "write")
|
||||
write["status"] = "planned"
|
||||
|
||||
executor = WaveExecutor(store, ScriptedMemberKernel())
|
||||
status = await executor.run_until_idle(run_id)
|
||||
assert status == "failed"
|
||||
run = await store.get_run(run_id)
|
||||
assert run["status"] == "failed"
|
||||
events = [item for item in await store.list_events(run_id) if item["type"] == "run.status.changed"]
|
||||
assert events and events[-1]["data"]["reason"] == "node_attempts_exhausted"
|
||||
assert events[-1]["data"]["node_id"] == "research"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_interrupted_with_budget_left_keeps_run_alive() -> None:
|
||||
"""未耗尽的 interrupted 节点仍留给 recovery 补开 attempt,不能提前 fail。"""
|
||||
|
||||
store = MemoryReportCollaborationStore()
|
||||
run_id = await _boot(store, _plan(max_attempts=3))
|
||||
nodes = await store.list_node_runs(run_id)
|
||||
research = next(item for item in nodes if item["node_id"] == "research")
|
||||
research["attempt"] = 1
|
||||
research["status"] = "interrupted"
|
||||
await store.save_node_run(research)
|
||||
ledger = TaskLedger(store)
|
||||
assert await ledger.refresh_run_terminal(run_id) != "failed"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_parallel_researchers_share_phase() -> None:
|
||||
store = MemoryReportCollaborationStore()
|
||||
@@ -221,6 +318,23 @@ async def test_member_failure_does_not_complete_run_until_cap() -> None:
|
||||
assert run["status"] == "failed"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_member_exception_becomes_node_failure_instead_of_crashing_executor() -> None:
|
||||
store = MemoryReportCollaborationStore()
|
||||
run_id = await _boot(store, _plan(max_attempts=1))
|
||||
|
||||
class RaisingKernel:
|
||||
async def run(self, assignment, *, context):
|
||||
raise RuntimeError("model unavailable")
|
||||
|
||||
executor = WaveExecutor(store, RaisingKernel())
|
||||
assert await executor.run_until_idle(run_id) == "failed"
|
||||
nodes = await store.list_node_runs(run_id)
|
||||
research = next(item for item in nodes if item["node_id"] == "research")
|
||||
assert research["status"] == "failed"
|
||||
assert "MEMBER_EXECUTION_ERROR:RuntimeError:model unavailable" in research["error"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_coordinator_cannot_dispatch_writer() -> None:
|
||||
store = MemoryReportCollaborationStore()
|
||||
|
||||
Reference in new issue
Block a user