"""Startup handoff feedback describes executed and blocked actions separately.""" import queue from types import SimpleNamespace import unittest from unittest import mock from gui_runtime import BotThread class QueuedHandoffReportTests(unittest.TestCase): def test_confirmation_needed_after_startup_only_prompts_return_to_queue(self): events=queue.Queue() thread=BotThread(events,'合成回复',.2) result=thread.handoff_pending_tasks(['receipt']) self.assertEqual(result['scheduled'],['receipt']) bot=SimpleNamespace(handoff_pending_replies=mock.Mock(return_value={ 'handed_off':[],'protected':['receipt'],'requires_confirmation':['receipt']})) thread._drain_queued_handoffs(bot) thread._drain_queued_handoffs(bot) bot.handoff_pending_replies.assert_called_once_with({'receipt'},confirm_uncertain=False) messages=list(events.queue) self.assertEqual(len(messages),1) self.assertEqual(messages[0][0],'log') self.assertIn('此次未执行移交',messages[0][1]) self.assertIn('返回任务队列',messages[0][1]) self.assertIn('重新点击转人工并确认',messages[0][1]) self.assertNotIn('启动后已将',messages[0][1]) def test_partial_result_counts_only_completed_tasks_as_handed_off(self): events=queue.Queue() thread=BotThread(events,'合成回复',.2) keys={'accepted','receipt','sending','missing','scheduled'} thread.handoff_pending_tasks(keys) bot=SimpleNamespace(handoff_pending_replies=mock.Mock(return_value={ 'handed_off':['accepted'],'deleted':['accepted'], 'protected':['receipt','sending'],'requires_confirmation':['receipt'], 'missing':['missing'],'scheduled':['scheduled']})) thread._drain_queued_handoffs(bot) bot.handoff_pending_replies.assert_called_once_with(keys,confirm_uncertain=False) messages=[text for kind,text in events.queue if kind=='log'] self.assertEqual(len(messages),5) self.assertEqual(sum('启动后已将 1 条任务交给人工' in text for text in messages),1) self.assertTrue(any('1 条任务仍在等待处理,尚未完成交接' in text for text in messages)) self.assertTrue(any('1 条任务仍受发送或账号保护,此次未执行移交' in text for text in messages)) self.assertTrue(any('1 条任务已不在待处理队列,此次未执行交接' in text for text in messages)) self.assertNotIn('启动后已将 5', '\n'.join(messages)) if __name__=='__main__': unittest.main()