sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -35,6 +35,44 @@ async def test_event_persistence_failure_keeps_job_live_and_emits_unique_fallbac
|
||||
assert published[1]["liveId"] == "event-persistence-fallback:drj_1:2"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_event_persistence_hang_does_not_block_the_writer(monkeypatch):
|
||||
"""A stuck MySQL append must not wait for cancel; writing continues live-only."""
|
||||
import asyncio
|
||||
|
||||
from deerflow.agents.deep_research.adapters import event_sink as sink_mod
|
||||
|
||||
monkeypatch.setattr(sink_mod, "_EVENT_PERSIST_TIMEOUT_SECONDS", 0.05)
|
||||
published: list[dict] = []
|
||||
released = asyncio.Event()
|
||||
|
||||
class _HungEventRepository:
|
||||
async def append(self, **kwargs): # noqa: ANN003
|
||||
await released.wait()
|
||||
raise RuntimeError("still hung")
|
||||
|
||||
async def publish(event: dict) -> None:
|
||||
published.append(event)
|
||||
|
||||
sink = PersistingEventSink(
|
||||
_HungEventRepository(),
|
||||
session_id="drs_1",
|
||||
job_id="drj_1",
|
||||
on_event=publish,
|
||||
)
|
||||
|
||||
event = await asyncio.wait_for(
|
||||
sink.emit("phase_changed", phase="writing", payload={"to": "writing"}),
|
||||
timeout=1.0,
|
||||
)
|
||||
released.set()
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert event.payload["eventPersistenceDegraded"] is True
|
||||
assert published
|
||||
assert published[0]["type"] == "phase_changed"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_publish_failure_does_not_fail_event_delivery():
|
||||
class _EventRepository:
|
||||
@@ -84,14 +122,8 @@ def _mirrored(repo: _RecordingEventRepository, event_type: str) -> list[dict]:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reasoning_frames_are_mirrored_durably_when_no_viewer_is_on_this_worker():
|
||||
"""Multi-worker guard: thinking must not vanish into a subscriber-less hub.
|
||||
|
||||
A job runs on the worker that won its lease while the SSE connection is
|
||||
served by whichever worker accepted it. Live-only frames published into an
|
||||
empty in-process hub are lost with no durable row to replay them from,
|
||||
which is what silently removed the step bar's thinking text.
|
||||
"""
|
||||
async def test_reasoning_frames_are_not_persisted_while_writing():
|
||||
"""Live thinking must not wait on the event table. The finished report is stored later."""
|
||||
repo = _RecordingEventRepository()
|
||||
sink = PersistingEventSink(
|
||||
repo,
|
||||
@@ -108,13 +140,7 @@ async def test_reasoning_frames_are_mirrored_durably_when_no_viewer_is_on_this_w
|
||||
payload={"delta": "思" * 240, "target": "report", "reportVersion": 1},
|
||||
)
|
||||
|
||||
mirrored = _mirrored(repo, "report_thinking")
|
||||
assert mirrored, "reasoning must be persisted when the hub has no subscriber"
|
||||
assert "".join(row["payload"]["delta"] for row in mirrored) == "思" * 720
|
||||
assert mirrored[0]["payload"]["liveMirror"] is True
|
||||
assert mirrored[0]["payload"]["target"] == "report"
|
||||
# Coalesced, never one row per provider token.
|
||||
assert len(mirrored) == 1
|
||||
assert repo.rows == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -157,7 +183,7 @@ async def test_report_text_is_never_mirrored_and_the_tail_flushes_before_the_nex
|
||||
|
||||
await sink.emit("report_completed", phase="writing", payload={})
|
||||
|
||||
assert [row["event_type"] for row in repo.rows] == ["report_thinking", "report_completed"]
|
||||
assert [row["event_type"] for row in repo.rows] == ["report_completed"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in new issue
Block a user