char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
a4e772a
main
1import { assertEquals , assertStringIncludes } from "@std/assert" ; 2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context" ; 3import { getOrThrow } from "@earendil-works/pi-durable/env" ; 4import { testExtension } from "@berry/api/testing.ts" ; 5import { tempDir } from "@berry/util" ; 6import code from "../../extensions/code/mod.ts" ; 7import { skillsExtension } from "../../extensions/skills/mod.ts" ; 8import { activeDirectory , hostEnvironment , writeSkill } from "../../extensions/skills/testing.ts" ; 9import { BOOTSTRAP , Connection , RemoteEnvironment } from "./connection.ts" ; 10 11Deno . test ({ 12name : 13"host skills expose ordinary readable paths and executable scripts on a remote worker without running them at load time" , 14ignore :Deno . build . os === "windows" , 15}, async () => { 16await usinghome = await tempDir (); 17await usingtarget = await tempDir (); 18const host = hostEnvironment ( home . path ); 19const main = await writeSkill ( 20host , 21` ${ home . path } /.config/berry/skills` , 22"release" , 23"Read references/checklist.txt and run scripts/check.sh when asked." , 24); 25const source = main . slice ( 0 , - "/SKILL.md" . length ); 26getOrThrow ( 27await host . writeFile ( ` ${ source } /references/checklist.txt` , "Host-authored checklist." , context ), 28); 29getOrThrow ( 30await host . writeFile ( 31` ${ source } /scripts/check.sh` , 32'#!/bin/sh\nprintf "%s" "$BERRY_MACHINE" > executed\ncat executed\n' , 33context , 34), 35); 36await Deno . chmod ( ` ${ source } /scripts/check.sh` , 0o755 ); 37const connection = await Connection . open ( "skills-test" , [ 38"env" , 39"BERRY_MACHINE=skills-test" , 40`HOME= ${ target . path } ` , 41`XDG_CONFIG_HOME= ${ target . path } /config` , 42`XDG_CACHE_HOME= ${ target . path } /cache` , 43Deno . execPath (), 44"eval" , 45"--quiet" , 46BOOTSTRAP , 47]); 48const env = new RemoteEnvironment ( "skills-test" , connection , target . path ); 49const ext = testExtension ( skillsExtension ( host ), { env}); 50const files = testExtension ( code , { env}); 51try { 52assertStringIncludes ( await ext . prompt (), '"name":"release"' ); 53await ext . call ( "load_skill" , { name :"release" }); 54const directory = await activeDirectory ( env , await ext . prompt ()); 55assertEquals ( directory . startsWith ( ` ${ target . path } /` ), true ); 56assertStringIncludes ( 57await files . call ( "read" , { path :` ${ directory } /references/checklist.txt` }) as string , 58"Host-authored checklist." , 59); 60assertEquals ( await Deno . stat ( ` ${ home . path } /executed` ). catch (() => null ), null ); 61assertEquals ( getOrThrow ( await env . exists ( "executed" , context )), false ); 62const result = await files . call ( "bash" , { 63command :` ${ JSON . stringify ( directory + "/scripts/check.sh" )} ` , 64timeout :10 , 65}) as { output :string ; exitCode :number }; 66assertEquals ( result . exitCode , 0 ); 67assertEquals ( result . output , "skills-test" ); 68assertEquals ( getOrThrow ( await env . readTextFile ( "executed" , context )), "skills-test" ); 69assertEquals ( await Deno . stat ( ` ${ home . path } /executed` ). catch (() => null ), null ); 70} finally { 71await ext . dispose (); 72await files . dispose (); 73await connection . close (); 74} 75});