fix: retain uncertain fixture owners and reject source overlap
This commit is contained in:
1 parent
b97556dcc1
commit
ca84bce24f
3 files changed
+74
-2
No files matched your search
@@ -89,6 +89,67 @@ def test_fixture_metadata_without_current_thread_lease_cannot_stage_source(tmp_p
|
||||
assert not (root/'source').exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('outcome', ['unsafe', 'exception', 'safe'])
|
||||
def test_owned_fixture_retains_default_caller_lease_until_native_release(tmp_path, monkeypatch, outcome):
|
||||
import cbb_refresh_verify.native_management as native
|
||||
from cbb_refresh_verify.management import ManagementRequest
|
||||
from cbb_refresh_verify.library_lock import LibraryLock, LibraryBusy, blocker_path, _owners, _guard
|
||||
library = tmp_path/'native-add/fixture/mentor_lib.lmc'
|
||||
library.parent.mkdir(parents=True); library.write_bytes(b'fixture')
|
||||
source = tmp_path/'original/Source.prj'; source.parent.mkdir(); source.write_bytes(b'source')
|
||||
(tmp_path/'probe-owner.json').write_text(json.dumps({'library': str(library), 'token': 'owned'}), encoding='utf-8')
|
||||
adapter = native.NativeManagementAdapter(mentor_home=tmp_path)
|
||||
monkeypatch.setattr(adapter, 'route_capabilities', lambda: {'add': native.Capability(True, 'ready')})
|
||||
monkeypatch.setattr(native, 'engineering_identity', lambda _: {'source': 'bytes'})
|
||||
def launch(*args):
|
||||
if outcome == 'exception': raise OSError('worker result lost after dispatch')
|
||||
return {'success': outcome == 'safe', 'safe_to_continue': outcome == 'safe'}
|
||||
monkeypatch.setattr(adapter, '_launch_worker', launch)
|
||||
lease = LibraryLock(library)
|
||||
try:
|
||||
with lease:
|
||||
if outcome == 'exception':
|
||||
with pytest.raises(OSError, match='after dispatch'):
|
||||
adapter.add_owned_fixture(ManagementRequest('add', library, 'Block', source=source),
|
||||
tmp_path/'add', probe_token='owned')
|
||||
else:
|
||||
adapter.add_owned_fixture(ManagementRequest('add', library, 'Block', source=source),
|
||||
tmp_path/'add', probe_token='owned')
|
||||
assert blocker_path(library).exists() is (outcome != 'safe')
|
||||
if outcome != 'safe':
|
||||
with pytest.raises(LibraryBusy):
|
||||
with LibraryLock(library): pass
|
||||
import win32file, win32con, pywintypes
|
||||
with pytest.raises(pywintypes.error):
|
||||
win32file.CreateFile(str(lease.path), win32con.GENERIC_READ, 0, None,
|
||||
win32con.OPEN_EXISTING, 0, None)
|
||||
else:
|
||||
with LibraryLock(library): pass
|
||||
finally:
|
||||
# Only the file-only fake worker above ran; release its test lease.
|
||||
with _guard:
|
||||
owner = _owners.pop(lease.key, None)
|
||||
if owner: owner['handle'].Close()
|
||||
blocker_path(library).unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_fixture_nested_inside_source_tree_rejected_before_staging(tmp_path):
|
||||
import cbb_refresh_verify.native_management as native
|
||||
from cbb_refresh_verify.library_lock import LibraryLock
|
||||
library = tmp_path/'native-add/fixture/mentor_lib.lmc'
|
||||
library.parent.mkdir(parents=True); library.write_bytes(b'fixture')
|
||||
source = tmp_path/'native-add/Source.prj'; source.write_bytes(b'original source')
|
||||
(tmp_path/'probe-owner.json').write_text(json.dumps({'library': str(library), 'token': 'owned'}), encoding='utf-8')
|
||||
root = tmp_path/'add'; root.mkdir()
|
||||
with LibraryLock(library):
|
||||
with pytest.raises(ValueError, match='independent'):
|
||||
native.prepare_owned_fixture_add({'library': str(library), 'source': str(source),
|
||||
'name': 'Block', 'partition': 'Logical-Physical', 'source_identity': {},
|
||||
'probe_token': 'owned'}, root)
|
||||
assert source.read_bytes() == b'original source' and library.read_bytes() == b'fixture'
|
||||
assert not (root/'source').exists()
|
||||
|
||||
|
||||
def test_add_route_readiness_is_separate_from_conservative_capability_gate(tmp_path, monkeypatch):
|
||||
import hashlib
|
||||
import cbb_refresh_verify.native_management as native
|
||||
|
||||
Reference in new issue
Block a user