Skip to content

Modular logistics and supply chain operating system (LSOS)

fix(api-contract): SIGPIPE aborted the run after one collection; restore colour

Ronald A. Richardson0e7fc604d581
diff --git a/.github/actions/postman-contract/action.yml b/.github/actions/postman-contract/action.yml
index 791bbf6a..14596c50 100644
--- a/.github/actions/postman-contract/action.yml
+++ b/.github/actions/postman-contract/action.yml
@@ -111,12 +111,13 @@ runs:
ran=0
mkdir -p postman-results
- # The Postman CLI has no --color flag and, like any chalk-based CLI, drops colour
- # when stdout is not a terminal — which it never is here, both because Actions has
- # no TTY and because we pipe into tee. Running it under a PTY (`script`) restores
- # it. TERM matters as much as the PTY: measured locally, a PTY with TERM unset
- # still produced plain text, while a PTY with TERM=xterm-256color produced fully
- # coloured output. Actions renders ANSI in the job log.
+ # The Postman CLI has no --color flag and drops colour when stdout is not a
+ # terminal — which it never is here, both because Actions has no TTY and because
+ # we pipe into tee. Three conditions are each necessary; measured against the
+ # real CLI, any one of them missing gives zero escape codes:
+ # PTY (via `script`) + TERM set to a real terminal + CI unset.
+ # Actions sets CI=true, which is why the first run had carriage returns (proof
+ # the PTY worked) but no colour at all. Actions renders ANSI in the job log.
#
# The command lives in a file rather than inline in `script -c` so the API key is
# inherited from the environment instead of being embedded in a shell string.
@@ -172,9 +173,10 @@ runs:
# Storefront declare api_prefix there, so without this every one of their
# requests would go to /%7B%7Bapi_prefix%7D%7D/... and 404. Read it from the
# collection rather than hardcoding, so a new prefixed collection just works.
- # \042 and \047 are " and ' — octal escapes dodge a nest of shell quoting.
- prefix="$(sed -n 's/^[[:space:]]*api_prefix:[[:space:]]*//p' \
- "$dir/.resources/definition.yaml" 2>/dev/null | head -1 | tr -d '\042\047')"
+ # One awk, no pipeline — same SIGPIPE reasoning as row() above.
+ prefix="$(awk -F: '/^[[:space:]]*api_prefix:/ {
+ sub(/^[^:]*:[[:space:]]*/, "", $0); gsub(/["'"'"']|[[:space:]]*$/, "", $0)
+ print; exit }' "$dir/.resources/definition.yaml" 2>/dev/null)"
if [[ -n "$prefix" ]]; then
args+=(--env-var "api_prefix=$prefix")
echo " api_prefix=$prefix"
@@ -193,7 +195,12 @@ runs:
# </dev/null is load-bearing: this loop is fed by `read` from a pipe, and a PTY
# child inherits and drains that stdin. Without it only the first collection
# ever runs — verified: 3 items in, 1 iteration out.
- if TERM=xterm-256color script -qec \
+ # env -u CI: the Postman CLI suppresses colour whenever CI is set, even with a
+ # PTY and a real TERM — which is why the last run had carriage returns (proof
+ # of the PTY) but no escape codes. Measured against the real CLI: PTY with
+ # TERM=xterm-256color and CI unset gives colour; setting CI=true, unsetting
+ # TERM, or TERM=dumb each independently drop it to none.
+ if env -u CI TERM=xterm-256color script -qec \
"$(printf '%q ' "$RUNNER" "${args[@]}")" \
/dev/null </dev/null 2>&1 | tee "$ansi"; then
status="✅ passed"
@@ -210,8 +217,15 @@ runs:
# "| <label> | <executed> | <failed> |", so match the label plus two numbers
# rather than the border, which differs between reporter versions. Verified
# against a real collection run: requests 8/8, assertions 0/0.
- row() { grep -aiE "(^|[^a-z])$1([^a-z]|$)" "$log" | grep -aE '[0-9]+[^0-9]+[0-9]+' \
- | head -1 | grep -oE '[0-9]+' | head -2 | paste -sd' ' - ; }
+ # Single awk, no `head` in a pipeline. GitHub runs composite steps under
+ # `bash -e -o pipefail`, so a `head` that closes the pipe early kills its
+ # producer with SIGPIPE, the pipeline reports 141 and -e aborts the whole
+ # step. That is what limited the last run to one of four collections.
+ row() { awk -v lbl="$1" '
+ tolower($0) ~ "(^|[^a-z])" lbl "([^a-z]|$)" {
+ n=0; for (i=1;i<=NF;i++) if ($i ~ /^[0-9]+$/) v[++n]=$i
+ if (n>=2) { print v[1], v[2]; exit }
+ }' "$log"; }
read -r r_exec r_fail <<<"$(row requests)"
read -r a_exec a_fail <<<"$(row assertions)"
echo "| $name | $status | ${r_exec:-–} | ${r_fail:-–} | ${a_exec:-–} | ${a_fail:-–} |" \
@@ -234,7 +248,7 @@ runs:
{
printf '\n<details><summary>Failures — %s</summary>\n\n' "$name"
printf '```\n'
- awk '/^[[:space:]]*#[[:space:]]+failure/{f=1} f' "$log" | head -80
+ awk '/^[[:space:]]*#[[:space:]]+failure/{f=1} f { if (++n<=80) print }' "$log"
printf '```\n</details>\n'
} >> postman-results/details.md
fi