43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""验证人肉 debug 埋点链路:
|
|
Python [正文]/[思考] 打印 + JS console 桥 → [JS] 打印 全部出现在控制台
|
|
"""
|
|
import os, sys
|
|
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--disable-gpu"
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from PyQt6.QtWidgets import QApplication
|
|
import PyQt6.QtWebEngineWidgets # noqa
|
|
from PyQt6.QtCore import QTimer
|
|
from ui.views.main_window import MainWindow
|
|
|
|
app = QApplication(sys.argv)
|
|
window = MainWindow()
|
|
window.resize(1280, 800)
|
|
window.show()
|
|
|
|
MID = "manual-debug-test"
|
|
|
|
def step1():
|
|
# 模拟一次真实的 send→token→finish 生命周期
|
|
window.chat_bridge.create_message(MID, "assistant", "", "Test")
|
|
window.chat_bridge.append_reasoning(MID, "这是思考内容A")
|
|
window.chat_bridge.append_reasoning(MID, "思考B")
|
|
window.chat_bridge.append_token(MID, "这是正文第一段。")
|
|
window.chat_bridge.append_token(MID, "正文第二段来了。")
|
|
window.chat_bridge.tool_execution_started(MID, "call-xyz", "bash", "echo hi")
|
|
window.chat_bridge.tool_execution_finished(MID, "call-xyz", "bash", True, "hi\n[exit 0] (0.1s)")
|
|
QTimer.singleShot(800, step2)
|
|
|
|
def step2():
|
|
window.chat_bridge.finish_message(MID)
|
|
QTimer.singleShot(1200, done)
|
|
|
|
def done():
|
|
app.quit()
|
|
|
|
QTimer.singleShot(2000, step1)
|
|
app.exec()
|
|
print("===== 测试结束(上方应看到 [生命周期]/[JS] 打印)=====")
|