fix(artifact): 类型误标回退 + 服务端阻断判可重试 + 空白单元格重读
build / build (push) Successful in 23s

压测/取件实测暴露的三类问题(均在真实 worker 容器里复现并已验证修复):
- 名为 .axls 实为 docx 的节点(清单扩展名与真实类型不符):dws 明确回报真实类型
  → 回退 drive download 取原始字节(实测该节点 243,949B docx 可正常取到),
  不再直接失败
- server model operate block 判可重试:同一节点 5 连测 3/5 成功(另一支 timeout),
  原判终态会把可成功节点永久失败
- axls 大表偶发返回全空单元格(12 次取件出现 1 次):全空时重读一次再上报,
  避免被平台空壳判定当「空文档」终态

新增 3 个回归测试(18 tests / 19 断言全绿)
This commit is contained in:
姚章浩
2026-10-09 12:15:22 +08:00
parent 6496ee3571
commit 9155bd3170
5 changed files with 83 additions and 4 deletions
+42
View File
@@ -212,6 +212,48 @@ class DingTalkDwsFetcherTest(unittest.TestCase):
self.assertEqual(raised.exception.code, "forbidden")
self.assertFalse(raised.exception.retryable)
def test_axls_with_wrong_extension_falls_back_to_drive_download(self):
# 实测:名为 .axls 实为 docx(清单扩展名与真实类型不符)。dws 会告知真实类型
# → 取原始字节,交给平台既有校验,而不是直接失败。
calls = []
def fake_run(args, timeout=300, cwd=None):
calls.append(args[:2])
if args[:2] == ["drive", "+download"]:
pathlib.Path(cwd, "out.docx").write_bytes(b"PK\x03\x04" + b"w" * 100)
return {"success": True}, self.ok_verdict
self.fail("不应走其它路径: %s" % args[:3])
with mock.patch.object(artifact_fetch, "DINGTALK_FETCHER", "dws"), \
mock.patch.object(artifact_fetch, "dingtalk_raw_keys", return_value=("raw-14", "file")), \
mock.patch.object(artifact_fetch, "dws_run", side_effect=fake_run), \
mock.patch.object(artifact_fetch.axls_to_xlsx, "fetch_sheets",
side_effect=artifact_fetch.axls_to_xlsx.DwsCallError(
"当前节点不是钉钉表格(扩展名=axls),无法使用表格相关工具操作。"
"当前文档类型:docx。请确认 nodeId 指向的是钉钉表格文件")):
path, size, digest, matched, fetcher = artifact_fetch.dingtalk_download(
{**self.manifest, "name": "各机型易损件清单.axls", "declared_type": "axls"}, 200_000_000)
self.assertEqual(calls, [["drive", "+download"]])
self.assertEqual(fetcher, "dws")
self.assertEqual(size, 104)
def test_axls_blank_read_is_retried_once(self):
# 大表偶发返回全空单元格:重读一次拿到数据时不得上报空白
empty_first = {"n": 0}
def flaky(args, timeout=180):
if args[:2] == ["sheet", "list"]:
return {"sheets": [{"sheetId": "st-1", "name": "S1"}]}
empty_first["n"] += 1
return {"cells": [] if empty_first["n"] == 1 else [["机型", "部件"]]}
with mock.patch.object(artifact_fetch.axls_to_xlsx, "run_json", side_effect=flaky):
sheets = artifact_fetch.axls_to_xlsx.fetch_sheets("raw-15")
self.assertEqual(empty_first["n"], 2, "全空后必须重读一次")
self.assertTrue(sheets[0]["cells"])
def test_link_and_mind_nodes_map_to_missing_and_unsupported(self):
cases = (("dlink", "链接节点.dlink", "missing", True),
("amind", "培训大纲.amind", "unsupported_format", False))