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

+19 -24
View File
@@ -8,6 +8,8 @@ from __future__ import annotations
import json
import pytest
from app import db
from app.models import Agent, ChatLog, User
@@ -48,21 +50,16 @@ def _create_user() -> User:
def _create_task_for_user(user_id: int) -> str:
from app.models import ShippingBatch, ShippingTask
"""创建无 batch 绑定的最小 ShippingNotice(co8 后 shipping_batches 已 DROP)。"""
from app.models import ShippingNotice
batch = ShippingBatch(
batch_no="BATCH-TURN-001",
user_id=user_id,
file_count=1,
)
task = ShippingTask(
task = ShippingNotice(
task_no="SN-20260706-ABCD1234",
batch=batch,
user_id=user_id,
source_type="manual",
process_status="created",
)
db.session.add_all([batch, task])
db.session.add(task)
db.session.commit()
return task.task_no
@@ -158,24 +155,17 @@ def test_chat_turn_rejects_shipping_action_for_non_shipping_agent(app, client):
assert any(item.get("event") == "run.failed" for item in events)
def test_chat_turn_multipart_upload_reads_agent_id_from_form(app, client, monkeypatch, tmp_path):
"""multipart 上传发货通知时,agent_id 应从 form 字段解析,而非 JSON body。"""
def test_chat_turn_multipart_upload_reads_agent_id_from_form(app, client, tmp_path):
"""
multipart 上传时 agent_id 应从 form 字段解析;create_batch_from_notices 已下线为 410。
关键断言:form 带 agent_id 时 run 能启动;建批动作固定 BATCHES_REMOVED(非 agent 解析失败)。
"""
from io import BytesIO
user = _create_user()
agent = _create_shipping_agent()
app.config["SHIPPING_NOTICE_STORAGE_ROOT"] = str(tmp_path)
monkeypatch.setattr(
"app.services.shipping_notice.batch_from_notices.create_shipping_batch_from_notice_items",
lambda **kwargs: {
"status": "ok",
"batch_no": "SB-MULTIPART-001",
"data": {
"tasks": [{"task_id": "SN-MULTIPART-001"}],
"focus_task": {"task_no": "SN-MULTIPART-001"},
},
},
)
res = client.post(
"/api/chat/turns/stream",
@@ -199,8 +189,11 @@ def test_chat_turn_multipart_upload_reads_agent_id_from_form(app, client, monkey
events = _parse_sse_events(res.get_data(as_text=True))
event_names = [item.get("event") for item in events]
assert "run.started" in event_names
assert "run.completed" in event_names
assert "run.failed" not in event_names
assert "run.failed" in event_names
assert "run.completed" not in event_names
failed = next(item for item in events if item.get("event") == "run.failed")
# 关键断言:SSE run.failed 顶层带业务 code(非嵌套 data)。
assert failed.get("code") == "SHIPPING.BATCHES_REMOVED"
def test_chat_turn_task_inventory_upload_uses_formal_inventory_handler(app, client, monkeypatch):
@@ -247,6 +240,7 @@ def test_chat_turn_task_inventory_upload_uses_formal_inventory_handler(app, clie
assert all('schema_preview' not in payload for payload in assistant_payloads)
@pytest.mark.skip(reason='legacy shipping_batches dropped in co8e9f0a1b2c')
def test_chat_turn_create_batch_forwards_idempotency_key(app, client, monkeypatch, tmp_path):
"""shipping.create_batch_from_notices 应透传 payload 中的建单幂等键。"""
from io import BytesIO
@@ -298,6 +292,7 @@ def test_chat_turn_create_batch_forwards_idempotency_key(app, client, monkeypatc
assert notice_items[0].get("source_content_hash")
@pytest.mark.skip(reason='legacy shipping_batches dropped in co8e9f0a1b2c')
def test_chat_turn_create_batch_idempotent_replay(app, client, monkeypatch, tmp_path):
"""相同幂等键重复 Chat Turn 不重复建批,并返回可恢复 UI state。"""
from io import BytesIO