59 lines
3.0 KiB
Python
59 lines
3.0 KiB
Python
import copy
|
|
from viano_bug_analysis.analysis.verbose_context import project
|
|
|
|
|
|
def test_preserves_literal_cells_and_qualified_provenance():
|
|
literal = {'origin': {'json_pointer': 'literal'}, 'sha256': 'cell', 'size': 7}
|
|
value = {'case': {'runtime_facts': {'facts': [{'id': 'F1', 'value': literal,
|
|
'provenance': {'kind': 'tester', 'author': 'A', 'observed_at': 'now',
|
|
'source_ref': 'original/report.json', 'json_pointer': '/facts/0',
|
|
'origin': {'snapshot_id': 'snapshot', 'time_scope': 'old', 'archive_ref': 'raw.zip'}}}]}},
|
|
'evidence': {'E1': {'content': {'items': [{'row': literal}]}}}}
|
|
before = copy.deepcopy(value)
|
|
result = project(value)
|
|
assert value == before
|
|
fact = result['case']['runtime_facts']['facts'][0]
|
|
assert fact['value'] == literal
|
|
assert result['evidence']['E1']['content']['items'][0]['row'] == literal
|
|
assert fact['provenance'] == {'kind':'tester','author':'A','observed_at':'now',
|
|
'source_ref':'original/report.json','origin':{'snapshot_id':'snapshot','time_scope':'old'}}
|
|
|
|
|
|
def test_only_visible_catalog_payload_is_replaced_by_reference():
|
|
value = {'evidence': {'E1': {'content': {'query': 'exact'}}},
|
|
'evidence_catalog': [{'id':'E1','collector':'H1','queries':['exact']},
|
|
{'id':'E2','collector':'H2','queries':['archived']} ]}
|
|
result = project(value)
|
|
assert result['evidence'] == value['evidence']
|
|
assert result['evidence_catalog'][0] == {'id':'E1','collector':'H1','details_in':'evidence'}
|
|
assert result['evidence_catalog'][1] == value['evidence_catalog'][1]
|
|
|
|
|
|
def test_plain_input_needs_no_notice_or_overhead():
|
|
value = {'case': {'bug':'unchanged'}, 'row':{'origin':{'size':99}}}
|
|
assert project(value) == value
|
|
|
|
|
|
def test_bootstrap_v23_reuses_codec_and_preserves_cache_partition():
|
|
import json
|
|
from test_investigation_lean import lean_context
|
|
from viano_bug_analysis.analysis.investigation_prompt import build_prompt
|
|
from viano_bug_analysis.analysis.json_consolidation import restore
|
|
from viano_bug_analysis.llm.stable_context import split_document, restore_document
|
|
context = lean_context()
|
|
context.pop('lean_session')
|
|
context.update(bootstrap_json_framing=True, bootstrap_framing_version=2)
|
|
old = build_prompt(context)
|
|
context['bootstrap_framing_version'] = 3
|
|
new = build_prompt(context)
|
|
assert new['prompt_version'] == 'investigation_bootstrap_v23'
|
|
assert new['output_schema'] == old['output_schema']
|
|
before = json.loads(old['messages'][1]['content'])['input']
|
|
document = json.loads(new['messages'][1]['content'])
|
|
for field in ('evidence', 'known_schemas', 'evidence_catalog'):
|
|
assert restore(document['input'][field]) == project(before)[field]
|
|
partition = split_document(document, new['prompt_version'])
|
|
assert partition and restore_document(*partition) == document
|
|
assert partition[0]['input']['case'] == before['case']
|
|
assert partition[0]['input']['interpretation'] == before['interpretation']
|