char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
8744a75
main
1import { assertEquals , assertMatch , assertRejects , assertStringIncludes } from "@std/assert" ; 2import { localEnvironment } from "@berry/api/environment.ts" ; 3import { testExtension } from "@berry/api/testing.ts" ; 4import { tempDir } from "@berry/util" ; 5import code from "./mod.ts" ; 6 7Deno . test ( "editing modes change reads, diffs, and accepted edits without losing legacy state" , async () => { 8await usingroot = await tempDir (); 9const path = ` ${ root . path } /notes.txt` ; 10await Deno . writeTextFile ( path , "hello\nworld\n" ); 11const ext = testExtension ( code , { 12env :localEnvironment ( root . path ), 13events :[{ type :"cd" , cwd :"/old-directory" }], 14}); 15const before = await ext . call ( "read" , { path}) as string ; 16assertMatch ( before , / ^[A-Za-z]{4}│hello\n[A-Za-z]{4}│world$ / ); 17const anchor = before . split ( "│" )[ 0 ]; 18 19await ext . configure ({ editMode :"naive" }); 20assertEquals ( await ext . call ( "read" , { path}), "hello\nworld\n" ); 21assertEquals ( await ext . call ( "read" , { path, offset :2 , limit :1 }), "world\n" ); 22await assertRejects (() => ext . call ( "edit" , { path, edits :[{ old :[ anchor ], new :[ "bad" ] }] })); 23const diff = await ext . call ( "edit" , { 24 path, 25edits :[{ oldText :"hello" , newText :"hi" }], 26}) as string ; 27assertStringIncludes ( diff , "-hello\n+hi" ); 28assertEquals ( await Deno . readTextFile ( path ), "hi\nworld\n" ); 29 30await ext . configure ({ editMode :"hashline" }); 31const read = await ext . call ( "read" , { path}) as string ; 32assertMatch ( read , / ^[A-Za-z]{4}│hi / ); 33await assertRejects (() => 34ext . call ( "edit" , { 35 path, 36edits :[{ oldText :"hi" , newText :"bad" }], 37}) 38); 39const hashed = await ext . call ( "edit" , { 40 path, 41edits :[{ old :[ read . split ( "│" )[ 0 ]], new :[ "hey" ] }], 42}) as string ; 43assertMatch ( hashed , / \+[A-Za-z]{4}│hey / ); 44assertEquals ( await Deno . readTextFile ( path ), "hey\nworld\n" ); 45 46await Deno . writeTextFile ( path , "" ); 47await ext . configure ({ editMode :"naive" }); 48assertStringIncludes ( await ext . call ( "read" , { path}) as string , 'oldText: ""' ); 49await ext . call ( "edit" , { path, edits :[{ oldText :"" , newText :"seeded" }] }); 50assertEquals ( await Deno . readTextFile ( path ), "seeded" ); 51 52await Deno . writeTextFile ( path , "one\r\ntwo\nthree" ); 53const literal = await ext . call ( "read" , { path}) as string ; 54assertEquals ( literal , "one\r\ntwo\nthree" ); 55await ext . call ( "edit" , { path, edits :[{ oldText :literal , newText :"replaced" }] }); 56assertEquals ( await Deno . readTextFile ( path ), "replaced" ); 57});