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:
@@ -102,7 +102,7 @@ class _AttemptOutcome:
|
||||
|
||||
|
||||
class OcrClient:
|
||||
"""治理化 OCR 入口: 同时实现 OcrTextPort 与 OcrLayoutPort(D9 端口族)。
|
||||
"""治理化 OCR 入口: 同时实现 OcrTextPort、OcrLayoutPort 与 OcrDocumentPort(D9 端口族;文档入口见 #34)。
|
||||
|
||||
两端点打同一服务实例池,共享同一 scope 的限流/熔断/选源状态;
|
||||
与其他 scope 共享后端实例即共享全局闸(显式传入,禁止隐式全局)。
|
||||
@@ -700,15 +700,17 @@ class OcrClient:
|
||||
def _summarize(result: _TransportResult) -> str:
|
||||
"""遥测行 response 摘要。**永不写入文档正文**:文档只记规模(元素数/页数/md 字数)。
|
||||
|
||||
用 isinstance 显式区分三类结果:旧的 `hasattr(result, "text")` 对没有顶层 `text` 的
|
||||
新结果会静默套成 layout 摘要,漏记 `md_chars`。
|
||||
**按结构分派而不是 isinstance**: 旧实现就是 `hasattr(result, "text")`,下游测试替身
|
||||
可能返回非库类型的鸭子对象,换成 isinstance 会让它们在开启遥测后以原生
|
||||
AttributeError 漏出。顺序要紧:文档结果有 `markdown`,先于只看 `text` 的判定,否则
|
||||
会被静默套成 layout 摘要而漏记 `md_chars`。
|
||||
"""
|
||||
if isinstance(result, OcrDocumentTransportResult):
|
||||
if hasattr(result, "markdown"):
|
||||
return (
|
||||
f"<document elements={len(result.elements)} pages={len(result.page_sizes)} "
|
||||
f"md_chars={len(result.markdown)}>"
|
||||
)
|
||||
if isinstance(result, OcrTextTransportResult):
|
||||
if hasattr(result, "text"):
|
||||
return result.text[:_RESPONSE_TEXT_CAP]
|
||||
return f"<elements n={len(result.elements)} pages={len(result.page_sizes)}>"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user