feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -601,6 +601,36 @@ def test_on_demand_evidence_returns_coordinates_merged_from_current_layout(app):
|
||||
assert restored['coordinate_evidence']['tables']['table-1'][0]['text'] == 'H'
|
||||
|
||||
|
||||
def test_on_demand_evidence_prefers_current_layout_coordinates_over_stale_run_snapshot(app):
|
||||
"""同页同时存在时,当前 Layout 是最新事实,不能被旧 Run 快照坐标覆盖。"""
|
||||
with app.app_context():
|
||||
document = _document()
|
||||
current = record_inline_layout_snapshot(document, {
|
||||
**_snapshot(),
|
||||
'coordinate_evidence': {
|
||||
'pages': {'1': {'width': 100, 'height': 200}},
|
||||
'page_glyphs': {'1': [{'text': 'CURRENT', 'bbox': {'x0': 1, 'y0': 1, 'x1': 2, 'y1': 2}}]},
|
||||
'sources': {'pages': {'1': 'pdf_coordinate'}},
|
||||
},
|
||||
})
|
||||
document.current_layout_version = current
|
||||
stale_run_layout = {
|
||||
**_snapshot(),
|
||||
'coordinate_evidence': {
|
||||
'pages': {'1': {'width': 100, 'height': 200}},
|
||||
'page_glyphs': {'1': [{'text': 'STALE', 'bbox': {'x0': 1, 'y0': 1, 'x1': 2, 'y1': 2}}]},
|
||||
'sources': {'pages': {'1': 'ocr_coordinate'}},
|
||||
},
|
||||
}
|
||||
|
||||
restored = ensure_on_demand_coordinate_evidence(
|
||||
document=document, layout=stale_run_layout, page_nos={1},
|
||||
)
|
||||
|
||||
assert restored['coordinate_evidence']['page_glyphs']['1'][0]['text'] == 'CURRENT'
|
||||
assert restored['coordinate_evidence']['sources']['pages']['1'] == 'pdf_coordinate'
|
||||
|
||||
|
||||
def test_on_demand_evidence_restores_every_table_on_the_same_page(app, monkeypatch):
|
||||
"""同一页存在多张物理表时,每个 table_id 都必须获得独立坐标字符证据。"""
|
||||
with app.app_context():
|
||||
@@ -644,6 +674,35 @@ def test_on_demand_evidence_restores_every_table_on_the_same_page(app, monkeypat
|
||||
}
|
||||
|
||||
|
||||
def test_on_demand_evidence_leaves_coordinates_missing_when_native_and_ocr_fail(app, monkeypatch):
|
||||
"""原 PDF 无字符且 OCR 不可用时不得伪造坐标,调用方必须转 Review。"""
|
||||
with app.app_context():
|
||||
document = _document()
|
||||
layout = {
|
||||
**_snapshot(),
|
||||
'tables': [{'table_id': 'table-1', 'page_no': 1, 'bbox': {'x0': 0, 'y0': 0, 'x1': 100, 'y1': 80}}],
|
||||
'coordinate_evidence': {'pages': {'1': {'width': 100, 'height': 200}}},
|
||||
}
|
||||
page = SimpleNamespace(page_no=1, width=100, height=200, image=None, characters=[])
|
||||
monkeypatch.setattr(
|
||||
'app.services.file_assets.service.read_asset_bytes', lambda _asset: b'%PDF-test',
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.document_layout.native_pdf.extract_native_pdf_pages',
|
||||
lambda _content: [page],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.document_layout.ocr_pdf.extract_ocr_lines',
|
||||
lambda *_args, **_kwargs: (_ for _ in ()).throw(RuntimeError('ocr unavailable')),
|
||||
)
|
||||
|
||||
restored = ensure_on_demand_coordinate_evidence(
|
||||
document=document, layout=layout, page_nos={1},
|
||||
)
|
||||
|
||||
assert not restored['coordinate_evidence'].get('page_glyphs')
|
||||
|
||||
|
||||
def test_layout_document_budget_creates_unsupported_audit_versions(app):
|
||||
"""超过单 Intake 配额的支持附件必须有 unsupported 审计,不能静默跳过。"""
|
||||
app.config['SHIPPING_NOTICE_LAYOUT_MINERU_ENABLED'] = True
|
||||
|
||||
Reference in new issue
Block a user