import { beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../../config/config.js"; import { resolveSessionKeyForRequest } from "./session.js";
it("returns a deterministic explicit sessionKey when sessionId not found in any store", async () => {
setupMainAndMybotStorePaths();
mocks.loadSessionStore.mockReturnValue({});
it("does not search other stores when explicitSessionKey is set", async () => {
mocks.listAgentIds.mockReturnValue(["main", "mybot"]);
mocks.resolveStorePath.mockReturnValue(MAIN_STORE_PATH);
mocks.loadSessionStore.mockReturnValue({ "agent:main:main": { sessionId: "other-id", updatedAt: 0 },
});
const result = resolveSessionKeyForRequest({
cfg: baseCfg,
sessionKey: "agent:main:main",
sessionId: "target-session-id",
}); // explicitSessionKey is set, so sessionKey comes from it, not from sessionId lookup
expect(result.sessionKey).toBe("agent:main:main");
});
it("searches other stores when --to derives a key that does not match --session-id", async () => {
setupMainAndMybotStorePaths();
mockStoresByPath({
[MAIN_STORE_PATH]: { "agent:main:main": { sessionId: "other-session-id", updatedAt: 0 },
},
[MYBOT_STORE_PATH]: { "agent:mybot:main": { sessionId: "target-session-id", updatedAt: 0 },
},
});
const result = resolveSessionKeyForRequest({
cfg: baseCfg,
to: "+15551234567",
sessionId: "target-session-id",
}); // --to derives agent:main:main, but its sessionId doesn't match target-session-id, // so the cross-store search finds it in the mybot store
expect(result.sessionKey).toBe("agent:mybot:main");
expect(result.storePath).toBe(MYBOT_STORE_PATH);
});
it("skips already-searched primary store when iterating agents", async () => {
setupMainAndMybotStorePaths();
mocks.loadSessionStore.mockReturnValue({});
// loadSessionStore should be called twice: once for main, once for mybot // (not twice for main) const storePaths = mocks.loadSessionStore.mock.calls.map((call) => String(call[0]));
expect(storePaths).toHaveLength(2);
expect(storePaths).toContain(MAIN_STORE_PATH);
expect(storePaths).toContain(MYBOT_STORE_PATH);
});
});
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.