Skip to content

fix(marketplace-check): leading-paren case pattern inside $( ) for bash 3.2; portability rule (#763) - #774

Open
MendixMau wants to merge 1 commit into
masterfrom
triage/763-case-in-subst
Open

MendixMau wants to merge 1 commit into
masterfrom
triage/763-case-in-subst

Conversation

@MendixMau

Copy link
Copy Markdown
Owner

Fixes #763

Direct lane

What changed and why (one paragraph): _mkt_locate in bin/lib/marketplace-check.sh:115 ran case "$m" in *"refusing to guess"*) ... esac inside a $( ... ) command substitution. macOS /bin/bash 3.2 reads the pattern's unmatched ) as the end of the substitution. Per the report, every bin/exec.sh run on a domain-model script stopped at the marketplace check. bash -n cannot catch this, because 3.2 parses the substitution only when it runs. It is the same class of bug as #552. The pattern now uses the POSIX leading paren: (*"refusing to guess"*).

To stop a third one from landing, bin/check-portability.sh gets rule 3. The rule runs bin/lib/case-in-subst.awk, a whole-file, multi-line scan:

  • It keeps a stack of contexts: $( ), ( ), "...", ${ }, $(( ))/(( )) and case (subject, then pattern, then body).
  • It skips '...' strings (also across lines), comments and heredoc bodies.
  • It flags a pattern-closing ) that has no leading ( while a $( ) sits anywhere below the case.
  • No file is exempt, and the usual # portability-ok: opt-out works per line.

A one-line pointer to the new rule was added to bin/check-scripts.sh's header, which already named this gap.

Sweep: I ran the scanner over bin/, bin/lib/, project-bin/, claude-hooks/ and tests/. It found one occurrence, bin/lib/marketplace-check.sh:115, the one reported. There were no others to fix. As a sanity check on the scanner, all 390 files on master end with an empty context stack: no unclosed quote, heredoc or substitution, so the state did not drift.

Proof, and its limit: bash 3.2 is not available on this runner, so I did not reproduce the runtime failure here. The proof is static: the portability-check fixture. The reporter verified the (pat) fix on bash 3.2 and bash 5.

master check-portability.sh branch
tests/wave2/test-case-in-subst.sh 2 passed, 2 failed (T1 reporter's repro and T2 shapes not flagged) 4 passed, 0 failed
bin/check-portability.sh over the toolkit tree master's own check: clean. Branch rule run over the master tree: 1 violation, bin/lib/marketplace-check.sh:115 clean, 391 files, rc 0

Fixture cases:

  • T1: the reporter's minimal repro, verbatim. Flagged at line 3.
  • T2: a one-line case, a multi-line case (a bare pattern after a (pat) one), and a nested $( … $(case …) … ). All 3 flagged at the right lines.
  • T3: shapes that must not be flagged: (pat) inside $( ), a case outside any $( ) with $( ) in its subject and body, a commented line, a '...' string, a quoted heredoc body, $(( … << … )) and a # portability-ok: line. 0 hits.
  • T4: the shipped marketplace-check.sh gives 0 hits. This passes trivially on master, because master has no such rule.

Known false negatives, documented in the awk header: backtick substitutions and <( ) are not tracked as substitutions, and ${…} bodies are opaque.

Impact

Row Answer
Process No human step or gate added. check-portability.sh (CI step and tests/run-tests.sh) can now fail on a new violation class. It reports 0 on the current tree.
Dependencies Touches bin/check-portability.sh, bin/check-scripts.sh (comment only) and bin/lib/marketplace-check.sh (one pattern). New bin/lib/case-in-subst.awk uses POSIX awk only: match/RLENGTH, substr, index, sub/gsub. It was written for gawk, mawk and BSD awk alike, but I exercised it only on this runner's awk. check-portability.sh is not installed into projects, so no sync impact. No new artifact reads.
Context cost none: no routed or always-loaded file touched
Behaviour NOT RUN: scripts only, no agent-read skill text changed. Maintainer to accept or request A/B.
Runtime The new rule adds about 2.2 s over the whole tree (390 files, one awk pass each), measured on this Linux runner. The full check-portability.sh run takes several minutes here anyway. marketplace-check.sh: unchanged wall-clock, and the hard failure on bash 3.2 is gone.

Time cost: per check-portability run · ~2.2 s measured on Linux CI-class runner · can force rework: y (a new bare pattern in $( ) fails CI) · offset: removes a hard stop on every domain-model exec on stock macOS bash

Field evidence: reported by thanarat on macOS /bin/bash 3.2.57, mxcli v0.31.0, toolkit v2026.11.16: every bin/exec.sh on a domain-model script stopped at the check. The reporter verified the (pat) fix there on bash 3.2 and bash 5. The new rule ran against this toolkit's real tree: 1 hit on master, 0 on the branch.

  • No client data anywhere in the diff (leak guard: clean)
  • Size cap: 6 files, ~117 non-fixture lines changed
  • Test tier: static check (portability fixture) plus bin/check-scripts.sh (137/137 parse). No bash 3.2 runtime run on this runner.
  • Golden input: T1 is the reporter's repro from the issue, verbatim, and T4 is the real shipped file. Layouts: n/a (no path resolution). Platforms: awk kept POSIX, nothing platform-specific.
  • CHANGELOG.md line under ## Unreleased, credited to thanarat

Not run: tests/wave2/test-marketplace-install.sh and test-fitgap-review.sh, which load marketplace-check.sh, plus the other fixtures that call check-portability.sh (test-sed-tab-bracket.sh, test-status-bare-var.sh, test-pipefail-grep-q.sh). This session's permission check refused the run. The reviewer may run them in a detached worktree.

Review: pending independent review


Generated by Claude Code

…sh 3.2; portability rule (#763)

_mkt_locate ran `case "$m" in *"refusing to guess"*)` inside a command
substitution; macOS /bin/bash 3.2 reads the pattern's `)` as the end of the
$( ), so every exec of a domain-model script stopped at the marketplace check.
Use the POSIX `(pat)` form. Sweep of bin/, bin/lib/, project-bin/ and
claude-hooks/ found no other occurrence.

check-portability.sh rule 3 (bin/lib/case-in-subst.awk, multi-line scan)
flags a case pattern without a leading `(` inside $( ). Master tree: 1 hit
(marketplace-check.sh:115); branch: clean over 391 files.
Fixture tests/wave2/test-case-in-subst.sh: master 2/4, branch 4/4.

Reported by thanarat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC
@MendixMau

Copy link
Copy Markdown
Owner Author

Review: MERGE. The one-character fix at bin/lib/marketplace-check.sh:115 is the reporter's verified fix. The new rule 3 finds exactly that line on master and nothing else in a 420-file tree.

Value: Fixes #763 as reported.

Regression risk:

  • check-portability.sh is not installed into projects (no install-manifest or sync reference). It scans only *.sh under the toolkit's own targets, so sync-project.sh changes nothing for an existing project.
  • The new exit-1 class can only turn CI red on a new violation. Run directly over 420 tracked scripts, the awk reports 0 hits. On master's marketplace-check.sh it prints 115.
  • Run only with mawk 1.3.4, which is this runner's awk and also what nawk points to. BSD one-true-awk (macOS pre-commit use) was not exercised. The constructs used (match/RLENGTH, substr, index, arrays) are POSIX.

Correctness: All fixtures were run in the detached worktree.

  • test-case-in-subst.sh: 4/0 on head. Positive control with master's check-portability.sh: 2/2, with T1 and T2 failing as claimed. T4 passes trivially on master, as the PR says.
  • test-marketplace-install.sh: 57/0
  • test-fitgap-review.sh: 23/0
  • test-sed-tab-bracket.sh: 11/0
  • test-status-bare-var.sh: 3/0 (T1-T2 SKIP, no ISO-8859-1 locale)
  • test-pipefail-grep-q.sh: 3/0

Extra edge cases run against the awk all behaved correctly, with only the two real bare patterns flagged:

  • a case in a trailing comment;
  • a case in a heredoc inside $( );
  • a case in a "..." string with an escaped quote;
  • [[ =~ ^(a|b)$ ]] inside $( );
  • in on the next line;
  • a '"'"' splice.

The documented blind spots (backticks, <( ), ${ } bodies) can only cause false negatives. T1 is the issue's verbatim repro, which is acceptable golden input for a static check. There is no bash 3.2 runtime proof here; the reporter's verification covers that. No conflict with origin/master.

Context cost: 66196 → 66196 always-loaded words (measured). No routed file touched.

Time cost: per check-portability.sh run, one extra awk pass per file (about 2 s over the tree by the builder's figure; this reviewer's run over 420 files was similar). Nothing per build row. It removes a hard stop on every domain-model exec on stock macOS bash.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

marketplace-check.sh: case pattern inside $( ) is a syntax error on macOS bash 3.2, so exec aborts silently

2 participants