""" 陆运选项联动单测:类型/线路/分类/中港装载,选错只纠正该项。 不连企微、主账、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, validate_land_options, ) class LandOptionsTest(unittest.TestCase): def test_domestic_ltl_rejects_sea_route(self): got = validate_land_options( { "运输类型": "国内运输拼车", "线路类别": "东南亚", "运输分类": "急件", } ) self.assertFalse(got["ok"]) msg = got["errors"][0]["message"] self.assertIn("国内长途/零担", msg) self.assertIn("国内城配/拖车/打包", msg) 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("运输类型", text) self.assertIn("线路类别", text) self.assertIn("运输分类", text) self.assertIn("国内运输拼车", text) self.assertIn("整车", text) self.assertNotIn("请补充陆运类型:", text) def test_copy_alias_lists_all_three(self): from agent.policy import inquiry_copy as copy text = copy.ASK_LAND_SUBTYPE self.assertIn("运输类型", text) self.assertIn("线路类别", text) self.assertIn("运输分类", text) self.assertNotIn("请补充陆运类型:国内运输拼车", text) def test_narrow_prompt_when_type_known(self): text = option_prompt(current={"运输类型": "国内运输拼车"}) self.assertIn("国内长途/零担", text) self.assertNotIn("请选择运输类型", text) def test_hk_needs_load(self): got = validate_land_options( { "运输类型": "中港", "线路类别": "东南亚", "运输分类": "急件", } ) self.assertIn("中港装载方式", got["missing"]) def test_confirm_intent(self): self.assertTrue(looks_like_confirm("确认")) self.assertTrue(looks_like_confirm("可以查了")) self.assertTrue(looks_like_confirm("查价")) self.assertFalse(looks_like_confirm("广州到深圳衣服")) if __name__ == "__main__": unittest.main()