diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index 9a963eb..2587524 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -440,3 +440,4 @@ {"id":"int-f75cefa76d1475da43d7744c088a4b87","kind":"field_change","created_at":"2026-11-20T18:21:23.188596174Z","actor":"Shinuwa","issue_id":"sokko-g-eecb.1","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Côté dépôt : node_modules livré avec dist (npm prune --omit=dev), route /api/health et attente de santé dans le script et les workflows, retour arrière de node_modules. Réinstallation du script sur le serveur suivie dans sokko-g-6vjw."}} {"id":"int-48d5d2077d92a245d65c3b067eabf51b","kind":"field_change","created_at":"2026-11-20T18:21:36.31133937Z","actor":"Shinuwa","issue_id":"sokko-g-eecb.6","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"AdminPanel chargé à la demande : chunk CardsPage 311,6 → 191,8 ko (77,6 → 47,8 ko gzip). Séparation configuration/catalogue non faite : 30 ko gzip une fois la compression active (sokko-g-6vjw)."}} {"id":"int-94dfd02acf23d34d6e65722cbb2386e4","kind":"field_change","created_at":"2026-11-21T09:02:20.762620584Z","actor":"Shinuwa","issue_id":"sokko-g-9r25","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"dev-auth limit is now the devAuthRateLimit option (default 10); the cards E2E server raises it like apiRateLimit. Full cards suite 14/14 locally."}} +{"id":"int-6e97e6d3763a00e700221d758dc65309","kind":"field_change","created_at":"2026-11-21T10:43:10.046418077Z","actor":"Shinuwa","issue_id":"sokko-g-65n7","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"service_env_value keeps a value a later file does not define; rollback uses rollback_commit instead of redeclaring the readonly previous_commit. Both covered by new tests that fail on the old script."}} diff --git a/scripts/deploy-sokko-g.sh b/scripts/deploy-sokko-g.sh index 60e31a0..b50b889 100755 --- a/scripts/deploy-sokko-g.sh +++ b/scripts/deploy-sokko-g.sh @@ -43,8 +43,9 @@ as_app_user() { sudo -u "$APP_USER" "$@" } +# Le nom diffère de la variable globale `previous_commit`, en lecture seule : `local` la redéclarerait et arrêterait le script. restore_previous_release() { - local previous_commit=$1 + local rollback_commit=$1 as_app_user rm -rf -- "$APP_ROOT/website/dist" if [[ -n "$backup_dist" && -d "$backup_dist" ]]; then @@ -55,18 +56,21 @@ restore_previous_release() { as_app_user rm -rf -- "$APP_ROOT/node_modules" as_app_user mv "$backup_node_modules" "$APP_ROOT/node_modules" fi - as_app_user git -C "$APP_ROOT" checkout --detach "$previous_commit" + as_app_user git -C "$APP_ROOT" checkout --detach "$rollback_commit" systemctl restart "$SERVICE_NAME" || true } # Valeur d'une variable telle que le service la voit : l'environnement systemd l'emporte sur le .env du site. +# Un fichier qui ne définit pas la variable garde la valeur trouvée dans le précédent. service_env_value() { local name=$1 - local file value="" + local file found value="" for file in "$APP_ROOT/.env" "$SERVICE_ENV_FILE"; do [[ -r "$file" ]] || continue - value="$(sed -n "s/^[[:space:]]*$name[[:space:]]*=[[:space:]]*//p" "$file" | tail -n 1 | sed -e 's/^["'"'"']//' -e 's/["'"'"'][[:space:]]*$//' -e 's/[[:space:]]*$//')" || true + grep -Eq "^[[:space:]]*$name[[:space:]]*=" "$file" || continue + found="$(sed -n "s/^[[:space:]]*$name[[:space:]]*=[[:space:]]*//p" "$file" | tail -n 1 | sed -e 's/^["'"'"']//' -e 's/["'"'"'][[:space:]]*$//' -e 's/[[:space:]]*$//')" || true + value=$found done printf '%s' "$value" } diff --git a/tests/deployment-workflow.test.mjs b/tests/deployment-workflow.test.mjs index c5eed0a..e792e3a 100644 --- a/tests/deployment-workflow.test.mjs +++ b/tests/deployment-workflow.test.mjs @@ -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");