Files
inquiry_robot/inquiry-agent/tests/test_inquiry_raw_text.py
T
linmianxun 9d7bc2b787 员工岗位与数据范围权限上线,企微群机器人接入与报价回执去重
- 新增员工岗位(InquiryStaffRole)实体、服务与后台页面,数据范围默认按岗位,看板由「仅本人」切换为岗位范围,补充业务负责人与角色说明迁移
- 新增企微群 webhook 通道、access_gate/staff_roles 鉴权与智价通/双 BOT 回复配置
- 报价回执增加去重防抖(quote_receipt_debounce),询价原文落库并补单测
- 同义词补陆运类型修正与地名通配 v2,更新种子生成脚本
- 空运/陆运/海运询价流程、报价单按需生成、转人工与多段处理调整
- 后台工单需求字段、BOT 显示名、站点标题与看板配套更新
2026-12-04 20:16:28 +08:00

184 lines
6.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
业务询价原始内容:建单落库 + 群摘要不再展示。
产品口径(2026-12-03):销售 1v1 首条询价原话存到 inq_ticket.inquiry_raw_text,
只在管理后台工单详情展示;海/空/陆/多段/转人工群摘要一律不输出这一段。
"""
from __future__ import annotations
import os
import sys
import unittest
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if ROOT not in sys.path:
sys.path.insert(0, ROOT)
os.environ.setdefault("YTD_ENV", "test")
os.environ.setdefault("REDIS_BACKEND", "memory")
os.environ.setdefault("CHECKPOINT_BACKEND", "memory")
os.environ.setdefault("MESSAGE_STORE_BACKEND", "memory")
os.environ.setdefault("LLM_DATA_USAGE_CONFIRMED", "false")
os.environ.setdefault("LLM_ALLOW_NETWORK", "false")
os.environ.setdefault("LEDGER_BACKEND", "memory")
from agent.ledger.memory_ledger import MemoryLedger
from agent.policy import inquiry_copy as copy
from agent.policy.multi_segments import Segment, group_brief
from agent.policy.sea_text_flow import SeaTextInquiryFlow
RAW = "上海到洛杉矶 3件 100kg 空运 普货 要含电"
LABEL = "业务询价原始内容"
class GroupBriefOmitsRawInquiryTests(unittest.TestCase):
"""原始内容只留后台:任何群摘要都不能再出现这一段。"""
def assert_omitted(self, text: str) -> None:
self.assertNotIn(LABEL, text)
self.assertNotIn(RAW, text)
def test_sea_brief_omits_raw_text(self) -> None:
text = copy.sea_group_brief(
work_order_no="WO202611250001",
facts={"起运港": "上海", "目的港": "洛杉矶", "品名": "普货"},
quote={},
collab_facts={},
sales_name="吴季林",
product_names=["罗小华"],
has_price=False,
)
self.assertIn("工单号:WO202611250001", text)
self.assert_omitted(text)
def test_air_brief_omits_raw_text(self) -> None:
text = copy.air_group_brief(
work_order_no="WO202611250002",
facts={"起运地": "上海", "目的地": "洛杉矶", "品名": "普货"},
quote={},
collab_facts={},
has_price=False,
)
self.assert_omitted(text)
def test_air_brief_with_tms_price_omits_raw_text(self) -> None:
text = copy.air_group_brief(
work_order_no="WO202611250003",
facts={"起运地": "上海", "目的地": "洛杉矶", "品名": "普货"},
quote={"total": "USD 100", "fee_lines": [{"name": "空运费", "amount": "USD 100"}]},
collab_facts={},
has_price=True,
tms_quote={"total": "USD 100", "fee_lines": [{"name": "空运费", "amount": "USD 100"}]},
sales_name="吴季林",
airline_names=["航线甲"],
)
self.assert_omitted(text)
def test_handoff_brief_omits_raw_text(self) -> None:
text = copy.handoff_group_brief(
work_order_no="WO202611250004",
facts={"起运港": "上海", "目的港": "洛杉矶", "品名": "普货"},
business_line="SEA",
product_names=["罗小华"],
sales_name="吴季林",
)
self.assertIn("WO202611250004转人工", text)
self.assert_omitted(text)
def test_multi_brief_omits_raw_text(self) -> None:
segs = [
Segment(index=1, mode="SEA", facts={"起运港": "上海", "目的港": "洛杉矶", "品名": "普货"}),
Segment(index=2, mode="AIR", facts={"起运地": "洛杉矶", "目的地": "纽约", "品名": "普货"}),
]
text = group_brief(
work_order_no="WO202611250005",
segments=segs,
sales_name="吴季林",
mention_names=["罗小华"],
)
self.assertIn("段1:", text)
self.assert_omitted(text)
def test_manual_quote_group_copy_omits_raw_ref(self) -> None:
"""人工报价群摘要也不再补「原始报价参考」,原话只落库。"""
quote = {
"total": "CNY13000",
"currency": "CNY",
"vehicleRates": {"7.6米": "13000"},
"raw_text": "东莞-春疆 7.6米 CNY13000",
}
text = "\n".join(
copy._manual_quote_lines(quote, business_line="LAND", transport_mode="陆运", layout="manual")
)
self.assertIn("运输费:CNY13000元", text)
self.assertNotIn("原始报价参考", text)
self.assertNotIn("东莞-春疆 7.6米 CNY13000", text)
class FlowRawTextWiringTests(unittest.TestCase):
def test_sea_ticket_keeps_first_message_not_confirm_word(self) -> None:
"""销售先发原话再回「确定」:落库必须是原话,不能是「确定」。"""
ledger = MemoryLedger()
flow = SeaTextInquiryFlow(ledger)
replies: list[str] = []
first = "上海到洛杉矶 20吨 整柜 1x40HQ FOB 港到港"
flow.on_text(
sender_id="s-raw",
text=first,
reply=lambda text, extra=None: replies.append(text),
injected_facts={
"起运港": "上海",
"目的港": "洛杉矶",
"品名": "普货",
"货量": "20吨",
"整柜或拼柜": "整柜",
"箱型箱量": "1x40HQ",
"贸易条款": "FOB",
"运输分类": "港到港",
},
injected_mode="SEA",
)
flow.on_text(
sender_id="s-raw",
text="确定",
reply=lambda text, extra=None: replies.append(text),
)
sess = flow.session_of("s-raw")
self.assertTrue(sess and sess.work_order_no)
ticket = ledger.get_ticket(work_order_no=sess.work_order_no)
self.assertIsNotNone(ticket)
self.assertEqual(ticket.inquiry_raw_text, first)
class MemoryLedgerRawTextTests(unittest.TestCase):
def test_create_and_snapshot_keep_raw_text(self) -> None:
ledger = MemoryLedger()
out = ledger.create_ticket(
sender_id="sales1",
business_line="AIR",
facts={"起运地": "上海", "目的地": "洛杉矶", "品名": "普货"},
raw_text=RAW,
)
no = str(out.get("work_order_no") or "")
self.assertTrue(no)
snap = ledger.get_for_agent(work_order_no=no, sender_id="sales1")
self.assertEqual(snap.get("inquiry_raw_text"), RAW)
self.assertEqual(snap.get("inquiryRawText"), RAW)
def test_without_raw_text_snapshot_is_blank(self) -> None:
ledger = MemoryLedger()
out = ledger.create_ticket(
sender_id="sales1",
business_line="SEA",
facts={"起运港": "上海", "目的港": "洛杉矶", "品名": "普货"},
)
no = str(out.get("work_order_no") or "")
snap = ledger.get_for_agent(work_order_no=no, sender_id="sales1")
self.assertEqual(snap.get("inquiry_raw_text"), "")
if __name__ == "__main__":
unittest.main()