char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
a988092
main
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" , () => { 8assertEquals ( testExtension ( misc ). compactionCap , undefined ); 9}); 10 11Deno . test ( "the threshold and background offset are tunable" , async () => { 12const harness = testExtension ( misc ); 13const report = await harness . command ( "context-cap" , "131072 16384" ); 14assertEquals ( harness . compactionCap , { maxContextTokens :131_072 , backgroundTokens :16_384 }); 15assertStringIncludes ( report as string , "131072" ); 16assertStringIncludes ( report as string , "114688" ); 17}); 18 19Deno . test ( "counts accept k and m suffixes, so 2^18 reads 256k" , async () => { 20const harness = testExtension ( misc ); 21await harness . command ( "context-cap" , "256k 32k" ); 22assertEquals ( 23harness . compactionCap , 24{ maxContextTokens :262_144 , backgroundTokens :32_768 }, 25); 26await harness . command ( "context-cap" , "1m" ); 27assertEquals ( harness . compactionCap ?. maxContextTokens , 1_048_576 ); 28}); 29 30Deno . test ( "counts it cannot parse leave the cap alone" , async () => { 31const harness = testExtension ( misc ); 32await harness . command ( "context-cap" , "100000 1000" ); 33const before = harness . compactionCap ; 34let failed = 0 ; 35for ( const args of [ "soon" , "-5" , "0" , "100000 soon" , "1 2 3" , "1000 2000" ]) { 36try { 37await harness . command ( "context-cap" , args ); 38} catch { 39failed ++ ; 40} 41} 42assertEquals ( failed , 6 ); 43assertEquals ( harness . compactionCap , before ); 44}); 45 46Deno . test ( "the cap switches off and back on" , async () => { 47const harness = testExtension ( misc ); 48await harness . command ( "context-cap" , "100000 1000" ); 49assert ( await harness . command ( "context-cap" , "off" )); 50assertEquals ( harness . compactionCap , undefined ); 51const report = await harness . command ( "context-cap" , "on" ); 52assertEquals ( harness . compactionCap , { maxContextTokens :100_000 , backgroundTokens :1_000 }); 53assertStringIncludes ( report as string , "100000" ); 54await harness . command ( "context-cap" , "256k 32k" ); 55});