from threading import Event import pytest from cbb_refresh_verify.operation_queue import BatchTaskContext, NativeQueue, TaskHandoff, hold_native_handoff from cbb_refresh_verify.ui.icdb_check_task import IcdbCheckTask from cbb_refresh_verify.verify_runner import VerifyResult from test_verify_runner import fixture, request def test_cancelled_diagnostic_report_survives_ongoing_handoff_finalization(qtbot,tmp_path): fixture(tmp_path) req=request(tmp_path,diagnostic_only=True) context=BatchTaskContext(str(req.lmc_file),native_policy='external') entered,finish=Event(),Event() def finalize(): try: hold_native_handoff(None,tmp_path/'session.json') except TaskHandoff: entered.set() assert finish.wait(5) try: with pytest.raises(TaskHandoff):context.run(finalize) assert entered.is_set() task=IcdbCheckTask([req],NativeQueue(),tmp_path/'reports') task.active=True task.results=[VerifyResult('CANCELLED',safe_to_continue=False,stderr='已转后台观察')] task._report() qtbot.waitUntil(lambda:not task.active,timeout=3000) assert task.report is not None and task.report.exists(),task.report_error assert not task.report_error and task.results[0].status=='CANCELLED' finally: finish.set() context.close(timeout_seconds=2)