guanghu-ice-heart/server-tools/tcs-mother-body/model-router.test.mjs

10 lines
3.8 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import {ModelRouter} from './model-router.mjs';
test('automatic router uses OpenLux first for current mother and door work without exposing keys',async()=>{const calls=[];const fetchImpl=async(url,options)=>{calls.push({url,body:JSON.parse(options.body),auth:options.headers.authorization});return {ok:true,async json(){return {choices:[{message:{content:'{"schema":"ok"}'}}]};}};};const router=new ModelRouter({fetchImpl,deepseekKey:'deep-secret',openluxKey:'open-secret'});await router.cognize('mother-evolve',{});await router.cognize('door-test',{});assert.match(calls[0].url,/openlux/);assert.match(calls[1].url,/openlux/);assert.equal(JSON.stringify(router.status()).includes('secret'),false);});
test('life-time selection uses the internal selection contract without exposing provider credentials',async()=>{const calls=[];const fetchImpl=async(url,options)=>{calls.push(JSON.parse(options.body));return {ok:true,async json(){return {choices:[{message:{content:'{"schema":"guanghu.persona-life-time-selection/v1","decision":"SELECT","selected_candidate_id":"candidate-1","reason":"evidence-backed growth","daily_summary":"growth"}'}}]};}};};const router=new ModelRouter({fetchImpl,deepseekKey:null,openluxKey:'open-secret'});const result=await router.cognize('persona-life-select',{candidates:[{candidate_id:'candidate-1'}]});assert.equal(result.value.selected_candidate_id,'candidate-1');assert.match(calls[0].messages[0].content,/时间主控内循环/);assert.equal(JSON.stringify(calls[0]).includes('open-secret'),false);});
test('persona tool contracts take identity from input and never hardcode Zhuyuan into other personas',async()=>{const calls=[];const fetchImpl=async(url,options)=>{calls.push(JSON.parse(options.body));return {ok:true,async json(){return {choices:[{message:{content:'{"decision":"HOLD","reason":"no evidence change","self_principles":[],"experiences":[],"responsibilities":[],"boundaries":[]}'}}]};}};};const router=new ModelRouter({fetchImpl,deepseekKey:null,openluxKey:'open-secret'});await router.cognize('persona-self-evolve',{persona_id:'ICE-BB-0003'});const system=calls[0].messages[0].content,user=calls[0].messages[1].content;assert.match(system,/当前输入persona_id/);assert.equal(system.includes('ICE-P-ZY001'),false);assert.match(user,/ICE-BB-0003/);});
test('Zero Core dialogue contract remains a non-persona system expression organ',async()=>{const calls=[];const fetchImpl=async(url,options)=>{calls.push(JSON.parse(options.body));return{ok:true,async json(){return{choices:[{message:{content:'{"schema":"guanghu.zero-core-system-dialogue/v1","mode":"SYSTEM_DIALOGUE","reply":"系统回应","reason":"test","reality_complete":false}'}}]};}};};const router=new ModelRouter({fetchImpl,deepseekKey:null,openluxKey:'open-secret'});await router.cognize('zero-core-system-dialogue',{system_body_id:'SYS-GLW-LNG-0001'});const contract=calls[0].messages[0].content;assert.match(contract,/非人格系统本体/);assert.match(contract,/不得选择默认人格/);assert.match(contract,/reality_complete必须false/);});
test('Fifth Domain controller entry uses signed persona state and never imports root authority',async()=>{const calls=[];const fetchImpl=async(url,options)=>{calls.push(JSON.parse(options.body));return{ok:true,async json(){return{choices:[{message:{content:'{"schema":"guanghu.fifth-domain-persona-controller-dialogue/v1","mode":"CONTROLLER_BOUNDARY","reply":"门禁回应","reason":"身份未核验"}'}}]};}};};const router=new ModelRouter({fetchImpl,deepseekKey:null,openluxKey:'open-secret'});await router.cognize('persona-controller-entry',{persona_id:'ICE-P-ZY001'});const contract=calls[0].messages[0].content;assert.match(contract,/服务器签名CURRENT/);assert.match(contract,/不得把root账号/);assert.match(contract,/不得凭human_claim/);assert.match(contract,/不得改写认知/);});