fix(cash): vouchers-json batch改为纯内容指纹(不含时间戳) — 快照每10分钟重推必须幂等命中

- batch=zxt-{sha1前10},同内容任意时刻重推 → 同一batch → already_imported跳过
- 原带秒级时间戳导致指纹去重失效(靠行级防重兜底,但会产生噪音import_logs)
- 验收脚本补用例4b(三次重发batch不变+already_imported), 13/13 PASS
This commit is contained in:
Hermes CI Fix
2026-09-06 16:47:25 +08:00
parent 3db805db4e
commit 594bb00a38
2 changed files with 9 additions and 2 deletions
+2 -2
View File
@@ -313,9 +313,9 @@ def api_import_vouchers_json(
success = len(valid_rows)
failed = len(errors)
# ── 幂等:batch 指纹去重 ──
# ── 幂等:batch 内容指纹去重(batch 不含时间戳——同内容快照每10分钟重推必须命中同一 batch)──
fingerprint = _content_fingerprint(rows_raw)
batch = f"zxt-{datetime.now().strftime('%Y%m%d%H%M%S')}-{fingerprint}"
batch = f"zxt-{fingerprint}"
existing_batch = db.query(ImportLog).filter(
ImportLog.batch == batch,
ImportLog.import_type == "vouchers-json",
@@ -94,6 +94,13 @@ r4 = client.post("/api/cma/cash/import/vouchers-json", json=payload, headers=HDR
j4 = r4.json()
results.append(check("用例4 同指纹重复导入 already_imported", r4.status_code == 200 and j4.get("already_imported") is True, f"body={r4.text[:200]}"))
# ── 用例4b: 同内容不同「模拟时间」仍同 batch → 幂等(batch 不含时间戳)──
def j4b_is_already(resp, j4):
j = resp.json()
return j.get("already_imported") is True and j.get("batch") == j4.get("batch")
r4b = client.post("/api/cma/cash/import/vouchers-json", json=payload, headers=HDR)
results.append(check("用例4b 再次重发仍 already_imported 且 batch 不变", r4b.status_code == 200 and j4b_is_already(r4b, j4), f"body={r4b.text[:200]}"))
# ── 用例5: 无 X-BOT-KEY → 401 ──
r5 = client.post("/api/cma/cash/import/vouchers-json", json=payload)
results.append(check("用例5 无X-BOT-KEY 401", r5.status_code == 401, f"status={r5.status_code}"))