|
1 | 1 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import { resolveSessionStoreTargets } from "./session-store-targets.js"; |
3 | 3 |
|
4 | | -const resolveStorePathMock = vi.hoisted(() => vi.fn()); |
5 | | -const resolveDefaultAgentIdMock = vi.hoisted(() => vi.fn()); |
6 | | -const listAgentIdsMock = vi.hoisted(() => vi.fn()); |
| 4 | +const resolveSessionStoreTargetsMock = vi.hoisted(() => vi.fn()); |
7 | 5 |
|
8 | 6 | vi.mock("../config/sessions.js", () => ({ |
9 | | - resolveStorePath: resolveStorePathMock, |
10 | | -})); |
11 | | - |
12 | | -vi.mock("../agents/agent-scope.js", () => ({ |
13 | | - resolveDefaultAgentId: resolveDefaultAgentIdMock, |
14 | | - listAgentIds: listAgentIdsMock, |
| 7 | + resolveSessionStoreTargets: resolveSessionStoreTargetsMock, |
15 | 8 | })); |
16 | 9 |
|
17 | 10 | describe("resolveSessionStoreTargets", () => { |
18 | 11 | beforeEach(() => { |
19 | 12 | vi.clearAllMocks(); |
20 | 13 | }); |
21 | 14 |
|
22 | | - it("resolves the default agent store when no selector is provided", () => { |
23 | | - resolveDefaultAgentIdMock.mockReturnValue("main"); |
24 | | - resolveStorePathMock.mockReturnValue("/tmp/main-sessions.json"); |
25 | | - |
26 | | - const targets = resolveSessionStoreTargets({}, {}); |
27 | | - |
28 | | - expect(targets).toEqual([{ agentId: "main", storePath: "/tmp/main-sessions.json" }]); |
29 | | - expect(resolveStorePathMock).toHaveBeenCalledWith(undefined, { agentId: "main" }); |
30 | | - }); |
31 | | - |
32 | | - it("resolves all configured agent stores", () => { |
33 | | - listAgentIdsMock.mockReturnValue(["main", "work"]); |
34 | | - resolveStorePathMock |
35 | | - .mockReturnValueOnce("/tmp/main-sessions.json") |
36 | | - .mockReturnValueOnce("/tmp/work-sessions.json"); |
37 | | - |
38 | | - const targets = resolveSessionStoreTargets( |
39 | | - { |
40 | | - session: { store: "~/.openclaw/agents/{agentId}/sessions/sessions.json" }, |
41 | | - }, |
42 | | - { allAgents: true }, |
43 | | - ); |
44 | | - |
45 | | - expect(targets).toEqual([ |
| 15 | + it("delegates session store target resolution to the shared config helper", () => { |
| 16 | + resolveSessionStoreTargetsMock.mockReturnValue([ |
46 | 17 | { agentId: "main", storePath: "/tmp/main-sessions.json" }, |
47 | | - { agentId: "work", storePath: "/tmp/work-sessions.json" }, |
48 | 18 | ]); |
49 | | - }); |
50 | | - |
51 | | - it("dedupes shared store paths for --all-agents", () => { |
52 | | - listAgentIdsMock.mockReturnValue(["main", "work"]); |
53 | | - resolveStorePathMock.mockReturnValue("/tmp/shared-sessions.json"); |
54 | 19 |
|
55 | | - const targets = resolveSessionStoreTargets( |
56 | | - { |
57 | | - session: { store: "/tmp/shared-sessions.json" }, |
58 | | - }, |
59 | | - { allAgents: true }, |
60 | | - ); |
61 | | - |
62 | | - expect(targets).toEqual([{ agentId: "main", storePath: "/tmp/shared-sessions.json" }]); |
63 | | - expect(resolveStorePathMock).toHaveBeenCalledTimes(2); |
64 | | - }); |
65 | | - |
66 | | - it("rejects unknown agent ids", () => { |
67 | | - listAgentIdsMock.mockReturnValue(["main", "work"]); |
68 | | - expect(() => resolveSessionStoreTargets({}, { agent: "ghost" })).toThrow(/Unknown agent id/); |
69 | | - }); |
| 20 | + const targets = resolveSessionStoreTargets({}, {}); |
70 | 21 |
|
71 | | - it("rejects conflicting selectors", () => { |
72 | | - expect(() => resolveSessionStoreTargets({}, { agent: "main", allAgents: true })).toThrow( |
73 | | - /cannot be used together/i, |
74 | | - ); |
75 | | - expect(() => |
76 | | - resolveSessionStoreTargets({}, { store: "/tmp/sessions.json", allAgents: true }), |
77 | | - ).toThrow(/cannot be combined/i); |
| 22 | + expect(targets).toEqual([{ agentId: "main", storePath: "/tmp/main-sessions.json" }]); |
| 23 | + expect(resolveSessionStoreTargetsMock).toHaveBeenCalledWith({}, {}); |
78 | 24 | }); |
79 | 25 | }); |
0 commit comments