fix: prevent None reply in collection flow and harden response fallback

This commit is contained in:
2026-03-01 12:37:51 +08:00
parent e31bb80063
commit 0f769607c4
2 changed files with 57 additions and 30 deletions

View File

@@ -337,6 +337,33 @@ class RegressionPipelineTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(st.pending_image_urls, ["u1", "u2"])
self.assertEqual(st.pending_requirements, ["r1"])
async def test_collection_reply_never_returns_none(self):
os.environ["AI_DYNAMIC_COLLECTION_REPLIES"] = "true"
agent = CustomerServiceAgent()
agent.agent_natural_reply.run = AsyncMock(side_effect=RuntimeError("mock ai fail"))
st = agent._get_conversation_state(self.customer_id)
msg = CustomerMessage(
msg_id="m-collection-fallback",
acc_id="test_shop",
msg="收到没",
from_id=self.customer_id,
from_name="t",
cy_id=self.customer_id,
acc_type="AliWorkbench",
msg_type=0,
cy_name="t",
goods_name="专业找图",
goods_order="",
)
reply = await agent._render_collection_reply_with_ai(
message=msg,
state=st,
scene="collect_ack",
intent_hint="确认已收到图片",
fallback="图片收到了,你继续发就行。",
)
self.assertEqual(reply, "图片收到了,你继续发就行。")
def tearDown(self):
db.clear_pending_quote_state(self.customer_id)