Initial commit: Discord-Claude Gateway with event-driven agent runtime

This commit is contained in:
2026-02-22 00:31:25 -05:00
commit 77d7c74909
58 changed files with 11772 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
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";
process.env.ANTHROPIC_API_KEY = "test-anthropic-key";
});
afterEach(() => {
process.env = originalEnv;
});
it("should load required environment variables", () => {
const config = loadConfig();
expect(config.discordBotToken).toBe("test-discord-token");
expect(config.anthropicApiKey).toBe("test-anthropic-key");
});
it("should apply default values for optional config", () => {
const config = loadConfig();
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";
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");
});
it("should throw when DISCORD_BOT_TOKEN is missing", () => {
delete process.env.DISCORD_BOT_TOKEN;
expect(() => loadConfig()).toThrow("DISCORD_BOT_TOKEN");
});
it("should throw when ANTHROPIC_API_KEY is missing", () => {
delete process.env.ANTHROPIC_API_KEY;
expect(() => loadConfig()).toThrow("ANTHROPIC_API_KEY");
});
it("should list all missing required variables in error message", () => {
delete process.env.DISCORD_BOT_TOKEN;
delete process.env.ANTHROPIC_API_KEY;
expect(() => loadConfig()).toThrow(
"Missing required environment variables: DISCORD_BOT_TOKEN, ANTHROPIC_API_KEY"
);
});
});