feat: complete native BOM and Harness execution acceptance
This commit is contained in:
1 parent
4f8fbd7806
commit
65438cb7e5
234 files changed
+24402
-865
No files matched your search
@@ -0,0 +1,53 @@
|
||||
"""Deferred diagnosis completion must respect the window's Qt lifetime."""
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from shiboken6 import delete
|
||||
|
||||
from dx_productivity.trial_task_center.ui.dsh_automation import DshAutomation
|
||||
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow
|
||||
|
||||
|
||||
def test_diagnosis_finished_close_is_cancelled_when_window_is_destroyed(ui, qtbot):
|
||||
ui.settle()
|
||||
window = TrialTaskCenterWindow(ui.service)
|
||||
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._resource_status.busy)
|
||||
window.archive_on_close_check.setChecked(False)
|
||||
automation = DshAutomation(window)
|
||||
window._dsh_automation = automation
|
||||
window._close_pending = True
|
||||
automation._finished()
|
||||
# Another accepted close can finish before the scheduled retry is delivered.
|
||||
window.close()
|
||||
assert window._closed
|
||||
delete(window)
|
||||
with qtbot.captureExceptions() as exceptions:
|
||||
QApplication.processEvents()
|
||||
assert exceptions == []
|
||||
|
||||
|
||||
def test_harness_stopped_close_is_cancelled_when_window_is_destroyed(ui, qtbot):
|
||||
class Harness(QObject):
|
||||
stopped = Signal()
|
||||
is_running = True
|
||||
|
||||
def shutdown(self):
|
||||
self.is_running = False
|
||||
self.stopped.emit()
|
||||
|
||||
ui.settle()
|
||||
window = TrialTaskCenterWindow(ui.service)
|
||||
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._resource_status.busy)
|
||||
window.archive_on_close_check.setChecked(False)
|
||||
window._dsh_view = Harness(window)
|
||||
window.close()
|
||||
assert not window._closed
|
||||
window.close()
|
||||
assert window._closed
|
||||
delete(window)
|
||||
with qtbot.captureExceptions() as exceptions:
|
||||
QApplication.processEvents()
|
||||
assert exceptions == []
|
||||
@@ -184,6 +184,7 @@ def test_new_manual_run_denies_old_ai_mutation_without_touching_controls(
|
||||
|
||||
window, automation, published, start = slow_diagnosis
|
||||
mutations = []
|
||||
receipt_started, release_receipt = Event(), Event()
|
||||
monkeypatch.setattr(window.service, 'cleanup_batch_resources', lambda: mutations.append('cleanup'))
|
||||
monkeypatch.setattr(window.service, 'prepare_failed_quick_run', lambda _task: mutations.append('prepare'))
|
||||
if action == 'cleanup_resources':
|
||||
@@ -193,15 +194,25 @@ def test_new_manual_run_denies_old_ai_mutation_without_touching_controls(
|
||||
interrupted=False, phase='retry')
|
||||
monkeypatch.setattr(dsh_automation.IncidentRunner, '_snapshot',
|
||||
lambda _self, task_id, _code, _message: ({'task_id': task_id, 'status': 'running'}, context))
|
||||
def certified_receipt(_task):
|
||||
receipt_started.set()
|
||||
assert release_receipt.wait(5), 'Controlled receipt read was not released'
|
||||
return {'items': [{'auto_retries_remaining': 1}]}
|
||||
monkeypatch.setattr(window.service, 'execution_problem_overview', certified_receipt)
|
||||
automation.enqueue(window._task_id, 'execution_failed', 'Controlled retryable failure',
|
||||
execution_authorized=True, run_id='d' * 32)
|
||||
automation._drain()
|
||||
qtbot.waitUntil(lambda: bool(window._dsh_view.requests), timeout=5000)
|
||||
# Certified replay precedes diagnosis; change the GUI execution epoch
|
||||
# while collecting its receipt, before action admission or any mutation.
|
||||
qtbot.waitUntil(receipt_started.is_set, timeout=5000)
|
||||
view = window._dsh_view
|
||||
window._begin_run(ui.tasks[1].task_id)
|
||||
manual_stop = window._batch_stop
|
||||
owner = window._active_quick_run_task_id
|
||||
try:
|
||||
release_receipt.set()
|
||||
qtbot.waitUntil(lambda: window._dsh_view is not None and bool(window._dsh_view.requests), timeout=5000)
|
||||
view = window._dsh_view
|
||||
reply_to_model(view, action)
|
||||
qtbot.waitUntil(lambda: len(view.requests) == 2, timeout=5000)
|
||||
assert not mutations
|
||||
@@ -217,6 +228,9 @@ def test_new_manual_run_denies_old_ai_mutation_without_touching_controls(
|
||||
assert window._active_quick_run_task_id == owner
|
||||
assert len(published) == 1
|
||||
finally:
|
||||
release_receipt.set()
|
||||
automation.cancel()
|
||||
qtbot.waitUntil(lambda: automation.worker is None, timeout=5000)
|
||||
window._finish_run()
|
||||
ui.settle()
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ def test_diagnosis_pins_the_same_route_as_readiness(slow_diagnosis):
|
||||
|
||||
def test_cold_session_wait_does_not_consume_shared_model_budget(slow_diagnosis, monkeypatch, ui):
|
||||
window, automation, _, _ = slow_diagnosis
|
||||
monkeypatch.setattr(automation, '_diagnosis_budget_seconds', lambda: 180)
|
||||
window._open_dsh()
|
||||
clock, waits = [100.0], []
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QDialogButtonBox
|
||||
import pytest
|
||||
from dx_productivity.trial_task_center.ui.dsh_task_creation import DshTaskCreationController
|
||||
from .test_dsh_native_menu import HarnessView
|
||||
|
||||
@@ -33,7 +34,8 @@ def test_model_abort_closes_preview_without_task_creation(ui, monkeypatch):
|
||||
assert controller.dialog is None and view.results[-1]['status'] == 'cancelled'
|
||||
|
||||
|
||||
def test_native_selection_creates_and_selects_real_task_without_executing(ui, monkeypatch, qtbot, tmp_path):
|
||||
@pytest.mark.parametrize('hidden_by', ['none', 'category', 'search'])
|
||||
def test_native_selection_creates_and_selects_real_task_without_executing(ui, monkeypatch, qtbot, tmp_path, hidden_by):
|
||||
controller, view = setup_controller(ui, monkeypatch)
|
||||
root = tmp_path / 'new-engineering'
|
||||
root.mkdir()
|
||||
@@ -45,6 +47,10 @@ def test_native_selection_creates_and_selects_real_task_without_executing(ui, mo
|
||||
qtbot.keyClicks(dialog.directory, str(root))
|
||||
qtbot.mouseClick(dialog.scan, Qt.MouseButton.LeftButton)
|
||||
qtbot.waitUntil(lambda: dialog._worker is None and dialog.projects.count() == 1, timeout=5000)
|
||||
if hidden_by == 'category':
|
||||
ui.window.task_list.filter.setCurrentIndex(ui.window.task_list.filter.findData('completed'))
|
||||
elif hidden_by == 'search':
|
||||
ui.window.task_list.search.setText('an unrelated previous project')
|
||||
qtbot.mouseClick(dialog.buttons.button(QDialogButtonBox.StandardButton.Ok), Qt.MouseButton.LeftButton)
|
||||
qtbot.waitUntil(lambda: controller.worker is None and bool(view.results), timeout=5000)
|
||||
assert view.results[-1]['created_count'] == 1
|
||||
@@ -53,6 +59,7 @@ def test_native_selection_creates_and_selects_real_task_without_executing(ui, mo
|
||||
assert ui.store.list_rules(task_id)[0].new_part_number == 'B'
|
||||
assert path.read_bytes() == original and not ui.calls
|
||||
ui.settle()
|
||||
assert ui.window.task_list.current_task_id() == task_id
|
||||
|
||||
|
||||
def test_unknown_fields_and_busy_state_do_not_open_creation_dialog(ui, monkeypatch):
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Imported plans must offer an actionable route to execution."""
|
||||
import pytest
|
||||
from dx_productivity.trial_task_center.target_plan import ComponentTarget, TargetPlanRow
|
||||
|
||||
|
||||
def test_imported_plan_can_be_saved_from_execution_button(ui):
|
||||
window = ui.window
|
||||
task = ui.tasks[0]
|
||||
project = ui.store.list_projects(task.task_id)[0].path
|
||||
rows = (TargetPlanRow(ComponentTarget(project, 'MAIN', '1', 'imported-r1', 'R1', 'OLD', '100nF'), True, 'NEW'),)
|
||||
ui.store.record_target_inventory(task.task_id, tuple(row.target for row in rows))
|
||||
window.plan_panel._preview_import(rows)
|
||||
ui.settle()
|
||||
assert window.run_panel.quick_run_button.isEnabled()
|
||||
assert '保存' in window.run_panel.quick_run_button.text()
|
||||
confirmations = []
|
||||
window._quick_run_confirmer = lambda *args: confirmations.append(args) or False
|
||||
window.run_panel.quick_run_button.click()
|
||||
ui.settle()
|
||||
assert ui.service.target_plan(task.task_id) == rows
|
||||
assert not window.plan_panel.table.dirty
|
||||
assert window.run_panel.quick_run_button.isEnabled()
|
||||
assert not ui.calls
|
||||
assert confirmations == [('current', 1, 1)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('batch', [False, True])
|
||||
def test_manual_confirmation_obeys_fresh_preflight_blockers(ui, batch):
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
project = ui.store.list_projects(ui.tasks[0].task_id)[0].path
|
||||
project.unlink()
|
||||
confirmations = []
|
||||
window._quick_run_confirmer = lambda *args: confirmations.append(args) or False
|
||||
(window.task_list.queue_button if batch else window.run_panel.quick_run_button).click()
|
||||
assert confirmations == []
|
||||
assert not ui.calls and not window._workers
|
||||
|
||||
|
||||
def test_missing_independent_report_is_visible_after_saved_execution(ui):
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
window._set_operator_message('任务已结束:已保存 1。', 'success')
|
||||
window._show_receipt_verification({'acceptance': {'status': 'unavailable',
|
||||
'tasks': {ui.tasks[0].task_id: 'unavailable'}}})
|
||||
assert '独立网表' in window.run_panel.operator_band.text()
|
||||
assert '未完成' in window.run_panel.operator_band.text()
|
||||
@@ -1,3 +1,21 @@
|
||||
def test_reading_history_does_not_block_current_task_confirmation(ui):
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
confirmations = []
|
||||
window._quick_run_confirmer = lambda *args: confirmations.append(args) or False
|
||||
original = window.history_panel._worker
|
||||
window.history_panel._worker = object()
|
||||
try:
|
||||
window._update_gates()
|
||||
assert window.run_panel.quick_run_button.isEnabled()
|
||||
window.run_panel.quick_run_button.click()
|
||||
assert confirmations == [('current', 1, 1)]
|
||||
assert not ui.calls
|
||||
finally:
|
||||
window.history_panel._worker = original
|
||||
window._update_gates()
|
||||
|
||||
|
||||
def test_owned_modal_can_be_handled_while_execution_worker_is_busy(ui, monkeypatch):
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
@@ -19,7 +37,7 @@ def test_owned_modal_can_be_handled_while_execution_worker_is_busy(ui, monkeypat
|
||||
window._update_gates()
|
||||
|
||||
|
||||
def test_retained_resource_force_requires_explicit_operator_choice(ui, monkeypatch):
|
||||
def test_retained_resource_force_requires_explicit_operator_choice(ui, qtbot, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
window = ui.window
|
||||
ui.settle()
|
||||
@@ -39,4 +57,4 @@ def test_retained_resource_force_requires_explicit_operator_choice(ui, monkeypat
|
||||
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]
|
||||
qtbot.waitUntil(lambda: forced == [True])
|
||||
@@ -78,8 +78,7 @@ def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monk
|
||||
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')), (
|
||||
(previous_run is None or record.get('run_id') != previous_run)), (
|
||||
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}, '
|
||||
@@ -89,16 +88,16 @@ def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monk
|
||||
if scope=='single':window._prepare_quick_run()
|
||||
else:window._execute_project_tasks()
|
||||
assert len(outcomes)==1
|
||||
# This is the review's edge: the queue is exhausted, so paused is False
|
||||
# even though the original control may carry a stop/force request.
|
||||
# A stopped primary pass retains its deferred failures for explicit resume.
|
||||
# Its diagnosis must also retain the original stop/force request.
|
||||
# DSH persists a receipt for single runs and returns (queue, receipt) for
|
||||
# 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
|
||||
assert (result['paused'] if isinstance(result, dict) else result.paused) is (stop_kind != 'none')
|
||||
wait_for_diagnosis()
|
||||
ui.settle()
|
||||
record=automation.latest
|
||||
assert len(calls)==(2 if stop_kind=='none'else 1)
|
||||
assert len(calls)==(2 if stop_kind=='none'else 1), record
|
||||
assert record['gates']['not_stopped']is (stop_kind=='none')
|
||||
assert record['attempts']==(1 if stop_kind=='none'else 0)
|
||||
if stop_kind=='force':assert controls[0].force_event.is_set()
|
||||
@@ -115,7 +114,14 @@ def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monk
|
||||
else:window._execute_project_tasks()
|
||||
wait_for_diagnosis(original_run)
|
||||
ui.settle()
|
||||
assert len(calls)==3
|
||||
# Explicit reauthorization performs the one shared replay. Its second
|
||||
# failure must not earn a third CAD call from the diagnostic model.
|
||||
assert len(calls)==2
|
||||
assert automation.latest['status']=='pending_issue'
|
||||
assert automation.latest['attempts']==0
|
||||
assert not automation.latest['gates']['failure_policy']['retry_allowed']
|
||||
overview=ui.service.execution_problem_overview(task.task_id)
|
||||
assert overview['items'] and all(item['auto_retries_remaining']==0 for item in overview['items'])
|
||||
assert automation.latest['gates']['not_stopped']
|
||||
assert controls[0].is_set() # New authorization never clears old intent.
|
||||
|
||||
|
||||
Reference in new issue
Block a user