1) 客服 Agent 四份交付文档 + 构建脚手架:品牌由包装占位 XX科技 / 旧名 南方财富 统一为南方基金(热线 400-889-8899 / 官网 nffund.com),系统名改为「智能服务系统」; 同步追加 §0.4 修订记录行,工程记录行保留原占位字面以支撑硬编码扫描验收。 2) 开发文档:清理 28 份已作废/残留文档(14 份移出归档 + 14 份仓库副本), 新增《文档规整方案与开发前待决事项-2026-09-17》。 3) 客服agent 四份交付文档首次纳入本分支。
69 lines
3.3 KiB
Python
69 lines
3.3 KiB
Python
"""消息列表游标的真实数据库验证(文档 §3.8 游标分页、§16.1 非法游标 400)。
|
|
|
|
单元测试用替身证明了"校验 → 透传"这条链,但"游标真的改变返回哪一页"只有真实
|
|
MySQL 能证明:`before` 边界最终会变成一条 `id < :cursor` 的 SQL 条件,写错了(例如
|
|
方向反了、被当成 `id > :cursor`、或 Python 侧过滤丢掉跨页一致性)单元测试看不出来。
|
|
|
|
本用例只写自己的临时会话数据,结束时全部删除;不依赖 Worker,也不依赖常驻队列。
|
|
"""
|
|
|
|
from datetime import UTC, datetime
|
|
from uuid import uuid4
|
|
|
|
import httpx
|
|
import pytest
|
|
from sqlalchemy import delete
|
|
|
|
from app.api.dependencies.auth import build_request_context
|
|
from app.core.contracts import RequestContext
|
|
from app.infrastructure.db import SessionFactory
|
|
from app.main import create_app
|
|
from app.model.conversation import ConversationMessage
|
|
|
|
# 依赖真实 MySQL:必须打 integration marker,否则按 marker 过滤时会漏测这批用例。
|
|
pytestmark = pytest.mark.integration
|
|
|
|
CUSTOMER_ID = 9001 # tools/seed_test_rbac.py 造的数据
|
|
|
|
|
|
async def test_cursor_walks_pages_and_invalid_cursor_is_rejected() -> None:
|
|
session_id = f"cursor-{uuid4()}"
|
|
now = datetime.now(UTC).replace(tzinfo=None)
|
|
async with SessionFactory() as session, session.begin():
|
|
session.add_all([
|
|
ConversationMessage(session_id=session_id, customer_id=CUSTOMER_ID,
|
|
portal="customer_chat", role="user", content=f"m{index}",
|
|
created_at=now)
|
|
for index in range(3)
|
|
])
|
|
|
|
context = RequestContext(user_id=str(CUSTOMER_ID), trace_id=str(uuid4()),
|
|
roles=("customer",), permissions=())
|
|
application = create_app()
|
|
application.dependency_overrides[build_request_context] = lambda: context
|
|
path = f"/api/v1/conversations/{session_id}/messages"
|
|
try:
|
|
async with httpx.AsyncClient(transport=httpx.ASGITransport(app=application),
|
|
base_url="http://test") as client:
|
|
first = await client.get(path, params={"limit": 2})
|
|
assert first.status_code == 200
|
|
page = first.json()["data"]
|
|
assert [item["content"] for item in page] == ["m2", "m1"]
|
|
|
|
# 用上一页最后一条的 message_id 作游标:必须取到更旧的一页,而不是重复第一页。
|
|
second = await client.get(path, params={"limit": 2, "cursor": page[-1]["message_id"]})
|
|
assert [item["content"] for item in second.json()["data"]] == ["m0"]
|
|
|
|
# 走到头:再往前没有数据,返回空集合而不是报错、也不是回到第一页。
|
|
last = second.json()["data"][-1]["message_id"]
|
|
third = await client.get(path, params={"limit": 2, "cursor": last})
|
|
assert third.json()["data"] == []
|
|
|
|
invalid = await client.get(path, params={"cursor": "abc"})
|
|
assert invalid.status_code == 400
|
|
assert invalid.json()["error"]["code"] == "INVALID_CURSOR"
|
|
finally:
|
|
async with SessionFactory() as session, session.begin():
|
|
await session.execute(delete(ConversationMessage).where(
|
|
ConversationMessage.session_id == session_id))
|