char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Somadd a /compact command to misc2c01ad9

main
2.2 KiB55 linesraw
1import { assertEquals } from "@std/assert";
2import type { PayloadHook } from "@berry/api";
3import { testExtension } from "@berry/api/testing.ts";
4import misc from "./mod.ts";
5
6type Model = Parameters<PayloadHook>[1];
7const codex = { provider: "openai-codex" } as unknown as Model;
8const other = { provider: "other" } as unknown as Model;
9
10Deno.test("compact starts a manual compaction, guided by any arguments", async () => {
11  const ext = testExtension(misc);
12  assertEquals(await ext.command("compact"), "Compacting context\u2026");
13  assertEquals(
14    await ext.command("compact", "  keep the failing test names  "),
15    "Compacting context\u2026",
16  );
17  assertEquals(ext.compactions, [undefined, "keep the failing test names"]);
18});
19
20Deno.test("oai-fast toggles fast mode for codex payloads only", async () => {
21  const ext = testExtension(misc);
22  assertEquals(await ext.payload({ a: 1 }, codex), { a: 1 });
23  assertEquals(await ext.command("oai-fast", ""), "OpenAI Codex fast mode enabled.");
24  assertEquals(await ext.payload({ a: 1 }, codex), { a: 1, service_tier: "priority" });
25  assertEquals(await ext.payload({ a: 1 }, other), { a: 1 });
26  assertEquals(await ext.payload("text", codex), "text");
27  assertEquals(await ext.command("oai-fast", ""), "OpenAI Codex fast mode disabled.");
28  assertEquals(await ext.payload({ a: 1 }, codex), { a: 1 });
29});
30
31Deno.test("oai-fast explicitly sets fast mode without toggling it", async () => {
32  const ext = testExtension(misc);
33  for (const mode of ["off", "on", "on", "off", "off"]) {
34    const enabled = mode === "on";
35    assertEquals(
36      await ext.command("oai-fast", ` ${mode} `),
37      `OpenAI Codex fast mode ${enabled ? "enabled" : "disabled"}.`,
38    );
39    assertEquals(
40      await ext.payload({}, codex),
41      enabled ? { service_tier: "priority" } : {},
42    );
43  }
44});
45
46Deno.test("oai-fast rejects invalid arguments without changing state", async () => {
47  const ext = testExtension(misc);
48  for (const mode of ["off", "on"]) {
49    await ext.command("oai-fast", mode);
50    for (const args of ["true", "on off", "onn"]) {
51      assertEquals(await ext.command("oai-fast", args), "Usage: /oai-fast [on|off]");
52      assertEquals(ext.state.oaiFast, mode === "on");
53    }
54  }
55});