fix: reconcile native save release and resume affected CBB batches

This commit is contained in:
阿白叔 committed 2026-11-24 13:34:56 +08:00
1 parent 443668aa4b
commit c76b755f13
16 files changed
+655 -36

No files matched your search

+70
View File
@@ -1036,6 +1036,76 @@ def test_saved_closed_without_cert_uses_bridge_and_never_reexecutes_verify(
assert ordering[-1] == 'failure_logs'
@pytest.mark.parametrize('config_name', ['CBB1.prj', 'PCB/pcb.prj'])
def test_native_save_waits_for_scoped_database_sharing_violation(tmp_path, monkeypatch, config_name):
from cbb_refresh_verify import file_probe
import win32con
import win32file
work = fixture(tmp_path)
config_path = work/config_name
database = config_path.parent/'ActualDatabase/icdb.dat'
if config_path.exists():
with config_path.open('a', encoding='utf-8') as config:
config.write('\nKEY iCDBDir "ActualDatabase"\n')
else:
config_path.write_text('KEY iCDBDir "ActualDatabase"\n', encoding='utf-8-sig')
database.parent.mkdir()
database.touch()
shared = tmp_path/'SymbolLibs/__ReusableBlocksSymb/icdb.dat'
shared.parent.mkdir(parents=True)
shared.touch()
locked = win32file.CreateFile(str(database), win32con.GENERIC_READ, 0, None,
win32con.OPEN_EXISTING, 0, None)
progress = []
released = False
class FinishedWorker:
desktop = None
returncode = 0
def __init__(self, command, *_args, **kwargs):
root = Path(command[-1]).parent
(root/'outcome.json').write_text('{"status":"PASS"}', encoding='utf-8')
(root/'save.log').write_text(
'SAVE_START\nSAVE_OK\nIS_SAVED\nCLOSE_OK\nQUIT_OK\n', encoding='utf-8')
def poll(self):
return 0
def close(self):
pass
def observe(event):
nonlocal released
progress.append(event)
if event['stage'] == 'post_save_release_pending':
# Model the original case: PCB is gone, the database is still held.
assert event['blocked_resources'] == [str(database)]
locked.Close()
released = True
def read_status(*_args):
assert released, 'Native status read started before iCDB released the database'
return BridgeResult('READY', 'IsVerifiedReuseBlock', 1)
monkeypatch.setattr('cbb_refresh_verify.desktop_worker.DesktopWorker', FinishedWorker)
monkeypatch.setattr('cbb_refresh_verify.verify_runner._cleanup_session_processes',
lambda *a, **kw: {'safe_to_continue': True, 'remaining_pids': []})
# Source-mode subprocess uses the same import root as the current test run.
monkeypatch.setenv('PYTHONPATH', str(Path(file_probe.__file__).parents[1]))
try:
result = run_verify(request(tmp_path), port_check=PORTS_OK, flag_reader=read_status, progress=observe)
finally:
if not released:
locked.Close()
assert result.status == 'PASS'
assert result.safe_to_continue
release = json.loads(result.evidence_path.with_name('session-release.json').read_text('utf-8'))
assert {str(shared), str(database)} <= set(release['database_release']['exclusive_files'])
assert sum(event['stage'] == 'post_save_release_pending' for event in progress) == 1
@pytest.mark.parametrize('detail, category', [
('PROJECT_INTEGRATION_FAILED: There were errors during packaging', 'MENTOR_PROJECT_INTEGRATION'),
('DATABASE_LOAD_FAILED: DataBase Load is being terminated with 2 errors', 'MENTOR_DATABASE_LOAD_FAILED'),