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
3.7 KiB101 linesraw
1import { assert, assertEquals, assertMatch, assertNotEquals } from "@std/assert";
2import { join } from "node:path";
3import { tempDir } from "@berry/util";
4import { denoCheck } from "./loader.ts";
5import { extension, fixture, open, put } from "./loader-fixture.ts";
6
7Deno.test("a reload checks the files first, and a failure keeps the running version", () =>
8  fixture({
9    "good/mod.ts": extension("good"),
10    "good/version.ts": `export const VERSION = "one";`,
11  }, async (root) => {
12    const { loader, close, describe } = await open(root);
13    await loader.loadAll();
14
15    await Deno.writeTextFile(
16      join(root, "extensions/good/version.ts"),
17      `export const VERSION: number = "two";`,
18    );
19    const failed = await loader.reload("good");
20    assertEquals(failed.status, "failed");
21    assertMatch(failed.error!, /TS2322/);
22    assertEquals(describe("good"), "one");
23
24    // only the relative import changes: the fresh copy is what makes it load anew
25    await Deno.writeTextFile(
26      join(root, "extensions/good/version.ts"),
27      `export const VERSION = "three";`,
28    );
29    assertEquals((await loader.reload("good")).status, "loaded");
30    assertEquals(describe("good"), "three");
31    await close();
32  }));
33
34Deno.test("a frontend that fails to build keeps both halves as they were", () =>
35  fixture({
36    "good/mod.ts": extension("good"),
37    "good/version.ts": `export const VERSION = "one";`,
38    "good/web.tsx": `export default { tools: {} };`,
39  }, async (root) => {
40    const { loader, close, describe } = await open(root);
41    await loader.loadAll();
42    const built = loader.entries()[0].web;
43    assert(built !== null);
44
45    await Deno.writeTextFile(
46      join(root, "extensions/good/version.ts"),
47      `export const VERSION = "two";`,
48    );
49    await Deno.writeTextFile(
50      join(root, "extensions/good/web.tsx"),
51      `export default { tools: {} } as unknown as (;`,
52    );
53    assertEquals((await loader.reload("good")).status, "failed");
54    assertEquals(describe("good"), "one");
55    assertEquals(loader.entries()[0].web, built);
56
57    await Deno.writeTextFile(
58      join(root, "extensions/good/web.tsx"),
59      `export default { tools: { t: {} } };`,
60    );
61    const reloaded = await loader.reload("good");
62    assertEquals([reloaded.status, describe("good")], ["loaded", "two"]);
63    assertNotEquals(loader.entries()[0].web, built);
64    await close();
65  }));
66
67Deno.test("external extensions use Berry's dependencies for loading, checking, and frontend builds", () =>
68  fixture({}, async (root) => {
69    await using user = await tempDir();
70    await put(user.path, {
71      "personal/mod.ts": extension("personal"),
72      "personal/version.ts": 'export const VERSION = "one";',
73      "personal/web.tsx": `
74        import { Signal } from "@char/aftercare";
75        import { VERSION } from "./version.ts";
76        export default { signal: Signal, view: <b>{VERSION}</b> };
77      `,
78      "deno.json": JSON.stringify({ imports: { "@berry/api": "./missing.ts" } }),
79    });
80    const source = join(user.path, "personal");
81    const { loader, close, describe } = await open(root, [join(root, "extensions"), user.path]);
82    try {
83      await loader.loadAll();
84      assertEquals(describe("personal"), "one");
85      assertEquals(loader.entries()[0].directory, source);
86      assert(loader.entries()[0].web);
87      assertEquals(
88        new Set(loader.files()),
89        new Set([
90          join(source, "mod.ts"),
91          join(source, "web.tsx"),
92        ]),
93      );
94      assertEquals(await denoCheck(root, loader.files()), null);
95      await Deno.writeTextFile(join(source, "version.ts"), 'export const VERSION = "two";');
96      assertEquals((await loader.reload("personal")).status, "loaded");
97      assertEquals(describe("personal"), "two");
98    } finally {
99      await close();
100    }
101  }));