Compact hypothesis prompts and separate evidence from causal assumptions

This commit is contained in:
Nico committed 2026-10-15 13:24:41 +02:00
1 parent 482df4579d
commit 680a5dd5ed
9 files changed
+184 -10

No files matched your search

+57 -1
View File
@@ -93,7 +93,7 @@ def test_generation_budget_registry_and_preservation(interpreted_case):
if name != "manifest.json": assert before.read_bytes(name) == after.read_bytes(name)
assert original.read_bytes() == original_bytes
assert len(adapter.requests) == 1
assert adapter.requests[0]["prompt_version"] == "hypotheses_v1"
assert adapter.requests[0]["prompt_version"] == "hypotheses_v2"
assert case_builder.build("case-A","stable-package").reused
assert asyncio.run(CaseInterpreter(store,gateway(adapter)).interpret("case-A","stable-package")).reused
@@ -449,3 +449,59 @@ def test_imported_hypotheses_without_creation_history_cannot_be_forgotten(interp
with pytest.raises(HypothesisError,match="HYPOTHESIS_EXISTING_REGISTRY"):
run(HypothesisBuilder(foreign,gateway(adapter)))
assert not adapter.requests
def test_historical_v1_start_resumes_and_completed_generation_replays(interpreted_case):
from viano_bug_analysis.analysis.hypothesis_contracts import build_context
from viano_bug_analysis.lifecycle.storage import json_bytes
store,_,interpreted,_,_=interpreted_case
with PackageReader(interpreted.package) as reader:
interpretation=json.loads(reader.read_bytes(interpreted.interpretation_ref))
case_context=json.loads(reader.read_bytes(interpretation['context_ref']))
policy=HypothesisConfig().policy()
context=build_context(case_context,interpretation,interpreted.interpretation_ref,policy,[],HypothesisLimits())
context_ref='analysis/hypotheses/0001/context.json'
policy_ref='analysis/hypotheses/0001/policy.json'
details={'operation':'hypotheses-generating','builder_version':'1','context_ref':context_ref,
'context_sha256':hashlib.sha256(json_bytes(context)).hexdigest(),'policy_ref':policy_ref,
'policy_sha256':hashlib.sha256(json_bytes(policy)).hexdigest(),
'interpretation_ref':interpreted.interpretation_ref,'interpretation_sha256':context['interpretation_sha256']}
generation=reader.manifest['package_generation']
store.advance('case-A','stable-package',State.GENERATING_HYPOTHESES,
step_id='hypothesis-builder:v1:revision:1:start',details=details,
additions={context_ref:json_bytes(context),policy_ref:json_bytes(policy)},
artifacts={'hypothesis_context':context_ref,'hypothesis_policy':policy_ref},expected_generation=generation)
model=ProposalAdapter()
builder=HypothesisBuilder(store,gateway(model))
result=run(builder)
assert result.status=='COMPLETED'
assert model.requests[0]['prompt_version']=='hypotheses_v1'
assert run(builder).reused and len(model.requests)==1
def test_compact_hypothesis_prompt_preserves_claims_sources_and_budget(interpreted_case):
from viano_bug_analysis.analysis.hypothesis_prompt import HypothesisPromptBuilder
from viano_bug_analysis.analysis.hypothesis_contracts import build_context
store,_,interpreted,_,_=interpreted_case
with PackageReader(interpreted.package) as reader:
interpretation=json.loads(reader.read_bytes(interpreted.interpretation_ref))
case_context=json.loads(reader.read_bytes(interpretation['context_ref']))
context=build_context(case_context,interpretation,interpreted.interpretation_ref,HypothesisConfig().policy(),[],HypothesisLimits())
context['case_context']['sources']['X9999']={'kind':'unread_reference','case_pointer':'/research/refs/0',
'data':{'path':'original/'+'a'*64+'/evidence.json','sha256':'b'*64,'size':100}}
prompt=HypothesisPromptBuilder()
old=prompt.build(context)
before=copy.deepcopy(context)
context['prompt_version']='hypotheses_v2'
new=prompt.build(context)
data=json.loads(new['messages'][1]['content'])['input']
assert data['policy']==context['policy']
assert data['interpretation_sources']==context['interpretation_sources']
assert set(data['case_context']['sources'])==set(case_context['sources'])|{'X9999'}
assert data['case_context']['sources']['O0001']['data']['text']==case_context['sources']['O0001']['data']['text']
assert len(new['messages'][1]['content'])<len(old['messages'][1]['content'])
assert prompt.build(before)==old
rules=new['messages'][0]['content']
assert 'conditional suspected' in rules and 'symbol-to-number mappings from memory' in rules
# Neither prompt supplies the known test-case cause or specific entity IDs.
assert '23487' not in rules and 'Dun Morogh' not in rules