char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Somtests: split the slowest files so that --parallel runs them side by sidebe80d8a

main
2.0 KiB50 linesraw
1// Extension roots on disk for the loader's tests, and a berry loading them.
2
3import { join } from "node:path";
4import { createModels } from "@earendil-works/pi-ai/models";
5import { MemoryStorage } from "@earendil-works/pi-durable";
6import { tempDir } from "@berry/util";
7import { openBerry } from "./berry.ts";
8import { extensionLoader } from "./loader.ts";
9import { extensionWeb } from "./web.ts";
10
11/** An extension's source, whose description is its `VERSION`. */
12export const extension = (
13  name: string,
14  description = `import { VERSION } from "./version.ts";`,
15  sortOrder?: number,
16) =>
17  `import { defineExtension } from "@berry/api";
18${description}
19export default defineExtension({ name: ${JSON.stringify(name)}, description: VERSION, ${
20    sortOrder === undefined ? "" : `sortOrder: ${sortOrder}, `
21  }initial: () => null, setup() {} });
22`;
23
24/** Write these files under `directory`. */
25export async function put(directory: string, files: Record<string, string>) {
26  for (const [path, text] of Object.entries(files)) {
27    await Deno.mkdir(join(directory, path, ".."), { recursive: true });
28    await Deno.writeTextFile(join(directory, path), text);
29  }
30}
31
32/** A berry root with the given extension files, inside the repo so that `deno check` finds its deno.json. */
33export async function fixture(files: Record<string, string>, run: (root: string) => Promise<void>) {
34  await using rootDir = await tempDir({ dir: Deno.cwd(), prefix: ".loader-test-" });
35  const root = rootDir.path;
36  await put(join(root, "extensions"), files);
37  await run(root);
38}
39
40/** A berry whose loader reads `root`, or these `directories`. */
41export async function open(root: string, directories?: readonly string[], web = extensionWeb()) {
42  const berry = await openBerry(new MemoryStorage(), createModels());
43  const loader = extensionLoader({ berry, web, root, directories });
44  const close = async () => {
45    await loader.close();
46    await berry.close();
47  };
48  const describe = (name: string) => berry.extensions().find((e) => e.name === name)?.description;
49  return { berry, loader, close, describe };
50}