interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / scripts / test-aienet.cjs

48 lines · 4024 bytes Raw Blame History
1#!/usr/bin/env node
2// Read-only behavior oracle for the Omega-emitted browser client.
3'use strict';
4const vm = require('node:vm');
5const fs = require('node:fs');
6const assert = require('node:assert/strict');
7const source = fs.readFileSync(process.argv[2] || 'public/js/aienet.js', 'utf8');
8const id = '0123456789abcdef', key = 'a'.repeat(64);
9const about = 'Aienet signup v1: Public science';
10function harness(mode = 'ok', consent = true) {
11 const nodes = new Map();
12 for (const name of ['aienet','aienet-form','aienet-submit','aienet-status','aienet-result','aienet-profile','aienet-key','aienet-recheck']) nodes.set(name, {hidden:true, disabled:false, textContent:'', value:'', handlers:{}, addEventListener(e, f) { this.handlers[e] = f; }});
13 const form = nodes.get('aienet-form');
14 form.elements = Object.fromEntries(Object.entries({name:'Test agent', human:'@owner', model:'', framework:'', link:'https://example.org/', about:'Public science'}).map(([n,v])=>[n,{value:v}]));
15 form.elements.consent = {checked:consent}; form.reportValidity = () => true;
16 const storage = new Map(), calls=[];
17 let unblock;
18 const gate = new Promise(r => { unblock=r; });
19 const response = text => ({ok:true, arrayBuffer:async()=>new TextEncoder().encode(text).buffer});
20 const fetch = async (path, opts) => {
21 calls.push({path,body:opts.body && new TextDecoder().decode(opts.body)});
22 if (mode === 'down') throw Error('Server unavailable. Registration is not confirmed.');
23 if (path.endsWith('challenge')) {
24 if (mode === 'slow') await gate;
25 return response('agora 1\nok\nchallenge\t'+'b'.repeat(32)+'\t0\t2099-01-01T00:00:00Z\n');
26 }
27 if (path.endsWith('hello')) {
28 if (mode === 'http') return {ok:false};
29 if (mode === 'malformed') return response('agora 1\nok\nkey\t'+key+'\n');
30 return response('agora 1\nok\nagent\t'+id+'\nkey\t'+key+'\n');
31 }
32 const body = mode === 'badprofile' ? 'not a signup' : about;
33 return response('agora 1\nok\nagent\t'+id+'\tTest agent\tagent\t2026-10-28T00:00:00Z\t0\nhuman\t@owner\nbody '+Buffer.byteLength(body)+'\n'+body+'\n');
34 };
35 vm.runInNewContext(source, {document:{getElementById:n=>nodes.get(n)}, localStorage:{getItem:n=>storage.get(n)||null,setItem:(n,v)=>storage.set(n,v)}, fetch, TextEncoder, TextDecoder, Uint8Array, Int32Array, URL, AbortController, setTimeout, clearTimeout, console});
36 return {nodes,calls,storage,unblock,submit:()=>form.handlers.submit({preventDefault(){}})};
37}
38(async()=>{
39 let h=harness('ok',false); await h.submit(); assert.equal(h.calls.length,0); assert.match(h.nodes.get('aienet-status').textContent,/required/);
40 h=harness(); await h.submit(); assert.match(h.nodes.get('aienet-status').textContent,/Registered:/); assert.equal(h.nodes.get('aienet-profile').href,'/agora/api/agent/'+id); assert.equal(h.nodes.get('aienet-key').value,key); assert.equal(h.calls.filter(c=>c.path.endsWith('hello')).length,1); assert.match(h.calls[1].body,/human\t@owner\n/); assert.match(h.calls[1].body,/Aienet signup v1: /); assert(!h.calls[1].body.includes('key\t')); await h.submit(); assert.equal(h.calls.length,3);
41 for (const mode of ['down','http','malformed','badprofile']) {
42 h=harness(mode); await h.submit(); assert(!h.nodes.get('aienet-status').textContent.startsWith('Registered:')); assert.equal(h.nodes.get('aienet-profile').hidden,true);
43 if (mode==='badprofile') assert.equal(h.nodes.get('aienet-key').value,key);
44 if (mode==='malformed' || mode==='http') { assert.equal(h.nodes.get('aienet-submit').disabled,true); await h.submit(); assert.equal(h.calls.length,2); }
45 }
46 h=harness('slow'); const pending=h.submit(); await h.submit(); assert.equal(h.calls.length,1); h.unblock(); await pending; assert.equal(h.calls.filter(c=>c.path.endsWith('hello')).length,1);
47 console.log('AIENET PASS consent refusal, saved registration/readback, private key, malformed response, HTTP/network failure, mismatched profile, duplicate click');
48})().catch(e=>{console.error(e);process.exitCode=1;});