diff --git a/docs/releases/2026-11-11-pr13-review381-validation.json b/docs/releases/2026-11-11-pr13-review381-validation.json new file mode 100644 index 0000000..2410779 --- /dev/null +++ b/docs/releases/2026-11-11-pr13-review381-validation.json @@ -0,0 +1,210 @@ +{ + "date": "2026-11-11", + "baseline": "fdd07224aac99bee8d1f29e8e82d6a2c49964c87", + "review_comment": "https://git.simgreek.com/Skyworth_Digital_Hardware/cbb-refresh-verify-795/pulls/13#issuecomment-381", + "full_suite": { + "tests": 1789, + "failures": 0, + "errors": 0, + "skipped": 0, + "seconds": 341.04 + }, + "focused_final": { + "tests": 57, + "failures": 0, + "errors": 0, + "skipped": 0, + "seconds": 10.935 + }, + "windows_native_direct_runs": [ + { + "tests": 21, + "failures": 0, + "errors": 0, + "skipped": 0, + "seconds": 14.625 + }, + { + "tests": 21, + "failures": 0, + "errors": 0, + "skipped": 0, + "seconds": 11.765 + } + ], + "windows_platform": { + "platform": "windows", + "desktop": "CbbUiReview381_ea1f0bcdc2", + "exit_status": 0, + "total": 21, + "failures": 0, + "mentor_calls": false + }, + "inconclusive_windows_controller_run": { + "controller_exit_code": 1, + "assertion_total": 21, + "assertion_failures": 0, + "counted_as_pass": false, + "controller_cause_confirmed": false, + "followup": "Direct pytest launch and stack diagnostics; two direct runs exited 0." + }, + "negative_control": { + "expected_failure": true, + "result": { + "tests": 1, + "failures": 1, + "errors": 0, + "skipped": 0, + "seconds": 3.75 + }, + "method": "Only baseline _queued_action restored in test memory; no source mutation." + }, + "compileall_passed": true, + "diff_check_passed": true, + "tested_production_sha256": "a18d36f893f6e23b8e52b3d7e0b8cfba9ebfa08abb44acb54219cc092b318942", + "full_run_file_hashes": { + "src/cbb_refresh_verify/ui/main_window.py": "a18d36f893f6e23b8e52b3d7e0b8cfba9ebfa08abb44acb54219cc092b318942", + "tests/test_review381_queue_release.py": "56661d607b55d1284fad69105d4457ab6816696a998188d6986ed67765b326e0", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.ico": "62d4472ebaa94f9b39aebae06459685d3322041d0e1a7ada9f368cfd816ba1d6", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.png": "840f657fd7c622d9afd78625a64ed8ad04c90a895dd3c9fd37eebae543cdebe8", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.svg": "cbba5b3f339cbeb5eb43012709237359442ef67c69fc5b6679a8ee4c0a1b7328" + }, + "final_file_hashes": { + "src/cbb_refresh_verify/ui/main_window.py": "a18d36f893f6e23b8e52b3d7e0b8cfba9ebfa08abb44acb54219cc092b318942", + "tests/test_review381_queue_release.py": "e568a2701337be068af91a03ff3451d82c705109a7b62c3c11663a42bcf552b5", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.ico": "62d4472ebaa94f9b39aebae06459685d3322041d0e1a7ada9f368cfd816ba1d6", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.png": "840f657fd7c622d9afd78625a64ed8ad04c90a895dd3c9fd37eebae543cdebe8", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.svg": "cbba5b3f339cbeb5eb43012709237359442ef67c69fc5b6679a8ee4c0a1b7328" + }, + "test_refinement_after_full": "Only one test gained an admission barrier; production unchanged; focused and Windows rerun.", + "candidate_rebuilt": true, + "candidate_executable": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-candidate\\dist\\CbbRefreshVerify-Background\\CbbRefreshVerify.exe", + "bundle": { + "module_count": 62, + "source_and_frozen_code_equal": true, + "source_sha256_checked": true, + "packaged_assets_equal": true, + "exe_icon_images_equal": true, + "executable_sha256": "71812c1fdfa6522fad4468f4ca4c7d8f77aa9c6880b70f0d8b7ad58a31d55ec2" + }, + "frozen_smoke": { + "gui": { + "status": "passed", + "exit_code": 0 + }, + "verify-worker": { + "exit_code": 1, + "status": "passed", + "evidence": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-candidate\\smoke-319c4ff4\\verify-worker" + }, + "management-worker": { + "exit_code": 2, + "status": "passed", + "evidence": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-candidate\\smoke-319c4ff4\\management-worker" + }, + "owner-probe": { + "exit_code": 0, + "status": "passed", + "evidence": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-candidate\\smoke-319c4ff4\\owner-probe" + }, + "dialog-agent": { + "status": "passed", + "exit_code": 0, + "scope": "empty PID set, observe only" + }, + "module_origins": { + "status": "passed", + "module_count": 62, + "source_root": "F:\\Sync Tool Skyworth\\Work Maps\\cbb-refresh-verify-795-review-stack\\src" + }, + "version": "0.2.4b2" + }, + "independent_review": { + "scope": "review381 and directly related stale/cross-task release UI", + "reviewer": "review381_final", + "reviewed_files": [ + "src/cbb_refresh_verify/ui/main_window.py", + "tests/test_review381_queue_release.py" + ], + "finding": "foreground completion erased independent background wait", + "followup": "fixed; both completion orders reproduced failing then passing", + "final_review": "no additional findings", + "review_native_calls": false + }, + "native_mentor_operations_verified": false, + "icdb_repair_accepted": false, + "field_library_modified": false, + "windows10_verified": false, + "shared_library_verified": false, + "merged": false, + "artifacts": { + "review381-baseline.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-baseline.xml", + "sha256": "f224548b02b5841f7d3148375eea50f6505c83af912b66a7d67c5d572bc287b3" + }, + "review381-red-controlled.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-red-controlled.xml", + "sha256": "15c620cb4ec251501d83fd7ebc4ee654df8b0e4b7aa8f8ccb2d7af30ec162c5f" + }, + "review381-interleaved-red.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-interleaved-red.xml", + "sha256": "fea4342c4bdab3b03e70f70585e66281188ac80ae7613e4bf7db9fcd616ce1f5" + }, + "review381-completion-red.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-completion-red.xml", + "sha256": "6dab11fbba7878db81885f5d11fadc5c80728a9dab3cab8edd0883cb7015d3e2" + }, + "review381-full.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-full.xml", + "sha256": "9f73a2dddae8831c2bad4ae1fb2f2f509b1981508a512fffb208dce1a858860f" + }, + "review381-focused-barrier.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-focused-barrier.xml", + "sha256": "ec7fd3dc3ce869b97ed3f22e7e9528f60dc8512a89e451eae434fe665bae838a" + }, + "review381-admission-negative-control.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-admission-negative-control.xml", + "sha256": "ecb66304ee5cc1be9c19c4ba33c57a7bd86e65b156a959fa5665cba2274679e9" + }, + "review381-windows-direct-first.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-windows-direct-first.xml", + "sha256": "3ba672a9190a5ec715ae99db01c0faca1b3bfcfe9d25a25ba46309af7f5c1880" + }, + "review381-windows-direct-first-platform.json": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-windows-direct-first-platform.json", + "sha256": "a255f39b48fe69656c553b6a4feff6f905beb1e18ba2de9724454f15d3d8ea56" + }, + "review381-windows.xml": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-windows.xml", + "sha256": "a2d53895c5afaf0907a670d544cd98db6c786bbf75f2e520ac0355d3c4a88ff2" + }, + "review381-windows-platform.json": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-windows-platform.json", + "sha256": "e06d76c1c2c297f6d4e11f76a903666a1bdf47cdc81a26a295c2040ef9381bbb" + }, + "review381-independent-review.json": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-independent-review.json", + "sha256": "155c0b1c4ae3ecb5b94b1a2d321e47b96a4885f18cc369f36c82408b20959981" + }, + "review381-candidate/source-sha256.json": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-candidate\\source-sha256.json", + "sha256": "6028d5cb3f6eeec68ae938fb73223d5343de7c8671ba3b77d9a1d1e6faa37608" + }, + "review381-candidate/bundle-verification.json": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-candidate\\bundle-verification.json", + "sha256": "08117158e59192c7ee7f0538968b24d5e4cb8e9f8f230636bd009aa39ffbc4b5" + }, + "review381-candidate/smoke-319c4ff4/result.json": { + "path": "C:\\Users\\ABS_Windows\\.codex\\visualizations\\2026\\11\\02\\01a19b86-b23f-7fe0-9407-45a4303e10e3\\review381-candidate\\smoke-319c4ff4\\result.json", + "sha256": "3cefd58746044c0f48455aba9796b0a30687ee5a30084fa1948449e5094c1a10" + } + }, + "committed_file_hashes": { + "src/cbb_refresh_verify/ui/main_window.py": "a18d36f893f6e23b8e52b3d7e0b8cfba9ebfa08abb44acb54219cc092b318942", + "tests/test_review381_queue_release.py": "e0d62424cbf70ec9573db78ede0a4c6534775399194eed4c6b28ba8d468307be", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.ico": "62d4472ebaa94f9b39aebae06459685d3322041d0e1a7ada9f368cfd816ba1d6", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.png": "840f657fd7c622d9afd78625a64ed8ad04c90a895dd3c9fd37eebae543cdebe8", + "src/cbb_refresh_verify/assets/cbb_refresh_verify.svg": "cbba5b3f339cbeb5eb43012709237359442ef67c69fc5b6679a8ee4c0a1b7328" + }, + "post_validation_whitespace_cleanup": "Trimmed one trailing blank line in test file; compiled test code equal; staged diff check rerun." +} diff --git a/docs/releases/2026-11-11-pr13-review381.md b/docs/releases/2026-11-11-pr13-review381.md new file mode 100644 index 0000000..ed8e116 --- /dev/null +++ b/docs/releases/2026-11-11-pr13-review381.md @@ -0,0 +1,43 @@ +# PR #13 评论 381:等待入口与交错操作验证 + +对应审查:。基线为 `fdd07224aac99bee8d1f29e8e82d6a2c49964c87`。 + +## 修复行为 + +校验获得原生执行机会后,立即刷新执行状态和残留入口。入口显示及点击均复核现有的内存保留状态,已释放的库不会因旧消息或延迟点击重新打开释放面板。窗口进入关闭流程后,不接受新的释放面板请求。 + +等待消息在覆盖当前目标前,同样检查消息所指库现在是否仍被保留。另一个库的普通排队消息、已过期的保留消息或 ICDB 开始事件,不会抹掉仍有效的等待入口。 + +独立复查补充发现:前台任务结束会清除另一个库正在等待的后台 ICDB 入口。现在前台结束时保留该后台任务的有效入口;后台取消或结束时,移除属于它的过期入口,同时保留同库前台仍需要的入口。路径比较使用已知别名,不查询磁盘、网络或 WMI。 + +没有新增库锁、占用扫描、轮询线程或强制结束逻辑。原生执行仍串行;未确认释放时的同库保护和自动 Repair 关闭状态不变。本次不调整整批调度。 + +## 实际执行的验证 + +| 验证 | 结果 | +| --- | --- | +| 既有队列入口基线 | 7 通过 | +| 原问题及交错操作,修复前 | 7 失败、2 通过;随后扩展的交错用例另有 3 项预期失败 | +| 前台结束/后台取消两种顺序,修复前 | 2 项均失败 | +| 全量 Python 测试 | 1,789 通过、0 失败、0 跳过;既有 STA COM 模式警告 1 项 | +| 加强并发屏障后的相关回归 | 57 通过 | +| Windows 原生 Qt 控件,独立私有桌面 | 21 项通过;直接启动的最终验证记录另存 JSON/XML | +| 负向对照 | 仅在测试进程内恢复旧的队列接纳方法,新用例稳定失败;不修改源文件 | +| 编译及差异检查 | `compileall` 和 `git diff --check` 通过 | +| 新冻结候选包 | 5 项冒烟通过;62 个包内模块与源码一致;包内图标及 EXE 图标资源一致 | + +全量测试后仅加强了一个测试的时序屏障,业务源码没有再变化;加强后的测试文件已重新执行相关回归和 Windows 控件验证。全量时与最终测试文件的哈希分别保留。 + +新增的 14 项用例覆盖:执行尚未结束时隐藏旧入口;五次延迟点击;过期等待消息;独立库事件交错;反复打开、关闭和重开面板;重复点校验后停止再点释放;前后台任务先后结束;关闭过程中送达的点击。控件点击使用真实 PySide6 控件与事件循环;库数据和原生扫描采用隔离替身,不操作现场库。 + +一次较长启动链的 Windows 验证中,21 项断言均通过,但外层控制器返回 1,未计为完整通过。随后缩短验证启动链,直接启动 pytest,并加入超时堆栈记录;直接运行的正常退出结果单独保留。不能据此把那次控制器异常认定为已复现的业务故障,也不隐去该次未完成验证。具体记录见相邻验证 JSON。 + +## 候选包与边界 + +新包位置记录于 `2026-11-11-pr13-review381-validation.json`,构建和验证产物保存在本机 Codex visualizations 目录。EXE SHA-256: + +`71812c1fdfa6522fad4468f4ca4c7d8f77aa9c6880b70f0d8b7ad58a31d55ec2` + +冻结冒烟包括 GUI 创建及正常退出、启动前取消的 Verify worker、桌面不匹配时拒绝操作的管理 worker、空所有者查询,以及私有桌面上空 PID 范围的弹窗观察。后四项是受控边界验证,不代表真实原生操作成功。 + +本轮未执行真实 Mentor Save/Close/Add/Remove 或 ICDB 修复,未写入现场中心库;也未验证 Windows 10、跨机器共享库或现场故障一致副本。不能将本次界面和生命周期验证作为 ICDB 自动修复成功的依据。不合并发布、不关闭现场工单。 diff --git a/src/cbb_refresh_verify/ui/main_window.py b/src/cbb_refresh_verify/ui/main_window.py index 55bc659..2daa573 100644 --- a/src/cbb_refresh_verify/ui/main_window.py +++ b/src/cbb_refresh_verify/ui/main_window.py @@ -419,8 +419,9 @@ class MainWindow(QWidget): self.backup_restore_button.setEnabled(ready and bool( self._eligible_names(checked_only=bool(self.selected_records())))) self.release_library_button.setEnabled(not self.busy and bool(self.lmc_edit.text().strip())) - self.queue_release_button.setVisible(self._queue_wait_library is not None) - self.queue_release_button.setEnabled(self._queue_wait_library is not None and not self._closing) + waiting_library = self._queued_release_library() + self.queue_release_button.setVisible(waiting_library is not None) + self.queue_release_button.setEnabled(waiting_library is not None and not self._closing) reasons = [] for operation, widget in (('add', self.add_button), ('update', self.update_button), ('remove', self.remove_button)): reason = self._management_block_reason(operation) @@ -492,8 +493,26 @@ class MainWindow(QWidget): self.output.append(f'未完成会话:{session.get("block") or ""} · ' f'{phase} · {session.get("detail", "")}\n{session["path"]}') + def _queued_release_library(self): + from cbb_refresh_verify.session_record import library_available + if self._queue_wait_library is not None and library_available(self._queue_wait_library): + self._queue_wait_library = None + return self._queue_wait_library + + def _queue_waiting(self, event): + from cbb_refresh_verify.session_record import library_available + library = event.get('library') + if event.get('retained') and library and not library_available(library): + self._queue_wait_library = library + self._update() + def check_library_release(self, checked=False, *, queued=False): - allowed_queue = queued and self._queue_wait_library is not None + if self._closing: + return + allowed_queue = queued and self._queued_release_library() is not None + if queued and not allowed_queue: + self._update() + return if (self.busy and not allowed_queue) or not self.lmc_edit.text().strip(): return from shiboken6 import isValid @@ -819,7 +838,10 @@ class MainWindow(QWidget): def _queued_action(self, action): from cbb_refresh_verify.session_record import library_available, library_wait_reason library = getattr(self, 'mentor_lmc_path', None) or self.lmc_edit.text() - return lambda: self.native_queue.run(action, stop=self.stop, + def execute(): + self.signals.event.emit({'stage': 'native_slot_acquired', 'library': str(library)}) + return action() + return lambda: self.native_queue.run(execute, stop=self.stop, ready=lambda: library_available(library), wait_state=lambda: library_wait_reason(library), waiting=lambda: self.signals.event.emit({'stage': 'waiting_native_slot', @@ -887,10 +909,8 @@ class MainWindow(QWidget): self.icdb_phase.setText(f'{name} · '+({'icdb_check_start': '正在检查', 'icdb_startup_check': '正在打开工程'}.get(stage, detail))) if stage == 'waiting_native_slot': - self._queue_wait_library = event.get('library') if event.get('retained') else None - self._update() + self._queue_waiting(event) elif stage == 'icdb_check_start': - self._queue_wait_library = None self._update() if not self.busy: self.status_label.setText('后台 ICDB 检查:'+self.icdb_phase.text()) if self.logging_context: @@ -927,6 +947,11 @@ class MainWindow(QWidget): def _icdb_done(self, task): from cbb_refresh_verify.icdb_maintenance import maintenance_counts + task_keys = _library_path_keys(task.requests[0].lmc_file, task.path_lease) + if (task_keys & _library_path_keys(self._queue_wait_library, task.path_lease) + and (not self.busy or not task_keys & _library_path_keys( + self.mentor_lmc_path or self.loaded_path, self.library_lease))): + self._queue_wait_library = None counts = maintenance_counts(task.results) lease = task.path_lease if lease is not None: @@ -1447,8 +1472,10 @@ class MainWindow(QWidget): if not isValid(self) or not isValid(self.cbb_table): return if event.get('stage') == 'waiting_native_slot': - self._queue_wait_library = event.get('library') if event.get('retained') else None self.status_label.setText(event.get('detail', '已排队,等待执行')) + self._queue_waiting(event) + elif event.get('stage') == 'native_slot_acquired': + self.status_label.setText('正在执行当前任务…') self._update() if event.get('stage') in ('session_handoff', 'save_stop_requested'): self.status_label.setText(event.get('detail', '当前状态无法确认')) @@ -1653,7 +1680,11 @@ class MainWindow(QWidget): if self.version_dialog is not None: self.version_dialog.reject() self.version_dialog = None - self._queue_wait_library = None + # Foreground completion must not erase an independent check's wait. + if not (self._icdb_active() and not self.icdb_task.stop.is_set() + and _library_path_keys(self._queue_wait_library, self.icdb_task.path_lease) + & _library_path_keys(self.icdb_task.requests[0].lmc_file, self.icdb_task.path_lease)): + self._queue_wait_library = None self.busy = False; self._update() def open_logs(self): diff --git a/tests/test_review381_queue_release.py b/tests/test_review381_queue_release.py new file mode 100644 index 0000000..673a1ac --- /dev/null +++ b/tests/test_review381_queue_release.py @@ -0,0 +1,241 @@ +"""Stale and repeated user actions around native queue admission.""" +from threading import Event +from types import SimpleNamespace +from pathlib import Path + +import pytest +from PySide6.QtCore import Qt + +from cbb_refresh_verify import session_record as sessions +from cbb_refresh_verify.verify_runner import VerifyResult +from test_review326_queue_guidance import retain +from test_ui_filters import load_window + + +def test_verify_admission_hides_release_entry_before_action_finishes(qtbot, tmp_path, monkeypatch): + window = load_window(qtbot, tmp_path, monkeypatch) + window.show() + retain(monkeypatch, window.mentor_lmc_path) + started, finish = Event(), Event() + + def action(): + started.set() + assert finish.wait(5) + + try: + # Hold admission until after the final waiting notification and proof. + # Neither _start's update nor a second waiting event can hide the bug. + with window.native_queue.condition: + window._start(action, lambda _: None) + window._progress(dict(stage='waiting_native_slot', library='test.lmc', retained=True)) + assert window.queue_release_button.isVisible() + sessions._retained_libraries.clear() + qtbot.waitUntil(started.is_set) + qtbot.waitUntil(lambda: not window.queue_release_button.isVisible(), timeout=1000) + assert window.busy, 'The entry must disappear before the running task ends' + assert window._queue_wait_library is None + assert '排队' not in window.status_label.text() + finally: + finish.set() + sessions._retained_libraries.clear() + window.native_queue.wake() + qtbot.waitUntil(lambda: not window.busy) + + +@pytest.mark.parametrize('stale_library', [None, 'test.lmc']) +def test_delayed_queued_click_cannot_open_a_release_panel_after_proof(qtbot, tmp_path, monkeypatch, stale_library): + from cbb_refresh_verify import library_lock + window = load_window(qtbot, tmp_path, monkeypatch) + window.show() + monkeypatch.setattr(sessions, '_retained_libraries', {}) + scans = [] + monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda library: + (scans.append(library) or dict(library=str(library), sessions=[]))) + window.busy = True + window._queue_wait_library = stale_library + try: + for _ in range(5): + window.check_library_release(queued=True) + qtbot.wait(50) + assert getattr(window, 'release_dialog', None) is None + assert scans == [], 'A stale click must not trigger a new native session scan' + assert window.busy + assert not window.queue_release_button.isVisible() + finally: + dialog = getattr(window, 'release_dialog', None) + if dialog is not None: + qtbot.waitUntil(lambda: not dialog.busy) + dialog.close() + window.busy = False + + +def test_old_waiting_event_is_rechecked_against_current_release_state(qtbot, tmp_path, monkeypatch): + window = load_window(qtbot, tmp_path, monkeypatch) + window.show() + monkeypatch.setattr(sessions, '_retained_libraries', {}) + window._progress(dict(stage='waiting_native_slot', library='test.lmc', retained=True)) + assert not window.queue_release_button.isVisible() + assert window._queue_wait_library is None + + +def test_other_library_icdb_start_preserves_the_foreground_wait(qtbot, tmp_path, monkeypatch): + window = load_window(qtbot, tmp_path, monkeypatch) + window.show() + retain(monkeypatch, window.mentor_lmc_path) + window._start(lambda: None, lambda _: None) + try: + qtbot.waitUntil(lambda: window.queue_release_button.isVisible()) + task = SimpleNamespace(requests=[SimpleNamespace(lmc_file='other.lmc')]) + window._icdb_event(task, dict(stage='icdb_check_start', block='OtherCBB')) + assert window.queue_release_button.isVisible() + assert window._queue_wait_library == 'test.lmc' + finally: + sessions._retained_libraries.clear() + window.native_queue.wake() + qtbot.waitUntil(lambda: not window.busy) + + +@pytest.mark.parametrize('channel', ['verify', 'icdb']) +def test_another_library_wait_without_retention_cannot_erase_a_live_reason(qtbot, tmp_path, monkeypatch, channel): + window = load_window(qtbot, tmp_path, monkeypatch) + window.show() + retain(monkeypatch, window.mentor_lmc_path) + window._queue_wait_library = 'test.lmc' + window._update() + event = dict(stage='waiting_native_slot', library='other.lmc', retained=False) + if channel == 'verify': + window._progress(event) + else: + window._icdb_event(SimpleNamespace(), event) + assert window.queue_release_button.isVisible() + assert window._queue_wait_library == 'test.lmc' + + +@pytest.mark.parametrize('channel', ['verify', 'icdb']) +def test_delayed_other_library_retention_does_not_replace_a_live_reason(qtbot, tmp_path, monkeypatch, channel): + window = load_window(qtbot, tmp_path, monkeypatch) + window.show() + retain(monkeypatch, window.mentor_lmc_path) + window._queue_wait_library = 'test.lmc' + event = dict(stage='waiting_native_slot', library='already-released.lmc', retained=True) + if channel == 'verify': + window._progress(event) + else: + window._icdb_event(SimpleNamespace(), event) + assert window.queue_release_button.isVisible() + assert window._queue_wait_library == 'test.lmc' + + +def test_repeated_click_and_close_reuse_one_panel_without_unlocking_the_task(qtbot, tmp_path, monkeypatch): + from cbb_refresh_verify import library_lock + window = load_window(qtbot, tmp_path, monkeypatch) + window.show() + retain(monkeypatch, window.mentor_lmc_path) + monkeypatch.setattr(library_lock, 'inspect_residual_sessions', + lambda library: dict(library=str(library), sessions=[])) + window._start(lambda: None, lambda _: None) + try: + qtbot.waitUntil(lambda: window.queue_release_button.isVisible()) + qtbot.mouseClick(window.queue_release_button, Qt.LeftButton) + original = window.release_dialog + for _ in range(5): + qtbot.mouseClick(window.queue_release_button, Qt.LeftButton) + assert window.release_dialog is original + qtbot.waitUntil(lambda: not original.busy) + original.reject() + assert window.busy, 'Closing a panel must not mark the queued task finished' + qtbot.mouseClick(window.queue_release_button, Qt.LeftButton) + reopened = window.release_dialog + qtbot.waitUntil(lambda: not reopened.busy) + reopened.close() + assert window.busy + finally: + sessions._retained_libraries.clear() + window.native_queue.wake() + qtbot.waitUntil(lambda: not window.busy) + + +def test_repeat_verify_then_stop_then_delayed_release_click_never_starts_work(qtbot, tmp_path, monkeypatch): + calls = [] + window = load_window(qtbot, tmp_path, monkeypatch, verifier=lambda request: calls.append(request.block_name)) + window.show() + retain(monkeypatch, window.mentor_lmc_path) + window.search_edit.setText('Beta') + window.verify_all() + try: + qtbot.waitUntil(lambda: window.queue_release_button.isVisible()) + for _ in range(5): + qtbot.mouseClick(window.batch_button, Qt.LeftButton) + window.verify_all() + assert len(window.native_queue.pending) == 1 + qtbot.mouseClick(window.stop_button, Qt.LeftButton) + qtbot.waitUntil(lambda: not window.busy) + for _ in range(5): + window.check_library_release(queued=True) + assert calls == [] + assert not window.native_queue.pending + assert getattr(window, 'release_dialog', None) is None + finally: + window.stop.set() + sessions._retained_libraries.clear() + window.native_queue.wake() + qtbot.waitUntil(lambda: not window.busy) + + +@pytest.mark.parametrize('foreground_finishes_first', [True, False]) +def test_foreground_completion_and_background_cancel_keep_only_live_waits(qtbot, tmp_path, monkeypatch, + foreground_finishes_first): + window = load_window(qtbot, tmp_path, monkeypatch, + verifier=lambda _: pytest.fail('A retained library must not start a native check')) + window.show() + retain(monkeypatch, window.mentor_lmc_path) + window._run(['Beta'], maintenance=True) + qtbot.waitUntil(lambda: window.queue_release_button.isVisible()) + window.mentor_lmc_path = Path('other.lmc') + window.lmc_edit.setText('other.lmc') + started, finish = Event(), Event() + + def foreground(): + started.set() + assert finish.wait(5) + return VerifyResult('PASS') + + window._start(foreground, lambda _: None) + try: + qtbot.waitUntil(started.is_set) + if foreground_finishes_first: + finish.set() + qtbot.waitUntil(lambda: not window.busy) + assert window.icdb_task.active + assert window.queue_release_button.isVisible() + assert window._queue_wait_library == 'test.lmc' + window.icdb_task.cancel() + qtbot.waitUntil(lambda: not window._icdb_active()) + assert not window.queue_release_button.isVisible() + if not foreground_finishes_first: + assert window.busy + finally: + finish.set() + window.icdb_task.cancel() + sessions._retained_libraries.clear() + window.native_queue.wake() + qtbot.waitUntil(lambda: not window.busy and not window._icdb_active()) + + +def test_delivered_click_during_window_close_does_not_open_a_panel(qtbot, tmp_path, monkeypatch): + from cbb_refresh_verify import library_lock + window = load_window(qtbot, tmp_path, monkeypatch) + retain(monkeypatch, window.mentor_lmc_path) + monkeypatch.setattr(library_lock, 'inspect_residual_sessions', + lambda library: dict(library=str(library), sessions=[])) + window._queue_wait_library = 'test.lmc' + window._closing = True + try: + window.check_library_release(queued=True) + assert getattr(window, 'release_dialog', None) is None + finally: + window._closing = False + dialog = getattr(window, 'release_dialog', None) + if dialog is not None: + qtbot.waitUntil(lambda: not dialog.busy) + dialog.close()