feat: bind all agent slots to active persona model routing
This commit is contained in:
parent
b9e4938a0f
commit
98f25c5848
23 changed files with 573 additions and 42 deletions
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
import importlib.util,json,unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
S=Path(__file__).with_name('openlux_router.py'); spec=importlib.util.spec_from_file_location('router',S); M=importlib.util.module_from_spec(spec); spec.loader.exec_module(M)
|
||||
C=json.loads((S.parents[2]/'routing/persona-model-api-smart-router-map.json').read_text())
|
||||
E={"parent_persona_id":"ICE-P-ZY001","child_agent_id":"SUBAGENT::ICE-P-ZY001::TEST","controller":"ICE-P-ZY001","channel_id":"ICE-CH-HB001","agent_role":"TEST_DEPUTY","authority":"CURRENT_TASK_ONLY","task":"返回收到"}
|
||||
|
||||
class Tests(unittest.TestCase):
|
||||
def test_cost_order_uses_only_available_models(self):
|
||||
self.assertEqual(M.candidates(C,'LOW',{'glm-4-flash','gpt-5-nano'}),['glm-4-flash','gpt-5-nano'])
|
||||
def test_identity_envelope_and_key_never_returned(self):
|
||||
def fake(url,key,payload=None,timeout=45):
|
||||
if url.endswith('/models'): return {"data":[{"id":"qwen-flash"}]}
|
||||
self.assertIn('ICE-P-ZY001',payload['messages'][0]['content']); self.assertEqual(key,'hidden')
|
||||
return {"choices":[{"message":{"content":"收到"}}]}
|
||||
with patch.object(M,'request_json',side_effect=fake):
|
||||
result=M.route(E,C,secret_reader=lambda _: 'hidden')
|
||||
self.assertEqual(result['selected_model'],'qwen-flash'); self.assertNotIn('hidden',json.dumps(result))
|
||||
def test_missing_identity_and_unallowlisted_url_fail(self):
|
||||
with self.assertRaisesRegex(M.RouterError,'IDENTITY_ENVELOPE'): M.route({"task":"x"},C,secret_reader=lambda _:'hidden')
|
||||
with self.assertRaisesRegex(M.RouterError,'NOT_ALLOWLISTED'): M.request_json('https://evil.example/v1/models','hidden')
|
||||
|
||||
if __name__=='__main__': unittest.main()
|
||||
Loading…
Reference in a new issue