|
1 | 1 | import fs from "node:fs"; |
2 | 2 | import os from "node:os"; |
3 | 3 | import path from "node:path"; |
4 | | -import { afterEach, beforeEach, describe, expect, test } from "vitest"; |
| 4 | +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; |
5 | 5 | import { |
6 | 6 | addSubagentRunForTests, |
7 | 7 | resetSubagentRegistryForTests, |
@@ -32,6 +32,68 @@ describe("listSessionsFromStore subagent metadata", () => { |
32 | 32 | agents: { list: [{ id: "main", default: true }] }, |
33 | 33 | } as OpenClawConfig; |
34 | 34 |
|
| 35 | + test("searches channel-derived display names before row enrichment", () => { |
| 36 | + const result = listSessionsFromStore({ |
| 37 | + cfg, |
| 38 | + storePath: "/tmp/sessions.json", |
| 39 | + store: { |
| 40 | + "agent:main:slack:group:general": { |
| 41 | + sessionId: "slack-general-session", |
| 42 | + updatedAt: 2, |
| 43 | + channel: "slack", |
| 44 | + } as SessionEntry, |
| 45 | + "agent:main:discord:group:random": { |
| 46 | + sessionId: "discord-random-session", |
| 47 | + updatedAt: 1, |
| 48 | + channel: "discord", |
| 49 | + } as SessionEntry, |
| 50 | + }, |
| 51 | + opts: { search: "slack:g-general" }, |
| 52 | + }); |
| 53 | + |
| 54 | + expect(result.sessions.map((session) => session.key)).toEqual([ |
| 55 | + "agent:main:slack:group:general", |
| 56 | + ]); |
| 57 | + expect(result.sessions[0]?.displayName).toBe("slack:g-general"); |
| 58 | + }); |
| 59 | + |
| 60 | + test("applies limit before transcript enrichment", () => { |
| 61 | + const store: Record<string, SessionEntry> = { |
| 62 | + "agent:main:newest": { |
| 63 | + sessionId: "newest-session", |
| 64 | + sessionFile: "/tmp/newest-session.jsonl", |
| 65 | + updatedAt: 300, |
| 66 | + } as SessionEntry, |
| 67 | + "agent:main:middle": { |
| 68 | + sessionId: "middle-session", |
| 69 | + sessionFile: "/tmp/middle-session.jsonl", |
| 70 | + updatedAt: 200, |
| 71 | + } as SessionEntry, |
| 72 | + "agent:main:oldest": { |
| 73 | + sessionId: "old-session", |
| 74 | + sessionFile: "/tmp/old-session.jsonl", |
| 75 | + updatedAt: 100, |
| 76 | + } as SessionEntry, |
| 77 | + }; |
| 78 | + const existsSpy = vi.spyOn(fs, "existsSync").mockReturnValue(false); |
| 79 | + try { |
| 80 | + const result = listSessionsFromStore({ |
| 81 | + cfg, |
| 82 | + storePath: "/tmp/sessions.json", |
| 83 | + store, |
| 84 | + opts: { limit: 2 }, |
| 85 | + }); |
| 86 | + |
| 87 | + expect(result.sessions.map((session) => session.sessionId)).toEqual([ |
| 88 | + "newest-session", |
| 89 | + "middle-session", |
| 90 | + ]); |
| 91 | + expect(existsSpy.mock.calls.flat().join("\n")).not.toContain("old-session"); |
| 92 | + } finally { |
| 93 | + existsSpy.mockRestore(); |
| 94 | + } |
| 95 | + }); |
| 96 | + |
35 | 97 | test("includes subagent status timing and direct child session keys", () => { |
36 | 98 | const now = Date.now(); |
37 | 99 | const store: Record<string, SessionEntry> = { |
|
0 commit comments