test_tool_description_boundaries.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import unittest
  2. from tools.export_out_of_province_port_data import (
  3. ExportOutOfProvincePortDataTool,
  4. )
  5. from tools.export_pallet_data import ExportPalletDataTool
  6. from tools.export_pending_outbound_orders import ExportPendingOutboundOrdersTool
  7. from tools.list_order_filter_options import ListOrderFilterOptionsTool
  8. from tools.list_pending_outbound_export_filter_options import (
  9. ListPendingOutboundExportFilterOptionsTool,
  10. )
  11. from tools.query_customs_declaration_files import QueryCustomsDeclarationFilesTool
  12. from tools.query_order import QueryOrderTool
  13. from tools.query_order_detail import QueryOrderDetailTool
  14. from tools.query_order_exact import QueryOrderExactTool
  15. from tools.query_outbound_detail import QueryOutboundDetailTool
  16. from tools.query_outbound_list import QueryOutboundListTool
  17. from tools.query_destination_trailer_list import QueryDestinationTrailerListTool
  18. from tools.list_destination_trailer_filter_options import (
  19. ListDestinationTrailerFilterOptionsTool,
  20. )
  21. from tools.query_order_abnormal_list import QueryOrderAbnormalListTool
  22. from tools.list_order_abnormal_filter_options import (
  23. ListOrderAbnormalFilterOptionsTool,
  24. )
  25. from tools.query_goods_info import QueryGoodsInfoTool
  26. from tools.trial_goods_tax import TrialGoodsTaxTool
  27. from tools.query_receive_volume_list import QueryReceiveVolumeListTool
  28. from tools.list_receive_volume_filter_options import (
  29. ListReceiveVolumeFilterOptionsTool,
  30. )
  31. from tools.query_container_timeliness_list import QueryContainerTimelinessListTool
  32. from tools.export_container_timeliness_report import (
  33. ExportContainerTimelinessReportTool,
  34. )
  35. from tools.query_track import QueryTrackTool
  36. class ToolDescriptionBoundaryTest(unittest.TestCase):
  37. def test_every_existing_tool_states_use_and_prohibition_boundaries(self):
  38. tools = (
  39. QueryOrderTool(),
  40. QueryOrderExactTool(),
  41. QueryTrackTool(),
  42. QueryCustomsDeclarationFilesTool(),
  43. QueryOutboundListTool(),
  44. QueryOutboundDetailTool(),
  45. ListOrderFilterOptionsTool(),
  46. ListPendingOutboundExportFilterOptionsTool(),
  47. ExportPendingOutboundOrdersTool(),
  48. ExportOutOfProvincePortDataTool(),
  49. ExportPalletDataTool(),
  50. QueryDestinationTrailerListTool(),
  51. ListDestinationTrailerFilterOptionsTool(),
  52. QueryOrderAbnormalListTool(),
  53. ListOrderAbnormalFilterOptionsTool(),
  54. QueryReceiveVolumeListTool(),
  55. QueryGoodsInfoTool(),
  56. TrialGoodsTaxTool(),
  57. ListReceiveVolumeFilterOptionsTool(),
  58. QueryContainerTimelinessListTool(),
  59. ExportContainerTimelinessReportTool(),
  60. )
  61. for tool in tools:
  62. with self.subTest(tool=tool.name):
  63. description = tool.metadata()['description']
  64. self.assertIn('使用场景:', description)
  65. self.assertIn('禁止使用:', description)
  66. def test_number_tools_require_clarification_and_forbid_trial_queries(self):
  67. tools = (
  68. QueryOrderTool(),
  69. QueryOrderExactTool(),
  70. QueryTrackTool(),
  71. QueryCustomsDeclarationFilesTool(),
  72. QueryOutboundListTool(),
  73. QueryOutboundDetailTool(),
  74. ExportOutOfProvincePortDataTool(),
  75. ExportPalletDataTool(),
  76. QueryDestinationTrailerListTool(),
  77. QueryOrderAbnormalListTool(),
  78. QueryContainerTimelinessListTool(),
  79. ExportContainerTimelinessReportTool(),
  80. TrialGoodsTaxTool(),
  81. )
  82. for tool in tools:
  83. with self.subTest(tool=tool.name):
  84. description = tool.metadata()['description']
  85. self.assertIn('号码类型不明确时必须先询问用户', description)
  86. self.assertIn('不得根据号码格式猜测', description)
  87. self.assertIn('不得跨字段或跨工具试查', description)
  88. def test_result_intent_distinguishes_adjacent_tools(self):
  89. expected = {
  90. QueryOrderTool(): ('旧版跨字段通用搜索', 'query_order_exact', '订单列表'),
  91. QueryOrderExactTool(): ('订单列表', 'query_order_detail', '排舱列表'),
  92. QueryOrderDetailTool(): ('单个订单的详情', '逐个调用', 'query_order_exact', '订单列表'),
  93. QueryTrackTool(): ('物流轨迹', '订单资料', '报关资料文件'),
  94. QueryCustomsDeclarationFilesTool(): ('报关资料文件', '完整排舱详情', '文件链接'),
  95. QueryOutboundListTool(): ('排舱列表', '40个字段', '排舱详情'),
  96. QueryOutboundDetailTool(): ('排舱详情', '11项汇总', '38项订单明细'),
  97. ListOrderFilterOptionsTool(): ('query_order_exact', '授权筛选值', '业务数据'),
  98. ListPendingOutboundExportFilterOptionsTool(): (
  99. 'export_pending_outbound_orders', '授权筛选值', 'query_outbound_list',
  100. ),
  101. ExportPendingOutboundOrdersTool(): ('明确要求导出', '未排舱订单', '查看或查询'),
  102. ExportOutOfProvincePortDataTool(): ('明确要求导出', '省外进港资料', '普通排舱查询'),
  103. ExportPalletDataTool(): ('明确要求导出', '打托数据', 'query_export_task'),
  104. QueryDestinationTrailerListTool(): (
  105. '海外提柜', 'query_outbound_list', '六个类型',
  106. ),
  107. ListDestinationTrailerFilterOptionsTool(): (
  108. 'query_destination_trailer_list', '禁止猜测', '排舱列表',
  109. ),
  110. QueryOrderAbnormalListTool(): (
  111. '头程问题件', 'admin/Order/abnormal', 'query_order',
  112. ),
  113. ListOrderAbnormalFilterOptionsTool(): (
  114. 'query_order_abnormal_list', '禁止猜测', '作废审核',
  115. ),
  116. QueryReceiveVolumeListTool(): (
  117. '收货量', 'admin/Report/receiveForm', 'query_order',
  118. ),
  119. ListReceiveVolumeFilterOptionsTool(): (
  120. 'query_receive_volume_list', '禁止猜测', '导出',
  121. ),
  122. QueryContainerTimelinessListTool(): (
  123. '柜子时效', 'admin/Report/outboundReport', 'query_outbound_list',
  124. ),
  125. ExportContainerTimelinessReportTool(): (
  126. '明确要求导出', '柜子时效', 'query_export_task',
  127. ),
  128. }
  129. for tool, phrases in expected.items():
  130. with self.subTest(tool=tool.name):
  131. description = tool.metadata()['description']
  132. for phrase in phrases:
  133. self.assertIn(phrase, description)
  134. def test_outbound_number_fields_require_explicit_business_types(self):
  135. properties = QueryOutboundListTool().metadata()['input_schema']['properties']
  136. for field, label in (
  137. ('outbound_numbers', '排舱单号'),
  138. ('order_numbers', '订单号'),
  139. ('container_codes', '柜号'),
  140. ('so_numbers', 'SO号'),
  141. ('bl_numbers', '提单号'),
  142. ):
  143. with self.subTest(field=field):
  144. description = properties[field]['description']
  145. self.assertIn(label, description)
  146. self.assertIn('仅当用户明确', description)
  147. self.assertIn('不得放入其他类型号码', description)
  148. def test_export_tools_describe_async_follow_up_without_long_wait(self):
  149. for tool in (
  150. ExportPendingOutboundOrdersTool(),
  151. ExportOutOfProvincePortDataTool(),
  152. ExportPalletDataTool(),
  153. ExportContainerTimelinessReportTool(),
  154. ):
  155. with self.subTest(tool=tool.name):
  156. description = tool.metadata()['description']
  157. self.assertIn('异步导出任务', description)
  158. self.assertIn('query_export_task', description)
  159. self.assertIn('不会在本次调用中等待文件生成', description)
  160. if __name__ == '__main__':
  161. unittest.main()