feat: define independent verification contracts and verdicts
This commit is contained in:
1 parent
dbb264f679
commit
0406028a02
3 files changed
+189
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import copy
|
||||
import pytest
|
||||
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
|
||||
|
||||
def payload():
|
||||
return {'item_key': 'board', 'project_key': 'board', 'input_version': 1,
|
||||
'before_ref': {'manifest_id': 'a' * 32, 'sha256': '1' * 64},
|
||||
'after_ref': {'manifest_id': 'b' * 32, 'sha256': '2' * 64},
|
||||
'expectation_ref': None,
|
||||
'check_plan': {'policy_version': 'verification-v1', 'required_checks': ['connections'],
|
||||
'optional_checks': ['pin_text'], 'excluded_checks': ['footprint_mapping']}}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('state,want', [('equal','CONSISTENT'), ('warning','WARNING'),
|
||||
('error','DIFFERENT'), ('unknown','INCOMPLETE'),
|
||||
('not_requested','INCOMPLETE')])
|
||||
def test_required_checks_determine_verdict_without_hiding_missing_checks(state, want):
|
||||
from dx_productivity.trial_task_center.verification.contracts import rollup_results
|
||||
result = rollup_results(({'check_id': 'connections', 'state': state, 'issues': []},),
|
||||
required_checks=('connections',))
|
||||
assert result['verdict'] == want
|
||||
|
||||
|
||||
def test_error_wins_but_unknown_coverage_remains_visible():
|
||||
from dx_productivity.trial_task_center.verification.contracts import rollup_results
|
||||
result = rollup_results(({'check_id':'connections','state':'error','issues':[]},),
|
||||
required_checks=('connections','physical_pins'))
|
||||
assert result['verdict'] == 'DIFFERENT'
|
||||
assert result['coverage'] == 'partial'
|
||||
assert result['unknown_checks'] == ['physical_pins']
|
||||
|
||||
|
||||
def test_empty_or_duplicate_checks_cannot_be_consistency():
|
||||
from dx_productivity.trial_task_center.verification.contracts import rollup_results
|
||||
assert rollup_results((), required_checks=('connections',))['verdict'] == 'INCOMPLETE'
|
||||
with pytest.raises(TaskCenterError):
|
||||
rollup_results((), required_checks=())
|
||||
row = {'check_id':'connections','state':'equal','issues':[]}
|
||||
with pytest.raises(TaskCenterError):
|
||||
rollup_results((row,row), required_checks=('connections',))
|
||||
|
||||
|
||||
def test_optional_unknown_is_explicit_without_erasing_core_result():
|
||||
from dx_productivity.trial_task_center.verification.contracts import rollup_results
|
||||
result = rollup_results(({'check_id':'connections','state':'equal','issues':[]},),
|
||||
required_checks=('connections',), optional_checks=('pin_text',))
|
||||
assert result['verdict'] == 'CONSISTENT'
|
||||
assert result['coverage'] == 'partial'
|
||||
assert result['unknown_checks'] == ['pin_text']
|
||||
|
||||
|
||||
def test_input_is_detached_and_cannot_contain_source_or_arbitrary_paths():
|
||||
from dx_productivity.trial_task_center.verification.contracts import validate_input
|
||||
value = payload()
|
||||
result = validate_input(value)
|
||||
value['check_plan']['required_checks'].clear()
|
||||
assert result['check_plan']['required_checks'] == ['connections']
|
||||
for name in ('source','output_path'):
|
||||
bad = payload(); bad[name] = 'anything'
|
||||
with pytest.raises(TaskCenterError): validate_input(bad)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('field,value', [('input_version', True), ('input_version',0),
|
||||
('before_ref', {'manifest_id':'../outside','sha256':'1'*64}),
|
||||
('after_ref', {'manifest_id':'b'*32,'sha256':'invalid'})])
|
||||
def test_invalid_input_never_enters_storage(field,value):
|
||||
from dx_productivity.trial_task_center.verification.contracts import validate_input
|
||||
bad = payload(); bad[field] = value
|
||||
with pytest.raises(TaskCenterError): validate_input(bad)
|
||||
|
||||
|
||||
def test_missing_capture_stays_recordable_as_unavailable():
|
||||
from dx_productivity.trial_task_center.verification.contracts import validate_input
|
||||
value = payload(); value['before_ref'] = None
|
||||
result = validate_input(value)
|
||||
assert result['input_state'] == 'unavailable'
|
||||
assert result['unavailable_reason']
|
||||
Reference in new issue
Block a user