mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 21:10:54 +00:00
* fix(discord): preserve channel session keys via channel_id fallbacks * docs(changelog): add discord session continuity note * Tests: cover discord channel_id fallback --------- Co-authored-by: Shadow <hi@shadowing.dev>
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import fs from "node:fs";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
getDiagnosticSessionStateCountForTest,
|
|
getDiagnosticSessionState,
|
|
resetDiagnosticSessionStateForTest,
|
|
} from "./diagnostic-session-state.js";
|
|
|
|
describe("diagnostic session state pruning", () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
resetDiagnosticSessionStateForTest();
|
|
});
|
|
|
|
afterEach(() => {
|
|
resetDiagnosticSessionStateForTest();
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("evicts stale idle session states", () => {
|
|
getDiagnosticSessionState({ sessionId: "stale-1" });
|
|
expect(getDiagnosticSessionStateCountForTest()).toBe(1);
|
|
|
|
vi.advanceTimersByTime(31 * 60 * 1000);
|
|
getDiagnosticSessionState({ sessionId: "fresh-1" });
|
|
|
|
expect(getDiagnosticSessionStateCountForTest()).toBe(1);
|
|
});
|
|
|
|
it("caps tracked session states to a bounded max", () => {
|
|
for (let i = 0; i < 2001; i += 1) {
|
|
getDiagnosticSessionState({ sessionId: `session-${i}` });
|
|
}
|
|
|
|
expect(getDiagnosticSessionStateCountForTest()).toBe(2000);
|
|
});
|
|
|
|
it("reuses keyed session state when later looked up by sessionId", () => {
|
|
const keyed = getDiagnosticSessionState({
|
|
sessionId: "s1",
|
|
sessionKey: "agent:main:discord:channel:c1",
|
|
});
|
|
const bySessionId = getDiagnosticSessionState({ sessionId: "s1" });
|
|
|
|
expect(bySessionId).toBe(keyed);
|
|
expect(bySessionId.sessionKey).toBe("agent:main:discord:channel:c1");
|
|
expect(getDiagnosticSessionStateCountForTest()).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe("logger import side effects", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("does not mkdir at import time", async () => {
|
|
vi.useRealTimers();
|
|
vi.resetModules();
|
|
|
|
const mkdirSpy = vi.spyOn(fs, "mkdirSync");
|
|
|
|
await import("./logger.js");
|
|
|
|
expect(mkdirSpy).not.toHaveBeenCalled();
|
|
});
|
|
});
|