更新
This commit is contained in:
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
from unittest import TestCase, main, mock
|
||||
|
||||
import wechat_gui
|
||||
from gui_runtime import LogQueue, delete_pending_reply_file
|
||||
from wechat_bot import WeChatBot
|
||||
|
||||
|
||||
@@ -128,6 +129,109 @@ class RuntimeSettingsTest(TestCase):
|
||||
)
|
||||
self.assertIn("7 秒", rendered)
|
||||
|
||||
def test_classic_capsule_renders_each_progress_message_as_a_numbered_step(self):
|
||||
app = wechat_gui.App.__new__(wechat_gui.App)
|
||||
app._running = True
|
||||
app._capsule_progress_text = ""
|
||||
app._capsule_progress_step = 0
|
||||
app._capsule_progress = mock.Mock()
|
||||
|
||||
app._update_capsule_progress("消息读取 6/8 · 复制聊天第 1/1 屏")
|
||||
|
||||
app._capsule_progress.configure.assert_called_once_with(
|
||||
text="步骤 001 · 消息读取 6/8 · 复制聊天第 1/1 屏"
|
||||
)
|
||||
self.assertEqual(app._capsule_progress_step, 1)
|
||||
self.assertEqual(app._capsule_progress_text, "消息读取 6/8 · 复制聊天第 1/1 屏")
|
||||
|
||||
def test_classic_queue_consumes_the_runtime_progress_channel(self):
|
||||
app = wechat_gui.App.__new__(wechat_gui.App)
|
||||
app._queue = queue.Queue()
|
||||
app._queue.put(("progress", "视觉识别 3/4 · 等待多模态模型分析"))
|
||||
app._sync_console_dpi = mock.Mock()
|
||||
app._update_capsule_progress = mock.Mock()
|
||||
app._start_time = None
|
||||
app._running = True
|
||||
app.after = mock.Mock()
|
||||
|
||||
app._process_queue()
|
||||
|
||||
app._update_capsule_progress.assert_called_once_with(
|
||||
"视觉识别 3/4 · 等待多模态模型分析"
|
||||
)
|
||||
|
||||
def test_atomic_operation_progress_includes_phase_step_detail_and_customer(self):
|
||||
bot = WeChatBot.__new__(WeChatBot)
|
||||
fp = b"customer"
|
||||
bot._pending_reply_sessions = {
|
||||
fp.hex(): {"display_name": "高瑞@微信"}
|
||||
}
|
||||
bot._progress_text = ""
|
||||
bot.progress_cb = mock.Mock()
|
||||
|
||||
bot.report_operation("发送", 9, 12, "按 Ctrl+V 粘贴回复", fp)
|
||||
|
||||
bot.progress_cb.assert_called_once_with(
|
||||
"发送 9/12 · 按 Ctrl+V 粘贴回复 · 高瑞@微信"
|
||||
)
|
||||
|
||||
def test_tagged_low_level_logs_are_mirrored_to_capsule_progress(self):
|
||||
target = queue.Queue()
|
||||
log = LogQueue.__new__(LogQueue)
|
||||
log.target_queue = target
|
||||
log._handle = None
|
||||
|
||||
log.write(" [未读扫描] 正在从列表顶部逐页查找未置顶未读…")
|
||||
|
||||
self.assertEqual(target.get_nowait()[0], "log")
|
||||
self.assertEqual(
|
||||
target.get_nowait(),
|
||||
("progress", "未读扫描 · 正在从列表顶部逐页查找未置顶未读…"),
|
||||
)
|
||||
|
||||
def test_customer_chat_body_is_not_mirrored_into_floating_capsule(self):
|
||||
self.assertEqual(
|
||||
LogQueue.progress_from_log("[AI] 本次提取的新内容:\n客户隐私正文"),
|
||||
"",
|
||||
)
|
||||
|
||||
def test_message_copy_retries_when_wecom_writes_clipboard_late(self):
|
||||
bot = WeChatBot.__new__(WeChatBot)
|
||||
bot.report_operation = mock.Mock()
|
||||
sentinel = WeChatBot._CLIP_SENTINEL
|
||||
clipboard_reads = [sentinel] + [sentinel] * 6 + ["客户刚发的消息"]
|
||||
|
||||
with mock.patch("wechat_bot.pyperclip.copy"), \
|
||||
mock.patch("wechat_bot.pyperclip.paste", side_effect=clipboard_reads), \
|
||||
mock.patch("wechat_bot.pyautogui.hotkey") as hotkey, \
|
||||
mock.patch("wechat_bot.time.sleep"):
|
||||
copied = bot._copy_selection()
|
||||
|
||||
self.assertEqual(copied, "客户刚发的消息")
|
||||
self.assertEqual(hotkey.call_count, 2)
|
||||
|
||||
def test_manual_queue_delete_removes_only_selected_full_key_atomically(self):
|
||||
first = "a" * 80
|
||||
second = "b" * 80
|
||||
payload = {
|
||||
"pending": {
|
||||
first: {"display_name": "甲", "created_at": 1},
|
||||
second: {"display_name": "乙", "created_at": 2},
|
||||
},
|
||||
"version": 1,
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path = Path(folder) / "pending_replies.json"
|
||||
path.write_text(json.dumps(payload, ensure_ascii=False), encoding="utf-8")
|
||||
with mock.patch("queue_log.QueueLog"):
|
||||
result = delete_pending_reply_file([first], str(path))
|
||||
saved = json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
self.assertEqual(result["deleted"], [first])
|
||||
self.assertNotIn(first, saved["pending"])
|
||||
self.assertIn(second, saved["pending"])
|
||||
self.assertEqual(saved["version"], 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user