Files
VianoBugAnalysis/tests/test_investigation_context_study.py

64 lines
3.1 KiB
Python

"""Offline design study must not alter production inputs or invent findings."""
import copy
import importlib.util
from pathlib import Path
spec = importlib.util.spec_from_file_location('context_study',
Path(__file__).parents[1] / 'scripts' / 'study_investigation_context.py')
study = importlib.util.module_from_spec(spec)
spec.loader.exec_module(study)
def document():
h = {'proposal':{'title':'Missing hook', 'mechanism':'Hook may be absent'},
'confidence':'supported', 'disposition':'active',
'notes':[{'kind':'assessment','text':'Found a hook; inspect dispatch.'}],
'questions':[{'id':'Q1','text':'Is it dispatched?', 'resolved':False}],
'last_record_ref':'internal/path', 'iterations':3, 'invalid_responses':0}
content = {'items':[{'query':{'kind':'database.lookup', 'where':{'entry':5}},
'result':{'items':[], 'coverage':'complete'},
'origin':{'snapshot_id':'snapshot-1'}}]}
e = {'record_ref':'internal/record', 'record':{'id':'E000001',
'hypothesis_id':'H2','operation':'project.query','origin':{'request_ref':'internal'}},
'content':content}
return {'input':{'selected_hypothesis':'H1', 'hypotheses':{'H1':h,'H2':copy.deepcopy(h)},
'evidence':{'E000001':e, 'E000002':copy.deepcopy(e)},
'previous_result':{'evidence_id':'E000002'},
'budget':{'accounts':{'H1':{'remaining':20},'H2':{'remaining':10}}},
'shared_sources':{'FILE1':{'blocks':[{'lines':['counterevidence']}]}}}}
def test_no_invented_pro_con_from_confidence():
result = study.brief(document()['input']['hypotheses']['H1'])
assert result['causal_balance']['status'] == 'not_recorded_in_this_legacy_run'
assert 'support' not in result['causal_balance']
def test_recorded_causal_review_retained_without_reinterpretation():
h = document()['input']['hypotheses']['H1']
review = {'effect':'contradicts','support':[], 'against':['E000001'],
'reason':'Required hook exists.'}
h['notes'].append({'kind':'assessment','text':'Check deployment.', 'causal_review':review})
assert study.brief(h)['causal_balance'] == review
def test_trim_preserves_all_payloads_and_cross_hypothesis_counterevidence():
original = document()
before = copy.deepcopy(original)
result = study.administrative_trim(original)
assert original == before
assert result['input']['evidence'].keys() == original['input']['evidence'].keys()
for eid, entry in original['input']['evidence'].items():
assert result['input']['evidence'][eid]['content'] == entry['content']
assert result['input']['shared_sources'] == original['input']['shared_sources']
assert result['input']['hypotheses']['H1']['omitted_note_count'] == 1
def test_unsafe_experiment_explicitly_lists_omissions_keeps_fresh_payload():
original = document()
result, omitted = study.fresh_only(original)
assert omitted == ['E000001']
assert set(result['input']['evidence']) == {'E000002'}
assert result['input']['evidence']['E000002']['content'] == original['input']['evidence']['E000002']['content']
assert 'not safe to deploy' in result['input']['omission_warning']