char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somcut a bunch of code volumecb11725

main
1.4 KiB39 linesraw
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(
5  check: () => boolean | Promise<boolean>,
6  { timeout = 5_000, message = "timed out waiting" } = {},
7): Promise<void> {
8  const deadline = Date.now() + timeout;
9  while (!(await check())) {
10    if (Date.now() > deadline) throw new Error(message);
11    await 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(
17  options: Deno.MakeTempOptions = {},
18): Promise<{ path: string } & AsyncDisposable> {
19  const path = await Deno.realPath(await Deno.makeTempDir({ prefix: "berry-test-", ...options }));
20  return {
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 {
28  return (Deno.env.get("PATH") ?? "").split(":").some((dir) => {
29    try {
30      return Deno.statSync(`${dir}/${command}`).isFile;
31    } catch {
32      return false;
33    }
34  });
35}
36
37/** A valid 1×1 PNG, as base64. */
38export const PNG =
39  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z/D/PwAG/gL+DHWJ3gAAAABJRU5ErkJggg==";