fix: preserve engineering identity in scoped runtime exclusions
This commit is contained in:
1 parent
29c154d2ca
commit
3415e010ff
4 files changed
+288
-12
No files matched your search
@@ -280,3 +280,49 @@ def test_source_address_record_is_rechecked_after_validation(recovery_files):
|
||||
assert 'ownership' in result.stderr
|
||||
assert address.read_bytes() == b'live owner'
|
||||
assert (original.parent/'database/icdb.dat').read_bytes() == b'damaged'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', ['Logs', 'tEmP', 'bAcKuP', 'Output'])
|
||||
@pytest.mark.parametrize('role', ['Work', 'Cert'])
|
||||
def test_cbb_names_matching_runtime_labels_do_not_hide_target_conflicts(tmp_path, monkeypatch, name, role):
|
||||
from cbb_refresh_verify.backup_recovery import recover_from_backup
|
||||
monkeypatch.setattr(Path, 'home', lambda: tmp_path/'profile')
|
||||
library = tmp_path/'target/target.lmc'
|
||||
original = project(library.parent/f'ReusableBlocksLP/{name}/Work', name, b'damaged')
|
||||
library.write_bytes(b'library')
|
||||
source = project(tmp_path/'backup/Work', name, b'healthy')
|
||||
request = VerifyRequest(library, name, tmp_path/'evidence')
|
||||
conflict = original.parent.parent/role/'database/icdb.dat'
|
||||
conflict.parent.mkdir(parents=True, exist_ok=True)
|
||||
if role == 'Cert':
|
||||
conflict.write_bytes(b'cert before')
|
||||
calls = []
|
||||
def verify(*args, **kwargs):
|
||||
calls.append(args)
|
||||
conflict.write_bytes(b'concurrent target edit')
|
||||
return VerifyResult('PASS', library_flag='GREEN')
|
||||
result = recover_from_backup(request, source, verifier=verify, idle_check=lambda *_: None)
|
||||
assert result.status == 'BLOCKED'
|
||||
assert len(calls) == 1
|
||||
assert conflict.read_bytes() == b'concurrent target edit'
|
||||
assert not list(original.parent.parent.glob('Work.before-restore-*'))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('relative', ['SymbolLibs/temp/icdb.dat', 'SymbolLibs/Temp_a/device.sym',
|
||||
'SharedDependency/hdl/Logs/design.v'])
|
||||
def test_shared_partition_engineering_conflicts_block_install(recovery_files, relative):
|
||||
from cbb_refresh_verify.backup_recovery import recover_from_backup
|
||||
request, original, source = recovery_files
|
||||
conflict = request.lmc_file.parent/relative
|
||||
conflict.parent.mkdir(parents=True, exist_ok=True)
|
||||
conflict.write_bytes(b'shared before')
|
||||
calls = []
|
||||
def verify(*args, **kwargs):
|
||||
calls.append(args)
|
||||
conflict.write_bytes(b'concurrent shared edit')
|
||||
return VerifyResult('PASS', library_flag='GREEN')
|
||||
result = recover_from_backup(request, source, verifier=verify, idle_check=lambda *_: None)
|
||||
assert result.status == 'BLOCKED'
|
||||
assert len(calls) == 1
|
||||
assert (original.parent/'database/icdb.dat').read_bytes() == b'damaged'
|
||||
assert conflict.read_bytes() == b'concurrent shared edit'
|
||||
@@ -213,3 +213,123 @@ def test_only_primary_paths_are_read_for_sha256_and_manifest_is_relocatable(tmp_
|
||||
assert recovery._manifest(source, scope=scope) == manifest
|
||||
assert recovery._manifest(destination, scope=scope) == manifest
|
||||
assert {p.relative_to(destination).as_posix() for p in destination.rglob('*') if p.is_file()} == primary | excluded
|
||||
|
||||
|
||||
@pytest.mark.parametrize('block', ['Logs', 'lOgS', 'Temp', 'tEmP', 'Backup', 'bAcKuP', 'Output', 'rEpOrT',
|
||||
'Log Files', 'ProjectBackup', 'Work.before-restore-engineering'])
|
||||
@pytest.mark.parametrize('role', ['Work', 'Cert'])
|
||||
def test_structural_cbb_identity_is_primary_in_semantic_and_copy_manifests(tmp_path, block, role):
|
||||
from cbb_refresh_verify.scoped_manifest import ManifestScope
|
||||
scope = ManifestScope.library(block, 'target.lmc')
|
||||
source, destination = tmp_path/'source', tmp_path/'destination'
|
||||
relative = f'ReusableBlocksLP/{block}/{role}/database/icdb.dat'
|
||||
primary = put(source, relative)
|
||||
runtime = f'ReusableBlocksLP/{block}/{role}/logs/session.txt'
|
||||
put(source, runtime)
|
||||
before = recovery._copy_verified(source, destination, scope=scope)
|
||||
assert set(before['files']) == {relative}
|
||||
assert (destination/runtime).read_bytes() == b'engineering'
|
||||
assert recovery._manifest(source, scope=scope) == before
|
||||
primary.write_bytes(b'concurrent primary edit')
|
||||
assert recovery._manifest(source, scope=scope) != before
|
||||
|
||||
|
||||
@pytest.mark.parametrize('relative', [
|
||||
'SymbolLibs/temp/icdb.dat', 'SymbolLibs/Temp_a/device.sym',
|
||||
'SymbolLibs/Logs/device.sym', 'SymbolLibs/BACKUP/device.sym',
|
||||
'SymbolLibs/temp/cdbsvr/persistent.bin',
|
||||
'ReusableBlocksLP/A/Work/hdl/Logs/design.v',
|
||||
'ReusableBlocksLP/A/Cert/hdl/bAcKuP/design.v',
|
||||
'SymbolLibs/temp/hdl/Backup/design.v', 'SharedDependency/hdl/Logs/design.v',
|
||||
])
|
||||
def test_library_engineering_partition_names_are_not_runtime_categories(tmp_path, relative):
|
||||
from cbb_refresh_verify.scoped_manifest import ManifestScope
|
||||
scope = ManifestScope.library('A', 'target.lmc')
|
||||
source, destination = tmp_path/'source', tmp_path/'destination'
|
||||
primary = put(source, relative)
|
||||
before = recovery._copy_verified(source, destination, scope=scope)
|
||||
assert relative in before['files']
|
||||
assert recovery._manifest(source, scope=scope) == before
|
||||
primary.write_bytes(b'concurrent shared/design edit')
|
||||
assert recovery._manifest(source, scope=scope) != before
|
||||
|
||||
|
||||
@pytest.mark.parametrize('relative', ['hdl/Logs/design.v', 'hdl/Backup/design.v', 'symbols/Temp/device.sym',
|
||||
'hdl/Log Files/design.v', 'hdl/ProjectBackup/backups/design.v',
|
||||
'hdl/Work.before-restore-engineering/design.v', 'database/cdbsvr/persistent.bin'])
|
||||
def test_nested_project_engineering_names_remain_primary(tmp_path, relative):
|
||||
primary = put(tmp_path, relative)
|
||||
before = recovery._manifest(tmp_path)
|
||||
assert relative in before['files']
|
||||
primary.unlink()
|
||||
assert recovery._manifest(tmp_path) != before
|
||||
|
||||
|
||||
@pytest.mark.parametrize('relative', [
|
||||
'ReusableBlocksLP/Logs/Work/Logs.prj',
|
||||
'ReusableBlocksLP/Backup/Cert/Backup.prj',
|
||||
'SymbolLibs/temp/device.sym', 'SharedDependency/hdl/Logs/design.v',
|
||||
])
|
||||
@pytest.mark.parametrize('side', ['source', 'destination'])
|
||||
def test_colliding_engineering_names_cannot_bypass_primary_copy_byte_checks(tmp_path, monkeypatch, relative, side):
|
||||
from cbb_refresh_verify.scoped_manifest import ManifestScope
|
||||
block = relative.split('/')[1] if relative.startswith('ReusableBlocksLP/') else 'A'
|
||||
scope = ManifestScope.library(block, 'target.lmc')
|
||||
source, destination = tmp_path/'source', tmp_path/'destination'
|
||||
put(source, relative)
|
||||
real_copy = shutil.copy2
|
||||
def copy_then_corrupt(src, dst, *args, **kwargs):
|
||||
result = real_copy(src, dst, *args, **kwargs)
|
||||
corrupt = Path(src) if side == 'source' else Path(dst)
|
||||
metadata = corrupt.stat()
|
||||
corrupt.write_bytes(b'X' * metadata.st_size)
|
||||
os.utime(corrupt, ns=(metadata.st_atime_ns, metadata.st_mtime_ns))
|
||||
return result
|
||||
monkeypatch.setattr(shutil, 'copy2', copy_then_corrupt)
|
||||
with pytest.raises(OSError):
|
||||
recovery._copy_verified(source, destination, scope=scope)
|
||||
assert (destination/relative).exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('prefix', ['', 'ReusableBlocksLP/Logs/Work/', 'ReusableBlocksLP/Temp/Cert/'])
|
||||
@pytest.mark.parametrize('relative', [
|
||||
'Log Files/ProjectBackupLog.txt', 'ProjectBackup/backups/old.zip',
|
||||
'database/cdbsvr/log/session/text.txt', 'database/cdbsvr/dbcheck/session/text.txt',
|
||||
'PCB/database/cdbsvr/dbrestore/session/text.txt',
|
||||
])
|
||||
def test_known_native_runtime_and_history_locations_are_ignored_contextually(tmp_path, prefix, relative):
|
||||
from cbb_refresh_verify.scoped_manifest import ManifestScope
|
||||
scope = ManifestScope.library(prefix.split('/')[1], 'target.lmc') if prefix else None
|
||||
runtime = put(tmp_path, prefix + relative)
|
||||
before = recovery._manifest(tmp_path, scope=scope)
|
||||
assert not before['files']
|
||||
runtime.write_bytes(b'updated runtime')
|
||||
assert recovery._manifest(tmp_path, scope=scope) == before
|
||||
|
||||
|
||||
@pytest.mark.parametrize('relative', ['SymbolLibs/temp/icdb.dat',
|
||||
'ReusableBlocksLP/Logs/Work/database/icdb.dat'])
|
||||
def test_locked_critical_bytes_in_colliding_names_are_checked_independently(tmp_path, relative):
|
||||
from cbb_refresh_verify.scoped_manifest import ManifestScope
|
||||
source, destination = tmp_path/'source', tmp_path/'destination'
|
||||
put(source, relative)
|
||||
def corrupt_after_copy(event):
|
||||
if event['copied_files'] == event['total_files']:
|
||||
copied = destination/relative
|
||||
metadata = copied.stat()
|
||||
copied.write_bytes(b'X' * metadata.st_size)
|
||||
os.utime(copied, ns=(metadata.st_atime_ns, metadata.st_mtime_ns))
|
||||
with pytest.raises(OSError):
|
||||
recovery._copy_verified(source, destination,
|
||||
scope=ManifestScope.library('Logs', 'target.lmc'), progress=corrupt_after_copy)
|
||||
assert (source/relative).read_bytes() == b'engineering'
|
||||
assert (destination/relative).read_bytes() == b'XXXXXXXXXXX'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('relative', ['SymbolLibs/temp/cdbsvr/log/session/text.txt',
|
||||
'SymbolLibs/Temp_a/cdbsvr/dbcheck/session/text.txt',
|
||||
'CellDB/cdbsvr/dbrestore/session/text.txt'])
|
||||
def test_shared_native_runtime_has_explicit_database_context(tmp_path, relative):
|
||||
from cbb_refresh_verify.scoped_manifest import ManifestScope
|
||||
put(tmp_path, relative)
|
||||
assert not recovery._manifest(tmp_path, scope=ManifestScope.library('A', 'target.lmc'))['files']
|
||||
Reference in new issue
Block a user