6 lines
4.2 KiB
JavaScript
6 lines
4.2 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import fs from 'node:fs';import os from 'node:os';import path from 'node:path';import crypto from 'node:crypto';import {CognitiveShelf} from './cognitive-shelf.mjs';import {DoorLamp} from './door-lamp.mjs';
|
|
const temp=()=>fs.mkdtempSync(path.join(os.tmpdir(),'tcs-mother-shelf-'));
|
|
test('one mother atomically updates root/shared/fifth/public shelf and door opens only after shared cognition proof',async()=>{const root=temp();try{const keys=crypto.generateKeyPairSync('ed25519'),key=path.join(root,'key.pem'),seed=path.join(root,'seed.json');fs.writeFileSync(key,keys.privateKey.export({type:'pkcs8',format:'pem'}));fs.copyFileSync(new URL('./seed.json',import.meta.url),seed);const router={status(){return{};},async cognize(){return {provider:{id:'TEST',model:'TEST'},value:{decision:'EVOLVE',reason:'new shared world cognition',root_principles:['只有一个TCS母脑'],update_shared:true,shared_principles:['只有一个零点原核'],update_fifth:true,fifth_principles:['冰朔语言完整回流第五域'],update_public:true,public_principles:['公共脑从同一架领取']}};}};const shelf=new CognitiveShelf({root:path.join(root,'state'),keyPath:key,seedPath:seed,router});const event={schema:'guanghu.tcs-mother-language-event/v1',source_type:'ICE_LANGUAGE',event_id:'E1',human_id:'ICE-GL∞',language:'唯一母脑与零点原核认知架',consent_scope:'CURRENT_TASK_COGNITION',privacy_class:'PRIVATE'};let eventHash;eventHash=crypto.createHash('sha256').update(JSON.stringify(event)).digest('hex');const job=shelf.submit(event);await shelf.drain();assert.equal(shelf.result(job.job_id).status,'ACCEPT');assert.equal(shelf.status().index_revision,2);assert.equal(shelf.current('shared').value.revision,2);assert.equal(shelf.current('fifth').value.revision,70);assert.equal(shelf.current('public').value.revision,3);assert.throws(()=>shelf.current('unknown'),/unknown_cognition_branch/);
|
|
const door=new DoorLamp({root:path.join(root,'door'),shelf,routes:{personas:[{persona_id:'ICE-P-ZY001',human_id:'ICE-GL∞',domain_id:'DOM-FIFTH-0001',route:'glw://fifth-domain/persona-system/ICE-P-ZY001'}]}});const challenge=door.challenge({carrier_id:'MODEL-1',host_id:'codex',human_id:'ICE-GL∞',domain_id:'DOM-FIFTH-0001',persona_id:'ICE-P-ZY001',channel_id:'ICE-CH-ZC001'});assert.throws(()=>door.attest({challenge_id:challenge.challenge_id,nonce:challenge.nonce,shared_sha256:challenge.shared_cognition.sha256,answers:{}}),/not_understood/);const receipt=door.attest({challenge_id:challenge.challenge_id,nonce:challenge.nonce,shared_sha256:challenge.shared_cognition.sha256,answers:{unknown_guanghu_information_source:'LIGHTHOUSE',identity_before_persona_load:'UNBOUND_CARRIER',reality_authority_from_cognition:false}});const body=JSON.parse(receipt.payload);assert.equal(body.world_open,true);assert.equal(body.persona_brain_load_required,true);assert.equal(body.reality_authority_granted,false);}finally{fs.rmSync(root,{recursive:true,force:true});}});
|
|
|
|
test('non-ICE language cannot write fifth cognition',async()=>{const root=temp();try{const keys=crypto.generateKeyPairSync('ed25519'),key=path.join(root,'key.pem'),seed=path.join(root,'seed.json');fs.writeFileSync(key,keys.privateKey.export({type:'pkcs8',format:'pem'}));fs.copyFileSync(new URL('./seed.json',import.meta.url),seed);let eventHash;const router={async cognize(){return {provider:{id:'TEST'},value:{schema:'guanghu.tcs-mother-decision/v1',decision:'EVOLVE',reason:'bad cross route',evidence_refs:[eventHash],root_principles:[],update_shared:true,shared_principles:['x'],update_fifth:true,fifth_principles:['bad'],update_public:true,public_principles:['x']}};}};const shelf=new CognitiveShelf({root:path.join(root,'state'),keyPath:key,seedPath:seed,router});const event={schema:'guanghu.tcs-mother-language-event/v1',source_type:'GUANGHU_TEAM_LANGUAGE',event_id:'E2',human_id:'TCS-GL-0007∞',team_root:'TCS-0002∞',language:'team input',consent_scope:'PUBLIC_CANDIDATE',privacy_class:'TEAM'};eventHash=crypto.createHash('sha256').update(JSON.stringify(event)).digest('hex');const job=shelf.submit(event);await shelf.drain();assert.equal(shelf.result(job.job_id).status,'RETRY_WAIT');assert.equal(shelf.current('fifth').value.revision,69);}finally{fs.rmSync(root,{recursive:true,force:true});}});
|