77 lines
2.7 KiB
TypeScript
77 lines
2.7 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
import { loadConfig } from "../../src/config.js";
|
|
|
|
describe("loadConfig", () => {
|
|
const originalEnv = process.env;
|
|
|
|
beforeEach(() => {
|
|
process.env = { ...originalEnv };
|
|
// Set required vars by default
|
|
process.env.DISCORD_BOT_TOKEN = "test-discord-token";
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
it("should load required environment variables", () => {
|
|
const config = loadConfig();
|
|
expect(config.discordBotToken).toBe("test-discord-token");
|
|
});
|
|
|
|
it("should apply default values for optional config", () => {
|
|
const config = loadConfig();
|
|
expect(config.claudeCliPath).toBe("claude");
|
|
expect(config.allowedTools).toEqual(["Read", "Write", "Edit", "Glob", "Grep", "WebSearch", "WebFetch"]);
|
|
expect(config.permissionMode).toBe("bypassPermissions");
|
|
expect(config.queryTimeoutMs).toBe(120_000);
|
|
expect(config.maxConcurrentQueries).toBe(5);
|
|
expect(config.configDir).toBe("./config");
|
|
expect(config.maxQueueDepth).toBe(100);
|
|
expect(config.outputChannelId).toBeUndefined();
|
|
});
|
|
|
|
it("should parse ALLOWED_TOOLS from comma-separated string", () => {
|
|
process.env.ALLOWED_TOOLS = "Read,Write,Bash";
|
|
const config = loadConfig();
|
|
expect(config.allowedTools).toEqual(["Read", "Write", "Bash"]);
|
|
});
|
|
|
|
it("should trim whitespace from ALLOWED_TOOLS entries", () => {
|
|
process.env.ALLOWED_TOOLS = " Read , Write , Bash ";
|
|
const config = loadConfig();
|
|
expect(config.allowedTools).toEqual(["Read", "Write", "Bash"]);
|
|
});
|
|
|
|
it("should read all optional environment variables", () => {
|
|
process.env.PERMISSION_MODE = "default";
|
|
process.env.QUERY_TIMEOUT_MS = "60000";
|
|
process.env.MAX_CONCURRENT_QUERIES = "10";
|
|
process.env.CONFIG_DIR = "/custom/config";
|
|
process.env.MAX_QUEUE_DEPTH = "200";
|
|
process.env.OUTPUT_CHANNEL_ID = "123456789";
|
|
process.env.CLAUDE_CLI_PATH = "/usr/local/bin/claude";
|
|
|
|
const config = loadConfig();
|
|
expect(config.permissionMode).toBe("default");
|
|
expect(config.queryTimeoutMs).toBe(60_000);
|
|
expect(config.maxConcurrentQueries).toBe(10);
|
|
expect(config.configDir).toBe("/custom/config");
|
|
expect(config.maxQueueDepth).toBe(200);
|
|
expect(config.outputChannelId).toBe("123456789");
|
|
expect(config.claudeCliPath).toBe("/usr/local/bin/claude");
|
|
});
|
|
|
|
it("should throw when DISCORD_BOT_TOKEN is missing", () => {
|
|
delete process.env.DISCORD_BOT_TOKEN;
|
|
expect(() => loadConfig()).toThrow("DISCORD_BOT_TOKEN");
|
|
});
|
|
|
|
it("should list all missing required variables in error message", () => {
|
|
delete process.env.DISCORD_BOT_TOKEN;
|
|
expect(() => loadConfig()).toThrow(
|
|
"Missing required environment variables: DISCORD_BOT_TOKEN"
|
|
);
|
|
});
|
|
});
|