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
@@ -164,3 +164,19 @@ only WMI: no owners permits release, either native owner prevents it, and
|
||||
arbitrary query names remain rejected. Focused validation: 172 passed. Candidate
|
||||
`c823a4b` must be rebuilt with this correction before frozen/native validation;
|
||||
field recovery remains unverified.
|
||||
|
||||
Runtime fix round 3 uses the actual frozen-worker window capture. A single Afx
|
||||
shell titled exactly `iCDB Project Backup` now waits, before invocation only,
|
||||
for the exact project title within the existing deadline. Two owned-process
|
||||
input-indicator classes (`UAC_InputIndicatorOverlayWnd`, `UAC Input Indicator`)
|
||||
are ignored only with empty titles. Wrong/duplicate target windows, ambiguous
|
||||
shells, named/lookalike auxiliary windows, unknown prompts, missing Output and
|
||||
busy verdicts still retain the tool without unsafe commands. The native loading
|
||||
line `Checking if project is in use.` is excluded from busy evidence; the actual
|
||||
ownership verdict continues to control the busy gate.
|
||||
|
||||
Sanitized recorded-shape replay includes real shell children, RichEdit Output
|
||||
readback, startup-to-loaded transition and both input indicators before and
|
||||
after load. Focused validation: 189 passed (12.40s); compile and scoped diff
|
||||
checks passed. New source/frozen native validation and rebuilding the candidate
|
||||
remain coordinator work; these replay results do not establish field recovery.
|
||||
@@ -34,6 +34,8 @@ def repair_completed(diagnostic_text, database_text, *, native_backup):
|
||||
def classify_repair_evidence(diagnostic, database, restore, output):
|
||||
"""Classify this invocation only; an error alone does not prove native idle."""
|
||||
combined = '\n'.join((diagnostic, database, restore, output))
|
||||
# This observed loading-progress line precedes the actual ownership verdict.
|
||||
combined = re.sub(r'(?im)^\s*(?:\[[^\]\r\n]+\]\s*)?Checking if project is in use\.\s*$', '', combined)
|
||||
terminal_error = bool(re.search(r'Repair project error\s*\[[^\r\n]+\]', output, re.I))
|
||||
closed_error = ('Diagnostic: FINISH' in diagnostic and 'IC: Closing project' in database)
|
||||
if re.search(r'project is in use|database.*(?:in use|busy)|other clients are connected', combined, re.I):
|
||||
@@ -225,12 +227,20 @@ def repair_worker_main(job_path):
|
||||
output_baseline = None
|
||||
output = ''
|
||||
while process.poll() is None and time.monotonic()<deadline:
|
||||
windows = _windows(process.pid)
|
||||
windows = [w for w in _windows(process.pid) if not (
|
||||
w['title'] == '' and w['class'] in (
|
||||
'UAC_InputIndicatorOverlayWnd', 'UAC Input Indicator'))]
|
||||
mains = [w for w in windows if w['class'].startswith('Afx:')
|
||||
and w['title'].casefold() == ('iCDB Project Backup - '+str(project)).casefold()]
|
||||
main = mains[0] if len(mains) == 1 else None
|
||||
# The native Afx shell appears before it loads the requested PRJ.
|
||||
# Only a unique, exact generic shell before Repair may wait here;
|
||||
# it never authorizes a command or masks another target/window.
|
||||
shells = [w for w in windows if not invoked and w['class'].startswith('Afx:')
|
||||
and w['title'] == 'iCDB Project Backup']
|
||||
starting = shells[0] if len(shells) == 1 and not mains else None
|
||||
dialogs = [w for w in windows if w['class'] == '#32770']
|
||||
unknown = [w for w in windows if w is not main and w not in dialogs]
|
||||
unknown = [w for w in windows if w is not main and w is not starting and w not in dialogs]
|
||||
current_output = _native_output(windows)
|
||||
busy_before_start = (not invoked and current_output is not None
|
||||
and classify_repair_evidence('', '', '', current_output)['outcome'] == 'DATABASE_BUSY')
|
||||
|
||||
@@ -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