92 lines
3.7 KiB
Python
92 lines
3.7 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from isphere_ai_bridge import mcp_api
|
|
|
|
|
|
class OfflineLabTests(unittest.TestCase):
|
|
def test_offline_lab_simulates_main_window_search_chat_and_files(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
workspace = str(Path(tmp) / "offline-lab")
|
|
|
|
start = mcp_api.offline_lab_start(workspace=workspace, reset=True)
|
|
self.assertTrue(start["started"])
|
|
self.assertEqual("offline-lab-simulated", start["mode"])
|
|
self.assertTrue(start["main_window"]["opened"])
|
|
|
|
users = mcp_api.offline_lab_search_users("文件", workspace=workspace)
|
|
self.assertEqual(1, users["count"])
|
|
user_jid = users["users"][0]["jid"]
|
|
|
|
opened = mcp_api.offline_lab_open_chat(user_jid, workspace=workspace)
|
|
self.assertTrue(opened["opened"])
|
|
self.assertEqual("p2p-chat", opened["main_window"]["active_panel"])
|
|
|
|
sent = mcp_api.offline_lab_send_message(
|
|
user_jid,
|
|
"这是一条离线模拟发送消息",
|
|
workspace=workspace,
|
|
)
|
|
self.assertTrue(sent["sent"])
|
|
self.assertEqual("outgoing", sent["message"]["direction"])
|
|
self.assertEqual("frmP2PChat.SaveAndShowMessage", sent["message"]["ui_hook"])
|
|
|
|
received = mcp_api.offline_lab_receive_message(
|
|
user_jid,
|
|
"这是一条离线模拟接收消息",
|
|
workspace=workspace,
|
|
)
|
|
self.assertTrue(received["received"])
|
|
self.assertEqual("incoming", received["message"]["direction"])
|
|
self.assertEqual("frmP2PChat.ProccessRecvMessage", received["message"]["ui_hook"])
|
|
|
|
outbound_file = Path(tmp) / "demo.txt"
|
|
outbound_file.write_text("file payload", encoding="utf-8")
|
|
send_file = mcp_api.offline_lab_send_file(
|
|
user_jid,
|
|
str(outbound_file),
|
|
workspace=workspace,
|
|
)
|
|
self.assertTrue(send_file["sent"])
|
|
self.assertEqual("file", send_file["file_event"]["content_type"])
|
|
self.assertEqual(True, send_file["file_event"]["attachments"][0]["exists"])
|
|
self.assertEqual(
|
|
"frmP2PChat.SendTcpFiles/SendOfflineFiles -> UC_FileSend",
|
|
send_file["file_event"]["ui_hook"],
|
|
)
|
|
|
|
receive_file = mcp_api.offline_lab_receive_file(
|
|
user_jid,
|
|
"incoming-report.pdf",
|
|
size=4096,
|
|
workspace=workspace,
|
|
)
|
|
self.assertTrue(receive_file["received"])
|
|
self.assertEqual(4096, receive_file["file_event"]["attachments"][0]["size"])
|
|
self.assertEqual(
|
|
"frmP2PChat.ProccessRecvMessage -> UC_FileReceive",
|
|
receive_file["file_event"]["ui_hook"],
|
|
)
|
|
|
|
conversation = mcp_api.offline_lab_read_conversation(user_jid, workspace=workspace)
|
|
self.assertEqual(4, conversation["conversation"]["message_count"])
|
|
self.assertEqual(4, len(conversation["conversation"]["messages"]))
|
|
|
|
status = mcp_api.offline_lab_status(workspace=workspace)
|
|
self.assertTrue(status["started"])
|
|
self.assertEqual(4, status["message_count"])
|
|
|
|
def test_offline_lab_status_before_start_is_actionable(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
status = mcp_api.offline_lab_status(workspace=str(Path(tmp) / "missing"))
|
|
|
|
self.assertFalse(status["started"])
|
|
self.assertEqual("call offline_lab_start", status["next_step"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|