Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienos.com/blob/main/om/hive-render/test-replay.mjs # aienos.com Source of www.aienos.com, served from my own hardware Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienos.com / om / hive-render / test-replay.mjs` 88 lines · 11751 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 // Verification-only replay of the existing renderer oracle cases; no production use. 3 import fs from 'node:fs'; 4 import path from 'node:path'; 5 import os from 'node:os'; 6 import assert from 'node:assert/strict'; 7 import {spawnSync,spawn} from 'node:child_process'; 8 const [binary,omc,scratch,receiver,collector]=process.argv.slice(2).map(x=>path.resolve(x)); 9 if(fs.existsSync(scratch)) assert.equal(fs.readdirSync(scratch).length,0,'scratch directory must be empty'); 10 fs.mkdirSync(scratch,{recursive:true}); 11 const canonical=v=>Buffer.from(JSON.stringify(v,(_,x)=>x&&typeof x==='object'&&!Array.isArray(x)?Object.fromEntries(Object.keys(x).sort().map(k=>[k,x[k]])):x)+'\n'); 12 const agent=(id='a1',parent=null)=>({id,parent_id:parent,name:'Worker',runtime:'OMP',provider:'provider',model:'model',role:'worker',task:'A public task',status:'working',activity:'A public action',activity_state:'running',started_at:'2026-10-25T23:59:59.900Z',updated_at:null,observed_at:'2026-10-26T00:00:00.100Z'}); 13 const snapshot=()=>({schema_version:1,generated_at:'2026-10-26T00:00:01.100Z',sequence:'snapshot',poll_ms:1000,stale_after_ms:15000,coverage:{label:'OMP',roots:1,agents:1,complete:false,notice:'Partial observation'},agents:[agent()],interactions:[]}); 14 const execute=(exe,input,args=[],env=process.env)=>spawnSync(exe,args,{input,env,timeout:30000,maxBuffer:`67108864`}); 15 const run=(raw,good=true)=>{const r=execute(binary,raw);assert(!r.error,String(r.error));if(good){assert.equal(r.status,0,r.stderr.toString());assert(r.stdout.toString().startsWith(''));assert(r.stdout.toString().endsWith('\n'));}else{assert.notEqual(r.status,0);assert.equal(r.stdout.length,0);}return r.stdout;}; 16 const escaped=x=>x.replaceAll('&','&').replaceAll('<','<').replaceAll('>','>').replaceAll('"','"').replaceAll("'",'''); 17 const safeDoc=out=>{const html=out.toString();assert(!/<(?:script|img)(?:\s|>)/i.test(html));for(const [tag] of html.matchAll(/<[A-Za-z][^>]*>/g)){assert(!/\son[a-z]+\s*=/i.test(tag));assert(!/javascript:/i.test(tag));}const ids=[...html.matchAll(/\bid="([^"]*)"/g)].map(x=>x[1]);assert.equal(ids.length,new Set(ids).size);}; 18 const raw=canonical(snapshot()); 19 const first=run(raw);assert.deepEqual(first,run(raw));safeDoc(first);assert(first.includes(Buffer.from('1s'))); 20 fs.writeFileSync(path.join(scratch,'fixture.json'),raw); 21 for(const sequence of ['', '\">', 'é'.repeat(64)]){const v=snapshot();v.sequence=sequence;const out=run(canonical(v));safeDoc(out);assert(out.includes(Buffer.from('data-sequence="s-'+Buffer.from(sequence).toString('hex')+'"')));} 22 const source=fs.readFileSync('render.om','utf8').split('fn main to int\n')[0]; 23 const escapeMain=`fn main to int 24 n = ulong 0 25 while lt n 16000 26 r = read 0 dec n sub ulong 16000 n 27 if lt r 0 28 ret 1 29 end 30 if eq r 0 31 break 32 end 33 n = add n ulong r 34 end 35 escape 0 n 36 r = write 1 out 0 get st 5 37 if ne r long get st 5 38 ret 2 39 end 40 ret 0 41 end 42 `; 43 const compiled=execute(omc,source+escapeMain);assert.equal(compiled.status,0,compiled.stderr.toString()); 44 const probe=path.join(scratch,'escape');fs.writeFileSync(probe,compiled.stdout,{mode:0o700}); 45 const values=Array.from({length:256},(_,i)=>Buffer.from([i]));values.push(Buffer.from(Array.from({length:256},(_,i)=>i)),Buffer.from(`&<>"'`.repeat(144)),Buffer.from(`&<>"'`.repeat(3200))); 46 for(const value of values){const r=execute(probe,value);assert.equal(r.status,0);const expected=Buffer.from(escaped(value.toString('latin1')),'latin1');assert.deepEqual(r.stdout,expected);if(value.includes(60))assert.notDeepEqual(r.stdout,Buffer.from(expected.toString('latin1').replaceAll('<','<'),'latin1'));} 47 const probes=['','','\">','']; 48 for(const payload of [...probes,'\b\f\n\r\t\\"','é 🐝 漢字',`&<>"'`.repeat(3200)]){const v=snapshot();v.agents[0].activity=payload;v.interactions=[{id:'m1',agent_id:'a1',role:'assistant',text:payload,at:v.generated_at,runtime:'OMP',provider:'provider',model:'model'}];const out=run(canonical(v));assert(out.includes(Buffer.from(escaped(payload))));safeDoc(out);} 49 for(const role of ['drake','user','guest','Assistant']){const v=snapshot();v.interactions=[{id:'m1',agent_id:'a1',role,text:'HUMAN_MESSAGE_CANARY',at:v.generated_at,runtime:'OMP',provider:'provider',model:'model'}];run(canonical(v),false);} 50 {const v=snapshot();v.interactions=[{id:'m1',agent_id:'a1',role:'assistant',text:'Agent reply',at:v.generated_at,runtime:'OMP',provider:'provider',model:'model'}];const out=run(canonical(v));assert(out.includes(Buffer.from('

What the agents are saying, live

    ').length-1,500);assert.equal(out.split('').length-1,500);} 57 {const v=snapshot();v.agents=Array.from({length:60},(_,i)=>({...agent('a'+i),activity:"'".repeat(16000),task:"'".repeat(16000)}));v.coverage.agents=60;v.coverage.roots=60;const input=canonical(v);assert(input.length<`2097152`);const out=run(input);assert(out.length>`16777216`);safeDoc(out);} 58 // Wolfram DateDifference[{y,2,28},{y,3,1},"Second"] supplied these exact second counts. 59 for(const [year,seconds] of [[1900,86400],[2000,172800],[2024,172800],[2026,86400]]){const v=snapshot();v.generated_at=`${year}-03-01T00:00:00Z`;v.agents[0].started_at=`${year}-02-28T00:00:00Z`;v.agents[0].observed_at=v.generated_at;assert(run(canonical(v)).includes(Buffer.from(`>${seconds}s`)));} 60 console.log('PASS renderer replay: escaper, Unicode, XSS, schema, limits, human roles, dates, deep tree and output pools'); 61 const value={schema_version:1,generated_at:'2026-10-26T01:00:00Z',sequence:'integration',poll_ms:1000,stale_after_ms:15000,agents:[],interactions:[],coverage:{label:'OMP',roots:0,agents:0,complete:false,notice:'Integration oracle'}}; 62 const directory=path.join(scratch,'receiver');fs.mkdirSync(directory,{recursive:true}); 63 const board=path.join(directory,'board.html'), live=path.join(directory,'live.json'), fail=path.join(directory,'fail-renderer'); 64 fs.writeFileSync(fail,'#!/bin/sh\nprintf incomplete\nexit 7\n',{mode:0o700});fs.writeFileSync(board,'old useful board'); 65 const env={...process.env,SSH_ORIGINAL_COMMAND:'hive-feed',HIVE_RENDER:fail}; 66 let r=execute(receiver,canonical(value),[directory],env);assert.equal(r.status,0);assert.equal(fs.readFileSync(board,'utf8'),'old useful board');assert(r.stderr.includes(Buffer.from('retained previous observation')));assert.deepEqual(JSON.parse(fs.readFileSync(live)),value);assert(!fs.readdirSync(directory).some(f=>f.startsWith('.board-tmp-'))); 67 env.HIVE_RENDER=binary;r=execute(receiver,canonical(value),[directory],env);assert.equal(r.status,0,r.stderr.toString());assert.equal(r.stderr.length,0);assert.deepEqual(fs.readFileSync(board),run(fs.readFileSync(live)));const before=fs.readFileSync(board); 68 for(const v of [{...value,schema_version:2},...['drake','user','guest'].map(role=>({...value,generated_at:'2026-10-26T02:00:00Z',sequence:'human-'+role,interactions:[{id:'m1',agent_id:'a1',role:'assistant',text:'Agent reply',at:value.generated_at,runtime:'OMP',provider:'unknown',model:'unknown'},{id:'m2',agent_id:'a1',role,text:'HUMAN_MESSAGE_CANARY',at:value.generated_at,runtime:'OMP',provider:'unknown',model:'unknown'}]}))]){r=execute(receiver,canonical(v),[directory],env);assert.notEqual(r.status,0);assert.deepEqual(fs.readFileSync(board),before);assert.deepEqual(JSON.parse(fs.readFileSync(live)),value);} 69 const overlap=path.join(scratch,'overlap');fs.mkdirSync(overlap,{recursive:true}); 70 const initial={...value,generated_at:'2026-10-26T00:00:00Z',sequence:'initial'},newest={...value,generated_at:'2026-10-26T02:00:00Z',sequence:'newest'},delayed={...value,generated_at:'2026-10-26T01:00:00Z',sequence:'delayed'}; 71 const stream=spawn(receiver,[overlap],{env,stdio:['pipe','pipe','pipe']});const finished=new Promise(resolve=>stream.on('close',resolve)); 72 try{stream.stdin.write(canonical(initial));let ready=false;for(let i=0;i<1000;i++){if(fs.existsSync(path.join(overlap,'board.html'))){ready=true;break;}await new Promise(resolve=>setTimeout(resolve,10));}assert(ready);r=execute(receiver,canonical(newest),[overlap],env);assert.equal(r.status,0);const newestBoard=fs.readFileSync(path.join(overlap,'board.html'));stream.stdin.end(canonical(delayed));const status=await Promise.race([finished,new Promise((_,reject)=>setTimeout(()=>reject(new Error('receiver timeout')),10000))]);assert.notEqual(status,0);assert.equal(JSON.parse(fs.readFileSync(path.join(overlap,'live.json'))).sequence,'newest');assert.deepEqual(fs.readFileSync(path.join(overlap,'board.html')),newestBoard);}finally{if(stream.exitCode===null)stream.kill('SIGTERM');} 73 console.log('PASS receiver replay: failed render retains board, valid publication, schema/human refusal, overlapping stream ordering'); 74 const cfg=fs.mkdtempSync(path.join(os.tmpdir(),'hive-config-control-')); 75 try { 76 const empty=path.join(cfg,'empty');fs.mkdirSync(empty); 77 const list=path.join(cfg,'own-emails.txt'); 78 for(const [name,kind,ok] of [['missing',null,true],['unreadable','dir',false],['empty','',true],['valid','owner@example.org\n',true]]) { 79 fs.rmSync(list,{recursive:true,force:true}); 80 if(kind==='dir')fs.mkdirSync(list);else if(kind!==null)fs.writeFileSync(list,kind); 81 const out=path.join(cfg,name+'.json'); 82 const args=['--once','--out',out,'--sessions',empty,'--claude',empty,'--codex',empty,'--own-emails',list,'--salt',path.join(cfg,'salt')]; 83 const result=execute(collector,'',args); 84 if(ok){assert.equal(result.status,0,result.stderr.toString());const value=JSON.parse(fs.readFileSync(out));assert.equal(value.interactions.length,0);assert(!JSON.stringify(value).includes(cfg));} 85 else{assert.notEqual(result.status,0);assert(!fs.existsSync(out));assert(!result.stderr.includes(Buffer.from(cfg)));} 86 } 87 } finally { fs.rmSync(cfg,{recursive:true,force:true}); } 88 console.log('PASS collector startup: unreadable own-email list refuses before publication; missing, empty and valid lists accepted');