import { describe, expect, it } from "vitest"; import { readRepoFile } from "~/utils/testing/repoPaths"; const webConfigRuntimeFiles = [ "apps/web/app/locale/i18next.server.ts", "apps/web/app/utils/session.server.ts", "apps/web/app/utils/analyticsCookie.server.ts", "apps/web/app/utils/loaders.middleware.ts", "apps/web/app/utils/stream/emitter.server.ts", ]; function readSource(relativePath: string) { return readRepoFile(relativePath); } function stripComments(source: string) { return source .replace(/\/\*[\s\S]*?\*\//g, "") .replace(/^\s*\/\/.*$/gm, "") .replace(/([^:])\/\/.*$/gm, "$1"); } describe("web config adoption for session and runtime-mode boundaries", () => { it.each(webConfigRuntimeFiles)("uses loadRequiredWebConfig in %s", (relativePath) => { const source = readSource(relativePath); expect(source, `${relativePath} should import the required web config loader`).toContain("loadRequiredWebConfig"); }); it.each(webConfigRuntimeFiles)("does not call permissive loadWebConfig().config in executable code in %s", (relativePath) => { const executableSource = stripComments(readSource(relativePath)); expect(executableSource, `${relativePath} should not use permissive web config access`).not.toMatch( /loadWebConfig\s*\(\s*\)\s*\.\s*config\b/ ); }); it.each(webConfigRuntimeFiles)("does not read SESSION_SECRET directly in executable code in %s", (relativePath) => { const source = stripComments(readSource(relativePath)); expect(source, `${relativePath} should not read SESSION_SECRET from process.env`).not.toMatch(/process\.env\.SESSION_SECRET\b/); }); it.each(webConfigRuntimeFiles)("does not read NODE_ENV directly in executable code in %s", (relativePath) => { const source = stripComments(readSource(relativePath)); expect(source, `${relativePath} should not read NODE_ENV from process.env`).not.toMatch(/process\.env\.NODE_ENV\b/); }); it("keeps loaders middleware admin-only development gate behind loadRequiredWebConfig", () => { const relativePath = "apps/web/app/utils/loaders.middleware.ts"; const source = readSource(relativePath); const executableSource = stripComments(source); expect(source, `${relativePath} should import loadRequiredWebConfig from the config package`).toMatch( /import\s+\{\s*loadRequiredWebConfig\s*\}\s+from\s+["']@toolctrl\/config["']/ ); expect(executableSource, `${relativePath} should initialize the required web config boundary once`).toContain( "const webConfig = loadRequiredWebConfig()" ); expect(executableSource, `${relativePath} should gate admin-only development behavior through webConfig.nodeEnv`).toContain( 'webConfig.nodeEnv !== "development"' ); expect(executableSource, `${relativePath} should not read NODE_ENV from process.env in executable code`).not.toMatch( /process\.env\.NODE_ENV\b/ ); }); });