105 lines
3.7 KiB
Python
105 lines
3.7 KiB
Python
"""DSH desktop layout and usable conversation lifecycle without model/CAD access."""
|
|
from threading import Event
|
|
|
|
from PySide6.QtCore import Qt
|
|
from dx_productivity.dsh.snapshot import TaskSnapshot
|
|
from dx_productivity.trial_task_center.ui.dsh_panel import DshPanel
|
|
|
|
|
|
def make_panel(qtbot, **kwargs):
|
|
panel = DshPanel(None, snapshot=TaskSnapshot('board-a', 'paused'), **kwargs)
|
|
qtbot.addWidget(panel)
|
|
panel.show()
|
|
return panel
|
|
|
|
|
|
def test_desktop_has_three_resizable_columns_and_initial_context(qtbot):
|
|
panel = make_panel(qtbot)
|
|
assert panel.workspace.orientation() == Qt.Orientation.Horizontal
|
|
assert panel.workspace.count() == 3
|
|
assert all(size > 0 for size in panel.workspace.sizes())
|
|
assert panel.windowTitle() == 'DSH助手'
|
|
assert 'board-a' in panel.context_text.toPlainText()
|
|
assert '暂停' in panel.issue.text()
|
|
|
|
|
|
def test_new_conversation_preserves_previous_local_history(qtbot):
|
|
panel = make_panel(qtbot)
|
|
panel.input.setPlainText('分析当前异常')
|
|
qtbot.mouseClick(panel.send, Qt.MouseButton.LeftButton)
|
|
qtbot.waitUntil(lambda: panel.send.isEnabled())
|
|
assert '未配置' in panel.chat.toPlainText()
|
|
qtbot.mouseClick(panel.new_chat_button, Qt.MouseButton.LeftButton)
|
|
assert panel.conversations.count() == 2
|
|
assert '分析当前异常' not in panel.chat.toPlainText()
|
|
panel.conversations.setCurrentRow(1)
|
|
assert '分析当前异常' in panel.chat.toPlainText()
|
|
|
|
|
|
def test_model_call_does_not_block_ui_or_mix_conversations(qtbot):
|
|
entered, release = Event(), Event()
|
|
|
|
class Client:
|
|
def chat(self, message, snapshot):
|
|
entered.set()
|
|
assert release.wait(5)
|
|
return {'reply': '<b>模型原文</b>', 'actions': []}
|
|
|
|
panel = make_panel(qtbot, client=Client())
|
|
panel.input.setPlainText('检查失败原因')
|
|
try:
|
|
qtbot.mouseClick(panel.send, Qt.MouseButton.LeftButton)
|
|
qtbot.waitUntil(entered.is_set)
|
|
assert not panel.send.isEnabled()
|
|
assert panel.stop_button.isEnabled()
|
|
qtbot.mouseClick(panel.new_chat_button, Qt.MouseButton.LeftButton)
|
|
release.set()
|
|
qtbot.waitUntil(lambda: not panel._workers)
|
|
assert '模型原文' not in panel.chat.toPlainText()
|
|
panel.conversations.setCurrentRow(1)
|
|
assert '<b>模型原文</b>' in panel.chat.toPlainText()
|
|
finally:
|
|
release.set()
|
|
|
|
|
|
def test_stopped_reply_is_not_displayed(qtbot):
|
|
release = Event()
|
|
|
|
class Client:
|
|
def chat(self, *_):
|
|
release.wait(5)
|
|
return {'reply': '迟到的回复', 'actions': []}
|
|
|
|
panel = make_panel(qtbot, client=Client())
|
|
panel.input.setPlainText('提问')
|
|
try:
|
|
qtbot.mouseClick(panel.send, Qt.MouseButton.LeftButton)
|
|
qtbot.mouseClick(panel.stop_button, Qt.MouseButton.LeftButton)
|
|
release.set()
|
|
qtbot.waitUntil(lambda: not panel._workers)
|
|
assert '迟到的回复' not in panel.chat.toPlainText()
|
|
assert '停止' in panel.chat.toPlainText()
|
|
finally:
|
|
release.set()
|
|
|
|
|
|
def test_escape_closes_panel_and_discards_late_reply(qtbot):
|
|
release = Event()
|
|
|
|
class Client:
|
|
def chat(self, *_):
|
|
release.wait(5)
|
|
return {'reply': '窗口关闭后的回复', 'actions': []}
|
|
|
|
panel = make_panel(qtbot, client=Client())
|
|
panel.input.setPlainText('分析')
|
|
try:
|
|
qtbot.mouseClick(panel.send, Qt.MouseButton.LeftButton)
|
|
qtbot.keyClick(panel, Qt.Key.Key_Escape)
|
|
release.set()
|
|
qtbot.waitUntil(lambda: not panel._workers)
|
|
assert not panel.isVisible()
|
|
assert '窗口关闭后的回复' not in panel.chat.toPlainText()
|
|
finally:
|
|
release.set()
|