Reduce verbose investigation and final phase prompt overhead
This commit is contained in:
1 parent
2fe1e478a5
commit
061f82e6f1
24 files changed
+279
-42
No files matched your search
@@ -13,9 +13,9 @@ from viano_bug_analysis.analysis import InvestigationConfig,InvestigationError
|
||||
from viano_bug_analysis.llm.gemini import GeminiProvider,bootstrap_shape
|
||||
|
||||
|
||||
def nested_request():
|
||||
def nested_request(version=2):
|
||||
from test_investigation_lean import lean_context
|
||||
c=lean_context();c.pop('lean_session');c.update(bootstrap_json_framing=True,bootstrap_framing_version=2)
|
||||
c=lean_context();c.pop('lean_session');c.update(bootstrap_json_framing=True,bootstrap_framing_version=version)
|
||||
return build_prompt(c)
|
||||
|
||||
|
||||
@@ -42,8 +42,9 @@ def test_native_shape_covers_nested_finding_fields(field,value):
|
||||
assert not Draft202012Validator(bootstrap_shape(nested_request()['output_schema'])).is_valid(r)
|
||||
|
||||
|
||||
def test_new_native_contract_sent_with_cache_and_full_schema_retained(monkeypatch):
|
||||
request=nested_request();assert request['prompt_version']=='investigation_bootstrap_v22'
|
||||
@pytest.mark.parametrize('version',[2,3])
|
||||
def test_new_native_contract_sent_with_cache_and_full_schema_retained(monkeypatch,version):
|
||||
request=nested_request(version);assert request['prompt_version']==f'investigation_bootstrap_v{20+version}'
|
||||
response=native();response['candidates'][0]['content']['parts'][0]['text']=json.dumps(nonempty_reply())
|
||||
adapter=GeminiProvider();seen=scripted(adapter,monkeypatch,[CACHE,response,response])
|
||||
settings=replace(config(),cache_min_prefix_chars=10**9,response_format='json_object')
|
||||
@@ -66,6 +67,6 @@ def test_legacy_request_remains_v21_and_schema_identical():
|
||||
assert new['output_schema']==old['output_schema']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('version',[0,3,True,'2'])
|
||||
@pytest.mark.parametrize('version',[0,4,True,'2'])
|
||||
def test_invalid_bootstrap_version_rejected(version):
|
||||
with pytest.raises(InvestigationError):InvestigationConfig(bootstrap_framing_version=version)
|
||||
@@ -70,7 +70,7 @@ def test_new_diagnosis_keeps_frozen_context_and_uses_compact_request(investigate
|
||||
adapter = FinalAdapter(True)
|
||||
result = build(DiagnosisBuilder(store, gateway(adapter)))
|
||||
request = adapter.requests[0]
|
||||
assert request['prompt_version'] == 'diagnosis_v6'
|
||||
assert request['prompt_version'] == 'diagnosis_v7'
|
||||
visible = restore(json.loads(request['messages'][1]['content'])['input'])
|
||||
with PackageReader(result.package) as reader:
|
||||
doc = json.loads(reader.read_bytes(result.diagnosis_ref))
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_retry_gets_actionable_feedback_and_portable_replay(diagnosed, tmp_path,
|
||||
class Correcting(RequestAdapter):
|
||||
async def generate(self, config, request, **kwargs):
|
||||
response = await super().generate(config, request, **kwargs)
|
||||
assert request['prompt_version'] == (first_version if self.calls == 1 else 'change_request_v7')
|
||||
assert request['prompt_version'] == (first_version if self.calls == 1 else 'change_request_v8')
|
||||
if self.calls == 1:
|
||||
response.document['affected_scope'][0]['source_ref'] = 'wrong.cpp'
|
||||
else:
|
||||
|
||||
@@ -218,7 +218,7 @@ def test_legacy_rejection_upgrades_next_attempt_without_rewriting_context(invest
|
||||
assert build(builder).status=='REJECTED'
|
||||
assert adapter.requests[0]['prompt_version']=='diagnosis_v1'
|
||||
assert build(builder).status=='COMPLETED'
|
||||
assert adapter.requests[1]['prompt_version']=='diagnosis_v6'
|
||||
assert adapter.requests[1]['prompt_version']=='diagnosis_v7'
|
||||
received=restore(json.loads(adapter.requests[1]['messages'][1]['content'])['input'])
|
||||
assert received['validation_feedback'][0]['code']=='DIAGNOSIS_SELECTION'
|
||||
assert build(builder).reused and adapter.calls==2
|
||||
@@ -235,7 +235,7 @@ def test_lean_reply_derivation_and_portable_replay(investigated,tmp_path):
|
||||
builder = DiagnosisBuilder(store,gateway(adapter))
|
||||
result = build(builder)
|
||||
assert result.status == 'COMPLETED'
|
||||
assert adapter.requests[0]['prompt_version'] == 'diagnosis_v6'
|
||||
assert adapter.requests[0]['prompt_version'] == 'diagnosis_v7'
|
||||
with PackageReader(result.package) as reader:
|
||||
doc=json.loads(reader.read_bytes(result.diagnosis_ref))
|
||||
call=json.loads(reader.read_bytes(doc['llm_result_ref']))
|
||||
|
||||
@@ -90,7 +90,7 @@ def test_coding_contract_rejects_wrong_column_value_but_accepts_placeholder():
|
||||
validate_request(payload,c)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('framing_version',[1,2])
|
||||
@pytest.mark.parametrize('framing_version',[1,2,3])
|
||||
def test_bootstrap_marker_is_persisted_and_replayable(tool_case,tmp_path,framing_version):
|
||||
import asyncio
|
||||
from test_investigation_hybrid import HybridAdapter
|
||||
@@ -104,14 +104,14 @@ def test_bootstrap_marker_is_persisted_and_replayable(tool_case,tmp_path,framing
|
||||
versions=[]
|
||||
async def generate(self,config,request,**kwargs):
|
||||
self.versions.append(request['prompt_version'])
|
||||
if request['prompt_version'] in {'investigation_bootstrap_v21','investigation_bootstrap_v22'}:
|
||||
if request['prompt_version'] in {'investigation_bootstrap_v21','investigation_bootstrap_v22','investigation_bootstrap_v23'}:
|
||||
request=dict(request,prompt_version='investigation_project_v18')
|
||||
return await super().generate(config,request,**kwargs)
|
||||
adapter=Framed();router=InvestigationToolRouter(project_research=service_for(tool_case))
|
||||
loop=Investigator(tool_case[0],gateway(adapter),InvestigationConfig(lean_loop=True,lean_protocol=2,
|
||||
lean_checkpoint_steps=0,bootstrap_json_framing=True,bootstrap_framing_version=framing_version),router=router)
|
||||
first=run(loop,steps=3)
|
||||
expected='investigation_bootstrap_v21' if framing_version==1 else 'investigation_bootstrap_v22'
|
||||
expected=f'investigation_bootstrap_v{20+framing_version}'
|
||||
assert adapter.versions==[expected]*3
|
||||
portable=CheckpointStore(Workspace(tmp_path/'portable'));portable.intake(first.package)
|
||||
result=run(Investigator(portable,gateway(adapter),router=router))
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
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']
|
||||
Reference in new issue
Block a user