|
1 | | -import { describe, expect, it } from "vitest"; |
2 | | -import { buildPromptSection } from "./index.js"; |
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import plugin, { buildPromptSection } from "./index.js"; |
3 | 3 |
|
4 | 4 | describe("buildPromptSection", () => { |
5 | 5 | it("returns empty when no memory tools are available", () => { |
@@ -29,4 +29,40 @@ describe("buildPromptSection", () => { |
29 | 29 | "Citations are disabled: do not mention file paths or line numbers in replies unless the user explicitly asks.", |
30 | 30 | ); |
31 | 31 | }); |
| 32 | + |
| 33 | + it("registers memory tools independently so one unavailable tool does not suppress the other", () => { |
| 34 | + const registerTool = vi.fn(); |
| 35 | + const registerMemoryPromptSection = vi.fn(); |
| 36 | + const registerCli = vi.fn(); |
| 37 | + const searchTool = { name: "memory_search" }; |
| 38 | + const getTool = null; |
| 39 | + const api = { |
| 40 | + registerTool, |
| 41 | + registerMemoryPromptSection, |
| 42 | + registerCli, |
| 43 | + runtime: { |
| 44 | + tools: { |
| 45 | + createMemorySearchTool: vi.fn(() => searchTool), |
| 46 | + createMemoryGetTool: vi.fn(() => getTool), |
| 47 | + registerMemoryCli: vi.fn(), |
| 48 | + }, |
| 49 | + }, |
| 50 | + }; |
| 51 | + |
| 52 | + plugin.register(api as never); |
| 53 | + |
| 54 | + expect(registerMemoryPromptSection).toHaveBeenCalledWith(buildPromptSection); |
| 55 | + expect(registerTool).toHaveBeenCalledTimes(2); |
| 56 | + expect(registerTool.mock.calls[0]?.[1]).toEqual({ names: ["memory_search"] }); |
| 57 | + expect(registerTool.mock.calls[1]?.[1]).toEqual({ names: ["memory_get"] }); |
| 58 | + |
| 59 | + const searchFactory = registerTool.mock.calls[0]?.[0] as |
| 60 | + | ((ctx: unknown) => unknown) |
| 61 | + | undefined; |
| 62 | + const getFactory = registerTool.mock.calls[1]?.[0] as ((ctx: unknown) => unknown) | undefined; |
| 63 | + const ctx = { config: { plugins: {} }, sessionKey: "agent:main:slack:dm:u123" }; |
| 64 | + |
| 65 | + expect(searchFactory?.(ctx)).toBe(searchTool); |
| 66 | + expect(getFactory?.(ctx)).toBeNull(); |
| 67 | + }); |
32 | 68 | }); |
0 commit comments