import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import test from 'node:test'; const root = path.resolve(import.meta.dirname, '../..'); const compose = fs.readFileSync(path.join(root, 'docker-compose.gateway.yml'), 'utf8'); const deploy = fs.readFileSync(path.join(root, 'scripts/deploy-gateway.sh'), 'utf8'); const workflow = fs.readFileSync(path.join(root, '.gitea/workflows/gateway-build.yml'), 'utf8'); const clientDockerfile = fs.readFileSync(path.join(root, 'Dockerfile.client'), 'utf8'); const dockerfiles = ['Dockerfile', 'Dockerfile.client'] .map((file) => fs.readFileSync(path.join(root, file), 'utf8')); test('gateway deploy updates control without recreating dataplane', () => { assert.match(compose, /vpn-proxy-control:/); assert.match(compose, /vpn-proxy-dataplane:/); assert.match(compose, /DATAPLANE_SOCKET: \/run\/vpn-proxy\/dataplane\.sock/); assert.match(deploy, /up -d --no-deps --wait[^\n]+vpn-proxy-control/); assert.match(workflow, /UPDATE_DATAPLANE="\$\{UPDATE_DATAPLANE\}"/); assert.match(workflow, /node scripts\/runtime-impact\.mjs --stdin/); assert.match(workflow, /Affected components: \$\{AFFECTED_COMPONENTS\}/); assert.match(workflow, /Restart scope: \$\{RESTART_SCOPE\}/); assert.match(workflow, /git diff --no-renames --name-only "\$BEFORE_SHA"/); assert.match(workflow, /git diff-tree --no-renames/); assert.match(workflow, /git cat-file -e "\$\{BEFORE_SHA\}\^\{commit\}"/); assert.match(workflow, /npm_status=\$\?[\s\S]*! -x node_modules\/\.bin\/tsc[\s\S]*tail -n 200 \/root\/\.npm\/_logs\/\*-debug-0\.log[\s\S]*exit 1/); assert.match(workflow, /npm test[\s\S]*Image build and push skipped: no Gateway runtime impact\.[\s\S]*exit 0[\s\S]*docker login/); assert.match(workflow, /Image build and push skipped: no Gateway runtime impact\.[\s\S]*exit 0[\s\S]*\.\/scripts\/build-runtime-base\.sh/); assert.match(workflow, /Deploy skipped: no Gateway runtime impact\.[\s\S]*exit 0[\s\S]*bash scripts\/deploy-gateway\.sh/); assert.doesNotMatch(workflow, /grep -Eq/); }); test('runtime images contain only compiled application modules', () => { for (const dockerfile of dockerfiles) { assert.match(dockerfile, /RUN npm run build:production/); assert.match(dockerfile, /COPY --from=build \/src\/dist \/app\/dist/); assert.doesNotMatch(dockerfile, /\/app\/src/); } assert.match(clientDockerfile, /COPY index\.html vite\.config\.ts/); assert.doesNotMatch(clientDockerfile, /vite\.config\.js/); });