merge(main): resolve PR19 review conflicts and run intervention regressions in CI
Core regression / Python core, intervention UI and release configuration (push) Failing after 2m42s
Core regression / JavaScript syntax (push) Successful in 6s
Core regression / Python core, intervention UI and release configuration (pull_request) Canceled after 1m17s
Core regression / JavaScript syntax (pull_request) Canceled after 0s
Core regression / Python core, intervention UI and release configuration (push) Failing after 2m42s
Core regression / JavaScript syntax (push) Successful in 6s
Core regression / Python core, intervention UI and release configuration (pull_request) Canceled after 1m17s
Core regression / JavaScript syntax (pull_request) Canceled after 0s
This commit is contained in:
commit
f8f07d30d2
127 files changed
+9390
-386
No files matched your search
@@ -13,6 +13,12 @@ from dx_productivity.trial_task_center.quick_run import QuickRunPreparer
|
||||
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def controlled_error_dialogs(monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
monkeypatch.setattr(QMessageBox, 'warning', lambda *args, **kwargs: QMessageBox.StandardButton.Ok)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ai_ready(monkeypatch):
|
||||
"""AI flow tests supply readiness explicitly; normal fixtures remain unconfigured."""
|
||||
@@ -43,6 +49,8 @@ def ui(qtbot, tmp_path):
|
||||
window=TrialTaskCenterWindow(service)
|
||||
qtbot.addWidget(window);window.show()
|
||||
def settle():
|
||||
if not isValid(window) or window._closed:
|
||||
return
|
||||
qtbot.waitUntil(lambda:not window._workers and not window._task_query.busy
|
||||
and not window._context_query.busy and not window._feedback_query.busy
|
||||
and not window._log_presenter.query.busy and not window._resource_status.busy
|
||||
@@ -59,4 +67,12 @@ def ui(qtbot, tmp_path):
|
||||
if isValid(window):
|
||||
window.plan_panel.discard_all()
|
||||
window.close()
|
||||
qtbot.waitUntil(lambda: not isValid(window) or window._closed, timeout=5000)
|
||||
from PySide6.QtCore import QThreadPool
|
||||
QThreadPool.globalInstance().waitForDone(5000)
|
||||
for name in ('_dsh_status', '_dsh_operations', '_dsh_lifecycle', '_dsh_automation'):
|
||||
controller = getattr(window, name, None)
|
||||
pool = getattr(controller, '_read_pool', None) or getattr(controller, '_pool', None)
|
||||
if pool is not None:
|
||||
assert pool.waitForDone(5000), 'Controlled AI reads must finish before closing the fixture store'
|
||||
store.close()
|
||||
@@ -84,7 +84,7 @@ def test_availability_check_cannot_starve_task_worker(
|
||||
|
||||
|
||||
@pytest.mark.parametrize('kind', ['authorized_retry', 'resource_cleanup'])
|
||||
def test_model_wait_never_owns_task_controls(slow_diagnosis, qtbot, kind):
|
||||
def test_model_wait_never_owns_task_controls(slow_diagnosis, ui, qtbot, kind):
|
||||
window, automation, _, start = slow_diagnosis
|
||||
if kind == 'resource_cleanup':
|
||||
start(read_only=False, cleanup=True)
|
||||
@@ -101,6 +101,7 @@ def test_model_wait_never_owns_task_controls(slow_diagnosis, qtbot, kind):
|
||||
finally:
|
||||
automation.cancel()
|
||||
qtbot.waitUntil(lambda: automation.worker is None, timeout=5000)
|
||||
ui.settle()
|
||||
|
||||
|
||||
def test_finishing_old_diagnosis_preserves_new_manual_run(slow_diagnosis, ui, qtbot):
|
||||
@@ -123,6 +124,7 @@ def test_finishing_old_diagnosis_preserves_new_manual_run(slow_diagnosis, ui, qt
|
||||
assert not manual_stop.is_set()
|
||||
finally:
|
||||
window._finish_run()
|
||||
ui.settle()
|
||||
|
||||
|
||||
def reply_to_model(view, action='none'):
|
||||
@@ -216,10 +218,11 @@ def test_new_manual_run_denies_old_ai_mutation_without_touching_controls(
|
||||
assert len(published) == 1
|
||||
finally:
|
||||
window._finish_run()
|
||||
ui.settle()
|
||||
|
||||
|
||||
def test_completed_taskless_observation_does_not_start_another_model_run(
|
||||
slow_diagnosis, qtbot):
|
||||
slow_diagnosis, ui, qtbot):
|
||||
window, automation, published, start = slow_diagnosis
|
||||
view = start()
|
||||
reply_to_model(view)
|
||||
@@ -241,6 +244,7 @@ def test_completed_taskless_observation_does_not_start_another_model_run(
|
||||
qtbot.waitUntil(lambda: len(view.requests) == 3, timeout=5000)
|
||||
automation.cancel()
|
||||
qtbot.waitUntil(lambda: automation.worker is None, timeout=5000)
|
||||
ui.settle()
|
||||
|
||||
|
||||
def test_admission_timeout_releases_even_if_gui_just_admitted(ui, monkeypatch):
|
||||
@@ -259,7 +263,7 @@ def test_admission_timeout_releases_even_if_gui_just_admitted(ui, monkeypatch):
|
||||
class ExpiringEvent:
|
||||
def set(self):
|
||||
pass
|
||||
def wait(self, _timeout):
|
||||
def wait(self, _timeout=None):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(module, 'Event', ExpiringEvent)
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
"""Model and supervision waits must not own execution admission or capacity."""
|
||||
from threading import Event
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QThreadPool, Signal
|
||||
|
||||
from dx_productivity.trial_task_center.ui.dsh_automation import DshAutomation, IncidentRequest
|
||||
from dx_productivity.trial_task_center.ui.workers import ServiceWorker
|
||||
from .test_dsh_native_menu import HarnessView
|
||||
from .test_dsh_operations import setup_view
|
||||
|
||||
|
||||
pytestmark = pytest.mark.usefixtures('ai_ready')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def single_execution_thread(ui, qtbot):
|
||||
ui.settle()
|
||||
pool = QThreadPool.globalInstance()
|
||||
previous = pool.maxThreadCount()
|
||||
pool.setMaxThreadCount(1)
|
||||
yield pool
|
||||
qtbot.waitUntil(lambda: pool.activeThreadCount() == 0, timeout=5000)
|
||||
pool.setMaxThreadCount(previous)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('source', ['timer', 'history', 'refresh_ticket'])
|
||||
def test_supervision_wait_leaves_execution_lane_and_thread_available(
|
||||
ui, monkeypatch, qtbot, single_execution_thread, source):
|
||||
setup_view(ui, monkeypatch)
|
||||
operations = ui.window._dsh_operations
|
||||
started, release, executed = Event(), Event(), Event()
|
||||
def read(*_args, **_kwargs):
|
||||
started.set()
|
||||
assert release.wait(5)
|
||||
return {'schedules': []}
|
||||
monkeypatch.setattr(operations, '_read', read)
|
||||
monkeypatch.setattr(operations.tickets, 'refresh', read)
|
||||
if source == 'timer':
|
||||
operations.tick()
|
||||
else:
|
||||
spec = {'operation': source}
|
||||
if source == 'refresh_ticket':
|
||||
spec['incident_id'] = 'a' * 24
|
||||
operations.request({'request_id': 'a' * 32, 'spec': spec})
|
||||
try:
|
||||
qtbot.waitUntil(started.is_set)
|
||||
assert operations.worker not in ui.window._workers
|
||||
assert not operations.busy
|
||||
ui.window._run_async(executed.set, lambda _: None)
|
||||
qtbot.waitUntil(executed.is_set, timeout=1000)
|
||||
assert not release.is_set()
|
||||
finally:
|
||||
release.set()
|
||||
qtbot.waitUntil(lambda: operations.worker is None and not ui.window._workers)
|
||||
|
||||
|
||||
class DiagnosisView(HarnessView):
|
||||
diagnosis_event = Signal(object)
|
||||
is_running = True
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.requests = []
|
||||
|
||||
def request_diagnosis(self, request):
|
||||
self.requests.append(request)
|
||||
|
||||
def shutdown(self):
|
||||
self.is_running = False
|
||||
self.stopped.emit()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def diagnosis(ui, monkeypatch, qtbot):
|
||||
from dx_productivity.trial_task_center.ui import dsh_automation as module
|
||||
ui.settle()
|
||||
monkeypatch.setattr(type(ui.window), '_create_dsh_view', lambda self: DiagnosisView(self))
|
||||
published = []
|
||||
monkeypatch.setattr(module, 'GitIssuePublisher', lambda _path: lambda *_args: published.append(True) or {'status': 'unavailable'})
|
||||
automation = DshAutomation(ui.window)
|
||||
ui.window._dsh_automation = automation
|
||||
assert automation.enqueue(ui.tasks[0].task_id, 'worker_error', 'controlled failure',
|
||||
execution_authorized=True, run_id='old-run')
|
||||
automation._drain()
|
||||
qtbot.waitUntil(lambda: bool(ui.window._dsh_view.requests))
|
||||
yield automation, ui.window._dsh_view, published
|
||||
automation._native_unavailable = True
|
||||
automation._runtime_stopped()
|
||||
if hasattr(automation, 'close'):
|
||||
automation.close()
|
||||
qtbot.waitUntil(lambda: automation.worker is None)
|
||||
|
||||
|
||||
def test_model_wait_does_not_own_controls_or_starve_execution(single_execution_thread, diagnosis, ui, qtbot):
|
||||
automation, _view, _ = diagnosis
|
||||
executed = Event()
|
||||
try:
|
||||
assert automation.worker not in ui.window._workers
|
||||
assert ui.window._batch_stop is None
|
||||
assert ui.window._active_quick_run_task_id is None
|
||||
worker = ServiceWorker(executed.set)
|
||||
single_execution_thread.start(worker)
|
||||
qtbot.waitUntil(executed.is_set, timeout=1000)
|
||||
finally:
|
||||
automation.close()
|
||||
qtbot.waitUntil(lambda: automation.worker is None)
|
||||
|
||||
|
||||
def test_old_diagnosis_finishing_preserves_new_manual_run(diagnosis, ui, qtbot):
|
||||
automation, _, _ = diagnosis
|
||||
ui.window._begin_run(ui.tasks[1].task_id)
|
||||
manual_stop, run_id = ui.window._batch_stop, ui.window._dsh_run_id
|
||||
try:
|
||||
automation._runtime_stopped()
|
||||
qtbot.waitUntil(lambda: automation.worker is None)
|
||||
assert ui.window._batch_stop is manual_stop
|
||||
assert ui.window._dsh_run_id == run_id
|
||||
assert ui.window._dsh_live_run['active']
|
||||
assert not manual_stop.is_set()
|
||||
finally:
|
||||
ui.window._finish_run()
|
||||
|
||||
|
||||
def test_close_wakes_model_wait_and_suppresses_ticket_submission(diagnosis, ui, qtbot):
|
||||
automation, _, published = diagnosis
|
||||
ui.window.close()
|
||||
qtbot.waitUntil(lambda: automation.worker is None, timeout=2000)
|
||||
assert not published
|
||||
|
||||
|
||||
def test_cancelled_close_keeps_idle_automation_available(ui, monkeypatch):
|
||||
ui.settle()
|
||||
ui.window.archive_on_close_check.setChecked(False)
|
||||
automation = DshAutomation(ui.window)
|
||||
ui.window._dsh_automation = automation
|
||||
monkeypatch.setattr(ui.window.plan_panel, 'has_unsaved_plans', lambda: True)
|
||||
monkeypatch.setattr(ui.window, '_close_plan_confirmer', lambda: 'cancel')
|
||||
ui.window.close()
|
||||
assert not ui.window._closed
|
||||
assert not automation._closing
|
||||
|
||||
|
||||
def test_cancelled_close_after_model_cancellation_keeps_automation_available(diagnosis, ui, monkeypatch, qtbot):
|
||||
automation, _, published = diagnosis
|
||||
ui.window.archive_on_close_check.setChecked(False)
|
||||
monkeypatch.setattr(ui.window.plan_panel, 'has_unsaved_plans', lambda: True)
|
||||
monkeypatch.setattr(ui.window, '_close_plan_confirmer', lambda: 'cancel')
|
||||
worker = automation.worker
|
||||
ui.window.close()
|
||||
assert automation.worker is worker
|
||||
assert not automation.cancel_event.is_set()
|
||||
assert not ui.window._closed and not automation._closing
|
||||
assert not published
|
||||
automation.cancel()
|
||||
qtbot.waitUntil(lambda: automation.worker is None)
|
||||
ui.settle()
|
||||
assert not ui.window._closed and not automation._closing
|
||||
assert not published
|
||||
|
||||
|
||||
def test_mutation_admission_owns_lane_only_until_actual_action_finishes(ui, qtbot):
|
||||
from dx_productivity.trial_task_center.stop_control import StopControl
|
||||
ui.settle()
|
||||
automation = DshAutomation(ui.window)
|
||||
ui.window._dsh_automation = automation
|
||||
automation._observed_run_id = ui.window._dsh_run_id
|
||||
automation.current_request = IncidentRequest(ui.tasks[0].task_id, 'worker_error',
|
||||
'controlled failure', True, 'old-run')
|
||||
automation._action_stop = StopControl()
|
||||
entered, release, reflected = Event(), Event(), Event()
|
||||
def action():
|
||||
with automation._action_scope('retry_failed'):
|
||||
entered.set()
|
||||
assert release.wait(5)
|
||||
reflected.set()
|
||||
assert automation.worker not in ui.window._workers
|
||||
return {'status': 'pending_issue'}
|
||||
automation._start_worker(ServiceWorker(action))
|
||||
try:
|
||||
qtbot.waitUntil(entered.is_set)
|
||||
assert automation.worker in ui.window._workers
|
||||
assert ui.window._batch_stop is automation._action_stop
|
||||
assert ui.window._active_quick_run_task_id == ui.tasks[0].task_id
|
||||
finally:
|
||||
release.set()
|
||||
qtbot.waitUntil(lambda: automation.worker is None)
|
||||
assert reflected.is_set()
|
||||
assert not ui.window._workers
|
||||
assert ui.window._batch_stop is None
|
||||
|
||||
|
||||
def test_new_manual_run_denies_old_admission_without_touching_controls(ui, qtbot):
|
||||
from dx_productivity.trial_task_center.stop_control import StopControl
|
||||
ui.settle()
|
||||
automation = DshAutomation(ui.window)
|
||||
ui.window._dsh_automation = automation
|
||||
automation._observed_run_id = ui.window._dsh_run_id
|
||||
automation.current_request = IncidentRequest(ui.tasks[0].task_id, 'worker_error',
|
||||
'controlled failure', True, 'old-run')
|
||||
automation._action_stop = StopControl()
|
||||
ui.window._begin_run(ui.tasks[1].task_id)
|
||||
manual_stop = ui.window._batch_stop
|
||||
rejected, mutated = Event(), Event()
|
||||
def action():
|
||||
try:
|
||||
with automation._action_scope('retry_failed'):
|
||||
mutated.set()
|
||||
except ValueError:
|
||||
rejected.set()
|
||||
return {'status': 'pending_issue'}
|
||||
try:
|
||||
automation._start_worker(ServiceWorker(action))
|
||||
qtbot.waitUntil(lambda: automation.worker is None)
|
||||
assert rejected.is_set() and not mutated.is_set()
|
||||
assert ui.window._batch_stop is manual_stop
|
||||
assert ui.window._active_quick_run_task_id == ui.tasks[1].task_id
|
||||
assert not manual_stop.is_set()
|
||||
finally:
|
||||
ui.window._finish_run()
|
||||
|
||||
|
||||
def test_reflection_waits_for_gui_to_confirm_lane_release(ui, qtbot):
|
||||
from dx_productivity.trial_task_center.stop_control import StopControl
|
||||
ui.settle()
|
||||
automation = DshAutomation(ui.window)
|
||||
ui.window._dsh_automation = automation
|
||||
automation._observed_run_id = ui.window._dsh_run_id
|
||||
automation.current_request = IncidentRequest(ui.tasks[0].task_id, 'worker_error',
|
||||
'controlled failure', True, 'old-run')
|
||||
automation._action_stop = StopControl()
|
||||
releases, reflected = [], Event()
|
||||
automation.action_requested.disconnect(automation._admit_action)
|
||||
def gui(request):
|
||||
if request['release']:
|
||||
releases.append(request)
|
||||
else:
|
||||
automation._admit_action(request)
|
||||
automation.action_requested.connect(gui)
|
||||
def action():
|
||||
with automation._action_scope('retry_failed'):
|
||||
pass
|
||||
reflected.set()
|
||||
return {'status': 'pending_issue'}
|
||||
automation._start_worker(ServiceWorker(action))
|
||||
try:
|
||||
qtbot.waitUntil(lambda: bool(releases))
|
||||
qtbot.wait(5100)
|
||||
assert not reflected.is_set(), 'Model work started before GUI acknowledged release'
|
||||
finally:
|
||||
automation._admit_action(releases[0])
|
||||
qtbot.waitUntil(lambda: automation.worker is None)
|
||||
@@ -155,7 +155,6 @@ def test_clear_removes_queued_blocker_and_disabled_replay_retains_episode():
|
||||
|
||||
|
||||
def test_readonly_diagnosis_starts_while_worker_is_stuck_and_keeps_controls(ui, monkeypatch, qtbot):
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from dx_productivity.trial_task_center.stop_control import StopControl
|
||||
from dx_productivity.trial_task_center.ui import dsh_automation as module
|
||||
ui.settle()
|
||||
@@ -165,7 +164,6 @@ def test_readonly_diagnosis_starts_while_worker_is_stuck_and_keeps_controls(ui,
|
||||
window._workers.add(original)
|
||||
window._batch_stop = stop
|
||||
window._active_quick_run_task_id = window._task_id
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
monkeypatch.setattr(window, '_open_dsh', lambda: None)
|
||||
monkeypatch.setattr(module, 'GitIssuePublisher', lambda path: lambda *args: {'status': 'unavailable'})
|
||||
automation = module.DshAutomation(window)
|
||||
@@ -188,7 +186,6 @@ def test_readonly_diagnosis_starts_while_worker_is_stuck_and_keeps_controls(ui,
|
||||
|
||||
|
||||
def test_resource_diagnosis_keeps_previous_cad_stop_intent(ui, monkeypatch, qtbot):
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from dx_productivity.trial_task_center.stop_control import StopControl
|
||||
from dx_productivity.trial_task_center.ui import dsh_automation as module
|
||||
ui.settle()
|
||||
@@ -196,7 +193,6 @@ def test_resource_diagnosis_keeps_previous_cad_stop_intent(ui, monkeypatch, qtbo
|
||||
previous_stop = StopControl()
|
||||
previous_stop.set()
|
||||
window._dsh_run_stop = previous_stop
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
monkeypatch.setattr(window, '_open_dsh', lambda: None)
|
||||
monkeypatch.setattr(module, 'GitIssuePublisher', lambda path: lambda *args: {'status': 'unavailable'})
|
||||
automation = module.DshAutomation(window)
|
||||
|
||||
@@ -3,7 +3,6 @@ from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import Qt, Signal
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
from dx_productivity.trial_task_center.ui import dsh_automation as module
|
||||
from .test_dsh_native_menu import HarnessView
|
||||
@@ -34,7 +33,6 @@ def slow_diagnosis(ui, qtbot, monkeypatch):
|
||||
ui.settle()
|
||||
window = ui.window
|
||||
published = []
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
monkeypatch.setattr(window, '_create_dsh_view', lambda: SlowHarness(window))
|
||||
monkeypatch.setattr(module, 'GitIssuePublisher', lambda path: lambda *args: published.append(args) or {'status': 'unavailable'})
|
||||
automation = module.DshAutomation(window)
|
||||
|
||||
@@ -188,7 +188,6 @@ def test_native_startup_failure_never_enqueues_itself(ui):
|
||||
def test_disabling_clears_pending_without_stopping_original_execution(ui, monkeypatch):
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from dx_productivity.trial_task_center.ui.dsh_automation import DshAutomation
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
automation = DshAutomation(ui.window)
|
||||
ui.window._dsh_automation = automation
|
||||
from dx_productivity.trial_task_center.stop_control import StopControl
|
||||
@@ -212,7 +211,6 @@ def test_disabling_clears_pending_without_stopping_original_execution(ui, monkey
|
||||
def test_duplicate_errors_share_pending_incident_but_new_runs_do_not(ui, monkeypatch):
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from dx_productivity.trial_task_center.ui.dsh_automation import DshAutomation
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
automation = DshAutomation(ui.window)
|
||||
monkeypatch.setattr(automation, '_drain', lambda: None)
|
||||
for run in ('first', 'first', 'second'):
|
||||
|
||||
@@ -156,7 +156,7 @@ def test_last_execution_receipt_survives_later_catalog_reads(ui, monkeypatch, qt
|
||||
assert view.operations['last_execution']['tasks'][0]['no_match_items'] == 2
|
||||
|
||||
|
||||
def test_history_read_busy_state_is_published_and_rejection_is_visible(ui, monkeypatch, qtbot):
|
||||
def test_history_read_busy_state_is_published_without_blocking_execution_confirmation(ui, monkeypatch, qtbot):
|
||||
from threading import Event
|
||||
view=setup_view(ui,monkeypatch); operations=ui.window._dsh_operations
|
||||
started,release=Event(),Event()
|
||||
@@ -169,8 +169,9 @@ def test_history_read_busy_state_is_published_and_rejection_is_visible(ui, monke
|
||||
assert view.operations['busy'] is True
|
||||
ui.window._dsh_lifecycle.request({'request_id':'b'*32,'capability':'execute',
|
||||
'spec':{'operation':'start','task_ids':[ui.tasks[0].task_id]}})
|
||||
assert view.lifecycle_results[-1]['status']=='busy'
|
||||
assert view.operations['activity']['message']
|
||||
qtbot.waitUntil(lambda: ui.window._dsh_lifecycle.dialog is not None)
|
||||
ui.window._dsh_lifecycle.dialog.reject()
|
||||
assert view.lifecycle_results[-1]['status']=='cancelled'
|
||||
assert not ui.calls
|
||||
finally:
|
||||
release.set()
|
||||
|
||||
@@ -2,7 +2,7 @@ from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QApplication, QMessageBox
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
|
||||
@@ -18,7 +18,6 @@ def test_fresh_install_without_key_is_red_and_task_error_never_starts_ai(no_mode
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
warnings = []
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
monkeypatch.setattr(QMessageBox, 'warning', lambda *args: warnings.append(args))
|
||||
monkeypatch.setattr(DshAutomation, '_drain', lambda self: None)
|
||||
window._show_error(TaskCenterError('worker_error', 'Controlled task failure'))
|
||||
@@ -44,6 +43,31 @@ def test_switch_off_shows_grey_silent_even_without_key(no_model, ui, qtbot):
|
||||
assert '已关闭' in window.ai_status_indicator.toolTip()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code', ['checking', 'runtime_unavailable', 'invalid_configuration', None])
|
||||
def test_unknown_ai_readiness_preserves_original_error_feedback(no_model, ui, monkeypatch, code):
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
warnings = []
|
||||
original = window._dsh_status
|
||||
monkeypatch.setattr(QMessageBox, 'warning', lambda *args: warnings.append(args))
|
||||
try:
|
||||
if code is None:
|
||||
window._dsh_status = None
|
||||
else:
|
||||
original._received({'available': False, 'code': code, 'message': 'Controlled uncertainty'})
|
||||
window._show_error(TaskCenterError('worker_error', 'original failure'))
|
||||
assert len(warnings) == 1
|
||||
assert 'original failure' in warnings[0][-1]
|
||||
assert window._dsh_automation is None
|
||||
if code is None:
|
||||
assert not window._queue_dsh_incident(window._task_id, 'worker_error', 'original failure')
|
||||
assert not window._enqueue_dsh_blocker(source='controlled', task_id=window._task_id,
|
||||
issue_code='worker_error', run_id='controlled', message='original failure', details={},
|
||||
read_only=True, cleanup_allowed=False, snapshot={})
|
||||
finally:
|
||||
window._dsh_status = original
|
||||
|
||||
|
||||
def test_indicator_tooltip_explains_live_intervention_reason_and_stage(no_model, ui, monkeypatch):
|
||||
window = ui.window
|
||||
assert hasattr(window, 'ai_status_indicator'), 'The old cancel button does not explain intervention'
|
||||
@@ -161,7 +185,6 @@ def test_actual_incident_sends_one_diagnosis_and_one_reflection_despite_readines
|
||||
window._dsh_status.query.close()
|
||||
ready = {'available': True, 'code': 'available', 'message': 'Controlled configured model'}
|
||||
window._dsh_status._received(ready)
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
monkeypatch.setattr(window, '_create_dsh_view', lambda: ControlledHarness(window))
|
||||
publications = []
|
||||
monkeypatch.setattr(dsh_automation, 'GitIssuePublisher', lambda path:
|
||||
@@ -239,7 +262,6 @@ def test_failed_runtime_start_keeps_unstarted_request_identity_for_recovery(no_m
|
||||
window._dsh_status.timer.stop()
|
||||
window._dsh_status.query.close()
|
||||
window._dsh_status._received({'available': True, 'code': 'available', 'message': 'Configured'})
|
||||
monkeypatch.setattr(QApplication, 'platformName', lambda: 'windows')
|
||||
automation = dsh_automation.DshAutomation(window)
|
||||
monkeypatch.setattr(window, '_dsh_automation', automation)
|
||||
monkeypatch.setattr(window, '_open_dsh', lambda: window._dsh_status.runtime_failed('Controlled startup failure'))
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
def test_owned_modal_can_be_handled_while_execution_worker_is_busy(ui, monkeypatch):
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
worker = object()
|
||||
invoked = []
|
||||
monkeypatch.setattr('dx_productivity.trial_task_center.ui.cad_dialog_operations.show_cad_dialogs',
|
||||
lambda current: invoked.append(current))
|
||||
window.service._supervisor_dialog_state = {'supervision': {'blocked': True}}
|
||||
window._workers.add(worker)
|
||||
try:
|
||||
window._update_gates()
|
||||
button = window.run_panel.cleanup_resources_button
|
||||
assert not button.isHidden() and button.isEnabled()
|
||||
button.click()
|
||||
assert invoked == [window]
|
||||
finally:
|
||||
window._workers.discard(worker)
|
||||
window.service._supervisor_dialog_state = None
|
||||
window._update_gates()
|
||||
|
||||
|
||||
def test_retained_resource_force_requires_explicit_operator_choice(ui, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
forced = []
|
||||
monkeypatch.setattr(window.service, 'cleanup_batch_resources', lambda: ({'state': 'blocked'},))
|
||||
monkeypatch.setattr(window.service, 'force_pending_owned_resources',
|
||||
lambda *, confirmed=False: forced.append(confirmed) or ())
|
||||
monkeypatch.setattr(window, '_run_async', lambda action, done, *_a, **_k: done(action()))
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *_a, **_k: QMessageBox.StandardButton.No)
|
||||
window.run_panel.cleanup_resources_button.setEnabled(True)
|
||||
window._cleanup_batch_resources()
|
||||
assert forced == []
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *_a, **_k: QMessageBox.StandardButton.Yes)
|
||||
window.run_panel.cleanup_resources_button.setEnabled(True)
|
||||
window._cleanup_batch_resources()
|
||||
assert forced == [True]
|
||||
@@ -24,7 +24,17 @@ def test_project_plan_discard_is_safe_after_qt_reclaims_report_control(ui, qtbot
|
||||
@pytest.mark.parametrize('stop_kind',['none','pause','force','pause_then_reauthorize'])
|
||||
def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monkeypatch,scope,stop_kind):
|
||||
from dx_productivity.trial_task_center.ui import dsh_automation
|
||||
from dx_productivity.trial_task_center import task_queue
|
||||
from dx_productivity.trial_task_center.target_plan import ComponentTarget, TargetPlanRow
|
||||
from dx_productivity.dsh import execution_runs
|
||||
ui.settle()
|
||||
window=ui.window;task=ui.tasks[0]
|
||||
project = ui.service.projects(task.task_id)[0].path
|
||||
target = ComponentTarget(project, 'MAIN', '1', 'controlled-uid', 'R1', 'OLD', '10K')
|
||||
ui.store.record_target_inventory(task.task_id, (target,))
|
||||
ui.store.replace_target_plan(task.task_id, (TargetPlanRow(target, True, 'NEW'),))
|
||||
ui.open(task)
|
||||
ui.settle()
|
||||
window._tasks=(task,)
|
||||
window._quick_run_confirmer=lambda *args:True
|
||||
window._update_gates()
|
||||
@@ -36,10 +46,18 @@ def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monk
|
||||
if stop_kind in {'pause','pause_then_reauthorize'}:window._pause_queue()
|
||||
elif stop_kind=='force':window._force_batch_stop()
|
||||
failure_count=2 if stop_kind=='pause_then_reauthorize'else 1
|
||||
state='batch_failed'if len(calls)<=failure_count else'no_match'
|
||||
if len(calls)<=failure_count:
|
||||
return subprocess.CompletedProcess(command,2,'','Controlled prewrite attachment failure')
|
||||
with (Path(command[3])/'status.tsv').open('a',encoding='utf8')as stream:
|
||||
stream.write(f'{command[-1]}\t{state}\tbatch_closed\tControlled result\n')
|
||||
stream.write(f'{command[-1]}\tno_match\tbatch_closed\tControlled result\n')
|
||||
return subprocess.CompletedProcess(command,0,'','')
|
||||
execute_queue = task_queue.execute_task_queue
|
||||
def primary_pass(*args, **kwargs):
|
||||
# Leave the one safe component replay to DSH so this tests its stop handoff.
|
||||
kwargs['defer_problem_pass'] = True
|
||||
return execute_queue(*args, **kwargs)
|
||||
monkeypatch.setattr(task_queue, 'execute_task_queue', primary_pass)
|
||||
monkeypatch.setattr(execution_runs, 'execute_task_queue', primary_pass)
|
||||
# Keep the real service, queue, persistence, IncidentRunner and Qt handoff;
|
||||
# replace only external CAD/model/issue transports and background dispatch.
|
||||
monkeypatch.setattr(ui.service.for_project_task(task.task_id)._quick_run_preparer,'_process_runner',executor)
|
||||
@@ -50,8 +68,23 @@ def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monk
|
||||
monkeypatch.setattr(window,'_open_dsh',lambda:None)
|
||||
automation=dsh_automation.DshAutomation(window)
|
||||
window._dsh_automation=automation
|
||||
monkeypatch.setattr(dsh_automation.QApplication,'platformName',lambda:'review-test')
|
||||
monkeypatch.setattr(automation,'_analyze',lambda *args:{'reply':json.dumps({'summary':'Retry suggestion','action':'retry_failed'})})
|
||||
analyzed = Event()
|
||||
def analyze(*args):
|
||||
analyzed.set()
|
||||
return {'reply':json.dumps({'summary':'Retry suggestion','action':'retry_failed'})}
|
||||
monkeypatch.setattr(automation,'_analyze',analyze)
|
||||
def wait_for_diagnosis(previous_run=None):
|
||||
def finished():
|
||||
record = automation.latest
|
||||
assert (analyzed.is_set() and automation.worker is None and
|
||||
record.get('status') in {'resolved','pending_issue','escalated'} and
|
||||
(previous_run is None or record.get('run_id') != previous_run and
|
||||
record.get('status') == 'resolved')), (
|
||||
f'{scope}/{stop_kind}: worker={automation.worker!r}, pending={automation.pending!r}, '
|
||||
f'latest={record!r}, loading={window._loading}, workers={window._workers!r}, '
|
||||
f'context_busy={window._context_query.busy}, operations_busy={window._dsh_operations.busy}, '
|
||||
f'readiness={window._dsh_status.availability!r}')
|
||||
qtbot.waitUntil(finished,timeout=10000)
|
||||
monkeypatch.setattr(dsh_automation,'GitIssuePublisher',lambda *args:lambda *args:{'status':'unavailable'})
|
||||
if scope=='single':window._prepare_quick_run()
|
||||
else:window._execute_project_tasks()
|
||||
@@ -62,8 +95,7 @@ def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monk
|
||||
# grouped runs. Observe the real result without replacing its executor.
|
||||
result = outcomes[0][0] if isinstance(outcomes[0], tuple) else outcomes[0]
|
||||
assert (result['paused'] if isinstance(result, dict) else result.paused) is False
|
||||
qtbot.waitUntil(lambda:automation.worker is None and
|
||||
automation.latest.get('status')in {'resolved','pending_issue','escalated'},timeout=10000)
|
||||
wait_for_diagnosis()
|
||||
ui.settle()
|
||||
record=automation.latest
|
||||
assert len(calls)==(2 if stop_kind=='none'else 1)
|
||||
@@ -75,14 +107,13 @@ def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monk
|
||||
assert not list((ui.data/'dsh/retry-budget').glob('*.json'))
|
||||
if stop_kind=='pause_then_reauthorize':
|
||||
original_run=record['run_id']
|
||||
analyzed.clear()
|
||||
window._retry_failed();ui.settle()
|
||||
window._tasks=(ui.service.get_task(task.task_id),)
|
||||
window._update_gates()
|
||||
if scope=='single':window._prepare_quick_run()
|
||||
else:window._execute_project_tasks()
|
||||
qtbot.waitUntil(lambda:automation.worker is None and
|
||||
automation.latest.get('run_id')!=original_run and
|
||||
automation.latest.get('status')=='resolved',timeout=10000)
|
||||
wait_for_diagnosis(original_run)
|
||||
ui.settle()
|
||||
assert len(calls)==3
|
||||
assert automation.latest['gates']['not_stopped']
|
||||
|
||||
Reference in new issue
Block a user