fix: close adversarial review findings on document parsing

Malformed download URLs are rejected before the second request, error bodies are read only up to a bound, the telemetry summary keeps structural dispatch for duck-typed results, and the BMP magic now requires a valid DIB header. Docs and design are aligned with the implementation, and new test wording is neutral.
This commit is contained in:
2026-10-22 02:09:06 -04:00
parent bb621cad4d
commit cb1e08f1f3
10 changed files with 180 additions and 25 deletions
+3 -3
View File
@@ -2,7 +2,7 @@
fixtures 全部**合成**: 保留 2026-10-21 实测的结构骨架(para_blocks 的块类型、
table/image 的嵌套 `blocks`、span 字段),一切识别文本替换为 `SYNTH-*` 占位——
第三方论文内容许可不明、医疗数据不入库(零业务假设 + P5),真实 ZIP 不提交。
第三方文档内容许可不明、敏感数据不入库(零业务假设 + P5),真实 ZIP 不提交。
契约表逐行一条,参数化列明各分支。解析函数是 bytes → 结果的纯函数,失败一律
`ResultInvalidError`,**不得漏出原生异常**(漏出会让 `OcrClient._call` 既不写终态遥测
@@ -498,7 +498,7 @@ class TestExternalDataExceptionBoundary:
class TestLayoutPathUntouched:
"""文档路径更严/更宽的口径不得外溢到医院线在用的 layout 解析。"""
"""文档路径更严/更宽的口径不得外溢到既有调用方在用的 layout 解析。"""
def test_layout_parser_still_rejects_degenerate_int_boxes(self):
from polygateway.transports.monkey_ocr import _parse_middle_json
@@ -510,7 +510,7 @@ class TestLayoutPathUntouched:
def test_layout_parser_keeps_its_lenient_page_idx_handling(self):
"""layout 路径: 合法的非负整数 `page_idx` 原样接受(哪怕与页序不符),非法值才回退
枚举下标——这正是文档路径改为严格的原因,但医院线的既有行为不得被连带改动。"""
枚举下标——这正是文档路径改为严格的原因,但既有调用方的行为不得被连带改动。"""
from polygateway.transports.monkey_ocr import _parse_middle_json
accepted, _ = _parse_middle_json(_package([_page([_text_block()], page_idx=7)]))