feat: embed native Harness assistant and verify live task model

This commit is contained in:
阿白叔 committed 2026-10-30 11:32:16 +08:00
1 parent 9c508333bb
commit 96227eed2e
29 files changed
+11110 -582

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QWidget
class HarnessView(QWidget):
action_requested = Signal(object)
def __init__(self, parent):
super().__init__(parent)
self.starts = 0
self.binds = []
def start(self):
self.starts += 1
def bind(self, snapshot, **kwargs):
self.binds.append(snapshot)
self.context = {'task_id': snapshot.task_id, 'revision': 'rev'}
def shutdown(self):
pass
def test_menu_opens_embedded_harness_and_returns_without_losing_task(ui, monkeypatch):
window = ui.window
monkeypatch.setattr(type(window), '_create_dsh_view', lambda self: HarnessView(self), raising=False)
task_id = window._task_id
window.dsh_action.trigger()
assert window.content_stack.currentWidget() is window._dsh_view
assert window._dsh_view.binds[-1].task_id == task_id
assert window._dsh_view.starts == 1
window.task_center_action.trigger()
assert window.content_stack.currentIndex() == 0
assert window._task_id == task_id
window.dsh_action.trigger()
assert window._dsh_view.starts == 1
def test_cross_task_harness_action_never_reaches_task_service(ui, monkeypatch):
window = ui.window
monkeypatch.setattr(type(window), '_create_dsh_view', lambda self: HarnessView(self), raising=False)
window.dsh_action.trigger()
called = []
monkeypatch.setattr(window, '_retry_failed', lambda: called.append('retry'))
window._handle_dsh_action({'action': 'retry_failed', 'task_id': 'another', 'revision': 'rev'})
assert not called
-104
View File
@@ -1,104 +0,0 @@
"""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()