fix: address PR 48 audit 667 lifecycle and legacy rule gaps
Core regression / Python core, intervention UI and release configuration (push) Successful in 6m54s
Core regression / JavaScript syntax (push) Successful in 8s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m22s
Core regression / JavaScript syntax (pull_request) Successful in 7s
Core regression / Python core, intervention UI and release configuration (push) Successful in 6m54s
Core regression / JavaScript syntax (push) Successful in 8s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m22s
Core regression / JavaScript syntax (pull_request) Successful in 7s
This commit is contained in:
1 parent
65f3a9c728
commit
e772723b4e
11 files changed
+386
-45
No files matched your search
@@ -0,0 +1,240 @@
|
||||
"""Incremental regression cases for PR 48 review comment 667."""
|
||||
from dataclasses import replace
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QPersistentModelIndex, QRect, Qt
|
||||
from PySide6.QtGui import QAccessible
|
||||
from PySide6.QtWidgets import QApplication, QMessageBox
|
||||
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
from dx_productivity.trial_task_center.models import TaskStatus
|
||||
from tests.ui.test_issue45_unsaved import seed, edit_cell
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def keep_pending_plans_open(ui):
|
||||
ui.window._close_plan_confirmer = lambda: 'cancel'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('choice', ['cancel', 'discard', 'save'])
|
||||
def test_soft_delete_resolves_active_editor_before_removal(ui, monkeypatch, choice):
|
||||
panel, original = seed(ui)
|
||||
task = ui.tasks[0]
|
||||
edit_cell(panel, 'DELETE_TYPED')
|
||||
asked = []
|
||||
ui.window._close_plan_confirmer = lambda: asked.append(True) or choice
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.StandardButton.Yes)
|
||||
ui.window._delete_task()
|
||||
ui.settle()
|
||||
assert asked == [True]
|
||||
if choice == 'cancel':
|
||||
assert ui.service.get_task(task.task_id).status is not TaskStatus.DELETED
|
||||
assert panel.has_unsaved_plans()
|
||||
assert panel.table.has_pending_editor() or panel.table.rows()[0].new_part_number == 'DELETE_TYPED'
|
||||
assert ui.service.target_plan(task.task_id) == original
|
||||
else:
|
||||
assert ui.service.get_task(task.task_id).status is TaskStatus.DELETED
|
||||
assert not panel.has_unsaved_plans() and not panel.table._active_editor
|
||||
saved = ui.service.target_plan(task.task_id)
|
||||
assert saved[0].new_part_number == ('DELETE_TYPED' if choice == 'save' else 'NEW')
|
||||
|
||||
|
||||
def test_delete_save_failure_keeps_input_and_task(ui, monkeypatch):
|
||||
panel, _ = seed(ui)
|
||||
edit_cell(panel, 'KEEP_TYPED')
|
||||
ui.window._close_plan_confirmer = lambda: 'save'
|
||||
errors = []
|
||||
monkeypatch.setattr(ui.window, '_show_error', lambda error, **kwargs: errors.append(error))
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.StandardButton.Yes)
|
||||
def fail(*args):
|
||||
raise TaskCenterError('controlled_save', 'controlled save failure')
|
||||
monkeypatch.setattr(ui.service, 'save_plan_drafts', fail)
|
||||
ui.window._delete_task()
|
||||
ui.settle()
|
||||
assert ui.service.get_task(ui.tasks[0].task_id).status is not TaskStatus.DELETED
|
||||
assert panel.has_unsaved_plans()
|
||||
assert panel.table.rows()[0].new_part_number == 'KEEP_TYPED'
|
||||
assert errors
|
||||
ui.window._close_plan_confirmer = lambda: 'cancel'
|
||||
|
||||
|
||||
def test_archive_cancel_keeps_active_editor(ui, monkeypatch):
|
||||
panel, _ = seed(ui)
|
||||
edit_cell(panel, 'ARCHIVE_TYPED')
|
||||
ui.window._context = replace(ui.window._context,
|
||||
task=replace(ui.window._context.task, status=TaskStatus.COMPLETED))
|
||||
ui.window._close_plan_confirmer = lambda: 'cancel'
|
||||
calls = []
|
||||
import dx_productivity.trial_task_center.task_archive as archive
|
||||
monkeypatch.setattr(archive, 'archive_completed_session', lambda *a, **k: calls.append(True))
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.StandardButton.Yes)
|
||||
ui.window._archive_completed_task()
|
||||
ui.settle()
|
||||
assert not calls
|
||||
assert panel.has_unsaved_plans()
|
||||
assert panel.table.has_pending_editor() or panel.table.rows()[0].new_part_number == 'ARCHIVE_TYPED'
|
||||
|
||||
|
||||
def test_archive_discard_cleans_the_removed_editor(ui, monkeypatch):
|
||||
from dx_productivity.trial_task_center.task_archive import ArchiveReport
|
||||
import dx_productivity.trial_task_center.task_archive as archive
|
||||
panel, _ = seed(ui)
|
||||
task = ui.tasks[0].task_id
|
||||
edit_cell(panel, 'ARCHIVE_TYPED')
|
||||
ui.window._context = replace(ui.window._context,
|
||||
task=replace(ui.window._context.task, status=TaskStatus.COMPLETED))
|
||||
ui.window._close_plan_confirmer = lambda: 'discard'
|
||||
def removed(*args, **kwargs):
|
||||
assert not panel.has_unsaved_plans()
|
||||
ui.service.delete_task(task)
|
||||
return ArchiveReport((task,))
|
||||
monkeypatch.setattr(archive, 'archive_completed_session', removed)
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.StandardButton.Yes)
|
||||
ui.window._archive_completed_task()
|
||||
ui.settle()
|
||||
assert ui.service.get_task(task).status is TaskStatus.DELETED
|
||||
assert panel.task_id is None and not panel.has_unsaved_plans()
|
||||
assert panel.table._active_editor is None
|
||||
|
||||
|
||||
def test_failed_refresh_commit_invalidates_context_and_blocks_execution(ui, monkeypatch):
|
||||
from dx_productivity.trial_task_center.ui.operation_state import ContextReadPhase
|
||||
panel, _ = seed(ui)
|
||||
edit_cell(panel, 'KEEP_TYPED')
|
||||
commit = panel.table.commit_editor
|
||||
def fail():
|
||||
raise TaskCenterError('editor_commit', 'controlled commit failure')
|
||||
monkeypatch.setattr(panel.table, 'commit_editor', fail)
|
||||
assert ui.window._load_task_data() is False
|
||||
assert ui.window._context is None
|
||||
assert ui.window._context_phase is ContextReadPhase.FAILED
|
||||
assert not ui.window.run_panel.quick_run_button.isEnabled()
|
||||
assert panel.table.has_pending_editor()
|
||||
monkeypatch.setattr(panel.table, 'commit_editor', commit)
|
||||
ui.window._refresh_bound_project()
|
||||
ui.settle()
|
||||
assert ui.window._context_phase is ContextReadPhase.READY
|
||||
assert panel.table.has_pending_editor()
|
||||
panel.save()
|
||||
ui.settle()
|
||||
assert ui.service.target_plan(ui.tasks[0].task_id)[0].new_part_number == 'KEEP_TYPED'
|
||||
|
||||
|
||||
def test_bom_preview_commit_failure_keeps_editor_and_existing_preview(ui):
|
||||
from dx_productivity.trial_task_center.bom_batch import BomBatchPreview, BomProjectPreview
|
||||
panel, rows = seed(ui)
|
||||
task = ui.tasks[0].task_id
|
||||
project = ui.store.list_projects(task)[0].path
|
||||
preview = BomBatchPreview(task, ((task, str(project)),),
|
||||
(BomProjectPreview(task, project, rows, (), ()),))
|
||||
edit_cell(panel, 'KEEP_TYPED')
|
||||
panel.table.set_plan_editable(False)
|
||||
assert panel._preview_bom(preview) is False
|
||||
assert not panel._bom_batches and not panel._drafts
|
||||
assert panel.table.has_pending_editor()
|
||||
assert '当前编辑内容' in ui.window.run_panel.operator_band.text()
|
||||
|
||||
|
||||
def test_invalid_editor_index_is_cancelled_and_tracking_cleared(ui):
|
||||
panel, _ = seed(ui)
|
||||
editor = edit_cell(panel)
|
||||
panel.table._active_editor = (editor, QPersistentModelIndex())
|
||||
closed = []
|
||||
panel.table.itemDelegate().closeEditor.connect(lambda *args: closed.append(args))
|
||||
panel.table.commit_editor()
|
||||
assert panel.table._active_editor is None
|
||||
assert len(closed) == 1
|
||||
|
||||
|
||||
def test_task_navigation_and_actual_list_have_accessible_names(ui):
|
||||
for widget in (ui.window.task_list, ui.window.task_list.list):
|
||||
interface = QAccessible.queryAccessibleInterface(widget)
|
||||
assert interface.text(QAccessible.Text.Name)
|
||||
|
||||
|
||||
def test_disabled_blank_mapping_has_no_pn_error(ui):
|
||||
rule = ui.store.list_rules(ui.tasks[0].task_id)[0]
|
||||
ui.window.mapping_table.populate((replace(rule, enabled=False, new_part_number=''),))
|
||||
index = ui.window.mapping_table.model().index(0, 1)
|
||||
assert index.data(Qt.ItemDataRole.BackgroundRole) is None
|
||||
|
||||
|
||||
def test_legacy_invalid_rules_can_be_quarantined_but_not_reenabled(ui):
|
||||
task = ui.tasks[0].task_id
|
||||
rules = [ui.store.list_rules(task)[0], ui.store.add_rule(task, 'OTHER', 'NEW-2')]
|
||||
with ui.store.transaction():
|
||||
for rule in rules:
|
||||
ui.store._connection.execute('UPDATE rules SET new_part_number=? WHERE rule_id=?',
|
||||
('LEGACY BAD!', rule.rule_id))
|
||||
for rule in rules:
|
||||
disabled = ui.service.update_rule(rule.rule_id, old_part_number=rule.old_part_number,
|
||||
new_part_number='LEGACY BAD!', enabled=False)
|
||||
assert not disabled.enabled
|
||||
for rule in rules:
|
||||
with pytest.raises(TaskCenterError):
|
||||
ui.store.update_rule(rule.rule_id, old_part_number=rule.old_part_number,
|
||||
new_part_number='LEGACY BAD!', enabled=True)
|
||||
with pytest.raises(TaskCenterError):
|
||||
ui.store.update_rule(rule.rule_id, old_part_number=rule.old_part_number,
|
||||
new_part_number='OTHER BAD!', enabled=False)
|
||||
repaired = ui.service.update_rule(rule.rule_id, old_part_number=rule.old_part_number,
|
||||
new_part_number='REPAIRED', enabled=False)
|
||||
assert repaired.new_part_number == 'REPAIRED'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value', [123, None])
|
||||
def test_nontext_pn_is_rejected_without_mutating_rules(ui, value):
|
||||
task = ui.tasks[0].task_id
|
||||
original = ui.store.list_rules(task)
|
||||
with pytest.raises(TaskCenterError, match='part_number'):
|
||||
ui.store.add_rule(task, 'OTHER', value)
|
||||
with pytest.raises(TaskCenterError, match='part_number'):
|
||||
ui.service.update_rule(original[0].rule_id, old_part_number='OLD',
|
||||
new_part_number=value, enabled=True)
|
||||
assert ui.store.list_rules(task) == original
|
||||
|
||||
|
||||
def test_filtering_cancels_hidden_selection_with_an_explicit_hint(ui):
|
||||
panel = ui.window.task_list
|
||||
panel.select_all_tasks()
|
||||
panel.search.setText('Board-A')
|
||||
assert len(panel.selected_task_ids()) == 1
|
||||
panel.search.clear()
|
||||
assert len(panel.selected_task_ids()) == 1
|
||||
assert '不恢复' in panel.search.toolTip()
|
||||
assert '可见' in panel.selected_queue_button.toolTip()
|
||||
|
||||
|
||||
def test_legacy_quarantine_still_respects_frozen_batch_members(ui):
|
||||
rule = ui.store.list_rules(ui.tasks[0].task_id)[0]
|
||||
with ui.store.transaction():
|
||||
ui.store._connection.execute('UPDATE rules SET new_part_number=? WHERE rule_id=?',
|
||||
('LEGACY BAD!', rule.rule_id))
|
||||
ui.store.set_task_status(ui.tasks[1].task_id, TaskStatus.READY)
|
||||
ui.store.set_task_status(ui.tasks[1].task_id, TaskStatus.RUNNING)
|
||||
before = tuple(ui.store.list_rules(task.task_id) for task in ui.tasks)
|
||||
with pytest.raises(TaskCenterError):
|
||||
ui.service.update_rule(rule.rule_id, old_part_number='OLD',
|
||||
new_part_number='LEGACY BAD!', enabled=False)
|
||||
assert tuple(ui.store.list_rules(task.task_id) for task in ui.tasks) == before
|
||||
|
||||
|
||||
def test_tiny_workarea_keeps_force_stop_reachable(ui, monkeypatch):
|
||||
window = ui.window
|
||||
screen = SimpleNamespace(availableGeometry=lambda: QRect(0, 0, 640, 344),
|
||||
logicalDotsPerInch=lambda: 288, devicePixelRatio=lambda: 3, name=lambda: 'tiny-workarea')
|
||||
monkeypatch.setattr(QApplication, 'screenAt', lambda _: screen)
|
||||
window._begin_run(ui.tasks[0].task_id)
|
||||
window._update_gates()
|
||||
try:
|
||||
window._restore_window_geometry(restore_saved=False)
|
||||
for button in (window.run_panel.force_stop_button, window.run_panel.stop_queue_button):
|
||||
assert button.isVisible() and button.isEnabled()
|
||||
window.workspace_scroll.ensureWidgetVisible(button, 0, 0)
|
||||
QApplication.processEvents()
|
||||
rect = window.workspace_scroll.viewport().rect()
|
||||
assert rect.contains(button.mapTo(window.workspace_scroll.viewport(), button.rect().bottomRight()))
|
||||
assert screen.availableGeometry().contains(window.frameGeometry())
|
||||
finally:
|
||||
window._finish_run()
|
||||
@@ -9,7 +9,7 @@ from test_ui_remediation import window
|
||||
|
||||
|
||||
@pytest.mark.parametrize('scale,saved,decorated', [(1.25, False, False), (1.5, False, False),
|
||||
(1.5, True, False), (1.5, False, True)])
|
||||
(1.5, True, False), (1.5, False, True), (3.0, False, True)])
|
||||
def test_first_and_restored_windows_fit_scaled_workarea(window, qtbot, monkeypatch, scale, saved, decorated):
|
||||
area = QRect(0, 0, int(1920 / scale), int(1032 / scale))
|
||||
screen = SimpleNamespace(availableGeometry=lambda: area, logicalDotsPerInch=lambda: 96 * scale,
|
||||
@@ -30,6 +30,11 @@ def test_first_and_restored_windows_fit_scaled_workarea(window, qtbot, monkeypat
|
||||
QApplication.processEvents()
|
||||
assert area.contains(window.frameGeometry()), (area, window.frameGeometry(), window.minimumSize())
|
||||
for button in (window.plan_panel.save_button, window.run_panel.quick_run_button, window.task_list.new_button):
|
||||
if scale == 3.0:
|
||||
window.workspace_scroll.ensureWidgetVisible(button, 0, 0)
|
||||
QApplication.processEvents()
|
||||
point = button.mapTo(window.workspace_scroll.viewport(), button.rect().bottomRight())
|
||||
assert window.workspace_scroll.viewport().rect().contains(point)
|
||||
point = button.mapTo(window, button.rect().bottomRight())
|
||||
assert window.rect().contains(point), (button.objectName(), point, window.size())
|
||||
|
||||
|
||||
Reference in new issue
Block a user