From 965ea01af497932c805fa01343eab31f0247cb0b Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 13:45:43 +0000 Subject: [PATCH 1/3] fix(deploy): a version.json with a commit is healthy only for this commit The health step accepted the version number as proof, so the release before could pass when it carried the same number: rasgo-core records the API version and checks a static host, whose version.json has another app's version. A JSON answer with a commit field now counts only by that commit (full, or a prefix of at least 7 characters). OS-Ref: WFA-01.1 Refs: RINF-54 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Fk5Z87VM8EWrxKi79DrFju --- README.md | 4 +++- actions/deploy-core/core.sh | 10 +++++++++- tests/deploy-core.test.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 26a0fd2..ea458ce 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,9 @@ Every deploy follows the same order, and stops at the first step that fails: the server (WFA-01.1, D-104). If Core does not answer, nothing deploys: there is no emergency exit. 4. **Deploy.** The adapter: the Ploi webhook, or the upload to Cloudflare Pages. 5. **Health.** Asks `url` + `health.path` until it answers with this commit (full or short) or this version, up to - `health.timeout_s`. With `expect: status` it only checks that the site answers, which does not prove the new code is live. + `health.timeout_s`. A JSON answer with a `commit` field, such as a `version.json`, counts only by that commit: the + release before may carry the same version number. With `expect: status` it only checks that the site answers, + which does not prove the new code is live. 6. **deploy-finish.** Closes the deploy in Core with `success`, `failure` or, for a healthy rollback, `rolled_back`. It runs even when an earlier step failed, so failed deploys are recorded too. diff --git a/actions/deploy-core/core.sh b/actions/deploy-core/core.sh index 5475851..dd40a1b 100755 --- a/actions/deploy-core/core.sh +++ b/actions/deploy-core/core.sh @@ -225,9 +225,17 @@ cmd_start() { } body_has_version() { - local body="$1" commit version pattern + local body="$1" commit version pattern served commit="$(state_get commit)" version="$(state_get version)" + # A JSON body that names its commit (version.json) answers by the commit alone: the release before can carry the same + # version number, as when rasgo-core records the API version and the health host is a static app. + served="$(jq -r 'if type == "object" and has("commit") then .commit | tostring else empty end' "$body" 2>/dev/null || true)" + if [ -n "$served" ]; then + [ "$served" = "$commit" ] && return 0 + [ "${#served}" -ge 7 ] && [ "${commit#"$served"}" != "$commit" ] && return 0 + return 1 + fi grep -Fq "$commit" "$body" && return 0 grep -Fq "$(short "$commit")" "$body" && return 0 [ -n "$version" ] || return 1 diff --git a/tests/deploy-core.test.sh b/tests/deploy-core.test.sh index e672b0d..58d25f1 100644 --- a/tests/deploy-core.test.sh +++ b/tests/deploy-core.test.sh @@ -296,6 +296,32 @@ answer health 200 '{"version":"11.4.0"}' expect_fail "health: another version is not this one (timeout)" "no sirve la versión 1.4.0" health check "health: state failed" test "$(state health)" = failed +setup +export DEPLOY_ENVIRONMENT=production APPROVAL_ID=a GITHUB_REF_TYPE=tag GITHUB_REF_NAME=acme-v1.4.0 +core contract +jq '.health_timeout = "1"' "$RASGO_STATE" > "$RASGO_STATE.tmp" && mv "$RASGO_STATE.tmp" "$RASGO_STATE" +export HEALTH_INTERVAL=1 +answer health 200 '{"app":"web","version":"1.4.0","commit":"aaaaaaabbbbbbb"}' +expect_fail "health: the same version from another commit is the old release" "no sirve la versión 1.4.0" health + +setup +export DEPLOY_ENVIRONMENT=production APPROVAL_ID=a GITHUB_REF_TYPE=tag GITHUB_REF_NAME=acme-v1.4.0 +core contract +answer health 200 "{\"app\":\"web\",\"version\":\"2.0.0\",\"commit\":\"$SHA\"}" +expect_ok "health: with a commit field, the full commit counts whatever the version" health + +setup +core contract +answer health 200 "{\"app\":\"web\",\"version\":\"2.0.0\",\"commit\":\"${SHA:0:10}\"}" +expect_ok "health: with a commit field, a prefix of the commit counts" health + +setup +core contract +jq '.health_timeout = "1"' "$RASGO_STATE" > "$RASGO_STATE.tmp" && mv "$RASGO_STATE.tmp" "$RASGO_STATE" +export HEALTH_INTERVAL=1 +answer health 200 "{\"app\":\"web\",\"commit\":\"${SHA:0:4}\"}" +expect_fail "health: a commit shorter than 7 characters does not count" "no sirve la versión" health + setup sed -i 's| timeout_s: 5| expect: status\n timeout_s: 5|' rasgo.deploy.yml core contract From 3614770443c3a38b0321123bc776d1ed2067f61d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 13:49:53 +0000 Subject: [PATCH 2/3] fix(deploy): deploy-finish handles the 409 and 404 of Core Core answers deploy-finish with 409 when the deploy is no longer started, as when a retry arrives after it closed it, and with 404 when it does not know the deployment_id (rasgo-core#74). A 409 now warns and leaves the run as it was; a 404 says the deploy was not recorded. OS-Ref: WFA-01.1 Refs: RINF-54 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Fk5Z87VM8EWrxKi79DrFju --- actions/deploy-core/core.sh | 6 ++++++ tests/deploy-core.test.sh | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/actions/deploy-core/core.sh b/actions/deploy-core/core.sh index dd40a1b..b65a61e 100755 --- a/actions/deploy-core/core.sh +++ b/actions/deploy-core/core.sh @@ -308,6 +308,12 @@ cmd_finish() { note "Core registra el despliegue $id: $result." summary "- Core: despliegue $id cerrado como $result." ;; + # 409: the deploy is no longer started, as when a retry arrives after Core already closed it. Nothing stays open. + 409) + echo "::warning::Core ya tenía cerrado el despliegue $id (409): no se registra otra vez como $result." + summary "- Core: el despliegue $id ya estaba cerrado." + ;; + 404) fail "Core no conoce el despliegue $id (404): este despliegue ($result) no queda registrado." ;; *) fail "Core respondió $code a deploy-finish: el despliegue $id ($result) queda abierto en Core." ;; esac rm -f "$request" "$response" diff --git a/tests/deploy-core.test.sh b/tests/deploy-core.test.sh index 58d25f1..bc617a5 100644 --- a/tests/deploy-core.test.sh +++ b/tests/deploy-core.test.sh @@ -388,6 +388,21 @@ jq '.deployment_id = "01JDEPLOY" | .health = "ok"' "$RASGO_STATE" > "$RASGO_STAT answer finish 500 '{}' expect_fail "finish: says when the deploy stays open in Core" "queda abierto en Core" finish +setup +core contract +export CORE_TOKEN=t +jq '.deployment_id = "42" | .health = "ok"' "$RASGO_STATE" > "$RASGO_STATE.tmp" && mv "$RASGO_STATE.tmp" "$RASGO_STATE" +answer finish 409 '{"error":"This deployment is already success."}' +expect_ok "finish: a deploy Core already closed (409) does not fail the run" finish +check "finish: warns about the 409" has "ya tenía cerrado el despliegue 42" + +setup +core contract +export CORE_TOKEN=t +jq '.deployment_id = "42" | .health = "ok"' "$RASGO_STATE" > "$RASGO_STATE.tmp" && mv "$RASGO_STATE.tmp" "$RASGO_STATE" +answer finish 404 '{"error":"This deployment does not exist."}' +expect_fail "finish: a deploy Core does not know (404)" "no conoce el despliegue 42" finish + setup core contract export CORE_TOKEN=t VERSIONS='not json' From 34be9de8de1982eaa5e3b78a3c8aef58f89ba1c2 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 13:59:16 +0000 Subject: [PATCH 3/3] fix(deploy): deploy-start explains the 422 of Core Core validates deploy-start and rejects a contract with any key that looks like a secret with 422 (rasgo-core#75, PLN-11). The step now shows Core's reason, and a test checks that the contract sent to Core has no such key. OS-Ref: WFA-01.1 Refs: RINF-54 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Fk5Z87VM8EWrxKi79DrFju --- actions/deploy-core/core.sh | 5 +++++ tests/deploy-core.test.sh | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/actions/deploy-core/core.sh b/actions/deploy-core/core.sh index b65a61e..6f9b4a5 100755 --- a/actions/deploy-core/core.sh +++ b/actions/deploy-core/core.sh @@ -219,6 +219,11 @@ cmd_start() { fail "Core no confirma la aprobación: $(reason_text "$reason") ($rule). No se toca el servidor." ;; 401) fail "Core no acepta el token de despliegue (401): revisa RASGO_CORE_DEPLOY_TOKEN. No se despliega." ;; + # 422: the request does not validate, such as a contract key that looks like a secret (PLN-11). + 422) + reason="$(jq -r '.error // .message // "petición no válida"' "$response" 2> /dev/null || printf 'petición no válida')" + fail "Core rechaza la petición de deploy-start (422): $reason No se despliega." + ;; *) fail "Core respondió $code a deploy-start. No se despliega." ;; esac rm -f "$request" "$response" diff --git a/tests/deploy-core.test.sh b/tests/deploy-core.test.sh index bc617a5..533e1ca 100644 --- a/tests/deploy-core.test.sh +++ b/tests/deploy-core.test.sh @@ -229,6 +229,9 @@ check "start: calls deploy-start on Core" grep -Fxq "https://core.test/api/v1/de check "start: the body carries the approval tuple" test "$(jq -r '[.repository, .app, .environment, .commit_sha, .approval_id, .task] | join(" ")' "$FAKE/request.start.json")" = "rasgo-studio/acme-portal acme-portal production $SHA 01JAPPROVAL ACME01WEB-23" check "start: the body carries the run url" test "$(jq -r .run_url "$FAKE/request.start.json")" = "https://github.com/rasgo-studio/acme-portal/actions/runs/42" check "start: no rollback_of when there is none" test "$(jq 'has("rollback_of")' "$FAKE/request.start.json")" = false +# Core answers 422 when any key of the contract looks like a secret (DeployContractCheck of rasgo-core, PLN-11). +check "start: the contract goes without keys that look like secrets" test "$(jq '[.contract | paths | .[] | strings | select(test("secret|token|password|passwd|private[_-]?key|api[_-]?key|credential"; "i"))] | length' "$FAKE/request.start.json")" = 0 +check "start: the contract keeps the rest" test "$(jq -r '.contract.environments.production.approval' "$FAKE/request.start.json")" = core check "start: the token goes in a header" grep -Fq "Authorization: Bearer token-secret-value" "$FAKE/headers" check "start: the token is not on the command line" test "$(grep -c token-secret-value "$FAKE/args")" = 0 @@ -269,6 +272,12 @@ export CORE_TOKEN=t answer start 201 '{}' expect_fail "start: a 201 without deployment_id stops the deploy" "sin deployment_id" start +setup +core contract +export CORE_TOKEN=t +answer start 422 '{"error":"The deploy contract must not carry secrets: environments.staging.secrets.","rule":"PLN-11"}' +expect_fail "start: a 422 says why Core refuses the request" "must not carry secrets" start + # --- health ----------------------------------------------------------------------------------------------------- setup