fix: isolate ICDB checks and recover scoped native sessions
This commit is contained in:
1 parent
1acfbd6374
commit
1bd7589fef
82 files changed
+7770
-1583
No files matched your search
@@ -50,7 +50,7 @@ def test_failed_startup_normally_closes_owned_empty_pcb(tmp_path, monkeypatch, t
|
||||
|
||||
|
||||
@pytest.mark.parametrize('obstacle', ['baseline', 'wrong_path', 'path_prefix', 'desktop', 'address',
|
||||
'dialog', 'document_title', 'mdi_document', 'disabled', 'no_diagnosis'])
|
||||
'dialog', 'document_title', 'mdi_document', 'disabled'])
|
||||
def test_failed_startup_preserves_unconfirmed_or_busy_session(tmp_path, monkeypatch, obstacle):
|
||||
import win32gui
|
||||
from cbb_refresh_verify import native_repair_ui
|
||||
@@ -79,6 +79,97 @@ def test_failed_startup_preserves_unconfirmed_or_busy_session(tmp_path, monkeypa
|
||||
assert not messages
|
||||
|
||||
|
||||
def test_owned_empty_shell_closes_without_an_icdb_diagnosis(tmp_path, monkeypatch):
|
||||
job, records, messages = startup_fixture(tmp_path, monkeypatch)
|
||||
(tmp_path/'diagnostics/icdb-recovery.json').unlink()
|
||||
result = failed_session.close_failed_startup(job, 12, timeout_seconds=0)
|
||||
assert result['status'] == 'CLOSED' and not records and len(messages) == 1
|
||||
|
||||
|
||||
def read_write_fixture(tmp_path, monkeypatch):
|
||||
import win32gui, win32con
|
||||
from cbb_refresh_verify.post_repair_consent import PROMPT_TEXT
|
||||
job, records, messages = startup_fixture(tmp_path, monkeypatch)
|
||||
(tmp_path/'diagnostics/icdb-recovery.json').unlink()
|
||||
visible = {100, 200}
|
||||
classes = {100: 'Afx:main', 200: '#32770', 201: 'Button', 202: 'Button', 203: 'Static'}
|
||||
names = {100: 'Expedition PCB', 200: 'Expedition PCB', 201: 'Yes', 202: 'No', 203: PROMPT_TEXT}
|
||||
identifiers = {201: 6, 202: 7, 203: 65535}
|
||||
monkeypatch.setattr(win32gui, 'EnumWindows', lambda fn, arg: [fn(h, arg) for h in tuple(visible)])
|
||||
monkeypatch.setattr(win32gui, 'EnumChildWindows', lambda h, fn, arg:
|
||||
[fn(c, arg) for c in (201, 202, 203)] if h == 200 else None)
|
||||
monkeypatch.setattr(win32gui, 'GetClassName', classes.__getitem__)
|
||||
monkeypatch.setattr(win32gui, 'GetWindowText', names.__getitem__)
|
||||
monkeypatch.setattr(win32gui, 'GetDlgCtrlID', identifiers.__getitem__)
|
||||
monkeypatch.setattr(win32gui, 'IsWindowEnabled', lambda h: h != 100 or 200 not in visible)
|
||||
monkeypatch.setattr(win32gui, 'IsWindowVisible', lambda h: h in visible or h in identifiers)
|
||||
def post(hwnd, message, *_):
|
||||
messages.append((hwnd, message))
|
||||
if hwnd == 202 and message == win32con.BM_CLICK:
|
||||
visible.remove(200)
|
||||
elif hwnd == 100 and message == win32con.WM_CLOSE:
|
||||
records.clear()
|
||||
monkeypatch.setattr(win32gui, 'PostMessage', post)
|
||||
return job, records, messages, names, visible
|
||||
|
||||
|
||||
def test_captured_read_write_question_is_declined_and_own_empty_shell_exits(tmp_path, monkeypatch):
|
||||
import win32con
|
||||
job, records, messages, _, _ = read_write_fixture(tmp_path, monkeypatch)
|
||||
# A pre-existing address must not prevent cancelling our own attempted open.
|
||||
address = tmp_path/'database/cdbsvr/sAddress.adr'
|
||||
address.parent.mkdir(parents=True)
|
||||
address.write_text('existing foreign or stale address')
|
||||
result = failed_session.close_failed_startup(job, 12, timeout_seconds=0)
|
||||
assert result['status'] == 'CLOSED' and result['release']['safe_to_continue']
|
||||
assert messages == [(202, win32con.BM_CLICK), (100, win32con.WM_CLOSE)]
|
||||
assert not records and address.read_text() == 'existing foreign or stale address'
|
||||
assert result['cancelled_prompt'] == 'read_write_access'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('obstacle', ['text', 'foreign_pid', 'baseline', 'wrong_path', 'desktop', 'stuck'])
|
||||
def test_read_write_cancel_never_accepts_unconfirmed_or_unclosed_prompt(tmp_path, monkeypatch, obstacle):
|
||||
import win32gui, win32process, win32con
|
||||
from cbb_refresh_verify import native_repair_ui
|
||||
job, records, messages, names, _ = read_write_fixture(tmp_path, monkeypatch)
|
||||
if obstacle == 'text': names[203] += ' Different recovery operation.'
|
||||
if obstacle == 'foreign_pid':
|
||||
monkeypatch.setattr(win32process, 'GetWindowThreadProcessId', lambda h: (1, 99 if h == 200 else 12))
|
||||
if obstacle == 'wrong_path': records[0] = (12, records[0][1], 'other.pcb -ReusableCircuit', 11)
|
||||
if obstacle == 'desktop': monkeypatch.setattr(native_repair_ui, '_current_desktop_name', lambda: 'Default')
|
||||
if obstacle == 'stuck':
|
||||
monkeypatch.setattr(win32gui, 'PostMessage', lambda h, m, *_: messages.append((h, m)))
|
||||
result = failed_session.close_failed_startup(job, 12,
|
||||
baseline_pids=(12,) if obstacle == 'baseline' else (), timeout_seconds=0)
|
||||
assert result['status'] == 'RETAINED' and records
|
||||
assert messages == ([(202, win32con.BM_CLICK)] if obstacle == 'stuck' else [])
|
||||
|
||||
|
||||
def test_version_choice_is_cancelled_without_selecting_or_confirming_a_version(tmp_path, monkeypatch):
|
||||
import win32gui, win32con
|
||||
from test_pcb_version_choice import captured
|
||||
job, records, messages, _, visible = read_write_fixture(tmp_path, monkeypatch)
|
||||
snapshot = captured()
|
||||
children = [c for c in snapshot.controls if c.handle and c.handle != snapshot.hwnd]
|
||||
mapping = {300+i: c for i, c in enumerate(children)}
|
||||
monkeypatch.setattr(win32gui, 'EnumChildWindows', lambda h, fn, arg:
|
||||
[fn(c, arg) for c in mapping] if h == 200 else None)
|
||||
monkeypatch.setattr(win32gui, 'GetClassName', lambda h: mapping[h].class_name if h in mapping else
|
||||
'#32770' if h == 200 else 'Afx:main')
|
||||
monkeypatch.setattr(win32gui, 'GetWindowText', lambda h: mapping[h].name if h in mapping else
|
||||
'Database Restoration' if h == 200 else 'Expedition PCB')
|
||||
monkeypatch.setattr(win32gui, 'GetDlgCtrlID', lambda h: mapping[h].control_id)
|
||||
cancel = next(h for h, c in mapping.items() if c.control_id == 2)
|
||||
def post(h, m, *_):
|
||||
messages.append((h, m))
|
||||
if h == cancel: visible.remove(200)
|
||||
elif h == 100: records.clear()
|
||||
monkeypatch.setattr(win32gui, 'PostMessage', post)
|
||||
result = failed_session.close_failed_startup(job, 12, timeout_seconds=0)
|
||||
assert result['status'] == 'CLOSED' and result['cancelled_prompt'] == 'pcb_version_choice'
|
||||
assert messages == [(cancel, win32con.BM_CLICK), (100, win32con.WM_CLOSE)]
|
||||
|
||||
|
||||
def test_requested_close_without_exit_is_not_reported_closed(tmp_path, monkeypatch):
|
||||
import win32gui
|
||||
job, records, messages = startup_fixture(tmp_path, monkeypatch)
|
||||
@@ -169,13 +260,13 @@ def test_failed_startup_accepts_current_owned_database_failure_dialog(tmp_path,
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pid,phase', [(99, 'PCB_STARTING'), (12, 'SAVING')])
|
||||
def test_failed_startup_rejects_unrelated_failure_dialog(tmp_path, monkeypatch, pid, phase):
|
||||
def test_unrelated_failure_record_is_not_needed_to_close_own_empty_shell(tmp_path, monkeypatch, pid, phase):
|
||||
job, records, messages = startup_fixture(tmp_path, monkeypatch)
|
||||
(tmp_path/'diagnostics/icdb-recovery.json').unlink()
|
||||
(tmp_path/'dialogs.jsonl').write_text(json.dumps({
|
||||
'pid': pid, 'phase': phase, 'error_code': 'MENTOR_DATABASE_LOAD_FAILED'})+'\n')
|
||||
assert failed_session.close_failed_startup(job, 12, timeout_seconds=0)['status'] == 'RETAINED'
|
||||
assert not messages
|
||||
assert failed_session.close_failed_startup(job, 12, timeout_seconds=0)['status'] == 'CLOSED'
|
||||
assert len(messages) == 1 and not records
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exits', [True, False])
|
||||
|
||||
Reference in new issue
Block a user