Files
cbb-refresh-verify-795/tests/test_review414_open_and_queue.py
T

52 lines
2.4 KiB
Python

"""Review #414: native clicks and queue binding must outlive only their proofs."""
from contextlib import contextmanager
from types import SimpleNamespace
from test_post_repair_consent import snapshot
def test_readwrite_click_can_open_files_after_exclusive_probe_closes(tmp_path, monkeypatch):
import win32con, win32file
from cbb_refresh_verify import pcb_open_consent as consent
path=tmp_path/'icdb.dat'; path.write_bytes(b'database')
monkeypatch.setattr(consent,'validate_owner',lambda *_: {'target':'owned'})
@contextmanager
def guard(*_):
handle=win32file.CreateFile(str(path),win32con.GENERIC_READ,0,None,win32con.OPEN_EXISTING,0,None)
try:yield
finally:handle.Close()
monkeypatch.setattr(consent,'resource_guard',guard)
controller=consent.OpenController(dict(root=str(tmp_path),block_name='A',lmc_file='lib.lmc',
project='A.prj',pcb='A.pcb',desktop='CbbVerify_test'))
shown=[]; accepted=[]
def perform(*_):
handle=win32file.CreateFile(str(path),win32con.GENERIC_READ|win32con.GENERIC_WRITE,
0,None,win32con.OPEN_EXISTING,0,None)
handle.Close(); accepted.append(True)
return SimpleNamespace(error_code='',accepted_controls=(6,),detail='',channel='win32_button_click')
options=dict(target_pid=20,launcher_pid=10,worker_pid=5,show=shown.append,perform=perform)
controller.handle(snapshot(),(snapshot(),),**options)
shown[0].choose('continue')
result=controller.handle(snapshot(),(snapshot(),),**options)
assert not result.error_code,result.detail
assert accepted==[True]
def test_batch_queue_never_reads_library_widget_from_worker(qtbot, tmp_path, monkeypatch):
from threading import get_ident
from test_ui_filters import load_window
from cbb_refresh_verify.verify_runner import VerifyResult
gui_thread=get_ident(); violations=[]; calls=[]
window=load_window(qtbot,tmp_path,monkeypatch,
verifier=lambda req: calls.append(req.lmc_file) or VerifyResult('FAIL',safe_to_continue=True))
window.mentor_lmc_path=None
original=window.lmc_edit.text
def text():
if get_ident()!=gui_thread:violations.append('lmc_edit.text')
return original()
monkeypatch.setattr(window.lmc_edit,'text',text)
window._run(['Beta'])
qtbot.waitUntil(lambda:not window.busy,timeout=10000)
assert calls
assert not violations