From 8818fa98416d64d9075b0215e1f5e7db33c2942e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Tue, 17 Nov 2026 11:33:49 +0800 Subject: [PATCH] fix: acknowledge each legacy tip once per cleanup intent --- src/cbb_refresh_verify/residual_sessions.py | 9 ++++-- tests/test_issue15_native_entry.py | 33 ++++++++++++++------- tests/test_registered_startup_release.py | 22 ++++++++++++-- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/cbb_refresh_verify/residual_sessions.py b/src/cbb_refresh_verify/residual_sessions.py index a3ea28f..6bcd9c4 100644 --- a/src/cbb_refresh_verify/residual_sessions.py +++ b/src/cbb_refresh_verify/residual_sessions.py @@ -698,7 +698,7 @@ def _close_registered_startup(row, handle, proof, *, stop=None): if not active_owner() or time.monotonic() >= deadline: raise ValueError('STARTUP_ACTION_UNCONFIRMED') _post_window_message({'desktop':job['desktop']}, hwnd, row['pid'], message) - state = {'clicked':set()}; closed = proof['closed_frame'] + state = {'clicked':set()}; closed = proof['closed_frame']; dismissed_tips = set() try: while time.monotonic() < deadline: if win32event.WaitForSingleObject(handle, 0) == win32con.WAIT_OBJECT_0: @@ -712,8 +712,11 @@ def _close_registered_startup(row, handle, proof, *, stop=None): if closed is not None: tip_row['startup_frame'] = closed has_tip = any(w['title'] == 'Tip of the Day' for w in snapshot.get(row['pid'],[])) - if has_tip and confirmed() and _dismiss_startup_tip(tip_row,handle,snapshot.get(row['pid'],[]), - incomplete=_window_error(snapshot,row['pid']),deadline=deadline,stop=stop) is not None: + tip = (_dismiss_startup_tip(tip_row,handle,snapshot.get(row['pid'],[]), + incomplete=_window_error(snapshot,row['pid']),dismissed=dismissed_tips,deadline=deadline,stop=stop) + if has_tip and confirmed() else None) + if tip is not None: + dismissed_tips.add(tip) if closed is None: continue # Tip may precede loading; the same intent still owns its one Close. while time.monotonic() < deadline: diff --git a/tests/test_issue15_native_entry.py b/tests/test_issue15_native_entry.py index 8a635cb..40ac413 100644 --- a/tests/test_issue15_native_entry.py +++ b/tests/test_issue15_native_entry.py @@ -218,34 +218,47 @@ def test_independent_backup_job_registration_retains_descendants_after_caller_ha def test_common_admission_refusal_publishes_bound_receipt_and_ui_can_reopen(qtbot, tmp_path, monkeypatch): - import win32api + import subprocess,sys from threading import Event, Thread from test_native_backup import project_fixture from test_ui_filters import load_window from cbb_refresh_verify import native_backup as native, desktop_worker - from cbb_refresh_verify.application import main request, _ = project_fixture(tmp_path) monkeypatch.setattr(native, 'native_backup_executable', lambda *_: tmp_path/'native.exe') - monkeypatch.setattr(native.subprocess, 'Popen', lambda *a, **k: - SimpleNamespace(pid=os.getpid(), handle=win32api.GetCurrentProcess(), poll=lambda: None)) - session = native.launch_native_backup(request) + # A cold observer reads kernel identity: poll=exited on pytest's live PID + # cannot represent a released worker. Use a real, harmless refused child. + invoke = tmp_path/'invoke-refusal.signal' + child = tmp_path/'refused_worker.py' + child.write_text('import sys,time\nfrom pathlib import Path\n' + f'gate=Path({str(invoke)!r})\ndeadline=time.monotonic()+10\n' + 'while not gate.exists() and time.monotonic()=.3: + state['tip']=False + if closed:records.clear() + return {12:deepcopy(tip_windows) if state['tip'] else []} + monkeypatch.setattr(sessions,'_process_windows',windows) monkeypatch.setattr(win32gui,'GetWindow',lambda h,k:100 if h==200 and k==win32con.GW_OWNER else 0) original=win32gui.PostMessage def post(hwnd,message,*args): original(hwnd,message,*args) - if closed and hwnd==201:records.clear() + if hwnd==201: + if delayed_tip:state.update(tip=True,tip_posted=True) + elif closed:records.clear() monkeypatch.setattr(win32gui,'PostMessage',post) + if delayed_tip and closed: + original_wait=__import__('win32event').WaitForSingleObject + def wait(handle,ms): + value=original_wait(handle,ms) + if state.get('tip_posted') and state['ticks']>=.3:records.clear() + return value + monkeypatch.setattr(__import__('win32event'),'WaitForSingleObject',wait) assert sessions._request_close(row)['release_status']=='RELEASED' assert messages==([(201,245)] if closed else [(201,245),(31,245),(100,16)]) assert not records and state['ticks']<30