char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
cb11725
main
1import { assertEquals , assertRejects } from "@std/assert" ; 2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context" ; 3import { ok } from "@earendil-works/pi-durable/env" ; 4import { localEnvironment } from "@berry/api/environment.ts" ; 5import { join , win32 } from "node:path" ; 6import { localOnly } from "./environment.ts" ; 7import { folders } from "./folders.ts" ; 8import { setup } from "./fixture.ts" ; 9import { tempDir } from "@berry/util" ; 10 11Deno . test ( "folder suggestions list only matching directories, including spaces, hidden folders, and directory symlinks" , async () => { 12await usingrootDir = await tempDir (); 13const root = rootDir . path ; 14for ( const name of [ "alpha" , "another folder" , ".hidden" , "Beta" ]) { 15await Deno . mkdir ( join ( root , name )); 16} 17await Deno . writeTextFile ( join ( root , "a-file" ), "" ); 18await Deno . symlink ( join ( root , "alpha" ), join ( root , "a-link" )); 19await Deno . symlink ( join ( root , "a-file" ), join ( root , "a-file-link" )); 20await Deno . symlink ( join ( root , "missing" ), join ( root , "a-broken" )); 21const env = localEnvironment ( root ); 22assertEquals ( await folders ( env , "a" , context ), [ "a-link/" , "alpha/" , "another folder/" ]); 23assertEquals ( await folders ( env , "." , context ), [ ".hidden/" ]); 24assertEquals ( await folders ( env , "b" , context ), []); 25assertEquals ( 26await folders ( env , ` ${ root } /a` , context ), 27[ "a-link" , "alpha" , "another folder" ]. map (( name ) => ` ${ root } / ${ name } /` ), 28); 29assertEquals ( await folders ( env , "alpha/" , context ), []); 30await assertRejects (() => folders ( env , "missing/" , context )); 31await assertRejects (() => folders ( env , "a\0" , context )); 32for ( let i = 0 ; i < 60 ; i ++ ) await Deno . mkdir ( join ( root , `many- ${ i } ` )); 33assertEquals (( await folders ( env , "many-" , context )). length , 50 ); 34}); 35 36Deno . test ( "folder completion uses the selected machine and base" , async () => { 37await usingrootDir = await tempDir (); 38const root = rootDir . path ; 39await Deno . mkdir ( join ( root , "remote-folder" )); 40await Deno . mkdir ( join ( root , "nested" )); 41await Deno . mkdir ( join ( root , "nested" , "child" )); 42await usingharness = await setup ({ 43open ( name , cwd , during ) { 44if ( name !== "other" ) return localOnly . open ( name , cwd , during ); 45return Promise . resolve ( Object . assign ( localEnvironment ( cwd ?? root ), { name, home :root })); 46}, 47close :() => Promise . resolve (), 48}); 49const { berry} = harness ; 50assertEquals ( await berry . folders ( "other" , null , "remote" ), [ "remote-folder/" ]); 51assertEquals ( await berry . folders ( "other" , join ( root , "nested" ), "c" ), [ "child/" ]); 52assertEquals ( await berry . folders ( "other" , null , "~/remote" ), [ ` ${ root } /remote-folder/` ]); 53await assertRejects (() => berry . folders ( "missing" , null , "" )); 54}); 55 56Deno . test ( "Windows suggestions use the remote machine's separators and case-insensitive prefixes" , async () => { 57const parents :string [] = []; 58const env = Object . assign ( localEnvironment ( "/" ), { 59platform :"win32" , 60home :"C:\\Users\\char" , 61absolutePath ( path :string ) { 62parents . push ( path ); 63return Promise . resolve ( ok ( win32 . resolve ( "C:\\Users\\char" , path ))); 64}, 65listDir :() => 66Promise . resolve ( ok ([ 67{ 68name :"Berry" , 69path :"C:\\Users\\char\\Berry" , 70kind :"directory" as const , 71size :0 , 72mtime :0 , 73}, 74{ 75name :"Book" , 76path :"C:\\Users\\char\\Book" , 77kind :"directory" as const , 78size :0 , 79mtime :0 , 80}, 81])), 82}); 83assertEquals ( await folders ( env , "b" , context ), [ "Berry\\" , "Book\\" ]); 84assertEquals ( await folders ( env , "~\\b" , context ), [ 85"C:\\Users\\char\\Berry\\" , 86"C:\\Users\\char\\Book\\" , 87]); 88assertEquals ( parents , [ "." , "C:\\Users\\char" ]); 89});