char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Somrestore queued messages to the composer on abort3d23fd2

main
2.2 KiB52 linesraw
1import { assertEquals } from "@std/assert";
2import type { SubmissionId } from "@earendil-works/pi-durable";
3import type { UserMessage } from "@earendil-works/pi-ai";
4import { IDBFactory } from "fake-indexeddb";
5import { PNG, until } from "@berry/util";
6import { withDom } from "@berry/util/dom.ts";
7import { stoppedInputs } from "./stopped-inputs.tsx";
8import { Scope } from "./ui.ts";
9
10Deno.test("stopped messages survive navigation and reload with attachments until restored or dismissed", async () => {
11  await withDom(async (window) => {
12    const tid = "stopped-drafts";
13    const content: UserMessage["content"] = [
14      { type: "text", text: "Keep the picture" },
15      { type: "image", mimeType: "image/png", data: PNG },
16    ];
17    const scope = new Scope();
18    const first = stoppedInputs(scope, tid, () => Promise.resolve(false), () => {});
19    document.body.append(first.element);
20    await first.recover([
21      { id: 1 as SubmissionId, mode: "steer", content },
22      { id: 2 as SubmissionId, mode: "followUp", content: "Another message" },
23    ]);
24    scope.dispose();
25    first.element.remove();
26
27    const fresh = await import(
28      new URL("./stopped-inputs.tsx?reload", import.meta.url).href
29    ) as typeof import("./stopped-inputs.tsx");
30    const restored: UserMessage["content"][] = [];
31    const reopenedScope = new Scope();
32    try {
33      const reopened = fresh.stoppedInputs(reopenedScope, tid, (value) => {
34        restored.push(value);
35        return Promise.resolve(true);
36      }, () => {});
37      document.body.append(reopened.element);
38      await until(() => reopened.element.querySelectorAll(".queued").length === 2);
39      reopened.element.querySelector<HTMLButtonElement>("button")!.click();
40      await until(() => reopened.element.querySelectorAll(".queued").length === 1);
41      assertEquals(restored, [content]);
42      const dismiss = [...reopened.element.querySelectorAll("button")].find((button) =>
43        button.textContent === "Dismiss"
44      )!;
45      dismiss.click();
46      await window.happyDOM.waitUntilComplete();
47      assertEquals(reopened.element.hidden, true);
48    } finally {
49      reopenedScope.dispose();
50    }
51  }, { globals: { indexedDB: new IDBFactory() } });
52});