Files
VianoBugAnalysis/tests/test_phase_selection.py

73 lines
5.8 KiB
Python

import copy
import json
from viano_bug_analysis.analysis.phase_selection import select_context
from viano_bug_analysis.analysis.investigation_focus import focused_view
from viano_bug_analysis.analysis.investigation_blocks import restore_blocks
from test_investigation_consolidation import populated
def sources():
return {'sources':{
'O0001':{'kind':'observation','case_pointer':'/human_observations/0','data':{'text':'Nothing happened','provenance':{'author':'Tester','observed_at':'old-build','source_ref':'observation.json','json_pointer':'/0'}}},
'F0001':{'kind':'fact','case_pointer':'/runtime_facts/0','data':{'value':{'row':{'path':'a','sha256':'b','value':None,'flag':False},'coverage':'complete_filtered_rows','truncated':False},'provenance':{'snapshot_id':'snapshot-A','source_ref':'capture.json'}}},
'N0001':{'kind':'entity','case_pointer':'/entity_resolution/entities/0','data':{'id':'17','type':'item','provenance':{'source_ref':'capture.json'}}},
'X0001':{'kind':'unread_reference','case_pointer':'/source_context/refs/0','data':{'path':'unread.cpp','sha256':'a'*64}},
'D0001':{'kind':'data_quality','case_pointer':'/quality/0','data':{'text':'Observation predates source revision'}}},
'case_ref':'case.json','case_sha256':'x'*64,'case':{'case_id':'C'}}
def test_interpretation_omits_unread_catalog_without_removing_facts_or_identity_links():
c=sources();before=copy.deepcopy(c);audit=[]
v=select_context(c,'interpretation',audit_out=audit)
assert 'X0001' not in v['sources'] and '/sources/X0001' in audit
assert v['unread_inventory']['counts']=={'unread_reference':1}
assert v['sources']['F0001']['data'] == c['sources']['F0001']['data']
assert v['sources']['N0001']==c['sources']['N0001']
assert v['sources']['O0001']['data']['provenance']['observed_at']=='old-build'
assert v['sources']['O0001']['data']['provenance']['source_ref']=='observation.json'
assert c==before and select_context(c,'interpretation')==v
def test_hypotheses_keep_all_interpretations_facts_prior_feedback_and_observations():
c={'case_context':sources(),'interpretation_sources':{'I0001':{'kind':'unknowns','interpretation_pointer':'/unknowns/0','data':{'text':'Deployment is unknown','source_ids':['D0001']}}},'policy':{},'prior_generations':[{'failed_patch':'Did not change behavior'}]}
v=select_context(c,'hypotheses')
assert v['interpretation_sources']['I0001']['data']==c['interpretation_sources']['I0001']['data']
assert v['prior_generations']==c['prior_generations']
assert set(v['case_context']['sources'])=={'O0001','F0001','N0001','D0001'}
def test_diagnosis_omits_plans_and_bookkeeping_retains_every_evidence_and_uncertainty():
h={'proposal':{'title':'Missing hook','mechanism':'May be missing','falsifying_evidence':['Hook exists'],'rationale':'Early speculation','open_questions':['Hook present?']},'notes':[{'text':'May be missing'},{'text':'Hook found; old deployment unknown'}],'questions':[{'id':'Q1','text':'Hook present?','resolved':True},{'id':'Q2','text':'Which deployment?','resolved':False}],'evidence_refs':['E1'],'confidence':'weakened','disposition':'active'}
c={'case':{'case':{},'human_observations':['Nothing moved'],'runtime_facts':{'facts':[{'id':'F1','value':False}],'raw_refs':['unread']},'inputs':['huge catalog']},'investigation':{'hypotheses':{'H1':h},'active':None},'evidence':{'E1':{'content':{'items':[],'coverage':'complete_filtered_rows','truncated':False}}},'interpretation':{'contradictions':['Old observation versus new code'],'unknowns':['Deployment']},'budget':{'seen_evidence':['hash'],'accounts':{'H1':{'remaining':80,'status':'investigating','actions':{'old':'history'}}}}}
before=copy.deepcopy(c);audit=[];v=select_context(c,'diagnosis',audit_out=audit)
assert v['evidence']==c['evidence'] and v['interpretation']==c['interpretation']
assert v['case']['runtime_facts']['facts']==c['case']['runtime_facts']['facts']
assert v['investigation']['hypotheses']['H1']['notes']==h['notes'][-1:]
assert v['investigation']['hypotheses']['H1']['closed_questions']=={'Q1':'Hook present?'}
assert '/investigation/hypotheses/H1/notes/0' in audit
assert c==before
def test_investigation_keeps_latest_note_and_can_recall_older_counterevidence():
c=populated();c['prompt_version']='investigation_project_v9';c['budget']['accounts']['H1']['actions']={}
h=c['hypotheses']['H1'];h['evidence_refs']=['E000002'];h['notes']=['old speculation','current counterevidence']
audit=[]
assert set(focused_view(c,audit_out=audit)['evidence'])=={'E000001'}
assert audit==['/hypotheses/H1/notes/0']
c['recalled_evidence']=['E000002']
v=restore_blocks(focused_view(c))
assert set(v['evidence'])=={'E000001','E000002'}
assert v['hypotheses']['H1']['notes']==['current counterevidence']
assert c['hypotheses']['H1']['notes']==['old speculation','current counterevidence']
c['prompt_version']='investigation_project_v8'
assert len(focused_view(c)['hypotheses']['H1']['notes'])==2
def test_handoff_keeps_repair_constraints_and_evidence_without_search_direction():
c={'case':{'human_observations':['Absent'],'data_quality':{'warnings':['Snapshot only']}},'interpretation':{'investigation_direction':'search more','contradictions':['different versions'],'unknowns':['Placement coordinates'],'relevant_entities':['typed id']},'evidence':{'E1':{'content':{'items':[],'coverage':'complete_filtered_rows'},'content_sha256':'hash'}},'local_context':{'capture':{'allowed_evidence_refs':['E1']}},'policy':{'rules':['No invented coordinates']}}
v=select_context(c,'handoff')
assert 'investigation_direction' not in v['interpretation']
assert v['interpretation']['unknowns']==c['interpretation']['unknowns']
assert v['evidence']['E1']['content']==c['evidence']['E1']['content']
assert v['local_context']==c['local_context'] and v['policy']==c['policy']