import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { test } from "node:test"; const read = (path) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8"); const compose = read("docker/docker-compose.prod.yml"); const dockerfile = read("docker/Dockerfile"); const web = compose.split(" web:\n")[1].split("\n collab:")[0]; const collab = compose.split("\n collab:\n")[1].split("\n mcp:")[0]; test("web receives the Chat URL at build time, without baking the signing secret", () => { assert.match( web, /NEXT_PUBLIC_CHAT_SERVER_URL: \$\{NEXT_PUBLIC_CHAT_SERVER_URL:-ws:\/\/localhost:1235\}/, ); assert.match( dockerfile, /ARG NEXT_PUBLIC_CHAT_SERVER_URL=ws:\/\/localhost:1235/, ); assert.match( dockerfile, /ENV NEXT_PUBLIC_CHAT_SERVER_URL=\$\{NEXT_PUBLIC_CHAT_SERVER_URL\}/, ); assert.doesNotMatch(dockerfile, /(?:ARG|ENV) CHAT_TICKET_SECRET/); const turbo = JSON.parse(read("turbo.json")); assert.ok(turbo.tasks.build.env.includes("NEXT_PUBLIC_*")); }); test("Workspace Chat uses its dedicated hostname, not the other app's hostname", () => { assert.match( read(".env.example"), /^NEXT_PUBLIC_CHAT_SERVER_URL="wss:\/\/echodo-chat\.stillwell\.cloud"$/m, ); const proxy = read("proxmox/ct116/traefik-ct100.example.yml"); assert.ok(proxy.includes("Host(`echodo-chat.stillwell.cloud`)")); assert.ok(!proxy.includes("Host(`chat.stillwell.cloud`)")); }); test("web and collab receive the same required runtime signing secret", () => { for (const service of [web, collab]) { assert.match( service, /CHAT_TICKET_SECRET=\$\{CHAT_TICKET_SECRET:\?[^}]+\}/, ); } }); test("collab exposes and checks both listeners", () => { assert.match(collab, /CHAT_PORT=\$\{CHAT_PORT:-1235\}/); assert.match(collab, /- "\$\{CHAT_PORT:-1235\}"/); assert.match(collab, /process\.env\.PORT\|\|1234/); assert.match(collab, /process\.env\.CHAT_PORT\|\|1235/); assert.match(dockerfile, /EXPOSE 1234 1235/); }); test("deployment preserves separately managed containers", () => { assert.doesNotMatch(read("scripts/deploy-prod.sh"), /--remove-orphans/); }); test("standalone publication matches the configurable Chat listener", () => { assert.match( read("docker/docker-compose.prod.standalone.yml"), /"\$\{CHAT_PORT:-1235\}:\$\{CHAT_PORT:-1235\}"/, ); }); test("Traefik example routes public Chat TLS to the second collab listener", () => { const proxy = read("proxmox/ct116/traefik-ct100.example.yml"); assert.match(proxy, /Host\(`echodo-chat\.stillwell\.cloud`\)/); assert.doesNotMatch(proxy, /Host\(`chat\.stillwell\.cloud`\)/); assert.match(proxy, /service: echodo-chat/); assert.match(proxy, /url: "http:\/\/192\.168\.68\.116:1235"/); });