31 lines
1.7 KiB
Python
31 lines
1.7 KiB
Python
import json
|
|
from dataclasses import asdict
|
|
from pathlib import Path
|
|
import pytest
|
|
from cbb_refresh_verify.verify_runner import VerifyRequest,VerifyResult,run_batch
|
|
|
|
|
|
@pytest.mark.parametrize('released',[True,False])
|
|
def test_batch_rechecks_owned_failure_before_skipping_next_item(tmp_path,monkeypatch,released):
|
|
from cbb_refresh_verify import library_lock,session_record
|
|
library=tmp_path/'lib.lmc';library.touch()
|
|
root=tmp_path/'failure';root.mkdir()
|
|
session_record.write_session_record(root/'session.json',dict(operation_id='test',library=str(library),block='A'))
|
|
outcome=VerifyResult('FAIL',stderr='original failure',safe_to_continue=False,
|
|
evidence_path=root/'result.json',session_record_path=root/'session.json')
|
|
calls=[]
|
|
monkeypatch.setattr(session_record,'inspect_session_record',lambda *a,**k:dict(status='UNCONFIRMED'))
|
|
def proof(*a,**k):
|
|
if not released:raise library_lock.LibraryBusy('shared database still occupied')
|
|
return dict(status='RELEASE_CONFIRMED',library=str(library),data_recovery_confirmed=False,
|
|
lease_state='RELEASED',blocked_resources=[],
|
|
resource_scope=dict(scope_state='OBSERVED',library=str(library)))
|
|
monkeypatch.setattr(library_lock,'release_retained_library',proof)
|
|
def verify(req):
|
|
calls.append(req.block_name)
|
|
return outcome if req.block_name=='A' else VerifyResult('PASS')
|
|
results=run_batch([VerifyRequest(library,n,tmp_path/'evidence') for n in ('A','B')],verifier=verify)
|
|
assert results[0].status=='FAIL' and results[0].stderr=='original failure'
|
|
assert results[0].safe_to_continue is released
|
|
assert calls==(['A','B'] if released else ['A'])
|