Read the health address and roll back correctly in the deploy script
Run 324 polled 127.0.0.1:5173 instead of the service's HOST and PORT: each env file overwrote the value found in the previous one, even when it did not define the variable, so the check failed against a healthy server. The rollback then stopped at once, because its local previous_commit redeclared the read-only global of the same name. A file now keeps the value of the previous one unless it defines the variable, and the rollback uses its own name. A test runs the lookup on real env files and another forbids locals that shadow read-only globals; both fail on the previous script. The fix applies once the script is reinstalled on the server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2831f01195
commit
632cc06a16
3 changed files with 41 additions and 5 deletions
|
|
@ -1,7 +1,9 @@
|
|||
// 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 { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { test } from "node:test";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
|
|
@ -114,6 +116,35 @@ test("the remote script ships the commit's dependencies and waits for a healthy
|
|||
}
|
||||
});
|
||||
|
||||
// Exécute une fonction du script seule, avec ses dépendances remplacées par celles du test.
|
||||
async function runScriptFunction(name, prelude, call) {
|
||||
const script = await readFile(remoteScriptPath, "utf8");
|
||||
const body = script.match(new RegExp(`^${name}\\(\\) \\{[\\s\\S]*?^\\}$`, "m"))?.[0];
|
||||
assert.ok(body, name);
|
||||
const { stdout } = await execFileAsync("bash", ["-c", `set -Eeuo pipefail\n${prelude}\n${body}\n${call}`]);
|
||||
return stdout;
|
||||
}
|
||||
|
||||
test("the health check reads HOST and PORT from whichever file defines them, the service file winning", async (t) => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "sokko-deploy-env-"));
|
||||
t.after(() => rm(directory, { recursive: true, force: true }));
|
||||
await writeFile(join(directory, ".env"), "PORT=3102\nHOST=10.0.0.1\n");
|
||||
await writeFile(join(directory, "cards.env"), "CARDS_ENABLED=true\nHOST=\"192.168.0.100\"\n");
|
||||
const prelude = `APP_ROOT=${JSON.stringify(directory)}; SERVICE_ENV_FILE=${JSON.stringify(join(directory, "cards.env"))}`;
|
||||
|
||||
assert.equal(await runScriptFunction("service_env_value", prelude, "service_env_value PORT"), "3102");
|
||||
assert.equal(await runScriptFunction("service_env_value", prelude, "service_env_value HOST"), "192.168.0.100");
|
||||
assert.equal(await runScriptFunction("service_env_value", prelude, "service_env_value MISSING"), "");
|
||||
});
|
||||
|
||||
test("no function of the remote script redeclares one of its read-only globals", async () => {
|
||||
const script = await readFile(remoteScriptPath, "utf8");
|
||||
const readonlyNames = [...script.matchAll(/^readonly ([A-Za-z_]\w*)=/gm)].map((match) => match[1]);
|
||||
const localNames = new Set([...script.matchAll(/^\s+local ([^=\n]+)/gm)].flatMap((match) => match[1].trim().split(/\s+/)).map((name) => name.split("=")[0]));
|
||||
assert.ok(readonlyNames.includes("previous_commit"));
|
||||
assert.deepEqual(readonlyNames.filter((name) => localNames.has(name)), []);
|
||||
});
|
||||
|
||||
test("the production service uses the same pinned Node runtime", async () => {
|
||||
const service = await readFile(servicePath, "utf8");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue