feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:18:37 +08:00
1 parent 3a9fbac2fc
commit d2b3d74def
571 files changed
+78064 -24681

No files matched your search

+21 -21
View File
@@ -2,7 +2,7 @@
backend/tests/test_shipping_notice_tools.py
用途:验证货代 Tool API 的鉴权、解析、库存、匹配、导出、RPA 与状态契约。
依赖:Flask 测试客户端、ShippingTask/Customer、货代 workflow 测试辅助。
依赖:Flask 测试客户端、ShippingNotice/Customer、货代 workflow 测试辅助。
逻辑:本模块聚焦客户确认后的历史 Tool 行为;客户 Gate 的阻断与确认分支由专项测试覆盖。
"""
@@ -14,7 +14,7 @@ import pytest
from app import db
from app.models import (
ChatLog, ShippingCustomer, ShippingInventoryField, ShippingInventoryRoutingRule,
ShippingCase, ShippingInventoryFile, ShippingInventoryRoutingRuleCondition, ShippingTask,
ShippingCase, ShippingInventoryFile, ShippingInventoryRoutingRuleCondition, ShippingNotice,
ShippingOrderExtraction, ShippingOrderField, ShippingOrderFieldDecision, ShippingOrderFieldValue,
ShippingOrderLine, ShippingOrderSchema, ShippingOrderSchemaVersion,
ShippingOrderSnapshot, ShippingOrderSnapshotLine,
@@ -34,7 +34,7 @@ def _tool_headers(app):
}
def _attach_dynamic_order(task: ShippingTask, *, part_number: str, reservation_id: str, quantity: int) -> None:
def _attach_dynamic_order(task: ShippingNotice, *, part_number: str, reservation_id: str, quantity: int) -> None:
"""为库存/RPA Tool 测试创建已接受 FieldValue,避免固定任务行投影绕过订单真相门禁。"""
order_schema_service.initialize_schema({'display_name': 'Tool 动态订单'}, actor_id=None)
fields = {
@@ -258,7 +258,7 @@ def test_openapi_spec_public(app, client):
assert "/tools/generate_shipment_excel" not in spec["paths"]
assert "/tools/upload_to_freight" not in spec["paths"]
assert "/tools/switch_focus_task" not in spec["paths"]
assert set(spec["paths"]) == {"/tools/get_task_status", "/tools/get_batch_status"}
assert set(spec["paths"]) == {"/tools/get_task_status"}
spec_text = str(spec)
assert "只读解释" in spec_text
assert "submit_decision" not in spec_text
@@ -268,7 +268,7 @@ def test_confirm_inventory_source_route_returns_json(app, client):
"""confirm_inventory_source HTTP 路由必须存在且可调用。"""
headers = _tool_headers(app)
with app.app_context():
task = ShippingTask(
task = ShippingNotice(
task_no="SN-HTTP-CONFIRM-SRC",
source_type="manual",
process_status="pending_review",
@@ -306,7 +306,7 @@ def test_legacy_inventory_mapping_decisions_are_rejected(app, client, decision):
"""已启用库存站点不得通过任务决策重开旧列映射路径。"""
headers = _tool_headers(app)
with app.app_context():
task = ShippingTask(task_no=f"SN-LEGACY-MAP-{decision}", source_type="manual", process_status="waiting_inventory")
task = ShippingNotice(task_no=f"SN-LEGACY-MAP-{decision}", source_type="manual", process_status="waiting_inventory")
db.session.add(task)
db.session.commit()
@@ -327,7 +327,7 @@ def test_reparse_inventory_clears_derived_state_and_deactivates_current_link(app
"""重新上传库存只重置正式库存结果,不进入任务级字段映射。"""
headers = _tool_headers(app)
with app.app_context():
task = ShippingTask(
task = ShippingNotice(
task_no="SN-REUPLOAD-INVENTORY",
source_type="manual",
process_status="matched",
@@ -367,7 +367,7 @@ def test_reparse_inventory_clears_derived_state_and_deactivates_current_link(app
assert body["checkpoint"] == "upload_req"
assert body["human_options"] == ["upload_inventory_file", "retry_rpa"]
with app.app_context():
task = ShippingTask.query.filter_by(task_no="SN-REUPLOAD-INVENTORY").one()
task = ShippingNotice.query.filter_by(task_no="SN-REUPLOAD-INVENTORY").one()
link = ShippingTaskInventoryLink.query.filter_by(task_id=task.id).one()
assert link.is_active is False
assert task.process_status == "waiting_inventory"
@@ -483,7 +483,7 @@ def test_retry_rpa_force_refresh_clears_derived_inventory_state(app, client, tmp
task_id = create_res.get_json()["task_id"]
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "inventory_ready"
@@ -520,7 +520,7 @@ def test_retry_rpa_force_refresh_clears_derived_inventory_state(app, client, tmp
assert retry_data.get("data", {}).get("rpa_runtime", {}).get("mode") in {"browser", "mock"}
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
assert task.process_status == "waiting_inventory"
assert task.pending_human_reason == "rpa_pending"
@@ -565,7 +565,7 @@ def test_rpa_pending_timeout_recheck_marks_task_needs_human_after_single_attempt
task_id = create_res.get_json()["task_id"]
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "waiting_inventory"
@@ -592,7 +592,7 @@ def test_rpa_pending_timeout_recheck_marks_task_needs_human_after_single_attempt
with app.app_context():
result = _run_single_task(task_id)
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
assert result["status"] == "needs_human"
assert task.process_status == "waiting_inventory"
@@ -629,7 +629,7 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
task_id = create_res.get_json()["task_id"]
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "waiting_inventory"
@@ -665,7 +665,7 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
assert retry_data.get("data", {}).get("rpa", {}).get("attempts") == 1
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
assert task.process_status == "waiting_inventory"
assert task.pending_human_reason == "rpa_pending"
@@ -713,7 +713,7 @@ def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client,
task_id = task_res.get_json()["task_id"]
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "waiting_inventory"
@@ -740,7 +740,7 @@ def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client,
with app.app_context():
result = retry_batch_pending_tasks(batch_no)
task = ShippingTask.query.filter_by(task_no=task_id).first()
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
assert result["started"] == 1
assert result["skipped"] == 0
@@ -755,7 +755,7 @@ def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client,
def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(app, client):
headers = _tool_headers(app)
first = ShippingTask(
first = ShippingNotice(
task_no="SN-MULTI-CONV-001",
conversation_id="conv-test-multi",
process_status="pending_review",
@@ -764,7 +764,7 @@ def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(a
source_type="manual",
lines_json=[{"part_number": "A001", "reservation_id": "1000140351", "qty": 1}],
)
second = ShippingTask(
second = ShippingNotice(
task_no="SN-MULTI-CONV-002",
conversation_id="conv-test-multi",
process_status="pending_review",
@@ -798,8 +798,8 @@ def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(a
with app.app_context():
rows = {
task.task_no: task
for task in ShippingTask.query.filter(ShippingTask.task_no.in_(["SN-MULTI-CONV-001", "SN-MULTI-CONV-002"]))
.order_by(ShippingTask.task_no)
for task in ShippingNotice.query.filter(ShippingNotice.task_no.in_(["SN-MULTI-CONV-001", "SN-MULTI-CONV-002"]))
.order_by(ShippingNotice.task_no)
.all()
}
assert rows["SN-MULTI-CONV-001"].process_status == "pending_review"
@@ -860,7 +860,7 @@ def test_chat_actions_empty_when_task_rejected(app):
from app.services.shipping_notice.ui_state import build_task_ui_state
with app.app_context():
task = ShippingTask(
task = ShippingNotice(
task_no="SN-20260101-TEST0001",
source_type="manual",
process_status="rejected",