fix: isolate ICDB checks and recover scoped native sessions
This commit is contained in:
1 parent
1acfbd6374
commit
1bd7589fef
82 files changed
+7770
-1583
No files matched your search
@@ -116,3 +116,83 @@ def test_successful_export_clears_only_its_bound_guard_after_fresh_copy_proof(tm
|
||||
finish_export_analysis(library, token)
|
||||
assert 'export_analysis' not in json.loads(marker.read_text())
|
||||
assert not marker.exists()
|
||||
|
||||
|
||||
def test_unrelated_same_name_server_does_not_prevent_copy_release(export_case, monkeypatch):
|
||||
import cbb_refresh_verify.native_engineering_identity as identity
|
||||
from cbb_refresh_verify.native_export_guard import prove_export_copies_released
|
||||
library, root, *_ = export_case
|
||||
monkeypatch.setattr(identity, '_process_snapshot', lambda: [
|
||||
{'pid': 777777, 'name': 'iCDBNetServer.exe', 'parent': 0, 'executable': 'native',
|
||||
'command': 'iCDBNetServer.exe C:\\other\\database'}])
|
||||
with prove_export_copies_released(library) as copies:
|
||||
assert copies == [str(root/'project')]
|
||||
|
||||
|
||||
def test_retained_export_registry_is_scoped_to_its_library(tmp_path, monkeypatch):
|
||||
import cbb_refresh_verify.native_engineering_identity as identity
|
||||
from cbb_refresh_verify.native_export_guard import assert_retained_exports_idle
|
||||
from cbb_refresh_verify.library_lock import LibraryBusy
|
||||
library_a, library_b = tmp_path/'a.lmc', tmp_path/'b.lmc'
|
||||
monkeypatch.setattr(identity, '_retained_exports', [
|
||||
(SimpleNamespace(poll=lambda: None), {}, {'library': str(library_a.resolve())})])
|
||||
assert_retained_exports_idle(library_b)
|
||||
with pytest.raises(LibraryBusy): assert_retained_exports_idle(library_a)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('created,blocked', [('new-process', False), ('original-process', True)])
|
||||
def test_recorded_export_pid_reuse_requires_matching_creation_identity(export_case, monkeypatch, created, blocked):
|
||||
import cbb_refresh_verify.native_engineering_identity as identity
|
||||
import cbb_refresh_verify.library_lock as locks
|
||||
from cbb_refresh_verify.native_export_guard import prove_export_copies_released
|
||||
library, root, *_ = export_case
|
||||
path = root/'ascii-process.json'
|
||||
record = json.loads(path.read_text('utf-8'))
|
||||
record['process_identities'] = [{'pid': 123456, 'created': 'original-process', 'executable': 'native'}]
|
||||
path.write_text(json.dumps(record), encoding='utf-8')
|
||||
monkeypatch.setattr(locks, '_supervisor_alive', lambda _: True)
|
||||
monkeypatch.setattr(identity, '_process_snapshot', lambda: [
|
||||
{'pid': 123456, 'name': 'unrelated.exe', 'parent': 0,
|
||||
'executable': 'native', 'created': created, 'command': ''}])
|
||||
if blocked:
|
||||
with pytest.raises(locks.LibraryBusy):
|
||||
with prove_export_copies_released(library): pass
|
||||
else:
|
||||
with prove_export_copies_released(library): pass
|
||||
|
||||
|
||||
@pytest.mark.parametrize('active', [False, True])
|
||||
def test_unknown_checkpoint_requires_explicit_full_proof_and_no_native_export_owner(tmp_path, monkeypatch, active):
|
||||
import cbb_refresh_verify.native_engineering_identity as identity
|
||||
import cbb_refresh_verify.library_lock as locks
|
||||
from cbb_refresh_verify.native_export_guard import prove_export_copies_released
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
locks.blocker_path(library).write_text('{torn metadata')
|
||||
monkeypatch.setattr(identity, '_retained_exports', [])
|
||||
monkeypatch.setattr(identity, '_process_snapshot', lambda: [
|
||||
{'pid': 12345, 'name': 'iCDBNetServer.exe', 'parent': 0}] if active else [])
|
||||
with pytest.raises(locks.LibraryBusy):
|
||||
with prove_export_copies_released(library): pass
|
||||
if active:
|
||||
with pytest.raises(locks.LibraryBusy):
|
||||
with prove_export_copies_released(library, allow_unknown_checkpoint=True): pass
|
||||
else:
|
||||
with prove_export_copies_released(library, allow_unknown_checkpoint=True) as copies:
|
||||
assert copies == []
|
||||
assert locks.blocker_path(library).read_text() == '{torn metadata'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('no_start_proven', [False, True])
|
||||
def test_missing_pid_requires_bound_no_start_evidence(export_case, no_start_proven):
|
||||
from cbb_refresh_verify.native_export_guard import prove_export_copies_released
|
||||
from cbb_refresh_verify.library_lock import LibraryBusy
|
||||
library, root, *_ = export_case
|
||||
record = {'success': False, 'safe_to_continue': True}
|
||||
if no_start_proven: record['native_started'] = False
|
||||
(root/'ascii-process.json').write_text(json.dumps(record), encoding='utf-8')
|
||||
(root/'export-launch.json').write_text(json.dumps({'started': not no_start_proven}), encoding='utf-8')
|
||||
if no_start_proven:
|
||||
with prove_export_copies_released(library): pass
|
||||
else:
|
||||
with pytest.raises(LibraryBusy):
|
||||
with prove_export_copies_released(library): pass
|
||||
Reference in new issue
Block a user