char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
f94442c
main
1import { assertEquals } from "@std/assert" ; 2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context" ; 3import { projectFor } from "@berry/api/projects.ts" ; 4import { onPath , tempDir } from "@berry/util" ; 5import { join } from "node:path" ; 6import code from "../extensions/code/mod.ts" ; 7import { type Environments , localOnly } from "./environment.ts" ; 8import { setup } from "./fixture.ts" ; 9import { Projects } from "./projects.ts" ; 10 11Deno . test ({ 12name : 13"workspace inherits the source directory's project on its machine without changing the default" , 14ignore :! onPath ( "jj" ), 15async fn () { 16await usingroot = await tempDir (); 17const repo = join ( root . path , "repo" ); 18const config = join ( root . path , "config.toml" ); 19await Deno . writeTextFile ( config , '[user]\nname = "Test"\nemail = "test@example.com"\n' ); 20const variables = { 21 ...Deno . env . toObject (), 22JJ_CONFIG :config , 23BERRY_WORKSPACES_DIR :join ( root . path , "workspaces" ), 24}; 25const jj = async ( ...args :string []) => { 26const result = await new Deno . Command ( "jj" , { 27args :[ "--no-pager" , "--color=never" , ...args ], 28cwd :root . path , 29env :variables , 30stdout :"piped" , 31stderr :"piped" , 32}). output (); 33assertEquals ( result . success , true , new TextDecoder (). decode ( result . stderr )); 34}; 35await jj ( "git" , "init" , repo ); 36await Deno . writeTextFile ( join ( repo , "baseline" ), "base\n" ); 37await jj ( "-R" , repo , "new" ); 38const src = join ( repo , "src" ); 39const outside = join ( root . path , "outside" ); 40await Deno . mkdir ( src ); 41await Deno . mkdir ( outside ); 42const environments :Environments = { 43async open ( name , cwd , during ) { 44const env = await localOnly . open ( "local" , cwd , during ); 45Object . defineProperty ( env , "variables" , { value :variables }); 46return Object . assign ( env , { name}); 47}, 48close :() => Promise . resolve (), 49}; 50await usingharness = await setup ( environments ); 51const { berry} = harness ; 52await berry . install ( code ); 53const local = await berry . saveProject ( undefined , { 54name :"Local" , 55roots :[{ environment :"local" , cwd :repo }], 56defaultRoot :0 , 57}); 58const broad = await berry . saveProject ( undefined , { 59name :"Broad" , 60roots :[{ environment :"other" , cwd :root . path }], 61defaultRoot :0 , 62}); 63const project = await berry . saveProject ( undefined , { 64name :"Repo" , 65roots :[{ environment :"other" , cwd :repo }], 66defaultRoot :0 , 67}); 68const before = ( await berry . harness . snapshot ( Projects , context )) ! ; 69const tid = await berry . create ({ 70extensions :{ code :{}, environment :{ environment :"other" , cwd :src } }, 71}); 72const target = await berry . command ( tid , "workspace" , "" ) as string ; 73const after = ( await berry . harness . snapshot ( Projects , context )) ! ; 74assertEquals ( after [ project ], { 75 ...before [ project ], 76roots :[ ...before [ project ]. roots , { 77environment :"other" , 78cwd :target , 79platform :before [ project ]. roots [ 0 ]. platform , 80}], 81}); 82assertEquals ( after [ local ], before [ local ]); 83assertEquals ( after [ broad ], before [ broad ]); 84const binding = await berry . state ( tid , "environment" ) as { environment :string ; cwd :string }; 85assertEquals ( binding . cwd , target ); 86assertEquals ( projectFor ( after , binding ), project ); 87assertEquals ( await berry . command ( tid , "workspace" , "" ), target ); 88await berry . command ( tid , "cd" , src ); 89assertEquals ( await berry . command ( tid , "workspace" , "" ), target ); 90await berry . command ( tid , "cd" , outside ); 91assertEquals ( await berry . harness . snapshot ( Projects , context ), after ); 92 93const unassigned = await berry . create ({ extensions :{ code :{}, environment :{ cwd :src } } }); 94await berry . deleteProject ( local ); 95const withoutLocal = ( await berry . harness . snapshot ( Projects , context )) ! ; 96await berry . command ( unassigned , "workspace" , "" ); 97assertEquals ( await berry . harness . snapshot ( Projects , context ), withoutLocal ); 98}, 99});