fix: unify async operation feedback and recover failed task reads

This commit is contained in:
阿白叔 committed 2026-10-16 10:19:31 +08:00
1 parent 032a80ac27
commit d9f65a0ac7
5 files changed
+245 -20

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
"""Regressions for retries, cancellation and task-read recovery outside BOM."""
from threading import Event
import pytest
from PySide6.QtWidgets import QFileDialog
from dx_productivity.trial_task_center.errors import TaskCenterError
from dx_productivity.trial_task_center.target_plan import ComponentTarget, TargetPlanRow
from test_ui_batch_retry import open_project
from test_ui_remediation import window
@pytest.mark.parametrize('cleanup_failure', [False, True])
def test_collection_cancel_waits_for_cleanup_then_shows_terminal_state(window, qtbot, tmp_path, monkeypatch, cleanup_failure):
open_project(window, qtbot, tmp_path)
started, release = Event(), Event()
def collect(*args, **controls):
controls['on_progress']('正在采集测试工程')
started.set()
assert release.wait(5)
if cleanup_failure:
raise TaskCenterError('native_cleanup', '测试会话释放失败')
raise TaskCenterError('operation_cancelled', '采集已取消')
monkeypatch.setattr(window.service, 'collect_target_inventory', collect)
panel = window.plan_panel
panel.collect_button.click()
try:
qtbot.waitUntil(started.is_set)
panel.cancel_operation()
assert window._workers and '正在取消' in panel.summary.text()
finally:
release.set()
qtbot.waitUntil(lambda: not window._workers and not window._loading and not window._context_query.busy)
panel._summary()
assert ('释放失败' if cleanup_failure else '已取消') in panel.summary.text()
assert '正在取消' not in panel.summary.text() and panel.stop_button.isHidden()
def test_collection_retry_clears_previous_failure_at_start_and_after_success(window, qtbot, tmp_path, monkeypatch):
open_project(window, qtbot, tmp_path)
def fail(*args, **kwargs):
raise TaskCenterError('target_inventory', 'previous collection failed')
monkeypatch.setattr(window.service, 'collect_target_inventory', fail)
panel = window.plan_panel
panel.collect_button.click()
qtbot.waitUntil(lambda: not window._workers and not window._loading and not window._context_query.busy)
assert 'previous collection failed' in window.run_panel.operator_band.text()
started, release = Event(), Event()
def collect(*args, **kwargs):
started.set()
assert release.wait(5)
return ()
monkeypatch.setattr(window.service, 'collect_target_inventory', collect)
panel.collect_button.click()
try:
qtbot.waitUntil(started.is_set)
assert 'previous collection failed' not in window.run_panel.operator_band.text()
assert '正在' in panel.summary.text()
finally:
release.set()
qtbot.waitUntil(lambda: not window._workers and not window._loading and not window._context_query.busy)
assert 'previous collection failed' not in window.run_panel.operator_band.text()
assert '完成' in window.run_panel.operator_band.text()
def test_task_read_failure_has_recovery_button_and_retries_without_restarting(window, qtbot, tmp_path, monkeypatch):
open_project(window, qtbot, tmp_path)
original = window.service.task_context
monkeypatch.setattr(window.service, 'task_context', lambda *args, **kwargs: (_ for _ in ()).throw(
TaskCenterError('task_read', 'temporary read failure')))
window._load_task_data()
qtbot.waitUntil(lambda: not window._loading and not window._context_query.busy)
assert '读取失败' in window.project_summary.state.text()
assert window.project_summary.refresh_button.isEnabled()
assert '重试' in window.project_summary.refresh_button.text()
monkeypatch.setattr(window.service, 'task_context', original)
window.project_summary.refresh_button.click()
qtbot.waitUntil(lambda: not window._loading and not window._context_query.busy)
assert window._context is not None
assert '正在读取' not in window.project_summary.state.text()
assert 'temporary read failure' not in window.run_panel.operator_band.text()
assert window.project_summary.refresh_button.text() == '重新读取工程'
def test_export_success_keeps_the_output_path_in_plan_feedback(window, qtbot, tmp_path, monkeypatch):
open_project(window, qtbot, tmp_path)
panel = window.plan_panel
target = ComponentTarget(window._context.project.path, 'MAIN', '1', 'u1', 'R1', 'OLD', '33R')
panel.table.populate((TargetPlanRow(target),))
window._update_gates()
output = tmp_path / 'export.xlsx'
monkeypatch.setattr(QFileDialog, 'getSaveFileName', lambda *args: (str(output), ''))
monkeypatch.setattr(window.service, 'export_target_plan', lambda *args: output)
panel.export_button.click()
qtbot.waitUntil(lambda: not window._workers)
assert str(output) in panel.summary.text()