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

625 lines
28 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-11-22):
1. 空运:「1:300,+500,USD11/kg,卡转/MUST GO、TH、NKG-KUL、11月2日」
2. 陆运:「东莞-春疆,危险品,7.6米CNY13000元;9.6米CNY14000;45HQ,CNY18500;都是含0点税」
3. 陆运:「春疆-罗勇,45HQ,运输费USD3200,燃油费USD300,过境费USD70,报关费cny1400」
本文件只测解析与挂段,不连企微/TMS/主账。
禁止把这三种写法退化回「7.6 当运费」或「USD+CNY 相加成 4970」。
"""
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.llm.extract_text import extract_product_quote
from agent.policy.sea_group_ops import _attach_land_vehicle_rates_segment
AIR_SAMPLE = "工单号、1:300,+500,USD11/kg,卡转/MUST GO、TH、NKG-KUL、11月2日"
# 正式环境 WO202611250017:航线另起一行「3G HKG-KUL 11月29日」,
# 旧实现把 kg 配上航班号 3、KUL 配上日期 11,抽成「kg:HKD3」「KUL:HKD11」。
AIR_ROUTE_LINE_SAMPLE = "WO202611250017 +1000 HKD24.5/kg\n3G HKG-KUL 11月29日"
LAND_VEHICLE_SAMPLE = (
"东莞-春疆,危险品,7.6米CNY13000元;9.6米CNY14000;45HQ,CNY18500;都是含0点税"
)
LAND_MULTI_CCY_SAMPLE = (
"春疆-罗勇,45HQ,运输费USD3200,燃油费USD300,过境费USD70,报关费cny1400"
)
class ManualQuoteAirTest(unittest.TestCase):
"""空运短句:单价按 KG、+500 只作重量分档,不冒充附加费。"""
def test_unit_price_and_weight_break(self) -> None:
quote = extract_product_quote(AIR_SAMPLE, business_line="AIR", transport_mode="空运")
rows = list(quote.get("fee_rows") or [])
self.assertEqual(len(rows), 1)
row = rows[0]
self.assertEqual(row.get("name"), "空运费")
self.assertEqual(row.get("unit"), "KG")
self.assertEqual(row.get("unit_price"), "11")
self.assertEqual(row.get("currency"), "USD")
self.assertEqual(row.get("weight_break"), "+500")
# 只有单价没有数量时合计就是单价,摘要显示「单价USD11/KG(+500)」。
self.assertEqual(str(quote.get("total") or ""), "11")
def test_side_fields_are_harvested(self) -> None:
from agent.policy.air_group_ops import _harvest_air_manual_airline
from agent.schema.added_services import harvest_added_services
from agent.schema.field_validate import _harvest_air_ratio, _harvest_quote_date
self.assertEqual(_harvest_air_manual_airline(AIR_SAMPLE), "TH")
self.assertEqual(harvest_added_services(AIR_SAMPLE), ["卡转", "MUST GO"])
self.assertEqual(_harvest_air_ratio(AIR_SAMPLE), "1:300")
self.assertTrue(_harvest_quote_date(AIR_SAMPLE).endswith("-11-02"))
class ManualQuoteAirRouteLineTest(unittest.TestCase):
"""
空运航线行不是费用行(正式环境 WO202611250017)。
产品原话把航班号、航线、日期另起一行:3G HKG-KUL 11月29日。
旧实现按「短英文费名 + 数字」抽成 kg:HKD3、KUL:HKD11,
合计 14,价格完全错。正确只认 HKD24.5/kg 这一条空运费。
"""
def _quote(self) -> dict:
return extract_product_quote(
AIR_ROUTE_LINE_SAMPLE, business_line="AIR", transport_mode="空运"
)
def test_only_unit_price_is_a_fee_row(self) -> None:
quote = self._quote()
rows = list(quote.get("fee_rows") or [])
self.assertEqual([r.get("name") for r in rows], ["空运费"])
row = rows[0]
self.assertEqual(row.get("unit"), "KG")
self.assertEqual(row.get("unit_price"), "24.5")
self.assertEqual(row.get("currency"), "HKD")
self.assertEqual(str(quote.get("total") or ""), "24.5")
self.assertEqual(str(quote.get("weight_break") or ""), "+1000")
# 旧缺陷:kg/KUL 两个假费目,合计 3+11=14。
for bad in rows:
self.assertNotEqual(str(bad.get("name") or "").upper(), "KUL")
self.assertNotEqual(str(bad.get("name") or "").lower(), "kg")
def test_route_and_date_are_side_fields(self) -> None:
from agent.policy.air_group_ops import _harvest_air_manual_route_airports
from agent.schema.field_validate import _harvest_quote_date
self.assertEqual(
_harvest_air_manual_route_airports(AIR_ROUTE_LINE_SAMPLE), ("HKG", "KUL")
)
self.assertEqual(_harvest_quote_date(AIR_ROUTE_LINE_SAMPLE), "2026-11-29")
def test_summary_lines_match_expected(self) -> None:
from agent.policy import inquiry_copy as copy
quote = self._quote()
quote["source_label"] = "航线报价"
facts = {"起运港": "HKG", "目的港": "KUL", "报价日期": "2026-11-29"}
lines = copy._manual_quote_lines(
quote, business_line="AIR", facts=facts, layout="manual"
)
self.assertIn("重量等级:+1000", lines)
self.assertIn("空运费:HKD24.5/kg", lines)
self.assertIn("报价有效期:2026-11-29", lines)
self.assertTrue(any(x.startswith("舱位信息:HKG-KUL,") for x in lines), lines)
body = "\n".join(lines)
self.assertNotIn("kg:HKD3", body)
self.assertNotIn("KUL:HKD11", body)
class ManualQuoteLandVehicleTest(unittest.TestCase):
"""陆运多车型价:米长与柜型都是车型键,米长数字绝不能当运费。"""
def test_mile_and_container_labels_become_rates(self) -> None:
quote = extract_product_quote(
LAND_VEHICLE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
rates = dict(quote.get("vehicleRates") or {})
self.assertEqual(rates.get("7.6米"), "13000")
self.assertEqual(rates.get("9.6米"), "14000")
self.assertEqual(rates.get("45HQ"), "18500")
self.assertEqual(str(quote.get("currency") or ""), "CNY")
# 备注由 land_quote_condition 归一成「含0税」;旧写法「含0点税」也算通过,
# 两条并行改动谁先落地都不该让用例红。
self.assertIn(str(quote.get("remark") or ""), {"含0点税", "含0税"})
self.assertEqual(str(quote.get("tax_rate") or ""), "0")
# 旧缺陷:整句只剩一行「陆运费 7.6」。
for row in quote.get("fee_rows") or []:
self.assertNotIn(str(row.get("amount") or ""), {"7.6", "9.6"})
def test_rates_attach_to_segment_and_clear_fee_rows(self) -> None:
quote = extract_product_quote(
LAND_VEHICLE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "东莞", "目的港": "春疆"}}
)
segs = list(out.get("landSegments") or [])
self.assertEqual(len(segs), 1)
self.assertEqual(segs[0].get("origin"), "东莞")
self.assertEqual(segs[0].get("destination"), "春疆")
self.assertEqual((segs[0].get("vehicleRates") or {}).get("45HQ"), "18500")
# 多车型价只走矩阵列,费目行清空,避免车型名被当成费目写进起始地。
self.assertEqual(list(out.get("fee_rows") or []), [])
class ManualQuoteLandMultiCurrencyTest(unittest.TestCase):
"""陆运跨境:美元运费 + 人民币报关费,各行保币种,合计不跨币种相加。"""
def test_rows_keep_their_own_currency(self) -> None:
quote = extract_product_quote(
LAND_MULTI_CCY_SAMPLE, business_line="LAND", transport_mode="陆运"
)
rows = list(quote.get("fee_rows") or [])
self.assertEqual([r.get("name") for r in rows], ["运输费", "燃油费", "过境费", "报关费"])
self.assertEqual([r.get("currency") for r in rows], ["USD", "USD", "USD", "CNY"])
def test_total_is_not_cross_currency_sum(self) -> None:
quote = extract_product_quote(
LAND_MULTI_CCY_SAMPLE, business_line="LAND", transport_mode="陆运"
)
# 3200+300+70 = 3570 USD;报关费 1400 CNY 另计,绝不加进 USD 合计。
self.assertEqual(str(quote.get("total") or ""), "3570.0")
self.assertEqual(str(quote.get("currency") or ""), "USD")
self.assertTrue(quote.get("mixed_currency"))
def test_vehicle_type_without_price_keeps_fees(self) -> None:
quote = extract_product_quote(
LAND_MULTI_CCY_SAMPLE, business_line="LAND", transport_mode="陆运"
)
self.assertEqual(str(quote.get("vehicleType") or ""), "45HQ")
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "春疆", "目的港": "罗勇"}}
)
seg = (out.get("landSegments") or [{}])[0]
self.assertEqual(seg.get("vehicleType"), "45HQ")
# 只有车型没有价矩阵:费用明细必须保留,不能因挂车型被清空。
self.assertEqual(len(out.get("fee_lines") or []), 4)
class ManualQuoteSummaryTest(unittest.TestCase):
"""销售侧摘要:三档车型价和备注必须露出来,不能只回一个合计。"""
def test_vehicle_matrix_and_remark_are_shown(self) -> None:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(
LAND_VEHICLE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "东莞", "目的港": "春疆"}}
)
text = "\n".join(copy._manual_quote_lines(out, business_line="LAND", transport_mode="陆运"))
self.assertIn("车型价:7.6米 CNY 13000;9.6米 CNY 14000;45HQ CNY 18500", text)
self.assertIn("备注:含0", text)
self.assertIn("此处取第一档", text)
def test_multi_currency_lines_keep_currency(self) -> None:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(
LAND_MULTI_CCY_SAMPLE, business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "春疆", "目的港": "罗勇"}}
)
text = "\n".join(copy._manual_quote_lines(out, business_line="LAND", transport_mode="陆运"))
self.assertIn("运输费:USD 3200", text)
self.assertIn("报关费:CNY 1400", text)
self.assertIn("费用合计:USD 3570.0", text)
# 不再出现把美元和人民币加在一起的假数。
self.assertNotIn("4970", text)
class ManualQuoteSeaRegressionTest(unittest.TestCase):
"""海运单币种仍照旧加总,别被多币种改动带偏。"""
def test_sea_single_currency_still_sums(self) -> None:
quote = extract_product_quote(
"码头操作费100CNY,报关费300CNY", business_line="SEA", transport_mode="海运"
)
self.assertEqual(str(quote.get("currency") or ""), "CNY")
self.assertEqual(str(quote.get("total") or ""), "400.0")
self.assertFalse(quote.get("mixed_currency"))
class ManualQuoteAirLayoutTest(unittest.TestCase):
"""空运人工报价对外版式(产品 2026-11-22 定稿):比例/重量等级/舱位信息 + 价格。"""
def _text(self) -> str:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(AIR_SAMPLE, business_line="AIR", transport_mode="空运")
quote["source"] = "PRODUCT"
quote["source_label"] = "航线报价"
quote["airlineCode"] = "TH"
quote["airline"] = "TH"
facts = {
"起运港": "NKG",
"目的港": "KUL",
"品名": "普货",
"件数": "10",
"毛重": "500",
"体积": "3",
"包装方式": "纸箱",
"比例": "1:300",
"报价日期": "2026-11-02",
"added_services": "卡转、MUST GO",
}
return "\n".join(
copy._manual_quote_lines(
quote, business_line="AIR", facts=facts, layout="manual"
)
)
def test_full_block_matches_product_layout(self) -> None:
self.assertEqual(
self._text(),
"\n".join(
[
"价格方案如下:",
"比例:1:300",
"重量等级:+500",
# 体积 3CBM × 166.7 = 500.1KG > 毛重 500KG → 取体积重;
# 产品 2026-11-22 晚确定只写数字,不括注依据。
"计费重:500.1KG",
"舱位信息:TH,NKG-KUL,2026-11-2起,具体根据放舱情况而定",
"",
"价格",
"空运费:USD11/kg",
"报价有效期:2026-11-2",
]
),
)
def test_missing_facts_do_not_print_dashes(self) -> None:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(AIR_SAMPLE, business_line="AIR", transport_mode="空运")
text = "\n".join(
copy._manual_quote_lines(quote, business_line="AIR", facts={}, layout="manual")
)
# 没有报价日期就不写有效期,不拿「-」占位、不编日期。
self.assertNotIn("报价有效期", text)
self.assertNotIn(":-", text)
def test_cabin_scope_note_is_not_printed(self) -> None:
"""
产品 2026-12-03:舱位信息不再带「(包含航司、线路、班期、舱位日期哪天起)」,
只保留「具体根据放舱情况而定」;四样全缺才整行不写。
"""
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(AIR_SAMPLE, business_line="AIR", transport_mode="空运")
quote["airlineCode"] = "TH"
text = "\n".join(
copy._manual_quote_lines(quote, business_line="AIR", facts={}, layout="manual")
)
self.assertIn("舱位信息:TH,具体根据放舱情况而定", text)
self.assertNotIn("包含航司、线路、班期、舱位日期哪天起", text)
empty = extract_product_quote(AIR_SAMPLE, business_line="AIR", transport_mode="空运")
empty.pop("airlineCode", None)
empty.pop("airline", None)
bare = "\n".join(
copy._manual_quote_lines(empty, business_line="AIR", facts={}, layout="manual")
)
self.assertNotIn("舱位信息", bare)
class ManualQuoteLandLayoutTest(unittest.TestCase):
"""陆运多车型人工报价竖排版式:一段一价 + 税率(原话只留后台,不上屏)。"""
def _text(self) -> str:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(
LAND_VEHICLE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "东莞", "目的港": "春疆"}}
)
out["raw_text"] = LAND_VEHICLE_SAMPLE
return "\n".join(
copy._manual_quote_lines(out, business_line="LAND", layout="manual")
)
def test_vehicle_matrix_is_vertical(self) -> None:
self.assertEqual(
self._text(),
"\n".join(
[
"车型/数量:7.6米",
"运输费:CNY13000元",
"车型/数量:9.6米",
"运输费:CNY14000元",
"车型/数量:45HQ",
"运输费:CNY18500元",
"税率:0",
]
),
)
def test_group_brief_drops_tms_miss_block_when_product_quoted(self) -> None:
"""
产品 2026-11-22 口径:TMS 没查到价、产品已经在群里报了多车型价时,
摘要不再出现「TMS报价:TMS 暂无匹配报价 + 请另报」这一段,直接进「人工报价:」。
图 WO202611220022 就是这种场景:销售看到红框里的无价空话会以为报价没生效。
"""
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(
LAND_VEHICLE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
manual = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "东莞", "目的港": "春疆"}}
)
brief = copy.sea_group_brief(
work_order_no="WO202611220022",
facts={"起运港": "东莞", "目的港": "春疆", "品名": "危险品"},
quote=None,
collab_facts={},
sales_name="罗小华",
product_names=[],
has_price=False,
tms_quote={},
product_quote=manual,
transport_mode="陆运",
)
self.assertNotIn("TMS报价:", brief)
self.assertNotIn("TMS 暂无匹配报价", brief)
self.assertNotIn("产品人员可通过“纯文字”告知新报价", brief)
# TMS 段整段去掉后上面没有小标题,必须补「人工报价:」才知道这是产品报的价。
self.assertIn(
"人工报价:\n车型/数量:7.6米\n运输费:CNY13000元", brief
)
def test_group_brief_keeps_tms_block_when_tms_priced(self) -> None:
"""TMS 有价时照旧保留 TMS 段,手工补的价另起「人工报价:」,两段不混。"""
from agent.policy import inquiry_copy as copy
tms = {
"total": "CNY 20000",
"currency": "CNY",
"source": "TMS",
"source_label": "TMS标准报价",
"fee_lines": [{"name": "海运费", "amount": "20000.00", "currency": "CNY"}],
}
brief = copy.sea_group_brief(
work_order_no="WO202611220023",
facts={"起运港": "上海", "目的港": "海防", "品名": "机器设备"},
quote=tms,
collab_facts={},
sales_name="罗小华",
product_names=["林绵勋"],
has_price=True,
tms_quote=tms,
product_quote={
"source_label": "产品报价",
"fee_lines": [
{"name": "燃油附加费", "amount": "150.00", "currency": "USD"}
],
},
transport_mode="海运",
)
self.assertIn("TMS报价:", brief)
self.assertNotIn("TMS 暂无匹配报价", brief)
self.assertIn("人工报价:", brief)
def test_zero_tax_word_becomes_tax_rate(self) -> None:
quote = extract_product_quote(
LAND_VEHICLE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
# 「都是含0点税」= 税率 0;备注归一为「含0税」后仍留着给报价单备注列。
self.assertEqual(str(quote.get("tax_rate") or ""), "0")
self.assertIn(str(quote.get("remark") or ""), {"含0点税", "含0税"})
def test_plain_tax_word_does_not_invent_rate(self) -> None:
# 「含税」看不出点数,禁止猜成 0 或 13。
quote = extract_product_quote(
"东莞-春疆,7.6米CNY13000元;9.6米CNY14000;含税",
business_line="LAND",
transport_mode="陆运",
)
self.assertEqual(str(quote.get("tax_rate") or ""), "")
def test_multi_currency_fees_keep_fee_lines(self) -> None:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(
LAND_MULTI_CCY_SAMPLE, business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "春疆", "目的港": "罗勇"}}
)
text = "\n".join(
copy._manual_quote_lines(out, business_line="LAND", layout="manual")
)
# 逐项费用写法保持原样;原话只在后台展示,群里不再附参考行。
self.assertIn("运输费:USD 3200", text)
self.assertIn("报关费:CNY 1400", text)
self.assertNotIn("原始报价参考", text)
class ManualQuoteLandSingleVehicleTest(unittest.TestCase):
"""单档车型价:群里「8T CNY990」不能把 8 当运费(WO202611100043)。"""
def test_single_vehicle_rate_keeps_model_and_price(self) -> None:
quote = extract_product_quote(
"产品报价:8T CNY990", business_line="LAND", transport_mode="陆运"
)
# 8T 是车型、990 才是费用;旧实现丢掉单档车型价后在金额回退里抽到 8。
self.assertEqual(dict(quote.get("vehicleRates") or {}), {"8T": "990"})
self.assertEqual(str(quote.get("total") or ""), "990")
self.assertEqual(str(quote.get("currency") or ""), "CNY")
for row in quote.get("fee_rows") or []:
self.assertNotEqual(str(row.get("amount") or "").strip(), "8")
def test_single_vehicle_rate_summary_shows_model_and_money(self) -> None:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(
"8T CNY990", business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "深圳", "目的港": "香港"}}
)
text = "\n".join(
copy._manual_quote_lines(
out, business_line="LAND", transport_mode="陆运", layout="manual"
)
)
self.assertIn("车型/数量:8T", text)
self.assertIn("运输费:CNY990元", text)
self.assertNotIn("CNY8元", text)
def test_fee_name_glued_vehicle_rate_shows_tonnage_and_unit(self) -> None:
"""「运费10T:1700HKD/车」:摘要要出车型 10T、1700/车,条款进备注(WO202610300015)。"""
from agent.policy import inquiry_copy as copy
text = (
"深圳--香港元朗运费10T:1700HKD/车\n"
"超时费:免等候2小时,超出按200/小时收取;如遇海关查验,查验等候免3小时,"
"超过了200/小时,压夜按运费80%,压日按运费100%以上港币报价,不含保,杂费实报实"
)
quote = extract_product_quote(
text, business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"起运港": "深圳", "目的港": "香港"}}
)
lines = copy._manual_quote_lines(
out, business_line="LAND", transport_mode="陆运", layout="manual"
)
self.assertIn("车型/数量:10T", lines)
self.assertIn("运输费:HKD1700/车", lines)
self.assertTrue(any(line.startswith("备注:超时费:免等候2小时") for line in lines))
self.assertFalse(any("HKD10" in line for line in lines))
self.assertFalse(any(line.startswith("压夜按运费:") for line in lines))
def test_non_land_single_rate_keeps_old_two_tier_guard(self) -> None:
"""非陆运不改旧口径:没写「车型」且只有一档时仍不当车型矩阵。"""
quote = extract_product_quote(
"8T CNY990", business_line="SEA", transport_mode="海运"
)
self.assertFalse(dict(quote.get("vehicleRates") or {}))
self.assertEqual(str(quote.get("total") or ""), "990")
LAND_CLAUSE_SAMPLE = (
"运费1700HKD/车。超时费:免等候2小时,超出按200/小时收取;"
"如遇海关查验,查验等候免3小时,超过了200/小时,"
"压夜按运费80%,压日按运费100%以上港币报价,不含保,杂费实报实"
)
LAND_CLAUSE_TAIL = (
"超时费:免等候2小时,超出按200/小时收取;"
"如遇海关查验,查验等候免3小时,超过了200/小时,"
"压夜按运费80%,压日按运费100%以上港币报价,不含保,杂费实报实"
)
class ManualQuoteLandClauseTest(unittest.TestCase):
"""
2026-11-23 真机(WO202611230011):超时/压夜/压日整段是备注,不是费目。
原话只有「运费1700HKD/车 + 条款」,车型 10T 在询价字段里;
摘要要出「车型/数量:10T / 运输费:1700HKD/车 / 备注:条款」,
不能再出现「压夜按运费:80%」「压日按运费:100%」两行。
"""
def test_clause_is_not_fee_rows(self) -> None:
quote = extract_product_quote(
LAND_CLAUSE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
names = [str(r.get("name") or "") for r in (quote.get("fee_rows") or [])]
self.assertNotIn("压夜按运费", names)
self.assertNotIn("压日按运费", names)
for row in quote.get("fee_rows") or []:
self.assertNotIn("%", str(row.get("amount") or ""))
self.assertIn("压夜按运费80%", str(quote.get("remark") or ""))
self.assertEqual(str(quote.get("total") or ""), "1700.0")
def test_only_clause_is_not_a_quote(self) -> None:
# 整句只有压夜/压日比例时,不能把 80/100 当整票报价。
quote = extract_product_quote(
"压夜按运费80%,压日按运费100%",
business_line="LAND",
transport_mode="陆运",
)
self.assertEqual(quote, {})
def test_ticket_vehicle_makes_manual_layout(self) -> None:
from agent.policy import inquiry_copy as copy
quote = extract_product_quote(
LAND_CLAUSE_SAMPLE, business_line="LAND", transport_mode="陆运"
)
out = _attach_land_vehicle_rates_segment(
quote,
{"facts": {"起运港": "深圳", "目的港": "香港", "车型/数量": "10T"}},
)
lines = copy._manual_quote_lines(
out, business_line="LAND", transport_mode="陆运", layout="manual"
)
self.assertEqual(
lines,
[
"车型/数量:10T",
"运输费:HKD1700/车",
"备注:" + LAND_CLAUSE_TAIL,
],
)
text = "\n".join(lines)
self.assertNotIn("压夜按运费:", text)
self.assertNotIn("费用合计", text)
def test_other_absolute_fee_keeps_fee_rows(self) -> None:
# 还有报关费这类绝对金额时,不能整单吞成车型价。
quote = extract_product_quote(
"运费1700HKD/车,报关费300CNY。超时费:免等候2小时,压夜按运费80%",
business_line="LAND",
transport_mode="陆运",
)
out = _attach_land_vehicle_rates_segment(
quote, {"facts": {"车型/数量": "10T"}}
)
self.assertFalse(dict(out.get("vehicleRates") or {}))
names = [str(r.get("name") or "") for r in (out.get("fee_rows") or [])]
self.assertIn("运费", names)
self.assertIn("报关费", names)
for row in out.get("fee_rows") or []:
self.assertNotIn("%", str(row.get("amount") or ""))
class ManualQuoteRawTextMentionTest(unittest.TestCase):
"""落库的产品原话不能把「@机器人」当报价内容(2026-11-22 产品反馈)。"""
def test_extraction_drops_mention_from_raw_text(self) -> None:
# 写入主账的原话不该带 @机器人:后台详情直接展示这段留档。
quote = extract_product_quote(
"@智价通 " + AIR_SAMPLE, business_line="AIR", transport_mode="空运"
)
self.assertEqual(str(quote.get("raw_text") or ""), AIR_SAMPLE)
if __name__ == "__main__":
unittest.main()