import { describe, expect, it } from "vitest" ;
import { applyCompactionDefaults } from "./defaults.js" ;
import type { OpenClawConfig } from "./types.js" ;
function materializeCompactionConfig(
compaction: NonNullable<NonNullable<OpenClawConfig["agents" ]>["defaults" ]>["compaction" ],
) {
const cfg = applyCompactionDefaults({
agents: {
defaults: {
compaction,
},
},
});
return cfg.agents?.defaults?.compaction;
}
describe("config compaction settings" , () => {
it("preserves memory flush config values" , () => {
const compaction = materializeCompactionConfig({
mode: "safeguard" ,
reserveTokensFloor: 12 _345 ,
identifierPolicy: "custom" ,
identifierInstructions: "Keep ticket IDs unchanged." ,
qualityGuard: {
enabled: true ,
maxRetries: 2 ,
},
memoryFlush: {
enabled: false ,
softThresholdTokens: 1234 ,
prompt: "Write notes." ,
systemPrompt: "Flush memory now." ,
},
});
expect(compaction?.reserveTokensFloor).toBe(12 _345 );
expect(compaction?.mode).toBe("safeguard" );
expect(compaction?.reserveTokens).toBeUndefined();
expect(compaction?.keepRecentTokens).toBeUndefined();
expect(compaction?.identifierPolicy).toBe("custom" );
expect(compaction?.identifierInstructions).toBe("Keep ticket IDs unchanged." );
expect(compaction?.qualityGuard?.enabled).toBe(true );
expect(compaction?.qualityGuard?.maxRetries).toBe(2 );
expect(compaction?.memoryFlush?.enabled).toBe(false );
expect(compaction?.memoryFlush?.softThresholdTokens).toBe(1234 );
expect(compaction?.memoryFlush?.prompt).toBe("Write notes." );
expect(compaction?.memoryFlush?.systemPrompt).toBe("Flush memory now." );
});
it("preserves pi compaction override values" , () => {
const compaction = materializeCompactionConfig({
reserveTokens: 15 _000 ,
keepRecentTokens: 12 _000 ,
});
expect(compaction?.reserveTokens).toBe(15 _000 );
expect(compaction?.keepRecentTokens).toBe(12 _000 );
});
it("defaults compaction mode to safeguard" , () => {
const compaction = materializeCompactionConfig({
reserveTokensFloor: 9000 ,
});
expect(compaction?.mode).toBe("safeguard" );
expect(compaction?.reserveTokensFloor).toBe(9000 );
});
it("preserves recent turn safeguard values during materialization" , () => {
const compaction = materializeCompactionConfig({
mode: "safeguard" ,
recentTurnsPreserve: 4 ,
});
expect(compaction?.recentTurnsPreserve).toBe(4 );
});
it("preserves oversized quality guard retry values for runtime clamping" , () => {
const compaction = materializeCompactionConfig({
qualityGuard: {
maxRetries: 99 ,
},
});
expect(compaction?.qualityGuard?.maxRetries).toBe(99 );
});
});
Messung V0.5 in Prozent C=100 H=100 G=100
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-04)
¤
*© Formatika GbR, Deutschland