fix: cancel owned prewrite PCB at the license selector
This commit is contained in:
1 parent
d45a29503d
commit
e4fc37a291
2 files changed
+59
No files matched your search
@@ -76,6 +76,20 @@ def _tip_target(snapshot):
|
||||
return target if target is not None and target.class_name == 'Button' else None
|
||||
|
||||
|
||||
def _startup_license_cancel(snapshot):
|
||||
if snapshot.window_class != '#32770' or snapshot.title:
|
||||
return None
|
||||
controls = snapshot.controls
|
||||
buttons = {(c.control_id, c.name) for c in controls if c.class_name == 'Button' and c.enabled}
|
||||
expected = {(5225, 'Select the desired product license'), (1, 'OK'), (2, 'Cancel')}
|
||||
if (buttons not in (expected, expected | {(57670, '')})
|
||||
or not any(c.control_id == 1522 and c.class_name == 'GXWND' for c in controls)):
|
||||
return None
|
||||
options = [c for c in controls if c.control_id == 2 and c.class_name == 'Button'
|
||||
and c.name == 'Cancel' and c.enabled]
|
||||
return options[0] if len(options) == 1 else None
|
||||
|
||||
|
||||
def _database_log_declined(root, pcb_pid):
|
||||
"""The supervisor can dismiss this exact failed-open question before cleanup."""
|
||||
from dataclasses import fields
|
||||
@@ -228,6 +242,7 @@ def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event:
|
||||
cancelled_open = _database_log_declined(root, pcb_pid)
|
||||
decline_owner = None
|
||||
dismissed_tips = set()
|
||||
license_cancelled = False
|
||||
close_handle = None
|
||||
close_identity = None
|
||||
close_frame = None
|
||||
@@ -346,6 +361,18 @@ def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event:
|
||||
break
|
||||
if dismissed:
|
||||
continue # Prove the Tip disappeared; it does not prove a cancelled open.
|
||||
if cancelled_prewrite and not license_cancelled:
|
||||
visible = [w for w in windows if win32gui.GetClassName(w) not in (
|
||||
'UAC_InputIndicatorOverlayWnd', 'UAC Input Indicator')]
|
||||
if len(visible) == 1 and win32gui.GetClassName(visible[0]) == '#32770':
|
||||
prompt = _startup_snapshot(visible[0], pcb_pid)
|
||||
cancel = _startup_license_cancel(prompt)
|
||||
if cancel is not None and _startup_snapshot(visible[0], pcb_pid) == prompt:
|
||||
cleanup_post(cancel.handle, win32con.BM_CLICK)
|
||||
license_cancelled = True
|
||||
emit(stage='startup_license_cancelled', pcb_pid=pcb_pid, hwnd=visible[0],
|
||||
control_id=cancel.control_id)
|
||||
continue
|
||||
if declined_hwnd is None:
|
||||
for hwnd in windows:
|
||||
if win32gui.GetClassName(hwnd) != '#32770':
|
||||
|
||||
@@ -33,6 +33,38 @@ def test_proved_ordinary_cancel_finishes_tip_to_loaded_without_annotation_or_sec
|
||||
assert messages==([(100,16),(31,245)] if prior_close else [(201,245),(31,245),(100,16)])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('obstacle', [None, 'unknown_control', 'other_window', 'write'])
|
||||
def test_cancel_at_owned_license_selector(tmp_path, monkeypatch, obstacle):
|
||||
import win32gui
|
||||
from cbb_refresh_verify.dialog_models import ControlSnapshot, DialogPhase, WindowSnapshot
|
||||
|
||||
job, records, messages, state = loaded_fixture(tmp_path, monkeypatch)
|
||||
ordinary_proof(job, tmp_path, job['diagnostic_log_baseline'])
|
||||
if obstacle == 'write':
|
||||
(tmp_path/'save.log').touch()
|
||||
controls = (ControlSnapshot(201, 5225, 'Button', 'Select the desired product license', enabled=True),
|
||||
ControlSnapshot(202, 1522, 'GXWND', ''),
|
||||
ControlSnapshot(203, 1, 'Button', 'OK', enabled=True),
|
||||
ControlSnapshot(204, 2, 'Button', 'Cancel' if obstacle != 'unknown_control' else 'Next',
|
||||
enabled=True))
|
||||
snapshot = WindowSnapshot(200, 12, 'ExpeditionPCB.exe', 'pcb', '#32770', '',
|
||||
DialogPhase.PCB_STARTING, controls)
|
||||
monkeypatch.setattr(failed_session, '_startup_snapshot', lambda *args: snapshot)
|
||||
monkeypatch.setattr(win32gui, 'EnumWindows', lambda fn, arg:
|
||||
[fn(hwnd, arg) for hwnd in ((200, 300) if obstacle == 'other_window' else (200,))])
|
||||
monkeypatch.setattr(win32gui, 'GetClassName', lambda hwnd: '#32770' if hwnd == 200 else 'Afx:other')
|
||||
monkeypatch.setattr(win32gui, 'GetWindowText', lambda hwnd: '')
|
||||
def post(hwnd, message, *_):
|
||||
messages.append((hwnd, message))
|
||||
records.clear()
|
||||
monkeypatch.setattr(win32gui, 'PostMessage', post)
|
||||
|
||||
result = failed_session.close_failed_startup(job, 12, timeout_seconds=1)
|
||||
|
||||
assert messages == ([(204, 245)] if obstacle is None else [])
|
||||
assert result['status'] == ('CLOSED' if obstacle is None else 'RETAINED')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('obstacle',['missing_ready','missing_cancel_phase','supervisor_write','worker_write',
|
||||
'missing_supervisor','missing_baseline','foreign_worker','foreign_target','save','missing_cancel','interactive','native_lm'])
|
||||
def test_ordinary_cleanup_requires_positive_bound_no_write_evidence(tmp_path,monkeypatch,obstacle):
|
||||
|
||||
Reference in new issue
Block a user