feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -56,6 +56,54 @@ def test_layout_job_completes_version_and_updates_document_current(app):
|
||||
assert version.lease_token is None
|
||||
assert document.current_layout_version_id == version.id
|
||||
assert job.status == 'success'
|
||||
assert job.result_json['status'] == 'ready'
|
||||
assert job.result_json['provider_status'] == 'ready'
|
||||
assert job.message == '文档版面解析完成'
|
||||
|
||||
|
||||
def test_layout_job_reports_compacted_recoverable_pdf_as_success(app):
|
||||
"""表内坐标可按需恢复时 Job/Layout 成功,并保留模板解析所需表格结构。"""
|
||||
app.config['SHIPPING_NOTICE_LAYOUT_MAX_SNAPSHOT_BYTES'] = 700
|
||||
with app.app_context():
|
||||
document, version, job = _running_layout_job(app)
|
||||
snapshot = {
|
||||
**_snapshot(marker='compacted-worker'),
|
||||
'tables': [{
|
||||
'table_id': 'table-1', 'page_no': 1,
|
||||
'bbox': {'x0': 1, 'y0': 2, 'x1': 30, 'y1': 40},
|
||||
'html': '<table><tr><td>PO-1</td></tr></table>',
|
||||
}],
|
||||
'coordinate_evidence': {
|
||||
'pages': {'1': {'width': 100, 'height': 200}},
|
||||
'page_glyphs': {'1': [{'text': 'X' * 3000}]},
|
||||
'tables': {'table-1': [{'text': 'Y' * 5000}]},
|
||||
},
|
||||
'layout_candidate': {'table_count': 1, 'tables': [{'table_id': 'table-1'}]},
|
||||
}
|
||||
with patch(
|
||||
'app.jobs.handlers.shipping_document_layout.read_asset_bytes', return_value=b'%PDF',
|
||||
), patch(
|
||||
'app.jobs.handlers.shipping_document_layout.build_mineru_table_snapshot',
|
||||
return_value=snapshot,
|
||||
):
|
||||
run_shipping_document_layout(
|
||||
JobContext(config=dict(app.config), logger=None, extras={}),
|
||||
{'job_id': job.id},
|
||||
)
|
||||
|
||||
db.session.refresh(version)
|
||||
db.session.refresh(document)
|
||||
db.session.refresh(job)
|
||||
assert version.status == 'ready'
|
||||
assert document.current_layout_version_id == version.id
|
||||
assert job.status == 'success'
|
||||
assert job.result_json['status'] == 'ready'
|
||||
assert job.message == '文档版面解析完成'
|
||||
assert version.payload_json['tables'] == snapshot['tables']
|
||||
assert version.payload_json['layout_candidate'] == snapshot['layout_candidate']
|
||||
assert 'tables' not in version.payload_json['coordinate_evidence']
|
||||
assert 'shipping_document_layout_table_glyphs_compacted' in version.issues_json
|
||||
assert 'shipping_document_layout_coordinate_evidence_on_demand' in version.issues_json
|
||||
|
||||
|
||||
def test_layout_job_failure_requeues_version_and_clears_lease(app):
|
||||
@@ -104,3 +152,57 @@ def test_layout_job_exhaustion_fails_version_without_leaking_provider_error(app)
|
||||
assert version.status == 'failed'
|
||||
assert version.lease_token is None
|
||||
assert 'shipping_document_layout_job_exhausted' in version.issues_json
|
||||
|
||||
|
||||
def test_layout_job_xfa_hybrid_skips_mineru_path(app):
|
||||
"""XFA hybrid 文档不得进入 MinerU/PDFium 表格路径。"""
|
||||
from tests.test_shipping_xfa_helpers import build_synthetic_xfa_hybrid_pdf, load_datasets_fixture
|
||||
|
||||
with app.app_context():
|
||||
document, version, job = _running_layout_job(app)
|
||||
pdf_bytes = build_synthetic_xfa_hybrid_pdf(load_datasets_fixture())
|
||||
with patch(
|
||||
'app.jobs.handlers.shipping_document_layout.read_asset_bytes',
|
||||
return_value=pdf_bytes,
|
||||
), patch(
|
||||
'app.jobs.handlers.shipping_document_layout.build_mineru_table_snapshot',
|
||||
) as mineru_mock:
|
||||
run_shipping_document_layout(
|
||||
JobContext(config=dict(app.config), logger=None, extras={}),
|
||||
{'job_id': job.id},
|
||||
)
|
||||
|
||||
db.session.refresh(version)
|
||||
db.session.refresh(document)
|
||||
db.session.refresh(job)
|
||||
mineru_mock.assert_not_called()
|
||||
assert version.status == 'ready'
|
||||
assert version.payload_json.get('provider') == 'xfa'
|
||||
assert version.payload_json.get('tables') == []
|
||||
assert version.payload_json['xfa_capability']['structure_analysis_ready'] is True
|
||||
assert document.current_layout_version_id == version.id
|
||||
assert job.status == 'success'
|
||||
|
||||
|
||||
def test_runtime_xfa_probe_skips_mineru_for_hybrid(app):
|
||||
"""runtime 在 XFA hybrid 探测成功后不得调用 MinerU。"""
|
||||
from tests.test_shipping_xfa_helpers import build_synthetic_xfa_hybrid_pdf, load_datasets_fixture
|
||||
|
||||
with app.app_context():
|
||||
app.config['SHIPPING_NOTICE_LAYOUT_MINERU_ENABLED'] = True
|
||||
pdf_bytes = build_synthetic_xfa_hybrid_pdf(load_datasets_fixture())
|
||||
with patch(
|
||||
'app.services.shipping_notice.document_layout.runtime.MinerUClient',
|
||||
) as mineru_client:
|
||||
from app.services.shipping_notice.document_layout.runtime import build_mineru_table_snapshot
|
||||
|
||||
snapshot = build_mineru_table_snapshot(
|
||||
filename='sample.pdf',
|
||||
content=pdf_bytes,
|
||||
document_id=1,
|
||||
content_hash='a' * 64,
|
||||
)
|
||||
mineru_client.assert_not_called()
|
||||
assert snapshot is not None
|
||||
assert snapshot['provider'] == 'xfa'
|
||||
assert snapshot['tables'] == []
|
||||
Reference in new issue
Block a user