import pytest from agent_framework.decisions.adapters.typesafe import build_request, normalize_answers, TypeSafeContractError from agent_framework.decisions import client def test_choice_wire_uses_verified_noul(): questions = [client.choice('decision', ['CONTINUE','ROUTE','END_SESSION'])] body = build_request('state', questions) assert len(body['questions']) == 3 assert all(x['type'] == 'noul' for x in body['questions'].values()) answer = {'answers': {'__jev_q0_o0': {'noul': .12}, '__jev_q0_o1': {'noul': .94}, '__jev_q0_o2': {'noul': .07}}} assert normalize_answers(answer, questions) == [{'name': 'decision', 'type': 'choice', 'choice': 'ROUTE', 'confidence': .94}] def test_ambiguous_choice_fails_closed(): questions = [client.choice('decision', ['CONTINUE','ROUTE'])] with pytest.raises(TypeSafeContractError, match='AMBIGUOUS_DIRECT_CHOICE'): normalize_answers({'answers': {'__jev_q0_o0': {'noul': .81}, '__jev_q0_o1': {'noul': .78}}}, questions) def test_predicate_wire(): questions = [client.predicate('allowed')] assert normalize_answers({'answers': {'__jev_q0': {'noul': .9}}}, questions)[0]['probability'] == .9 def test_score_fails_closed(): with pytest.raises(TypeSafeContractError, match='UNSUPPORTED_DIRECT_SCORE'): build_request('state', [client.score('score')])