char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
be80d8a
main
1import { assert , assertEquals , assertStringIncludes } from "@std/assert" ; 2import { join } from "node:path" ; 3import { tempDir , until } from "@berry/util" ; 4import { extension , fixture , open , put } from "./loader-fixture.ts" ; 5 6Deno . test ( "duplicate names fail without choosing a directory and recover when the collision is removed" , () => 7fixture ({ 8"same/mod.ts" :extension ( "same" ), 9"same/version.ts" :'export const VERSION = "shipped";' , 10}, async ( root ) => { 11await usinguser = await tempDir (); 12await put ( user . path , { 13"same/mod.ts" :extension ( "same" ), 14"same/version.ts" :'export const VERSION = "personal";' , 15}); 16const shipped = join ( root , "extensions" ); 17const { loader, close, describe} = await open ( root , [ shipped , user . path ]); 18try { 19await loader . loadAll (); 20const [ entry ] = loader . entries (); 21assertEquals ( entry . status , "failed" ); 22assertEquals ( entry . running , false ); 23assertEquals ( entry . directory , null ); 24assertEquals ( describe ( "same" ), undefined ); 25assertStringIncludes ( entry . error ! , join ( shipped , "same" )); 26assertStringIncludes ( entry . error ! , join ( user . path , "same" )); 27await Deno . remove ( join ( user . path , "same" ), { recursive :true }); 28assertEquals (( await loader . reload ( "same" )). status , "loaded" ); 29assertEquals ( describe ( "same" ), "shipped" ); 30} finally { 31await close (); 32} 33})); 34 35Deno . test ( "both roots hot-reload additions, edits, collisions, and removals even if a root starts absent" , () => 36fixture ({}, async ( root ) => { 37await usinguser = await tempDir (); 38const personal = join ( user . path , "extensions" ); 39const shipped = join ( root , "extensions" ); 40const { loader, close, describe} = await open ( root , [ shipped , personal ]); 41try { 42await loader . loadAll (); 43loader . watch (); 44await put ( personal , { 45"added/mod.ts" :extension ( "added" ), 46"added/version.ts" :'export const VERSION = "one";' , 47}); 48await until (() => describe ( "added" ) === "one" , { timeout :10_000 }); 49await Deno . writeTextFile ( join ( personal , "added/version.ts" ), 'export const VERSION = "two";' ); 50await until (() => describe ( "added" ) === "two" , { timeout :10_000 }); 51await put ( shipped , { 52"added/mod.ts" :extension ( "added" ), 53"added/version.ts" :'export const VERSION = "shadow";' , 54}); 55await until (() => loader . entries ()[ 0 ]?. status === "failed" , { timeout :10_000 }); 56assertEquals ( describe ( "added" ), "two" ); 57assert ( loader . entries ()[ 0 ]. running ); 58await Deno . remove ( join ( shipped , "added" ), { recursive :true }); 59await until (() => loader . entries ()[ 0 ]?. status === "loaded" , { timeout :10_000 }); 60await Deno . remove ( join ( personal , "added" ), { recursive :true }); 61await until (() => describe ( "added" ) === undefined , { timeout :10_000 }); 62assertEquals ( loader . entries (), []); 63} finally { 64await close (); 65} 66}));