feat: open bot access and guide invalid delivery queries

This commit is contained in:
ar51
2026-09-28 10:05:53 +08:00
parent 1c25c9e1d9
commit f35351d540
8 changed files with 101 additions and 47 deletions

View File

@@ -116,6 +116,29 @@ class TriggerGateTests(unittest.TestCase):
react.assert_not_called()
reply.assert_not_called()
def test_invalid_inputs_get_guidance_without_query_or_reaction(self) -> None:
for chat_type, text in [
("p2p", "你好"), ("p2p", None),
("p2p", "还有吗"), ("group", "交期怎么查"),
("group", "eRob110H160I-FHM-18ET[V6]"),
("group", "eRob110H160I-FHM-18ET[V6] 10台或20台"),
("group", "eRob110H160I-FHM-18ET[V6] 10台 eRob142H100I-BHM-18ET[V4] 20台"),
]:
with self.subTest(chat_type=chat_type, text=text):
data = message_event("om_help", "oc_help", "ou_help")
data.event.message.chat_type = chat_type
with (
mock.patch.object(bridge, "message_text", return_value=text),
mock.patch.object(bridge, "build_report") as build,
mock.patch.object(bridge, "add_received_reaction") as react,
mock.patch.object(bridge, "reply") as reply,
):
bridge.handle_message("client", data)
build.assert_not_called()
react.assert_not_called()
reply.assert_called_once()
self.assertIn("提问示例", reply.call_args.args[2])
def test_valid_message_builds_and_replies(self) -> None:
data = SimpleNamespace(
event=SimpleNamespace(message=SimpleNamespace(message_id="om_valid"))
@@ -270,7 +293,7 @@ class TriggerGateTests(unittest.TestCase):
with self.subTest(phrase=phrase):
self.assertFalse(bridge.is_candidate_continuation_request(phrase))
def test_continuation_without_same_conversation_context_is_silent(self) -> None:
def test_continuation_without_same_conversation_context_gets_guidance(self) -> None:
data = message_event("om_more", "oc_other", "ou_other")
with (
@@ -290,7 +313,8 @@ class TriggerGateTests(unittest.TestCase):
build_report.assert_not_called()
react.assert_not_called()
reply.assert_not_called()
reply.assert_called_once()
self.assertIn("当前没有可继续的查询", reply.call_args.args[2])
def test_follow_up_continues_from_fifth_candidate_in_same_conversation(self) -> None:
request_text = "eRob70H50I-FS-18CN[V5] 10台"
@@ -362,7 +386,9 @@ class TriggerGateTests(unittest.TestCase):
bridge.RequestInput(model="eRob70H50I-BHM-18CTC[V5]", quantity=10)
)
react.assert_called_once_with("client", "om_small")
reply.assert_called_once_with("client", "om_small", "report")
self.assertEqual(reply.call_count, 2)
self.assertEqual(reply.call_args_list[0], mock.call("client", "om_small", "report"))
self.assertIn("当前没有可继续的查询", reply.call_args.args[2])
def test_expired_candidate_context_is_removed(self) -> None:
key = "oc_expired:ou_expired"