mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:41:22 +00:00
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 64a28900f1
Co-authored-by: mverrilli <816450+mverrilli@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
selectCompactionTimeoutSnapshot,
|
|
shouldFlagCompactionTimeout,
|
|
} from "./compaction-timeout.js";
|
|
|
|
describe("compaction-timeout helpers", () => {
|
|
it("flags compaction timeout consistently for internal and external timeout sources", () => {
|
|
const internalTimer = shouldFlagCompactionTimeout({
|
|
isTimeout: true,
|
|
isCompactionPendingOrRetrying: true,
|
|
isCompactionInFlight: false,
|
|
});
|
|
const externalAbort = shouldFlagCompactionTimeout({
|
|
isTimeout: true,
|
|
isCompactionPendingOrRetrying: true,
|
|
isCompactionInFlight: false,
|
|
});
|
|
expect(internalTimer).toBe(true);
|
|
expect(externalAbort).toBe(true);
|
|
});
|
|
|
|
it("does not flag when timeout is false", () => {
|
|
expect(
|
|
shouldFlagCompactionTimeout({
|
|
isTimeout: false,
|
|
isCompactionPendingOrRetrying: true,
|
|
isCompactionInFlight: true,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("uses pre-compaction snapshot when compaction timeout occurs", () => {
|
|
const pre = [{ role: "assistant", content: "pre" }] as const;
|
|
const current = [{ role: "assistant", content: "current" }] as const;
|
|
const selected = selectCompactionTimeoutSnapshot({
|
|
timedOutDuringCompaction: true,
|
|
preCompactionSnapshot: [...pre],
|
|
preCompactionSessionId: "session-pre",
|
|
currentSnapshot: [...current],
|
|
currentSessionId: "session-current",
|
|
});
|
|
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 = [{ role: "assistant", content: "current" }] as const;
|
|
const selected = selectCompactionTimeoutSnapshot({
|
|
timedOutDuringCompaction: true,
|
|
preCompactionSnapshot: null,
|
|
preCompactionSessionId: "session-pre",
|
|
currentSnapshot: [...current],
|
|
currentSessionId: "session-current",
|
|
});
|
|
expect(selected.source).toBe("current");
|
|
expect(selected.sessionIdUsed).toBe("session-current");
|
|
expect(selected.messagesSnapshot).toEqual(current);
|
|
});
|
|
});
|