91 lines
4.5 KiB
JavaScript
91 lines
4.5 KiB
JavaScript
// Rôle : vérifie que le workflow de livraison conserve ses barrières de validation et de provenance.
|
|
import assert from "node:assert/strict";
|
|
import { execFile } from "node:child_process";
|
|
import { readFile } from "node:fs/promises";
|
|
import { test } from "node:test";
|
|
import { promisify } from "node:util";
|
|
|
|
const deployWorkflowPath = ".forgejo/workflows/deploy-prod.yml";
|
|
const packageLockPath = "package-lock.json";
|
|
const remoteScriptPath = "scripts/deploy-sokko-g.sh";
|
|
const servicePath = "ops/systemd/sokko-g.service";
|
|
const validationWorkflowPath = ".forgejo/workflows/validate-main.yml";
|
|
const execFileAsync = promisify(execFile);
|
|
|
|
test("main pushes run the complete gate without access to deployment secrets", async () => {
|
|
const workflow = await readFile(validationWorkflowPath, "utf8");
|
|
|
|
assert.match(workflow, /push:\s+[\s\S]*branches:\s+[\s\S]*- main/);
|
|
assert.match(workflow, /ref: \$\{\{ gitea\.sha \}\}/);
|
|
assert.match(workflow, /container: "mcr\.microsoft\.com\/playwright:v1\.62\.1-noble@sha256:[0-9a-f]{64}"/);
|
|
assert.match(workflow, /npm ci/);
|
|
assert.match(workflow, /npm run check:full/);
|
|
assert.doesNotMatch(workflow, /workflow_dispatch:/);
|
|
assert.doesNotMatch(workflow, /secrets\./);
|
|
assert.doesNotMatch(workflow, /\bssh\b/);
|
|
});
|
|
|
|
test("production deployment requires a validated exact commit and pinned SSH host", async () => {
|
|
const workflow = await readFile(deployWorkflowPath, "utf8");
|
|
|
|
assert.match(workflow, /workflow_dispatch:\s+[\s\S]*commit:/);
|
|
assert.doesNotMatch(workflow, /push:/);
|
|
assert.match(workflow, /REQUESTED_COMMIT[\s\S]*\^\[0-9a-f\]\{40\}\$/);
|
|
assert.match(workflow, /deploy:\s+[\s\S]*needs: validate/);
|
|
assert.match(workflow, /validate:\s+[\s\S]*container: "mcr\.microsoft\.com\/playwright:v1\.62\.1-noble@sha256:[0-9a-f]{64}"/);
|
|
assert.match(workflow, /npm ci/);
|
|
assert.match(workflow, /npm run check:full/);
|
|
assert.match(workflow, /git merge-base --is-ancestor "\$commit" origin\/main/);
|
|
assert.match(workflow, />> "\$GITEA_OUTPUT"/);
|
|
assert.match(workflow, /DEPLOY_COMMIT: \$\{\{ needs\.validate\.outputs\.commit \}\}/);
|
|
assert.match(workflow, /deploy-contract/);
|
|
assert.match(workflow, /deploy-sokko-g --commit/);
|
|
assert.match(workflow, /\[webapps\.shinuwa\.fr\]:2911/);
|
|
assert.match(workflow, /shinuwa@webapps\.shinuwa\.fr/);
|
|
assert.match(workflow, /StrictHostKeyChecking=yes/);
|
|
assert.doesNotMatch(workflow, /StrictHostKeyChecking=no/);
|
|
assert.doesNotMatch(workflow, /192\.168\.0\.100/);
|
|
assert.doesNotMatch(workflow, /\$\{\{\s*forgejo\./);
|
|
});
|
|
|
|
test("validation containers match the locked Playwright release", async () => {
|
|
const [lockContents, validationWorkflow, deployWorkflow] = await Promise.all([
|
|
readFile(packageLockPath, "utf8"),
|
|
readFile(validationWorkflowPath, "utf8"),
|
|
readFile(deployWorkflowPath, "utf8")
|
|
]);
|
|
const lock = JSON.parse(lockContents);
|
|
const playwrightVersion = lock.packages["node_modules/@playwright/test"].version;
|
|
const expectedImage = `mcr.microsoft.com/playwright:v${playwrightVersion}-noble@sha256:`;
|
|
|
|
assert.ok(validationWorkflow.includes(expectedImage));
|
|
assert.ok(deployWorkflow.includes(expectedImage));
|
|
assert.doesNotMatch(validationWorkflow, /playwright install --with-deps/);
|
|
assert.doesNotMatch(deployWorkflow, /playwright install --with-deps/);
|
|
});
|
|
|
|
test("the versioned remote script builds and activates only the requested commit", async () => {
|
|
await execFileAsync("bash", ["-n", remoteScriptPath]);
|
|
const script = await readFile(remoteScriptPath, "utf8");
|
|
|
|
assert.match(script, /\$1 == "--commit"/);
|
|
assert.match(script, /\^\[0-9a-f\]\{40\}\$/);
|
|
assert.match(script, /flock --wait 900/);
|
|
assert.match(script, /merge-base --is-ancestor/);
|
|
assert.match(script, /worktree add --detach/);
|
|
assert.match(script, /"\$NPM_BIN" --prefix "\$worktree" ci/);
|
|
assert.match(script, /"\$NPM_BIN" --prefix "\$worktree" run build/);
|
|
assert.match(script, /checkout --detach "\$requested_commit"/);
|
|
assert.match(script, /write_state previous-commit/);
|
|
assert.match(script, /systemctl is-active --quiet/);
|
|
assert.match(script, /systemctl show --property=ExecStart/);
|
|
assert.doesNotMatch(script, /git\s+pull/);
|
|
});
|
|
|
|
test("the production service uses the same pinned Node runtime", async () => {
|
|
const service = await readFile(servicePath, "utf8");
|
|
|
|
assert.match(service, /ExecStart=\/home\/shinuwa\/\.nvm\/versions\/node\/v24\.11\.1\/bin\/npm start/);
|
|
assert.match(service, /Environment=PATH=\/home\/shinuwa\/\.nvm\/versions\/node\/v24\.11\.1\/bin:/);
|
|
assert.doesNotMatch(service, /v26\.3\.0/);
|
|
});
|