Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: an unset fresh-session handle does not hold the soft handle up; docs vale fixes

This commit is contained in:
iris 2026-11-16 11:04:04 +01:00
commit 0db9868eee
2 changed files with 22 additions and 7 deletions

View file

@ -74,10 +74,15 @@ export function clampFresh(to: number, limits: Limits): number {
);
}
/** Where the soft handle may go: not below the fresh-session handle. */
/**
* Where the soft handle may go: not below the fresh-session handle when the
* swarm sets one. An unset fresh-session handle only follows the soft one down
* (`limitsOf`), so it does not hold it up.
*/
export function clampSoft(to: number, limits: Limits): number {
const floor = limits.freshSet ? limits.fresh : MIN_SOFT_CONTEXT_PERCENT;
return Math.min(
Math.max(Math.round(to), limits.fresh, MIN_SOFT_CONTEXT_PERCENT),
Math.max(Math.round(to), floor, MIN_SOFT_CONTEXT_PERCENT),
MAX_SOFT_CONTEXT_PERCENT,
);
}

View file

@ -52,7 +52,14 @@ test("the fresh-session handle stops at the soft one and at 5", () => {
assert.equal(clampFresh(44.6, l), 45);
});
test("the soft handle stops at the fresh-session one and at 100", () => {
test("an unset fresh-session handle does not hold the soft one up", () => {
const l = limitsOf("", "");
assert.equal(clampSoft(20, l), 20);
assert.equal(clampSoft(5, l), 5);
assert.equal(limitsOf("", "20").fresh, 20, "it follows the soft handle down");
});
test("the soft handle stops at a set fresh-session one and at 100", () => {
const l = limitsOf("30", "60");
assert.equal(clampSoft(75, l), 75);
assert.equal(clampSoft(10, l), 30);