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.3 KiB29 linesraw
1import { assertEquals } from "@std/assert";
2import { withBerry } from "./testing.ts";
3
4Deno.test("a first snapshot shows as its older entries arrive, and a later one only once it is whole", async () => {
5  await withBerry(async ({ server: { deliver } }) => {
6    const { watch } = await import("./client.ts");
7    deliver({ t: "ready" });
8    const topic = "conversation:a";
9    const seen: number[][] = [];
10    const release = watch<{ entries: { id: number }[] }>(topic, ({ entries }) => {
11      seen.push(entries.map((entry) => entry.id));
12    });
13    const entries = (...ids: number[]) => ids.map((id) => ({ id }));
14    deliver({ t: "snapshot", topic, value: { entries: entries(3) }, older: 2 });
15    deliver({ t: "older", topic, entries: entries(2) });
16    deliver({ t: "older", topic, entries: entries(1) });
17    assertEquals(seen, [[3], [2, 3], [1, 2, 3]]);
18
19    // as after a reconnect: the topic is asked for again, and has what it had meanwhile
20    deliver({ t: "ready" });
21    deliver({ t: "snapshot", topic, value: { entries: entries(4) }, older: 3 });
22    deliver({ t: "older", topic, entries: entries(2, 3) });
23    assertEquals(seen.length, 3);
24    deliver({ t: "older", topic, entries: entries(1) });
25    assertEquals(seen.at(-1), [1, 2, 3, 4]);
26    assertEquals(seen.length, 4);
27    release();
28  });
29});