/** * TASK-0091 — realtime config: the gateway port must come from `REALTIME_PORT` * (the documented env), NOT the shared `PORT`, which the dev stack sets to the * API's 4000. Regression: the gateway used to read `PORT` and die with * EADDRINUSE when launched from the same sourced env as the API. */ import { describe, expect, it } from "vitest"; import { loadConfig } from "../src/config.js"; const BASE = { JWT_SECRET: "test-secret", INTERNAL_SERVICE_TOKEN: "tok" }; describe("realtime loadConfig — port resolution", () => { it("defaults to 4001 when neither REALTIME_PORT nor PORT is set", () => { const cfg = loadConfig({ ...BASE }); expect(cfg.port).toBe(4001); expect(cfg.healthPort).toBe(4002); }); it("reads REALTIME_PORT and does NOT take the API's PORT (dev-stack collision)", () => { const cfg = loadConfig({ ...BASE, PORT: "4000", REALTIME_PORT: "4001" }); expect(cfg.port).toBe(4001); expect(cfg.healthPort).toBe(4002); }); it("honors an explicit REALTIME_PORT override", () => { const cfg = loadConfig({ ...BASE, PORT: "4000", REALTIME_PORT: "5050" }); expect(cfg.port).toBe(5050); }); it("falls back to PORT only when REALTIME_PORT is unset (standalone run)", () => { const cfg = loadConfig({ ...BASE, PORT: "6000" }); expect(cfg.port).toBe(6000); }); it("throws without JWT_SECRET", () => { expect(() => loadConfig({ ...BASE, JWT_SECRET: "" })).toThrow(/JWT_SECRET/); expect(() => loadConfig({ ...BASE, JWT_SECRET: " " })).toThrow(/JWT_SECRET/); expect(() => loadConfig({} as NodeJS.ProcessEnv)).toThrow(/JWT_SECRET/); }); });