Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: one slider for the fresh-session threshold and the soft context limit

This commit is contained in:
iris 2026-11-16 10:50:13 +01:00
commit b16074e76b

View file

@ -0,0 +1,68 @@
// The two context limits behind the slider: where the handles sit, how far
// each may move and when the pair is refused. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
clampFresh,
clampSoft,
crossProblem,
DEFAULT_FRESH_SESSION_PERCENT,
DEFAULT_SOFT_CONTEXT_PERCENT,
limitsOf,
} from "../src/agent/detail/soft-context.ts";
test("with nothing set the handles sit at the harness's own defaults", () => {
assert.deepEqual(limitsOf("", ""), {
fresh: DEFAULT_FRESH_SESSION_PERCENT,
soft: DEFAULT_SOFT_CONTEXT_PERCENT,
freshSet: false,
softSet: false,
});
});
test("a set value moves its handle and marks it set", () => {
assert.deepEqual(limitsOf("30", "90"), {
fresh: 30,
soft: 90,
freshSet: true,
softSet: true,
});
const onlySoft = limitsOf("", "90");
assert.equal(onlySoft.fresh, 50);
assert.equal(onlySoft.freshSet, false);
});
test("an unset fresh-session handle never sits above the soft one", () => {
const l = limitsOf("", "40");
assert.equal(l.fresh, 40);
assert.equal(l.soft, 40);
});
test("text that is not a valid percent counts as unset", () => {
const l = limitsOf("abc", "200");
assert.equal(l.freshSet, false);
assert.equal(l.softSet, false);
});
test("the fresh-session handle stops at the soft one and at 5", () => {
const l = limitsOf("30", "60");
assert.equal(clampFresh(45, l), 45);
assert.equal(clampFresh(80, l), 60);
assert.equal(clampFresh(1, l), 5);
assert.equal(clampFresh(44.6, l), 45);
});
test("the soft handle stops at the fresh-session one and at 100", () => {
const l = limitsOf("30", "60");
assert.equal(clampSoft(75, l), 75);
assert.equal(clampSoft(10, l), 30);
assert.equal(clampSoft(150, l), 100);
});
test("a fresh-session threshold above the soft limit is refused, both set", () => {
assert.match(crossProblem("80", "60"), /above the soft limit/);
assert.equal(crossProblem("60", "60"), null);
assert.equal(crossProblem("30", "60"), null);
assert.equal(crossProblem("", "60"), null);
assert.equal(crossProblem("90", ""), null);
});