diff --git a/src/cbb_refresh_verify/ui/main_window.py b/src/cbb_refresh_verify/ui/main_window.py index ac20390..ab043a1 100644 --- a/src/cbb_refresh_verify/ui/main_window.py +++ b/src/cbb_refresh_verify/ui/main_window.py @@ -1960,8 +1960,9 @@ class MainWindow(QWidget): 'detail': result.stderr or result.stdout})) report = None try: - report = BatchTaskContext(str(library)).run(lambda: - write_batch_report(requests, results, self.data_root/'reports')) + report_root = self.data_root/'reports' + report = BatchTaskContext(str(report_root), native_policy='restricted').run( + lambda: write_batch_report(requests, results, report_root)) if maintenance: from cbb_refresh_verify.icdb_maintenance import write_maintenance_report write_maintenance_report(requests, results, report, ()) diff --git a/tests/test_all_buttons.py b/tests/test_all_buttons.py index 73f1571..3c2e6cc 100644 --- a/tests/test_all_buttons.py +++ b/tests/test_all_buttons.py @@ -492,6 +492,39 @@ def test_result_release_and_resume_buttons_run_only_unexecuted_items(controls, q assert [request.block_name for request in controls.runs] == ['Beta','Gamma'] +def test_cancelled_batch_report_is_saved_during_native_handoff(controls, qtbot, monkeypatch): + from cbb_refresh_verify.operation_queue import BatchTaskContext, TaskHandoff + from cbb_refresh_verify.ui import main_window + + window = controls.window + finish_native = Event() + native_finished = Event() + + def pending_native(): + finish_native.wait(8) + native_finished.set() + + def cancelled_batch(requests, **_): + handoff = BatchTaskContext(str(controls.library)) + with pytest.raises(TaskHandoff): + handoff.run(pending_native, timeout_seconds=.1) + return [VerifyResult('CANCELLED', safe_to_continue=False), + *[VerifyResult('SKIPPED') for _ in requests[1:]]] + + monkeypatch.setattr(main_window, 'run_batch', cancelled_batch) + try: + with modal_click(qtbot, QMessageBox.Yes): + press(qtbot, window.batch_button) + qtbot.waitUntil(lambda: not window.busy) + reports = list((window.data_root/'reports').glob('batch-*.log')) + assert len(reports) == 1 + assert 'Beta\tCANCELLED' in reports[0].read_text(encoding='utf-8-sig') + assert not native_finished.is_set() + finally: + finish_native.set() + assert native_finished.wait(3) + + @pytest.mark.parametrize('entry', ['icdb_copy', 'icdb_release', 'batch_copy', 'batch_close']) def test_result_recovery_and_release_entries_stay_bound_to_failed_cbb(controls, qtbot, entry): from dataclasses import replace