From 65ec2db167edcb120fb1c006582d55bb0dd42a91 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 18:43:06 +0000 Subject: [PATCH 01/10] fix(exec): keep the cause line of a v0.32 two-line reference error in the refusal row mxcli v0.32 prints "statement N: microflow 'X' has reference errors:" and the cause on the next line as " - entity not found: ...". check_refusal_reason kept only the header, so the BUILD-LOG row lost the cause. Fixture F on a verbatim capture from mxcli v0.32.0-374. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC --- CHANGELOG.md | 1 + project-bin/exec.sh | 6 ++++- .../exec-check-refusal/reference-v0.32.0.mdl | 27 +++++++++++++++++++ .../exec-check-refusal/reference-v0.32.0.out | 27 +++++++++++++++++++ tests/wave2/test-exec-check-refusal.sh | 13 +++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.mdl create mode 100644 tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.out diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e148df..6b6e7d68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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(exec): **a refused pre-exec check keeps the cause of a v0.32 reference error in the BUILD-LOG row**: mxcli v0.32 prints a reference error as two lines under `Reference errors:` (`statement 3: microflow 'X' has reference errors:` then ` - entity not found: โ€ฆ`) and the ๐Ÿšซ row kept only the header, which names no cause. The cause line is now appended. Fixture `test-exec-check-refusal.sh` F, on a verbatim v0.32.0 capture โ€” real-mxcli field run (mxcli v0.32.0-374, blank Mendix 11.8.0 app) - new(doctor, bug ledger): **a guard for mxcli's silent MxBuild fallback**: when the project's Mendix version is not in `~/.mxcli/mxbuild/` (and no Studio Pro of that version exists), `mxcli docker build` / `docker check` fall back to the newest cached MxBuild and print its path but no version warning (`run --local` is exact-or-refuse); `bin/doctor.sh` now warns, naming the model version, the cached ones and `./mxcli setup mxbuild -p .mpr` (`mxtk_mxbuild_cache_gap`, warning only, never changes a gate). Ledger entry `BUG-DRAFT-mxbuild-silent-version-fallback`; upstream issue not filed. โ€” a four-app Mendix build (field run), independent review - fix(gate-check): **a fresh clone no longer FAILs Stage 3 as "stale render"**: `blueprint.html` / `process-map.html` freshness used `[ render -ot source ]`, a nanosecond mtime compare, and a checkout stamps files in directory order (`process-map.html` lands before `process-model.json`), so an unedited project read stale on every clone (reproduced: 200-wireframe checkout, 10 of 10 clones). New `bin/lib/render-fresh.sh` keeps `-ot` as the first test (a pass never flips, no git call) and, only where `-ot` would FAIL, asks git once per render (one `log`, one `status`) whether the source was committed after the render's commit; measured 0.19 s for 200 sources all `-ot`-stale on a 300-commit history (a per-source git version cost 12.9 s). Limit: a depth-1 clone cannot see a genuinely stale render. Field run: a four-app Mendix build checked out on a second machine. โ€” a four-app Mendix build (field run), independent review - fix(test-stack-up, e2e-harness-base): **the app port follows the app's configured port, and a multi-app start is no longer pinned to 8080**: with no `APP_PORTS`, `test-stack-up.sh` puts `RUN_LOCAL_APP_PORT`, then `APP_PORT` from the `.docker/.env` beside the `.mpr` (`apps//.docker/.env`; the project-root one as fallback) first, ahead of the old fixed `8080 8081 8084` tail. A fresh `run --local` start for a model under `apps/` with no handshake and no configured port used to fall back to 8080 for every app (`--app-port 8080`); it now exits 4 naming `RUN_LOCAL_APP_PORT`. `e2e-harness-base.md` states that a PAD/Docker runtime listens on 8080 *inside* the container only. Fixtures T28โ€“T32 added. Field run: a four-app Mendix build on 8081โ€“8084 whose fresh start failed with every app pinned to 8080. โ€” a four-app Mendix build (field run), independent review diff --git a/project-bin/exec.sh b/project-bin/exec.sh index c4a721a7..fd398316 100755 --- a/project-bin/exec.sh +++ b/project-bin/exec.sh @@ -1589,11 +1589,15 @@ step_done guards # Shapes are real mxcli v0.26.0 captures (tests/wave2/fixtures/exec-check-refusal/): an error # violation is "โœ— [RULE]" after any warnings, in ANSI colour even when piped; a parse # failure is "- line N:M ..." under "Syntax errors found:". Rule id first, so truncation keeps it. +# v0.32 reference errors take two lines under "Reference errors:", a header ending in ":" and the +# cause as " - ..." (fixtures/exec-check-refusal/reference-v0.32.0.out); both go in the row, +# because the header alone ("microflow 'X' has reference errors:") names no cause. check_refusal_reason() { # $1 = captured check output _esc="$(printf '\033')" tr -d '\r' < "$1" 2>/dev/null | sed "s/${_esc}\[[0-9;]*m//g" | awk ' /^(Syntax|Reference) errors( found)?:$/ { hdr = 1; next } - hdr && h == "" && NF { h = $0 } + hd == 1 { hd = 2; if ($0 ~ /^ *- /) { d = $0; sub(/^ *- */, "", d); h = h " " d } } + hdr && h == "" && NF { h = $0; if (h ~ /:$/) hd = 1 } e == "" && /^ *โœ— / && !/ found$/ { e = $0 } f == "" && /[Ee]rror/ && !/^WARNING: / { f = $0 } END { r = (e != "") ? e : ((h != "") ? h : f); print r }' \ diff --git a/tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.mdl b/tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.mdl new file mode 100644 index 00000000..69352334 --- /dev/null +++ b/tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.mdl @@ -0,0 +1,27 @@ +mdl 1; +create module Broken2; + +create persistent entity Broken2.Thing ( + Name: string(100) +); + +create microflow Broken2.ACT_Thing () +returns boolean as $ok +begin + $T = create Broken2.Thing (Nmae = 'x'); + $L = create Broken2.Missing (Name = 'y'); + declare $ok boolean = true; + return $ok; +end; + +create page Broken2.Thing_Edit +( + title: 'Edit', + layout: Atlas_Core.NoSuchLayout, + params: { $Thing: Broken2.Thing } +) +{ + dataview dv1 (datasource: $Thing) { + textbox tb1 (label: 'Name', attribute: Nmae) + } +}; diff --git a/tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.out b/tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.out new file mode 100644 index 00000000..6542297a --- /dev/null +++ b/tests/wave2/fixtures/exec-check-refusal/reference-v0.32.0.out @@ -0,0 +1,27 @@ +WARNING: This is a vibe-coded PoC, alpha quality, use with caution. +Checking syntax: mdl/02-broken.mdl +โœ“ Syntax OK (4 statements) +Connected to: ProbeApp.mpr (Mendix 11.8.0) + +(no module) +----------- + โš  page Broken2.Thing_Edit: DataView `dv1` contains input fields but is not inside a layout grid โ€” label and input widths only render correctly inside a layoutgrid [MPR010] + at  + โ†’ Wrap dataview `dv1` in `layoutgrid { row { column (desktopwidth: autofill) { โ€ฆ } } }` + + โš  line 21: `Params: { $P: M.E } / Variables: { $v: Boolean = 'true' }` is deprecated; write `Params: ( $P: M.E ) / Variables: ( $v: Boolean = 'true' )` โ€” same meaning. Refused from `mdl 2`. (mxcli help MDL-DEPR123) [MDL-DEPR123] + at  + โ†’ Rewrite the header map: the braces become ( ). In a page's and a snippet's header. A map is a property list, so it is in ( ); { } holds children (R2). + + +Validating references against: ProbeApp.mpr +(Note: References to objects created within the script are skipped) +Reference errors: + statement 3: microflow 'Broken2.ACT_Thing' has reference errors: + - entity not found: Broken2.Missing (referenced by create) + statement 4: page 'Broken2.Thing_Edit' has attribute binding errors: + - widget `tb1` (textbox) binds `Nmae`, but Broken2.Thing has no attribute Nmae (attributes: Name) โ€” mxbuild reports CE1613 "The selected attribute 'Broken2.Thing.Nmae' no longer exists" + +โœ— 2 reference error(s) found + +4 issues: 2 errors, 2 warnings, 0 info diff --git a/tests/wave2/test-exec-check-refusal.sh b/tests/wave2/test-exec-check-refusal.sh index e627c67b..6b8e4136 100644 --- a/tests/wave2/test-exec-check-refusal.sh +++ b/tests/wave2/test-exec-check-refusal.sh @@ -21,6 +21,12 @@ # C the screen still shows mxcli's own output, and mxcli check ran exactly once # D a plain one-line refusal (no rule bracket) is recorded too # E a reason in non-Latin text longer than 160 bytes is cut on a character boundary, not to "..." +# F a v0.32 two-line reference error keeps its cause, not only the header line +# +# reference-v0.32.0.out is `mxcli check reference-v0.32.0.mdl -p ProbeApp.mpr --references`, stdout +# and stderr as exec.sh captures them, from a real mxcli v0.32.0-374-g591bcd73e on a blank Mendix +# 11.8.0 app (2026-11-20). Under "Reference errors:" each error is a header ending in ":" and the +# cause on the next line as " - ...". Before the fix the row kept only the header. # # Synthetic project, stub mxcli replaying the capture. Nothing real runs. set -uo pipefail @@ -102,6 +108,13 @@ if printf '%s' "$_why" | iconv -f UTF-8 -t UTF-8 >/dev/null 2>&1 && [ "$(printf && [ "$(printf '%s' "$_why" | wc -c)" -ge 157 ]; then ok "E: cut is valid UTF-8, 157-160 bytes" else bad "E: cut is valid UTF-8, 157-160 bytes" "$(printf '%s' "$_why" | wc -c) bytes"; fi +# F +run "$GOLD/reference-v0.32.0.out" +case "$ROW" in *"check: statement 3: microflow 'Broken2.ACT_Thing' has reference errors: entity not found: Broken2.Missing (referenced by create)"*) + ok "F: v0.32 reference error keeps its cause line" ;; + *) bad "F: v0.32 reference error keeps its cause line" "$ROW" ;; esac +[ "$(cells "$ROW")" = 6 ] && ok "F: row still has 5 cells" || bad "F: row still has 5 cells" "$(cells "$ROW") bars: $ROW" + echo "" echo "== $PASS passed, $FAIL failed" [ "$FAIL" -eq 0 ] From 4e709e0abaabfe1e2578aa1e1dce45732a564276 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 18:44:39 +0000 Subject: [PATCH 02/10] fix(_common): use the mxbuild mxcli reports after a download when MXCLI_HOME points elsewhere mxcli always caches MxBuild under ~/.mxcli (os.UserHomeDir) and ignores MXCLI_HOME, which only the toolkit reads, so exec.sh's auto-download "succeeded" and was then not found. Take the "MxBuild ready: " line when re-discovery finds nothing, version-checked. Fixture on a verbatim `setup mxbuild` capture from mxcli v0.32.0-374. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC --- CHANGELOG.md | 1 + project-bin/_common.sh | 26 +++++- .../setup-mxbuild-cached-v0.32.0.out | 5 + tests/wave2/test-mxbuild-setup-home.sh | 92 +++++++++++++++++++ 4 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 tests/wave2/fixtures/mxbuild-setup/setup-mxbuild-cached-v0.32.0.out create mode 100755 tests/wave2/test-mxbuild-setup-home.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b6e7d68..efe60ba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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(exec, _common): **the mxbuild auto-download works when `MXCLI_HOME` points elsewhere**: the toolkit looks for the cache at `${MXCLI_HOME:-~/.mxcli}`, but mxcli itself always caches under `~/.mxcli` (`os.UserHomeDir`), so `exec.sh` downloaded, printed `MxBuild ready: โ€ฆ`, then reported "no runnable mxbuild was found afterwards" and refused the exec. `mxtk_ensure_mxbuild` now takes the path mxcli reports when re-discovery finds nothing (same version only) and says that `MXCLI_HOME` is not mxcli's. Fixture `test-mxbuild-setup-home.sh` on a verbatim `setup mxbuild` capture โ€” real-mxcli field run (mxcli v0.32.0-374, blank Mendix 11.8.0 app) - fix(exec): **a refused pre-exec check keeps the cause of a v0.32 reference error in the BUILD-LOG row**: mxcli v0.32 prints a reference error as two lines under `Reference errors:` (`statement 3: microflow 'X' has reference errors:` then ` - entity not found: โ€ฆ`) and the ๐Ÿšซ row kept only the header, which names no cause. The cause line is now appended. Fixture `test-exec-check-refusal.sh` F, on a verbatim v0.32.0 capture โ€” real-mxcli field run (mxcli v0.32.0-374, blank Mendix 11.8.0 app) - new(doctor, bug ledger): **a guard for mxcli's silent MxBuild fallback**: when the project's Mendix version is not in `~/.mxcli/mxbuild/` (and no Studio Pro of that version exists), `mxcli docker build` / `docker check` fall back to the newest cached MxBuild and print its path but no version warning (`run --local` is exact-or-refuse); `bin/doctor.sh` now warns, naming the model version, the cached ones and `./mxcli setup mxbuild -p .mpr` (`mxtk_mxbuild_cache_gap`, warning only, never changes a gate). Ledger entry `BUG-DRAFT-mxbuild-silent-version-fallback`; upstream issue not filed. โ€” a four-app Mendix build (field run), independent review - fix(gate-check): **a fresh clone no longer FAILs Stage 3 as "stale render"**: `blueprint.html` / `process-map.html` freshness used `[ render -ot source ]`, a nanosecond mtime compare, and a checkout stamps files in directory order (`process-map.html` lands before `process-model.json`), so an unedited project read stale on every clone (reproduced: 200-wireframe checkout, 10 of 10 clones). New `bin/lib/render-fresh.sh` keeps `-ot` as the first test (a pass never flips, no git call) and, only where `-ot` would FAIL, asks git once per render (one `log`, one `status`) whether the source was committed after the render's commit; measured 0.19 s for 200 sources all `-ot`-stale on a 300-commit history (a per-source git version cost 12.9 s). Limit: a depth-1 clone cannot see a genuinely stale render. Field run: a four-app Mendix build checked out on a second machine. โ€” a four-app Mendix build (field run), independent review diff --git a/project-bin/_common.sh b/project-bin/_common.sh index 8fa01072..b3db6f08 100755 --- a/project-bin/_common.sh +++ b/project-bin/_common.sh @@ -1771,15 +1771,31 @@ mxtk_ensure_mxbuild() { fi echo "โ†’ mxbuild not found โ€” downloading the toolchain for this model's Mendix version" >&2 echo " ($mxcli setup mxbuild โ€” the same download bin/doctor.sh --install runs; cached under ~/.mxcli/mxbuild/)" >&2 - if (cd "$root" && "$mxcli" setup mxbuild -p "$(basename "$mpr")" >&2); then + # mxcli always caches under its own home (~/.mxcli, os.UserHomeDir) and ignores MXCLI_HOME, which only + # the toolkit reads. So the path mxcli prints last ("MxBuild ready: ", mxcli v0.32 setup.go; capture + # in tests/wave2/fixtures/mxbuild-setup/) is taken as the answer when re-discovery under MXCLI_HOME finds + # nothing: before, a "successful" download was followed by "no runnable mxbuild found" and a refused exec. + local _sout _src _ready _vdir + _sout="$(mktemp "${TMPDIR:-/tmp}/mxbuild-setup.XXXXXX")" + (cd "$root" && "$mxcli" setup mxbuild -p "$(basename "$mpr")") 2>&1 | tee "$_sout" >&2; _src=${PIPESTATUS[0]} + _ready="$(tr -d '\r' < "$_sout" | sed -n 's/^MxBuild ready: //p' | tail -1)"; rm -f "$_sout" + if [ "$_src" -eq 0 ]; then found="$(find_mxbuild 2>/dev/null || true)" - if [ -n "$found" ] && [ -x "$found" ]; then - if [ -n "$ver" ] && ! mxtk_mxbuild_for_version "$ver" >/dev/null 2>&1; then - echo " โš  download finished but there is still no mxbuild for $ver โ€” using $found; the gate will report the refusal as unverified." >&2 + if [ -n "$found" ] && [ -x "$found" ] && { [ -z "$ver" ] || mxtk_mxbuild_for_version "$ver" >/dev/null 2>&1; }; then + printf '%s\n' "$found"; return 0 + fi + if [ -n "$_ready" ] && [ -x "$_ready" ]; then + _vdir="${_ready%/modeler/mxbuild*}" + if [ -z "$ver" ] || mxtk_version_in_name "$_vdir" "$ver"; then + [ -n "${MXCLI_HOME:-}" ] && echo " note: mxcli caches under ~/.mxcli whatever MXCLI_HOME says (MXCLI_HOME=$MXCLI_HOME); using the mxbuild it reported: $_ready" >&2 + printf '%s\n' "$_ready"; return 0 fi + fi + if [ -n "$found" ] && [ -x "$found" ]; then + echo " โš  download finished but there is still no mxbuild for $ver โ€” using $found; the gate will report the refusal as unverified." >&2 printf '%s\n' "$found"; return 0 fi - echo " download reported success but no runnable mxbuild was found afterwards (looked under ${MXCLI_HOME:-$HOME/.mxcli}/mxbuild/)." >&2 + echo " download reported success but no runnable mxbuild was found afterwards (looked under ${MXCLI_HOME:-$HOME/.mxcli}/mxbuild/${_ready:+ and at $_ready, the path mxcli reported})." >&2 else echo " '$mxcli setup mxbuild' failed โ€” a blocked network or proxy is the usual cause (the download comes from the Mendix CDN)." >&2 fi diff --git a/tests/wave2/fixtures/mxbuild-setup/setup-mxbuild-cached-v0.32.0.out b/tests/wave2/fixtures/mxbuild-setup/setup-mxbuild-cached-v0.32.0.out new file mode 100644 index 00000000..b3976a38 --- /dev/null +++ b/tests/wave2/fixtures/mxbuild-setup/setup-mxbuild-cached-v0.32.0.out @@ -0,0 +1,5 @@ +WARNING: This is a vibe-coded PoC, alpha quality, use with caution. +Detected Mendix version: 11.8.0 + MxBuild 11.8.0 already cached at /root/.mxcli/mxbuild/11.8.0/modeler/mxbuild + +MxBuild ready: /root/.mxcli/mxbuild/11.8.0/modeler/mxbuild diff --git a/tests/wave2/test-mxbuild-setup-home.sh b/tests/wave2/test-mxbuild-setup-home.sh new file mode 100755 index 00000000..e519fd6a --- /dev/null +++ b/tests/wave2/test-mxbuild-setup-home.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +# test-mxbuild-setup-home.sh โ€” mxtk_ensure_mxbuild finds the mxbuild that `mxcli setup mxbuild` just +# fetched, also when MXCLI_HOME points somewhere else. +# +# usage: bash tests/wave2/test-mxbuild-setup-home.sh project-bin/_common.sh +# +# Field (real-mxcli run, mxcli v0.32.0-374, Mendix 11.8.0, 2026-11-20): the toolkit reads the mxbuild +# cache at ${MXCLI_HOME:-~/.mxcli}, but mxcli itself always uses ~/.mxcli (os.UserHomeDir, in +# cmd/mxcli/docker/download.go). With MXCLI_HOME set, exec.sh's auto-download printed +# "MxBuild ready: /root/.mxcli/mxbuild/11.8.0/modeler/mxbuild", then "download reported success but +# no runnable mxbuild was found afterwards", and refused the exec. +# +# Golden input, captured verbatim: fixtures/mxbuild-setup/setup-mxbuild-cached-v0.32.0.out is the +# stdout+stderr of `./mxcli setup mxbuild -p ProbeApp.mpr` from that run. The stub mxcli replays it +# with "/root" replaced by this test's HOME (the only edit, so the path it names exists here) and +# creates that mxbuild, as the real command does. +# +# A MXCLI_HOME elsewhere: the reported mxbuild is used, rc 0, a note names MXCLI_HOME (fails on master) +# B MXCLI_HOME unset: the same mxbuild, rc 0 (guard) +# C setup reports an mxbuild of another version: not used, rc 1 (guard) +# D setup fails: rc 1, the "failed" line (guard) +# +# Nothing here touches a real .mpr, a real mxcli or a real mxbuild. +set -u + +COMMON="${1:?usage: $0 project-bin/_common.sh}" +COMMON="$(cd "$(dirname "$COMMON")" && pwd)/$(basename "$COMMON")" +HERE="$(cd "$(dirname "$0")" && pwd)" +GOLDEN="$HERE/fixtures/mxbuild-setup/setup-mxbuild-cached-v0.32.0.out" +T="$(mktemp -d "${TMPDIR:-/tmp}/mxtk-mxb-setup.XXXXXX")" +trap 'rm -rf "$T"' EXIT +PASS=0; FAIL=0 +ok() { PASS=$((PASS + 1)); echo " ok $*"; } +fail() { FAIL=$((FAIL + 1)); echo " FAIL $*"; } + +# shellcheck disable=SC1091 +. "$HERE/../../bin/lib/portable.sh" +PY="$(resolve_py)" && "$PY" -c 'import sqlite3' >/dev/null 2>&1 \ + || { echo "SKIP: no Python 3 with sqlite3"; exit 0; } + +P="$T/proj"; mkdir -p "$P" +"$PY" - "$P/ProbeApp.mpr" <<'PYEOF' +import sqlite3, sys +c = sqlite3.connect(sys.argv[1]) +c.execute('CREATE TABLE _MetaData (_ProductVersion TEXT, _BuildVersion TEXT, _SchemaHash TEXT, _DisableAutoMprV2Upgrade INTEGER)') +c.execute("INSERT INTO _MetaData VALUES ('11.8.0', '11.8.0', '{SHA256}fixture', 0)") +c.commit() +PYEOF +H="$T/home"; mkdir -p "$H" "$T/elsewhere" +# Stub project mxcli. SETUP_VER: the version the replayed capture names (default 11.8.0). SETUP_RC: exit code. +cat > "$P/mxcli" < "\$HOME/.mxcli/mxbuild/\$v/modeler/mxbuild"; chmod +x "\$HOME/.mxcli/mxbuild/\$v/modeler/mxbuild" +sed -e "s#/root#\$HOME#g" -e "s#11\\.8\\.0#\$v#g" "$GOLDEN" +MXCLI +chmod +x "$P/mxcli" + +run() { # run -> OUT (stdout), ERR, RC + rm -rf "$H/.mxcli" + env -i PATH="$PATH" HOME="$H" PROJECT_ROOT="$P" TMPDIR="$T" "$@" \ + bash -c "set -u; source '$COMMON'; mxtk_ensure_mxbuild '$P/ProbeApp.mpr'" >"$T/out" 2>"$T/err" + RC=$?; OUT="$(cat "$T/out")"; ERR="$(cat "$T/err")" +} +WANT="$H/.mxcli/mxbuild/11.8.0/modeler/mxbuild" + +echo "== A: MXCLI_HOME elsewhere ==" +run MXCLI_HOME="$T/elsewhere" +[ "$RC" = 0 ] && [ "$OUT" = "$WANT" ] && ok "A: rc 0, the mxbuild mxcli reported" || fail "A: rc=$RC out='$OUT' err: $(tail -2 "$T/err")" +case "$ERR" in *"MXCLI_HOME=$T/elsewhere"*) ok "A: note names MXCLI_HOME" ;; *) fail "A: no MXCLI_HOME note" ;; esac +case "$ERR" in *"MxBuild ready: $WANT"*) ok "A: mxcli's own output still on stderr" ;; *) fail "A: setup output not shown" ;; esac + +echo "== B: MXCLI_HOME unset ==" +run +[ "$RC" = 0 ] && [ "$OUT" = "$WANT" ] && ok "B: rc 0, same mxbuild" || fail "B: rc=$RC out='$OUT'" +case "$ERR" in *"note: mxcli caches"*) fail "B: MXCLI_HOME note without MXCLI_HOME" ;; *) ok "B: no note" ;; esac + +echo "== C: setup reports another version ==" +run MXCLI_HOME="$T/elsewhere" SETUP_VER=11.9.0 +[ "$RC" = 1 ] && ok "C: rc 1, a wrong-version mxbuild is not the gate" || fail "C: rc=$RC out='$OUT'" + +echo "== D: setup fails ==" +run MXCLI_HOME="$T/elsewhere" SETUP_RC=1 +[ "$RC" = 1 ] && case "$ERR" in *"setup mxbuild' failed"*) true ;; *) false ;; esac \ + && ok "D: rc 1, failure named" || fail "D: rc=$RC err: $(tail -2 "$T/err")" + +echo "" +echo "== $PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ] From 757ff7c144c5bd1b3e9dc7cdef0c98ac7d7accde Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 18:46:50 +0000 Subject: [PATCH 03/10] fix(exec): remove module source folders a rolled-back write created The snapshot covers the .mpr and mprcontents/ only; `create module` also writes themesource//, which stayed behind untracked after a failed gate restored the model (real mxcli v0.32.0-374, CE1613 rollback). After a successful auto-restore, remove folders under themesource/, javasource/, javascriptsource/ that did not exist at snapshot time and hold no tracked file. Fixture on the verbatim leftover files, single tree and app/. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC --- CHANGELOG.md | 1 + project-bin/exec.sh | 28 +++++ .../sliptwo/native/design-properties.json | 3 + .../sliptwo/native/main.js | 2 + .../sliptwo/settings.json | 3 + .../sliptwo/web/design-properties.json | 3 + .../sliptwo/web/main.scss | 2 + .../rollback-untracked-v0.32.0.txt | 7 ++ tests/wave2/test-exec-rollback-module-dirs.sh | 115 ++++++++++++++++++ 9 files changed, 164 insertions(+) create mode 100644 tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/design-properties.json create mode 100644 tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/main.js create mode 100644 tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/settings.json create mode 100644 tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/design-properties.json create mode 100644 tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/main.scss create mode 100644 tests/wave2/fixtures/exec-rollback-module-dirs/rollback-untracked-v0.32.0.txt create mode 100755 tests/wave2/test-exec-rollback-module-dirs.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index efe60ba1..c095701c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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(exec): **a rolled-back exec no longer leaves the new module's source folder behind**: the snapshot covers the `.mpr` and `mprcontents/` only, and `create module` also writes `themesource//` (five files on mxcli v0.32), so after a failed gate restored the model the folder stayed, untracked, for a module the model no longer had โ€” one `git add -A` from being committed. After a successful auto-restore, `exec.sh` now removes a folder under `themesource/`, `javasource/` or `javascriptsource/` beside the `.mpr` that did not exist at snapshot time and holds no tracked file, and says so; anything that existed before the write is kept (single tree and `app/`). Fixture `test-exec-rollback-module-dirs.sh` on the verbatim leftover files โ€” real-mxcli field run (mxcli v0.32.0-374, blank Mendix 11.8.0 app) - fix(exec, _common): **the mxbuild auto-download works when `MXCLI_HOME` points elsewhere**: the toolkit looks for the cache at `${MXCLI_HOME:-~/.mxcli}`, but mxcli itself always caches under `~/.mxcli` (`os.UserHomeDir`), so `exec.sh` downloaded, printed `MxBuild ready: โ€ฆ`, then reported "no runnable mxbuild was found afterwards" and refused the exec. `mxtk_ensure_mxbuild` now takes the path mxcli reports when re-discovery finds nothing (same version only) and says that `MXCLI_HOME` is not mxcli's. Fixture `test-mxbuild-setup-home.sh` on a verbatim `setup mxbuild` capture โ€” real-mxcli field run (mxcli v0.32.0-374, blank Mendix 11.8.0 app) - fix(exec): **a refused pre-exec check keeps the cause of a v0.32 reference error in the BUILD-LOG row**: mxcli v0.32 prints a reference error as two lines under `Reference errors:` (`statement 3: microflow 'X' has reference errors:` then ` - entity not found: โ€ฆ`) and the ๐Ÿšซ row kept only the header, which names no cause. The cause line is now appended. Fixture `test-exec-check-refusal.sh` F, on a verbatim v0.32.0 capture โ€” real-mxcli field run (mxcli v0.32.0-374, blank Mendix 11.8.0 app) - new(doctor, bug ledger): **a guard for mxcli's silent MxBuild fallback**: when the project's Mendix version is not in `~/.mxcli/mxbuild/` (and no Studio Pro of that version exists), `mxcli docker build` / `docker check` fall back to the newest cached MxBuild and print its path but no version warning (`run --local` is exact-or-refuse); `bin/doctor.sh` now warns, naming the model version, the cached ones and `./mxcli setup mxbuild -p .mpr` (`mxtk_mxbuild_cache_gap`, warning only, never changes a gate). Ledger entry `BUG-DRAFT-mxbuild-silent-version-fallback`; upstream issue not filed. โ€” a four-app Mendix build (field run), independent review diff --git a/project-bin/exec.sh b/project-bin/exec.sh index fd398316..78ec155c 100755 --- a/project-bin/exec.sh +++ b/project-bin/exec.sh @@ -1741,10 +1741,37 @@ if [ ! -x "$MXBUILD" ] || [ ! -x "$JAVA_EXE" ]; then fi fi +# The snapshot holds the .mpr and mprcontents/ only. `create module` also writes the module's source +# folders beside the .mpr (mxcli v0.32: themesource//{settings.json,web/*,native/*}, measured +# on a rolled-back real exec, fixtures/exec-rollback-module-dirs/), so a restore left them behind, +# untracked, for a module the model no longer has. module_dirs lists the folders under the three roots +# mxcli writes per module; after a successful restore, a folder that was not there at snapshot time +# and holds no tracked file is removed. Anything that existed before the write is never touched. +module_dirs() { + local d + for d in "$MODEL_DIR"/themesource/*/ "$MODEL_DIR"/javasource/*/ "$MODEL_DIR"/javascriptsource/*/; do + [ -d "$d" ] && printf '%s\n' "${d%/}" + done + return 0 +} +remove_new_module_dirs() { + local d rel + while IFS= read -r d; do + [ -n "$d" ] || continue + printf '%s\n' "$MODDIRS_BEFORE" | grep -qxF -- "$d" && continue + rel="${d#"$PROJECT_ROOT"/}" + [ -n "$(git -C "$PROJECT_ROOT" ls-files -- "$rel" 2>/dev/null | head -1)" ] && continue + rm -rf -- "$d" && echo " โ†’ Removed $rel/ (created by this write, not in the restored model)" + done <.mxunit.bak inside @@ -1776,6 +1803,7 @@ restore_snapshot() { elif R_OUT=$(MXTK_RESTORE_SAME_LEDGER=1 bash "$RESTORER" "$NEWEST_SNAP" 2>&1); then RESTORED=1 printf '%s\n' "$R_OUT" | sed 's/^/ โ†’ /' + [ -n "${MODDIRS_BEFORE+x}" ] && remove_new_module_dirs echo " โ†’ Auto-restored from: $NEWEST_SNAP" else printf '%s\n' "$R_OUT" | sed 's/^/ /' diff --git a/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/design-properties.json b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/design-properties.json new file mode 100644 index 00000000..49d1a202 --- /dev/null +++ b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/design-properties.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/main.js b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/main.js new file mode 100644 index 00000000..b611ae1e --- /dev/null +++ b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/native/main.js @@ -0,0 +1,2 @@ +import * as variables from "../../../theme/native/custom-variables"; + diff --git a/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/settings.json b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/settings.json new file mode 100644 index 00000000..49d1a202 --- /dev/null +++ b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/settings.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/design-properties.json b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/design-properties.json new file mode 100644 index 00000000..49d1a202 --- /dev/null +++ b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/design-properties.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/main.scss b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/main.scss new file mode 100644 index 00000000..122370f7 --- /dev/null +++ b/tests/wave2/fixtures/exec-rollback-module-dirs/created-by-create-module/sliptwo/web/main.scss @@ -0,0 +1,2 @@ +@import '../../../theme/web/custom-variables'; + diff --git a/tests/wave2/fixtures/exec-rollback-module-dirs/rollback-untracked-v0.32.0.txt b/tests/wave2/fixtures/exec-rollback-module-dirs/rollback-untracked-v0.32.0.txt new file mode 100644 index 00000000..dbf772af --- /dev/null +++ b/tests/wave2/fixtures/exec-rollback-module-dirs/rollback-untracked-v0.32.0.txt @@ -0,0 +1,7 @@ + M .claude/loop/metrics-ledger.tsv + M docs/BUILD-LOG.md +?? themesource/sliptwo/native/design-properties.json +?? themesource/sliptwo/native/main.js +?? themesource/sliptwo/settings.json +?? themesource/sliptwo/web/design-properties.json +?? themesource/sliptwo/web/main.scss diff --git a/tests/wave2/test-exec-rollback-module-dirs.sh b/tests/wave2/test-exec-rollback-module-dirs.sh new file mode 100755 index 00000000..371b6a28 --- /dev/null +++ b/tests/wave2/test-exec-rollback-module-dirs.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash +# test-exec-rollback-module-dirs.sh - a rolled-back exec leaves no module source folder behind. +# +# usage: bash tests/wave2/test-exec-rollback-module-dirs.sh [path-to-exec.sh] +# +# Field (real-mxcli run, mxcli v0.32.0-374, Mendix 11.8.0, 2026-11-20): `create module SlipTwo` plus a +# microflow with a member typo passed `mxcli check`, was written, failed the mx check gate (CE1613) +# and was rolled back. The snapshot covers the .mpr and mprcontents/ only, so themesource/sliptwo/ +# (five files mxcli writes for a new module) stayed behind, untracked, for a module the model no +# longer has; the next `git add -A` would commit it. +# +# Golden input, captured verbatim from that run, in fixtures/exec-rollback-module-dirs/: +# rollback-untracked-v0.32.0.txt `git status --porcelain --untracked-files=all` after the rollback +# created-by-create-module/sliptwo/ the five files themselves, byte for byte +# The stub `mxcli exec` copies that folder into themesource/ beside the .mpr, as the real one does. +# +# A single tree: gate fails -> restored, themesource/sliptwo/ gone (fails on master) +# B .mpr under app/: same, app/themesource/sliptwo/ gone (fails on master) +# C a folder that existed before the write is kept: tracked, untracked, and ignored ones +# D a clean apply keeps the new module's folder +# +# Synthetic project, stub mxcli / mxbuild / java. The real snapshot-mpr.sh and restore-mpr.sh run. +set -uo pipefail + +TOOLKIT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +SUBJECT="${1:-$TOOLKIT/project-bin/exec.sh}" +case "$SUBJECT" in /*) ;; *) SUBJECT="$PWD/$SUBJECT" ;; esac +GOLD="$TOOLKIT/tests/wave2/fixtures/exec-rollback-module-dirs" +WORK="$(cd "$(mktemp -d "${TMPDIR:-/tmp}/exec-moddirs.XXXXXX")" && pwd -P)" || exit 2 +trap 'rm -rf "$WORK"' EXIT +PASS=0; FAIL=0 +ok() { PASS=$((PASS+1)); echo " ok - $1"; } +bad() { FAIL=$((FAIL+1)); echo " FAIL - $1${2:+: $2}"; } +echo "== subject: $SUBJECT" + +# The captured status lists exactly the files the captured folder holds. +_want="$(sed -n 's#^?? themesource/##p' "$GOLD/rollback-untracked-v0.32.0.txt" | LC_ALL=C sort)" +_have="$(cd "$GOLD/created-by-create-module" && find . -type f | sed 's#^\./##' | LC_ALL=C sort)" +[ -n "$_want" ] && [ "$_want" = "$_have" ] && ok "[golden] status capture and folder capture agree ($(printf '%s\n' "$_want" | grep -c .) files)" \ + || bad "[golden] status capture and folder capture disagree" "$_want / $_have" + +mkdir -p "$WORK/jdk/bin"; printf '#!/usr/bin/env bash\nexit 0\n' > "$WORK/jdk/bin/java" +cat > "$WORK/mxbuild" <<'MXB' +#!/usr/bin/env bash +err=""; for a in "$@"; do case "$a" in --write-errors=*) err="${a#--write-errors=}" ;; esac; done +n=$(( $(cat "$MXB_N" 2>/dev/null || echo 0) + 1 )); echo "$n" > "$MXB_N" +mode="$(printf '%s\n' "$MXB_MODES" | tr ',' '\n' | sed -n "${n}p")"; mode="${mode:-ok}" +case "$mode" in + ok) [ -n "$err" ] && printf '{"problems":[]}' > "$err"; exit 0 ;; + err) [ -n "$err" ] && printf '{"problems":[{"severity":"Error","code":"CE1613","message":"The selected attribute '"'"'SlipTwo.Thing.Nmae'"'"' no longer exists.","element":{"document":"SlipTwo.ACT_Thing"}}]}' > "$err"; exit 1 ;; +esac +MXB +chmod +x "$WORK/mxbuild" "$WORK/jdk/bin/java" + +# mk : a committed project with tracked themesource/sales, an untracked +# themesource/userwork (theme work not yet committed) and an ignored javasource/sales/proxies. +mk() { + P="$1"; M="$P${2:+/$2}" + mkdir -p "$P/bin" "$P/mdlsource" "$M/mprcontents" "$M/themesource/sales" "$M/javasource/sales/proxies" + printf 'not a real model\n' > "$M/Fixture.mpr"; printf 'bson\n' > "$M/mprcontents/a.mxunit" + printf '{}\n' > "$M/themesource/sales/settings.json"; printf 'x\n' > "$M/javasource/sales/proxies/P.java" + printf 'mdl 1;\ncreate module SlipTwo;\n' > "$P/mdlsource/test.mdl" + cp "$TOOLKIT/project-bin/_common.sh" "$TOOLKIT/project-bin/restore-mpr.sh" "$TOOLKIT/project-bin/snapshot-mpr.sh" "$P/bin/" + cp "$SUBJECT" "$P/bin/exec.sh" + cat > "$P/mxcli" <> "$M/Fixture.mpr"; echo x >> "$M/mprcontents/a.mxunit" + cp -R "$GOLD/created-by-create-module/sliptwo" "$M/themesource/sliptwo"; echo "Created module: SlipTwo"; exit 0 ;; +esac +exit 0 +MXCLI + chmod +x "$P/bin/"*.sh "$P/mxcli" + ( cd "$P" && git init -q . && printf '.mpr-snapshots/\ndocs/\n.claude/\n/javasource/*/proxies/\n/app/javasource/*/proxies/\n' > .gitignore \ + && git add -A && git -c user.email=t@t -c user.name=t commit -qm fixture ) >/dev/null 2>&1 + mkdir -p "$M/themesource/userwork"; printf 'mine\n' > "$M/themesource/userwork/main.scss" +} +run() { # run -> RC + rm -f "$WORK/n"; mkdir -p "$WORK/tmp" + ( cd "$1" && TMPDIR="$WORK/tmp" SP_RESTART=0 MXTK_NO_INSTALL=1 SKIP_LINT=fixture MXB_N="$WORK/n" MXB_MODES="$2" \ + MXBUILD_PATH="$WORK/mxbuild" JAVA_HOME="$WORK/jdk" ./bin/exec.sh mdlsource/test.mdl ) >"$WORK/out" 2>&1 + RC=$? +} +kept_old() { # kept_old