char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
3d23fd2
main
1import { assertEquals } from "@std/assert" ; 2import type { SubmissionId } from "@earendil-works/pi-durable" ; 3import type { UserMessage } from "@earendil-works/pi-ai" ; 4import { IDBFactory } from "fake-indexeddb" ; 5import { PNG , until } from "@berry/util" ; 6import { withDom } from "@berry/util/dom.ts" ; 7import { stoppedInputs } from "./stopped-inputs.tsx" ; 8import { Scope } from "./ui.ts" ; 9 10Deno . test ( "stopped messages survive navigation and reload with attachments until restored or dismissed" , async () => { 11await withDom ( async ( window ) => { 12const tid = "stopped-drafts" ; 13const content :UserMessage [ "content" ] = [ 14{ type :"text" , text :"Keep the picture" }, 15{ type :"image" , mimeType :"image/png" , data :PNG }, 16]; 17const scope = new Scope (); 18const first = stoppedInputs ( scope , tid , () => Promise . resolve ( false ), () => {}); 19document . body . append ( first . element ); 20await first . recover ([ 21{ id :1 as SubmissionId , mode :"steer" , content}, 22{ id :2 as SubmissionId , mode :"followUp" , content :"Another message" }, 23]); 24scope . dispose (); 25first . element . remove (); 26 27const fresh = await import ( 28new URL ( "./stopped-inputs.tsx?reload" , import . meta. url ). href 29) as typeof import ( "./stopped-inputs.tsx" ); 30const restored :UserMessage [ "content" ][] = []; 31const reopenedScope = new Scope (); 32try { 33const reopened = fresh . stoppedInputs ( reopenedScope , tid , ( value ) => { 34restored . push ( value ); 35return Promise . resolve ( true ); 36}, () => {}); 37document . body . append ( reopened . element ); 38await until (() => reopened . element . querySelectorAll ( ".queued" ). length === 2 ); 39reopened . element . querySelector < HTMLButtonElement >( "button" ) ! . click (); 40await until (() => reopened . element . querySelectorAll ( ".queued" ). length === 1 ); 41assertEquals ( restored , [ content ]); 42const dismiss = [ ...reopened . element . querySelectorAll ( "button" )]. find (( button ) => 43button . textContent === "Dismiss" 44) ! ; 45dismiss . click (); 46await window . happyDOM . waitUntilComplete (); 47assertEquals ( reopened . element . hidden , true ); 48} finally { 49reopenedScope . dispose (); 50} 51}, { globals :{ indexedDB :new IDBFactory () } }); 52});