mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-18 13:30:48 +00:00
refactor(compaction-tests): share snapshot assertions
This commit is contained in:
@@ -7,6 +7,30 @@ import {
|
||||
shouldFlagCompactionTimeout,
|
||||
} from "./compaction-timeout.js";
|
||||
|
||||
function expectSelectedSnapshot(params: {
|
||||
currentSessionId: string;
|
||||
currentSnapshot: Parameters<typeof selectCompactionTimeoutSnapshot>[0]["currentSnapshot"];
|
||||
expectedSessionIdUsed: string;
|
||||
expectedSnapshot: ReadonlyArray<ReturnType<typeof castAgentMessage>>;
|
||||
expectedSource: "current" | "pre-compaction";
|
||||
preCompactionSessionId: string;
|
||||
preCompactionSnapshot: Parameters<
|
||||
typeof selectCompactionTimeoutSnapshot
|
||||
>[0]["preCompactionSnapshot"];
|
||||
timedOutDuringCompaction: boolean;
|
||||
}) {
|
||||
const selected = selectCompactionTimeoutSnapshot({
|
||||
timedOutDuringCompaction: params.timedOutDuringCompaction,
|
||||
preCompactionSnapshot: params.preCompactionSnapshot,
|
||||
preCompactionSessionId: params.preCompactionSessionId,
|
||||
currentSnapshot: params.currentSnapshot,
|
||||
currentSessionId: params.currentSessionId,
|
||||
});
|
||||
expect(selected.source).toBe(params.expectedSource);
|
||||
expect(selected.sessionIdUsed).toBe(params.expectedSessionIdUsed);
|
||||
expect(selected.messagesSnapshot).toEqual(params.expectedSnapshot);
|
||||
}
|
||||
|
||||
describe("compaction-timeout helpers", () => {
|
||||
it("flags compaction timeout consistently for internal and external timeout sources", () => {
|
||||
const internalTimer = shouldFlagCompactionTimeout({
|
||||
@@ -75,29 +99,29 @@ describe("compaction-timeout helpers", () => {
|
||||
it("uses pre-compaction snapshot when compaction timeout occurs", () => {
|
||||
const pre = [castAgentMessage({ role: "assistant", content: "pre" })] as const;
|
||||
const current = [castAgentMessage({ role: "assistant", content: "current" })] as const;
|
||||
const selected = selectCompactionTimeoutSnapshot({
|
||||
expectSelectedSnapshot({
|
||||
timedOutDuringCompaction: true,
|
||||
preCompactionSnapshot: [...pre],
|
||||
preCompactionSessionId: "session-pre",
|
||||
currentSnapshot: [...current],
|
||||
currentSessionId: "session-current",
|
||||
expectedSource: "pre-compaction",
|
||||
expectedSessionIdUsed: "session-pre",
|
||||
expectedSnapshot: pre,
|
||||
});
|
||||
expect(selected.source).toBe("pre-compaction");
|
||||
expect(selected.sessionIdUsed).toBe("session-pre");
|
||||
expect(selected.messagesSnapshot).toEqual(pre);
|
||||
});
|
||||
|
||||
it("falls back to current snapshot when pre-compaction snapshot is unavailable", () => {
|
||||
const current = [castAgentMessage({ role: "assistant", content: "current" })] as const;
|
||||
const selected = selectCompactionTimeoutSnapshot({
|
||||
expectSelectedSnapshot({
|
||||
timedOutDuringCompaction: true,
|
||||
preCompactionSnapshot: null,
|
||||
preCompactionSessionId: "session-pre",
|
||||
currentSnapshot: [...current],
|
||||
currentSessionId: "session-current",
|
||||
expectedSource: "current",
|
||||
expectedSessionIdUsed: "session-current",
|
||||
expectedSnapshot: current,
|
||||
});
|
||||
expect(selected.source).toBe("current");
|
||||
expect(selected.sessionIdUsed).toBe("session-current");
|
||||
expect(selected.messagesSnapshot).toEqual(current);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user