test(gateway): cover default-agent transcript fallbacks

This commit is contained in:
Gustavo Madeira Santana 2026-02-14 13:35:36 -05:00
parent 914d47f0a8
commit 8ce7cfdc12
2 changed files with 35 additions and 0 deletions

View File

@ -594,6 +594,22 @@ describe("resolveSessionTranscriptCandidates", () => {
});
describe("resolveSessionTranscriptCandidates safety", () => {
test("keeps cross-agent absolute sessionFile when storePath agent context differs", () => {
const storePath = "/tmp/openclaw/agents/main/sessions/sessions.json";
const sessionFile = "/tmp/openclaw/agents/ops/sessions/sess-safe.jsonl";
const candidates = resolveSessionTranscriptCandidates("sess-safe", storePath, sessionFile);
expect(candidates.map((value) => path.resolve(value))).toContain(path.resolve(sessionFile));
});
test("keeps cross-agent absolute sessionFile for custom per-agent store roots", () => {
const storePath = "/srv/custom/agents/main/sessions/sessions.json";
const sessionFile = "/srv/custom/agents/ops/sessions/sess-safe.jsonl";
const candidates = resolveSessionTranscriptCandidates("sess-safe", storePath, sessionFile);
expect(candidates.map((value) => path.resolve(value))).toContain(path.resolve(sessionFile));
});
test("drops unsafe session IDs instead of producing traversal paths", () => {
const candidates = resolveSessionTranscriptCandidates(
"../etc/passwd",

View File

@ -70,6 +70,25 @@ describe("gateway session utils", () => {
);
});
test("resolveSessionStoreKey falls back to first list entry when no agent is marked default", () => {
const cfg = {
session: { mainKey: "main" },
agents: { list: [{ id: "ops" }, { id: "review" }] },
} as OpenClawConfig;
expect(resolveSessionStoreKey({ cfg, sessionKey: "main" })).toBe("agent:ops:main");
expect(resolveSessionStoreKey({ cfg, sessionKey: "discord:group:123" })).toBe(
"agent:ops:discord:group:123",
);
});
test("resolveSessionStoreKey falls back to main when agents.list is missing", () => {
const cfg = {
session: { mainKey: "work" },
} as OpenClawConfig;
expect(resolveSessionStoreKey({ cfg, sessionKey: "main" })).toBe("agent:main:work");
expect(resolveSessionStoreKey({ cfg, sessionKey: "thread-1" })).toBe("agent:main:thread-1");
});
test("resolveSessionStoreKey normalizes session key casing", () => {
const cfg = {
session: { mainKey: "main" },