""" 陆运选项单测:三项各自必填、不联动;中港拆进运输类型;补问只发复制清单,不再发填写样例图。 不连企微、主账、TMS。 """ 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) from agent.schema.land_options import ( harvest_land_options, looks_like_confirm, option_prompt, option_prompt_needs_sample, sample_pair_allowed, validate_land_options, ) class LandOptionsTest(unittest.TestCase): def test_any_type_route_combo_ok(self): got = validate_land_options( { "运输类型": "国内运输拼车", "线路类别": "东南亚", "运输分类": "急件", } ) self.assertTrue(got["ok"]) self.assertEqual(got["normalized"]["运输类型"], "国内运输拼车") self.assertEqual(got["normalized"]["线路类别"], "东南亚") def test_bare_hk_does_not_fill_type_or_route(self): cur = harvest_land_options("中港 急件") self.assertFalse(cur.get("运输类型")) self.assertFalse(cur.get("线路类别")) self.assertEqual(cur.get("运输分类"), "急件") def test_hk_full_and_lcl_types(self): self.assertEqual( harvest_land_options("中港整车")["运输类型"], "中港整车" ) self.assertEqual( harvest_land_options("中港零担/集拼 东南亚")["运输类型"], "中港零担/集拼", ) self.assertEqual( harvest_land_options("中港零担")["运输类型"], "中港零担/集拼" ) def test_new_class_names(self): cur = harvest_land_options( "普件(东南亚、中港常用线路/常规车型)" ) self.assertEqual( cur["运输分类"], "普件(东南亚、中港常用线路/常规车型)" ) self.assertFalse( harvest_land_options("普件,常用线路/常规车型").get("运输分类") ) def test_no_hk_load_field(self): got = validate_land_options( { "运输类型": "中港整车", "线路类别": "东南亚", "运输分类": "急件", } ) self.assertTrue(got["ok"]) self.assertNotIn("中港装载方式", got["missing"]) self.assertFalse(got["normalized"].get("中港装载方式")) def test_followup_route_class_keeps_type(self): cur = harvest_land_options( "国内城配/拖车/打包;普件(东南亚、中港常用线路/常规车型)", current={"运输类型": "国内运输拼车"}, ) self.assertEqual(cur["运输类型"], "国内运输拼车") self.assertEqual(cur["线路类别"], "国内城配/拖车/打包") self.assertEqual( cur["运输分类"], "普件(东南亚、中港常用线路/常规车型)" ) def test_model_land_does_not_wipe_type(self): dropped = harvest_land_options( "国内城配/拖车/打包;急件", current={"运输类型": "陆运"}, ) self.assertFalse(dropped.get("运输类型")) cur = harvest_land_options( "国内城配/拖车/打包;急件", current={"运输类型": "国内运输拼车"}, ) junk = harvest_land_options("陆运", current=cur) self.assertEqual(junk["运输类型"], "国内运输拼车") self.assertEqual(junk["线路类别"], "国内城配/拖车/打包") cur = harvest_land_options("广州到深圳国内拼车衣服100方") self.assertEqual(cur["运输类型"], "国内运输拼车") self.assertFalse(cur.get("线路类别")) def test_full_prompt_when_empty(self): text = option_prompt(current={}) self.assertIn("Step1: 请复制以下内容,粘贴到输入框;", text) self.assertIn("Step2:在粘贴内容的每个字段的冒号后,回复数字或文字,告诉我对应字段的值:", text) self.assertIn("---请复制以下内容---\n运输类型(必填):", text) self.assertIn("运输类型(必填):\n1.国内运输拼车", text) self.assertIn("6.中港零担/集拼", text) self.assertIn("线路类别(必填):\n1.1国内长途/零担", text) self.assertIn("6.1中港/中亚/中欧", text) self.assertIn("运输分类(必填):\n1.普件(常用线路/常规车型)", text) self.assertIn("2.普件(东南亚、中港常用线路/常规车型)", text) self.assertIn("5.急件", text) self.assertNotIn("请一次选择:运输类型", text) self.assertNotIn("可选择回复", text) self.assertNotIn("填写样例见图", text) self.assertNotIn("国内运输整车 + 国内城配/拖车/打包", text) self.assertNotIn("中港装载方式", text) def test_copy_alias_lists_new_types(self): from agent.policy import inquiry_copy as copy text = copy.ASK_LAND_SUBTYPE self.assertIn("中港整车", text) self.assertIn("Step1: 请复制以下内容,粘贴到输入框;", text) self.assertIn("---请复制以下内容---", text) self.assertNotIn("请补充陆运类型:国内运输拼车", text) def test_sample_table_when_route_missing(self): text = option_prompt(current={"运输类型": "国内运输拼车"}) self.assertIn("Step1: 请复制以下内容,粘贴到输入框;", text) self.assertIn("---请复制以下内容---\n线路类别(必填):", text) self.assertIn("线路类别(必填):\n1.1国内长途/零担", text) self.assertIn("运输分类(必填):\n1.普件", text) self.assertFalse(option_prompt_needs_sample(current={"运输类型": "国内运输拼车"})) self.assertFalse(option_prompt_needs_sample(current={})) self.assertNotIn("国内运输拼车 + 国内长途/零担", text) self.assertNotIn("请一次选择:运输类型", text) self.assertNotIn("运输类型(必填)", text) def test_sample_pairs_go_to_image_not_text(self): text = option_prompt(current={}) self.assertIn("Step1: 请复制以下内容,粘贴到输入框;", text) self.assertIn("---请复制以下内容---", text) self.assertNotIn("填写样例见图", text) self.assertNotIn("填写样例", text) self.assertNotIn("国内运输拼车 + 国内长途/零担", text) def test_no_sample_when_only_class_missing(self): text = option_prompt( current={ "运输类型": "国内运输拼车", "线路类别": "东南亚", } ) self.assertIn("运输分类(必填)", text) self.assertNotIn("填写样例", text) def test_sample_pair_gate(self): self.assertTrue(sample_pair_allowed("国内运输拼车", "国内长途/零担")) self.assertTrue(sample_pair_allowed("国内运输整车", "国内城配/拖车/打包")) self.assertTrue(sample_pair_allowed("国内运输整车", "国内长途/零担")) self.assertTrue(sample_pair_allowed("中港整车", "中港/中亚/中欧")) self.assertFalse(sample_pair_allowed("国内运输拼车", "东南亚")) self.assertFalse(sample_pair_allowed("中港整车", "东南亚")) def test_scrub_template_ports(self): from agent.schema.land_options import scrub_land_placeholder_ports out = scrub_land_placeholder_ports( {"起运港": "DOM", "目的港": "FTL", "品名": "衣服", "运输类型": "国内运输整车"} ) self.assertNotIn("起运港", out) self.assertNotIn("目的港", out) self.assertEqual(out.get("品名"), "衣服") def test_paste_numbers_and_codes(self): """复制清单后在冒号后填数字/编号,要收到标准项。""" pasted = ( "运输类型(必填):2\n" "线路类别(必填):2.1\n" "运输分类(必填):5" ) got = harvest_land_options(pasted) self.assertEqual(got.get("运输类型"), "国内运输整车") self.assertEqual(got.get("线路类别"), "国内长途/零担") self.assertEqual(got.get("运输分类"), "急件") def test_common_route_class_only_full_text_or_number(self): """新项只认编号 1 或全文;短话和逗号写法不收。""" full = "普件(常用线路/常规车型)" self.assertEqual(harvest_land_options(full).get("运输分类"), full) numbered = harvest_land_options( "1", current={"运输类型": "国内运输拼车", "线路类别": "国内长途/零担"}, ) self.assertEqual(numbered.get("运输分类"), full) self.assertFalse(harvest_land_options("常用线路").get("运输分类")) self.assertFalse(harvest_land_options("常规车型").get("运输分类")) self.assertFalse(harvest_land_options("普件,常用线路/常规车型").get("运输分类")) def test_route_code_infers_type_when_empty(self): got = harvest_land_options("1.1") self.assertEqual(got.get("运输类型"), "国内运输拼车") self.assertEqual(got.get("线路类别"), "国内长途/零担") def test_unfilled_prompt_does_not_eat_menu(self): """原样粘贴未填的清单,不能把选项名当成已选。""" got = harvest_land_options(option_prompt(current={})) self.assertFalse(got.get("运输类型")) self.assertFalse(got.get("线路类别")) self.assertFalse(got.get("运输分类")) def test_confirm_intent(self): self.assertTrue(looks_like_confirm("确认")) self.assertTrue(looks_like_confirm("确定")) self.assertTrue(looks_like_confirm("可以查了")) self.assertTrue(looks_like_confirm("查价")) self.assertFalse(looks_like_confirm("广州到深圳衣服")) # 询价正文里的「确认」不是点核对卡。 self.assertFalse( looks_like_confirm( "服务器、不带电,预计7月初货好,因货值较高 派送需确认安全运输方案,比如押运。" ) ) if __name__ == "__main__": unittest.main()