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

+62
View File
@@ -363,3 +363,65 @@ def test_shared_address_is_bound_to_shared_database_without_a_project_prj(tmp_pa
}]
assert str(address) in proof['binding_files']
assert str(database / 'icdb.dat') in proof['exclusive_files']
def test_shared_address_with_matching_native_shutdown_allows_release_and_open(tmp_path, monkeypatch):
from cbb_refresh_verify import library_lock, owner_probe, pcb_open_consent
library = tmp_path/'library/lib.lmc'
work = library.parent/'ReusableBlocksLP/A/Work'
project, pcb = work/'A.prj', work/'PCB/A.pcb'
shared = library.parent/'SymbolLibs/__ReusableBlocksSymb'
database = shared/'icdb.dat'
address = shared/'cdbsvr/sAddress.adr'
log = address.parent/'log/2026-11-24 10.51.10-16972/2026.11.24.txt'
for path in (library, work/'database/icdb.dat', pcb.parent/'Layout/LayoutDB.lyt', database, log):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(b'fixture')
project.write_text('KEY PCBDesignPath "PCB/A.pcb"\nKEY iCDBDir "database"\n')
pcb.write_text('KEY ProjectFile "../A.prj"\n')
guid = 'e3f4-cafd-6e7f-6e1b-f9bf-40b5-abf4-0b60-117c-d02d-bff6-3645'
adr = f'{guid}\n127.0.0.1\n10000\n1094\n2026-11-24 10.51.10-16972\n.\n'
address.write_text(adr)
lines = [
'iCDB Server ver.1.094, build:535943',
'Machine [LOCAL] User [operator] PID [16972]',
f'S: Project path [{shared}] on file system [NTFS]',
f'S: Server GUID [{guid}]',
'S: Wrote data to server address file',
'iCDB Server PI: Database closed',
f'Single file [{database}] closed with size [7 (0 kB)]',
f'AT: ERROR: Could not remove server address file [{address}]',
'S: STOP',
]
def write_log(events):
log.write_text('\n'.join(f'[2026.11.24 10:51:22] [0000m.11s.465ms] [0] {event}'
for event in events) + '\n')
write_log(lines)
monkeypatch.setattr(owner_probe, 'query_process_snapshot', lambda: [])
monkeypatch.setattr(owner_probe, 'query_owners', lambda *_: [])
release = library_lock.release_retained_library(library, tmp_path/'recovery', block_name='A')
assert release['status'] == 'RELEASE_CONFIRMED'
assert release['shared_shutdowns'][str(address)]['server_guid'] == guid
evidence = tmp_path/'open'
evidence.mkdir()
job = dict(root=str(evidence), lmc_file=str(library), block_name='A', project=str(project), pcb=str(pcb))
with pcb_open_consent.resource_guard(job, set(), require_complete_proof=True):
pass
proof = json.loads((evidence/'pcb-open-resource-proof.json').read_text('utf-8'))
assert proof['shared_shutdowns'] == release['shared_shutdowns']
assert address.read_text() == adr
assert database.read_bytes() == b'fixture'
import os
modified = log.stat().st_mtime_ns + 2_000_000_000
os.utime(database, ns=(modified, modified))
with pytest.raises(ValueError, match='SHARED_ICDB_INSPECTION_UNAVAILABLE'):
with pcb_open_consent.resource_guard(job, set(), require_complete_proof=True):
pytest.fail('an older server shutdown was accepted after a database change')
os.utime(database, ns=(modified, modified - 3_000_000_000))
write_log(lines[:-1]) # Database closed, but server shutdown is incomplete.
with pytest.raises(ValueError, match='SHARED_ICDB_INSPECTION_UNAVAILABLE'):
with pcb_open_consent.resource_guard(job, set(), require_complete_proof=True):
pytest.fail('incomplete native shutdown allowed read/write open')