mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 21:04:31 +00:00
test(reply): reuse compaction fixture setup and cover numeric fallback defaults
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it } from "vitest";
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
|
import { DEFAULT_PI_COMPACTION_RESERVE_TOKENS_FLOOR } from "../../agents/pi-settings.js";
|
||||||
import type { SessionEntry } from "../../config/sessions.js";
|
import type { SessionEntry } from "../../config/sessions.js";
|
||||||
import {
|
import {
|
||||||
appendHistoryEntry,
|
appendHistoryEntry,
|
||||||
@@ -22,6 +23,12 @@ import {
|
|||||||
import { CURRENT_MESSAGE_MARKER } from "./mentions.js";
|
import { CURRENT_MESSAGE_MARKER } from "./mentions.js";
|
||||||
import { incrementCompactionCount } from "./session-updates.js";
|
import { incrementCompactionCount } from "./session-updates.js";
|
||||||
|
|
||||||
|
const tempDirs: string[] = [];
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
||||||
|
});
|
||||||
|
|
||||||
async function seedSessionStore(params: {
|
async function seedSessionStore(params: {
|
||||||
storePath: string;
|
storePath: string;
|
||||||
sessionKey: string;
|
sessionKey: string;
|
||||||
@@ -37,6 +44,7 @@ async function seedSessionStore(params: {
|
|||||||
|
|
||||||
async function createCompactionSessionFixture(entry: SessionEntry) {
|
async function createCompactionSessionFixture(entry: SessionEntry) {
|
||||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compact-"));
|
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compact-"));
|
||||||
|
tempDirs.push(tmp);
|
||||||
const storePath = path.join(tmp, "sessions.json");
|
const storePath = path.join(tmp, "sessions.json");
|
||||||
const sessionKey = "main";
|
const sessionKey = "main";
|
||||||
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };
|
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };
|
||||||
@@ -219,6 +227,24 @@ describe("memory flush settings", () => {
|
|||||||
expect(settings?.prompt).toContain("NO_REPLY");
|
expect(settings?.prompt).toContain("NO_REPLY");
|
||||||
expect(settings?.systemPrompt).toContain("NO_REPLY");
|
expect(settings?.systemPrompt).toContain("NO_REPLY");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("falls back to defaults when numeric values are invalid", () => {
|
||||||
|
const settings = resolveMemoryFlushSettings({
|
||||||
|
agents: {
|
||||||
|
defaults: {
|
||||||
|
compaction: {
|
||||||
|
reserveTokensFloor: Number.NaN,
|
||||||
|
memoryFlush: {
|
||||||
|
softThresholdTokens: -100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(settings?.softThresholdTokens).toBe(DEFAULT_MEMORY_FLUSH_SOFT_TOKENS);
|
||||||
|
expect(settings?.reserveTokensFloor).toBe(DEFAULT_PI_COMPACTION_RESERVE_TOKENS_FLOOR);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("shouldRunMemoryFlush", () => {
|
describe("shouldRunMemoryFlush", () => {
|
||||||
@@ -312,12 +338,8 @@ describe("resolveMemoryFlushContextWindowTokens", () => {
|
|||||||
|
|
||||||
describe("incrementCompactionCount", () => {
|
describe("incrementCompactionCount", () => {
|
||||||
it("increments compaction count", async () => {
|
it("increments compaction count", async () => {
|
||||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compact-"));
|
|
||||||
const storePath = path.join(tmp, "sessions.json");
|
|
||||||
const sessionKey = "main";
|
|
||||||
const entry = { sessionId: "s1", updatedAt: Date.now(), compactionCount: 2 } as SessionEntry;
|
const entry = { sessionId: "s1", updatedAt: Date.now(), compactionCount: 2 } as SessionEntry;
|
||||||
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };
|
const { storePath, sessionKey, sessionStore } = await createCompactionSessionFixture(entry);
|
||||||
await seedSessionStore({ storePath, sessionKey, entry });
|
|
||||||
|
|
||||||
const count = await incrementCompactionCount({
|
const count = await incrementCompactionCount({
|
||||||
sessionEntry: entry,
|
sessionEntry: entry,
|
||||||
|
|||||||
Reference in New Issue
Block a user