|
| 1 | +import { afterEach, beforeEach, describe, expect, it } from "bun:test"; |
| 2 | +import { loadMemoryConfig } from "./mount-config.ts"; |
| 3 | + |
| 4 | +const REQUIRED_ENV = { |
| 5 | + KNOWLEDGE_DATABASE_URL: "postgres://localhost:5432/test", |
| 6 | + EMBED_BASE_URL: "http://embed.example", |
| 7 | + EMBED_MODEL: "test-model", |
| 8 | +}; |
| 9 | + |
| 10 | +const ENV_KEYS = [ |
| 11 | + ...Object.keys(REQUIRED_ENV), |
| 12 | + "EMBED_TIMEOUT_MS", |
| 13 | + "RERANK_TIMEOUT_MS", |
| 14 | +]; |
| 15 | + |
| 16 | +let savedEnv: Record<string, string | undefined>; |
| 17 | + |
| 18 | +beforeEach(() => { |
| 19 | + savedEnv = {}; |
| 20 | + for (const key of ENV_KEYS) { |
| 21 | + savedEnv[key] = process.env[key]; |
| 22 | + delete process.env[key]; |
| 23 | + } |
| 24 | + for (const [key, value] of Object.entries(REQUIRED_ENV)) { |
| 25 | + process.env[key] = value; |
| 26 | + } |
| 27 | +}); |
| 28 | + |
| 29 | +afterEach(() => { |
| 30 | + for (const key of ENV_KEYS) { |
| 31 | + if (savedEnv[key] === undefined) delete process.env[key]; |
| 32 | + else process.env[key] = savedEnv[key]; |
| 33 | + } |
| 34 | +}); |
| 35 | + |
| 36 | +describe("loadMemoryConfig — EMBED_TIMEOUT_MS / RERANK_TIMEOUT_MS", () => { |
| 37 | + it("leaves embed.timeoutMs and rerank.timeoutMs undefined when unset, so the clients' own defaults apply", () => { |
| 38 | + const config = loadMemoryConfig(); |
| 39 | + expect(config.memory.embed.timeoutMs).toBeUndefined(); |
| 40 | + expect(config.memory.rerank.timeoutMs).toBeUndefined(); |
| 41 | + }); |
| 42 | + |
| 43 | + it("flows EMBED_TIMEOUT_MS through to embed.timeoutMs", () => { |
| 44 | + process.env.EMBED_TIMEOUT_MS = "20000"; |
| 45 | + const config = loadMemoryConfig(); |
| 46 | + expect(config.memory.embed.timeoutMs).toBe(20_000); |
| 47 | + }); |
| 48 | + |
| 49 | + it("flows RERANK_TIMEOUT_MS through to rerank.timeoutMs", () => { |
| 50 | + process.env.RERANK_TIMEOUT_MS = "15000"; |
| 51 | + const config = loadMemoryConfig(); |
| 52 | + expect(config.memory.rerank.timeoutMs).toBe(15_000); |
| 53 | + }); |
| 54 | + |
| 55 | + it("rejects a non-positive-integer EMBED_TIMEOUT_MS", () => { |
| 56 | + process.env.EMBED_TIMEOUT_MS = "not-a-number"; |
| 57 | + expect(() => loadMemoryConfig()).toThrow("EMBED_TIMEOUT_MS must be a positive integer"); |
| 58 | + }); |
| 59 | +}); |
0 commit comments