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.9 KiB66 linesraw
1import { assert, assertEquals, assertStringIncludes } from "@std/assert";
2import { join } from "node:path";
3import { tempDir, until } from "@berry/util";
4import { extension, fixture, open, put } from "./loader-fixture.ts";
5
6Deno.test("duplicate names fail without choosing a directory and recover when the collision is removed", () =>
7  fixture({
8    "same/mod.ts": extension("same"),
9    "same/version.ts": 'export const VERSION = "shipped";',
10  }, async (root) => {
11    await using user = await tempDir();
12    await put(user.path, {
13      "same/mod.ts": extension("same"),
14      "same/version.ts": 'export const VERSION = "personal";',
15    });
16    const shipped = join(root, "extensions");
17    const { loader, close, describe } = await open(root, [shipped, user.path]);
18    try {
19      await loader.loadAll();
20      const [entry] = loader.entries();
21      assertEquals(entry.status, "failed");
22      assertEquals(entry.running, false);
23      assertEquals(entry.directory, null);
24      assertEquals(describe("same"), undefined);
25      assertStringIncludes(entry.error!, join(shipped, "same"));
26      assertStringIncludes(entry.error!, join(user.path, "same"));
27      await Deno.remove(join(user.path, "same"), { recursive: true });
28      assertEquals((await loader.reload("same")).status, "loaded");
29      assertEquals(describe("same"), "shipped");
30    } finally {
31      await close();
32    }
33  }));
34
35Deno.test("both roots hot-reload additions, edits, collisions, and removals even if a root starts absent", () =>
36  fixture({}, async (root) => {
37    await using user = await tempDir();
38    const personal = join(user.path, "extensions");
39    const shipped = join(root, "extensions");
40    const { loader, close, describe } = await open(root, [shipped, personal]);
41    try {
42      await loader.loadAll();
43      loader.watch();
44      await put(personal, {
45        "added/mod.ts": extension("added"),
46        "added/version.ts": 'export const VERSION = "one";',
47      });
48      await until(() => describe("added") === "one", { timeout: 10_000 });
49      await Deno.writeTextFile(join(personal, "added/version.ts"), 'export const VERSION = "two";');
50      await until(() => describe("added") === "two", { timeout: 10_000 });
51      await put(shipped, {
52        "added/mod.ts": extension("added"),
53        "added/version.ts": 'export const VERSION = "shadow";',
54      });
55      await until(() => loader.entries()[0]?.status === "failed", { timeout: 10_000 });
56      assertEquals(describe("added"), "two");
57      assert(loader.entries()[0].running);
58      await Deno.remove(join(shipped, "added"), { recursive: true });
59      await until(() => loader.entries()[0]?.status === "loaded", { timeout: 10_000 });
60      await Deno.remove(join(personal, "added"), { recursive: true });
61      await until(() => describe("added") === undefined, { timeout: 10_000 });
62      assertEquals(loader.entries(), []);
63    } finally {
64      await close();
65    }
66  }));