import { describe, expect, it } from "vitest"; import { resolveConfig } from "#lib/server/config.ts"; const fosterKnotUrl = (foster?: string) => resolveConfig({ FOSTER_KNOT_URL: foster }).fosterKnotUrl; describe("resolveConfig fosterKnotUrl", () => { it("parses a bare-origin url into the knot origin, ignoring a trailing slash", () => { expect(fosterKnotUrl("https://foster.test")).toBe("foster.test"); expect(fosterKnotUrl("https://foster.test/")).toBe("foster.test"); expect(fosterKnotUrl("http://127.0.0.1:5555")).toBe("127.0.0.1:5555"); }); it("is empty when unset or blank", () => { expect(fosterKnotUrl()).toBe(""); expect(fosterKnotUrl(" ")).toBe(""); }); it.each(["https://foster.test/foster", "foster.test"])( "rejects %s at config load instead of quietly routing reads to the origin", (url) => { expect(() => fosterKnotUrl(url)).toThrow(/FOSTER_KNOT_URL/); } ); }); describe("resolveConfig metrics export", () => { it("is off unless an endpoint is set, and names the service svfe", () => { expect(resolveConfig({})).toMatchObject({ otlpEndpoint: "", otlpServiceName: "svfe" }); }); it("reads the collector, its login and the resource from the env", () => { expect( resolveConfig({ SVFE_OTLP_ENDPOINT: "https://telemetry.test/", SVFE_OTLP_AUTH: " user:pass ", SVFE_OTLP_SERVICE_NAME: "svfe-prod", OTEL_RESOURCE_ATTRIBUTES: "cloud.region=europe-north1" }) ).toMatchObject({ otlpEndpoint: "https://telemetry.test", otlpAuth: "user:pass", otlpServiceName: "svfe-prod", otlpResourceAttributes: "cloud.region=europe-north1" }); }); }); describe("resolveConfig admission", () => { it("lets every request in when nothing is set", () => { expect(resolveConfig({})).toMatchObject({ ssrMaxInFlight: 0, ssrHeavyMaxInFlight: 0, ssrQueueMax: 64, ssrQueueWaitMs: 1_000 }); }); it("reads the budgets and the wait", () => { expect( resolveConfig({ SSR_MAX_IN_FLIGHT: "96", SSR_HEAVY_MAX_IN_FLIGHT: "32", SSR_QUEUE_MAX: "0", SSR_QUEUE_WAIT_MS: "250" }) ).toMatchObject({ ssrMaxInFlight: 96, ssrHeavyMaxInFlight: 32, ssrQueueMax: 0, ssrQueueWaitMs: 250 }); }); });