Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Sections dated before 2026-09-19 predate the cycle and stay as they are. Named m
`docs/RELEASE-PROCESS.md` §8.

## Unreleased
- fix(marketplace-check, portability): **`bin/exec.sh` on a domain-model script no longer stops at the marketplace check on macOS `/bin/bash` 3.2 (#763)**: `_mkt_locate` ran `case "$m" in *"refusing to guess"*) ...` inside `$( ... )`, and bash 3.2 read the pattern's `)` as the end of the substitution (the #552 class, `bash -n` blind to it). The pattern now uses the POSIX leading paren `(pat)`; a sweep of `bin/`, `bin/lib/`, `project-bin/` and `claude-hooks/` found no other. New `bin/check-portability.sh` rule 3 (`bin/lib/case-in-subst.awk`, multi-line) flags a case pattern without a leading `(` inside `$( )`, so a third one cannot land; fixture `tests/wave2/test-case-in-subst.sh` — thanarat
- fix(intake,interview-protocol): **the intake preamble and `interview-protocol.md` now state the Stage P answer form for `Interview mode: auto`, `Assumed (auto-mode): <default> — rejected: <alt>`, colon right after the parenthesis (#766)**: the preamble listed only `Answered (CONFIRMED):` and `Unverified — how to verify:`, and the protocol said "recorded `ASSUMED` as above", pointing at the register shape the intake gate rejects, so an auto-mode kickoff learned the accepted form only from the FAIL message. Text only: the gate matcher and Q9 are unchanged, and existing intakes are not re-synced. Proof: `tests/wave2/test-stage-p.sh` T12 (fails on master's template) — field report from a greenfield auto-mode build, relayed by the maintainer
- process(poc-build): **POC test cadence cut to what finds bugs (#770)**: per page one LOOK at 1280 and one polish round (390 on the first page only); once at the end one journey with the happy path, one negative step per business rule and per must-have and one cross-user refusal per role, ending in a logout, run 2× (warm, then cold after one restart on the used DB) instead of 3 cold runs, then the broken control without a restart and one LOOK pass at 1280 + 390 over every page. "Done when" updated; status stays EXPERIMENTAL and says the new cadence is unmeasured. The open-session-count assertion after each run is a follow-up. — POC light-mode experiment (#729/#730), 2026-11
- learn(security): **MxAdmin no longer "ships with password `1`" in the rules (#662)**: `learned-mdl-preflight.md` (baseline), `brd-to-build-plan.md` Step 7 and the rendered `generated/rules-access.md` now say MxAdmin exists only where the runtime host created it (Studio Pro's own run, or the buildpack's `ADMIN_PASSWORD`); `mxcli run --local` never creates it (`MxAdmin user ... does not exist!`) and `mxcli docker build` seeds `admin` / `Admin123!` instead, so sign in as a demo user. The "never touch MxAdmin" rule stays — field run, 2026-11
Expand Down
15 changes: 15 additions & 0 deletions bin/check-portability.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ while IFS= read -r f; do
'Brace the name: ${NAME}. A single-byte locale (and bash 3.2) reads the first byte as part of the name; set -u then aborts.'
done <<EOF
$(code_lines "$f" | LC_ALL=C grep -E '^[0-9]+:.*\$[A-Za-z_][A-Za-z0-9_]*[^[:print:][:cntrl:]]')
EOF

# 3. A case pattern with no leading "(" inside a $( ... ) command substitution. bash 3.2
# (macOS /bin/bash) reads the pattern's unmatched ")" as the end of the substitution, and
# bash -n cannot see it because 3.2 parses the substitution only when it runs (#552
# script-owners.sh, #763 marketplace-check.sh: every exec of a domain-model script stopped).
# Multi-line, so it is a whole-file scan (bin/lib/case-in-subst.awk), not a per-line match.
# No file is exempt. Fix: the POSIX form, case "$x" in (pat) ... ;; esac.
while IFS= read -r ln; do
[ -n "$ln" ] || continue
case "$(sed -n "${ln}p" "$f")" in (*portability-ok:*) continue ;; esac
report "$f" "$ln" "case pattern without a leading ( inside \$(...) — breaks the substitution on bash 3.2" \
'Write the pattern in the POSIX form with a leading paren: case "$x" in (pat) ... ;; esac.'
done <<EOF
$(awk -f "$ROOT/bin/lib/case-in-subst.awk" "$f")
EOF

is_meta "$f" && continue
Expand Down
3 changes: 2 additions & 1 deletion bin/check-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ PROJECT_DIR="${1:-}"
# macOS ships bash 3.2 as /bin/bash and its $(...) scanner rejects things bash 5 accepts. When
# the bash on PATH is a different one, parse with /bin/bash too — script-owners.sh shipped
# unparseable on a Mac this way. `bash -n` there catches an apostrophe in a comment inside
# $(...); it does not catch a case pattern without a leading "(" (that fails only when run).
# $(...); it does not catch a case pattern without a leading "(" (that fails only when run;
# bin/check-portability.sh rule 3 flags it statically).
SYS_BASH=""
if [ -x /bin/bash ] && [ "$(/bin/bash -c 'printf %s "$BASH_VERSION"' 2>/dev/null)" != "$BASH_VERSION" ]; then
SYS_BASH=/bin/bash
Expand Down
98 changes: 98 additions & 0 deletions bin/lib/case-in-subst.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# case-in-subst.awk — used by bin/check-portability.sh (rule: case pattern inside $(...)).
#
# Prints the line number of every `case` pattern written WITHOUT the POSIX leading `(` while
# that case sits inside a $( ... ) command substitution. bash 3.2 (macOS /bin/bash) reads the
# pattern's unmatched `)` as the end of the substitution; `bash -n` does not see it because 3.2
# parses the substitution only when it runs (#552 script-owners.sh, #763 marketplace-check.sh).
#
# A small shell scanner, not a parser: it tracks a stack of contexts — $( ) "S", ( ) "P",
# "..." "D", ${ } "B", $(( )) / (( )) "A", case "C" (subject -> pattern -> body) — skips
# '...' (also across lines), comments and heredoc bodies, and reports a pattern-closing `)`
# when no leading `(` opened the pattern and an "S" is anywhere below the case on the stack.
# Known blind spots (false negatives, never false positives on the tree it shipped against):
# backtick substitutions and <( ) process substitutions are not tracked as "S"; ${...} bodies
# are opaque, so a $( ) inside one is not seen.
{
line = $0
if (hd != "") { # inside a heredoc body: skip to its terminator
t = line; if (hdstrip) sub(/^\t+/, "", t)
if (t == hd) hd = ""
next
}
n = length(line); i = 1; pend = ""; pendstrip = 0
if (sq) { j = index(line, "'"); if (j == 0) next; i = j + 1; sq = 0 } # multi-line '...'
while (i <= n) {
c = substr(line, i, 1); c2 = substr(line, i, 2); c3 = substr(line, i, 3)
top = (sp > 0) ? st[sp] : ""
prev = (i > 1) ? substr(line, i - 1, 1) : " "
if (top == "B") { # ${ ... }: nesting only, everything else is opaque
if (c2 == "${") { st[++sp] = "B"; i += 2; continue }
if (c == "}") { sp--; i++; continue }
if (c == "\\") { i += 2; continue }
i++; continue
}
if (c == "\\") { i += 2; continue }
if (top == "D") { # inside "...": only $( ${ $(( and the closing quote count
if (c == "\"") { sp--; i++; continue }
if (c3 == "$((") { st[++sp] = "A"; i += 3; continue }
if (c2 == "$(") { st[++sp] = "S"; i += 2; continue }
if (c2 == "${") { st[++sp] = "B"; i += 2; continue }
i++; continue
}
if (top == "A") { # arithmetic: parens nest, no heredocs, no words
if (c2 == "))") { sp--; i += 2; continue }
if (c == "(") { st[++sp] = "a"; i++; continue }
i++; continue
}
if (top == "a") {
if (c == "(") { st[++sp] = "a"; i++; continue }
if (c == ")") { sp--; i++; continue }
i++; continue
}
# ---- code context (top is "", S, P, or C) ----
if (c == "'") { j = index(substr(line, i + 1), "'"); if (j == 0) { i = n + 1; sq = 1; break } i += j + 1; continue }
if (c == "#" && (prev ~ /[ \t;|&(]/ || i == 1)) break
if (c == "\"") { st[++sp] = "D"; i++; continue }
if (c3 == "$((") { st[++sp] = "A"; i += 3; continue }
if (c2 == "((" && (prev ~ /[ \t;|&(]/ || i == 1)) { st[++sp] = "A"; i += 2; continue }
if (c2 == "$(") { st[++sp] = "S"; i += 2; continue }
if (c2 == "${") { st[++sp] = "B"; i += 2; continue }
if (c3 == "<<<") { i += 3; continue }
if (c2 == "<<") {
rest = substr(line, i + 2); strip = 0
if (substr(rest, 1, 1) == "-") { strip = 1; rest = substr(rest, 2) }
sub(/^[ \t]*/, "", rest); gsub(/["'\\]/, "", rest)
if (match(rest, /^[A-Za-z_][A-Za-z0-9_]*/)) { pend = substr(rest, 1, RLENGTH); pendstrip = strip }
i += 2; continue
}
# words: case / in / esac
if (c ~ /[a-z]/ && (i == 1 || prev ~ /[ \t;|&()]/)) {
w = substr(line, i); match(w, /^[A-Za-z0-9_]+/); w = substr(w, 1, RLENGTH)
after = substr(line, i + length(w), 1)
isword = (after == "" || after ~ /[ \t;|&()]/)
if (isword && top == "C" && cs[sp] == "pat" && !started[sp] && w == "esac") { sp--; i += 4; continue }
if (isword && top == "C" && cs[sp] == "body" && w == "esac") { sp--; i += 4; continue }
if (isword && top == "C" && cs[sp] == "subj" && w == "in") { cs[sp] = "pat"; started[sp] = 0; lead[sp] = 0; i += 2; continue }
if (isword && w == "case" && !(top == "C" && cs[sp] == "pat")) { st[++sp] = "C"; cs[sp] = "subj"; i += 4; continue }
if (top == "C" && cs[sp] == "pat") started[sp] = 1
i += length(w); continue
}
if (top == "C" && cs[sp] == "pat") {
if (c ~ /[ \t]/) { i++; continue }
if (c == "(" && !started[sp]) { started[sp] = 1; lead[sp] = 1; i++; continue }
if (c == ")") {
if (!lead[sp]) { for (k = sp - 1; k > 0; k--) if (st[k] == "S") { print NR; break } }
cs[sp] = "body"; i++; continue
}
started[sp] = 1
}
if (top == "C" && cs[sp] == "body" && (c2 == ";;" || c2 == ";&")) {
cs[sp] = "pat"; started[sp] = 0; lead[sp] = 0
i += (substr(line, i, 3) == ";;&") ? 3 : 2; continue
}
if (c == "(") { st[++sp] = "P"; i++; continue }
if (c == ")") { if (top == "S" || top == "P") sp--; i++; continue }
i++
}
if (pend != "") { hd = pend; hdstrip = pendstrip }
}
2 changes: 1 addition & 1 deletion bin/lib/marketplace-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ _mkt_locate() {
[ -f "$_MKT_COMMON" ] || return 0
out="$( export PROJECT_ROOT="$root"; . "$_MKT_COMMON" >/dev/null 2>&1 || exit 0
m="$(find_mpr 2>&1)" && printf 'mpr\t%s\n' "$m" || {
case "$m" in *"refusing to guess"*) printf 'mpr\tAMBIGUOUS\n' ;; esac; }
case "$m" in (*"refusing to guess"*) printf 'mpr\tAMBIGUOUS\n' ;; esac; }
x="$(find_project_mxcli 2>/dev/null)" && printf 'mx\t%s\n' "$x"
exit 0 )"
local IFS=$'\n' l
Expand Down
88 changes: 88 additions & 0 deletions tests/wave2/test-case-in-subst.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash
# test-case-in-subst.sh — a case pattern without a leading "(" inside $( ... ) is flagged (#763).
#
# Usage: bash tests/wave2/test-case-in-subst.sh bin/check-portability.sh
#
# bash 3.2 (macOS /bin/bash) reads the unmatched ")" of a case pattern as the end of an enclosing
# $( ... ) command substitution. bash -n does not see it (3.2 parses the substitution only when it
# runs), and this runner has no bash 3.2, so the proof is static: the portability check must
# flag the shape. #552 (script-owners.sh) and #763 (marketplace-check.sh _mkt_locate) shipped it.
#
# T1 the reporter's minimal repro from #763, verbatim: flagged, rc 1, at the pattern's line
# T2 one-line, multi-line (one bare pattern after a parenthesised one), and nested
# $( ... $(case ...) ... ): 3 of 3 flagged, at the right lines
# T3 not flagged: the (pat) form inside $( ), a case outside any $( ) (even with $( ) in its
# subject and body), a commented-out line, a '...' string, a heredoc body, $(( << )),
# and a `# portability-ok:` line
# T4 the shipped bin/lib/marketplace-check.sh (same toolkit as the SUT): 0 hits (passes
# trivially on a check-portability.sh without the rule; T1/T2 are the ones that bite)
#
# GOLDEN INPUT: T1 is copied from the issue as reported on macOS /bin/bash 3.2.57, and T4 is the
# real file the issue was filed against.
set -uo pipefail
SUT="${1:?usage: test-case-in-subst.sh /path/to/bin/check-portability.sh}"
case "$SUT" in /*) ;; *) SUT="$PWD/$SUT" ;; esac
SRC="$(cd "$(dirname "$SUT")/.." && pwd)"
W="$(mktemp -d "${TMPDIR:-/tmp}/caseinsubst.XXXXXX")" || exit 2
trap 'rm -rf "$W"' EXIT
PASS=0; FAIL=0
ok() { PASS=$((PASS+1)); printf ' ok %s\n' "$1"; }
bad() { FAIL=$((FAIL+1)); printf ' FAIL %s\n' "$1"; [ -n "${2:-}" ] && printf '%s\n' "$2" | sed 's/^/ FAIL-detail: /'; }
RULE='case pattern without a leading ( inside'
hits() { printf '%s\n' "$1" | grep -F "$RULE" | sed 's/^[^:]*:\([0-9]*\):.*/\1/' | tr '\n' ' '; }

echo "== check-portability.sh: case pattern inside \$(...) (#763) =="
mkdir -p "$W/t1" "$W/t2" "$W/t3" "$W/t4"

cat > "$W/t1/repro.sh" <<'X'
#!/usr/bin/env bash
f() { out="$( m="x refusing to guess"; false || {
case "$m" in *"refusing to guess"*) printf 'A\n' ;; esac; }
exit 0 )"; echo "OUT=[$out]"; }
f
X
out="$(bash "$SUT" "$W/t1" 2>&1)"; rc=$?
if [ "$rc" -eq 1 ] && [ "$(hits "$out")" = "3 " ]; then ok "T1 reporter's repro flagged at line 3"
else bad "T1 want rc 1, hit at line 3; got rc $rc, lines [$(hits "$out")]" "$out"; fi

cat > "$W/t2/shapes.sh" <<'X'
#!/usr/bin/env bash
y="$(case "$a" in b) echo 1 ;; esac)"
z="$(
case "$a" in
(a) echo a ;;
b|c) echo b ;;
esac
)"
w="$(echo "$(case $q in x) :;; esac)")"
X
out="$(bash "$SUT" "$W/t2" 2>&1)"; rc=$?
if [ "$rc" -eq 1 ] && [ "$(hits "$out")" = "2 6 9 " ]; then ok "T2 one-line, multi-line and nested: 3 of 3 flagged (lines 2 6 9)"
else bad "T2 want rc 1, lines [2 6 9 ]; got rc $rc, lines [$(hits "$out")]" "$out"; fi

cat > "$W/t3/good.sh" <<'X'
#!/usr/bin/env bash
out="$( case "$m" in (*"refusing to guess"*) printf 'A\n' ;; esac; exit 0 )"
case "$(basename "$1")" in a) x="$(echo a)" ;; *) : ;; esac
case "$x" in
a) y="$(case "$x" in (a) echo ;; esac)" ;;
esac
# out="$( case x in a) ;; esac )"
s='$( case x in a) ;; esac )'
cat <<'EOF'
v="$( case x in a) ;; esac )"
EOF
n=$(( (a + 1) << 2 ))
u="$(case "$x" in a) echo ;; esac)" # portability-ok: fixture opt-out
X
out="$(bash "$SUT" "$W/t3" 2>&1)"; rc=$?
if [ "$rc" -eq 0 ]; then ok "T3 (pat) form, case outside \$( ), comment, '...', heredoc, \$(( << )), portability-ok: 0 hits"
else bad "T3 want rc 0, got $rc, lines [$(hits "$out")]" "$out"; fi

cp "$SRC/bin/lib/marketplace-check.sh" "$W/t4/"
out="$(bash "$SUT" "$W/t4" 2>&1)"
if [ -z "$(hits "$out")" ]; then ok "T4 shipped marketplace-check.sh: 0 hits"
else bad "T4 shipped marketplace-check.sh still has a bare pattern in \$( ) at [$(hits "$out")]" "$out"; fi

echo "-- $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]
Loading