char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
be80d8a
main
1import { assert , assertEquals , assertMatch , assertNotEquals } from "@std/assert" ; 2import { join } from "node:path" ; 3import { tempDir } from "@berry/util" ; 4import { denoCheck } from "./loader.ts" ; 5import { extension , fixture , open , put } from "./loader-fixture.ts" ; 6 7Deno . test ( "a reload checks the files first, and a failure keeps the running version" , () => 8fixture ({ 9"good/mod.ts" :extension ( "good" ), 10"good/version.ts" :`export const VERSION = "one";` , 11}, async ( root ) => { 12const { loader, close, describe} = await open ( root ); 13await loader . loadAll (); 14 15await Deno . writeTextFile ( 16join ( root , "extensions/good/version.ts" ), 17`export const VERSION: number = "two";` , 18); 19const failed = await loader . reload ( "good" ); 20assertEquals ( failed . status , "failed" ); 21assertMatch ( failed . error ! , / TS2322 / ); 22assertEquals ( describe ( "good" ), "one" ); 23 24// only the relative import changes: the fresh copy is what makes it load anew 25await Deno . writeTextFile ( 26join ( root , "extensions/good/version.ts" ), 27`export const VERSION = "three";` , 28); 29assertEquals (( await loader . reload ( "good" )). status , "loaded" ); 30assertEquals ( describe ( "good" ), "three" ); 31await close (); 32})); 33 34Deno . test ( "a frontend that fails to build keeps both halves as they were" , () => 35fixture ({ 36"good/mod.ts" :extension ( "good" ), 37"good/version.ts" :`export const VERSION = "one";` , 38"good/web.tsx" :`export default { tools: {} };` , 39}, async ( root ) => { 40const { loader, close, describe} = await open ( root ); 41await loader . loadAll (); 42const built = loader . entries ()[ 0 ]. web ; 43assert ( built !== null ); 44 45await Deno . writeTextFile ( 46join ( root , "extensions/good/version.ts" ), 47`export const VERSION = "two";` , 48); 49await Deno . writeTextFile ( 50join ( root , "extensions/good/web.tsx" ), 51`export default { tools: {} } as unknown as (;` , 52); 53assertEquals (( await loader . reload ( "good" )). status , "failed" ); 54assertEquals ( describe ( "good" ), "one" ); 55assertEquals ( loader . entries ()[ 0 ]. web , built ); 56 57await Deno . writeTextFile ( 58join ( root , "extensions/good/web.tsx" ), 59`export default { tools: { t: {} } };` , 60); 61const reloaded = await loader . reload ( "good" ); 62assertEquals ([ reloaded . status , describe ( "good" )], [ "loaded" , "two" ]); 63assertNotEquals ( loader . entries ()[ 0 ]. web , built ); 64await close (); 65})); 66 67Deno . test ( "external extensions use Berry's dependencies for loading, checking, and frontend builds" , () => 68fixture ({}, async ( root ) => { 69await usinguser = await tempDir (); 70await put ( user . path , { 71"personal/mod.ts" :extension ( "personal" ), 72"personal/version.ts" :'export const VERSION = "one";' , 73"personal/web.tsx" :` 74import { Signal } from "@char/aftercare"; 75import { VERSION } from "./version.ts"; 76export default { signal: Signal, view: <b>{VERSION}</b> }; 77` , 78"deno.json" :JSON . stringify ({ imports :{ "@berry/api" :"./missing.ts" } }), 79}); 80const source = join ( user . path , "personal" ); 81const { loader, close, describe} = await open ( root , [ join ( root , "extensions" ), user . path ]); 82try { 83await loader . loadAll (); 84assertEquals ( describe ( "personal" ), "one" ); 85assertEquals ( loader . entries ()[ 0 ]. directory , source ); 86assert ( loader . entries ()[ 0 ]. web ); 87assertEquals ( 88new Set ( loader . files ()), 89new Set ([ 90join ( source , "mod.ts" ), 91join ( source , "web.tsx" ), 92]), 93); 94assertEquals ( await denoCheck ( root , loader . files ()), null ); 95await Deno . writeTextFile ( join ( source , "version.ts" ), 'export const VERSION = "two";' ); 96assertEquals (( await loader . reload ( "personal" )). status , "loaded" ); 97assertEquals ( describe ( "personal" ), "two" ); 98} finally { 99await close (); 100} 101}));