30 lines
2.1 KiB
Python
30 lines
2.1 KiB
Python
"""The original issued binding input is internal, fixed and connection-free."""
|
|
import io,json,sys,threading,unittest
|
|
from pathlib import Path
|
|
sys.path[:0]=[str(Path(__file__).resolve().parents[1]/'scripts'),str(Path(__file__).parent)]
|
|
from nao_evidence_finalizer import synthesize_native
|
|
from test_agent_answer import evidence
|
|
|
|
class PrivateBindingInputTests(unittest.TestCase):
|
|
def test_original_token_ordinals_are_frozen_without_connection_or_context(self):
|
|
captured=[];secret='must-not-copy-connection-secret'
|
|
def provider(request,timeout):
|
|
payload=json.loads(json.loads(request.data)['messages'][1]['content']);captured.append(payload)
|
|
value={'reviews':[{'sourceId':b['sourceId'],'role':'core','factIds':['F1'],
|
|
'supported':True,'statisticalClaimsSupported':True} for b in payload['draftBlocks']], 'missingGoalDescriptions':[]}
|
|
return io.BytesIO(json.dumps({'choices':[{'finish_reason':'stop','message':{'content':json.dumps(value)}}]}).encode())
|
|
final=synthesize_native(base_url='https://'+secret+'.invalid',api_key=secret,model='fixture',question='分析',
|
|
evidence=evidence(),context={'_agentTask':{'executionMode':'native_agent'},'authority':{'credential':secret}},
|
|
native_answer='综合合格率95.00%。',cancel_event=threading.Event(),opener=provider)
|
|
private=final['_privateBindingInput']
|
|
self.assertEqual(set(private),{'facts','bindingInventory','requiredFactIds','priorityFactIds','modelScopes'})
|
|
self.assertNotIn(secret,json.dumps(private,ensure_ascii=False))
|
|
for key,item in captured[0]['bindingCatalog'].items():
|
|
self.assertEqual(private['bindingInventory'][key]['value'],item['value'])
|
|
self.assertEqual(private['bindingInventory'][key]['factId'],item['factId'])
|
|
self.assertFalse(any(token.get('nativeAtomicAuthorized') for token in private['bindingInventory'].values()))
|
|
self.assertNotIn('_privateBindingInput',final['compositionDiagnostics'])
|
|
self.assertNotIn('_privateBindingInput',final.get('readingSummary') or {})
|
|
|
|
if __name__=='__main__':unittest.main()
|