diff --git a/source/utils/auto-compact.spec.ts b/source/utils/auto-compact.spec.ts index b205eb18..807a09df 100644 --- a/source/utils/auto-compact.spec.ts +++ b/source/utils/auto-compact.spec.ts @@ -15,6 +15,7 @@ import { setAutoCompactStrategy, setAutoCompactThreshold, } from './auto-compact'; +import {COMPRESSION_CONSTANTS} from './message-compression'; // Reset session overrides before each test test.beforeEach(() => { @@ -51,24 +52,36 @@ test('setAutoCompactThreshold sets threshold value', t => { t.is(autoCompactSessionOverrides.threshold, 75); }); -test('setAutoCompactThreshold clamps to minimum of 50', t => { - setAutoCompactThreshold(30); - t.is(autoCompactSessionOverrides.threshold, 50); +test('setAutoCompactThreshold clamps to the configured minimum', t => { + setAutoCompactThreshold(COMPRESSION_CONSTANTS.MIN_THRESHOLD_PERCENT - 20); + t.is( + autoCompactSessionOverrides.threshold, + COMPRESSION_CONSTANTS.MIN_THRESHOLD_PERCENT, + ); }); -test('setAutoCompactThreshold clamps to maximum of 95', t => { - setAutoCompactThreshold(99); - t.is(autoCompactSessionOverrides.threshold, 95); +test('setAutoCompactThreshold clamps to the configured maximum', t => { + setAutoCompactThreshold(COMPRESSION_CONSTANTS.MAX_THRESHOLD_PERCENT + 4); + t.is( + autoCompactSessionOverrides.threshold, + COMPRESSION_CONSTANTS.MAX_THRESHOLD_PERCENT, + ); }); -test('setAutoCompactThreshold handles boundary value 50', t => { - setAutoCompactThreshold(50); - t.is(autoCompactSessionOverrides.threshold, 50); +test('setAutoCompactThreshold handles the configured minimum', t => { + setAutoCompactThreshold(COMPRESSION_CONSTANTS.MIN_THRESHOLD_PERCENT); + t.is( + autoCompactSessionOverrides.threshold, + COMPRESSION_CONSTANTS.MIN_THRESHOLD_PERCENT, + ); }); -test('setAutoCompactThreshold handles boundary value 95', t => { - setAutoCompactThreshold(95); - t.is(autoCompactSessionOverrides.threshold, 95); +test('setAutoCompactThreshold handles the configured maximum', t => { + setAutoCompactThreshold(COMPRESSION_CONSTANTS.MAX_THRESHOLD_PERCENT); + t.is( + autoCompactSessionOverrides.threshold, + COMPRESSION_CONSTANTS.MAX_THRESHOLD_PERCENT, + ); }); test('setAutoCompactThreshold sets threshold to null', t => { diff --git a/source/utils/auto-compact.ts b/source/utils/auto-compact.ts index ef3fccd2..d3455464 100644 --- a/source/utils/auto-compact.ts +++ b/source/utils/auto-compact.ts @@ -8,7 +8,7 @@ import {calculateToolDefinitionsTokensFromDefs} from '@/usage/calculator'; import {getLogger} from '@/utils/logging'; import {compressionBackup} from './compression-backup'; import {summariseWithLLM} from './llm-summariser'; -import {compressMessages} from './message-compression'; +import {COMPRESSION_CONSTANTS, compressMessages} from './message-compression'; import {filterModelFacing} from './message-visibility'; import {createSessionOverride} from './session-override'; @@ -19,11 +19,16 @@ export interface AutoCompactSessionOverrides { strategy: CompressionStrategy | null; } -// Session overrides for auto-compact. `threshold` is clamped to 50–95. +// Session overrides for auto-compact. `threshold` is clamped to the configured range. const autoCompactSession = { enabled: createSessionOverride(), threshold: createSessionOverride(value => - value !== null ? Math.max(50, Math.min(95, value)) : null, + value !== null + ? Math.max( + COMPRESSION_CONSTANTS.MIN_THRESHOLD_PERCENT, + Math.min(COMPRESSION_CONSTANTS.MAX_THRESHOLD_PERCENT, value), + ) + : null, ), mode: createSessionOverride(), strategy: createSessionOverride(),