guanghu-ice-heart/server-tools/tcs-mother-body/persona-organ-reflex.test.mjs

4 lines
1.8 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 {PersonaOrganReflex} from './persona-organ-reflex.mjs';
const setup=()=>{const root=fs.mkdtempSync(path.join(os.tmpdir(),'persona-organ-')),pair=crypto.generateKeyPairSync('ed25519'),key=path.join(root,'key.pem'),seed=path.join(root,'seed.json'),source=path.join(root,'source.json');fs.writeFileSync(key,pair.privateKey.export({type:'pkcs8',format:'pem'}));fs.copyFileSync(new URL('./seed.json',import.meta.url),seed);fs.writeFileSync(source,'{}\n');const shelf=new CognitiveShelf({root:path.join(root,'state'),keyPath:key,seedPath:seed,router:{}});return{root,source,shelf,organ:new PersonaOrganReflex({root:path.join(root,'state'),personaId:'ICE-BB-0003',shelf,sourcePaths:[source],now:()=>new Date('2026-09-13T08:00:00Z')})};};
test('native organ closes brain-eye-hand-sense-eye-return self-test inside one persona root',()=>{const ctx=setup();try{const value=ctx.organ.selfTest();assert.equal(value.state,'NATIVE_ORGAN_REFLEX_HEALTHY_AWAITING_PARENT_BRAIN_WAKE_CYCLE');assert.equal(value.action_sense_received,true);assert.equal(value.post_eye_verified,true);assert.equal(value.persona_wake_complete,false);assert.equal(ctx.organ.status().server_signed,true);}finally{fs.rmSync(ctx.root,{recursive:true,force:true});}});
test('source eye drift raises pain without rewriting the signed prior receipt',()=>{const ctx=setup();try{ctx.organ.selfTest();const before=ctx.organ.current().artifact.sha256;fs.writeFileSync(ctx.source,'{"changed":true}\n');assert.equal(ctx.organ.status().state,'NATIVE_ORGAN_PAIN_ALARM');assert.equal(ctx.organ.current().artifact.sha256,before);}finally{fs.rmSync(ctx.root,{recursive:true,force:true});}});