fix: complete legacy CBB import recovery and guard late native submission
This commit is contained in:
1 parent
d36b6bcad0
commit
7527800128
12 files changed
+326
-25
No files matched your search
@@ -7,6 +7,91 @@ import pytest
|
||||
ERROR = b'REUSE BLOCK: INFORMATION: Block\tError! Cannot copy iCDB base of Reusable Block project.\r\n'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('change', ['', 'target', 'pcb_present', 'question', 'extra_button', 'wrong_button', 'escape'])
|
||||
def test_editor_missing_pcb_notice_is_only_for_unrelated_incomplete_entries(tmp_path, change):
|
||||
from cbb_refresh_verify.native_add_failures import missing_other_pcb_notice
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
work = tmp_path/'ReusableBlocksLP/Missing/Work'
|
||||
(work/'PCB/Layout').mkdir(parents=True)
|
||||
(work/'Missing.prj').write_text('KEY PCBDesignPath "PCB/Missing.pcb"\n')
|
||||
text = ('The following Reusable Blocks do not contain PCB files and will not appear in the list of available reusable blocks:'
|
||||
'\n\n\tMissing')
|
||||
buttons = [{'hwnd':123, 'id':2, 'class':'Button', 'text':'确定', 'enabled':True}]
|
||||
target = 'Missing' if change == 'target' else 'Current'
|
||||
if change == 'pcb_present':
|
||||
(work/'PCB/Missing.pcb').touch(); (work/'PCB/Layout/LayoutDB.lyt').touch()
|
||||
if change == 'question': text += '\nOverwrite existing files?'
|
||||
if change == 'extra_button': buttons.append({**buttons[0], 'hwnd':456})
|
||||
if change == 'wrong_button': buttons[0]['text']='Yes'
|
||||
if change == 'escape': text=text.replace('\tMissing', '\t../other')
|
||||
result = missing_other_pcb_notice(library, target, 'Library Manager', text, buttons)
|
||||
assert result == ({'names':['Missing'], 'button':123} if not change else None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('reason', ['cancelled', 'supervisor_exited'])
|
||||
def test_add_cannot_submit_after_timeout_or_supervisor_exit(tmp_path, monkeypatch, reason):
|
||||
from cbb_refresh_verify.native_management import _require_add_supervisor
|
||||
import cbb_refresh_verify.library_lock as locks
|
||||
if reason == 'cancelled': (tmp_path/'cancel-native-add.signal').touch()
|
||||
monkeypatch.setattr(locks, '_supervisor_alive', lambda _:reason != 'supervisor_exited')
|
||||
with pytest.raises(RuntimeError, match='NATIVE_ADD_CANCELLED'):
|
||||
_require_add_supervisor({'supervisor_pid':123}, tmp_path)
|
||||
|
||||
|
||||
def test_add_timeout_publishes_cancellation_without_killing_native_owner(tmp_path, monkeypatch):
|
||||
import cbb_refresh_verify.native_management as native
|
||||
monkeypatch.setattr(native, '_retained_workers', [])
|
||||
class Running:
|
||||
def __init__(self, *args): pass
|
||||
def poll(self): return None
|
||||
def close(self): pytest.fail('live worker must not be killed')
|
||||
adapter=native.NativeManagementAdapter(worker_factory=Running)
|
||||
result=adapter._launch_worker({'operation':'add','desktop':'CbbManagement_test','timeout_seconds':0},tmp_path)
|
||||
assert not result['safe_to_continue'] and (tmp_path/'cancel-native-add.signal').exists()
|
||||
assert len(native._retained_workers)==1
|
||||
|
||||
|
||||
def test_cancellation_during_log_evidence_prevents_native_submit(tmp_path, monkeypatch):
|
||||
import os,sys
|
||||
from types import SimpleNamespace
|
||||
import win32gui,win32process
|
||||
import cbb_refresh_verify.native_management as native
|
||||
import cbb_refresh_verify.native_add_failures as failures
|
||||
from test_management import project
|
||||
source=project(tmp_path/'source',name='Block')
|
||||
root=tmp_path/'native-add';root.mkdir()
|
||||
library=root/'fixture/lib.lmc';library.parent.mkdir();library.touch()
|
||||
for path in (source,source.parent/'PCB/pcb.prj'):
|
||||
with path.open('a',encoding='utf-8') as stream:stream.write(f'KEY CentralLibrary "{library}"\n')
|
||||
state={'new':False,'posted':[]}
|
||||
tab=SimpleNamespace(window_text=lambda:'Logical - Physical',is_selected=lambda:True)
|
||||
monkeypatch.setitem(sys.modules,'pywinauto',SimpleNamespace(Desktop=lambda **k:SimpleNamespace(
|
||||
window=lambda **k:SimpleNamespace(descendants=lambda **k:[tab]))))
|
||||
monkeypatch.setattr(win32process,'GetWindowThreadProcessId',lambda h:(1,99))
|
||||
monkeypatch.setattr(win32gui,'IsWindowVisible',lambda h:True)
|
||||
monkeypatch.setattr(win32gui,'IsWindowEnabled',lambda h:True)
|
||||
monkeypatch.setattr(win32gui,'GetWindowText',lambda h:{100:'Reusable Blocks',200:'New Reusable Block'}[int(h)])
|
||||
monkeypatch.setattr(win32gui,'GetDlgItem',lambda h,c:110 if h==100 else 210 if c==1083 else c+1000)
|
||||
monkeypatch.setattr(win32gui,'GetClassName',lambda h:'Edit')
|
||||
monkeypatch.setattr(native,'_set_probe_field',lambda *a:None)
|
||||
def post(h,*args):
|
||||
state['posted'].append(h)
|
||||
if h==110:state['new']=True
|
||||
monkeypatch.setattr(win32gui,'PostMessage',post)
|
||||
original=native._write_json
|
||||
def write(path,data):
|
||||
original(path,data)
|
||||
if path.name=='native-add-log-baseline.json':(root/'cancel-native-add.signal').touch()
|
||||
monkeypatch.setattr(native,'_write_json',write)
|
||||
monkeypatch.setattr(failures,'observe_add_failure',lambda *a:(_ for _ in ()).throw(RuntimeError('unsafe OK posted')))
|
||||
desktop=SimpleNamespace(EnumDesktopWindows=lambda:[100,200] if state['new'] else [100])
|
||||
job={'operation':'probe_create_add','source':str(source),'library':str(library),
|
||||
'name':'Block','timeout_seconds':5,'supervisor_pid':os.getpid()}
|
||||
with pytest.raises(RuntimeError,match='NATIVE_ADD_CANCELLED'):
|
||||
native._probe_add_dialog_impl(SimpleNamespace(OnReusableBlocksEditor=lambda:None),job,desktop,{99},root)
|
||||
assert state['posted']==[110]
|
||||
|
||||
|
||||
def test_copy_failure_log_must_be_new_and_match_current_block(tmp_path):
|
||||
from cbb_refresh_verify.native_add_failures import snapshot_add_log, fresh_add_failure
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
|
||||
Reference in new issue
Block a user