char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
cb11725
main
1// What berry's tests share, wherever they are: an extension's tests may import it too, as a bare specifier. 2 3/** Wait for `check` to hold, failing after `timeout` milliseconds. */ 4export async function until ( 5check :() => boolean | Promise < boolean >, 6{ timeout= 5_000 , message= "timed out waiting" } = {}, 7) :Promise < void > { 8const deadline = Date . now () + timeout ; 9while ( ! ( await check ())) { 10if ( Date . now () > deadline ) throw new Error ( message ); 11await new Promise (( resolve ) => setTimeout ( resolve , 5 )); 12} 13} 14 15/** A temporary directory, by its real path, gone once its `await using` scope ends. */ 16export async function tempDir ( 17options :Deno . MakeTempOptions = {}, 18) :Promise <{ path :string } & AsyncDisposable > { 19const path = await Deno . realPath ( await Deno . makeTempDir ({ prefix :"berry-test-" , ...options })); 20return { 21 path, 22[ Symbol . asyncDispose ] :() => Deno . remove ( path , { recursive :true }). catch (() => {}), 23}; 24} 25 26/** Whether `command` is on this machine's PATH, for skipping tests that need it. */ 27export function onPath ( command :string ) :boolean { 28return ( Deno . env . get ( "PATH" ) ?? "" ). split ( ":" ). some (( dir ) => { 29try { 30return Deno . statSync ( ` ${ dir } / ${ command } ` ). isFile ; 31} catch { 32return false ; 33} 34}); 35} 36 37/** A valid 1×1 PNG, as base64. */ 38export const PNG = 39"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z/D/PwAG/gL+DHWJ3gAAAABJRU5ErkJggg==" ;