diff --git a/app/chain/site.py b/app/chain/site.py index aa5786dc..a0c19322 100644 --- a/app/chain/site.py +++ b/app/chain/site.py @@ -789,6 +789,7 @@ class SiteChain(ChainBase): userid=userid, username=username, title="站点交互已结束", + save_history=False, ) ) return True diff --git a/app/chain/skills.py b/app/chain/skills.py index 331d751e..4eaf0f1c 100644 --- a/app/chain/skills.py +++ b/app/chain/skills.py @@ -266,6 +266,7 @@ class SkillsChain(ChainBase): userid=userid, username=username, title="技能交互已结束", + save_history=False, ) ) return True diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 65ec3d6c..cb88fc4b 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -2240,6 +2240,7 @@ class SubscribeChain(ChainBase): userid=userid, username=username, title="订阅交互已结束", + save_history=False, ) ) return True diff --git a/tests/test_skills_command.py b/tests/test_skills_command.py index 6d9370a5..343ec9ee 100644 --- a/tests/test_skills_command.py +++ b/tests/test_skills_command.py @@ -90,6 +90,30 @@ class TestSkillsCommand(unittest.TestCase): handle_text.assert_called_once() handle_ai.assert_not_called() + def test_skills_text_exit_skips_notification_history(self): + chain = SkillsChain() + skills_interaction_manager.create_or_replace( + user_id="10001", + channel=MessageChannel.Telegram, + source="telegram-test", + username="tester", + ) + + with patch.object(chain, "post_message") as post_message: + handled = chain.handle_text_interaction( + channel=MessageChannel.Telegram, + source="telegram-test", + userid="10001", + username="tester", + text="退出", + ) + + self.assertTrue(handled) + notification = post_message.call_args.args[0] + self.assertEqual(notification.title, "技能交互已结束") + self.assertFalse(notification.save_history) + self.assertIsNone(skills_interaction_manager.get_by_user("10001")) + def test_callback_routes_to_skills_chain(self): chain = MessageChain() request = skills_interaction_manager.create_or_replace( diff --git a/tests/test_slash_command_interactions.py b/tests/test_slash_command_interactions.py index 8a2e23e0..79f89aee 100644 --- a/tests/test_slash_command_interactions.py +++ b/tests/test_slash_command_interactions.py @@ -147,6 +147,56 @@ class TestSlashCommandInteractions(unittest.TestCase): handle_callback.assert_called_once() + def test_sites_text_exit_skips_notification_history(self): + chain = SiteChain() + site_interaction_manager.create_or_replace( + user_id="10001", + command="/sites", + channel=MessageChannel.Telegram, + source="telegram-test", + username="tester", + ) + + with patch.object(chain, "post_message") as post_message: + handled = chain.handle_text_interaction( + channel=MessageChannel.Telegram, + source="telegram-test", + userid="10001", + username="tester", + text="退出", + ) + + self.assertTrue(handled) + notification = post_message.call_args.args[0] + self.assertEqual(notification.title, "站点交互已结束") + self.assertFalse(notification.save_history) + self.assertIsNone(site_interaction_manager.get_by_user("10001")) + + def test_subscribes_text_exit_skips_notification_history(self): + chain = SubscribeChain() + subscribe_interaction_manager.create_or_replace( + user_id="10001", + command="/subscribes", + channel=MessageChannel.Telegram, + source="telegram-test", + username="tester", + ) + + with patch.object(chain, "post_message") as post_message: + handled = chain.handle_text_interaction( + channel=MessageChannel.Telegram, + source="telegram-test", + userid="10001", + username="tester", + text="退出", + ) + + self.assertTrue(handled) + notification = post_message.call_args.args[0] + self.assertEqual(notification.title, "订阅交互已结束") + self.assertFalse(notification.save_history) + self.assertIsNone(subscribe_interaction_manager.get_by_user("10001")) + def test_sites_renders_markdown_table_when_channel_supports_markdown(self): chain = SiteChain() fake_sites = [