app
AI Flow
Public Made by Adomby adom
Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board.
main
John Lauer
Reuse the run webview, isolate fixture tests, and stream dashboard updates over SSE
97410b9
import fs from 'node:fs';
import vm from 'node:vm';
import assert from 'node:assert/strict';
const html=fs.readFileSync(new URL('../tools/timeline/index.html',import.meta.url),'utf8');
const code=html.slice(html.indexOf(' // One live page per run.'),html.indexOf('\n let rz = 0;'));
let channel,fetches=0,renders=0,presentations=[],status;
class EventSource {constructor(url){assert.equal(url,'events');channel=this;this.handlers={};}addEventListener(name,fn){this.handlers[name]=fn;}close(){this.closed=true;}}
const ctx={EventSource,JSON,Date,AbortSignal,SRC:'timeline.json',lastOkAt:0,lastRaw:null,model:null,everOk:false,
$:()=>({classList:{toggle(){}},querySelector:()=>({set textContent(v){status=v;}})}),
document:{body:{classList:{remove(){}}}},normalize:x=>x?.steps?x:null,render:()=>renders++,refreshPresentation:async p=>presentations.push(p),
setTimeout:()=>0,addEventListener(){},fetch:async()=>{fetches++;return {ok:true,json:async()=>({steps:['intake'],current:'intake'})};}};
vm.createContext(ctx);vm.runInContext(code+'\nglobalThis.transport=()=>liveChannel;',ctx);
const emit=state=>channel.handlers.state({data:JSON.stringify(state)});
const first={timeline:{steps:['thermal'],current:'thermal'},presentation:{caption:'Thermal open'}};
emit(first);assert.equal(ctx.transport(),'sse');assert.equal(renders,1);assert.equal(status,'Live');
emit(first);assert.equal(renders,1,'unchanged state must not rerender');
await ctx.poll();assert.equal(fetches,0,'connected SSE must not poll state or navigate');assert(presentations.length>=2);
emit({...first,presentation:{caption:'Current passed; thermal open'}});assert.equal(renders,1);assert.equal(presentations.at(-1).caption,'Current passed; thermal open');
emit({timeline:{steps:['thermal','fields'],current:'fields'}});assert.equal(renders,2);
channel.handlers.state({data:'{'});assert.equal(renders,2,'malformed event preserves last view');
channel.onerror();assert.equal(ctx.transport(),'reconnecting');await ctx.poll();assert.equal(fetches,1,'fallback remains available');
emit(first);assert.equal(ctx.transport(),'sse');assert.equal(ctx.model.current,'thermal');
console.log('PASS: relative SSE, in-place updates, no state polling while connected, presentation updates, reconnect and malformed-event preservation');