feat(shipping-notice): 增强发货通知候选管理功能,支持候选选择、重复检测与业务摘要修订

This commit is contained in:
hugo committed 2026-07-15 11:57:04 +08:00
1 parent 70f684b94a
commit b595e157e9
83 files changed
+5857 -200

No files matched your search

@@ -10,7 +10,10 @@ from app import db
from app.models import Agent, User
from app.services.chat.action_schema import TurnInput
from app.services.chat.turn_context import TurnContext
from app.services.shipping_notice.chat_action_handlers import ShippingGenerateExcelAction
from app.services.shipping_notice.chat_action_handlers import (
ShippingCreateBatchFromIntakesAction,
ShippingGenerateExcelAction,
)
def _create_task(user_id: int) -> str:
@@ -76,3 +79,62 @@ def test_generate_excel_handler_yields_ui_state_and_message(app, monkeypatch):
assert "message.completed" in event_names
completed = next(item for item in events if item.event == "message.completed")
assert "Excel 已生成" in str(completed.data.get("content") or "")
def test_create_batch_from_intakes_handler_forwards_candidate_nos(app, monkeypatch):
"""Chat Turn Candidate 建批必须把选择集合透传后端,且不得引用未定义局部变量。"""
user = User(username="candidate_handler", email="candidate-handler@example.com", role="user", status="active")
user.set_password("password")
agent = Agent(
name="货代发货通知 Agent",
description="t",
dify_api_key="k",
api_base_url="http://example.com",
agent_code="shipping_notice",
runtime_provider="hybrid",
conversation_mode="task_chat",
)
db.session.add_all([user, agent])
db.session.commit()
captured: dict = {}
def _fake_create(**kwargs):
captured.update(kwargs)
return {
"status": "ok",
"batch_no": None,
"message": "已打开已有任务,未创建新批次",
"opened_existing": [{"candidate_no": "SNC-1", "task_no": "SN-EXISTING"}],
"data": {"focus_task": {"task_no": "SN-EXISTING"}},
}
monkeypatch.setattr(
"app.services.shipping_notice.batch_from_intakes.create_shipping_batch_from_intakes",
_fake_create,
)
ctx = TurnContext(
turn_id="turn-candidate",
run_id="turn-candidate",
session_id="sess-candidate",
request_id="req-candidate",
user=user,
agent=agent,
input=TurnInput(
type="action",
display_text="确认两个订单",
action_type="shipping.create_batch_from_intakes",
payload={
"intake_nos": ["SNI-1"],
"candidate_nos": ["SNC-1", "SNC-2"],
"idempotency_key": "idem-candidate-handler",
},
),
refs={},
)
events = list(ShippingCreateBatchFromIntakesAction().stream(ctx))
assert captured["intake_nos"] == ["SNI-1"]
assert captured["candidate_nos"] == ["SNC-1", "SNC-2"]
assert captured["conversation_id"] == "sess-candidate"
assert any(event.event == "message.completed" for event in events)