feat(shipping-notice): 添加 MinerU 订单附件表格结构化功能,更新环境配置和数据模型以支持新布局解析和文档模板管理
This commit is contained in:
1 parent
c4095b08da
commit
c35223d49d
148 files changed
+15709
-1353
No files matched your search
@@ -112,7 +112,7 @@ def test_candidate_review_duplicate_api_and_access_guards(app, client):
|
||||
structured_result_json={
|
||||
'business_summary': {
|
||||
'po_number': '7001',
|
||||
'lines': [{'reservation_id': 'R-1', 'part_number': 'SKU-1', 'qty': 1}],
|
||||
'lines': [{'reservation_id': '1000140351', 'part_number': 'SKU-1', 'qty': 1}],
|
||||
},
|
||||
},
|
||||
validation_status='needs_review',
|
||||
@@ -134,7 +134,7 @@ def test_candidate_review_duplicate_api_and_access_guards(app, client):
|
||||
'selected': False,
|
||||
'business_summary': {
|
||||
'po_number': '7001',
|
||||
'lines': [{'reservation_id': 'R-1', 'part_number': 'SKU-1', 'qty': 2}],
|
||||
'lines': [{'reservation_id': '1000140351', 'part_number': 'SKU-1', 'qty': 2}],
|
||||
},
|
||||
},
|
||||
headers=owner_headers,
|
||||
@@ -3333,8 +3333,13 @@ def test_run_intake_parse_three_pdfs_creates_documents_and_assets_without_candid
|
||||
)
|
||||
eml_bytes = msg.as_bytes()
|
||||
|
||||
app.config['SHIPPING_NOTICE_LAYOUT_MINERU_ENABLED'] = True
|
||||
app.config['SHIPPING_NOTICE_LAYOUT_MINERU_MAX_DOCUMENTS_PER_INTAKE'] = 4
|
||||
with app.app_context():
|
||||
with patch('app.services.file_assets.service.file_asset_storage.upload_bytes'):
|
||||
with patch('app.services.file_assets.service.file_asset_storage.upload_bytes'), patch(
|
||||
'app.services.shipping_notice.document_layout.runtime.build_mineru_table_snapshot',
|
||||
side_effect=AssertionError('Intake parse must not call MinerU inline'),
|
||||
):
|
||||
asset_data = upload_file_asset(
|
||||
user_id=shipping_user.id,
|
||||
upload=FileStorage(
|
||||
@@ -3408,6 +3413,12 @@ def test_run_intake_parse_three_pdfs_creates_documents_and_assets_without_candid
|
||||
assert len(cands) == 0
|
||||
assert len(children) == 3
|
||||
assert len({c.content_hash for c in children}) == 3
|
||||
from app.models import Job, ShippingDocumentLayoutVersion
|
||||
|
||||
assert ShippingDocumentLayoutVersion.query.filter(
|
||||
ShippingDocumentLayoutVersion.document_id.in_([item.id for item in pdf_docs]),
|
||||
).count() == 3
|
||||
assert Job.query.filter_by(job_type='shipping_document_layout').count() == 3
|
||||
|
||||
detail = serialize_intake(refreshed_intake, asset=parent, include_parse_texts=True)
|
||||
assert detail['document_count'] == 4
|
||||
@@ -3431,6 +3442,8 @@ def test_run_intake_parse_three_pdfs_creates_documents_and_assets_without_candid
|
||||
)
|
||||
assert db.session.query(ShippingNoticeDocument).filter_by(intake_id=intake_id).count() == 4
|
||||
assert db.session.query(ShippingNoticeCandidate).filter_by(intake_id=intake_id).count() == 0
|
||||
assert ShippingDocumentLayoutVersion.query.count() == 3
|
||||
assert Job.query.filter_by(job_type='shipping_document_layout').count() == 3
|
||||
assert (
|
||||
db.session.query(FileAsset)
|
||||
.filter(FileAsset.parent_asset_id == parent.id, FileAsset.deleted_at.is_(None))
|
||||
@@ -3439,6 +3452,66 @@ def test_run_intake_parse_three_pdfs_creates_documents_and_assets_without_candid
|
||||
)
|
||||
|
||||
|
||||
def test_run_intake_parse_persists_sanitized_email_html_layout_without_meta_leak(
|
||||
app, shipping_user, monkeypatch,
|
||||
):
|
||||
"""HTML 正文表格应生成独立布局版本,临时 HTML 不得进入 Intake 摘要或 Dify 文档正文。"""
|
||||
from email.message import EmailMessage
|
||||
from io import BytesIO
|
||||
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from app.models import ShippingDocumentLayoutVersion
|
||||
from app.services.file_assets.service import upload_file_asset
|
||||
from app.services.shipping_notice.intake_parse_workflow import run_intake_parse
|
||||
|
||||
msg = EmailMessage()
|
||||
msg['Subject'] = 'HTML table order'
|
||||
msg.set_content('PO 12345')
|
||||
msg.add_alternative(
|
||||
'<html><body><script>SECRET()</script><table style="color:red">'
|
||||
'<tr><th>Part</th><th>Qty</th></tr><tr><td>A-1</td><td>2</td></tr>'
|
||||
'</table></body></html>',
|
||||
subtype='html',
|
||||
)
|
||||
eml_bytes = msg.as_bytes()
|
||||
with app.app_context(), patch(
|
||||
'app.services.file_assets.service.file_asset_storage.upload_bytes',
|
||||
):
|
||||
asset_data = upload_file_asset(
|
||||
user_id=shipping_user.id,
|
||||
upload=FileStorage(
|
||||
stream=BytesIO(eml_bytes), filename='html-order.eml', content_type='message/rfc822',
|
||||
),
|
||||
)
|
||||
parent = db.session.query(FileAsset).filter_by(asset_no=asset_data['asset_no']).one()
|
||||
intake = ShippingNoticeIntake(
|
||||
intake_no='SNI-HTML-LAYOUT', asset_id=parent.id, user_id=shipping_user.id,
|
||||
purpose='shipping_notice', parse_status='parsing', parser_version='v6',
|
||||
)
|
||||
db.session.add(intake)
|
||||
db.session.commit()
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.intake_parse_workflow.read_asset_bytes',
|
||||
lambda _asset: eml_bytes,
|
||||
)
|
||||
|
||||
result = run_intake_parse(intake, parent)
|
||||
db.session.expire_all()
|
||||
body = ShippingNoticeDocument.query.filter_by(
|
||||
intake_id=intake.id, document_type='email_body',
|
||||
).one()
|
||||
version = ShippingDocumentLayoutVersion.query.filter_by(document_id=body.id).one()
|
||||
structured = db.session.get(ShippingNoticeIntake, intake.id).structured_result_json
|
||||
|
||||
assert result['status'] == 'parsed'
|
||||
assert version.status == 'needs_review'
|
||||
assert version.payload_json['layout_candidate']['parser']['name'] == 'eml-html-dom'
|
||||
assert 'SECRET' not in repr(version.payload_json)
|
||||
assert 'body_html_tables' not in repr(structured)
|
||||
assert '<table' not in repr(structured)
|
||||
|
||||
|
||||
def test_stage2_supporting_pdf_without_po_has_document_but_no_candidate(
|
||||
app, shipping_user, monkeypatch,
|
||||
):
|
||||
|
||||
Reference in new issue
Block a user