Files
dxdesigner-part-replacement/tests/ui/test_pr27_confirmation_admission.py
T
阿白叔 392ae365da
Core regression / Python core, intervention UI and release configuration (push) Failing after 9m5s
Core regression / JavaScript syntax (push) Successful in 7s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 8m0s
Core regression / JavaScript syntax (pull_request) Successful in 7s
fix: reconcile batch scope, resource safety and durable receipts (#44)
2026-11-27 12:26:19 +08:00

96 lines
3.9 KiB
Python

"""A modal confirmation must not reserve a lane that another operation owns."""
from types import SimpleNamespace
import pytest
from dx_productivity.trial_task_center.stop_control import StopControl
@pytest.mark.parametrize('batch', [False, True])
@pytest.mark.parametrize('change', ['worker', 'stop', 'closing', 'task', 'dirty', 'dialog'])
def test_confirmation_rechecks_admission_before_authorizing_or_replacing_controls(ui, monkeypatch, qtbot, batch, change):
window = ui.window
ui.settle()
submitted = []
original_run_async = window._run_async
def dispatch(*args, **kwargs):
if kwargs.get('operation_area') == 'batch_preflight':
return original_run_async(*args, **kwargs)
submitted.append(args)
monkeypatch.setattr(window, '_run_async', dispatch)
original_task = window._task_id
original_authorization = set(window._dsh_authorized_tasks)
original_dialog = window._dsh_operations.dialog
original_dirty = window.plan_panel.table.dirty
live_stop = StopControl()
live_worker = object()
live_run = {'active': True, 'run_id': 'already-running', 'task_id': 'other-owner'}
confirmation_seen = []
def confirm(*_):
confirmation_seen.append(True)
if change in {'worker', 'stop'}:
window._batch_stop = live_stop
window._dsh_run_stop = live_stop
window._dsh_live_run = live_run
if change == 'worker':
window._workers.add(live_worker)
elif change == 'closing':
window._close_pending = True
elif change == 'task':
window._task_id = ui.tasks[1].task_id
elif change == 'dirty':
window.plan_panel.table.dirty = True
else:
window._dsh_operations.dialog = SimpleNamespace()
return True
window._quick_run_confirmer = confirm
try:
(window._execute_project_tasks if batch else window._prepare_quick_run)()
if batch:
qtbot.waitUntil(lambda: bool(confirmation_seen), timeout=5000)
assert not submitted, 'stale confirmation must not submit another execution'
assert window._dsh_authorized_tasks == original_authorization
assert '未启动' in window.run_panel.operator_band.text()
if change in {'worker', 'stop'}:
assert window._batch_stop is live_stop
assert window._dsh_run_stop is live_stop
assert window._dsh_live_run is live_run
finally:
window._workers.discard(live_worker)
window._close_pending = False
window._task_id = original_task
window._dsh_operations.dialog = original_dialog
window.plan_panel.table.dirty = original_dirty
window._finish_run()
@pytest.mark.parametrize('batch', [False, True])
def test_idle_confirmation_still_starts_execution_while_read_query_is_busy(ui, monkeypatch, qtbot, batch):
window = ui.window
ui.settle()
submitted = []
original_run_async = window._run_async
def dispatch(*args, **kwargs):
if kwargs.get('operation_area') == 'batch_preflight':
return original_run_async(*args, **kwargs)
submitted.append(args)
monkeypatch.setattr(window, '_run_async', dispatch)
original_query = window._feedback_query
window._quick_run_confirmer = lambda *_: True
# A background read is not the mutation/execution lane.
window._feedback_query = SimpleNamespace(busy=True, invalidate=lambda: None)
try:
(window._execute_project_tasks if batch else window._prepare_quick_run)()
if batch:
qtbot.waitUntil(lambda: window._batch_stop is not None, timeout=5000)
assert len(submitted) == 1
assert isinstance(window._batch_stop, StopControl)
assert ui.tasks[0].task_id in window._dsh_authorized_tasks
assert not ui.calls # The submitted executor is controlled, with no CAD.
finally:
window._finish_run()
window._feedback_query = original_query