mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-06-10 17:35:57 +00:00
fix: load paginated run history messages (#3305)
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
from _router_auth_helpers import make_authed_test_app
|
||||
from _run_message_pagination_helpers import assert_run_message_page
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.gateway.routers import runs
|
||||
@@ -97,6 +98,51 @@ def test_run_messages_has_more_true_when_extra_row_returned():
|
||||
body = response.json()
|
||||
assert body["has_more"] is True
|
||||
assert len(body["data"]) == 50 # trimmed to limit
|
||||
assert [m["seq"] for m in body["data"]] == list(range(2, 52))
|
||||
|
||||
|
||||
def test_run_messages_default_page_keeps_newest_messages_when_extra_row_returned():
|
||||
"""Default latest-page trimming drops the older sentinel row, not the newest message."""
|
||||
rows = [_make_message(i) for i in range(16, 67)]
|
||||
run_record = {"run_id": "run-2", "thread_id": "thread-2"}
|
||||
app = _make_app(
|
||||
run_store=_make_run_store(run_record),
|
||||
event_store=_make_event_store(rows),
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
assert_run_message_page(client, "/api/runs/run-2/messages", expected_seq=list(range(17, 67)))
|
||||
|
||||
|
||||
def test_run_messages_before_seq_page_keeps_newest_side_when_extra_row_returned():
|
||||
"""Backward pagination trims the older sentinel so adjacent pages do not miss the boundary message."""
|
||||
rows = [_make_message(i) for i in range(1, 18)]
|
||||
run_record = {"run_id": "run-2", "thread_id": "thread-2"}
|
||||
app = _make_app(
|
||||
run_store=_make_run_store(run_record),
|
||||
event_store=_make_event_store(rows),
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
assert_run_message_page(
|
||||
client,
|
||||
"/api/runs/run-2/messages?before_seq=18&limit=16",
|
||||
expected_seq=list(range(2, 18)),
|
||||
)
|
||||
|
||||
|
||||
def test_run_messages_after_seq_page_keeps_oldest_side_when_extra_row_returned():
|
||||
"""Forward pagination still trims the newer sentinel row."""
|
||||
rows = [_make_message(i) for i in range(11, 62)]
|
||||
run_record = {"run_id": "run-2", "thread_id": "thread-2"}
|
||||
app = _make_app(
|
||||
run_store=_make_run_store(run_record),
|
||||
event_store=_make_event_store(rows),
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
assert_run_message_page(
|
||||
client,
|
||||
"/api/runs/run-2/messages?after_seq=10",
|
||||
expected_seq=list(range(11, 61)),
|
||||
)
|
||||
|
||||
|
||||
def test_run_messages_passes_after_seq_to_event_store():
|
||||
|
||||
Reference in New Issue
Block a user