import { describe, expect, it } from "vitest"; import { loadMcpRuntimeConfig } from "./config.js"; describe("MCP config", () => { it("defaults to the host-root MCP service shape", () => { const config = loadMcpRuntimeConfig({}); expect(config.listen.port).toBe(8080); expect(config.security.allowedHosts).toContain("mcp.hivegrid.de"); expect(config.security.allowedOrigins).toContain("https://mcp.hivegrid.de"); expect(config.oauth.resourceUrl).toBe("https://mcp.hivegrid.de"); expect(config.oauth.authorizationServerUrl).toBe("https://app.hivegrid.de"); }); it("parses explicit runtime values", () => { const config = loadMcpRuntimeConfig({ MCP_PORT: "9090", MCP_HOST: "127.0.0.1", MCP_ALLOWED_HOSTS: "mcp.hivegrid.de,localhost", MCP_ALLOWED_ORIGINS: "https://mcp.hivegrid.de,http://localhost:9090", API_KEY_LEGACY_PLAINTEXT_FALLBACK: "true", API_KEY_HASH_SECRET: "hash-secret", MCP_RESOURCE_URL: "https://staging-mcp.hivegrid.de/", MCP_AUTHORIZATION_SERVER_URL: "https://staging-app.hivegrid.de/", APP_REVISION: "abc123", }); expect(config.listen).toEqual({ host: "127.0.0.1", port: 9090 }); expect(config.apiKeys.allowLegacyPlaintextFallback).toBe(true); expect(config.revision).toBe("abc123"); expect(config.security.allowedHosts).toEqual(["mcp.hivegrid.de", "localhost"]); expect(config.oauth).toEqual({ resourceUrl: "https://staging-mcp.hivegrid.de", authorizationServerUrl: "https://staging-app.hivegrid.de", tokenHashSecret: "hash-secret", }); }); it("refuses to boot in production without a token hash secret", () => { expect(() => loadMcpRuntimeConfig({ NODE_ENV: "production" })).toThrow(/missing the production token hash secret/); expect(() => loadMcpRuntimeConfig({ NODE_ENV: "production", MCP_OAUTH_TOKEN_HASH_SECRET: " " })).toThrow(/token hash secret/); }); it("boots in production with MCP_OAUTH_TOKEN_HASH_SECRET alone", () => { const config = loadMcpRuntimeConfig({ NODE_ENV: "production", MCP_OAUTH_TOKEN_HASH_SECRET: "prod-token-secret" }); expect(config.oauth.tokenHashSecret).toBe("prod-token-secret"); }); it("boots in production with API_KEY_HASH_SECRET as the fallback token secret", () => { const config = loadMcpRuntimeConfig({ NODE_ENV: "production", API_KEY_HASH_SECRET: "prod-hash-secret" }); expect(config.apiKeys.hashSecret).toBe("prod-hash-secret"); expect(config.oauth.tokenHashSecret).toBe("prod-hash-secret"); }); it("does not enforce the hash secrets outside production", () => { expect(() => loadMcpRuntimeConfig({ NODE_ENV: "development" })).not.toThrow(); }); });