fix(analytics): run_full水位前置防回填窗口漏扫+README/DEPLOY/脚本号收尾

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-04 23:27:41 +08:00
parent 0fad1b09bb
commit 8499a74a72
5 changed files with 63 additions and 10 deletions
+39
View File
@@ -190,6 +190,45 @@ async def test_disposition_preserved(make_client):
await make_client(seed)
async def test_full_backfill_window_rows_scanned_by_incremental(
make_client, monkeypatch
):
"""回填窗口内新入库的行不漏:水位必须在词循环前取。
若 run_full 在词循环后才读 MAX(fetched_at),窗口内 commit 的行
fetched_at ≤ 水位,>= 增量也扫不到——首部署夜间回填与 02:00 全量
批写重叠时漏扫。m_max(无命中)垫高窗口内 MAX,锁死判别力。
"""
async def seed(session):
session.add(_msg("m1", "私单", dt.datetime(2026, 9, 4, 10, 0)))
await words_svc.create_word(session, word="私单")
await session.commit()
orig = scanner._scan_batch
fired = False
async def _hook(sess, word, rows):
nonlocal fired
if not fired: # 首个分片时模拟回填窗口内新消息入库
fired = True
sess.add(_msg("m_win", "窗口内私单", dt.datetime(2026, 9, 4, 11, 0)))
sess.add(_msg("m_max", "正常", dt.datetime(2026, 9, 4, 12, 0)))
await sess.commit()
return await orig(sess, word, rows)
monkeypatch.setattr(scanner, "_scan_batch", _hook)
await scanner.run_full(session) # 词行集已物化,窗口行不在其中
await session.commit()
st = await session.get(SensitiveScanState, "message_text")
# 水位是扫描前取的(10:00),未被窗口行推后
assert st.last_fetched_at == dt.datetime(2026, 9, 4, 10, 0)
r = await scanner.run_incremental(session)
await session.commit()
assert r["hits"] == 1 # 窗口内命中行(m_win)由增量补上
await make_client(seed)
# ------------------------------------------------------------- C1 命中列表/处置
async def test_hits_list_default_filter_and_dispose(make_client):