3333: " ${INST_ROOT:? could not locate tests/ instances/ above $PWD } "
3434
3535inst=" $INST_ROOT /$name /instance.yaml"
36- [[ -f " $inst " ]] || { echo " no instance.yaml at $inst " >&2 ; exit 2; }
36+ [[ -f " $inst " ]] || {
37+ echo " no instance.yaml at $inst " >&2
38+ exit 2
39+ }
3740
3841INST_DIR_PARENT=" ${INST_ROOT%/ instances} "
3942PLATFORM_DIST=" $INST_DIR_PARENT /xtest/platform/dist"
@@ -51,12 +54,12 @@ declare -A PORT_OF=(
5154
5255# Helper: resolve a pin (ref or dist) to expected_sha by reading .version.
5356expected_sha_for () {
54- local pin=" $1 " # could be a ref like 'main' or 'pr:3537', or a dist slug
57+ local pin=" $1 " # could be a ref like 'main' or 'pr:3537', or a dist slug
5558 for cand in " $PLATFORM_DIST " /* /; do
5659 [[ -f " $cand /.version" ]] || continue
57- if grep -Fq " ref=$pin " " $cand /.version" \
58- || grep -Fq " ref=refs/pull/${pin# pr: } /head" " $cand /.version" \
59- || [[ " $( basename " ${cand%/ } " ) " == " $pin " ]]; then
60+ if grep -Fq " ref=$pin " " $cand /.version" ||
61+ grep -Fq " ref=refs/pull/${pin# pr: } /head" " $cand /.version" ||
62+ [[ " $( basename " ${cand%/ } " ) " == " $pin " ]]; then
6063 awk -F= ' /^sha=/ {print substr($2,1,12); exit}' " $cand /.version"
6164 return
6265 fi
@@ -69,9 +72,15 @@ actual_sha_for_port() {
6972 local port=" $1 "
7073 local pid binary version
7174 pid=" $( lsof -nP -iTCP:" $port " -sTCP:LISTEN 2> /dev/null | awk ' NR>1 {print $2; exit}' ) "
72- [[ -z " $pid " ]] && { echo " " ; return ; }
75+ [[ -z " $pid " ]] && {
76+ echo " "
77+ return
78+ }
7379 binary=" $( ps -o command= -p " $pid " 2> /dev/null | awk ' {print $1}' ) "
74- [[ -f " $binary " ]] || { echo " ?" ; return ; }
80+ [[ -f " $binary " ]] || {
81+ echo " ?"
82+ return
83+ }
7584 version=" $( dirname " $binary " ) /.version"
7685 [[ -f " $version " ]] && awk -F= ' /^sha=/ {print substr($2,1,12); exit}' " $version " || echo " ?"
7786}
@@ -84,7 +93,7 @@ health_of() {
8493
8594# Extract pins from instance.yaml. yq optional; fall back to grep.
8695get_pin () {
87- local field=" $1 " # e.g. .platform OR .kas.km1
96+ local field=" $1 " # e.g. .platform OR .kas.km1
8897 if command -v yq > /dev/null 2>&1 ; then
8998 yq -r " ($field .source.ref? // $field .dist? // \"\" )" " $inst "
9099 else
@@ -117,9 +126,12 @@ pin="$(get_pin .platform)"
117126exp=" $( expected_sha_for " $pin " ) "
118127act=" $( actual_sha_for_port 8080) "
119128hc=" $( health_of 8080) "
120- if [[ -z " $pin " ]]; then status=NO-PIN
121- elif [[ -z " $act " ]]; then status=NOT-RUNNING
122- elif [[ " $act " == " $exp " ]]; then status=MATCH
129+ if [[ -z " $pin " ]]; then
130+ status=NO-PIN
131+ elif [[ -z " $act " ]]; then
132+ status=NOT-RUNNING
133+ elif [[ " $act " == " $exp " ]]; then
134+ status=MATCH
123135else status=WRONG-BINARY; fi
124136printf ' platform\t8080\t%s\t%s\t%s\t%s\n' " ${exp:- ?} " " ${act:- -} " " $hc " " $status "
125137
@@ -140,9 +152,12 @@ for kas in "${kas_names[@]}"; do
140152 exp=" $( expected_sha_for " $pin " ) "
141153 act=" $( actual_sha_for_port " $port " ) "
142154 hc=" $( [[ " $port " != " ?" ]] && health_of " $port " || echo -) "
143- if [[ -z " $pin " ]]; then status=NO-PIN
144- elif [[ -z " $act " ]]; then status=NOT-RUNNING
145- elif [[ " $act " == " $exp " ]]; then status=MATCH
155+ if [[ -z " $pin " ]]; then
156+ status=NO-PIN
157+ elif [[ -z " $act " ]]; then
158+ status=NOT-RUNNING
159+ elif [[ " $act " == " $exp " ]]; then
160+ status=MATCH
146161 else status=WRONG-BINARY; fi
147162 printf ' %s\t%s\t%s\t%s\t%s\t%s\n' " $kas " " $port " " ${exp:- ?} " " ${act:- -} " " $hc " " $status "
148163done
0 commit comments