char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Sommisc: disable the context cap by defaulta988092

main
2.2 KiB55 linesraw
1import { assert, assertEquals, assertStringIncludes } from "@std/assert";
2import { testExtension } from "@berry/api/testing.ts";
3import misc from "./mod.ts";
4
5// the cap is server-wide module state, so each test sets what it needs first,
6// except this one, which runs on the fresh import and pins the default
7Deno.test("the context cap is off by default", () => {
8  assertEquals(testExtension(misc).compactionCap, undefined);
9});
10
11Deno.test("the threshold and background offset are tunable", async () => {
12  const harness = testExtension(misc);
13  const report = await harness.command("context-cap", "131072 16384");
14  assertEquals(harness.compactionCap, { maxContextTokens: 131_072, backgroundTokens: 16_384 });
15  assertStringIncludes(report as string, "131072");
16  assertStringIncludes(report as string, "114688");
17});
18
19Deno.test("counts accept k and m suffixes, so 2^18 reads 256k", async () => {
20  const harness = testExtension(misc);
21  await harness.command("context-cap", "256k 32k");
22  assertEquals(
23    harness.compactionCap,
24    { maxContextTokens: 262_144, backgroundTokens: 32_768 },
25  );
26  await harness.command("context-cap", "1m");
27  assertEquals(harness.compactionCap?.maxContextTokens, 1_048_576);
28});
29
30Deno.test("counts it cannot parse leave the cap alone", async () => {
31  const harness = testExtension(misc);
32  await harness.command("context-cap", "100000 1000");
33  const before = harness.compactionCap;
34  let failed = 0;
35  for (const args of ["soon", "-5", "0", "100000 soon", "1 2 3", "1000 2000"]) {
36    try {
37      await harness.command("context-cap", args);
38    } catch {
39      failed++;
40    }
41  }
42  assertEquals(failed, 6);
43  assertEquals(harness.compactionCap, before);
44});
45
46Deno.test("the cap switches off and back on", async () => {
47  const harness = testExtension(misc);
48  await harness.command("context-cap", "100000 1000");
49  assert(await harness.command("context-cap", "off"));
50  assertEquals(harness.compactionCap, undefined);
51  const report = await harness.command("context-cap", "on");
52  assertEquals(harness.compactionCap, { maxContextTokens: 100_000, backgroundTokens: 1_000 });
53  assertStringIncludes(report as string, "100000");
54  await harness.command("context-cap", "256k 32k");
55});