Merge branch 'codex/review-native-backend' into codex/review-ui-integration
This commit is contained in:
commit
746e5b5145
7 files changed
+554
-8
No files matched your search
@@ -0,0 +1,112 @@
|
||||
import json
|
||||
from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
|
||||
from test_management import setup, execute
|
||||
|
||||
|
||||
def test_maintenance_totals_do_not_count_pass_as_unconfirmed():
|
||||
from cbb_refresh_verify.icdb_maintenance import maintenance_counts
|
||||
from cbb_refresh_verify.verify_runner import VerifyResult
|
||||
counts = maintenance_counts([VerifyResult('PASS'), VerifyResult('CHECKED'),
|
||||
VerifyResult('FAIL'), VerifyResult('SKIPPED')])
|
||||
assert counts['passed'] == 1 and counts['unconfirmed'] == 1
|
||||
assert sum(counts[k] for k in ('passed', 'checked_without_repair', 'unconfirmed',
|
||||
'skipped', 'cancelled', 'issues_found', 'in_use')) == counts['total']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('occupied', [False, True])
|
||||
def test_verify_rechecks_history_instead_of_ignoring_or_permanently_blocking_it(tmp_path, monkeypatch, occupied):
|
||||
import cbb_refresh_verify.library_lock as locks
|
||||
import cbb_refresh_verify.verify_runner as runner
|
||||
library = tmp_path/'library/lib.lmc'; library.parent.mkdir(); library.touch()
|
||||
locks._persist_blocker(library, lease_id='a'*32, block_name='Target')
|
||||
before = locks.blocker_path(library).read_bytes()
|
||||
monkeypatch.setattr('cbb_refresh_verify.owner_probe.query_owners', lambda *_: [])
|
||||
address = library.parent/'ReusableBlocksLP/Target/Work/database/cdbsvr/sAddress.adr'
|
||||
if occupied:
|
||||
address.parent.mkdir(parents=True); address.touch()
|
||||
called = []
|
||||
monkeypatch.setattr(runner, '_run_verify_serialized', lambda *a, **kw:
|
||||
called.append(1) or runner.VerifyResult('PASS', library_flag='GREEN'))
|
||||
events = []
|
||||
result = runner.run_verify(runner.VerifyRequest(library, 'Target', tmp_path/'evidence'), progress=events.append)
|
||||
if occupied:
|
||||
assert not called and result.safe_to_continue
|
||||
assert result.error_category == 'LIBRARY_IN_USE'
|
||||
assert locks.blocker_path(library).read_bytes() == before
|
||||
else:
|
||||
assert called == [1] and result.status == 'PASS'
|
||||
assert result.release_proof['data_recovery_confirmed'] is False
|
||||
assert not locks.blocker_path(library).exists()
|
||||
assert any(e['stage'] == 'previous_release_confirmed' for e in events)
|
||||
|
||||
|
||||
def test_management_preserves_release_context_before_first_native_call(setup, monkeypatch):
|
||||
import cbb_refresh_verify.library_lock as locks
|
||||
request, adapter, _ = setup
|
||||
locks._persist_blocker(request.library, lease_id='b'*32)
|
||||
monkeypatch.setattr('cbb_refresh_verify.owner_probe.query_owners', lambda *_: [])
|
||||
catalog = adapter.catalog
|
||||
def inspect(library, evidence):
|
||||
checkpoint = next(request.evidence_dir.glob('*/checkpoint.json'))
|
||||
history = json.loads(checkpoint.read_text('utf-8'))['history']
|
||||
assert any(item.get('release_proof', {}).get('data_recovery_confirmed') is False for item in history)
|
||||
return catalog(library, evidence)
|
||||
monkeypatch.setattr(adapter, 'catalog', inspect)
|
||||
result = execute(request, adapter)
|
||||
assert result.status == 'REMOVED' and result.release_proof['status'] == 'RELEASE_CONFIRMED'
|
||||
|
||||
|
||||
def test_management_records_scoped_changes_without_hashing_unrelated_cbb(setup, monkeypatch):
|
||||
from cbb_refresh_verify import scoped_manifest
|
||||
request, adapter, _ = setup
|
||||
root = request.library.parent
|
||||
target = root/'ReusableBlocksLP/Block/Work/Block.prj'
|
||||
deleted = root/'ReusableBlocksLP/Block/Work/obsolete.dat'; deleted.write_bytes(b'old')
|
||||
shared = root/'SymbolLibs/shared/icdb.dat'; shared.parent.mkdir(parents=True); shared.write_bytes(b'old')
|
||||
foreign = root/'ReusableBlocksLP/Other/Work/private.dat'; foreign.parent.mkdir(parents=True); foreign.write_bytes(b'other')
|
||||
original_hash = scoped_manifest.hash_file
|
||||
def hashed(path):
|
||||
assert path != foreign, 'Post-write report must not add whole-library hashing'
|
||||
return original_hash(path)
|
||||
monkeypatch.setattr(scoped_manifest, 'hash_file', hashed)
|
||||
remove = adapter.remove
|
||||
def mutate(req, evidence):
|
||||
target.write_bytes(target.read_bytes()+b'# updated\n')
|
||||
deleted.unlink(); (target.parent/'created.dat').write_bytes(b'new')
|
||||
shared.write_bytes(b'changed')
|
||||
return remove(req, evidence)
|
||||
monkeypatch.setattr(adapter, 'remove', mutate)
|
||||
result = execute(request, adapter)
|
||||
report = json.loads((result.evidence_path.parent/'library-changes.json').read_text('utf-8'))
|
||||
assert report['status'] == 'RECORDED' and report['unrelated_cbb_content_checked'] is False
|
||||
assert report['added'] == ['ReusableBlocksLP/Block/Work/created.dat']
|
||||
assert report['deleted'] == ['ReusableBlocksLP/Block/Work/obsolete.dat']
|
||||
assert 'SymbolLibs/shared/icdb.dat' in report['modified']
|
||||
assert 'ReusableBlocksLP/Block/Work/Block.prj' in report['modified']
|
||||
assert result.change_report == report
|
||||
|
||||
|
||||
def test_failed_mutation_still_records_changes_and_release_fact(setup):
|
||||
request, adapter, source = setup
|
||||
adapter.fail_add = True
|
||||
result = execute(replace(request, operation='update', source=source), adapter)
|
||||
assert result.status == 'RECOVERY_REQUIRED' and result.safe_to_continue
|
||||
assert result.change_report['status'] == 'RECORDED'
|
||||
|
||||
|
||||
def test_change_report_storage_failure_does_not_invent_unfinished_native_write(setup, monkeypatch):
|
||||
import cbb_refresh_verify.management as management
|
||||
request, adapter, _ = setup
|
||||
original = management._write_json
|
||||
def write(path, value):
|
||||
if path.name == 'library-changes.json': raise PermissionError('report disk full')
|
||||
return original(path, value)
|
||||
monkeypatch.setattr(management, '_write_json', write)
|
||||
result = execute(request, adapter)
|
||||
assert result.safe_to_continue and result.status == 'REMOVED'
|
||||
assert result.change_report['status'] == 'UNCONFIRMED'
|
||||
assert 'report disk full' in result.detail
|
||||
assert not management.unfinished_operations(request.evidence_dir)
|
||||
Reference in new issue
Block a user