fix: complete confirmed legacy cleanup from one release intent

This commit is contained in:
阿白叔 committed 2026-11-17 09:44:49 +08:00
1 parent 7cc65f78da
commit a3f69de201
7 files changed
+189 -20

No files matched your search

+78
View File
@@ -12,6 +12,9 @@ def registered_fixture(tmp_path,monkeypatch,*,closed=False,obstacle=''):
import win32con,win32event
job,records,messages,state=loaded_fixture(tmp_path,monkeypatch)
state.update(tip=False,closing=closed)
state['observer_requests']=[]
monkeypatch.setattr(session_record,'handoff_session',lambda path,**kw:
state['observer_requests'].append((path,list(messages),kw)))
job.update(operation_id='verify-old',operation='verify',library=job['lmc_file'],block='IP101GR',
session_record_path=str(tmp_path/'session.json'),interactive_input=False)
job.pop('diagnostic_log_baseline') # Old builds never persisted this; do not invent it.
@@ -148,3 +151,78 @@ def test_registered_cleanup_cannot_act_from_another_windows_user_session(tmp_pat
dict(owner_sid='current',session_id=1,force_user_confirmed=False))
assert sessions._request_close(row)['release_status']=='WAITING'
assert not messages and records
assert not state['observer_requests']
@pytest.mark.parametrize('obstacle',['','progress','stop','unknown'])
def test_one_legacy_intent_keeps_diagnostic_budget_across_no_ready_and_close(tmp_path,monkeypatch,obstacle):
from threading import Event
job,row,records,messages,state=registered_fixture(tmp_path,monkeypatch)
stop=Event();original=sessions._legacy_diagnostic_windows
def windows(bound):
value=original(bound)
if state['declined']:
if obstacle=='stop' and state['ticks']>=4:stop.set()
if state['ticks']<4 or obstacle=='progress':
value[0]['children'].append(dict(hwnd=123,**{'class':'msctls_progress32'},text='',visible=True))
if obstacle=='unknown':
value.append(dict(hwnd=999,pid=12,**{'class':'#32770'},text='Unknown action',children=[]))
return value
monkeypatch.setattr(sessions,'_legacy_diagnostic_windows',windows)
result=sessions._request_close(row,stop=stop)
assert state['observer_requests'] and state['observer_requests'][0][1]==[]
assert state['observer_requests'][0][2].get('observe_only',False) is False
if not obstacle:
assert result['release_status']=='RELEASED' and not records
assert messages==[(31,245),(100,16)] and 4<=state['ticks']<5
else:
assert result['release_status'] in ('WAITING','CANCELLED') and records
assert messages==[(31,245)]
assert state['ticks']<5 if obstacle=='stop' else 30<=state['ticks']<30.2
def test_known_no_then_changing_ready_snapshot_revalidates_within_same_intent(tmp_path,monkeypatch):
job,row,records,messages,state=registered_fixture(tmp_path,monkeypatch)
original=sessions._legacy_diagnostic_windows;reads=[]
def windows(bound):
value=original(bound)
if state['declined']:
reads.append(1)
if len(reads)==2:value[0]['children'].append(dict(hwnd=124,**{'class':'Afx:tool'},text='settling',parent=100))
return value
monkeypatch.setattr(sessions,'_legacy_diagnostic_windows',windows)
assert sessions._request_close(row)['release_status']=='RELEASED'
assert messages==[(31,245),(100,16)] and not records
def test_proved_native_cleanup_uses_its_budget_instead_of_metadata_inactivity(tmp_path,monkeypatch):
from threading import Event,Timer
from cbb_refresh_verify.operation_queue import BatchTaskContext
job,row,records,messages,state=registered_fixture(tmp_path,monkeypatch)
ready,done=Event(),Event();original=sessions._legacy_diagnostic_windows
def windows(bound):
if state['declined']:assert ready.wait(1)
return original(bound)
monkeypatch.setattr(sessions,'_legacy_diagnostic_windows',windows)
timer=Timer(.25,ready.set);timer.start()
context=BatchTaskContext(str(row['library']))
def cleanup():
try:return sessions._request_close(row)
finally:done.set()
try:
result=context.run(cleanup,timeout_seconds=.08)
assert result['release_status']=='RELEASED' and messages==[(31,245),(100,16)]
finally:
ready.set();timer.join(1);assert done.wait(2)
def test_registered_cleanup_preserves_frame_with_an_additional_mdi_document(tmp_path,monkeypatch):
job,row,records,messages,state=registered_fixture(tmp_path,monkeypatch)
original=sessions._legacy_diagnostic_windows
def windows(bound):
value=original(bound)
value[0]['children'].append(dict(hwnd=888,**{'class':'Afx:document'},text='Other',parent=101))
return value
monkeypatch.setattr(sessions,'_legacy_diagnostic_windows',windows)
assert sessions._request_close(row)['release_status']=='WAITING'
assert records and not messages