From c3b362951501d6c449d7a96b4a55d62ce08a6de7 Mon Sep 17 00:00:00 2001 From: KyuubiYoru Date: Fri, 17 Jul 2026 00:54:04 +0200 Subject: [PATCH] fix(deploy): gate smoke readiness atomically (#1) --- scripts/smoke-deployment.sh | 28 +++++++++++-------- .../DocumentationContractTests.cs | 4 ++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/scripts/smoke-deployment.sh b/scripts/smoke-deployment.sh index 937c454..4438487 100755 --- a/scripts/smoke-deployment.sh +++ b/scripts/smoke-deployment.sh @@ -58,6 +58,14 @@ temp_dir="$(mktemp -d)" host_log="$temp_dir/host.jsonl" join_log="$temp_dir/join.jsonl" host_pid='' +sanitize_log() { + jq -Rrc 'fromjson? | { + event: (.event // "unknown"), + status: (.status // "unknown"), + phase: (.phase // "unknown"), + hasListingId: (((.listingId // "") | length) > 0) + }' "$1" +} cleanup() { local status="$?" if [[ -n "$host_pid" ]] && kill -0 "$host_pid" 2>/dev/null; then @@ -66,8 +74,8 @@ cleanup() { fi if [[ "$status" -ne 0 ]]; then printf 'Deployment smoke failed; sanitized diagnostic events follow.\n' >&2 - [[ -f "$host_log" ]] && jq -c . "$host_log" >&2 || true - [[ -f "$join_log" ]] && jq -c . "$join_log" >&2 || true + [[ -f "$host_log" ]] && sanitize_log "$host_log" >&2 || true + [[ -f "$join_log" ]] && sanitize_log "$join_log" >&2 || true fi rm -rf "$temp_dir" return "$status" @@ -84,26 +92,24 @@ dotnet run --project "$PROJECT" --configuration "$BUILD_CONFIGURATION" --no-buil host_pid="$!" ready=false +listing_id='' for ((iteration = 0; iteration < TIMEOUT_SECONDS * 4; iteration++)); do - if jq -e 'select(.event == "host.ready")' "$host_log" >/dev/null 2>&1; then + if listing_id="$(jq -er ' + select(.event == "host.ready" and .status == "ready") + | .listingId // empty + ' "$host_log" 2>/dev/null | tail -n 1)" && [[ -n "$listing_id" ]]; then ready=true break fi if ! kill -0 "$host_pid" 2>/dev/null; then printf 'Host diagnostic stopped before it became ready.\n' >&2 - jq -c . "$host_log" >&2 || true + sanitize_log "$host_log" >&2 || true exit 1 fi sleep 0.25 done if [[ "$ready" != true ]]; then - printf 'Host diagnostic did not become ready within %s seconds.\n' "$TIMEOUT_SECONDS" >&2 - exit 1 -fi - -listing_id="$(jq -r 'select(.event == "host.ready") | .listingId' "$host_log" | tail -n 1)" -if [[ -z "$listing_id" || "$listing_id" == null ]]; then - printf 'Host diagnostic did not report a listing ID.\n' >&2 + printf 'Host diagnostic did not report a ready listing within %s seconds.\n' "$TIMEOUT_SECONDS" >&2 exit 1 fi diff --git a/tests/FinalFactory.Rendezvous.Tests/Documentation/DocumentationContractTests.cs b/tests/FinalFactory.Rendezvous.Tests/Documentation/DocumentationContractTests.cs index c8c3e91..360530e 100644 --- a/tests/FinalFactory.Rendezvous.Tests/Documentation/DocumentationContractTests.cs +++ b/tests/FinalFactory.Rendezvous.Tests/Documentation/DocumentationContractTests.cs @@ -61,7 +61,9 @@ public sealed partial class DocumentationContractTests Assert.Contains("metadata.st_mode & 0o077", helper, StringComparison.Ordinal); Assert.Contains("metadata.st_nlink != 1", helper, StringComparison.Ordinal); Assert.Contains("mint-local-publisher-credential.sh", smoke, StringComparison.Ordinal); - Assert.Contains("select(.event == \"host.ready\") | .listingId", smoke, StringComparison.Ordinal); + Assert.Contains("select(.event == \"host.ready\" and .status == \"ready\")", smoke, StringComparison.Ordinal); + Assert.Contains("hasListingId", smoke, StringComparison.Ordinal); + Assert.DoesNotContain("jq -c .", smoke, StringComparison.Ordinal); Assert.DoesNotContain("hexkey:", smoke, StringComparison.Ordinal); Assert.DoesNotContain("openssl dgst", smoke, StringComparison.Ordinal); }