fix: wait for native repair project shell and ignore known input indicators
This commit is contained in:
1 parent
b90a9bbfab
commit
877e3b4c76
4 files changed
+156
-2
No files matched your search
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"source": "Frozen b90a9bb native startup capture: no-history-repair/repair-result.json; HWNDs sanitized. Auxiliary classes/empty titles from coordinator's readback of the same owned native process.",
|
||||
"startup_shell": {
|
||||
"hwnd": 100,
|
||||
"title": "iCDB Project Backup",
|
||||
"class": "Afx:00400000:b:00010003:00000006:5F991B0D",
|
||||
"enabled": true,
|
||||
"children": [
|
||||
{"hwnd": 401, "text": "", "class": "BCGPSlider:400000:8:10003:10", "id": -1, "enabled": true},
|
||||
{"hwnd": 402, "text": "Output ", "class": "BCGPControlBar:400000:8:10003:10", "id": 313, "enabled": true},
|
||||
{"hwnd": 403, "text": "", "class": "#32770", "id": 0, "enabled": true},
|
||||
{"hwnd": 400, "text": "", "class": "RichEdit20A", "id": 1002, "enabled": true},
|
||||
{"hwnd": 404, "text": "", "class": "BCGPStatusBar:400000:8:10003:10", "id": 59393, "enabled": true},
|
||||
{"hwnd": 405, "text": "", "class": "BCGPDockBar:400000:8:10003:10", "id": 59419, "enabled": true},
|
||||
{"hwnd": 406, "text": "Standard", "class": "BCGPToolBar:400000:8:10003:10", "id": 59392, "enabled": true},
|
||||
{"hwnd": 407, "text": "Menu Bar", "class": "BCGPToolBar:400000:8:10003:10", "id": 59398, "enabled": true},
|
||||
{"hwnd": 408, "text": "", "class": "#32770", "id": 59648, "enabled": true}
|
||||
]
|
||||
},
|
||||
"auxiliary_windows": [
|
||||
{"hwnd": 500, "title": "", "class": "UAC_InputIndicatorOverlayWnd", "enabled": true, "children": []},
|
||||
{"hwnd": 501, "title": "", "class": "UAC Input Indicator", "enabled": true, "children": []}
|
||||
],
|
||||
"loaded_title_prefix": "iCDB Project Backup - ",
|
||||
"loaded_output": "Checking if project is in use.\r\nProject is not in use. Full iCDB Project Backup's functionality is available.\r\n"
|
||||
}
|
||||
@@ -854,3 +854,105 @@ def test_repair_process_queries_still_reject_arbitrary_input(monkeypatch, name):
|
||||
monkeypatch.setattr(win32com.client, 'GetObject', lambda *a: pytest.fail('Unsupported name reached WMI'))
|
||||
with pytest.raises(ValueError, match='Unsupported process query'):
|
||||
_process_details(name)
|
||||
|
||||
|
||||
def real_shape_repair_fixture(tmp_path, monkeypatch, scenario, window_state='loads'):
|
||||
"""Replay recorded UI structures through the real bounded Output reader."""
|
||||
from copy import deepcopy
|
||||
from types import SimpleNamespace
|
||||
from cbb_refresh_verify import native_repair_ui
|
||||
actual_output_reader = native_repair_ui._native_output
|
||||
ui, root, job, actions = repair_worker_fixture(tmp_path, monkeypatch, scenario)
|
||||
capture = json.loads((Path(__file__).parent/'fixtures/icdb-repair-startup-windows-sanitized.json').read_text('utf-8'))
|
||||
project = json.loads(job.read_text('utf-8'))['project']
|
||||
original_windows, operation_output = ui._windows, ui._native_output
|
||||
polls = []
|
||||
current = {'loading': True}
|
||||
def windows(pid):
|
||||
polls.append(ui.time.monotonic())
|
||||
loading = len(polls) <= 2 or window_state == 'shell_stuck'
|
||||
if loading: assert not actions, 'Startup shell must never receive a command'
|
||||
original = original_windows(pid)
|
||||
main = deepcopy(capture['startup_shell'])
|
||||
current['loading'] = loading
|
||||
if not loading:
|
||||
main['title'] = capture['loaded_title_prefix']+project
|
||||
if window_state == 'wrong_target': main['title'] = capture['loaded_title_prefix']+'C:\\Other\\other.prj'
|
||||
if window_state == 'shell_after_invoke' and actions: main['title'] = 'iCDB Project Backup'
|
||||
auxiliary = deepcopy(capture['auxiliary_windows'])
|
||||
if window_state == 'named_aux': auxiliary[0]['title'] = 'Unrecognized prompt'
|
||||
if window_state == 'lookalike_aux': auxiliary[0]['class'] += '.Other'
|
||||
if window_state == 'duplicate_shell' and loading:
|
||||
auxiliary.append({**deepcopy(main), 'hwnd': 101})
|
||||
if window_state == 'duplicate_target' and not loading:
|
||||
auxiliary.append({**deepcopy(main), 'hwnd': 101})
|
||||
return [main, *original[1:], *auxiliary]
|
||||
class Readback:
|
||||
def __call__(self, hwnd, message, length, buffer, flags, timeout, copied):
|
||||
assert hwnd == 400
|
||||
if window_state == 'missing_output': return 0
|
||||
text = '' if current['loading'] else capture['loaded_output']+operation_output([])
|
||||
if window_state == 'busy_loading': text = 'Project is in use. Full functionality is unavailable.'
|
||||
ui.ctypes.cast(buffer, ui.ctypes.POINTER(ui.ctypes.c_wchar * length)).contents.value = text
|
||||
copied._obj.value = len(text)
|
||||
return 1
|
||||
monkeypatch.setattr(ui, '_windows', windows)
|
||||
monkeypatch.setattr(ui.ctypes, 'WinDLL', lambda *a, **kw: SimpleNamespace(SendMessageTimeoutW=Readback()))
|
||||
monkeypatch.setattr(ui, '_native_output', actual_output_reader)
|
||||
return ui, root, job, actions, polls
|
||||
|
||||
|
||||
@pytest.mark.parametrize('scenario,expected,closed', [
|
||||
('failed', 'MISSING_HEALTHY_BACKUP', True), ('success', 'REPAIRED', True),
|
||||
('restore', 'RESTORED_REVIEW_REQUIRED', True), ('busy', 'DATABASE_BUSY', False),
|
||||
('unknown', 'UNKNOWN_DIALOG', False),
|
||||
])
|
||||
def test_recorded_startup_shell_loads_target_with_input_indicator_windows(
|
||||
tmp_path, monkeypatch, scenario, expected, closed):
|
||||
import win32con
|
||||
ui, root, job, actions, polls = real_shape_repair_fixture(tmp_path, monkeypatch, scenario)
|
||||
assert ui.repair_worker_main(job) == (0 if scenario == 'success' else 1)
|
||||
result = json.loads((root/'repair-result.json').read_text('utf-8'))
|
||||
assert len(polls) >= 4 and polls[2] >= .4
|
||||
assert result['status'] == expected
|
||||
assert actions[:2] == [(100, win32con.WM_COMMAND), (201, win32con.BM_CLICK)]
|
||||
assert ((100, win32con.WM_CLOSE) in actions) is closed
|
||||
assert result['release']['safe_to_continue'] is closed
|
||||
assert 'Project is not in use' in json.loads((root/'native-output.json').read_text('utf-8'))['baseline']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('state,expected', [
|
||||
('shell_stuck', 'TIMEOUT_UNRELEASED'), ('wrong_target', 'UNKNOWN_DIALOG'),
|
||||
('duplicate_shell', 'UNKNOWN_DIALOG'), ('duplicate_target', 'UNKNOWN_DIALOG'),
|
||||
('named_aux', 'UNKNOWN_DIALOG'), ('lookalike_aux', 'UNKNOWN_DIALOG'),
|
||||
('missing_output', 'TIMEOUT_UNRELEASED'), ('busy_loading', 'DATABASE_BUSY'),
|
||||
])
|
||||
def test_recorded_startup_shape_retains_unconfirmed_or_unknown_state(tmp_path, monkeypatch, state, expected):
|
||||
ui, root, job, actions, polls = real_shape_repair_fixture(tmp_path, monkeypatch, 'failed', state)
|
||||
assert ui.repair_worker_main(job) == 1
|
||||
result = json.loads((root/'repair-result.json').read_text('utf-8'))
|
||||
assert result['status'] == expected
|
||||
assert actions == []
|
||||
assert result['release']['safe_to_continue'] is False
|
||||
|
||||
|
||||
def test_generic_shell_after_invocation_is_not_a_startup_exception(tmp_path, monkeypatch):
|
||||
import win32con
|
||||
ui, root, job, actions, polls = real_shape_repair_fixture(tmp_path, monkeypatch, 'failed', 'shell_after_invoke')
|
||||
assert ui.repair_worker_main(job) == 1
|
||||
result = json.loads((root/'repair-result.json').read_text('utf-8'))
|
||||
assert result['status'] == 'UNKNOWN_DIALOG'
|
||||
assert actions == [(100, win32con.WM_COMMAND)]
|
||||
assert result['release']['safe_to_continue'] is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('verdict,expected', [
|
||||
('', 'UNCONFIRMED'),
|
||||
("Project is not in use. Full iCDB Project Backup's functionality is available.", 'UNCONFIRMED'),
|
||||
('Project is in use. Full functionality is unavailable.', 'DATABASE_BUSY'),
|
||||
])
|
||||
def test_native_usage_check_progress_waits_for_actual_busy_verdict(verdict, expected):
|
||||
from cbb_refresh_verify.native_repair_ui import classify_repair_evidence
|
||||
output = '[2026-11-02 12:00:00] Checking if project is in use.\r\n'
|
||||
output += '[2026-11-02 12:00:00] '+verdict
|
||||
assert classify_repair_evidence('', '', '', output)['outcome'] == expected
|
||||
Reference in new issue
Block a user