mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 23:40:21 +00:00
test(reply): dedupe compaction session fixture setup
This commit is contained in:
@@ -35,6 +35,15 @@ async function seedSessionStore(params: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createCompactionSessionFixture(entry: SessionEntry) {
|
||||||
|
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compact-"));
|
||||||
|
const storePath = path.join(tmp, "sessions.json");
|
||||||
|
const sessionKey = "main";
|
||||||
|
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };
|
||||||
|
await seedSessionStore({ storePath, sessionKey, entry });
|
||||||
|
return { storePath, sessionKey, sessionStore };
|
||||||
|
}
|
||||||
|
|
||||||
describe("history helpers", () => {
|
describe("history helpers", () => {
|
||||||
it("returns current message when history is empty", () => {
|
it("returns current message when history is empty", () => {
|
||||||
const result = buildHistoryContext({
|
const result = buildHistoryContext({
|
||||||
@@ -323,9 +332,6 @@ describe("incrementCompactionCount", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("updates totalTokens when tokensAfter is provided", async () => {
|
it("updates totalTokens when tokensAfter is provided", async () => {
|
||||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compact-"));
|
|
||||||
const storePath = path.join(tmp, "sessions.json");
|
|
||||||
const sessionKey = "main";
|
|
||||||
const entry = {
|
const entry = {
|
||||||
sessionId: "s1",
|
sessionId: "s1",
|
||||||
updatedAt: Date.now(),
|
updatedAt: Date.now(),
|
||||||
@@ -334,8 +340,7 @@ describe("incrementCompactionCount", () => {
|
|||||||
inputTokens: 170_000,
|
inputTokens: 170_000,
|
||||||
outputTokens: 10_000,
|
outputTokens: 10_000,
|
||||||
} as SessionEntry;
|
} as SessionEntry;
|
||||||
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };
|
const { storePath, sessionKey, sessionStore } = await createCompactionSessionFixture(entry);
|
||||||
await seedSessionStore({ storePath, sessionKey, entry });
|
|
||||||
|
|
||||||
await incrementCompactionCount({
|
await incrementCompactionCount({
|
||||||
sessionEntry: entry,
|
sessionEntry: entry,
|
||||||
@@ -354,17 +359,13 @@ describe("incrementCompactionCount", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not update totalTokens when tokensAfter is not provided", async () => {
|
it("does not update totalTokens when tokensAfter is not provided", async () => {
|
||||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compact-"));
|
|
||||||
const storePath = path.join(tmp, "sessions.json");
|
|
||||||
const sessionKey = "main";
|
|
||||||
const entry = {
|
const entry = {
|
||||||
sessionId: "s1",
|
sessionId: "s1",
|
||||||
updatedAt: Date.now(),
|
updatedAt: Date.now(),
|
||||||
compactionCount: 0,
|
compactionCount: 0,
|
||||||
totalTokens: 180_000,
|
totalTokens: 180_000,
|
||||||
} as SessionEntry;
|
} as SessionEntry;
|
||||||
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };
|
const { storePath, sessionKey, sessionStore } = await createCompactionSessionFixture(entry);
|
||||||
await seedSessionStore({ storePath, sessionKey, entry });
|
|
||||||
|
|
||||||
await incrementCompactionCount({
|
await incrementCompactionCount({
|
||||||
sessionEntry: entry,
|
sessionEntry: entry,
|
||||||
|
|||||||
Reference in New Issue
Block a user