"""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, batch, change): window = ui.window ui.settle() submitted = [] monkeypatch.setattr(window, '_run_async', lambda *args, **kwargs: submitted.append(args)) 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'} def confirm(*_): 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)() 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, batch): window = ui.window ui.settle() submitted = [] monkeypatch.setattr(window, '_run_async', lambda *args, **kwargs: submitted.append(args)) 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)() 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