char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
cb11725
main
1import { assertEquals } from "@std/assert" ; 2import { withBerry } from "./testing.ts" ; 3 4Deno . test ( "a first snapshot shows as its older entries arrive, and a later one only once it is whole" , async () => { 5await withBerry ( async ({ server :{ deliver} }) => { 6const { watch} = await import ( "./client.ts" ); 7deliver ({ t :"ready" }); 8const topic = "conversation:a" ; 9const seen :number [][] = []; 10const release = watch <{ entries :{ id :number }[] }>( topic , ({ entries}) => { 11seen . push ( entries . map (( entry ) => entry . id )); 12}); 13const entries = ( ...ids :number []) => ids . map (( id ) => ({ id})); 14deliver ({ t :"snapshot" , topic, value :{ entries :entries ( 3 ) }, older :2 }); 15deliver ({ t :"older" , topic, entries :entries ( 2 ) }); 16deliver ({ t :"older" , topic, entries :entries ( 1 ) }); 17assertEquals ( seen , [[ 3 ], [ 2 , 3 ], [ 1 , 2 , 3 ]]); 18 19// as after a reconnect: the topic is asked for again, and has what it had meanwhile 20deliver ({ t :"ready" }); 21deliver ({ t :"snapshot" , topic, value :{ entries :entries ( 4 ) }, older :3 }); 22deliver ({ t :"older" , topic, entries :entries ( 2 , 3 ) }); 23assertEquals ( seen . length , 3 ); 24deliver ({ t :"older" , topic, entries :entries ( 1 ) }); 25assertEquals ( seen . at ( - 1 ), [ 1 , 2 , 3 , 4 ]); 26assertEquals ( seen . length , 4 ); 27release (); 28}); 29});