feat(shipping-notice): 收敛复核状态隔离、STP 重试幂等与 XFA 合成预览标注

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-07 02:58:28 +08:00
1 parent 84a881b554
commit 74270adc22
149 files changed
+20111 -3871

No files matched your search

@@ -0,0 +1,61 @@
"""
tests/test_shipping_xfa_preview_renderer.py
用途:硬冻结后验收——完整 flatten 未就绪时 compose 必须 needs_review,禁止 overlay ready。
依赖:xfa_preview_renderer、xfa_preview_contract、pytest。
逻辑:断言空 PDF failed;任意有效输入均不得 status=ready;diagnostics.reason=flatten_engine_unavailable。
"""
from __future__ import annotations
import pytest
from app.services.shipping_notice.document_layout.xfa_preview_contract import (
RENDER_MODE,
XFA_PREVIEW_UNAVAILABLE,
)
from app.services.shipping_notice.document_layout.xfa_preview_renderer import (
RENDERER_VERSION,
attempt_offline_xfa_flatten,
compose_xfa_dataset_preview_pages,
)
pytestmark = pytest.mark.pure_unit
def test_compose_without_flatten_engine_is_needs_review_not_ready():
"""关键断言:flatten 未交付 → needs_review,绝非 ready(禁 overlay)。"""
result = compose_xfa_dataset_preview_pages(
pdf_bytes=b'%PDF-1.4 minimal',
analysis_or_nodes={'/data/HEADER/EBELN': '4510039227'},
page_boxes=[{'page_no': 1, 'width': 612.0, 'height': 792.0}],
)
assert result.status == 'needs_review'
assert result.error_code == XFA_PREVIEW_UNAVAILABLE
assert result.pages == []
assert result.preview_render_checksum is None
assert result.render_mode == RENDER_MODE
assert result.renderer_version == RENDERER_VERSION
assert result.diagnostics.get('reason') == 'flatten_engine_unavailable'
assert result.diagnostics.get('operational_status') == 'OPERATIONAL_PENDING'
def test_attempt_offline_flatten_same_fail_closed():
"""关键断言:attempt_offline_xfa_flatten 与 compose 同口径 fail-closed。"""
result = attempt_offline_xfa_flatten(
pdf_bytes=b'%PDF-1.4',
analysis_or_nodes={},
)
assert result.status == 'needs_review'
assert result.pages == []
def test_empty_pdf_failed_not_ready():
"""关键断言:空 PDF → failed,绝非 ready。"""
result = compose_xfa_dataset_preview_pages(
pdf_bytes=b'',
analysis_or_nodes={'/data/HEADER/EBELN': 'x'},
)
assert result.status == 'failed'
assert result.status != 'ready'
assert result.pages == []