From 2baa6d08141c0f73197cc1d9cec702c6aacf06ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Tue, 25 Aug 2026 16:22:44 +0800 Subject: [PATCH] =?UTF-8?q?test(moments):=20=E5=90=8Ccreate=5Ftime?= =?UTF-8?q?=E5=B9=B6=E5=88=97=E6=97=B6=E6=8C=89id=E5=8D=87=E5=BA=8Ftiebrea?= =?UTF-8?q?k=E6=B5=8B=E8=AF=95(=E9=94=81=E5=88=86=E9=A1=B5=E7=A8=B3?= =?UTF-8?q?=E5=AE=9A=E5=A5=91=E7=BA=A6,=E4=BB=BB=E5=8A=A16=E8=AF=84?= =?UTF-8?q?=E5=AE=A1=E9=81=97=E7=95=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- yunke-server/tests/test_api_moments.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/yunke-server/tests/test_api_moments.py b/yunke-server/tests/test_api_moments.py index 0e238a6..a4f5770 100644 --- a/yunke-server/tests/test_api_moments.py +++ b/yunke-server/tests/test_api_moments.py @@ -77,3 +77,28 @@ async def test_moments_pagination(make_client): assert b1["total"] == b2["total"] == 3 # alias 非空时映射到 header(列直读) assert b1["header"]["alias"] == "al_o" + + +async def test_moments_same_create_time_tiebreak_id_asc(make_client): + """同 create_time(秒级来源×1000 必然同值)→ 按 id 升序稳定排列。 + + 锁死分页稳定契约:tie-break 缺失会让同秒帖跨页漂移(每页 offset 重查 + 时顺序抖动 → 重复/丢帖)。任务 6 评审遗留补测。 + """ + + async def seed(s: AsyncSession): + s.add(WechatAccount(wx_id=STAFF, nick_name="员工昵称")) + s.add_all([ + MomentsPost(id="pz", wechat_id=STAFF, create_time=200, content="z"), + MomentsPost(id="pa", wechat_id=STAFF, create_time=200, content="a"), + MomentsPost(id="pb", wechat_id=STAFF, create_time=200, content="b"), + ]) + await s.commit() + + client = await make_client(seed) + b1 = (await client.get("/api/moments", params={"wechat_id": STAFF, "page": 1, "page_size": 2})).json() + b2 = (await client.get("/api/moments", params={"wechat_id": STAFF, "page": 2, "page_size": 2})).json() + # create_time desc 全并列 → id 升序断尾:pa, pb | pz + assert [p["id"] for p in b1["items"]] == ["pa", "pb"] + assert [p["id"] for p in b2["items"]] == ["pz"] + assert b1["total"] == b2["total"] == 3