refactor(agent, shipping): 简化代理模型并完善订单抽取业务
- 移除 Agent 的 exposure_mode 与 internal_executor 相关逻辑,清理关联的过滤、序列化代码 - 删除废弃的 AgentRuntimeBinding 模型及其依赖 - 新增订单抽取上传批次、请求快照等数据库迁移与业务逻辑 - 修复附件完整性检测、订单抽取状态映射问题 - 更新多语言错误文案与前端单元测试配置 - 清理平台配置中不再使用的暴露模式配置
This commit is contained in:
1 parent
1f3ecb87b7
commit
61ac6403c4
159 files changed
+12883
-5099
No files matched your search
@@ -1,5 +1,6 @@
|
||||
from email.message import EmailMessage
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -93,6 +94,44 @@ def _minimal_pdf_bytes(marker: str) -> bytes:
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def test_extract_notice_text_preview_only_skips_pdf_loader_and_ocr(tmp_path):
|
||||
"""上传快览只返回普通文件元信息,绝不能同步调用 PDF Loader 或 OCR。"""
|
||||
from app.services.shipping_notice.notice_upload import extract_notice_text
|
||||
|
||||
path = tmp_path / "order.pdf"
|
||||
path.write_bytes(_minimal_pdf_bytes("PREVIEW-ONLY"))
|
||||
with patch('app.services.shipping_notice.notice_upload.loader_pdf.run') as pdf_loader, patch(
|
||||
'app.services.shipping_notice.notice_upload.ocr.run',
|
||||
) as ocr_loader:
|
||||
text, meta = extract_notice_text(path, preview_only=True)
|
||||
|
||||
assert text == ""
|
||||
assert meta == {
|
||||
'warnings': [],
|
||||
'file_type': 'pdf',
|
||||
'content_mode': 'preview',
|
||||
}
|
||||
pdf_loader.assert_not_called()
|
||||
ocr_loader.assert_not_called()
|
||||
|
||||
|
||||
def test_extract_notice_text_preview_only_skips_plain_text_read(tmp_path):
|
||||
"""快览对文本文件也只返回目录元信息,不能读取或持久化正文。"""
|
||||
from app.services.shipping_notice.notice_upload import extract_notice_text
|
||||
|
||||
path = tmp_path / "order.txt"
|
||||
path.write_text("PO Number: 4510039227", encoding="utf-8")
|
||||
with patch.object(Path, "read_bytes", side_effect=AssertionError("preview must not read content")):
|
||||
text, meta = extract_notice_text(path, preview_only=True)
|
||||
|
||||
assert text == ""
|
||||
assert meta == {
|
||||
'warnings': [],
|
||||
'file_type': 'txt',
|
||||
'content_mode': 'preview',
|
||||
}
|
||||
|
||||
|
||||
_TINY_PNG = (
|
||||
b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01"
|
||||
b"\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\x0f\x00"
|
||||
@@ -290,6 +329,33 @@ def test_extract_eml_skips_signature_inline_image(tmp_path):
|
||||
assert "--- attachment: signature.png ---" not in text
|
||||
|
||||
|
||||
def test_preview_eml_skips_signature_inline_image_from_attachment_count(tmp_path):
|
||||
"""签名图不计数,但快览和深度解析必须保留一致的业务附件键。"""
|
||||
from app.services.shipping_notice.notice_upload import extract_notice_text
|
||||
|
||||
raw = _build_eml(
|
||||
subject="Two POs",
|
||||
body="Body with two PO attachments.",
|
||||
attachments=[
|
||||
("order-1.pdf", "application/pdf", _minimal_pdf_bytes("PO-ONE")),
|
||||
("order-2.pdf", "application/pdf", _minimal_pdf_bytes("PO-TWO")),
|
||||
],
|
||||
inline_images=[("signature.png", "<sig001@example.com>", _TINY_PNG)],
|
||||
)
|
||||
path = tmp_path / "preview-with-signature.eml"
|
||||
path.write_bytes(raw)
|
||||
|
||||
_, preview_meta = extract_notice_text(path, eml_attachment_mode="preview")
|
||||
_, deep_meta = extract_notice_text(path)
|
||||
|
||||
assert preview_meta["attachment_count"] == 2
|
||||
assert preview_meta["attachment_registered_count"] == 2
|
||||
assert [item["filename"] for item in preview_meta["attachments"]] == ["order-1.pdf", "order-2.pdf"]
|
||||
assert [item["attachment_key"] for item in preview_meta["attachments"]] == ["att-002", "att-003"]
|
||||
assert [item["attachment_key"] for item in deep_meta["attachments"]] == ["att-002", "att-003"]
|
||||
assert any(str(w).startswith("eml_inline_resources_skipped:") for w in preview_meta["warnings"])
|
||||
|
||||
|
||||
def test_extract_eml_duplicate_attachments(tmp_path):
|
||||
"""同信内重复内容哈希的附件标记 duplicate,不重复抽取。"""
|
||||
from app.services.shipping_notice.notice_upload import extract_notice_text
|
||||
|
||||
Reference in new issue
Block a user