interplane-mv
INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.
Brought by drakestapleton
interplane-mv / tests / hardware / transport.mjs
| 1 | import fs from 'node:fs'; |
| 2 | import {spawn,spawnSync} from 'node:child_process'; |
| 3 | import assert from 'node:assert/strict'; |
| 4 | import {intent,discovery} from './fixtures.mjs'; |
| 5 | const exe=process.cwd()+'/target/L558/hardware-map'; |
| 6 | const rows=[]; |
| 7 | async function fragmented(name,parts,expected) { |
| 8 | const c=spawn(exe,[],{stdio:['pipe','pipe','pipe','pipe']}); |
| 9 | let out=Buffer.alloc(0),err=Buffer.alloc(0); |
| 10 | c.stdout.on('data',b=>out=Buffer.concat([out,b]));c.stderr.on('data',b=>err=Buffer.concat([err,b])); |
| 11 | c.stdin.on('error',e=>{if(e.code!=='EPIPE')throw e;});c.stdio[3].on('error',e=>{if(e.code!=='EPIPE')throw e;}); |
| 12 | const result=new Promise((resolve,reject)=>{c.on('error',reject);c.on('close',(code,signal)=>resolve({code,signal}));}); |
| 13 | const timer=setTimeout(()=>c.kill('SIGKILL'),3000); |
| 14 | const r=intent(4),d=discovery(); |
| 15 | for(let i=0;i<96;i+=parts){c.stdin.write(r.subarray(i,i+parts));c.stdio[3].write(d.subarray(i,i+parts));await new Promise(ok=>setImmediate(ok));} |
| 16 | c.stdin.end();c.stdio[3].end(); |
| 17 | const status=await result;clearTimeout(timer);assert.equal(status.code,expected,err.toString());assert.equal(status.signal,null); |
| 18 | assert.equal(JSON.parse(out).capability,'hw_dma_map');assert.equal(err.length,0); |
| 19 | rows.push({name,exit:status.code,stdout_bytes:out.length}); |
| 20 | } |
| 21 | for(const size of [1,2,7,31])await fragmented('fragmented-'+size,size,0); |
| 22 | const path='target/L558/discovery.bin';fs.writeFileSync(path,discovery()); |
| 23 | let fd=fs.openSync(path,'r'); |
| 24 | const run=(name,args,expected)=>{const x=spawnSync(args[0],args.slice(1),{input:intent(),stdio:['pipe','pipe','pipe',fd],timeout:3000});assert.equal(x.error,undefined);assert.equal(x.status,expected,x.stderr?.toString());rows.push({name,exit:x.status,stdout_bytes:x.stdout.length});return x;}; |
| 25 | // Absence of host channel cannot be repaired with model bytes. |
| 26 | const nohost=spawnSync(exe,[],{input:intent(),timeout:3000});assert.equal(nohost.status,20);assert.equal(nohost.stdout.length,0);rows.push({name:'missing-trusted-channel',exit:nohost.status}); |
| 27 | fs.closeSync(fd);fd=fs.openSync(path,'r'); |
| 28 | // Inject failures into this child only. No signal or syscall reaches any other process. |
| 29 | run('stdin-EINTR',['strace','-qq','-o','target/L558/eintr.trace','-e','inject=read:error=EINTR:when=1',exe],0); |
| 30 | fs.closeSync(fd);fd=fs.openSync(path,'r'); |
| 31 | run('stdin-EIO',['strace','-qq','-o','target/L558/eio.trace','-e','inject=read:error=EIO:when=1',exe],20); |
| 32 | fs.closeSync(fd);fd=fs.openSync(path,'r'); |
| 33 | run('stdout-EIO',['strace','-qq','-o','target/L558/write-eio.trace','-e','inject=write:error=EIO:when=1',exe],29); |
| 34 | fs.closeSync(fd);fd=fs.openSync(path,'r'); |
| 35 | run('normal-syscall-trace',['strace','-qq','-o','qualification/evidence/L558/native-syscalls.log',exe],0); |
| 36 | fs.closeSync(fd); |
| 37 | const trace=fs.readFileSync('qualification/evidence/L558/native-syscalls.log','utf8'); |
| 38 | const syscalls=[...trace.matchAll(/^([a-z0-9_]+)\(/gm)].map(m=>m[1]); |
| 39 | assert(syscalls.every(s=>['execve','read','write','exit'].includes(s)),syscalls.join(',')); |
| 40 | fs.writeFileSync('qualification/evidence/L558/transport.json',JSON.stringify({cases:rows,observed_syscalls:[...new Set(syscalls)]},null,2)+'\n'); |
| 41 | console.log(`PASS ${rows.length} native transport/fault checks`); |