diff --git a/scripts/test-verify-cloudfront-release.sh b/scripts/test-verify-cloudfront-release.sh index fcbc6c2d..7cc5607b 100755 --- a/scripts/test-verify-cloudfront-release.sh +++ b/scripts/test-verify-cloudfront-release.sh @@ -8,7 +8,9 @@ CURRENT="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-2-1" PREVIOUS="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-1-1" NEW_HASH="1111111111111111111111111111111111111111111111111111111111111111" OLD_HASH="0000000000000000000000000000000000000000000000000000000000000000" -INDEX_HTML='
' +# Vite writes index.html with a trailing newline. Keep it in the fixture so +# the expected hash covers every served byte, exactly like dist/index.html. +INDEX_HTML=$'\n' INDEX_HASH="$(printf '%s' "${INDEX_HTML}" | python3 -c 'import hashlib,sys; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest())')" failures=0 @@ -75,12 +77,12 @@ if [[ "${url}" == *"/assets/"* ]]; then [[ -z "${output}" ]] && printf '%s' "${body}" exit 0 fi -body="$(cat "${state_dir}/index.html")" +# Serve index.html byte-for-byte, trailing newline included, like real curl. [[ -n "${dump}" ]] && printf 'HTTP/1.1 200 OK\nCache-Control: no-cache,no-store,must-revalidate\n\n' > "${dump}" if [[ -n "${output}" ]]; then - printf '%s' "${body}" > "${output}" + cat "${state_dir}/index.html" > "${output}" else - printf '%s' "${body}" + cat "${state_dir}/index.html" fi exit 0 CURL diff --git a/scripts/verify-cloudfront-release.sh b/scripts/verify-cloudfront-release.sh index 2382c37c..f0ed3b7c 100755 --- a/scripts/verify-cloudfront-release.sh +++ b/scripts/verify-cloudfront-release.sh @@ -80,10 +80,11 @@ observe() { last_status="$(printf '%s\n' "${parsed}" | sed -n '1p')" last_paths="$(printf '%s\n' "${parsed}" | sed -n '2p' | tr '\037' ' ')" last_path_ok="$(printf '%s\n' "${parsed}" | sed -n '3p')" - local body - body="$(curl -fsS --max-time 30 "${SITE_URL}/" || true)" - if [[ -n "${body}" ]]; then - last_hash="$(printf '%s' "${body}" | sha256_of)" + # Hash the response stream directly. Capturing the body in "$(...)" strips + # trailing newlines, so the hash never matched dist/index.html. + local hash + if hash="$(curl -fsS --max-time 30 "${SITE_URL}/" | sha256_of)" && [[ -n "${hash}" ]]; then + last_hash="${hash}" else last_hash="unreachable" fi