char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Somtests: drop those that only pin what the UI shows, and assertions on its own wording6f4605c

main
2.5 KiB69 linesraw
1import { assertEquals, assertStringIncludes } from "@std/assert";
2import type { JsonValue } from "@berry/api";
3import type { ConfigurationContext } from "@berry/api/web.ts";
4import { fill, withDom } from "@berry/util/dom.ts";
5import renderers from "./web.tsx";
6
7const openrouter = { provider: "openrouter", modelId: "lab/model" };
8
9function harness(patch: Partial<ConfigurationContext> = {}) {
10  const view = renderers.configuration!();
11  document.body.append(view.element);
12  const saves: Record<string, JsonValue>[] = [];
13  let context: ConfigurationContext = {
14    tid: "3mxd6epszps5d",
15    extension: "openrouter-routing",
16    model: openrouter,
17    schema: { properties: {} },
18    values: { sort: "default", maxCompletionPrice: "1" },
19    saveStatus: "idle",
20    error: null,
21    save(patch) {
22      saves.push(patch);
23      return Promise.resolve();
24    },
25    renderDefault: () => {
26      throw new Error("The routing form is its own.");
27    },
28    ...patch,
29  };
30  const update = (patch: Partial<ConfigurationContext>) =>
31    view.update(context = { ...context, ...patch });
32  update({});
33  const control = (label: string) =>
34    [...view.element.querySelectorAll("label")]
35      .find((element) => element.textContent?.includes(label))!
36      .querySelector<HTMLInputElement & HTMLSelectElement>("input, select")!;
37  return { view, saves, update, control };
38}
39
40Deno.test("routing stages typed values and keeps a refused edit to fix", () =>
41  withDom(() => {
42    const { saves, update, control } = harness();
43    const price = control("Max output");
44    assertEquals(price.value, "1");
45    price.focus();
46    fill(price, "-0.5");
47    assertEquals(saves, [{ maxCompletionPrice: "-0.5" }]);
48    price.blur();
49    update({
50      error: "Output price must be a nonnegative decimal in $/M tokens.",
51    });
52    assertEquals(price.value, "-0.5");
53    assertStringIncludes(document.body.textContent!, "Output price must be");
54    update({ values: { sort: "price", maxCompletionPrice: "1" } });
55    assertEquals(control("Sort").value, "price");
56    assertEquals(price.value, "-0.5");
57  }));
58
59Deno.test("a new conversation's draft takes each keystroke", () =>
60  withDom(() => {
61    const { saves, control } = harness({ tid: null });
62    fill(control("Allowed"), "baseten/fast");
63    assertEquals(saves, [{ only: "baseten/fast" }]);
64  }));
65
66Deno.test("routing configuration events are hidden without suppressing unrelated events", () => {
67  assertEquals(renderers.event!({ type: "configured", values: { sort: "price" } }), null);
68  assertEquals(renderers.event!({ type: "other" }), undefined);
69});