fix: cancel orphaned PCB before its license completes

This commit is contained in:
阿白叔 committed 2026-11-25 18:08:14 +08:00
1 parent e4fc37a291
commit becaf2e8e4
2 files changed
+29 -9

No files matched your search

+7 -1
View File
@@ -1150,7 +1150,7 @@ def finish_owned_idle_session(path, *, stop=None):
return target
return None
def startup_prompt():
from .failed_session import _startup_snapshot, _cancel_target, _tip_target
from .failed_session import _startup_snapshot, _cancel_target, _tip_target, _startup_license_cancel
snapshot = _process_windows({client['pid']}, include_hidden_documents=True)
windows = snapshot.get(client['pid'], [])
if (_window_error(snapshot, client['pid']) or not windows
@@ -1174,6 +1174,12 @@ def finish_owned_idle_session(path, *, stop=None):
for event in read('events.jsonl', lines=True)):
return None
return observed, tip.handle, 'tip', modal['hwnd']
if orphan_client is not None and all(w is modal or (
w['class'] in ('UAC_InputIndicatorOverlayWnd', 'UAC Input Indicator')
and not w.get('documents')) for w in windows):
license_cancel = _startup_license_cancel(observed)
if license_cancel is not None:
return observed, license_cancel.handle, 'license_cancel', modal['hwnd']
target = _cancel_target(observed)
if target is not None and (orphan_client is not None or target[0] == 'database_load_log'):
return observed, target[1].handle, target[0], modal['hwnd']
+22 -8
View File
@@ -179,7 +179,7 @@ def test_cancelled_prewrite_can_dismiss_exact_late_load_failure(qtbot, tmp_path,
assert (root/'result.json').read_bytes() == original
@pytest.mark.parametrize('obstacle', [None, 'tip', 'slow_tip', 'cancelled_tip', 'previously_dismissed_tip',
@pytest.mark.parametrize('obstacle', [None, 'tip', 'slow_tip', 'cancelled_tip', 'previously_dismissed_tip', 'license',
'read_write', 'unknown_prompt', 'save',
'uncertain_phase', 'live_supervisor', 'live_worker',
'wrong_pcb', 'possible_write', 'loaded', 'unproved_loaded'])
@@ -249,10 +249,11 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
monkeypatch.setattr(residual_sessions, '_recorded_process_exited',
lambda identity: obstacle != 'live_supervisor' and identity == supervisor)
if obstacle in ('tip', 'slow_tip', 'cancelled_tip', 'previously_dismissed_tip', 'read_write', 'unknown_prompt'):
frame = windows[0]
if obstacle in ('tip', 'slow_tip', 'cancelled_tip', 'previously_dismissed_tip', 'license', 'read_write', 'unknown_prompt'):
frame = windows.pop() if obstacle == 'license' else windows[0]
frame['enabled'] = False
windows.append(dict(hwnd=200, title='Tip of the Day' if obstacle.endswith('tip') else 'Expedition PCB',
title = {'license': ''}.get(obstacle, 'Tip of the Day' if obstacle.endswith('tip') else 'Expedition PCB')
windows.append(dict(hwnd=200, title=title,
desktop=job['desktop'], children=[], enabled=True, **{'class': '#32770'}))
def post(window, hwnd, pid, message):
@@ -262,6 +263,8 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
if hwnd == 201:
windows.pop()
frame['enabled'] = obstacle != 'slow_tip'
if obstacle == 'license':
state['native_alive'] = False
else:
state['native_alive'] = False
@@ -272,7 +275,18 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
monkeypatch.setattr(residual_sessions, '_dismiss_startup_tip', dismiss_tip)
monkeypatch.setattr(residual_sessions, '_post_window_message', post)
monkeypatch.setattr(residual_sessions, '_window_desktop', lambda *_: nullcontext())
monkeypatch.setattr(failed_session, '_startup_snapshot', lambda *_: 'exact shutdown prompt')
if obstacle == 'license':
from cbb_refresh_verify.dialog_models import ControlSnapshot, DialogPhase, WindowSnapshot
license_prompt = WindowSnapshot(200, 12, 'ExpeditionPCB.exe', 'pcb', '#32770', '',
DialogPhase.PCB_STARTING, (
ControlSnapshot(210, 5225, 'Button', 'Select the desired product license', enabled=True),
ControlSnapshot(211, 1522, 'GXWND', ''),
ControlSnapshot(212, 1, 'Button', 'OK', enabled=True),
ControlSnapshot(201, 2, 'Button', 'Cancel', enabled=True),
))
monkeypatch.setattr(failed_session, '_startup_snapshot', lambda *_: license_prompt)
else:
monkeypatch.setattr(failed_session, '_startup_snapshot', lambda *_: 'exact shutdown prompt')
monkeypatch.setattr(failed_session, '_tip_target', lambda _: SimpleNamespace(handle=201))
monkeypatch.setattr(failed_session, '_cancel_target', lambda _: ('read_write_access',
SimpleNamespace(handle=201)) if obstacle == 'read_write' else None)
@@ -289,9 +303,9 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
assert residual_sessions.finish_owned_idle_session(path)
assert state['posts'] == [(201, 12, 245), (100, 12, 16)]
return
assert recovered is (obstacle in (None, 'tip', 'cancelled_tip', 'read_write', 'loaded'))
expected_posts = [(201, 12, 245)] if obstacle in ('tip', 'cancelled_tip', 'read_write') else []
if recovered:
assert recovered is (obstacle in (None, 'tip', 'cancelled_tip', 'license', 'read_write', 'loaded'))
expected_posts = [(201, 12, 245)] if obstacle in ('tip', 'cancelled_tip', 'license', 'read_write') else []
if recovered and obstacle != 'license':
expected_posts.append((100, 12, 16))
assert state['posts'] == expected_posts
if recovered: