fix: bound native edit messages and identify empty IE infrastructure

This commit is contained in:
阿白叔 committed 2026-11-02 22:44:50 +08:00
1 parent bb98fe66dd
commit 8e486c1097
4 files changed
+132 -3

No files matched your search

+23
View File
@@ -230,3 +230,26 @@ def test_custom_prompt_must_disappear_before_main_close(tmp_path, monkeypatch):
result = failed_session.close_failed_startup(job, 12, timeout_seconds=1)
assert result['status'] == 'CLOSED' and ticks[0] > 0
assert len(messages) == 1
@pytest.mark.parametrize('obstacle', ['', 'title', 'area', 'children', 'near_class'])
def test_only_exact_empty_zero_area_childless_ie_infrastructure_is_benign(tmp_path, monkeypatch, obstacle):
import win32gui, win32con
job, records, messages = startup_fixture(tmp_path, monkeypatch)
monkeypatch.setattr(win32gui, 'EnumWindows', lambda fn, arg: [fn(hwnd, arg) for hwnd in (100, 200)])
monkeypatch.setattr(win32gui, 'GetClassName', lambda hwnd: 'Afx:main' if hwnd == 100 else
'Internet Explorer_Hidden_other' if obstacle == 'near_class' else 'Internet Explorer_Hidden')
monkeypatch.setattr(win32gui, 'GetWindowText', lambda hwnd: 'Expedition PCB' if hwnd == 100 else
'Active prompt' if obstacle == 'title' else '')
monkeypatch.setattr(win32gui, 'GetWindowRect', lambda hwnd: (0, 0, 100, 50) if obstacle == 'area' else (0, 0, 0, 0))
monkeypatch.setattr(win32gui, 'EnumChildWindows', lambda hwnd, fn, arg:
fn(201, arg) if hwnd == 200 and obstacle == 'children' else None)
result = failed_session.close_failed_startup(job, 12, timeout_seconds=0)
if obstacle:
assert result['status'] == 'RETAINED' and messages == []
assert result['unknown_windows'][0]['hwnd'] == 200
else:
assert result['status'] == 'CLOSED' and messages == [(100, win32con.WM_CLOSE)]
entry = result['benign_auxiliary_windows'][0]
assert entry['class'] == 'Internet Explorer_Hidden' and entry['rect'] == [0, 0, 0, 0]
assert entry['children'] == []
+58
View File
@@ -0,0 +1,58 @@
import ctypes
import json
from types import SimpleNamespace
import pytest
@pytest.mark.parametrize('expected,actual', [('S:\\source\\项目.prj', 'S:\\source\\项目.prj'), ('', '')])
def test_field_uses_bounded_set_and_remote_gettext_with_exact_readback(tmp_path, monkeypatch, expected, actual):
from cbb_refresh_verify import native_management as native
calls = []
class Send:
def __call__(self, hwnd, message, wparam, lparam, flags, timeout, result):
calls.append((hwnd, message, flags, timeout))
if message == 0x000C:
assert ctypes.wstring_at(lparam) == expected
result._obj.value = 1
elif message == 0x000D:
buffer = ctypes.create_unicode_buffer(actual)
ctypes.memmove(lparam, ctypes.addressof(buffer), ctypes.sizeof(buffer))
result._obj.value = len(actual)
else:
pytest.fail('unproven field message')
return 1
monkeypatch.setattr(native.ctypes, 'WinDLL', lambda *a, **k: SimpleNamespace(SendMessageTimeoutW=Send()))
assert native._set_probe_field(123, 1217, expected, tmp_path) == actual
assert [item[1] for item in calls] == [0x000C, 0x000D]
assert all(item[0] == 123 and item[2] == 0x0002 and 0 < item[3] <= 1000 for item in calls)
record = json.loads((tmp_path/'native-field-readback.jsonl').read_text(encoding='utf-8'))
assert record['expected'] == expected and record['actual'] == actual and record['matched']
@pytest.mark.parametrize('failure', ['empty', 'mismatch', 'set_timeout', 'read_timeout', 'set_rejected', 'truncated'])
def test_field_failure_is_recorded_before_rejection_without_foreground_fallback(tmp_path, monkeypatch, failure):
from cbb_refresh_verify import native_management as native
calls = []
class Send:
def __call__(self, hwnd, message, wparam, lparam, flags, timeout, result):
calls.append(message)
if message == 0x000C:
result._obj.value = 0 if failure == 'set_rejected' else 1
return 0 if failure == 'set_timeout' else 1
if failure == 'read_timeout': return 0
actual = '' if failure == 'empty' else 'other project'
buffer = ctypes.create_unicode_buffer(actual)
ctypes.memmove(lparam, ctypes.addressof(buffer), ctypes.sizeof(buffer))
result._obj.value = wparam - 1 if failure == 'truncated' else len(actual)
return 1
monkeypatch.setattr(native.ctypes, 'WinDLL', lambda *a, **k: SimpleNamespace(SendMessageTimeoutW=Send()))
with pytest.raises((RuntimeError, TimeoutError)):
native._set_probe_field(123, 1217, 'expected project', tmp_path)
record = json.loads((tmp_path/'native-field-readback.jsonl').read_text(encoding='utf-8'))
assert record['expected'] == 'expected project' and not record['matched']
assert record['control_id'] == 1217 and record['exception']['type']
if failure in ('empty', 'mismatch'):
assert record['actual'] == ('' if failure == 'empty' else 'other project')
if failure in ('set_timeout', 'set_rejected'):
assert calls == [0x000C]