fix: distinguish UIA dialog chrome from native consent controls

This commit is contained in:
阿白叔 committed 2026-11-03 09:43:16 +08:00
1 parent 9806ef8f66
commit 99a708b40c
2 files changed
+61 -3

No files matched your search

+45
View File
@@ -195,3 +195,48 @@ def test_agent_revalidates_real_window_before_single_button_message(monkeypatch,
def test_ordinary_rule_remains_hard_blocked_for_exact_recovery_prompt():
from cbb_refresh_verify.dialog_rules import decide
assert decide(snapshot(), ()).error_code == 'DATABASE_RECOVERY_REQUIRED'
def enriched_snapshot():
"""Sanitized actual aa-r2 merged Win32/UIA capture (only HWNDs changed)."""
from cbb_refresh_verify.dialog_models import ControlSnapshot
value = snapshot()
native = (replace(value.controls[0], name='是(Y)', automation_id='6', control_type='Button', patterns=('Invoke',)),
replace(value.controls[1], name='否(N)', automation_id='7', control_type='Button', patterns=('Invoke',)),
replace(value.controls[2], automation_id='20', control_type='Image'),
replace(value.controls[3], automation_id='65535', control_type='Text'))
return replace(value, controls=(*native,
ControlSnapshot(value.hwnd, 0, '#32770', 'Expedition PCB', control_type='Window', patterns=('Window',)),
ControlSnapshot(0, 0, '', '', control_type='TitleBar', patterns=('Value',)),
ControlSnapshot(0, 0, '', '关闭', control_type='Button', enabled=False, patterns=('Invoke',))))
@pytest.mark.parametrize('change', ['', 'extra_real_child', 'enabled_close', 'titlebar_text', 'other_self'])
def test_enriched_native_prompt_ignores_only_observed_uia_chrome(change):
from cbb_refresh_verify.post_repair_consent import exact_prompt
from cbb_refresh_verify.dialog_models import ControlSnapshot
value = enriched_snapshot()
if change == 'extra_real_child':
value = replace(value, controls=(*value.controls, ControlSnapshot(888, 0, '', '关闭',
control_type='Button', enabled=False, patterns=('Invoke',))))
if change == 'enabled_close': value = replace(value, controls=(*value.controls[:-1], replace(value.controls[-1], enabled=True)))
if change == 'titlebar_text': value = replace(value, controls=(*value.controls[:-2], replace(value.controls[-2], name='unexpected'), value.controls[-1]))
if change == 'other_self': value = replace(value, controls=(*value.controls[:4], replace(value.controls[4], handle=999), *value.controls[5:]))
assert exact_prompt(value) is (not change)
def test_enriched_prompt_still_reaches_live_native_child_check(monkeypatch):
import win32gui, win32process
from cbb_refresh_verify.post_repair_consent import validate_action_window
from cbb_refresh_verify import native_repair_ui
value = enriched_snapshot()
native = {c.handle: c for c in value.controls[:4]}
monkeypatch.setattr(native_repair_ui, '_current_desktop_name', lambda: 'CbbVerify_fixture')
monkeypatch.setattr(win32process, 'GetWindowThreadProcessId', lambda hwnd: (1, 20))
monkeypatch.setattr(win32gui, 'IsWindowVisible', lambda hwnd: True)
monkeypatch.setattr(win32gui, 'IsWindowEnabled', lambda hwnd: True)
monkeypatch.setattr(win32gui, 'GetClassName', lambda hwnd: value.window_class if hwnd == value.hwnd else native[hwnd].class_name)
monkeypatch.setattr(win32gui, 'GetWindowText', lambda hwnd: value.title if hwnd == value.hwnd else native[hwnd].name)
monkeypatch.setattr(win32gui, 'GetDlgCtrlID', lambda hwnd: native[hwnd].control_id)
monkeypatch.setattr(win32gui, 'EnumChildWindows', lambda hwnd, fn, arg: [fn(child, arg) for child in native])
validate_action_window(value, {'pid':20, 'desktop':'CbbVerify_fixture'})