|
| 1 | +/** |
| 2 | + * Tests for PowerMem plugin config parsing and resolvers. |
| 3 | + */ |
| 4 | +import { describe, it, expect } from "vitest"; |
| 5 | +import { |
| 6 | + powerMemConfigSchema, |
| 7 | + resolveUserId, |
| 8 | + resolveAgentId, |
| 9 | + DEFAULT_USER_ID, |
| 10 | + DEFAULT_AGENT_ID, |
| 11 | + type PowerMemConfig, |
| 12 | +} from "../config.js"; |
| 13 | + |
| 14 | +describe("powerMemConfigSchema", () => { |
| 15 | + it("parses valid http config with required fields", () => { |
| 16 | + const cfg = powerMemConfigSchema.parse({ |
| 17 | + mode: "http", |
| 18 | + baseUrl: "http://localhost:8000", |
| 19 | + autoCapture: true, |
| 20 | + autoRecall: true, |
| 21 | + inferOnAdd: true, |
| 22 | + }) as PowerMemConfig; |
| 23 | + expect(cfg.mode).toBe("http"); |
| 24 | + expect(cfg.baseUrl).toBe("http://localhost:8000"); |
| 25 | + expect(cfg.autoCapture).toBe(true); |
| 26 | + expect(cfg.autoRecall).toBe(true); |
| 27 | + expect(cfg.inferOnAdd).toBe(true); |
| 28 | + expect(cfg.recallLimit).toBe(5); |
| 29 | + expect(cfg.recallScoreThreshold).toBe(0); |
| 30 | + }); |
| 31 | + |
| 32 | + it("parses valid cli config", () => { |
| 33 | + const cfg = powerMemConfigSchema.parse({ |
| 34 | + mode: "cli", |
| 35 | + baseUrl: "", |
| 36 | + autoCapture: false, |
| 37 | + autoRecall: true, |
| 38 | + inferOnAdd: false, |
| 39 | + }) as PowerMemConfig; |
| 40 | + expect(cfg.mode).toBe("cli"); |
| 41 | + expect(cfg.pmemPath).toBe("pmem"); |
| 42 | + }); |
| 43 | + |
| 44 | + it("rejects non-object config", () => { |
| 45 | + expect(() => powerMemConfigSchema.parse(null)).toThrow("memory-powermem config required"); |
| 46 | + expect(() => powerMemConfigSchema.parse("")).toThrow(); |
| 47 | + }); |
| 48 | + |
| 49 | + it("rejects http mode without baseUrl", () => { |
| 50 | + expect(() => |
| 51 | + powerMemConfigSchema.parse({ |
| 52 | + mode: "http", |
| 53 | + baseUrl: "", |
| 54 | + autoCapture: true, |
| 55 | + autoRecall: true, |
| 56 | + inferOnAdd: true, |
| 57 | + }), |
| 58 | + ).toThrow("baseUrl is required when mode is http"); |
| 59 | + }); |
| 60 | +}); |
| 61 | + |
| 62 | +describe("resolveUserId / resolveAgentId", () => { |
| 63 | + it("returns default user/agent when not set", () => { |
| 64 | + const cfg = { userId: undefined, agentId: undefined } as PowerMemConfig; |
| 65 | + expect(resolveUserId(cfg)).toBe(DEFAULT_USER_ID); |
| 66 | + expect(resolveAgentId(cfg)).toBe(DEFAULT_AGENT_ID); |
| 67 | + }); |
| 68 | + |
| 69 | + it("returns configured user/agent when set", () => { |
| 70 | + const cfg = { |
| 71 | + userId: "user-1", |
| 72 | + agentId: "agent-1", |
| 73 | + } as PowerMemConfig; |
| 74 | + expect(resolveUserId(cfg)).toBe("user-1"); |
| 75 | + expect(resolveAgentId(cfg)).toBe("agent-1"); |
| 76 | + }); |
| 77 | +}); |
0 commit comments