test_tool_description_boundaries.py 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import unittest
  2. from tools.export_out_of_province_port_data import (
  3. ExportOutOfProvincePortDataTool,
  4. )
  5. from tools.export_pending_outbound_orders import ExportPendingOutboundOrdersTool
  6. from tools.list_order_filter_options import ListOrderFilterOptionsTool
  7. from tools.list_pending_outbound_export_filter_options import (
  8. ListPendingOutboundExportFilterOptionsTool,
  9. )
  10. from tools.query_customs_declaration_files import QueryCustomsDeclarationFilesTool
  11. from tools.query_order import QueryOrderTool
  12. from tools.query_order_exact import QueryOrderExactTool
  13. from tools.query_outbound_detail import QueryOutboundDetailTool
  14. from tools.query_outbound_list import QueryOutboundListTool
  15. from tools.query_track import QueryTrackTool
  16. class ToolDescriptionBoundaryTest(unittest.TestCase):
  17. def test_every_existing_tool_states_use_and_prohibition_boundaries(self):
  18. tools = (
  19. QueryOrderTool(),
  20. QueryOrderExactTool(),
  21. QueryTrackTool(),
  22. QueryCustomsDeclarationFilesTool(),
  23. QueryOutboundListTool(),
  24. QueryOutboundDetailTool(),
  25. ListOrderFilterOptionsTool(),
  26. ListPendingOutboundExportFilterOptionsTool(),
  27. ExportPendingOutboundOrdersTool(),
  28. ExportOutOfProvincePortDataTool(),
  29. )
  30. for tool in tools:
  31. with self.subTest(tool=tool.name):
  32. description = tool.metadata()['description']
  33. self.assertIn('使用场景:', description)
  34. self.assertIn('禁止使用:', description)
  35. def test_number_tools_require_clarification_and_forbid_trial_queries(self):
  36. tools = (
  37. QueryOrderTool(),
  38. QueryOrderExactTool(),
  39. QueryTrackTool(),
  40. QueryCustomsDeclarationFilesTool(),
  41. QueryOutboundListTool(),
  42. QueryOutboundDetailTool(),
  43. ExportOutOfProvincePortDataTool(),
  44. )
  45. for tool in tools:
  46. with self.subTest(tool=tool.name):
  47. description = tool.metadata()['description']
  48. self.assertIn('号码类型不明确时必须先询问用户', description)
  49. self.assertIn('不得根据号码格式猜测', description)
  50. self.assertIn('不得跨字段或跨工具试查', description)
  51. def test_result_intent_distinguishes_adjacent_tools(self):
  52. expected = {
  53. QueryOrderTool(): ('旧版跨字段通用搜索', 'query_order_exact', '订单列表'),
  54. QueryOrderExactTool(): ('订单资料', '排舱列表', '物流轨迹'),
  55. QueryTrackTool(): ('物流轨迹', '订单资料', '报关资料文件'),
  56. QueryCustomsDeclarationFilesTool(): ('报关资料文件', '完整排舱详情', '文件链接'),
  57. QueryOutboundListTool(): ('排舱列表', '19个字段', '排舱详情'),
  58. QueryOutboundDetailTool(): ('排舱详情', '11项汇总', '34项订单明细'),
  59. ListOrderFilterOptionsTool(): ('query_order_exact', '授权筛选值', '业务数据'),
  60. ListPendingOutboundExportFilterOptionsTool(): (
  61. 'export_pending_outbound_orders', '授权筛选值', 'query_outbound_list',
  62. ),
  63. ExportPendingOutboundOrdersTool(): ('明确要求导出', '未排舱订单', '查看或查询'),
  64. ExportOutOfProvincePortDataTool(): ('明确要求导出', '省外进港资料', '普通排舱查询'),
  65. }
  66. for tool, phrases in expected.items():
  67. with self.subTest(tool=tool.name):
  68. description = tool.metadata()['description']
  69. for phrase in phrases:
  70. self.assertIn(phrase, description)
  71. def test_outbound_number_fields_require_explicit_business_types(self):
  72. properties = QueryOutboundListTool().metadata()['input_schema']['properties']
  73. for field, label in (
  74. ('outbound_numbers', '排舱单号'),
  75. ('order_numbers', '订单号'),
  76. ('container_codes', '柜号'),
  77. ('so_numbers', 'SO号'),
  78. ('bl_numbers', '提单号'),
  79. ):
  80. with self.subTest(field=field):
  81. description = properties[field]['description']
  82. self.assertIn(label, description)
  83. self.assertIn('仅当用户明确', description)
  84. self.assertIn('不得放入其他类型号码', description)
  85. if __name__ == '__main__':
  86. unittest.main()