From 416358980d0c5ac3321f61a55a2489e08c38b544 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Thu, 18 Jun 2026 12:02:54 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`codex/c?= =?UTF-8?q?heck-docker-container-status`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @MEECHAIN1. * https://github.com/MEECHAIN1/MeeChain-Connect/pull/83#issuecomment-4387356415 The following files were modified: * `scripts/test-production.sh` --- scripts/test-production.sh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) mode change 100755 => 100644 scripts/test-production.sh diff --git a/scripts/test-production.sh b/scripts/test-production.sh old mode 100755 new mode 100644 index 18bae57..945f182 --- a/scripts/test-production.sh +++ b/scripts/test-production.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -# Production post-deploy validation for MeeChain Connect. +# usage prints the help message describing the script's command-line arguments, examples, and environment variables. usage() { cat <<'USAGE' @@ -91,11 +91,16 @@ HEADERS="$TMP_DIR/headers" BODY="$TMP_DIR/body" trap 'rm -rf "$TMP_DIR"' EXIT +# pass prints the provided message prefixed with a checkmark (✅) to stdout. pass() { echo "✅ $*"; } +# fail prints an error message to stderr and exits the script with code 1. fail() { echo "❌ $*" >&2; exit 1; } +# warn prints a warning message to stdout with a warning emoji prefix. warn() { echo "⚠️ $*"; } +# info พิมพ์ข้อความข้อมูลไปยัง stdout พร้อมคำนำหน้า ℹ️ info() { echo "ℹ️ $*"; } +# require_cmd ตรวจสอบว่าคำสั่งมีอยู่ใน PATH หากไม่พบจะหยุดสคริปต์ด้วยข้อผิดพลาด require_cmd() { local cmd="$1" if ! command -v "$cmd" >/dev/null 2>&1; then @@ -103,6 +108,7 @@ require_cmd() { fi } +# normalize_url แปลง URL ให้เป็น origin (แบบแผน โฮสต์ และพอร์ต) และส่งออกไปยัง stdout หรือล้มเหลวหากกำหนด URL ไม่ถูกต้อง normalize_url() { local raw="$1" local original="${raw%/}" @@ -127,10 +133,12 @@ if [[ -n "$CF_ACCESS_CLIENT_ID" && -n "$CF_ACCESS_CLIENT_SECRET" ]]; then ACCESS_HEADERS+=(-H "CF-Access-Client-Secret: ${CF_ACCESS_CLIENT_SECRET}") fi +# status_code extracts and prints the HTTP status code from the response headers file. status_code() { awk 'toupper($1) ~ /^HTTP/ {code=$2} END{print code}' "$HEADERS" } +# assert_no_access_redirect fails if a Cloudflare Access redirect is detected in the HTTP response headers. assert_no_access_redirect() { local location location="$(awk 'tolower($1)=="location:" {print $2}' "$HEADERS" | tr -d '\r' || true)" @@ -139,6 +147,7 @@ assert_no_access_redirect() { fi } +# curl_get performs an HTTP GET request to the specified URL and saves the response headers and body for subsequent validation. curl_get() { local url="$1" if ! curl "${CURL_ARGS[@]}" -D "$HEADERS" -o "$BODY" "${ACCESS_HEADERS[@]}" "$url"; then @@ -146,6 +155,7 @@ curl_get() { fi } +# curl_post_json posts JSON to the specified URL and saves the response. curl_post_json() { local url="$1" local payload="$2" @@ -158,6 +168,7 @@ curl_post_json() { fi } +# assert_http_200 validates that the most recent HTTP response has status code 200. assert_http_200() { local label="$1" local code @@ -173,11 +184,13 @@ assert_http_200() { pass "$label HTTP 200" } +# json_field อ่านข้อมูล JSON จากการตอบสนอง ประเมินนิพจน์ที่ให้มา และแสดงผลลัพธ์ หรือออกจากโปรแกรมด้วยรหัส 3 หากค่าไม่มีหรือเป็น null json_field() { local expression="$1" node -e "const fs=require('fs'); const data=JSON.parse(fs.readFileSync(process.argv[1], 'utf8')); const value=($expression); if (value === undefined || value === null) process.exit(3); console.log(typeof value === 'object' ? JSON.stringify(value) : value);" "$BODY" } +# assert_json_field_equals ตรวจสอบว่าเขตข้อมูล JSON ของการตอบสนองตรงกับค่าที่คาดหวัง assert_json_field_equals() { local label="$1" local expression="$2" @@ -192,6 +205,7 @@ assert_json_field_equals() { pass "$label = $actual" } +# assert_json_field_present ตรวจสอบว่าช่องข้อมูล JSON ที่ระบุโดยนิพจน์นั้นมีอยู่และถูกต้อง assert_json_field_present() { local label="$1" local expression="$2" @@ -199,6 +213,7 @@ assert_json_field_present() { pass "$label present" } +# assert_json_field_truthy_or_warn confirms a JSON field equals true, failing in strict mode (EXPECT_UPSTREAM_CONNECTED=1) or warning in lenient mode with degraded behavior noted. assert_json_field_truthy_or_warn() { local label="$1" local expression="$2" @@ -215,6 +230,7 @@ assert_json_field_truthy_or_warn() { fi } +# assert_body_contains ตรวจสอบว่าเนื้อหาการตอบสนองมีข้อความที่กำหนด assert_body_contains() { local label="$1" local expected="$2" @@ -227,6 +243,7 @@ assert_body_contains() { pass "$label contains '$expected'" } +# check_get_json ส่งคำขอ GET ไปยังจุดปลายทาง API และตรวจสอบว่าการตอบสนอง HTTP มีสถานะ 200 check_get_json() { local path="$1" local label="$2" @@ -236,6 +253,7 @@ check_get_json() { } +# check_app_shell ตรวจสอบว่าเปลือกแอปพลิเคชันมีข้อความที่คาดหวัง check_app_shell() { if [[ "$SKIP_APP" -eq 1 ]]; then info "skipping app shell check (--skip-app)" @@ -246,6 +264,7 @@ check_app_shell() { assert_body_contains "app shell" "$EXPECTED_APP_TEXT" } +# check_health_endpoints validates the health status of root, API, and RPC endpoints and confirms correct chain configuration. check_health_endpoints() { check_get_json "/health" "root health" assert_json_field_equals "root health status" "data.status" "ok" @@ -260,6 +279,7 @@ check_health_endpoints() { assert_json_field_present "RPC health mode" "data.mode" } +# check_rpc_proxy ตรวจสอบจุดปลายทาง RPC proxy โดยตรวจสอบการตอบสนองรหัสเชนและหมายเลขบล็อก check_rpc_proxy() { info "POST ${BASE_URL}/rpc eth_chainId" curl_post_json "${BASE_URL}/rpc" '{"jsonrpc":"2.0","id":1,"method":"eth_chainId","params":[]}' @@ -272,6 +292,7 @@ check_rpc_proxy() { assert_json_field_present "RPC eth_blockNumber result" "data.result" } +# check_network_config ตรวจสอบการกำหนดค่าเครือข่ายและสถานะการเชื่อมต่อ web3 check_network_config() { check_get_json "/api/network" "network config" assert_json_field_equals "network chainId" "String(data.chainId)" "$EXPECTED_CHAIN_ID_HEX" @@ -283,12 +304,14 @@ check_network_config() { } +# normalize_dns_name removes trailing dots from a DNS name and converts it to lowercase. normalize_dns_name() { local name="$1" name="${name%.}" printf '%s\n' "${name,,}" } +# check_expected_cname_target validates that a host's CNAME record matches the expected target, failing or warning based on the EXPECTED_CNAME_STRICT setting. check_expected_cname_target() { local host="$1" [[ -n "$EXPECTED_CNAME_TARGET" ]] || return @@ -320,6 +343,7 @@ check_expected_cname_target() { warn "$message" } +# check_external_network validates DNS resolution for the base URL's hostname and checks its CNAME target against expected configuration. check_external_network() { if [[ "$SKIP_NETWORK" -eq 1 ]]; then info "skipping external network checks (--skip-network)" @@ -342,6 +366,7 @@ check_external_network() { check_expected_cname_target "$host" } +# run_checks_for_base_url orchestrates production post-deploy validation checks for a MeeChain Connect HTTP endpoint. run_checks_for_base_url() { BASE_URL="$(normalize_url "$1")" @@ -363,6 +388,7 @@ run_checks_for_base_url() { pass "production validation checklist passed for $BASE_URL" } +# main orchestrates production post-deployment validation for the primary and additional configured base URLs. main() { require_cmd curl require_cmd node