Core regression / Python 3.12 core, intervention UI and release configuration (push) Failing after 21s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python 3.12 core, intervention UI and release configuration (pull_request) Failing after 21s
Core regression / JavaScript syntax (pull_request) Successful in 3s
149 lines
7.7 KiB
Python
149 lines
7.7 KiB
Python
"""Click a real unconfigured desktop through a BOM failure and capture lamp states."""
|
|
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
import time
|
|
from types import SimpleNamespace
|
|
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(REPO / 'src'))
|
|
|
|
|
|
def main():
|
|
for key in ('QT_QPA_PLATFORM', 'DSH_API_BASE', 'DSH_MODEL', 'DSH_API_KEY', 'DEEPSEEK_API_KEY'):
|
|
os.environ.pop(key, None)
|
|
output = REPO / 'build' / 'dsh-status-desktop' / time.strftime('%Y%m%d-%H%M%S')
|
|
output.mkdir(parents=True)
|
|
project = output / 'fixtures/Board-A/board.prj'
|
|
project.parent.mkdir(parents=True)
|
|
project.write_text('KEY FrontEndSnapshot "DxD"\nKEY iCDBDir "database"\n', encoding='utf8')
|
|
workbook_path = output / 'fixtures/invalid-bom.xlsx'
|
|
from openpyxl import Workbook
|
|
workbook = Workbook()
|
|
workbook.active.append(['invalid_required_headers'])
|
|
workbook.active.append(['controlled invalid BOM row'])
|
|
workbook.save(workbook_path)
|
|
workbook.close()
|
|
|
|
from PySide6.QtCore import QEvent, QPoint, QThreadPool, QTimer, Qt
|
|
from PySide6.QtGui import QHelpEvent
|
|
from PySide6.QtTest import QTest
|
|
from PySide6.QtWidgets import QApplication, QDialogButtonBox, QFileDialog, QLineEdit, QMessageBox, QToolTip
|
|
from dx_productivity.trial_task_center.bom_import_state import BomImportPhase
|
|
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
|
from dx_productivity.trial_task_center.service import TaskCenterService
|
|
from dx_productivity.trial_task_center.store import TaskStore
|
|
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow
|
|
|
|
QApplication.setAttribute(Qt.ApplicationAttribute.AA_DontUseNativeDialogs)
|
|
app = QApplication([])
|
|
popups = []
|
|
QMessageBox.warning = lambda *args, **kwargs: popups.append('warning') or QMessageBox.StandardButton.Ok
|
|
QMessageBox.critical = lambda *args, **kwargs: popups.append('critical') or QMessageBox.StandardButton.Ok
|
|
data = output / 'data'
|
|
store = TaskStore(data / 'tasks.db')
|
|
service = TaskCenterService(store, configure_logging(data))
|
|
service._supervised = True
|
|
tasks = service.create_project_tasks(project.parent.parent)
|
|
window = TrialTaskCenterWindow(service, close_plan_confirmer=lambda: 'discard')
|
|
window.resize(1380, 880)
|
|
window.setAttribute(Qt.WidgetAttribute.WA_AlwaysShowToolTips, True)
|
|
window.show()
|
|
window.open_task(tasks[0].task_id)
|
|
report = {'status': 'running', 'driver': 'real Qt/QTest; no API keys', 'output': str(output), 'checks': []}
|
|
state = {'phase': 'ready', 'deadline': time.monotonic() + 60}
|
|
|
|
def capture(name):
|
|
window.menuWidget().grab().save(str(output / (name + '-navigation.png')))
|
|
lamp = window.ai_status_indicator
|
|
point = lamp.rect().center()
|
|
QTest.mouseMove(lamp, point)
|
|
QApplication.sendEvent(lamp, QHelpEvent(QEvent.Type.ToolTip, point, lamp.mapToGlobal(point)))
|
|
QToolTip.showText(lamp.mapToGlobal(point), lamp.toolTip(), lamp)
|
|
app.processEvents()
|
|
tips = [widget for widget in app.topLevelWidgets() if widget.windowType() == Qt.WindowType.ToolTip and widget.isVisible()]
|
|
assert tips, 'Actual Qt hover tooltip was not shown: ' + str([(w.metaObject().className(), str(w.windowType()), w.isVisible()) for w in app.topLevelWidgets()])
|
|
tips[0].grab().save(str(output / (name + '-tooltip.png')))
|
|
QToolTip.hideText()
|
|
|
|
def finish(error=None):
|
|
state['phase'] = 'closing'
|
|
report.update(status='failed' if error else 'passed', popups=popups,
|
|
automaticRuntimeStarted=window._dsh_view is not None,
|
|
incidentCount=len(list(data.glob('dsh/incidents/*'))))
|
|
if error:
|
|
report['error'] = type(error).__name__ + ': ' + str(error)
|
|
(output / 'report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf8')
|
|
window._dsh_automation = None
|
|
window.close()
|
|
QTimer.singleShot(100, app.quit)
|
|
|
|
def pick_file():
|
|
try:
|
|
picker = app.activeModalWidget()
|
|
assert isinstance(picker, QFileDialog)
|
|
edit = picker.findChild(QLineEdit, 'fileNameEdit')
|
|
QTest.keyClicks(edit, str(workbook_path))
|
|
buttons = picker.findChild(QDialogButtonBox)
|
|
QTest.mouseClick(buttons.button(QDialogButtonBox.StandardButton.Open), Qt.MouseButton.LeftButton)
|
|
state['phase'] = 'failed-bom'
|
|
except Exception as error:
|
|
finish(error)
|
|
|
|
def tick():
|
|
try:
|
|
if state['phase'] == 'closing':
|
|
return
|
|
if time.monotonic() > state['deadline']:
|
|
raise TimeoutError('status acceptance deadline')
|
|
if state['phase'] == 'ready' and window._context and not window._loading and not window._resource_status.blocked and window._dsh_status.availability['code'] != 'checking':
|
|
assert window.ai_status_indicator.property('state') == 'unavailable'
|
|
assert 'API Key' in window.ai_status_indicator.toolTip()
|
|
capture('red-unconfigured')
|
|
tabs = window.mapping_tabs.tabBar()
|
|
QTest.mouseClick(tabs, Qt.MouseButton.LeftButton, pos=tabs.tabRect(1).center())
|
|
state['phase'] = 'picker'
|
|
QTimer.singleShot(200, pick_file)
|
|
QTest.mouseClick(window.plan_panel.import_bom_button, Qt.MouseButton.LeftButton)
|
|
elif state['phase'] == 'failed-bom' and not window._workers and window.plan_panel.bom_import_state.phase is BomImportPhase.FAILED:
|
|
assert not popups and window._dsh_view is None and window._dsh_automation is None
|
|
assert not list(data.glob('dsh/incidents/*'))
|
|
assert window.task_list.list.isEnabled() and window.task_list.new_button.isEnabled()
|
|
report['checks'].append('Unconfigured model + real BOM parser failure: red lamp, no dialog/runtime/incident, task controls usable')
|
|
QTest.mouseClick(window.auto_intervention_check, Qt.MouseButton.LeftButton)
|
|
assert window.ai_status_indicator.property('state') == 'silent'
|
|
capture('grey-silent')
|
|
report['checks'].append('Clicked automatic-intervention switch off: grey silent state and hover explanation')
|
|
# The remaining captures exercise visual states only, with no model calls.
|
|
window._dsh_status.timer.stop()
|
|
window._dsh_status.query.close()
|
|
window._dsh_blockers.pending.clear()
|
|
window._dsh_status._received({'available': True, 'code': 'available', 'message': 'Controlled visual fixture'})
|
|
QTest.mouseClick(window.auto_intervention_check, Qt.MouseButton.LeftButton)
|
|
capture('green-idle')
|
|
window._dsh_automation = SimpleNamespace(worker=object(), pending=[], can_cancel=True,
|
|
latest={'status': 'reflecting', 'message': 'BOM 表头缺少旧料号、新料号和位号', 'task_name': 'Board-A'},
|
|
current_request=None, cancel=lambda: None)
|
|
window._update_gates()
|
|
assert window.ai_status_indicator.property('state') == 'working'
|
|
capture('yellow-intervening')
|
|
report['checks'].append('Controlled visual-only ready/working states: hover shows task, BOM reason and reflection stage')
|
|
finish()
|
|
except Exception as error:
|
|
finish(error)
|
|
|
|
timer = QTimer(window)
|
|
timer.setInterval(100)
|
|
timer.timeout.connect(tick)
|
|
timer.start()
|
|
app.exec()
|
|
QThreadPool.globalInstance().waitForDone()
|
|
store.close()
|
|
print(json.dumps(report, ensure_ascii=True))
|
|
return 0 if report['status'] == 'passed' else 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|