char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
c5dd844
main
1import { assertEquals } from "@std/assert" ; 2import { EditorView } from "@codemirror/view" ; 3import { until } from "@berry/util" ; 4import { withDom } from "@berry/util/dom.ts" ; 5import { highlighting } from "./highlight.ts" ; 6 7Deno . test ( "highlight replies decorate the current text across lines without moving selection or applying stale tokens" , () => 8withDom ( async () => { 9const replies :{ source :string ; resolve ( lines :Node [][]) :void }[] = []; 10const parent = document . createElement ( "div" ); 11document . body . append ( parent ); 12const view = new EditorView ({ 13 parent, 14doc :"old\nname" , 15extensions :[ highlighting ( "a.ts" , ( source ) => 16new Promise (( resolve ) => { 17replies . push ({ source, resolve}); 18}))], 19}); 20const lit = ( a :string , b :string ) => { 21const keyword = document . createElement ( "a-k" ); 22keyword . textContent = a ; 23const name = document . createElement ( "a-vm" ); 24name . textContent = b ; 25return [[ keyword ], [ name ]]; 26}; 27try { 28await until (() => replies . length === 1 ); 29view . dispatch ({ 30changes :{ from :0 , to :view . state . doc . length , insert :"new\nother" }, 31selection :{ anchor :6 }, 32}); 33await until (() => replies . length === 2 ); 34replies [ 1 ]. resolve ( lit ( "new" , "other" )); 35await until (() => !! parent . querySelector ( "a-k" )); 36replies [ 0 ]. resolve ( lit ( "old" , "name" )); 37await Promise . resolve (); 38assertEquals ( parent . querySelector ( "a-k" ) ! . textContent , "new" ); 39assertEquals ( parent . querySelector ( "a-vm" ) ! . textContent , "other" ); 40assertEquals ( view . state . doc . toString (), "new\nother" ); 41assertEquals ( view . state . selection . main . anchor , 6 ); 42} finally { 43view . destroy (); 44} 45}));