From 8ff7fdb8b621cd709a30b1cad2d4acdf0d2ababc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 05:49:59 +0000 Subject: [PATCH 01/19] fix(git merge): refuse another Mendix version's mx merge engine ResolveMxForVersion treats the project's version as a preference: an mx on PATH first, then the newest installed one, then any cached download. So on a Linux container or CI runner with only another version cached, `mxcli git merge` ran that version's `mx merge`, which wrote the project's merged model, and nothing said so. A model merge (and the mx diff behind its conflict review) now runs only on an mx of the project's own release, checked with MxBinaryVersion and SameMendixRelease. Another version, or an mx whose version cannot be told, is refused before it runs; the existing abort path restores the tree, and the message names `mxcli setup mxbuild --version `. --mxbuild-path is the deliberate override and only warns, the rule `marketplace package` already applies. Test: cmd/mxcli/gitmerge_mx_version_test.go. Control: with the check stubbed out, all three merge tests fail. Co-Authored-By: Claude Opus 5.5 --- ...25-git-merge-runs-another-versions-mx.json | 1 + CHANGELOG.md | 4 + cmd/mxcli/cmd_git_merge.go | 122 +++++++++++++-- cmd/mxcli/gitmerge_mx_version_test.go | 140 ++++++++++++++++++ docs-site/src/tools/outside-studio-pro.md | 8 +- 5 files changed, 262 insertions(+), 13 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json create mode 100644 cmd/mxcli/gitmerge_mx_version_test.go diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json new file mode 100644 index 000000000..70fd1e52e --- /dev/null +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json @@ -0,0 +1 @@ +{"area": "cmd/mxcli", "date": "2026-11-25", "symptom": "`mxcli git merge` merged a model with another Mendix version's `mx merge` when the project's exact version was not installed: the merge commit was written by that engine and nothing warned.", "cause": "realMxMerge and realMxDiff called docker.ResolveMxForVersion, which treats the version as a preference: it takes an mx on PATH first, then the newest installed one, then any cached download, and returns no error when none matches.", "file": "cmd/mxcli/cmd_git_merge.go", "fix": "mergeMxLookup resolves mx once per run and checks docker.MxBinaryVersion against the project's _ProductVersion with docker.SameMendixRelease; another release, or an mx whose version cannot be told, is an error, so the runner fails before exec and the existing abort path restores the tree. --mxbuild-path is the override (warns once), the same rule marketplace package's checkMxVersion applies.", "insight": "ResolveMxForVersion's 'any version will do' fallbacks are right for read-only checks and wrong for anything that writes the model; every writer (new, marketplace package, fix hashes, now git merge) has had to add its own exact-version check. Grep for ResolveMxForVersion callers that write before trusting the resolver.", "refs": [], "test": "cmd/mxcli/gitmerge_mx_version_test.go (another version refused and aborted; unknown version refused; --mxbuild-path runs the engine with one warning; control: with the check stubbed out all three fail)"} diff --git a/CHANGELOG.md b/CHANGELOG.md index 157076a50..edd44db77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] +### Fixed + +- **`git merge` no longer runs another Mendix version's merge engine** — the engine was resolved by preference, so with only another version cached (a Linux container, a CI runner) or an `mx` on PATH, `mx merge` of that version wrote the project's merged model and nothing said so. A model merge now runs only on an mx of the project's own release: another version's, or one whose version cannot be told, is refused before it runs, the merge is aborted, and the message names `mxcli setup mxbuild --version `. The `mx diff` behind the conflict review is held to the same check. `--mxbuild-path` names an mx on purpose; with it a mismatch only warns, as in `marketplace package`. + ## [0.34.0] - 2026-11-27 Headline: **Mendix 11.17 support, domain model diagrams that `mxcli layout` actually untangles, and pluggable widgets judged by running their own `editorConfig.js`.** Workflows with boundary events, pages and change data capture services are written in the shape 11.17 reads, and `run --local --watch` drops its client-copy workaround there. `mxcli layout` places entities by what they link to, re-attaches every association line and reports crossings, while new lint rules `MPR020`-`MPR022` flag a diagram never laid out, a line through an unrelated entity and an agent naming a missing document. Microflows gain Metrics activities (`increment counter`, `set gauge`), `@documentation` on a statement and a `@curve` per decision outcome. diff --git a/cmd/mxcli/cmd_git_merge.go b/cmd/mxcli/cmd_git_merge.go index 3fb321e95..8cd31f1b3 100644 --- a/cmd/mxcli/cmd_git_merge.go +++ b/cmd/mxcli/cmd_git_merge.go @@ -106,7 +106,13 @@ Once the merge commits, the plan template beside the .mpr is removed. The merge is refused while Studio Pro has the project open (.mpr.lock). MPR v2 projects only. The mx binary is resolved for the project's Mendix -version (PATH, the mxcli cache, or the Studio Pro installation).`, +version (PATH, the mxcli cache, or the Studio Pro installation), and a model +merge runs only on an mx of that exact release: another Mendix version's +engine would write this project's model, so an mx of another version, or one +whose version cannot be told, is refused before it runs (the merge is +aborted, nothing is committed). Install the matching one with +'mxcli setup mxbuild --version '. --mxbuild-path names the +mx to use on purpose; with it a version mismatch is only warned about.`, Example: ` mxcli git merge feature/orders -p app.mpr mxcli git merge origin/main -p app.mpr --push mxcli git merge feature/orders -p app.mpr --theirs # after reviewing the report @@ -125,6 +131,8 @@ func init() { gitMergeCmd.Flags().Bool("theirs", false, "on a model conflict mx cannot resolve, take their side of every conflicted model file") gitMergeCmd.Flags().String("plan", "", "resolve per unit from a plan file written by a previous run (.merge-plan.json)") gitMergeCmd.Flags().Bool("push", false, "push the branch and the notes ref to their remote afterwards") + gitMergeCmd.Flags().String("mxbuild-path", "", + "path to the Mendix installation to take mx from; it overrides the version check (a mismatch only warns)") gitCmd.AddCommand(gitMergeCmd) } @@ -136,6 +144,7 @@ func runGitMerge(cmd *cobra.Command, args []string) error { plan, _ := cmd.Flags().GetString("plan") push, _ := cmd.Flags().GetBool("push") project, _ := cmd.Flags().GetString("project") + mxbuildPath, _ := cmd.Flags().GetString("mxbuild-path") strategy := "" switch { case ours && theirs: @@ -147,7 +156,14 @@ func runGitMerge(cmd *cobra.Command, args []string) error { case theirs: strategy = "theirs" } - return mergeRun(project, ref, message, strategy, plan, push, mxRunners{merge: realMxMerge, diff: realMxDiff}, cmd.OutOrStdout()) + if mxbuildPath != "" { + // ResolveMxForVersion quietly falls back to an mx on PATH when this + // path is bad, which would turn a typo into an unchecked merge. + if _, err := os.Stat(mxbuildPath); err != nil { + return fmt.Errorf("--mxbuild-path %s: %w", mxbuildPath, err) + } + } + return mergeRun(project, ref, message, strategy, plan, push, mxRunnersFor(mxbuildPath, cmd.ErrOrStderr()), cmd.OutOrStdout()) } // mxRunners are the mx invocations, injected for tests. @@ -640,14 +656,96 @@ func projectMendixVersion(mprPath string) string { return v } -// realMxMerge shells out to `mx merge -v BASE MINE THEIRS` over the three +// resolveMxForMerge and mergeMxVersion are injected for tests. +var ( + resolveMxForMerge = docker.ResolveMxForVersion + mergeMxVersion = docker.MxBinaryVersion +) + +// mxLookup finds the mx for the project file at mprPath. +type mxLookup func(mprPath string) (string, error) + +// mergeMxLookup resolves the mx a merge runs, and refuses one that is not the +// project's Mendix release. +// +// ResolveMxForVersion prefers an mx on PATH over the project's version and +// falls back to any cached one, so on a machine with only another version +// cached the merge engine — which writes the merged model — would silently be +// another Mendix version's. The version check makes that a refusal, the way +// `mxcli new` and `marketplace package` already treat a substituted mx. With +// --mxbuild-path (override) the same findings are warned about once on stderr. +func mergeMxLookup(mxbuildPath string, stderr io.Writer) mxLookup { + warned := false + return func(mprPath string) (string, error) { + version := projectMendixVersion(mprPath) + mxPath, err := resolveMxForMerge(mxbuildPath, version) + if err != nil { + return "", fmt.Errorf("no mx for Mendix %s: %w (model conflicts need it)\nhint: run 'mxcli setup mxbuild --version %s'", version, err, version) + } + problem := mergeMxProblem(mxPath, version) + if problem == "" { + return mxPath, nil + } + if mxbuildPath != "" { + if !warned { + fmt.Fprintf(stderr, "warning: %s; going on because --mxbuild-path was given\n", problem) + warned = true + } + return mxPath, nil + } + return "", fmt.Errorf("%s.\nA model merge by another Mendix version's engine than the project's is refused.\n"+ + "hint: run 'mxcli setup mxbuild --version %s' to install the matching mx (an mx on PATH is used before it,\n"+ + "so take that one off PATH); to use this mx on purpose, pass --mxbuild-path", problem, version) + } +} + +// mergeMxProblem says why the mx at mxPath must not merge a project of +// version, or "" when it may: it is the same Mendix release. An unknown +// project version is not checked (ResolveMxForVersion had nothing to prefer +// either); an mx whose own version cannot be told is a problem. +func mergeMxProblem(mxPath, version string) string { + if version == "" { + return "" + } + got := mergeMxVersion(mxPath) + if docker.SameMendixRelease(got, version) { + return "" + } + if got == "" { + return fmt.Sprintf("cannot tell which Mendix version %s is, and the project is Mendix %s", mxPath, version) + } + return fmt.Sprintf("the mx found, %s, is Mendix %s, but the project is Mendix %s", mxPath, got, version) +} + +// mxRunnersFor wires the real mx invocations to one version-checked lookup. +func mxRunnersFor(mxbuildPath string, stderr io.Writer) mxRunners { + mx := mergeMxLookup(mxbuildPath, stderr) + return mxRunners{ + merge: func(baseMpr, mineMpr, theirsMpr string, shas [3]string) (int, string, error) { + return runMxMerge(mx, baseMpr, mineMpr, theirsMpr) + }, + diff: func(base, mine, outJSON string) error { + return runMxDiff(mx, base, mine, outJSON) + }, + } +} + +// realMxMerge and realMxDiff are the runners with no --mxbuild-path. +func realMxMerge(baseMpr, mineMpr, theirsMpr string, shas [3]string) (int, string, error) { + return mxRunnersFor("", os.Stderr).merge(baseMpr, mineMpr, theirsMpr, shas) +} + +func realMxDiff(base, mine, outJSON string) error { + return mxRunnersFor("", os.Stderr).diff(base, mine, outJSON) +} + +// runMxMerge shells out to `mx merge -v BASE MINE THEIRS` over the three // revisions' project files, mx resolved for the project's Mendix version; // -v makes the engine print its per-unit conflict list. -func realMxMerge(baseMpr, mineMpr, theirsMpr string, shas [3]string) (int, string, error) { - version := projectMendixVersion(mineMpr) - mxPath, err := docker.ResolveMxForVersion("", version) +func runMxMerge(mx mxLookup, baseMpr, mineMpr, theirsMpr string) (int, string, error) { + mxPath, err := mx(mineMpr) if err != nil { - return 1, "", fmt.Errorf("no mx for Mendix %s: %w (model conflicts need it)", version, err) + return 1, "", err } cmd := exec.Command(mxPath, "merge", "-v", baseMpr, mineMpr, theirsMpr) docker.PrepareMxCommand(cmd) @@ -1059,12 +1157,12 @@ func statusOrNone(s string) string { return s } -// realMxDiff shells out to `mx diff BASE MINE OUTPUT` (resolved like the merge). -func realMxDiff(base, mine, outJSON string) error { - version := projectMendixVersion(mine) - mxPath, err := docker.ResolveMxForVersion("", version) +// runMxDiff shells out to `mx diff BASE MINE OUTPUT` (resolved and +// version-checked like the merge). +func runMxDiff(mx mxLookup, base, mine, outJSON string) error { + mxPath, err := mx(mine) if err != nil { - return fmt.Errorf("no mx for Mendix %s: %w", version, err) + return err } cmd := exec.Command(mxPath, "diff", base, mine, outJSON) docker.PrepareMxCommand(cmd) diff --git a/cmd/mxcli/gitmerge_mx_version_test.go b/cmd/mxcli/gitmerge_mx_version_test.go new file mode 100644 index 000000000..8165e4459 --- /dev/null +++ b/cmd/mxcli/gitmerge_mx_version_test.go @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "bytes" + "os" + "path/filepath" + "runtime" + "strings" + "testing" +) + +// stubMergeMx makes the mx lookup return mxPath, reported as Mendix version +// (the project fixtures are 11.13.0), and restores the real lookup afterwards. +func stubMergeMx(t *testing.T, mxPath, version string) *[]string { + t.Helper() + origResolve, origVersion := resolveMxForMerge, mergeMxVersion + t.Cleanup(func() { resolveMxForMerge, mergeMxVersion = origResolve, origVersion }) + var asked []string + resolveMxForMerge = func(mxbuildPath, preferred string) (string, error) { + asked = append(asked, preferred) + return mxPath, nil + } + mergeMxVersion = func(string) string { return version } + return &asked +} + +func assertMergeAborted(t *testing.T, dir, before string) { + t.Helper() + if got := commitSubject(t, dir); got != before { + t.Errorf("HEAD moved despite the refusal: %q", got) + } + if _, err := gitOut(dir, "rev-parse", "--verify", "--quiet", "MERGE_HEAD"); err == nil { + t.Error("MERGE_HEAD still present: the refusal must abort the merge") + } + if uu := gitOutT(t, dir, "diff", "--name-only", "--diff-filter=U"); strings.TrimSpace(uu) != "" { + t.Errorf("working tree not restored:\n%s", uu) + } +} + +// With only another Mendix version's mx resolvable (a cached download, an mx +// on PATH), the model merge must not run that engine: it would write this +// project's model with another version's merge. Refuse, abort, and say how to +// get the right one. +func TestGitMerge_RefusesAnotherVersionsMx(t *testing.T) { + dir, mprPath := modelConflictRepo(t) + doctorEnv(t, dir) + before := commitSubject(t, dir) + asked := stubMergeMx(t, "/cache/mxbuild/11.6.3/modeler/mx", "11.6.3") + + var out, stderr bytes.Buffer + err := mergeRun(mprPath, "side", "", "", "", false, mxRunnersFor("", &stderr), &out) + if err == nil { + t.Fatalf("want a refusal, the merge went through:\n%s", out.String()) + } + for _, want := range []string{ + "is Mendix 11.6.3, but the project is Mendix 11.13.0", + "mxcli setup mxbuild --version 11.13.0", + "--mxbuild-path", + } { + if !strings.Contains(err.Error(), want) { + t.Errorf("refusal lacks %q:\n%v", want, err) + } + } + if len(*asked) == 0 || (*asked)[0] != "11.13.0" { + t.Errorf("mx was not resolved for the project's version: %v", *asked) + } + assertMergeAborted(t, dir, before) +} + +// An mx whose version cannot be told is refused too: nothing shows it is the +// project's release. +func TestGitMerge_RefusesMxOfUnknownVersion(t *testing.T) { + dir, mprPath := modelConflictRepo(t) + doctorEnv(t, dir) + before := commitSubject(t, dir) + stubMergeMx(t, "/usr/local/bin/mx", "") + + var out, stderr bytes.Buffer + err := mergeRun(mprPath, "side", "", "", "", false, mxRunnersFor("", &stderr), &out) + if err == nil || !strings.Contains(err.Error(), "cannot tell which Mendix version /usr/local/bin/mx is") { + t.Fatalf("want the unknown-version refusal, got %v\n%s", err, out.String()) + } + assertMergeAborted(t, dir, before) +} + +// --mxbuild-path is the deliberate choice: a mismatch is warned about once and +// the engine runs. The fake mx exits 129 so the run ends in the existing +// engine-failure abort, which proves it was invoked. +func TestGitMerge_MxbuildPathOverridesVersionCheck(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("fake mx is a shell script") + } + dir, mprPath := modelConflictRepo(t) + doctorEnv(t, dir) + before := commitSubject(t, dir) + mx := filepath.Join(t.TempDir(), "mx") + if err := os.WriteFile(mx, []byte("#!/bin/sh\necho crashed\nexit 129\n"), 0o755); err != nil { + t.Fatal(err) + } + stubMergeMx(t, mx, "11.6.3") + + var out, stderr bytes.Buffer + err := mergeRun(mprPath, "side", "", "", "", false, mxRunnersFor(filepath.Dir(mx), &stderr), &out) + if err == nil || !strings.Contains(err.Error(), "exit 129") { + t.Fatalf("want the fake engine to have run (exit 129), got %v\n%s", err, out.String()) + } + warn := stderr.String() + if !strings.Contains(warn, "is Mendix 11.6.3, but the project is Mendix 11.13.0") || + !strings.Contains(warn, "going on because --mxbuild-path was given") { + t.Errorf("want the mismatch warned about, stderr:\n%s", warn) + } + if n := strings.Count(warn, "warning:"); n != 1 { + t.Errorf("want one warning, got %d:\n%s", n, warn) + } + assertMergeAborted(t, dir, before) +} + +func TestMergeMxProblem(t *testing.T) { + orig := mergeMxVersion + t.Cleanup(func() { mergeMxVersion = orig }) + for _, tc := range []struct { + name, project, mx, want string + }{ + {"same release", "11.13.0", "11.13.0", ""}, + {"build number ignored", "11.13.0.81004", "11.13.0", ""}, + {"other patch", "11.13.0", "11.13.1", "is Mendix 11.13.1, but the project is Mendix 11.13.0"}, + {"unknown mx", "11.13.0", "", "cannot tell which Mendix version"}, + {"unknown project is not checked", "", "11.6.3", ""}, + } { + t.Run(tc.name, func(t *testing.T) { + mergeMxVersion = func(string) string { return tc.mx } + got := mergeMxProblem("/x/mx", tc.project) + if tc.want == "" && got != "" || tc.want != "" && !strings.Contains(got, tc.want) { + t.Errorf("mergeMxProblem(%q, mx %q) = %q, want %q", tc.project, tc.mx, got, tc.want) + } + }) + } +} diff --git a/docs-site/src/tools/outside-studio-pro.md b/docs-site/src/tools/outside-studio-pro.md index 3fe6abaa7..8c3c3b7eb 100644 --- a/docs-site/src/tools/outside-studio-pro.md +++ b/docs-site/src/tools/outside-studio-pro.md @@ -256,7 +256,13 @@ HEAD) and theirs revisions are checked out into temporary worktrees and the three projects' .mpr files go to `mx merge` (resolved for the project's Mendix version; MINE is never the working tree mid-merge — the engine chokes on the conflicted state); the engine writes its result into MINE and -it is copied back, so the engine owns the `.mpr`: +it is copied back, so the engine owns the `.mpr`. The engine must be the +project's own Mendix release: an mx of another version (an `mx` on PATH, or +the only cached download), or one whose version cannot be told, is refused +before it runs and the merge is aborted. Install the matching one with +`mxcli setup mxbuild --version `, which is the usual first +step on a Linux container or CI runner; `--mxbuild-path` names an mx on +purpose, and then a mismatch is only a warning: - what the engine auto-resolves is copied back, hash-checked, staged and committed as the normal two-parent merge commit, with the note attached. From 9d8aec94ac389ed0228f7f79f649623d1c492b5e Mon Sep 17 00:00:00 2001 From: MendixMau Date: Sat, 28 Nov 2026 01:23:42 +0800 Subject: [PATCH 02/19] findings: ref mendixlabs/mxcli#1976 for the git merge mx version finding Co-Authored-By: Claude Opus 5.5 (1M context) --- .../2026-11-25-git-merge-runs-another-versions-mx.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json index 70fd1e52e..e95d9490a 100644 --- a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-25-git-merge-runs-another-versions-mx.json @@ -1 +1 @@ -{"area": "cmd/mxcli", "date": "2026-11-25", "symptom": "`mxcli git merge` merged a model with another Mendix version's `mx merge` when the project's exact version was not installed: the merge commit was written by that engine and nothing warned.", "cause": "realMxMerge and realMxDiff called docker.ResolveMxForVersion, which treats the version as a preference: it takes an mx on PATH first, then the newest installed one, then any cached download, and returns no error when none matches.", "file": "cmd/mxcli/cmd_git_merge.go", "fix": "mergeMxLookup resolves mx once per run and checks docker.MxBinaryVersion against the project's _ProductVersion with docker.SameMendixRelease; another release, or an mx whose version cannot be told, is an error, so the runner fails before exec and the existing abort path restores the tree. --mxbuild-path is the override (warns once), the same rule marketplace package's checkMxVersion applies.", "insight": "ResolveMxForVersion's 'any version will do' fallbacks are right for read-only checks and wrong for anything that writes the model; every writer (new, marketplace package, fix hashes, now git merge) has had to add its own exact-version check. Grep for ResolveMxForVersion callers that write before trusting the resolver.", "refs": [], "test": "cmd/mxcli/gitmerge_mx_version_test.go (another version refused and aborted; unknown version refused; --mxbuild-path runs the engine with one warning; control: with the check stubbed out all three fail)"} +{"area": "cmd/mxcli", "date": "2026-11-25", "symptom": "`mxcli git merge` merged a model with another Mendix version's `mx merge` when the project's exact version was not installed: the merge commit was written by that engine and nothing warned.", "cause": "realMxMerge and realMxDiff called docker.ResolveMxForVersion, which treats the version as a preference: it takes an mx on PATH first, then the newest installed one, then any cached download, and returns no error when none matches.", "file": "cmd/mxcli/cmd_git_merge.go", "fix": "mergeMxLookup resolves mx once per run and checks docker.MxBinaryVersion against the project's _ProductVersion with docker.SameMendixRelease; another release, or an mx whose version cannot be told, is an error, so the runner fails before exec and the existing abort path restores the tree. --mxbuild-path is the override (warns once), the same rule marketplace package's checkMxVersion applies.", "insight": "ResolveMxForVersion's 'any version will do' fallbacks are right for read-only checks and wrong for anything that writes the model; every writer (new, marketplace package, fix hashes, now git merge) has had to add its own exact-version check. Grep for ResolveMxForVersion callers that write before trusting the resolver.", "refs": ["mendixlabs/mxcli#1976"], "test": "cmd/mxcli/gitmerge_mx_version_test.go (another version refused and aborted; unknown version refused; --mxbuild-path runs the engine with one warning; control: with the check stubbed out all three fail)"} From 5f7b11a7df3a7d7c84420f841588a7a9cfe0e762 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 09:18:36 +0000 Subject: [PATCH 03/19] fix(git merge): take the exact mx before PATH; --mxbuild-path must hold one (#2644) Two holes left by the version check integrated from mendixlabs/mxcli#1977, both from ResolveMxForVersion's preference order: - it tries PATH before an exact-version install or cache, so with the project's mx cached and another version on PATH the merge was refused although the right engine was there. Without --mxbuild-path the lookup now takes docker.LocalMxForVersion (exact, never PATH) first. - when the --mxbuild-path folder holds no mx it falls back to PATH, and the override then ran that unnamed mx with only a warning. The override now covers only an mx under the named path (a file path stands for its folder); anything else is "no mx in ". A project whose version cannot be read now warns that the mx was not checked, as marketplace package does. The PR's test stub also stubs the exact-version lookup, so an mx cached on the test machine cannot leak in. Tests: cmd/mxcli/gitmerge_mx_resolve_2644_test.go (exact install beats PATH; --mxbuild-path without an mx refused, with one warned; the mx diff refused too; unknown project version warns; pathWithin). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QiMsnXa9crge2qnSk9S7Zn --- ...merge-mx-path-precedence-and-override.json | 1 + CHANGELOG.md | 2 +- cmd/mxcli/cmd_git_merge.go | 66 ++++++++-- cmd/mxcli/gitmerge_mx_resolve_2644_test.go | 122 ++++++++++++++++++ cmd/mxcli/gitmerge_mx_version_test.go | 7 +- docs-site/src/tools/outside-studio-pro.md | 5 +- 6 files changed, 189 insertions(+), 14 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-git-merge-mx-path-precedence-and-override.json create mode 100644 cmd/mxcli/gitmerge_mx_resolve_2644_test.go diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-git-merge-mx-path-precedence-and-override.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-git-merge-mx-path-precedence-and-override.json new file mode 100644 index 000000000..7e365f835 --- /dev/null +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-git-merge-mx-path-precedence-and-override.json @@ -0,0 +1 @@ +{"area": "cmd/mxcli", "date": "2026-11-28", "symptom": "after the git merge mx version check (mendixlabs/mxcli#1977), a merge was refused although the project's exact mx was installed, whenever another version's mx was on PATH; and `--mxbuild-path` naming a folder without an mx ran the mx on PATH under the override, with only a warning", "cause": "docker.ResolveMxForVersion tries PATH before an exact-version install or cache, and when --mxbuild-path holds no mx it falls back to PATH; the version check sat after the resolver, so it refused the PATH mx instead of looking for the right one, and the override applied to an mx nobody named", "file": "cmd/mxcli/cmd_git_merge.go (mergeMxLookup, pathWithin)", "fix": "without --mxbuild-path take docker.LocalMxForVersion (exact install or cache, never PATH) first, then the resolver plus the check; with it, refuse an mx that does not lie under the named path (a file path stands for its folder); warn when the project's version is unknown, as marketplace package does", "insight": "a version check placed after a preference-ordered resolver turns every resolver fallback into a refusal or an override; the exact-version lookup has to come before the resolver, not after it. marketplace package has the same PATH-first refusal", "refs": ["ako/mxcli#2644", "mendixlabs/mxcli#1976", "mendixlabs/mxcli#1977"], "test": "cmd/mxcli/gitmerge_mx_resolve_2644_test.go"} diff --git a/CHANGELOG.md b/CHANGELOG.md index b74ad4d26..974bf7500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **A catalog build no longer hangs forever on one document** (ako/mxcli#2641, upstream mendixlabs/mxcli#1975) — `lint`, `report` and `search` could stop at "source N-1/N documents" with 0% CPU, for half an hour, when a stale `.mxcli/catalog.db` was present. A document whose describe does not finish within 2 minutes is now given up on: the build finishes without it, names the document, and writes every goroutine's stack to the session log so the blocked wait can be found. - **`alter page … set (DataSource: microflow …(args))` keeps the arguments** (ako/mxcli#2634, upstream mendixlabs/mxcli#1969) — the data source was replaced but its arguments were dropped, so `mx check` failed with CE1571 for every parameter. A stated `FormValidations` was also reset to All. Microflow and nanoflow sources set by `alter` are now written exactly as `create page` writes them. - **`create or modify` changes a `case`'s branches in place** (ako/mxcli#2618, upstream mendixlabs/mxcli#1959) — adding a new enumeration value to a `when`, moving one to another `when`, taking a `when` out or adding a new one was refused ("it has N paths, not two"), so a dispatcher could only be rebuilt, losing what Studio Pro drew. Branches now pair by a shared value. A moved value's flow is re-pointed, a branch merge is added or taken out as needed, a removed branch takes its activities with it, and a new branch gets its own path into the case's merge, drawn below the others. Every other activity keeps its `$ID` and position. A removed branch that returns, raises an error, or holds a decision or a loop is still refused. -- **`git merge` no longer runs another Mendix version's merge engine** — the engine was resolved by preference, so with only another version cached (a Linux container, a CI runner) or an `mx` on PATH, `mx merge` of that version wrote the project's merged model and nothing said so. A model merge now runs only on an mx of the project's own release: another version's, or one whose version cannot be told, is refused before it runs, the merge is aborted, and the message names `mxcli setup mxbuild --version `. The `mx diff` behind the conflict review is held to the same check. `--mxbuild-path` names an mx on purpose; with it a mismatch only warns, as in `marketplace package`. +- **`git merge` no longer runs another Mendix version's merge engine** (ako/mxcli#2644, upstream mendixlabs/mxcli#1976) — the engine was resolved by preference, so with only another version cached (a Linux container, a CI runner) or an `mx` on PATH, `mx merge` of that version wrote the project's merged model and nothing said so. A model merge now runs only on an mx of the project's own release: another version's, or one whose version cannot be told, is refused before it runs, the merge is aborted, and the message names `mxcli setup mxbuild --version `. The `mx diff` behind the conflict review is held to the same check. `--mxbuild-path` names an mx on purpose; with it a mismatch only warns, as in `marketplace package`. An installed mx of the project's release is taken before an `mx` on PATH, so a different version on PATH no longer blocks a merge the right engine is there for. `--mxbuild-path` must name a folder that holds an mx: it no longer falls back to the `mx` on PATH and runs that under the override. ## [0.34.0] - 2026-11-27 diff --git a/cmd/mxcli/cmd_git_merge.go b/cmd/mxcli/cmd_git_merge.go index 8cd31f1b3..fa8ce615d 100644 --- a/cmd/mxcli/cmd_git_merge.go +++ b/cmd/mxcli/cmd_git_merge.go @@ -110,9 +110,11 @@ version (PATH, the mxcli cache, or the Studio Pro installation), and a model merge runs only on an mx of that exact release: another Mendix version's engine would write this project's model, so an mx of another version, or one whose version cannot be told, is refused before it runs (the merge is -aborted, nothing is committed). Install the matching one with +aborted, nothing is committed). An installed mx of the project's release is +used before an mx on PATH. Install the matching one with 'mxcli setup mxbuild --version '. --mxbuild-path names the -mx to use on purpose; with it a version mismatch is only warned about.`, +mx to use on purpose: it must hold an mx, and with it a version mismatch is +only warned about.`, Example: ` mxcli git merge feature/orders -p app.mpr mxcli git merge origin/main -p app.mpr --push mxcli git merge feature/orders -p app.mpr --theirs # after reviewing the report @@ -656,9 +658,10 @@ func projectMendixVersion(mprPath string) string { return v } -// resolveMxForMerge and mergeMxVersion are injected for tests. +// resolveMxForMerge, localMxForMerge and mergeMxVersion are injected for tests. var ( resolveMxForMerge = docker.ResolveMxForVersion + localMxForMerge = docker.LocalMxForVersion mergeMxVersion = docker.MxBinaryVersion ) @@ -674,29 +677,74 @@ type mxLookup func(mprPath string) (string, error) // another Mendix version's. The version check makes that a refusal, the way // `mxcli new` and `marketplace package` already treat a substituted mx. With // --mxbuild-path (override) the same findings are warned about once on stderr. +// +// Without --mxbuild-path an installed or cached mx of exactly the project's +// release is taken first: ResolveMxForVersion tries PATH before it, so an mx of +// another version on PATH made the merge refuse although the right engine was +// installed (ako/mxcli#2644). With it, the override covers only an mx under +// that path — the resolver falls back to PATH when the folder holds none, and +// the override would then run an mx nobody named. func mergeMxLookup(mxbuildPath string, stderr io.Writer) mxLookup { warned := false + warn := func(format string, args ...any) { + if !warned { + fmt.Fprintf(stderr, "warning: "+format+"\n", args...) + warned = true + } + } return func(mprPath string) (string, error) { version := projectMendixVersion(mprPath) + if mxbuildPath == "" && version != "" { + if exact := localMxForMerge(version); exact != "" { + return exact, nil + } + } mxPath, err := resolveMxForMerge(mxbuildPath, version) if err != nil { return "", fmt.Errorf("no mx for Mendix %s: %w (model conflicts need it)\nhint: run 'mxcli setup mxbuild --version %s'", version, err, version) } + if mxbuildPath != "" && !pathWithin(mxPath, mxbuildPath) { + return "", fmt.Errorf("no mx in %s (the mx found instead, %s, was not named by --mxbuild-path)", mxbuildPath, mxPath) + } + if version == "" { + warn("the project's Mendix version is unknown, so the version of %s was not checked", mxPath) + return mxPath, nil + } problem := mergeMxProblem(mxPath, version) if problem == "" { return mxPath, nil } if mxbuildPath != "" { - if !warned { - fmt.Fprintf(stderr, "warning: %s; going on because --mxbuild-path was given\n", problem) - warned = true - } + warn("%s; going on because --mxbuild-path was given", problem) return mxPath, nil } return "", fmt.Errorf("%s.\nA model merge by another Mendix version's engine than the project's is refused.\n"+ - "hint: run 'mxcli setup mxbuild --version %s' to install the matching mx (an mx on PATH is used before it,\n"+ - "so take that one off PATH); to use this mx on purpose, pass --mxbuild-path", problem, version) + "hint: run 'mxcli setup mxbuild --version %s' to install the matching mx (an installed mx of the\n"+ + "project's release is used before one on PATH); to use this mx on purpose, pass --mxbuild-path", problem, version) + } +} + +// pathWithin reports whether path lies under dir, symbolic links resolved: an +// mx the --mxbuild-path folder holds (in it or in its modeler/ subfolder). A +// dir naming a file — the mxbuild binary itself — stands for its folder, where +// the resolver finds mx beside it. +func pathWithin(path, dir string) bool { + if p, err := filepath.EvalSymlinks(path); err == nil { + path = p + } + if d, err := filepath.EvalSymlinks(dir); err == nil { + dir = d + } + if info, err := os.Stat(dir); err == nil && !info.IsDir() { + dir = filepath.Dir(dir) + } + absPath, err1 := filepath.Abs(path) + absDir, err2 := filepath.Abs(dir) + if err1 != nil || err2 != nil { + return false } + rel, err := filepath.Rel(absDir, absPath) + return err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator)) } // mergeMxProblem says why the mx at mxPath must not merge a project of diff --git a/cmd/mxcli/gitmerge_mx_resolve_2644_test.go b/cmd/mxcli/gitmerge_mx_resolve_2644_test.go new file mode 100644 index 000000000..cc11ebf5f --- /dev/null +++ b/cmd/mxcli/gitmerge_mx_resolve_2644_test.go @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "bytes" + "os" + "path/filepath" + "strings" + "testing" +) + +// ako/mxcli#2644 (integration of mendixlabs/mxcli#1977): the version check on +// git merge's mx, and the two holes left in it. + +// An installed mx of the project's exact release wins over an mx on PATH. +// ResolveMxForVersion tries PATH first, so with 11.13.0 cached and 11.6.3 on +// PATH the merge was refused although the right engine was there. +func TestGitMergeMx_ExactInstallBeatsPath(t *testing.T) { + _, mprPath := modelConflictRepo(t) // Mendix 11.13.0 + stubMergeMx(t, "/usr/local/bin/mx", "11.6.3") + localMxForMerge = func(v string) string { + if v == "11.13.0" { + return "/cache/mxbuild/11.13.0/modeler/mx" + } + return "" + } + var stderr bytes.Buffer + got, err := mergeMxLookup("", &stderr)(mprPath) + if err != nil { + t.Fatalf("refused although Mendix 11.13.0's mx is installed: %v", err) + } + if got != "/cache/mxbuild/11.13.0/modeler/mx" { + t.Errorf("merge engine = %s, want the exact-version install", got) + } + if stderr.Len() != 0 { + t.Errorf("warned about an exact match: %s", stderr.String()) + } +} + +// --mxbuild-path overrides the check only for an mx under that path. A folder +// without one made ResolveMxForVersion fall back to PATH, and the override then +// ran that unnamed mx with only a warning. +func TestGitMergeMx_MxbuildPathMustHoldTheMx(t *testing.T) { + _, mprPath := modelConflictRepo(t) + empty := t.TempDir() + stubMergeMx(t, "/usr/local/bin/mx", "11.6.3") + var stderr bytes.Buffer + _, err := mergeMxLookup(empty, &stderr)(mprPath) + if err == nil || !strings.Contains(err.Error(), "no mx in "+empty) { + t.Fatalf("want a refusal naming %s, got %v (stderr %q)", empty, err, stderr.String()) + } + + // Control: an mx under the named path is used, the mismatch warned about. + dir := t.TempDir() + mx := filepath.Join(dir, "modeler", "mx") + if err := os.MkdirAll(filepath.Dir(mx), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(mx, []byte("#!/bin/sh\n"), 0o755); err != nil { + t.Fatal(err) + } + stubMergeMx(t, mx, "11.6.3") + stderr.Reset() + got, err := mergeMxLookup(dir, &stderr)(mprPath) + if err != nil || got != mx { + t.Fatalf("an mx under --mxbuild-path was refused: %v (%s)", err, got) + } + if !strings.Contains(stderr.String(), "going on because --mxbuild-path was given") { + t.Errorf("mismatch not warned about: %q", stderr.String()) + } +} + +// The mx diff behind the conflict review is held to the same check. +func TestGitMergeMx_DiffIsRefusedToo(t *testing.T) { + _, mprPath := modelConflictRepo(t) + stubMergeMx(t, "/cache/mxbuild/11.6.3/modeler/mx", "11.6.3") + var stderr bytes.Buffer + err := mxRunnersFor("", &stderr).diff(mprPath, mprPath, filepath.Join(t.TempDir(), "d.json")) + if err == nil || !strings.Contains(err.Error(), "is Mendix 11.6.3, but the project is Mendix 11.13.0") { + t.Fatalf("want the diff refused, got %v", err) + } +} + +// A project whose version cannot be read is not checked, and says so, as +// marketplace package does. +func TestGitMergeMx_UnknownProjectVersionWarns(t *testing.T) { + stubMergeMx(t, "/usr/local/bin/mx", "11.6.3") + var stderr bytes.Buffer + missing := filepath.Join(t.TempDir(), "none.mpr") + if _, err := mergeMxLookup("", &stderr)(missing); err != nil { + t.Fatalf("refused a project of unknown version: %v", err) + } + if !strings.Contains(stderr.String(), "version is unknown, so the version of /usr/local/bin/mx was not checked") { + t.Errorf("no warning for an unchecked mx: %q", stderr.String()) + } +} + +// --mxbuild-path may name the mxbuild binary itself; its mx sits beside it. +func TestPathWithin(t *testing.T) { + dir := t.TempDir() + modeler := filepath.Join(dir, "modeler") + if err := os.MkdirAll(modeler, 0o755); err != nil { + t.Fatal(err) + } + mxbuild := filepath.Join(modeler, "mxbuild") + if err := os.WriteFile(mxbuild, nil, 0o755); err != nil { + t.Fatal(err) + } + mx := filepath.Join(modeler, "mx") + if err := os.WriteFile(mx, nil, 0o755); err != nil { + t.Fatal(err) + } + for _, c := range []struct { + dir string + want bool + }{{dir, true}, {modeler, true}, {mxbuild, true}, {t.TempDir(), false}, {filepath.Join(dir, "modeler2"), false}} { + if got := pathWithin(mx, c.dir); got != c.want { + t.Errorf("pathWithin(%s, %s) = %v, want %v", mx, c.dir, got, c.want) + } + } +} diff --git a/cmd/mxcli/gitmerge_mx_version_test.go b/cmd/mxcli/gitmerge_mx_version_test.go index 8165e4459..7d1596763 100644 --- a/cmd/mxcli/gitmerge_mx_version_test.go +++ b/cmd/mxcli/gitmerge_mx_version_test.go @@ -15,8 +15,11 @@ import ( // (the project fixtures are 11.13.0), and restores the real lookup afterwards. func stubMergeMx(t *testing.T, mxPath, version string) *[]string { t.Helper() - origResolve, origVersion := resolveMxForMerge, mergeMxVersion - t.Cleanup(func() { resolveMxForMerge, mergeMxVersion = origResolve, origVersion }) + origResolve, origVersion, origLocal := resolveMxForMerge, mergeMxVersion, localMxForMerge + t.Cleanup(func() { resolveMxForMerge, mergeMxVersion, localMxForMerge = origResolve, origVersion, origLocal }) + // No exact-version install, so the lookup falls through to the resolver + // (and an mx cached on the machine running the test cannot leak in). + localMxForMerge = func(string) string { return "" } var asked []string resolveMxForMerge = func(mxbuildPath, preferred string) (string, error) { asked = append(asked, preferred) diff --git a/docs-site/src/tools/outside-studio-pro.md b/docs-site/src/tools/outside-studio-pro.md index 8c3c3b7eb..29ec342a4 100644 --- a/docs-site/src/tools/outside-studio-pro.md +++ b/docs-site/src/tools/outside-studio-pro.md @@ -259,10 +259,11 @@ chokes on the conflicted state); the engine writes its result into MINE and it is copied back, so the engine owns the `.mpr`. The engine must be the project's own Mendix release: an mx of another version (an `mx` on PATH, or the only cached download), or one whose version cannot be told, is refused -before it runs and the merge is aborted. Install the matching one with +before it runs and the merge is aborted. An installed or cached mx of the +project's release is used before an `mx` on PATH. Install the matching one with `mxcli setup mxbuild --version `, which is the usual first step on a Linux container or CI runner; `--mxbuild-path` names an mx on -purpose, and then a mismatch is only a warning: +purpose (the folder must hold one), and then a mismatch is only a warning: - what the engine auto-resolves is copied back, hash-checked, staged and committed as the normal two-parent merge commit, with the note attached. From dc09ce75af7ffb19e40d680f60ca54bee64f2115 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 09:51:39 +0000 Subject: [PATCH 04/19] fix(marketplace package): take the exact mx before PATH; --mxbuild-path must hold one (#2652) The holes #2644 closed for git merge, in marketplace package: the version check ran after ResolveMxForVersion, which tries PATH before an exact install and falls back to PATH when --mxbuild-path holds no mx. - without --mxbuild-path, packageMxPath takes docker.LocalMxForVersion (exact, never PATH) first, so another version's mx on PATH no longer blocks an export the right toolchain is installed for; - with it, an mx outside the named path is refused ("no mx in ") rather than exporting with the PATH one under the override (pathWithin, shared with git merge). The test fake now returns an mx inside --mxbuild-path and stubs the exact-version lookup, so an mx cached on the test machine cannot leak in. Tests: cmd_marketplace_package_mx_2652_test.go; with both guards disabled both fail. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QiMsnXa9crge2qnSk9S7Zn --- ...arketplace-package-mx-path-precedence.json | 1 + CHANGELOG.md | 1 + cmd/mxcli/cmd_marketplace_package.go | 48 +++++++++++++++---- .../cmd_marketplace_package_mx_2652_test.go | 46 ++++++++++++++++++ cmd/mxcli/cmd_marketplace_package_test.go | 26 ++++++++-- 5 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-marketplace-package-mx-path-precedence.json create mode 100644 cmd/mxcli/cmd_marketplace_package_mx_2652_test.go diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-marketplace-package-mx-path-precedence.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-marketplace-package-mx-path-precedence.json new file mode 100644 index 000000000..880f95899 --- /dev/null +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-marketplace-package-mx-path-precedence.json @@ -0,0 +1 @@ +{"area": "cmd/mxcli", "date": "2026-11-28", "symptom": "`mxcli marketplace package` refused to export when another Mendix version's mx was on PATH although the project's exact mx was cached (the hint said to take it off PATH), and `--mxbuild-path` naming a folder without an mx exported with the PATH mx under the override", "cause": "the version check (checkMxVersion) ran after docker.ResolveMxForVersion, which tries PATH before an exact-version install and falls back to PATH when --mxbuild-path holds no mx", "file": "cmd/mxcli/cmd_marketplace_package.go (packageMxPath)", "fix": "packageMxPath takes docker.LocalMxForVersion first without --mxbuild-path, and refuses an mx outside the named path with it (pathWithin, shared with git merge); the help text and hint say so", "insight": "same defect, same fix as git merge (ako/mxcli#2644): the version check must follow an exact-version lookup, not a preference-ordered resolver. Any other writer that checks ResolveMxForVersion's result after the fact has the hole too", "refs": ["ako/mxcli#2652", "ako/mxcli#2644"], "test": "cmd/mxcli/cmd_marketplace_package_mx_2652_test.go"} diff --git a/CHANGELOG.md b/CHANGELOG.md index 974bf7500..f455ada0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`marketplace package` uses the project's installed mx before one on PATH** (ako/mxcli#2652) — with the project's Mendix version cached and another version's `mx` on PATH, the export was refused, and the hint said to take that one off PATH. An installed or cached `mx` of the project's release now comes first. `--mxbuild-path` must name a folder that holds an `mx`: it no longer falls back to the `mx` on PATH and exports with that under the override. This is the same rule as `git merge` (#2644). - **`test --attach` no longer breaks the running app's Java class loading** (ako/mxcli#2640, upstream mendixlabs/mxcli#1973) — the attach's build rewrote `deployment/model/bundles/project.jar` under the running runtime. Any class it had not loaded yet then failed with `NoClassDefFoundError` ("ZipFile invalid LOC header"). When the rebuilt jar holds the same classes, the runtime's original jar is now put back. A build that changes the Java is refused as needing a restart. - **`test --local` next to a running `run --local --watch` no longer breaks the dev loop's next build** (ako/mxcli#2639, upstream mendixlabs/mxcli#1972) — the test run removed MxTest and its Java but left `javasource/system/UserActionsRegistrar.java` registering `mxtest.actions.RegisterTestEndpoint`. The next warm build then failed to compile, and the app served a blank page until `run restart`. Cleanup now takes that registration out too. - **A catalog build no longer hangs forever on one document** (ako/mxcli#2641, upstream mendixlabs/mxcli#1975) — `lint`, `report` and `search` could stop at "source N-1/N documents" with 0% CPU, for half an hour, when a stale `.mxcli/catalog.db` was present. A document whose describe does not finish within 2 minutes is now given up on: the build finishes without it, names the document, and writes every goroutine's stack to the session log so the blocked wait can be found. diff --git a/cmd/mxcli/cmd_marketplace_package.go b/cmd/mxcli/cmd_marketplace_package.go index 2b020b2c2..34bae70db 100644 --- a/cmd/mxcli/cmd_marketplace_package.go +++ b/cmd/mxcli/cmd_marketplace_package.go @@ -43,11 +43,13 @@ read it back. its usage and write nothing. The mx must be the Mendix version of the project: a package made by another -version than the app it comes from is refused, naming both versions. mx is taken -from, in order, an mx on PATH, a Studio Pro install and the mxbuild cache, so a -different version can be found first; 'mxcli setup mxbuild --version ' -installs the right one. --mxbuild-path is the override: with it a mismatch is -allowed, with a warning on stderr. +version than the app it comes from is refused, naming both versions. An +installed or cached mx of the project's release is taken first, before an mx on +PATH; without one, mx is taken from an mx on PATH, a Studio Pro install or the +mxbuild cache, so a different version can be found, and +'mxcli setup mxbuild --version ' installs the right one. --mxbuild-path +is the override: the folder must hold an mx, and with it a mismatch is allowed, +with a warning on stderr. mx writes into the project it is given (theme-cache/, deployment/sass/, the module's themesource/ folder), so it runs on a temporary copy; the project on @@ -143,6 +145,10 @@ var packageProjectInfo = func(mprPath string) (version string, modules []string, var resolveMxForPackage = docker.ResolveMxForVersion +// localMxForPackage finds an installed or cached mx of exactly a version, never +// one on PATH (docker.LocalMxForVersion); injected for tests. +var localMxForPackage = docker.LocalMxForVersion + // mxBinaryVersion reports the Mendix version of an mx binary, "" when unknown. var mxBinaryVersion = docker.MxBinaryVersion @@ -208,9 +214,9 @@ func runPackage(ctx context.Context, opts packageOptions, stdout, stderr io.Writ return nil, fmt.Errorf("--mxbuild-path %s: %w", opts.MxBuildPath, err) } } - mxPath, err := resolveMxForPackage(opts.MxBuildPath, version) + mxPath, err := packageMxPath(opts.MxBuildPath, version, opts.ProjectPath) if err != nil { - return nil, fmt.Errorf("locate mx for Mendix %s: %w\nhint: run 'mxcli setup mxbuild -p %s'", version, err, opts.ProjectPath) + return nil, err } mxVersion, err := checkMxVersion(mxPath, version, opts.MxBuildPath != "", stderr) if err != nil { @@ -320,6 +326,30 @@ func mxArgs(opts packageOptions, packageDir, targetMpr, module string) []string // Mendix version than the app it comes from. override is true when the user named // the mx with --mxbuild-path; then the same findings are only warned about on // stderr (which --json leaves alone). +// packageMxPath finds the mx a package is made with (ako/mxcli#2652). +// +// Without --mxbuild-path an installed or cached mx of exactly the project's +// release comes first: ResolveMxForVersion tries PATH before it, so another +// version's mx on PATH made the export refuse although the right toolchain was +// installed. With it, only an mx under that path may be used — the resolver +// falls back to PATH when the folder holds none, and the override would then +// export with an mx nobody named. The same rule as git merge (#2644). +func packageMxPath(mxbuildPath, version, projectPath string) (string, error) { + if mxbuildPath == "" && version != "" { + if exact := localMxForPackage(version); exact != "" { + return exact, nil + } + } + mxPath, err := resolveMxForPackage(mxbuildPath, version) + if err != nil { + return "", fmt.Errorf("locate mx for Mendix %s: %w\nhint: run 'mxcli setup mxbuild -p %s'", version, err, projectPath) + } + if mxbuildPath != "" && !pathWithin(mxPath, mxbuildPath) { + return "", fmt.Errorf("no mx in %s (the mx found instead, %s, was not named by --mxbuild-path)", mxbuildPath, mxPath) + } + return mxPath, nil +} + func checkMxVersion(mxPath, projectVersion string, override bool, stderr io.Writer) (string, error) { got := mxBinaryVersion(mxPath) if projectVersion == "" { @@ -340,8 +370,8 @@ func checkMxVersion(mxPath, projectVersion string, override bool, stderr io.Writ return got, nil } return "", fmt.Errorf("%s.\nA package made by another Mendix version than the app it comes from is refused.\n"+ - "hint: run 'mxcli setup mxbuild --version %s' to install the matching toolchain (an mx on PATH is used before it,\n"+ - "so take that one off PATH); to use this mx on purpose, pass --mxbuild-path", problem, projectVersion) + "hint: run 'mxcli setup mxbuild --version %s' to install the matching toolchain (an installed mx of the\n"+ + "project's release is used before one on PATH); to use this mx on purpose, pass --mxbuild-path", problem, projectVersion) } // mxDescription names the mx for the progress line: its path, and its version when known. diff --git a/cmd/mxcli/cmd_marketplace_package_mx_2652_test.go b/cmd/mxcli/cmd_marketplace_package_mx_2652_test.go new file mode 100644 index 000000000..c6153f035 --- /dev/null +++ b/cmd/mxcli/cmd_marketplace_package_mx_2652_test.go @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "strings" + "testing" +) + +// ako/mxcli#2652: the holes #2644 closed for git merge, in marketplace package. + +// An installed mx of the project's release is used before an mx on PATH. +// ResolveMxForVersion tries PATH first, so with 11.12.5 cached and 11.12.1 on +// PATH the package was refused although the right toolchain was installed. +func TestPackage_ExactInstallBeatsPath(t *testing.T) { + f := &packageFake{modules: []string{"PbxExport"}, version: "11.12.5", mxVersion: "11.12.1", + localMx: "/cache/mxbuild/11.12.5/modeler/mx", entries: pkgOwnEntries} + installPackageFake(t, f) + _, stderr, _, err := runPackageForTest(t, packageOptions{ProjectPath: pkgPlaceholderProject(t), Module: "PbxExport", OutputDir: t.TempDir()}) + if err != nil { + t.Fatalf("refused although Mendix 11.12.5's mx is installed: %v", err) + } + if f.ranMx != f.localMx { + t.Errorf("package made with %s, want the exact-version install %s", f.ranMx, f.localMx) + } + if strings.Contains(stderr, "warning") { + t.Errorf("warned about an exact match:\n%s", stderr) + } +} + +// --mxbuild-path overrides the version check only for an mx that folder holds. +// A folder without one made ResolveMxForVersion fall back to PATH, and the +// override then exported with an mx nobody named, with only a warning. +func TestPackage_MxbuildPathWithoutAnMxIsAnError(t *testing.T) { + f := &packageFake{modules: []string{"PbxExport"}, mxVersion: "11.12.1", resolveOutside: true, entries: pkgOwnEntries} + installPackageFake(t, f) + dir := t.TempDir() + _, _, _, err := runPackageForTest(t, packageOptions{ + ProjectPath: pkgPlaceholderProject(t), Module: "PbxExport", OutputDir: t.TempDir(), MxBuildPath: dir}) + if err == nil || !strings.Contains(err.Error(), "no mx in "+dir) { + t.Fatalf("want a refusal naming %s, got %v", dir, err) + } + if len(f.calls) != 0 { + t.Error("mx ran although --mxbuild-path holds none") + } +} diff --git a/cmd/mxcli/cmd_marketplace_package_test.go b/cmd/mxcli/cmd_marketplace_package_test.go index 32a3cfa0c..a4b0c1d76 100644 --- a/cmd/mxcli/cmd_marketplace_package_test.go +++ b/cmd/mxcli/cmd_marketplace_package_test.go @@ -35,13 +35,17 @@ type packageFake struct { mxVersionUnknown bool // the version of that mx cannot be told gotMxbuildPath string // the --mxbuild-path resolution was given inspectCopy func(workDir string) + + localMx string // an installed mx of exactly the project's release, "" for none (#2652) + resolveOutside bool // with --mxbuild-path, resolution falls back to an mx outside it (PATH) + ranMx string // the mx the package was made with } func installPackageFake(t *testing.T, f *packageFake) { t.Helper() - origInfo, origResolve, origMx, origVer := packageProjectInfo, resolveMxForPackage, mxCreateModulePackageCmd, mxBinaryVersion + origInfo, origResolve, origMx, origVer, origLocal := packageProjectInfo, resolveMxForPackage, mxCreateModulePackageCmd, mxBinaryVersion, localMxForPackage t.Cleanup(func() { - packageProjectInfo, resolveMxForPackage, mxCreateModulePackageCmd, mxBinaryVersion = origInfo, origResolve, origMx, origVer + packageProjectInfo, resolveMxForPackage, mxCreateModulePackageCmd, mxBinaryVersion, localMxForPackage = origInfo, origResolve, origMx, origVer, origLocal }) if f.version == "" { f.version = "11.12.5" @@ -50,18 +54,32 @@ func installPackageFake(t *testing.T, f *packageFake) { f.mxVersion = f.version } packageProjectInfo = func(string) (string, []string, error) { return f.version, f.modules, nil } + // The machine running the test may have an mx cached; only f.localMx counts. + localMxForPackage = func(version string) string { + if version == f.version { + return f.localMx + } + return "" + } resolveMxForPackage = func(mxbuildPath, version string) (string, error) { f.gotMxbuildPath = mxbuildPath f.mx = "mx-stub@" + version + if mxbuildPath != "" && !f.resolveOutside { + f.mx = filepath.Join(mxbuildPath, "modeler", "mx") // the mx the named folder holds + } return f.mx, nil } - mxBinaryVersion = func(string) string { + mxBinaryVersion = func(mxPath string) string { + if f.localMx != "" && mxPath == f.localMx { + return f.version + } if f.mxVersionUnknown { return "" } return f.mxVersion } - mxCreateModulePackageCmd = func(_ context.Context, _ string, args []string, out io.Writer) (int, error) { + mxCreateModulePackageCmd = func(_ context.Context, mxPath string, args []string, out io.Writer) (int, error) { + f.ranMx = mxPath f.calls = append(f.calls, args) if f.inspectCopy != nil { f.inspectCopy(filepath.Dir(args[len(args)-2])) // args end with From 1847a483ec767006d30c665f10e2e10ccb64c07a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:09:01 +0000 Subject: [PATCH 05/19] fix: stop writing @mxcli-layout into flow documentation (#2635) In a project with a layout-config.yaml every flow mxcli laid out gained an `@mxcli-layout: ...` line in its Documentation, even in the project style, and the next write appended it again so MDL could not remove it. The style is no longer stored in the flow. DESCRIBE reads an unmarked flow in the project style, the one create or modify rebuilds in, so derived positions are judged against what exec will do and the round trip stays exact; a flow drawn in another style prints the @position lines that keep it. A line written by an older release is honoured once and removed by the next write or `mxcli layout flows`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...28-layout-stamp-in-flow-documentation.json | 1 + .../skills/mendix/write-microflows/SKILL.md | 2 +- CHANGELOG.md | 1 + cmd/mxcli/cmd_layout_flows.go | 15 ++-- cmd/mxcli/syntax/features_microflow.go | 8 +- docs-site/src/tools/flow-layout.md | 34 +++---- mdl/executor/cmd_microflows_layout.go | 16 ++-- mdl/executor/flowlayout_config.go | 90 +++++++++---------- mdl/executor/flowlayout_config_test.go | 63 ++++++------- mdl/executor/flowlayout_describe_test.go | 48 +++++----- 10 files changed, 139 insertions(+), 139 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-28-layout-stamp-in-flow-documentation.json diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-layout-stamp-in-flow-documentation.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-layout-stamp-in-flow-documentation.json new file mode 100644 index 000000000..3a5650dc1 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-layout-stamp-in-flow-documentation.json @@ -0,0 +1 @@ +{"area": "mdl-executor", "date": "2026-11-28", "refs": ["ako/mxcli#2635", "mendixlabs/mxcli#1970"], "symptom": "In a project with layout-config.yaml every flow mxcli wrote gained an `@mxcli-layout: …` line in its Documentation — Studio Pro's documentation pane, generated docs and DESCRIBE output — even when the style was the project's; leaving it out of the doc comment did not remove it, because the write appended it again.", "file": "mdl/executor/flowlayout_config.go (resolveFlowLayout, withoutFlowLayoutMarker, describingFlowLayout), cmd_microflows_layout.go", "cause": "The style a flow was drawn in was recorded per flow in user content so DESCRIBE could judge positions against it after the project changed style.", "fix": "The marker is never written. DESCRIBE reads an unmarked flow in the project style (the one create or modify rebuilds in), so derived positions are judged against what exec will do; a flow drawn in another style prints the @position lines that keep it. A legacy marker is honoured once and removed by the next write or `layout flows`.", "insight": "Inferring the style from geometry (try project, then default) sounds free but breaks the round trip: exec has nothing to tell it the description was derived against the default, so it rebuilds in the project style. The only style DESCRIBE may treat as derivable is the one exec will use. The guard shape (flowLooksLikeGuardContinuation) had to read the project style too, or guard flows printed positions.", "test": "flowlayout_config_test.go TestWithoutFlowLayoutMarker, TestResolveFlowLayout; flowlayout_describe_test.go TestDescribeJudgesPositionsAgainstTheProjectStyle (control: project back on default prints positions). Reverting the describe fallback fails the guard case; re-adding the stamp fails 'wrote a marker'. Live 11.17.0 on the issue's repro: no line in bson, no @position, second exec unchanged; legacy marker stripped, round trip unchanged; mx check 0 errors."} diff --git a/.claude/skills/mendix/write-microflows/SKILL.md b/.claude/skills/mendix/write-microflows/SKILL.md index 7dc4303e1..3c9bd51e3 100644 --- a/.claude/skills/mendix/write-microflows/SKILL.md +++ b/.claude/skills/mendix/write-microflows/SKILL.md @@ -645,7 +645,7 @@ $var/Module.AssociationName/attribute -- Chained ### Annotation Pattern ```mdl -@position(200, 200) -- optional: omit it and mxcli lays the flow out in the project's layout-config.yaml style (never imitate a style with @position; keep, never hand-write, a `@mxcli-layout:` doc line); to re-arrange an existing flow run `mxcli layout flows`; inside a LOOP body @position is in the loop BOX's coordinates (from its top-left), not the canvas's (ako/mxcli#2564); `check` warns MDL-LOOP01 when a body looks written in canvas coordinates +@position(200, 200) -- optional: omit it and mxcli lays the flow out in the project's layout-config.yaml style (never imitate a style with @position; never write a `@mxcli-layout:` doc line — mxcli no longer stores the style in the flow and removes an old one on the next write); to re-arrange an existing flow run `mxcli layout flows`; inside a LOOP body @position is in the loop BOX's coordinates (from its top-left), not the canvas's (ako/mxcli#2564); `check` warns MDL-LOOP01 when a body looks written in canvas coordinates @caption 'Persist order' @color Green @annotation 'Note about the next activity' diff --git a/CHANGELOG.md b/CHANGELOG.md index 102762cff..b01a01e18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **`mxcli layout` puts each entity on the row of the entity it is most linked to, and sizes each column gap to its association names** — before, every column was stacked from the top on its own, so most lines ran diagonally, and a fixed 90 px gap cut off any association name over ~10 characters in Studio Pro. On ako/PizzaV1's Catalog, Fulfilment, Shop and PizzaChat modules every horizontal line now has room for its label (16 of 16, against 1 of 16), and more lines run straight across; diagrams with long association names are wider. Phase 1 of `PROPOSAL_domain_model_readable_layout.md`. ### Fixed +- **mxcli no longer writes `@mxcli-layout:` into a flow's documentation** (ako/mxcli#2635, upstream mendixlabs/mxcli#1970) — in a project with a `layout-config.yaml`, every flow mxcli laid out gained an `@mxcli-layout: …` line in its Documentation, even when its style was the project's. Studio Pro showed it, generated documentation copied it, and it could not be removed through MDL, because the next write appended it again. The style is now never stored in the flow: `describe` judges positions against the project style, the one `create or modify` rebuilds in, so a round trip stays exact. A flow drawn in another style prints the `@position` lines that keep it. A line written by an older release is honoured once and then removed by the next write of the flow or by `mxcli layout flows`. - **`test --attach` no longer breaks the running app's Java class loading** (ako/mxcli#2640, upstream mendixlabs/mxcli#1973) — the attach's build rewrote `deployment/model/bundles/project.jar` under the running runtime. Any class it had not loaded yet then failed with `NoClassDefFoundError` ("ZipFile invalid LOC header"). When the rebuilt jar holds the same classes, the runtime's original jar is now put back. A build that changes the Java is refused as needing a restart. - **`test --local` next to a running `run --local --watch` no longer breaks the dev loop's next build** (ako/mxcli#2639, upstream mendixlabs/mxcli#1972) — the test run removed MxTest and its Java but left `javasource/system/UserActionsRegistrar.java` registering `mxtest.actions.RegisterTestEndpoint`. The next warm build then failed to compile, and the app served a blank page until `run restart`. Cleanup now takes that registration out too. - **A catalog build no longer hangs forever on one document** (ako/mxcli#2641, upstream mendixlabs/mxcli#1975) — `lint`, `report` and `search` could stop at "source N-1/N documents" with 0% CPU, for half an hour, when a stale `.mxcli/catalog.db` was present. A document whose describe does not finish within 2 minutes is now given up on: the build finishes without it, names the document, and writes every goroutine's stack to the session log so the blocked wait can be found. diff --git a/cmd/mxcli/cmd_layout_flows.go b/cmd/mxcli/cmd_layout_flows.go index fca3f92bc..2816b29ae 100644 --- a/cmd/mxcli/cmd_layout_flows.go +++ b/cmd/mxcli/cmd_layout_flows.go @@ -38,15 +38,14 @@ out every microflow and nanoflow in a module. Positions change: activity and event positions and sizes, parameter positions, and the anchors and curves of sequence flows. Content, element IDs and everything else about the flow are left exactly as stored, apart from -the one documentation line described next. +an '@mxcli-layout:' documentation line, which releases before ako/mxcli#2635 +wrote and this command removes. The style is the project's layout-config.yaml (in .claude/ or next to the .mpr; see 'mxcli layout config'), or the default when there is none. --style -lays out in a preset instead, to try one. Each flow laid out in a style other -than the default records it as an '@mxcli-layout:' line in its documentation, -which DESCRIBE and CREATE OR MODIFY then keep using for that flow; laying it out -in the default removes the line. That line is the one thing besides positions -this command writes. +lays out in a preset instead, to try one. Nothing records the style in the +flow: DESCRIBE and CREATE OR MODIFY use the project's, so a flow laid out with +--style in another one describes with the positions that style chose. A flow whose description does not rebuild into the same graph — something MDL cannot yet express — is skipped with the reason, never laid out by guesswork. @@ -258,9 +257,9 @@ func layoutFlowTargets(out io.Writer, exec *executor.Executor, targets []flowTar fmt.Fprintf(out, "%s: moved %d of %d objects, re-anchored %d flows\n", res.Name, res.Moved, res.Objects, res.Flows) } if res.Restyled && res.Refused == "" { - verb := "updates" + verb := "removes" if layoutDryRun { - verb = "would update" + verb = "would remove" } fmt.Fprintf(out, "%s: %s the %s line in its documentation\n", res.Name, verb, "@mxcli-layout:") } diff --git a/cmd/mxcli/syntax/features_microflow.go b/cmd/mxcli/syntax/features_microflow.go index 9333eec79..8bcdae00b 100644 --- a/cmd/mxcli/syntax/features_microflow.go +++ b/cmd/mxcli/syntax/features_microflow.go @@ -1128,9 +1128,11 @@ func init() { " case-split: first-right-rest-columns\n" + " guard: true-right # early return on the line\n" + " wrap: off # or max-row-width: \n" + - "`mxcli layout config` shows the style in force. A flow drawn in a non-default\n" + - "style carries a `@mxcli-layout: …` line in its /** … */ documentation: keep\n" + - "it when copying a described flow, never write one by hand. (ako/mxcli#1832)", + "`mxcli layout config` shows the style in force. Nothing about the style is\n" + + "stored in the flow: DESCRIBE judges positions against the project style, and a\n" + + "flow drawn in another prints the @position lines that keep it. An\n" + + "`@mxcli-layout: …` documentation line from an older release is honoured once and\n" + + "removed on the next write; never write one. (ako/mxcli#1832, #2635)", Example: "create microflow MyModule.ACT_Flow (\n @position(145, 0)\n $In: String\n)\nreturns String as $Out\nbegin\n" + " @start(145, 100)\n @position(200, 100)\n @anchor(from: bottom)\n" + " @curve(from: (40, -90), to: (-40, 90))\n declare $Tmp String = $In;\n" + diff --git a/docs-site/src/tools/flow-layout.md b/docs-site/src/tools/flow-layout.md index 16cd48756..2eb0844f0 100644 --- a/docs-site/src/tools/flow-layout.md +++ b/docs-site/src/tools/flow-layout.md @@ -65,21 +65,21 @@ To try a style without committing it, pass `--style`: mxcli layout flows -p app.mpr --module Sales --style true-right-false-down --dry-run ``` -### The style a flow was drawn in travels with it - -A flow laid out in a style other than the default gets one line at the end of -its documentation, which Studio Pro shows in the documentation pane: - -``` -@mxcli-layout: if-else=true-right-else-column -``` - -`DESCRIBE` and `CREATE OR MODIFY` use that line for that flow, whatever the -project file says now. So a flow drawn in one style describes without `@position` -noise after the project switches to another, and its description rebuilds the -same geometry. Laying a flow out in the default style removes the line. If the -line is deleted or unreadable, nothing breaks: `DESCRIBE` then prints the -positions it can no longer derive, and a warning says why. +### The style lives in the project, not in the flow + +mxcli writes nothing about the style into a flow. `DESCRIBE` judges which +positions are derived against the project's style — the one `CREATE OR MODIFY` +rebuilds the description in — so a describe → exec round trip is exact. A flow +drawn in another style (in Studio Pro, with `--style`, or before the project +changed its file) describes with the `@position` lines of the places that +style chose, and executing that description puts them back. + +Releases before ako/mxcli#2635 recorded a non-default style as an +`@mxcli-layout: …` line at the end of the flow's documentation. A flow that +still carries one is read as before — described and rebuilt in the style it +records — and the next write of that flow, or `mxcli layout flows`, removes the +line. Deleting it in Studio Pro is also fine: the flow then describes with the +positions the project style would not derive. ## What changes @@ -90,8 +90,8 @@ nothing but layout changes: - positions of parameters and notes (a note keeps its size); - the connection sides and curves of sequence flows. -- the `@mxcli-layout:` line in the flow's documentation (above) — the rest of - the documentation is left byte for byte. +- an `@mxcli-layout:` line an older release left in the flow's documentation + (above) is removed — the rest of the documentation is left byte for byte. Element IDs, captions, expressions and every property MDL cannot express are left exactly as stored. That is also why this works on flows drawn in Studio diff --git a/mdl/executor/cmd_microflows_layout.go b/mdl/executor/cmd_microflows_layout.go index 9298ba9b0..e5b7f7561 100644 --- a/mdl/executor/cmd_microflows_layout.go +++ b/mdl/executor/cmd_microflows_layout.go @@ -50,8 +50,8 @@ type FlowLayoutResult struct { Objects int // objects in the flow Moved int // objects whose position or size changed Flows int // sequence flows whose anchors or curve changed - // Restyled says the flow's @mxcli-layout documentation line changed: it is - // now laid out in a different style than the one it recorded. + // Restyled says an @mxcli-layout documentation line an older release wrote + // was removed (ako/mxcli#2635). Restyled bool Refused string // why the flow was left alone; empty when it was laid out } @@ -141,14 +141,10 @@ func layoutFlow(ctx *ExecContext, kind string, name ast.QualifiedName, dryRun bo } patched := plan.apply(doc) res.Moved, res.Flows = plan.movedObjects, plan.changedFlows - // The flow now records the style it was laid out in (flowlayout_config.go). - // Only the marker line changes; the rest of the documentation is the stored - // text, not the description's normal form of it. - style, err := ctx.ProjectFlowLayout() - if err != nil { - return res, fmt.Errorf("layout config: %w", err) - } - res.Restyled = setLayoutString(patched, "Documentation", withFlowLayoutMarker(stored.documentation, *style)) + // A marker line an older release wrote goes (flowlayout_config.go). Only that + // line changes; the rest of the documentation is the stored text, not the + // description's normal form of it. + res.Restyled = setLayoutString(patched, "Documentation", withoutFlowLayoutMarker(stored.documentation)) if !res.Changed() || dryRun { return res, nil } diff --git a/mdl/executor/flowlayout_config.go b/mdl/executor/flowlayout_config.go index 18949fd80..b8eca2102 100644 --- a/mdl/executor/flowlayout_config.go +++ b/mdl/executor/flowlayout_config.go @@ -2,19 +2,20 @@ // Package executor - where a flow's layout style comes from. // -// Two places, in this order (ako/mxcli#1832): +// The project's committed layout-config.yaml, looked up the way lint-config.yaml +// is; no file is the default style. A canonical DESCRIBE judges a position +// "derived" against that same style, because it is the style `create or modify` +// rebuilds the description in — so a describe → exec round trip is exact. // -// 1. The flow's own documentation, when it carries an `@mxcli-layout:` line. -// That line records the style the flow was last laid out with, so a -// describe → exec round trip rebuilds the same geometry whatever the project -// says now, and canonical DESCRIBE judges a position "derived" against the -// style that actually drew it. -// 2. Otherwise the project's committed layout-config.yaml, looked up the way -// lint-config.yaml is. No file is the default style. -// -// A flow laid out under a style other than the default gets the line; under the -// default it loses it. So a project with no config file writes exactly what it -// always wrote. +// Nothing about the style is stored in the flow (ako/mxcli#2635). Until then a +// flow laid out in a style other than the default carried an `@mxcli-layout:` +// line in its Documentation, which is the modeler's text: Studio Pro shows it and +// generated documentation copies it. A flow that still carries one is read as +// before — DESCRIBE and the next write lay it out in the style it records — and +// that write removes the line, so a project sheds them as its flows are +// rewritten. A flow drawn in a style other than the project's now describes with +// the positions that style put where the project's would not; the round trip +// stays exact, only louder. package executor import ( @@ -39,9 +40,10 @@ const ( maxRowWidthLimit = 20000 ) -// flowLayoutMarker starts the documentation line that records a flow's style. -// It is plain documentation text: the visitor keeps it inside `/** … */` -// verbatim and never reads it as an annotation. +// flowLayoutMarker starts the documentation line older releases wrote to record a +// flow's style. It is plain documentation text: the visitor keeps it inside +// `/** … */` verbatim and never reads it as an annotation. mxcli reads it and +// removes it, and never writes it (ako/mxcli#2635). const flowLayoutMarker = "@mxcli-layout:" // flowLayoutConfigName is the project file holding the layout style. @@ -291,34 +293,20 @@ func flowLayoutFromDocumentation(doc string) (l flowLayout, found bool, err erro return flowLayout{}, false, nil } -// withFlowLayoutMarker returns doc with its marker line set for l: any marker -// line is removed, and one is appended for a style other than the default. The -// rest of the documentation is kept byte for byte; only blank lines the removed -// marker leaves at the end go with it. -func withFlowLayoutMarker(doc string, l flowLayout) string { - _, found, _ := flowLayoutFromDocumentation(doc) - value := l.markerValue() - if !found && value == "" { +// withoutFlowLayoutMarker returns doc without its marker line. Documentation +// with none is returned byte for byte; otherwise only the marker line goes, with +// the blank lines it leaves at the end. +func withoutFlowLayoutMarker(doc string) string { + if _, found, _ := flowLayoutFromDocumentation(doc); !found { return doc } - out := doc - if found { - var kept []string - for line := range strings.SplitSeq(doc, "\n") { - if !isFlowLayoutMarkerLine(line) { - kept = append(kept, line) - } + var kept []string + for line := range strings.SplitSeq(doc, "\n") { + if !isFlowLayoutMarkerLine(line) { + kept = append(kept, line) } - out = strings.TrimRight(strings.Join(kept, "\n"), "\r\n\t ") - } - if value == "" { - return out - } - line := flowLayoutMarker + " " + value - if out == "" { - return line } - return out + "\n" + line + return strings.TrimRight(strings.Join(kept, "\n"), "\r\n\t ") } // ProjectFlowLayout returns the style new flows are laid out with: the @@ -344,9 +332,10 @@ func (ctx *ExecContext) ProjectFlowLayout() (*flowLayout, error) { } // resolveFlowLayout decides the style a flow is built with from its final -// documentation, and returns the documentation with the marker set for that -// style. A marked flow keeps its recorded style; an unmarked one gets the -// project's. A marker that does not parse is warned about and treated as absent. +// documentation, and returns the documentation without a marker line. A flow +// that still carries one (written by an older release) is built in the style it +// records, once — the line goes with this write; any other gets the project's. +// A marker that does not parse is warned about and treated as absent. // // keepRecorded false ignores the marker: `mxcli layout flows` re-lays a flow out // in the project style (or --style), which is the point of running it. @@ -354,7 +343,7 @@ func resolveFlowLayout(ctx *ExecContext, doc string, keepRecorded bool) (*flowLa if keepRecorded { l, found, err := flowLayoutFromDocumentation(doc) if found && err == nil { - return &l, withFlowLayoutMarker(doc, l), nil + return &l, withoutFlowLayoutMarker(doc), nil } if found && err != nil && ctx != nil && ctx.Output != nil { fmt.Fprintf(ctx.Output, "Warning: ignoring the flow's %s line: %v\n", flowLayoutMarker, err) @@ -364,13 +353,16 @@ func resolveFlowLayout(ctx *ExecContext, doc string, keepRecorded bool) (*flowLa if err != nil { return nil, doc, fmt.Errorf("layout config: %w", err) } - return l, withFlowLayoutMarker(doc, *l), nil + return l, withoutFlowLayoutMarker(doc), nil } -// describingFlowLayout records, for the description of one flow, the style its -// documentation says it was laid out in, and returns the function that restores -// what was recorded before. The describer reads a shape only that style draws -// as the statement that drew it (flowLooksLikeGuardContinuation). +// describingFlowLayout records, for the description of one flow, the style it +// is read in, and returns the function that restores what was recorded before: +// the style a marker line records, else the project's — the one `create or +// modify` rebuilds the description in. The describer reads a shape only that +// style draws as the statement that drew it (flowLooksLikeGuardContinuation). +// A project config that does not load reads as the default; the build reports +// it. func (ctx *ExecContext) describingFlowLayout(doc string) func() { if ctx == nil { return func() {} @@ -379,6 +371,8 @@ func (ctx *ExecContext) describingFlowLayout(doc string) func() { ctx.describedFlowLayout = nil if l, found, err := flowLayoutFromDocumentation(doc); found && err == nil { ctx.describedFlowLayout = &l + } else if l, err := ctx.ProjectFlowLayout(); err == nil && l != nil { + ctx.describedFlowLayout = l } return func() { ctx.describedFlowLayout = prev } } diff --git a/mdl/executor/flowlayout_config_test.go b/mdl/executor/flowlayout_config_test.go index 6cc288ae7..35b0aefb7 100644 --- a/mdl/executor/flowlayout_config_test.go +++ b/mdl/executor/flowlayout_config_test.go @@ -71,38 +71,27 @@ func TestFindFlowLayoutConfig_PrefersClaudeDir(t *testing.T) { } } -func TestFlowLayoutMarker(t *testing.T) { - column := flowLayout{IfElse: IfElseColumn} +// ako/mxcli#2635: the style is never written into the flow's documentation; a +// line an older release wrote is removed, and the rest kept byte for byte. +func TestWithoutFlowLayoutMarker(t *testing.T) { const line = "@mxcli-layout: if-else=true-right-else-column" - - for _, c := range []struct { - name string - doc string - layout flowLayout - want string - }{ - {"default leaves undocumented flow alone", "", flowLayout{}, ""}, - {"default leaves documentation byte for byte", "Submits.\r\n trailing ", flowLayout{}, "Submits.\r\n trailing "}, - {"style on an undocumented flow", "", column, line}, - {"style appended", "Submits the order.", column, "Submits the order.\n" + line}, - {"style replaced, not duplicated", "Submits.\n" + line, column, "Submits.\n" + line}, - {"older marker replaced", "Submits.\n@mxcli-layout: if-else=lanes", column, "Submits.\n" + line}, - {"default removes the marker", "Submits.\n" + line, flowLayout{}, "Submits."}, - {"default removes a lone marker", line, flowLayout{}, ""}, + for _, c := range []struct{ name, doc, want string }{ + {"undocumented flow", "", ""}, + {"documentation byte for byte", "Submits.\r\n trailing ", "Submits.\r\n trailing "}, + {"marker removed", "Submits.\n" + line, "Submits."}, + {"lone marker removed", line, ""}, + {"marker in the middle", "Submits.\n" + line + "\nThen returns.", "Submits.\nThen returns."}, } { t.Run(c.name, func(t *testing.T) { - got := withFlowLayoutMarker(c.doc, c.layout) + got := withoutFlowLayoutMarker(c.doc) if got != c.want { t.Fatalf("got %q, want %q", got, c.want) } - // What is written reads back as the style it records. - back, found, err := flowLayoutFromDocumentation(got) - if err != nil || back != c.layout || found != (c.layout != flowLayout{}) { - t.Fatalf("read back %+v found=%v err=%v, want %+v", back, found, err, c.layout) + if _, found, _ := flowLayoutFromDocumentation(got); found { + t.Fatalf("%q still has a marker", got) } - // Writing it again changes nothing (ADR-0008). - if again := withFlowLayoutMarker(got, c.layout); again != got { - t.Fatalf("second write %q differs from first %q", again, got) + if again := withoutFlowLayoutMarker(got); again != got { + t.Fatalf("second pass %q differs from first %q", again, got) } }) } @@ -113,17 +102,18 @@ func TestResolveFlowLayout(t *testing.T) { writeLayoutConfig(t, dir, "flows:\n preset: true-right-false-down\n") ctx := &ExecContext{MprPath: filepath.Join(dir, "app.mpr"), Output: &strings.Builder{}} - // Unmarked flow: the project's style, and the marker is written. + // Unmarked flow: the project's style, and the documentation is left alone + // (ako/mxcli#2635 — it used to gain a marker line). l, doc, err := resolveFlowLayout(ctx, "Submits.", true) - if err != nil || l.IfElse != IfElseColumn || !strings.HasSuffix(doc, "if-else=true-right-else-column") { + if err != nil || l.IfElse != IfElseColumn || doc != "Submits." { t.Fatalf("unmarked: %+v %q %v", l, doc, err) } - // A flow recording the default (no line can say so) is unmarked; one recording - // a style keeps it whatever the project says. + // A flow an older release marked is built in the style it records, once: the + // line goes with this write, whatever the project says. ctx2 := &ExecContext{MprPath: filepath.Join(t.TempDir(), "app.mpr"), Output: &strings.Builder{}} l, doc, err = resolveFlowLayout(ctx2, "Submits.\n@mxcli-layout: if-else=true-right-else-column", true) - if err != nil || l.IfElse != IfElseColumn || !strings.Contains(doc, flowLayoutMarker) { + if err != nil || l.IfElse != IfElseColumn || doc != "Submits." { t.Fatalf("recorded style in a default project: %+v %q %v", l, doc, err) } @@ -141,6 +131,19 @@ func TestResolveFlowLayout(t *testing.T) { t.Fatalf("bad marker: %+v %q %v, output %q", l, doc, err, out.String()) } + // DESCRIBE reads an unmarked flow in the project's style — the one create or + // modify rebuilds it in — and a marked one in the style it records. + restore := ctx.describingFlowLayout("Submits.") + if ctx.describedFlowLayout == nil || ctx.describedFlowLayout.IfElse != IfElseColumn { + t.Fatalf("unmarked flow described in %+v, want the project style", ctx.describedFlowLayout) + } + restore() + restore = ctx2.describingFlowLayout("Submits.\n@mxcli-layout: case-split=first-right-rest-columns") + if ctx2.describedFlowLayout == nil || ctx2.describedFlowLayout.CaseSplit != CaseSplitColumns { + t.Fatalf("marked flow described in %+v, want the recorded style", ctx2.describedFlowLayout) + } + restore() + // A broken project config is an error, not a silent default. bad := t.TempDir() writeLayoutConfig(t, bad, "flows:\n preset: zigzag\n") diff --git a/mdl/executor/flowlayout_describe_test.go b/mdl/executor/flowlayout_describe_test.go index cded7f250..10e1758ce 100644 --- a/mdl/executor/flowlayout_describe_test.go +++ b/mdl/executor/flowlayout_describe_test.go @@ -8,10 +8,11 @@ import ( "testing" ) -// ako/mxcli#1832: a flow laid out in a style records it, and a canonical -// DESCRIBE judges its positions against that style — whatever style the project -// is in when it is described. With the record gone the same description keeps -// every position it can no longer derive, which is the control. +// ako/mxcli#1832, #2635: a canonical DESCRIBE judges a flow's positions against +// the project's style, the one `create or modify` rebuilds the description in. +// Nothing is written into the flow's documentation. Described after the project +// moves to another style, the same flow keeps every position that style would +// not derive, which is the control. const styledFlowsMDL = ` create microflow MyFirstModule.ACT_Styled ($N: Integer) returns Boolean @@ -50,7 +51,7 @@ begin end; ` -func TestDescribeUsesTheRecordedLayoutStyle(t *testing.T) { +func TestDescribeJudgesPositionsAgainstTheProjectStyle(t *testing.T) { for _, preset := range []string{"true-right-false-down"} { for _, guard := range []bool{false, true} { style := preset @@ -68,17 +69,24 @@ func TestDescribeUsesTheRecordedLayoutStyle(t *testing.T) { exec.flowLayoutOverride = &l } run(t, exec, styledFlowsMDL) - // The project is back on the default style; the flows record theirs. - if err := exec.SetFlowLayoutStyle(""); err != nil { - t.Fatal(err) - } - for _, d := range []string{"describe microflow MyFirstModule.ACT_Styled", "describe nanoflow MyFirstModule.NAV_Styled"} { + describes := []string{"describe microflow MyFirstModule.ACT_Styled", "describe nanoflow MyFirstModule.NAV_Styled"} + for _, d := range describes { mdl := describeText(t, exec, out, d) - if !strings.Contains(mdl, flowLayoutMarker) { - t.Fatalf("%s: no %s line:\n%s", d, flowLayoutMarker, mdl) + if strings.Contains(mdl, flowLayoutMarker) { + t.Fatalf("%s: wrote a %s line:\n%s", d, flowLayoutMarker, mdl) } if got := layoutLines(mdl); len(got) > 0 { - t.Errorf("%s printed layout annotations under the recorded style: %v\n%s", d, got, mdl) + t.Errorf("%s printed layout annotations under the project style: %v\n%s", d, got, mdl) + } + } + // Control: in a project on the default style the same flows are + // not derivable, so their positions are printed. + if err := exec.SetFlowLayoutStyle(""); err != nil { + t.Fatal(err) + } + for _, d := range describes { + if got := layoutLines(describeText(t, exec, out, d)); len(got) == 0 { + t.Errorf("%s: no layout annotations under a style that did not draw it", d) } } }) @@ -127,12 +135,9 @@ func TestDescribeKeepsCaseOrderInCaseColumns(t *testing.T) { t.Fatal(err) } run(t, exec, styledCaseSplitsMDL) - if err := exec.SetFlowLayoutStyle(""); err != nil { - t.Fatal(err) - } mdl := describeText(t, exec, out, "describe microflow MyFirstModule.ACT_Cases") if got := layoutLines(mdl); len(got) > 0 { - t.Errorf("printed layout annotations under the recorded style: %v\n%s", got, mdl) + t.Errorf("printed layout annotations under the project style: %v\n%s", got, mdl) } // The cases come back in the order they were written, not the order a // column's sides would sort them in. @@ -146,7 +151,7 @@ func TestDescribeKeepsCaseOrderInCaseColumns(t *testing.T) { } } -func TestDescribeUsesTheRecordedWrap(t *testing.T) { +func TestDescribeJudgesWrapAgainstTheProjectStyle(t *testing.T) { var body strings.Builder for i := 0; i < 30; i++ { fmt.Fprintf(&body, " log info 'step %d';\n", i) @@ -158,13 +163,12 @@ func TestDescribeUsesTheRecordedWrap(t *testing.T) { style := l exec.flowLayoutOverride = &style run(t, exec, mdl) - exec.flowLayoutOverride = nil got := describeText(t, exec, out, "describe microflow MyFirstModule.ACT_Long") - if l.markerValue() != "" && !strings.Contains(got, flowLayoutMarker+" "+l.markerValue()) { - t.Fatalf("no marker for %s:\n%s", l, got) + if strings.Contains(got, flowLayoutMarker) { + t.Fatalf("wrote a marker for %s:\n%s", l, got) } if lines := layoutLines(got); len(lines) > 0 { - t.Errorf("printed layout annotations under the recorded style: %v", lines) + t.Errorf("printed layout annotations under the project style: %v", lines) } }) } From f6bf16f7613885899040f68dcb1b8607b59a1007 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:11:31 +0000 Subject: [PATCH 06/19] check: reject a split type the build rejects (CE0090/CE0774/CE0771, MDL109) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82tETa46YQmMS58pQjL --- ...it-type-branches-ce0090-ce0774-ce0771.json | 1 + CHANGELOG.md | 1 + cmd/mxcli/syntax/features_microflow.go | 6 +- .../bug-tests/split-type-branches.mdl | 46 +++++ .../split-type-invalid-branches.fail.mdl | 60 ++++++ mdl/ast/ast_microflow.go | 5 +- mdl/executor/validate_inheritance_splits.go | 187 ++++++++++++++++++ .../validate_inheritance_splits_test.go | 171 ++++++++++++++++ mdl/executor/validate_microflow.go | 2 +- mdl/executor/validate_program.go | 2 + 10 files changed, 476 insertions(+), 5 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-28-split-type-branches-ce0090-ce0774-ce0771.json create mode 100644 mdl-examples/bug-tests/split-type-branches.mdl create mode 100644 mdl-examples/bug-tests/split-type-invalid-branches.fail.mdl create mode 100644 mdl/executor/validate_inheritance_splits.go create mode 100644 mdl/executor/validate_inheritance_splits_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-split-type-branches-ce0090-ce0774-ce0771.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-split-type-branches-ce0090-ce0774-ce0771.json new file mode 100644 index 000000000..c97550247 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-split-type-branches-ce0090-ce0774-ce0771.json @@ -0,0 +1 @@ +{"area": "mdl/executor", "date": "2026-11-28", "refs": ["ako/mxcli#1258"], "ce": ["CE0090", "CE0774", "CE0771", "CE0089"], "symptom": "A `split type $V` with no branch for $V's own entity (CE0090), a branch on an entity that is not that entity or a specialization of it (CE0774: an unrelated entity, the subject's generalization, a sibling) or the same entity twice (CE0771) passed `check` and `exec`; `mx check` rejected the microflow.", "file": "mdl/executor/validate_inheritance_splits.go ValidateInheritanceSplits (MDL109), wired in validate_program.go with the lazy project opener. Tests validate_inheritance_splits_test.go; fixtures mdl-examples/bug-tests/split-type-invalid-branches.fail.mdl and split-type-branches.mdl", "cause": "Only the spelling of the split was checked (MDL065). The builder emits the (empty) flow unconditionally, so CE0089 — the code this started from — cannot be produced by MDL, and nothing judged which entities the branches name.", "insight": "**The code in the coverage list was unreachable; its siblings were not, and the old records described an older build.** CE0089 is the missing (empty) flow, which the builder always adds. The 11.13.0 records said every subtype needs a branch; re-measured on 11.16.1, a missing subtype (direct or deeper) builds clean and only the subject's own entity is required, so reporting missing subtypes would have been a false error on every partial split, and the help text, an AST comment and the MDL065 message were corrected. The subject's entity is taken from the flow's parameters and its retrieve-first or create results only; the branch entity's chain from the script, then the project, and an incomplete chain is never read as unrelated."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 974bf7500..3cb310490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`check` rejects a `split type` the build rejects** (ako/mxcli#1258) — a split with no branch for its subject's own entity (CE0090), a branch on an entity that is not that entity or a specialization of it (CE0774), or the same entity twice (CE0771) passed `check` and `exec`. New MDL109; the hierarchy is read from the script, then the project, and a subject or chain it cannot read is not judged. Measured on MxBuild 11.16.1: a subtype left out builds clean, so it is not reported, and the help text that said every subtype needs a branch is corrected. CE0089 (no `(empty)` flow) cannot be produced by MDL, because the builder always adds it. - **`test --attach` no longer breaks the running app's Java class loading** (ako/mxcli#2640, upstream mendixlabs/mxcli#1973) — the attach's build rewrote `deployment/model/bundles/project.jar` under the running runtime. Any class it had not loaded yet then failed with `NoClassDefFoundError` ("ZipFile invalid LOC header"). When the rebuilt jar holds the same classes, the runtime's original jar is now put back. A build that changes the Java is refused as needing a restart. - **`test --local` next to a running `run --local --watch` no longer breaks the dev loop's next build** (ako/mxcli#2639, upstream mendixlabs/mxcli#1972) — the test run removed MxTest and its Java but left `javasource/system/UserActionsRegistrar.java` registering `mxtest.actions.RegisterTestEndpoint`. The next warm build then failed to compile, and the app served a blank page until `run restart`. Cleanup now takes that registration out too. - **A catalog build no longer hangs forever on one document** (ako/mxcli#2641, upstream mendixlabs/mxcli#1975) — `lint`, `report` and `search` could stop at "source N-1/N documents" with 0% CPU, for half an hour, when a stale `.mxcli/catalog.db` was present. A document whose describe does not finish within 2 minutes is now given up on: the build finishes without it, names the document, and writes every goroutine's stack to the session log so the blocked wait can be found. diff --git a/cmd/mxcli/syntax/features_microflow.go b/cmd/mxcli/syntax/features_microflow.go index 9333eec79..7e93c5036 100644 --- a/cmd/mxcli/syntax/features_microflow.go +++ b/cmd/mxcli/syntax/features_microflow.go @@ -307,8 +307,10 @@ func init() { " WHEN (empty) THEN -- the NULL-object branch, not a default\n" + " ...\n" + "END SPLIT;\n\n" + - "Both take `WHEN ... THEN` branches. `SPLIT TYPE` needs one per subtype AND\n" + - "the base entity; its `(empty)` branch is the null object and covers no type.\n" + + "Both take `WHEN ... THEN` branches. `SPLIT TYPE` needs a branch for the\n" + + "subject's own entity (CE0090); a subtype may be left out (MxBuild 11.16.1).\n" + + "Branch only on that entity or a specialization (CE0774), each once (CE0771):\n" + + "check reports all three as MDL109. The `(empty)` branch is the null object.\n" + "Legacy `CASE Module.Entity` / `ELSE` inside SPLIT TYPE still parse (MDL065).", Example: "CASE $Order/Status\n WHEN Draft, Submitted THEN\n LOG INFO 'Not shipped yet';\n WHEN Approved THEN\n LOG INFO 'Ready to ship';\n WHEN (empty) THEN\n LOG INFO 'No status';\nEND CASE;\n\nSPLIT TYPE $Animal\n WHEN Zoo.Dog THEN\n LOG INFO 'woof';\n WHEN Zoo.Cat THEN\n LOG INFO 'meow';\n WHEN Zoo.Animal THEN\n LOG INFO 'some other animal';\n WHEN (empty) THEN\n LOG INFO 'no animal at all';\nEND SPLIT;", SeeAlso: []string{"microflow.control-flow", "microflow.variables"}, diff --git a/mdl-examples/bug-tests/split-type-branches.mdl b/mdl-examples/bug-tests/split-type-branches.mdl new file mode 100644 index 000000000..344ab27e7 --- /dev/null +++ b/mdl-examples/bug-tests/split-type-branches.mdl @@ -0,0 +1,46 @@ +mdl 1; +-- CONTROL for split-type-invalid-branches.fail.mdl: `split type` shapes MxBuild 11.16.1 +-- builds clean. A subtype may be left out; only the subject's own entity is required. +create persistent entity MyFirstModule.StAnimal (Name: string(50)); +create persistent entity MyFirstModule.StDog extends MyFirstModule.StAnimal (Bark: string(50)); +create persistent entity MyFirstModule.StCat extends MyFirstModule.StAnimal (Meow: string(50)); +create persistent entity MyFirstModule.StOther (X: string(5)); +create microflow MyFirstModule.StAll ($A: MyFirstModule.StAnimal) returns boolean begin + @start(100, 200) + @position(400, 200) + split type $A + when MyFirstModule.StDog then + log info node 'n' 'StDog'; + when MyFirstModule.StCat then + log info node 'n' 'StCat'; + when MyFirstModule.StAnimal then + log info node 'n' 'StAnimal'; + when (empty) then + log info node 'n' 'none'; + end split; + return true; +end; +create microflow MyFirstModule.StSubtypeLeftOut ($A: MyFirstModule.StAnimal) returns boolean begin + @start(100, 200) + @position(400, 200) + split type $A + when MyFirstModule.StDog then + log info node 'n' 'StDog'; + when MyFirstModule.StAnimal then + log info node 'n' 'StAnimal'; + when (empty) then + log info node 'n' 'none'; + end split; + return true; +end; +create microflow MyFirstModule.StDogSubject ($A: MyFirstModule.StDog) returns boolean begin + @start(100, 200) + @position(400, 200) + split type $A + when MyFirstModule.StDog then + log info node 'n' 'StDog'; + when (empty) then + log info node 'n' 'none'; + end split; + return true; +end; diff --git a/mdl-examples/bug-tests/split-type-invalid-branches.fail.mdl b/mdl-examples/bug-tests/split-type-invalid-branches.fail.mdl new file mode 100644 index 000000000..eec6185ac --- /dev/null +++ b/mdl-examples/bug-tests/split-type-invalid-branches.fail.mdl @@ -0,0 +1,60 @@ +mdl 1; +-- NEGATIVE TEST — `mxcli check` must REFUSE this file (MDL109), with no project. +-- +-- A `split type` the build rejects. `check` and `exec` accepted all three and the +-- build reported, one per microflow: +-- +-- [CE0090] "The 'MyFirstModule.StAnimal' value should be configured for an outgoing flow." +-- [CE0774] "Value is not entity 'MyFirstModule.StAnimal' or a specialization." +-- [CE0771] "Value is already handled by another sequence flow." +-- +-- Measured on MxBuild 11.16.1. Only the subject's own entity needs a branch: a missing +-- subtype builds clean (see split-type-branches.mdl), and the `(empty)` branch is the null +-- object, not a default. +create persistent entity MyFirstModule.StAnimal (Name: string(50)); +create persistent entity MyFirstModule.StDog extends MyFirstModule.StAnimal (Bark: string(50)); +create persistent entity MyFirstModule.StCat extends MyFirstModule.StAnimal (Meow: string(50)); +create persistent entity MyFirstModule.StOther (X: string(5)); +create microflow MyFirstModule.StNoBase ($A: MyFirstModule.StAnimal) returns boolean begin + @start(100, 200) + @position(400, 200) + split type $A + when MyFirstModule.StDog then + log info node 'n' 'StDog'; + when MyFirstModule.StCat then + log info node 'n' 'StCat'; + when (empty) then + log info node 'n' 'none'; + end split; + return true; +end; +create microflow MyFirstModule.StUnrelated ($A: MyFirstModule.StAnimal) returns boolean begin + @start(100, 200) + @position(400, 200) + split type $A + when MyFirstModule.StDog then + log info node 'n' 'StDog'; + when MyFirstModule.StAnimal then + log info node 'n' 'StAnimal'; + when MyFirstModule.StOther then + log info node 'n' 'StOther'; + when (empty) then + log info node 'n' 'none'; + end split; + return true; +end; +create microflow MyFirstModule.StTwice ($A: MyFirstModule.StAnimal) returns boolean begin + @start(100, 200) + @position(400, 200) + split type $A + when MyFirstModule.StDog then + log info node 'n' 'StDog'; + when MyFirstModule.StDog then + log info node 'n' 'StDog'; + when MyFirstModule.StAnimal then + log info node 'n' 'StAnimal'; + when (empty) then + log info node 'n' 'none'; + end split; + return true; +end; diff --git a/mdl/ast/ast_microflow.go b/mdl/ast/ast_microflow.go index f63f7aba4..b736ca41b 100644 --- a/mdl/ast/ast_microflow.go +++ b/mdl/ast/ast_microflow.go @@ -279,8 +279,9 @@ type InheritanceSplitCase struct { // // ElseBody is Mendix's `(empty)` outgoing flow — the branch taken when the // object is NULL. It is NOT a default for unmatched types: mxbuild demands a -// flow for every subtype and for the base entity regardless (CE0090), and -// omitting this one is CE0089. It is spelled `when (empty) then`; `else` is +// flow for the subject's own entity regardless (CE0090; on 11.13.0 for every +// subtype as well, on 11.16.1 only for the base), and omitting this one is +// CE0089 — which is why the builder always emits it. It is spelled `when (empty) then`; `else` is // the legacy spelling that reads as a default and is not one (mxcli #913). type InheritanceSplitStmt struct { Variable string // Variable name without $ prefix diff --git a/mdl/executor/validate_inheritance_splits.go b/mdl/executor/validate_inheritance_splits.go new file mode 100644 index 000000000..92d3fbdae --- /dev/null +++ b/mdl/executor/validate_inheritance_splits.go @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "fmt" + "strings" + + "github.com/mendixlabs/mxcli/mdl/ast" + "github.com/mendixlabs/mxcli/mdl/backend" + "github.com/mendixlabs/mxcli/mdl/linter" +) + +// inheritanceSplitRule is the rule ID for "a `split type` branch the build rejects". +const inheritanceSplitRule = "MDL109" + +// A `split type $V` must have a branch for $V's own entity, may only branch on that +// entity or a specialization of it, and may name each once. Measured on MxBuild +// 11.16.1, one project per case (Animal <- Dog <- Puppy, Animal <- Cat): +// +// every type + (empty) clean +// a subtype left out (Cat, or Puppy) clean (only the base is required) +// the subject's entity left out CE0090 "The 'M.Animal' value should be configured for an outgoing flow." +// a branch on an unrelated entity CE0774 "Value is not entity 'M.Animal' or a specialization." +// a branch on the subject's generalization CE0774 (subject Dog, branch Animal) +// a branch on a sibling (subject Dog, branch Cat) CE0774 +// the same entity twice CE0771 "Value is already handled by another sequence flow." +// no (empty) branch clean (the builder always adds it) +// +// check and exec accepted every rejected case. Older records (11.13.0) said every +// subtype needs a branch; on 11.16.1 only the subject's own entity does, so a +// missing subtype is not reported. +// +// CE0089 ("The '(empty)' value should be configured"), which this was started from, +// is not reachable from MDL: the builder emits the (empty) flow unconditionally. +// +// The subject's entity comes from the flow's parameters and the objects it +// retrieves (`first`) or creates; a subject typed any other way is not judged. A +// branch entity's generalizations come from the script, then the project; one +// whose chain cannot be read completely is not judged for CE0774 (an incomplete +// chain can say yes, never no). +func ValidateInheritanceSplits(prog *ast.Program, open func() backend.FullBackend) []linter.Violation { + if prog == nil { + return nil + } + scriptGen := map[string]string{} // lower-cased entity QN -> its generalization QN, as written + scriptEntities := map[string]bool{} + for _, stmt := range prog.Statements { + if e, ok := stmt.(*ast.CreateEntityStmt); ok { + key := strings.ToLower(e.Name.String()) + scriptEntities[key] = true + if e.Generalization != nil { + scriptGen[key] = qualifyIn(e.Name.Module, e.Generalization.String()) + } + } + } + + var lookup entityLookupBackend + opened := false + projectBackend := func() entityLookupBackend { + if !opened { + opened = true + if open != nil { + if b := open(); b != nil { + if lb, ok := b.(entityLookupBackend); ok { + lookup = lb + } + } + } + } + return lookup + } + // chain is entity followed by its generalizations, nearest first, and whether + // the walk reached the root. + chain := func(entity string) ([]string, bool) { + var out []string + seen := map[string]bool{} + for cur := entity; cur != ""; { + key := strings.ToLower(cur) + if seen[key] { + return out, false + } + seen[key] = true + out = append(out, cur) + if scriptEntities[key] { + cur = scriptGen[key] + continue + } + rest, complete := generalizationChainFor(projectBackend(), cur) + if len(rest) > 1 { + out = append(out, rest[1:]...) + } + return out, complete + } + return out, true + } + + var out []linter.Violation + judge := func(kind string, name ast.QualifiedName, params []ast.MicroflowParam, body []ast.MicroflowStatement) { + vars := splitSubjectEntities(params, body) + forEachMicroflowStatement(body, func(s ast.MicroflowStatement) { + stmt, ok := s.(*ast.InheritanceSplitStmt) + if !ok { + return + } + base := vars[stmt.Variable] + if base == "" { + return + } + base = qualifyIn(name.Module, base) + loc := linter.Location{Module: name.Module, DocumentType: kind, DocumentName: name.Name} + report := func(code, msg, fix string) { + out = append(out, linter.Violation{ + RuleID: inheritanceSplitRule, Severity: linter.SeverityError, Location: loc, + Message: fmt.Sprintf("%s %s: `split type $%s` %s — mxbuild reports %s", kind, name, stmt.Variable, msg, code), + Suggestion: fix, + }) + } + seen := map[string]bool{} + hasBase := false + for _, c := range stmt.Cases { + entity := qualifyIn(name.Module, c.Entity.String()) + key := strings.ToLower(entity) + if seen[key] { + report("CE0771", fmt.Sprintf("has two branches for %s", entity), + "Keep one branch per entity: the build routes each type to exactly one flow.") + continue + } + seen[key] = true + if strings.EqualFold(entity, base) { + hasBase = true + continue + } + ch, complete := chain(entity) + related := false + for _, e := range ch { + if strings.EqualFold(e, base) { + related = true + break + } + } + if !related && complete { + report("CE0774", fmt.Sprintf("branches on %s, which is not %s or a specialization of it", entity, base), + fmt.Sprintf("Branch only on %s or an entity that extends it; a generalization or a sibling can never be the object's type.", base)) + } + } + if !hasBase { + report("CE0090", fmt.Sprintf("has no branch for %s, the subject's own entity", base), + fmt.Sprintf("Add `when %s then …`: it is taken for an object of exactly that type, and the build requires it. "+ + "The `(empty)` branch is the null object and does not count.", base)) + } + }) + } + for _, stmt := range prog.Statements { + switch s := stmt.(type) { + case *ast.CreateMicroflowStmt: + judge("microflow", s.Name, s.Parameters, s.Body) + case *ast.CreateNanoflowStmt: + judge("nanoflow", s.Name, s.Parameters, s.Body) + } + } + return out +} + +// splitSubjectEntities is the entity each object variable of a flow holds: its +// entity-typed parameters, and the objects it retrieves with `first` or creates. +func splitSubjectEntities(params []ast.MicroflowParam, body []ast.MicroflowStatement) map[string]string { + vars := map[string]string{} + for _, p := range params { + if p.Type.Kind == ast.TypeEntity && p.Type.EntityRef != nil { + vars[p.Name] = p.Type.EntityRef.String() + } + } + forEachMicroflowStatement(body, func(s ast.MicroflowStatement) { + switch st := s.(type) { + case *ast.RetrieveStmt: + if st.First && st.Variable != "" && st.StartVariable == "" && st.Source.Name != "" { + vars[st.Variable] = st.Source.String() + } + case *ast.CreateObjectStmt: + if st.Variable != "" && st.EntityType.Name != "" { + vars[st.Variable] = st.EntityType.String() + } + } + }) + return vars +} diff --git a/mdl/executor/validate_inheritance_splits_test.go b/mdl/executor/validate_inheritance_splits_test.go new file mode 100644 index 000000000..de829c5ba --- /dev/null +++ b/mdl/executor/validate_inheritance_splits_test.go @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "strings" + "testing" + + "github.com/mendixlabs/mxcli/mdl/backend" + "github.com/mendixlabs/mxcli/mdl/backend/mock" + "github.com/mendixlabs/mxcli/model" + "github.com/mendixlabs/mxcli/sdk/domainmodel" +) + +// A `split type $V` must have a branch for $V's own entity, may only branch on that +// entity or a specialization of it, and may name each once. Measured on MxBuild +// 11.16.1, one project per case, Animal <- Dog <- Puppy and Animal <- Cat: +// +// every type + (empty) clean +// a subtype left out (Cat, or Puppy) clean (only the base is required) +// the subject's entity left out CE0090 "The 'M.Animal' value should be configured for an outgoing flow." +// a branch on an unrelated entity CE0774 "Value is not entity 'M.Animal' or a specialization." +// a branch on the subject's generalization CE0774 (subject $D: Dog, branch Animal) +// a branch on a sibling (subject Dog, branch Cat) CE0774 +// the same entity twice CE0771 "Value is already handled by another sequence flow." +// no (empty) branch clean (the builder always adds it) +// +// check and exec accepted every rejected case. CE0089, the code this was started +// from ("The '(empty)' value should be configured"), cannot be produced by MDL: the +// builder emits the (empty) flow unconditionally. +const splitTypeEntities = `mdl 1; +create persistent entity Zoo.Animal (Name: string(50)); +create persistent entity Zoo.Dog extends Zoo.Animal (Bark: string(50)); +create persistent entity Zoo.Cat extends Zoo.Animal (Meow: string(50)); +create persistent entity Zoo.Puppy extends Zoo.Dog (Small: boolean); +create persistent entity Zoo.Other (X: string(5)); +` + +func splitTypeFlow(subject string, branches ...string) string { + var b strings.Builder + b.WriteString(splitTypeEntities) + b.WriteString("create microflow Zoo.MF ($A: Zoo." + subject + ") returns boolean begin\n split type $A\n") + for _, e := range branches { + b.WriteString(" when Zoo." + e + " then\n log info node 'n' 'x';\n") + } + b.WriteString(" when (empty) then\n log info node 'n' 'e';\n end split;\n return true;\nend;\n") + return b.String() +} + +func TestValidateInheritanceSplits(t *testing.T) { + cases := []struct { + name, subject string + branches []string + want string // CE code, "" for clean + }{ + {"every type (control)", "Animal", []string{"Dog", "Cat", "Puppy", "Animal"}, ""}, + {"a subtype left out", "Animal", []string{"Dog", "Animal"}, ""}, + {"a deeper subtype left out", "Animal", []string{"Dog", "Cat", "Animal"}, ""}, + {"the base left out", "Animal", []string{"Dog", "Cat", "Puppy"}, "CE0090"}, + {"an unrelated entity", "Animal", []string{"Dog", "Animal", "Other"}, "CE0774"}, + {"the subject's generalization", "Dog", []string{"Puppy", "Dog", "Animal"}, "CE0774"}, + {"a sibling", "Dog", []string{"Puppy", "Dog", "Cat"}, "CE0774"}, + {"the same entity twice", "Animal", []string{"Dog", "Dog", "Animal"}, "CE0771"}, + {"a leaf subject with its own branch (control)", "Puppy", []string{"Puppy"}, ""}, + {"a specialization subject without its own branch", "Dog", []string{"Puppy"}, "CE0090"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + got := ValidateInheritanceSplits(mustBuild(t, splitTypeFlow(c.subject, c.branches...)), nil) + if c.want == "" { + if len(got) != 0 { + t.Fatalf("want none, got %v: %+v", rulesOf(got), got) + } + return + } + if len(got) != 1 { + t.Fatalf("want one violation, got %v: %+v", rulesOf(got), got) + } + if got[0].RuleID != inheritanceSplitRule || !strings.Contains(got[0].Message, c.want) { + t.Errorf("rule or code wrong: %+v", got[0]) + } + if got[0].Location.DocumentName != "MF" { + t.Errorf("location: %+v", got[0].Location) + } + }) + } +} + +// Nanoflows have the same split. +func TestValidateInheritanceSplits_Nanoflow(t *testing.T) { + src := strings.Replace(splitTypeFlow("Animal", "Dog"), "create microflow", "create nanoflow", 1) + if got := ValidateInheritanceSplits(mustBuild(t, src), nil); len(got) != 1 || !strings.Contains(got[0].Message, "CE0090") { + t.Errorf("nanoflow without the base: want one CE0090, got %+v", got) + } +} + +// What is not judged: a subject whose entity is not known (a variable the flow +// does not declare), and a branch entity whose generalizations cannot be read. +func TestValidateInheritanceSplits_NotJudged(t *testing.T) { + noSubject := strings.Replace(splitTypeFlow("Animal", "Dog"), "split type $A", "split type $Unknown", 1) + if got := ValidateInheritanceSplits(mustBuild(t, noSubject), nil); len(got) != 0 { + t.Errorf("an untyped subject: want none, got %+v", got) + } + // The entities are the project's, not the script's, and there is no project: + // the base is still known from the parameter, so CE0090 is judged, but whether + // Elsewhere is a specialization is not. + src := `mdl 1; +create microflow Pj.MF ($A: Pj.Animal) returns boolean begin + split type $A + when Pj.Animal then + log info node 'n' 'x'; + when Pj.Elsewhere then + log info node 'n' 'y'; + end split; + return true; +end; +` + if got := ValidateInheritanceSplits(mustBuild(t, src), nil); len(got) != 0 { + t.Errorf("unknown generalizations: want none, got %+v", got) + } +} + +// The hierarchy comes from the project when the entities are not the script's. +func TestValidateInheritanceSplits_ProjectHierarchy(t *testing.T) { + mod := &model.Module{BaseElement: model.BaseElement{ID: "mod-pj"}, Name: "Pj"} + dm := &domainmodel.DomainModel{ + BaseElement: model.BaseElement{ID: "dm-pj"}, ContainerID: mod.ID, + Entities: []*domainmodel.Entity{ + {BaseElement: model.BaseElement{ID: "e1"}, Name: "Animal"}, + {BaseElement: model.BaseElement{ID: "e2"}, Name: "Dog", GeneralizationRef: "Pj.Animal"}, + {BaseElement: model.BaseElement{ID: "e3"}, Name: "Rock"}, + }, + } + mb := &mock.MockBackend{ + IsConnectedFunc: func() bool { return true }, + ListModulesFunc: func() ([]*model.Module, error) { return []*model.Module{mod}, nil }, + GetModuleByNameFunc: func(name string) (*model.Module, error) { + if name == "Pj" { + return mod, nil + } + return nil, nil + }, + ListDomainModelsFunc: func() ([]*domainmodel.DomainModel, error) { return []*domainmodel.DomainModel{dm}, nil }, + GetDomainModelFunc: func(id model.ID) (*domainmodel.DomainModel, error) { + if id == mod.ID { + return dm, nil + } + return nil, nil + }, + } + open := func() backend.FullBackend { return mb } + flow := func(extra string) string { + return `mdl 1; +create microflow Pj.MF ($A: Pj.Animal) returns boolean begin + split type $A + when Pj.Animal then + log info node 'n' 'x'; + when Pj.` + extra + ` then + log info node 'n' 'y'; + end split; + return true; +end; +` + } + if got := ValidateInheritanceSplits(mustBuild(t, flow("Dog")), open); len(got) != 0 { + t.Errorf("Dog specializes Animal in the project (control): want none, got %+v", got) + } + if got := ValidateInheritanceSplits(mustBuild(t, flow("Rock")), open); len(got) != 1 || !strings.Contains(got[0].Message, "CE0774") { + t.Errorf("Rock is not a specialization: want one CE0774, got %+v", got) + } +} diff --git a/mdl/executor/validate_microflow.go b/mdl/executor/validate_microflow.go index 08f47586b..92c04ef6e 100644 --- a/mdl/executor/validate_microflow.go +++ b/mdl/executor/validate_microflow.go @@ -1875,7 +1875,7 @@ func (v *microflowValidator) checkInheritanceSplitSpelling(stmt *ast.Inheritance v.addViolation("MDL065", linter.SeverityWarning, fmt.Sprintf("split type '$%s' uses `else`, which reads as a default branch and is not one: "+ "it is Mendix's `(empty)` flow, taken when the object is null. Mendix still requires an "+ - "outgoing flow for every subtype and for the base entity (CE0090)", stmt.Variable), + "outgoing flow for the subject's own entity (CE0090)", stmt.Variable), "Write `when (empty) then …` instead — same flow, accurate name. "+ "To handle unmatched types, add a `when then …` branch.") } diff --git a/mdl/executor/validate_program.go b/mdl/executor/validate_program.go index 7a685dd99..575885e70 100644 --- a/mdl/executor/validate_program.go +++ b/mdl/executor/validate_program.go @@ -445,6 +445,8 @@ func ValidateProgram(prog *ast.Program, projectPath string) []linter.Violation { violations = append(violations, ValidateMappingHandlerParams(prog, project)...) // A custom handler feeding a JSON member to a microflow parameter of another type (CE0282). violations = append(violations, ValidateMappingHandlerTypes(prog, project)...) + // A `split type` without its subject's own entity, with a duplicate, or with an entity that is not a specialization (CE0090/CE0771/CE0774). + violations = append(violations, ValidateInheritanceSplits(prog, project)...) // Flag a REST client operation whose Body/Response mapping clause has no // `{ ... }` body — Mendix cannot reference a mapping document from an From 30695a4e2bac5fb5a7f5d27852b47012a48ae09e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:44:14 +0000 Subject: [PATCH 07/19] fix: true-right-false-down keeps TRUE on the line for an if without else (#2636) Under if-else: true-right-else-column an `if` without `else` whose THEN carries on kept the default shape: TRUE in a lane below the split, the empty FALSE on the main line. It is now laid out as one with an empty ELSE (in the builder and the measurer alike): TRUE on the line, FALSE from the split's bottom into the merge's bottom. The model is the same, so describe still prints no `else`; a guard is left to the guard setting. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...lumn-style-if-without-else-true-below.json | 1 + CHANGELOG.md | 1 + .../cmd_microflows_builder_control.go | 6 +++ mdl/executor/flowlayout_describe_test.go | 3 ++ mdl/executor/flowlayout_ifelse_column_test.go | 51 +++++++++++++++++++ mdl/executor/layout.go | 1 + mdl/executor/layout_lanes.go | 17 +++++++ 7 files changed, 80 insertions(+) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-28-column-style-if-without-else-true-below.json diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-column-style-if-without-else-true-below.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-column-style-if-without-else-true-below.json new file mode 100644 index 000000000..681de877c --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-column-style-if-without-else-true-below.json @@ -0,0 +1 @@ +{"area": "mdl-executor", "date": "2026-11-28", "refs": ["ako/mxcli#2636", "mendixlabs/mxcli#1971"], "symptom": "Under true-right-false-down an `if` without `else` whose THEN carries on was drawn the default way round: the TRUE activity in a lane below the split (530, 300), the empty FALSE straight to the merge on the line. `create` and `layout flows` both produced it, and layout flows swapped explicit @anchor(true: right) back.", "file": "mdl/executor/layout_lanes.go (withColumnElse), cmd_microflows_builder_control.go addIfStatement, layout.go measureIf", "cause": "The style only applied to ifHasElse(s); an IF without ELSE always took the default's TRUE-below path, whatever the style.", "fix": "Under IfElseColumn an IF without ELSE whose THEN carries on is laid out as one with an empty ELSE (HasElse on a copy, in both the builder and the measurer): TRUE on the line, FALSE from the split's bottom into the merge's bottom. The model is the same — an empty ELSE is the false flow into the merge — so describe still prints no `else`. A guard (THEN returns) is left to the guard setting.", "insight": "The empty-ELSE path already existed and was right; the defect was only which IFs reached it. Applying the copy in the measurer too keeps bounds and positions from disagreeing, which is what the overlap assertions catch.", "test": "flowlayout_ifelse_column_test.go TestIfElseColumn_IfWithoutElseKeepsTrueOnTheCentreLine (controls: default style keeps TRUE below; a guard keeps TRUE below) failed before the fix at exactly the issue's (530, 300); flowlayout_describe_test.go styled flow gained the shape and describes with no positions. Live 11.17.0: issue repro gives TRUE at (530, 200), false flow bottom->bottom, describe prints the plain `if`, second exec and layout flows --dry-run unchanged, mx check 0 errors."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c56a6415..32370a391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **true-right-false-down: an `if` without `else` keeps TRUE on the line** (ako/mxcli#2636, upstream mendixlabs/mxcli#1971) — with `if-else: true-right-else-column`, an `if` without `else` whose true branch carries on was still drawn the default way round. The true branch went into a lane below the split, and the empty false branch ran to the merge on the main line. This happened both in `create` and in `mxcli layout flows`, which also swapped explicit `@anchor(true: (from: right))` back. Under that style, such an `if` is now laid out like one with an empty `else`: true on the line, and false running from the split's bottom into the merge's bottom. The model is unchanged, and `describe` still prints no `else`. Guards, whose true branch ends the flow, keep following the `guard` setting. - **mxcli no longer writes `@mxcli-layout:` into a flow's documentation** (ako/mxcli#2635, upstream mendixlabs/mxcli#1970) — in a project with a `layout-config.yaml`, every flow mxcli laid out gained an `@mxcli-layout: …` line in its Documentation, even when its style was the project's. Studio Pro showed it, generated documentation copied it, and it could not be removed through MDL, because the next write appended it again. The style is now never stored in the flow: `describe` judges positions against the project style, the one `create or modify` rebuilds in, so a round trip stays exact. A flow drawn in another style prints the `@position` lines that keep it. A line written by an older release is honoured once and then removed by the next write of the flow or by `mxcli layout flows`. - **`check` rejects a `split type` the build rejects** (ako/mxcli#1258) — a split with no branch for its subject's own entity (CE0090), a branch on an entity that is not that entity or a specialization of it (CE0774), or the same entity twice (CE0771) passed `check` and `exec`. New MDL109; the hierarchy is read from the script, then the project, and a subject or chain it cannot read is not judged. Measured on MxBuild 11.16.1: a subtype left out builds clean, so it is not reported, and the help text that said every subtype needs a branch is corrected. CE0089 (no `(empty)` flow) cannot be produced by MDL, because the builder always adds it. - **`marketplace package` uses the project's installed mx before one on PATH** (ako/mxcli#2652) — with the project's Mendix version cached and another version's `mx` on PATH, the export was refused, and the hint said to take that one off PATH. An installed or cached `mx` of the project's release now comes first. `--mxbuild-path` must name a folder that holds an `mx`: it no longer falls back to the `mx` on PATH and exports with that under the override. This is the same rule as `git merge` (#2644). diff --git a/mdl/executor/cmd_microflows_builder_control.go b/mdl/executor/cmd_microflows_builder_control.go index 74d9136e9..806445899 100644 --- a/mdl/executor/cmd_microflows_builder_control.go +++ b/mdl/executor/cmd_microflows_builder_control.go @@ -19,6 +19,7 @@ import ( // When a branch ends with RETURN, it terminates at its own EndEvent and does not // connect to the merge. When both branches end with RETURN, no merge is created. func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID { + s = withColumnElse(fb.layoutStyle(), s) // First, measure the branches to know how much space they need thenBounds := fb.measurer.measureBranch(s.ThenBody) elseBounds := fb.measurer.measureBranch(s.ElseBody) @@ -406,6 +407,11 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID { // Explicit empty ELSE body: the split still needs a configured // false case when both branches converge at the merge. flow := newDownwardFlowWithCase(splitID, mergeID, "false") + if column != nil { + // Down from the split and back up into the merge, under the + // TRUE body rather than through it (ako/mxcli#2636). + flow.DestinationConnectionIndex = AnchorBottom + } applyUserAnchors(flow, falseBranchAnchor, falseBranchAnchor) fb.flows = append(fb.flows, flow) } diff --git a/mdl/executor/flowlayout_describe_test.go b/mdl/executor/flowlayout_describe_test.go index 10e1758ce..4d76ecde8 100644 --- a/mdl/executor/flowlayout_describe_test.go +++ b/mdl/executor/flowlayout_describe_test.go @@ -32,6 +32,9 @@ begin log info 'small 1'; log info 'small 2'; end if; + if $N > 5 then + log info 'over five'; + end if; log info 'ok'; return true; end; diff --git a/mdl/executor/flowlayout_ifelse_column_test.go b/mdl/executor/flowlayout_ifelse_column_test.go index 20c746365..f954b072f 100644 --- a/mdl/executor/flowlayout_ifelse_column_test.go +++ b/mdl/executor/flowlayout_ifelse_column_test.go @@ -333,3 +333,54 @@ func TestIfElseColumn_AppliesInsideALoopBody(t *testing.T) { } } } + +// ako/mxcli#2636: under true-right-else-column an IF without ELSE whose THEN +// carries on is drawn as one with an empty ELSE — TRUE on the centre line, the +// empty FALSE straight down from the split and back up into the merge. It used +// to keep the default's shape, with TRUE in a lane below. +func TestIfElseColumn_IfWithoutElseKeepsTrueOnTheCentreLine(t *testing.T) { + noElse := &ast.IfStmt{Condition: &ast.LiteralExpr{Kind: ast.LiteralBoolean, Value: true}, ThenBody: logStatements(1)} + stmts := append([]ast.MicroflowStatement{noElse}, logStatements(1)...) + fb := buildWithLayout(t, stmts, columnLayout()) + + split, _ := firstOfType[*microflows.ExclusiveSplit](fb.objects) + merge, ok := firstOfType[*microflows.ExclusiveMerge](fb.objects) + if !ok { + t.Fatal("no merge") + } + acts := activityIDs(fb.objects) + then := objectByIDIn(fb.objects, acts[0]) + sp := split.GetPosition() + if then.GetPosition().Y != sp.Y || then.GetPosition().X <= sp.X { + t.Errorf("TRUE activity at %v, want right of the split at %v on its line", then.GetPosition(), sp) + } + if merge.GetPosition().Y != sp.Y || merge.GetPosition().X <= then.GetPosition().X { + t.Errorf("merge at %v, want on the centre line past the TRUE activity", merge.GetPosition()) + } + if f := flowFrom(fb.flows, split.GetID(), "true"); f == nil || f.OriginConnectionIndex != AnchorRight || f.DestinationID != then.GetID() { + t.Errorf("TRUE flow = %+v, want split right -> TRUE activity", f) + } + if f := flowFrom(fb.flows, split.GetID(), "false"); f == nil || f.DestinationID != merge.GetID() || + f.OriginConnectionIndex != AnchorBottom || f.DestinationConnectionIndex != AnchorBottom { + t.Errorf("FALSE flow = %+v, want split bottom -> merge bottom", f) + } + assertNoOverlap(t, fb.objects) + + // Control: the default style keeps TRUE in the lane below. + fb = buildWithLayout(t, stmts, &flowLayout{}) + split, _ = firstOfType[*microflows.ExclusiveSplit](fb.objects) + if p := objectByIDIn(fb.objects, activityIDs(fb.objects)[0]).GetPosition(); p.Y <= split.GetPosition().Y { + t.Errorf("default style: TRUE activity at %v, want below the split at %v", p, split.GetPosition()) + } + + // A guard is not this case: its THEN ends the flow, and the guard setting + // decides where it goes. + guard := &ast.IfStmt{Condition: &ast.LiteralExpr{Kind: ast.LiteralBoolean, Value: true}, + ThenBody: append(logStatements(1), &ast.ReturnStmt{})} + fb = buildWithLayout(t, append([]ast.MicroflowStatement{guard}, logStatements(1)...), columnLayout()) + split, _ = firstOfType[*microflows.ExclusiveSplit](fb.objects) + if p := objectByIDIn(fb.objects, activityIDs(fb.objects)[0]).GetPosition(); p.Y <= split.GetPosition().Y { + t.Errorf("guard: TRUE activity at %v, want below the split at %v", p, split.GetPosition()) + } +} + diff --git a/mdl/executor/layout.go b/mdl/executor/layout.go index 9a8ad34de..3f4cd0ca7 100644 --- a/mdl/executor/layout.go +++ b/mdl/executor/layout.go @@ -388,6 +388,7 @@ func (m *layoutMeasurer) measureIfStatement(s *ast.IfStmt) Bounds { // centre, as if that were its left edge, and came out 45px short: the merge of an // enclosing IF stood inside the activity after it (ako/mxcli#1773). func (m *layoutMeasurer) measureIf(s *ast.IfStmt, atTail bool) Bounds { + s = withColumnElse(m.layoutStyle(), s) // Measure THEN branch thenBounds := m.measureBranch(s.ThenBody) diff --git a/mdl/executor/layout_lanes.go b/mdl/executor/layout_lanes.go index 6e94804c9..2467f168d 100644 --- a/mdl/executor/layout_lanes.go +++ b/mdl/executor/layout_lanes.go @@ -55,6 +55,23 @@ func ifHasElse(s *ast.IfStmt) bool { return s.HasElse && !lastStmtIsReturn(s.ThenBody) } +// withColumnElse returns s as the layout draws it under style. Under +// true-right-else-column an IF without ELSE whose THEN carries on is drawn as one +// with an empty ELSE: TRUE on the centre line, the empty FALSE down from the +// split and back up into the merge. Left as it was, it kept the default's shape +// — TRUE in a lane below, FALSE on the line — the one IF the style turned the +// other way round (ako/mxcli#2636). The model is the same either way: an empty +// ELSE is the false flow into the merge. A guard is left alone; where its +// branch goes is the guard setting's. +func withColumnElse(style flowLayout, s *ast.IfStmt) *ast.IfStmt { + if style.IfElse != IfElseColumn || ifHasElse(s) || len(s.ThenBody) == 0 || lastStmtIsReturn(s.ThenBody) { + return s + } + c := *s + c.HasElse = true + return &c +} + // ifJoinsNothingAtTail reports whether addIfStatement, building s as the last // statement of a loop body, leaves out its merge: an IF/ELSE whose two branches // both carry on there ends the iteration either way (mendixlabs/mxcli#884). From 79e66582da546b3de129763a97ed3634b47fdc39 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 12:27:51 +0000 Subject: [PATCH 08/19] test: gofmt the #2636 layout test Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- mdl/executor/flowlayout_ifelse_column_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/mdl/executor/flowlayout_ifelse_column_test.go b/mdl/executor/flowlayout_ifelse_column_test.go index f954b072f..c7c898e3f 100644 --- a/mdl/executor/flowlayout_ifelse_column_test.go +++ b/mdl/executor/flowlayout_ifelse_column_test.go @@ -383,4 +383,3 @@ func TestIfElseColumn_IfWithoutElseKeepsTrueOnTheCentreLine(t *testing.T) { t.Errorf("guard: TRUE activity at %v, want below the split at %v", p, split.GetPosition()) } } - From 76ff384c562c75a105c5c985d1f7c2ca385d4790 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:44:30 +0000 Subject: [PATCH 09/19] fix: true-right-false-down nested false branches share the first row (#2650) Each ELSE column started BranchGap under the TRUE body's whole measured height, which includes the columns of IFs nested in it, so nested guards made a staircase (the outermost at y=1080 with the decisions at 200). The column now starts on the first row under its decision, and lower only when an object the TRUE body actually drew stands in the column's band. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...6-11-28-nested-else-columns-staircase.json | 1 + CHANGELOG.md | 1 + .../cmd_microflows_builder_control.go | 7 ++- mdl/executor/flowlayout.go | 33 ++++++++++++ mdl/executor/flowlayout_ifelse_column_test.go | 52 +++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-28-nested-else-columns-staircase.json diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-nested-else-columns-staircase.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-nested-else-columns-staircase.json new file mode 100644 index 000000000..54875bdac --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-nested-else-columns-staircase.json @@ -0,0 +1 @@ +{"area": "mdl-executor", "date": "2026-11-28", "refs": ["ako/mxcli#2650", "mendixlabs/mxcli#1978"], "symptom": "Under true-right-false-down, nested decisions' ELSE columns formed a staircase: each outer column started under the last element of every column inside it (no C at y=660, no B 870, no A 1080 with the decisions at y=200), though each column has its own x. layout flows --dry-run called it already laid out.", "file": "mdl/executor/flowlayout.go (elseColumnTop), cmd_microflows_builder_control.go addIfStatement", "cause": "The column's top was BranchGap under the TRUE body's whole measured height, and that height includes the columns of IFs nested in the TRUE body, which stand right of this column.", "fix": "The column starts on the first row under the decision unless an object the TRUE body actually drew (built before the ELSE, so its positions are known) stands in the column's band — half an activity left of the split to the measured column width plus laneGap — then BranchGap under the lowest such object.", "insight": "Measured bounds are a box; deciding clearance from them stacks anything nested. The TRUE body is built first, so the real objects are there to test against — the same move the guard line already made with objectsExtent. The measurer's height stays an upper bound, which only reserves room.", "test": "flowlayout_ifelse_column_test.go TestIfElseColumn_NestedElseColumnsShareTheFirstRow failed with the issue's exact staircase (300/660/870/1080); control TestIfElseColumn_ElseColumnStillClearsTheThenBody and the existing NestedColumnInTheTrueBodyIsCleared fail with overlaps when the band test is stubbed. Live 11.17.0: issue repro puts every false branch at y=300, describe prints no positions, second exec unchanged, mx check 0 errors."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 32370a391..0dd0d5f55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **true-right-false-down: nested false branches share the first row** (ako/mxcli#2650, upstream mendixlabs/mxcli#1978) — each `else` column of a nested decision started below every column nested inside its true branch. A flow with four guards put the outermost false branch at y = 1080 while the decisions sat at y = 200. Each column already stands at its own decision's x, so a column now starts on the first row under its decision. It drops lower only when something its true branch drew actually stands in the column's way. - **true-right-false-down: an `if` without `else` keeps TRUE on the line** (ako/mxcli#2636, upstream mendixlabs/mxcli#1971) — with `if-else: true-right-else-column`, an `if` without `else` whose true branch carries on was still drawn the default way round. The true branch went into a lane below the split, and the empty false branch ran to the merge on the main line. This happened both in `create` and in `mxcli layout flows`, which also swapped explicit `@anchor(true: (from: right))` back. Under that style, such an `if` is now laid out like one with an empty `else`: true on the line, and false running from the split's bottom into the merge's bottom. The model is unchanged, and `describe` still prints no `else`. Guards, whose true branch ends the flow, keep following the `guard` setting. - **mxcli no longer writes `@mxcli-layout:` into a flow's documentation** (ako/mxcli#2635, upstream mendixlabs/mxcli#1970) — in a project with a `layout-config.yaml`, every flow mxcli laid out gained an `@mxcli-layout: …` line in its Documentation, even when its style was the project's. Studio Pro showed it, generated documentation copied it, and it could not be removed through MDL, because the next write appended it again. The style is now never stored in the flow: `describe` judges positions against the project style, the one `create or modify` rebuilds in, so a round trip stays exact. A flow drawn in another style prints the `@position` lines that keep it. A line written by an older release is honoured once and then removed by the next write of the flow or by `mxcli layout flows`. - **`check` rejects a `split type` the build rejects** (ako/mxcli#1258) — a split with no branch for its subject's own entity (CE0090), a branch on an entity that is not that entity or a specialization of it (CE0774), or the same entity twice (CE0771) passed `check` and `exec`. New MDL109; the hierarchy is read from the script, then the project, and a subject or chain it cannot read is not judged. Measured on MxBuild 11.16.1: a subtype left out builds clean, so it is not reported, and the help text that said every subtype needs a branch is corrected. CE0089 (no `(empty)` flow) cannot be produced by MDL, because the builder always adds it. diff --git a/mdl/executor/cmd_microflows_builder_control.go b/mdl/executor/cmd_microflows_builder_control.go index 806445899..747ce4212 100644 --- a/mdl/executor/cmd_microflows_builder_control.go +++ b/mdl/executor/cmd_microflows_builder_control.go @@ -27,8 +27,10 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID { // Calculate branch width (max of both branches) branchWidth := max(thenBounds.Width, elseBounds.Width) elseColumn := fb.layoutStyle().IfElse == IfElseColumn && ifHasElse(s) + var columnBounds Bounds if elseColumn { - branchWidth = elseColumnBranchWidth(thenBounds, fb.measurer.measureColumn(s.ElseBody)) + columnBounds = fb.measurer.measureColumn(s.ElseBody) + branchWidth = elseColumnBranchWidth(thenBounds, columnBounds) } if branchWidth == 0 { branchWidth = HorizontalSpacing / 2 @@ -183,6 +185,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID { if hasElseBody { // IF WITH ELSE: TRUE path horizontal (happy path), FALSE path below + thenFirst := len(fb.objects) fb.posX = thenStartX fb.posY = centerY fb.endsWithReturn = false @@ -303,7 +306,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID { fb.posY = elseCenterY var column *elseColumnCursor if elseColumn { - column = fb.startElseColumn(splitX, centerY+thenH/2+BranchGap) + column = fb.startElseColumn(splitX, elseColumnTop(splitX, centerY, columnBounds, fb.objects[thenFirst:])) } fb.endsWithReturn = false diff --git a/mdl/executor/flowlayout.go b/mdl/executor/flowlayout.go index da00865bb..361fb071a 100644 --- a/mdl/executor/flowlayout.go +++ b/mdl/executor/flowlayout.go @@ -192,6 +192,39 @@ func objectsExtent(objects []microflows.MicroflowObject) (top, bottom int, ok bo return top, bottom, ok } +// elseColumnTop is the top edge of an ELSE column hung under the split at +// (splitX, centerY): the first row under the decision, unless something the +// TRUE body drew stands in the column's band — from half an activity left of +// the split to the column's measured width and a lane gap past it — in which case +// BranchGap under the lowest such thing. +// +// It used to be BranchGap under the TRUE body's whole measured height. That +// height includes the columns of IFs nested in the TRUE body, which stand at +// their own decisions' x, right of this column; so each outer column began under +// every inner one, a staircase as deep as the nesting (ako/mxcli#2650). +func elseColumnTop(splitX, centerY int, column Bounds, then []microflows.MicroflowObject) int { + top := centerY + ActivityHeight/2 + BranchGap + left := splitX - ActivityWidth/2 + right := left + max(column.Width, ActivityWidth) + laneGap + for _, o := range then { + if o == nil { + continue + } + p := o.GetPosition() + w, h := ActivityWidth, ActivityHeight + if ws, ok := o.(interface{ GetSize() model.Size }); ok { + if sz := ws.GetSize(); sz.Width > 0 && sz.Height > 0 { + w, h = sz.Width, sz.Height + } + } + if p.X+w/2 <= left || p.X-w/2 >= right { + continue + } + top = max(top, p.Y+h/2+BranchGap) + } + return top +} + // measureColumn measures an ELSE body stacked as a column: as wide as its widest // statement, as tall as all of them with RowGap between. A RETURN draws an end // event at the bottom. diff --git a/mdl/executor/flowlayout_ifelse_column_test.go b/mdl/executor/flowlayout_ifelse_column_test.go index c7c898e3f..d51d4e052 100644 --- a/mdl/executor/flowlayout_ifelse_column_test.go +++ b/mdl/executor/flowlayout_ifelse_column_test.go @@ -383,3 +383,55 @@ func TestIfElseColumn_IfWithoutElseKeepsTrueOnTheCentreLine(t *testing.T) { t.Errorf("guard: TRUE activity at %v, want below the split at %v", p, split.GetPosition()) } } + +// ako/mxcli#2650: nested IFs whose ELSE columns stand at different x start all +// of them on the first row under the decisions. Each outer column used to start +// under the deepest point of the THEN body, inner columns included, so four +// guards made a staircase down to y=1080. +func TestIfElseColumn_NestedElseColumnsShareTheFirstRow(t *testing.T) { + ret := func() ast.MicroflowStatement { return &ast.ReturnStmt{} } + innermost := ifElse([]ast.MicroflowStatement{ret()}, append(logStatements(2), ret())) + c := ifElse([]ast.MicroflowStatement{innermost}, append(logStatements(1), ret())) + b := ifElse([]ast.MicroflowStatement{c}, append(logStatements(1), ret())) + a := ifElse([]ast.MicroflowStatement{b}, append(logStatements(1), ret())) + fb := buildWithLayout(t, []ast.MicroflowStatement{a}, columnLayout()) + assertNoOverlap(t, fb.objects) + + var splits []microflows.MicroflowObject + for _, o := range fb.objects { + if _, ok := o.(*microflows.ExclusiveSplit); ok { + splits = append(splits, o) + } + } + if len(splits) != 4 { + t.Fatalf("want 4 splits, got %d", len(splits)) + } + // The first ELSE element of each decision is the false flow's destination. + row := -1 + for _, s := range splits { + f := flowFrom(fb.flows, s.GetID(), "false") + if f == nil { + t.Fatalf("split at %v has no false flow", s.GetPosition()) + } + p := objectByIDIn(fb.objects, f.DestinationID).GetPosition() + if p.X != s.GetPosition().X { + t.Errorf("ELSE of the split at %v starts at %v, want in its column", s.GetPosition(), p) + } + if row == -1 { + row = p.Y + } + if p.Y != row { + t.Errorf("ELSE of the split at %v starts at y=%d, want the shared first row y=%d", s.GetPosition(), p.Y, row) + } + } +} + +// Control for #2650: a column that would run into the THEN body's own column +// still starts under it. Here the outer ELSE holds an IF/ELSE, which reaches +// right into the inner split's column. +func TestIfElseColumn_ElseColumnStillClearsTheThenBody(t *testing.T) { + inner := ifElse(logStatements(1), logStatements(3)) + outerElse := []ast.MicroflowStatement{ifElse(logStatements(2), logStatements(1))} + fb := buildWithLayout(t, []ast.MicroflowStatement{ifElse([]ast.MicroflowStatement{inner}, outerElse)}, columnLayout()) + assertNoOverlap(t, fb.objects) +} From e703263b8124fc08444930b9aee7760f2fe93e2e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 13:34:03 +0000 Subject: [PATCH 10/19] check: reject a published OData service that exposes a Binary attribute (CE5013, MDL110) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82tETa46YQmMS58pQjL --- ...6-11-28-published-odata-binary-ce5013.json | 1 + CHANGELOG.md | 1 + .../published-odata-attribute-types.mdl | 15 ++ .../published-odata-binary-attribute.fail.mdl | 19 +++ mdl/executor/validate_program.go | 2 + mdl/executor/validate_published_binary.go | 143 ++++++++++++++++++ .../validate_published_binary_test.go | 101 +++++++++++++ 7 files changed, 282 insertions(+) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-28-published-odata-binary-ce5013.json create mode 100644 mdl-examples/bug-tests/published-odata-attribute-types.mdl create mode 100644 mdl-examples/bug-tests/published-odata-binary-attribute.fail.mdl create mode 100644 mdl/executor/validate_published_binary.go create mode 100644 mdl/executor/validate_published_binary_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-published-odata-binary-ce5013.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-published-odata-binary-ce5013.json new file mode 100644 index 000000000..369a1a240 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-published-odata-binary-ce5013.json @@ -0,0 +1 @@ +{"area": "mdl/executor", "date": "2026-11-28", "refs": ["ako/mxcli#1258"], "ce": ["CE5013"], "symptom": "A published OData service that exposes a Binary attribute (the entity's own, or one it inherits) passed `check` and `exec`; `mx check` reported CE5013 \"Binary attribute 'Photo' cannot be exposed through an OData entity.\"", "file": "mdl/executor/validate_published_binary.go ValidatePublishedBinary (MDL110), wired in validate_program.go. Tests validate_published_binary_test.go; fixtures mdl-examples/bug-tests/published-odata-binary-attribute.fail.mdl and published-odata-attribute-types.mdl", "cause": "The writer maps Binary to Edm.Binary to keep the mapping total and its comment already said Mendix rejects it, but nothing refused the member before the write.", "insight": "**Of eleven OData codes in the coverage list, re-measuring found three still reachable from MDL; this is the publish-side one.** CE0309 (key marked CanBeEmpty), CE0729 (empty service name) and CE4583 (exposed enumeration) build clean now because the writer handles them; every other attribute type was measured as exposing clean, so the rule is Binary only. The attribute is resolved through the generalization chain, because an inherited Binary attribute fails the same way and is the case a by-entity lookup would miss."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 32370a391..5563632a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`check` rejects a published OData service that exposes a Binary attribute** (ako/mxcli#1258) — exposing the entity's own Binary attribute, or one it inherits, passed `check` and `exec`, and the build reported CE5013 "Binary attribute … cannot be exposed through an OData entity". New MDL110; the attribute's type is read from the script, then the project. Every other attribute type exposes clean. Measured on MxBuild 11.16.1. - **true-right-false-down: an `if` without `else` keeps TRUE on the line** (ako/mxcli#2636, upstream mendixlabs/mxcli#1971) — with `if-else: true-right-else-column`, an `if` without `else` whose true branch carries on was still drawn the default way round. The true branch went into a lane below the split, and the empty false branch ran to the merge on the main line. This happened both in `create` and in `mxcli layout flows`, which also swapped explicit `@anchor(true: (from: right))` back. Under that style, such an `if` is now laid out like one with an empty `else`: true on the line, and false running from the split's bottom into the merge's bottom. The model is unchanged, and `describe` still prints no `else`. Guards, whose true branch ends the flow, keep following the `guard` setting. - **mxcli no longer writes `@mxcli-layout:` into a flow's documentation** (ako/mxcli#2635, upstream mendixlabs/mxcli#1970) — in a project with a `layout-config.yaml`, every flow mxcli laid out gained an `@mxcli-layout: …` line in its Documentation, even when its style was the project's. Studio Pro showed it, generated documentation copied it, and it could not be removed through MDL, because the next write appended it again. The style is now never stored in the flow: `describe` judges positions against the project style, the one `create or modify` rebuilds in, so a round trip stays exact. A flow drawn in another style prints the `@position` lines that keep it. A line written by an older release is honoured once and then removed by the next write of the flow or by `mxcli layout flows`. - **`check` rejects a `split type` the build rejects** (ako/mxcli#1258) — a split with no branch for its subject's own entity (CE0090), a branch on an entity that is not that entity or a specialization of it (CE0774), or the same entity twice (CE0771) passed `check` and `exec`. New MDL109; the hierarchy is read from the script, then the project, and a subject or chain it cannot read is not judged. Measured on MxBuild 11.16.1: a subtype left out builds clean, so it is not reported, and the help text that said every subtype needs a branch is corrected. CE0089 (no `(empty)` flow) cannot be produced by MDL, because the builder always adds it. diff --git a/mdl-examples/bug-tests/published-odata-attribute-types.mdl b/mdl-examples/bug-tests/published-odata-attribute-types.mdl new file mode 100644 index 000000000..37f77eaf2 --- /dev/null +++ b/mdl-examples/bug-tests/published-odata-attribute-types.mdl @@ -0,0 +1,15 @@ +mdl 1; +-- CONTROL for published-odata-binary-attribute.fail.mdl: every attribute type MxBuild +-- 11.16.1 exposes clean in a published OData service. Binary is the only one it refuses. +create enumeration MyFirstModule.PtLevel (Low 'Low', High 'High'); +create persistent entity MyFirstModule.PtAll ( + Code: string(36) unique, H: hashedstring, I: integer, L: long, De: decimal, B: boolean, + D: datetime, An: autonumber default 1, Lvl: enumeration(MyFirstModule.PtLevel), Photo: binary +); +create module role MyFirstModule.PtApiUser; +create published odata service MyFirstModule.PtApi (path: 'odata/ptapi/', version: '1.0.0', ODataVersion: OData4, namespace: 'My.PtApi', ServiceName: 'PtApi', Authentication: (basic)) +{ + publish entity MyFirstModule.PtAll as 'Alls' (ReadMode: source, InsertMode: not_supported, UpdateMode: not_supported, DeleteMode: not_supported) + expose (Code (KEY), H, I, L, De, B, D, An, Lvl); +}; +grant access on published odata service MyFirstModule.PtApi to MyFirstModule.PtApiUser; diff --git a/mdl-examples/bug-tests/published-odata-binary-attribute.fail.mdl b/mdl-examples/bug-tests/published-odata-binary-attribute.fail.mdl new file mode 100644 index 000000000..ed5ed3358 --- /dev/null +++ b/mdl-examples/bug-tests/published-odata-binary-attribute.fail.mdl @@ -0,0 +1,19 @@ +mdl 1; +-- NEGATIVE TEST — `mxcli check` must REFUSE this file (MDL110), with no project. +-- +-- A published OData service that exposes a Binary attribute, the entity's own and an +-- inherited one. `check` and `exec` accepted both, and the build reported +-- +-- [CE5013] "Binary attribute 'Photo' cannot be exposed through an OData entity." +-- +-- Measured on MxBuild 11.16.1. Every other attribute type exposes clean; see +-- published-odata-attribute-types.mdl. +create persistent entity MyFirstModule.PbBase (Data: binary, Title: string(50)); +create persistent entity MyFirstModule.PbChild extends MyFirstModule.PbBase (Code: string(36) unique, Photo: binary); +create module role MyFirstModule.PbApiUser; +create published odata service MyFirstModule.PbApi (path: 'odata/pbapi/', version: '1.0.0', ODataVersion: OData4, namespace: 'My.PbApi', ServiceName: 'PbApi', Authentication: (basic)) +{ + publish entity MyFirstModule.PbChild as 'Children' (ReadMode: source, InsertMode: not_supported, UpdateMode: not_supported, DeleteMode: not_supported) + expose (Code (KEY), Photo, Data); +}; +grant access on published odata service MyFirstModule.PbApi to MyFirstModule.PbApiUser; diff --git a/mdl/executor/validate_program.go b/mdl/executor/validate_program.go index 575885e70..a75170303 100644 --- a/mdl/executor/validate_program.go +++ b/mdl/executor/validate_program.go @@ -447,6 +447,8 @@ func ValidateProgram(prog *ast.Program, projectPath string) []linter.Violation { violations = append(violations, ValidateMappingHandlerTypes(prog, project)...) // A `split type` without its subject's own entity, with a duplicate, or with an entity that is not a specialization (CE0090/CE0771/CE0774). violations = append(violations, ValidateInheritanceSplits(prog, project)...) + // A published OData service that exposes a Binary attribute (CE5013). + violations = append(violations, ValidatePublishedBinary(prog, project)...) // Flag a REST client operation whose Body/Response mapping clause has no // `{ ... }` body — Mendix cannot reference a mapping document from an diff --git a/mdl/executor/validate_published_binary.go b/mdl/executor/validate_published_binary.go new file mode 100644 index 000000000..35e1f3573 --- /dev/null +++ b/mdl/executor/validate_published_binary.go @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "fmt" + "strings" + + "github.com/mendixlabs/mxcli/mdl/ast" + "github.com/mendixlabs/mxcli/mdl/backend" + "github.com/mendixlabs/mxcli/mdl/linter" + "github.com/mendixlabs/mxcli/sdk/domainmodel" +) + +// publishedBinaryRule is the rule ID for "a published OData service exposes a +// Binary attribute". +const publishedBinaryRule = "MDL110" + +// A Binary attribute cannot be exposed by a published OData service. MxBuild +// 11.16.1 reports CE5013 "Binary attribute 'Photo' cannot be exposed through an +// OData entity." for the entity's own attribute and for one it inherits; check and +// exec accepted both. Every other attribute type (String, HashedString, Integer, +// Long, Decimal, Boolean, DateTime, AutoNumber, Enumeration) exposes clean. +// +// The attribute's type comes from the script, then the project, walking the +// generalization chain for an inherited one. A member whose type cannot be found +// (an association, an entity neither declares) is not judged. +func ValidatePublishedBinary(prog *ast.Program, open func() backend.FullBackend) []linter.Violation { + if prog == nil { + return nil + } + type scriptEntity struct { + gen string + binary map[string]bool // lower-cased attribute names + attrs map[string]bool + } + script := map[string]*scriptEntity{} + for _, stmt := range prog.Statements { + switch s := stmt.(type) { + case *ast.CreateEntityStmt: + e := &scriptEntity{binary: map[string]bool{}, attrs: map[string]bool{}} + if s.Generalization != nil { + e.gen = qualifyIn(s.Name.Module, s.Generalization.String()) + } + for _, a := range s.Attributes { + e.attrs[strings.ToLower(a.Name)] = true + if a.Type.Kind == ast.TypeBinary { + e.binary[strings.ToLower(a.Name)] = true + } + } + script[strings.ToLower(s.Name.String())] = e + case *ast.AlterEntityStmt: + if e := script[strings.ToLower(s.Name.String())]; e != nil && s.Operation == ast.AlterEntityAddAttribute && s.Attribute != nil { + e.attrs[strings.ToLower(s.Attribute.Name)] = true + if s.Attribute.Type.Kind == ast.TypeBinary { + e.binary[strings.ToLower(s.Attribute.Name)] = true + } + } + } + } + + var lookup entityLookupBackend + opened := false + project := func() entityLookupBackend { + if !opened { + opened = true + if open != nil { + if b := open(); b != nil { + lookup, _ = b.(entityLookupBackend) + } + } + } + return lookup + } + // isBinary answers whether entity (or a generalization) declares attr as + // Binary, and whether the answer is known. + isBinary := func(entity, attr string) (bool, bool) { + seen := map[string]bool{} + for cur := entity; cur != ""; { + key := strings.ToLower(cur) + if seen[key] { + return false, false + } + seen[key] = true + if e := script[key]; e != nil { + if e.attrs[attr] { + return e.binary[attr], true + } + cur = e.gen + continue + } + b := project() + if b == nil { + return false, false + } + ent, ok := findEntityByQN(b, cur) + if !ok { + return false, false + } + for _, a := range ent.Attributes { + if a != nil && strings.EqualFold(a.Name, attr) { + _, bin := a.Type.(*domainmodel.BinaryAttributeType) + return bin, true + } + } + cur = ent.GeneralizationRef + } + return false, false + } + + var out []linter.Violation + for _, stmt := range prog.Statements { + svc, ok := stmt.(*ast.CreateODataServiceStmt) + if !ok { + continue + } + for _, pe := range svc.Entities { + if pe == nil { + continue + } + entity := qualifyIn(svc.Name.Module, pe.Entity.String()) + for _, m := range pe.Members { + if m == nil || m.Name == "" { + continue + } + if bin, known := isBinary(entity, strings.ToLower(bareMemberName(m.Name))); !known || !bin { + continue + } + out = append(out, linter.Violation{ + RuleID: publishedBinaryRule, + Severity: linter.SeverityError, + Message: fmt.Sprintf("published odata service %s exposes %s, a Binary attribute of %s — mxbuild reports "+ + "CE5013 \"Binary attribute '%s' cannot be exposed through an OData entity\"", + svc.Name, m.Name, entity, m.Name), + Location: linter.Location{Module: svc.Name.Module, DocumentType: "published odata service", DocumentName: svc.Name.Name}, + Suggestion: "Leave the Binary attribute out of `expose (…)`. To serve file contents, publish a " + + "REST operation that returns them, or expose a URL or an ID the client can download from.", + }) + } + } + } + return out +} diff --git a/mdl/executor/validate_published_binary_test.go b/mdl/executor/validate_published_binary_test.go new file mode 100644 index 000000000..cd71f0233 --- /dev/null +++ b/mdl/executor/validate_published_binary_test.go @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "strings" + "testing" + + "github.com/mendixlabs/mxcli/mdl/backend" + "github.com/mendixlabs/mxcli/mdl/backend/mock" + "github.com/mendixlabs/mxcli/model" + "github.com/mendixlabs/mxcli/sdk/domainmodel" +) + +// A published OData service that exposes a Binary attribute does not build: MxBuild +// 11.16.1 reports CE5013 "Binary attribute 'Photo' cannot be exposed through an OData +// entity.", for the entity's own attribute and for one it inherits. check and exec +// accepted both. Every other attribute type (String, HashedString, Integer, Long, +// Decimal, Boolean, DateTime, AutoNumber, Enumeration) exposes clean. +func publishedBinaryScript(expose string) string { + return `mdl 1; +create persistent entity Api.Base (Data: binary, Title: string(50)); +create persistent entity Api.Child extends Api.Base (Code: string(36) unique, Photo: binary, Name: string(50)); +create published odata service Api.Svc (path: 'odata/api/', version: '1.0.0', ODataVersion: OData4, namespace: 'My.Api', ServiceName: 'Api') +{ + publish entity Api.Child as 'Children' (ReadMode: source, InsertMode: not_supported, UpdateMode: not_supported, DeleteMode: not_supported) + expose (` + expose + `); +}; +` +} + +func TestValidatePublishedBinary(t *testing.T) { + cases := []struct { + name, expose string + want []string // attributes reported + }{ + {"no binary exposed (control)", "Code (KEY), Name, Title", nil}, + {"the entity's own binary attribute", "Code (KEY), Photo", []string{"Photo"}}, + {"an inherited binary attribute", "Code (KEY), Data", []string{"Data"}}, + {"both", "Code (KEY), Photo, Data", []string{"Photo", "Data"}}, + {"the name in another case", "Code (KEY), photo", []string{"photo"}}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + got := ValidatePublishedBinary(mustBuild(t, publishedBinaryScript(c.expose)), nil) + if len(got) != len(c.want) { + t.Fatalf("want %d violations, got %v: %+v", len(c.want), rulesOf(got), got) + } + for i, attr := range c.want { + v := got[i] + if v.RuleID != publishedBinaryRule || !strings.Contains(v.Message, "CE5013") || !strings.Contains(v.Message, attr) { + t.Errorf("violation %d: %+v", i, v) + } + } + }) + } +} + +// The entity lives in the project, not the script. +func TestValidatePublishedBinary_ProjectEntity(t *testing.T) { + mod := &model.Module{BaseElement: model.BaseElement{ID: "mod-pj"}, Name: "Pj"} + dm := &domainmodel.DomainModel{ + BaseElement: model.BaseElement{ID: "dm-pj"}, ContainerID: mod.ID, + Entities: []*domainmodel.Entity{ + {BaseElement: model.BaseElement{ID: "e1"}, Name: "Doc", Attributes: []*domainmodel.Attribute{ + {Name: "Code", Type: &domainmodel.StringAttributeType{Length: 36}}, + {Name: "Blob", Type: &domainmodel.BinaryAttributeType{}}, + }}, + }, + } + mb := &mock.MockBackend{ + IsConnectedFunc: func() bool { return true }, + GetModuleByNameFunc: func(name string) (*model.Module, error) { + if name == "Pj" { + return mod, nil + } + return nil, nil + }, + GetDomainModelFunc: func(id model.ID) (*domainmodel.DomainModel, error) { return dm, nil }, + } + open := func() backend.FullBackend { return mb } + src := func(expose string) string { + return `mdl 1; +create published odata service Pj.Svc (path: 'odata/pj/', version: '1.0.0', ODataVersion: OData4, namespace: 'Pj', ServiceName: 'Pj') +{ + publish entity Pj.Doc as 'Docs' (ReadMode: source, InsertMode: not_supported, UpdateMode: not_supported, DeleteMode: not_supported) + expose (` + expose + `); +}; +` + } + if got := ValidatePublishedBinary(mustBuild(t, src("Code (KEY)")), open); len(got) != 0 { + t.Errorf("control: want none, got %+v", got) + } + if got := ValidatePublishedBinary(mustBuild(t, src("Code (KEY), Blob")), open); len(got) != 1 { + t.Errorf("a project entity's binary attribute: want one, got %+v", got) + } + // Unknown entity, no project: not judged. + if got := ValidatePublishedBinary(mustBuild(t, src("Code (KEY), Blob")), nil); len(got) != 0 { + t.Errorf("no project: want none, got %+v", got) + } +} From 92fdae752f82cae8dbe0eb137852f972ef443cec Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 13:42:54 +0000 Subject: [PATCH 11/19] fix(test): --attach no longer refuses a microflow proxy as a Java change The nightly went red on the Mendix 11.15.0 and 11.16.0 legs in TestTestAttach_KeepsTheHostingAppsPageBundles: every `mxcli test --attach` was refused with "this change compiles to other Java classes, which the running runtime cannot load without a restart", although it only injects a test microflow. The project.jar guard of ako/mxcli#2640 counted any changed entry as new Java. Mendix generates a call stub per microflow in each module's proxies/microflows/Microflows class, and on 11.15/11.16 the attach's build recompiles it: a diagnostic build of the guard showed exactly one of 163 entries differing, mxtest/proxies/microflows/Microflows.class 860 -> 1128 bytes. The runtime runs microflows by name (the test endpoint calls Core.microflowCall), and Java that calls a new stub is a changed class of its own, so jarEntries now leaves microflow proxies out of the comparison. The running app's jar is still put back either way. Control: the unit test's proxy-only case fails with the filter stubbed (changed=true); a proxy change beside a real class change is still refused. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + cmd/mxcli/testrunner/jar_guard.go | 25 +++++++++++++++-- cmd/mxcli/testrunner/jar_guard_2640_test.go | 31 ++++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd0d5f55..6c6f75677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`test --attach` runs again on Mendix 11.15 and 11.16** — since the project.jar guard (ako/mxcli#2640), every attach on those versions was refused with "this change compiles to other Java classes": their build recompiles the generated microflow proxy, and the test microflow the attach injects adds a call stub to MxTest's `proxies/microflows/Microflows` class. The runtime runs microflows by name, so the guard no longer counts a microflow proxy as a Java change; the running app's jar is still put back, and any other changed class is still refused. - **true-right-false-down: nested false branches share the first row** (ako/mxcli#2650, upstream mendixlabs/mxcli#1978) — each `else` column of a nested decision started below every column nested inside its true branch. A flow with four guards put the outermost false branch at y = 1080 while the decisions sat at y = 200. Each column already stands at its own decision's x, so a column now starts on the first row under its decision. It drops lower only when something its true branch drew actually stands in the column's way. - **true-right-false-down: an `if` without `else` keeps TRUE on the line** (ako/mxcli#2636, upstream mendixlabs/mxcli#1971) — with `if-else: true-right-else-column`, an `if` without `else` whose true branch carries on was still drawn the default way round. The true branch went into a lane below the split, and the empty false branch ran to the merge on the main line. This happened both in `create` and in `mxcli layout flows`, which also swapped explicit `@anchor(true: (from: right))` back. Under that style, such an `if` is now laid out like one with an empty `else`: true on the line, and false running from the split's bottom into the merge's bottom. The model is unchanged, and `describe` still prints no `else`. Guards, whose true branch ends the flow, keep following the `guard` setting. - **mxcli no longer writes `@mxcli-layout:` into a flow's documentation** (ako/mxcli#2635, upstream mendixlabs/mxcli#1970) — in a project with a `layout-config.yaml`, every flow mxcli laid out gained an `@mxcli-layout: …` line in its Documentation, even when its style was the project's. Studio Pro showed it, generated documentation copied it, and it could not be removed through MDL, because the next write appended it again. The style is now never stored in the flow: `describe` judges positions against the project style, the one `create or modify` rebuilds in, so a round trip stays exact. A flow drawn in another style prints the `@position` lines that keep it. A line written by an older release is honoured once and then removed by the next write of the flow or by `mxcli layout flows`. diff --git a/cmd/mxcli/testrunner/jar_guard.go b/cmd/mxcli/testrunner/jar_guard.go index 6ce12556f..24bd59247 100644 --- a/cmd/mxcli/testrunner/jar_guard.go +++ b/cmd/mxcli/testrunner/jar_guard.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "path/filepath" + "strings" ) // jarGuard keeps the running runtime's project.jar readable across an @@ -18,8 +19,12 @@ import ( // attach drives rewrites the file in place — same size, new bytes — so the // next class the runtime had not loaded yet failed with NoClassDefFoundError, // caused by "ZipFile invalid LOC header (bad signature)". The test microflows -// an attach injects add no Java, so the rebuilt jar holds the same classes: -// putting the original bytes back leaves the runtime reading what it opened. +// an attach injects add no Java the runtime needs, so putting the original +// bytes back leaves the runtime reading what it opened. They do change one +// class: Mendix generates a call stub per microflow in each module's +// proxies/microflows/Microflows class (measured on 11.16.0: MxTest's grew from +// 860 to 1128 bytes, the jar's only changed entry), which sameJarEntries +// therefore leaves out. type jarGuard struct { path string data []byte @@ -66,7 +71,7 @@ func (g *jarGuard) settle() (changed bool, err error) { // sameJarEntries reports whether two jars hold the same entries with the same // contents (by CRC-32 and size), whatever order or timestamps they were written -// with. +// with, microflow proxies aside (isMicroflowProxy). func sameJarEntries(a, b []byte) (bool, error) { ea, err := jarEntries(a) if err != nil { @@ -99,7 +104,21 @@ func jarEntries(data []byte) (map[string]jarEntrySum, error) { } out := make(map[string]jarEntrySum, len(r.File)) for _, f := range r.File { + if isMicroflowProxy(f.Name) { + continue + } out[f.Name] = jarEntrySum{f.CRC32, f.UncompressedSize64} } return out, nil } + +// isMicroflowProxy reports whether a jar entry is a module's generated +// microflow call stubs. A new microflow, an injected test microflow among +// them, adds a method there, but the runtime runs microflows by name, and the +// test endpoint calls them with Core.microflowCall: only Java that calls the +// new stub needs the new class, and that Java is a changed class of its own, +// which the comparison still sees. Without this, every --attach on a Mendix +// version that recompiles the proxy for it was refused as a Java change. +func isMicroflowProxy(name string) bool { + return strings.HasSuffix(name, "/proxies/microflows/Microflows.class") +} diff --git a/cmd/mxcli/testrunner/jar_guard_2640_test.go b/cmd/mxcli/testrunner/jar_guard_2640_test.go index 3cbdc8a6f..fb6efa484 100644 --- a/cmd/mxcli/testrunner/jar_guard_2640_test.go +++ b/cmd/mxcli/testrunner/jar_guard_2640_test.go @@ -11,11 +11,15 @@ import ( "time" ) +// testProxy is MxTest's generated microflow proxy, the class an injected test +// microflow adds a call stub to. +const testProxy = "mxtest/proxies/microflows/Microflows.class" + func jarOf(t *testing.T, stamp time.Time, files map[string]string) []byte { t.Helper() var buf bytes.Buffer zw := zip.NewWriter(&buf) - for _, name := range []string{"a/A.class", "b/B.class", "c/C.class"} { + for _, name := range []string{"a/A.class", "b/B.class", "c/C.class", testProxy} { body, ok := files[name] if !ok { continue @@ -78,6 +82,31 @@ func TestJarGuard_2640(t *testing.T) { t.Error("the running app's jar was not put back after a Java change") } + // The attach's own change on Mendix 11.15/11.16, where its build recompiles + // the proxies: MxTest's microflow proxy gains the injected test microflow's + // call stub, and nothing else changes. That is no Java the running runtime + // needs, so nothing is refused, and its jar still goes back. + withProxy := jarOf(t, time.Date(2026, 11, 28, 9, 0, 0, 0, time.UTC), + map[string]string{"a/A.class": "AAAA", "b/B.class": "BBBB", testProxy: "stubs for 2 microflows"}) + _ = os.WriteFile(jar, withProxy, 0o644) + g = guardProjectJar(mpr) + _ = os.WriteFile(jar, jarOf(t, time.Now(), + map[string]string{"a/A.class": "AAAA", "b/B.class": "BBBB", testProxy: "stubs for 3 microflows, one a test"}), 0o644) + if changed, err := g.settle(); err != nil || changed { + t.Errorf("only the microflow proxy changed: changed=%v err=%v, want unchanged", changed, err) + } + if now, _ := os.ReadFile(jar); !bytes.Equal(now, withProxy) { + t.Error("the jar the runtime opened was not put back after a proxy-only change") + } + + // Control: the proxy changing beside a real class is still a Java change. + g = guardProjectJar(mpr) + _ = os.WriteFile(jar, jarOf(t, time.Now(), + map[string]string{"a/A.class": "CHANGED", "b/B.class": "BBBB", testProxy: "stubs for 3 microflows"}), 0o644) + if changed, err := g.settle(); err != nil || !changed { + t.Errorf("a class and the proxy changed: changed=%v err=%v, want changed", changed, err) + } + // No jar: nothing to guard. if g := guardProjectJar(filepath.Join(t.TempDir(), "X.mpr")); g != nil { t.Error("guarded a jar that does not exist") From 551ad932b657b438aba5af936eead1342b9fb013 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 13:46:09 +0000 Subject: [PATCH 12/19] findings: attach jar guard refused the injected microflow's proxy as Java Co-Authored-By: Claude Opus 5.5 --- .../2026-11-28-attach-jar-guard-refuses-microflow-proxy.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 .claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-attach-jar-guard-refuses-microflow-proxy.json diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-attach-jar-guard-refuses-microflow-proxy.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-attach-jar-guard-refuses-microflow-proxy.json new file mode 100644 index 000000000..b60a37463 --- /dev/null +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-28-attach-jar-guard-refuses-microflow-proxy.json @@ -0,0 +1 @@ +{"area":"cmd/mxcli","date":"2026-11-28","symptom":"The nightly goes red on the Mendix 11.15.0 and 11.16.0 legs (ako/mxcli run 46132208195, mendixlabs/mxcli run 46132550380), in `TestTestAttach_KeepsTheHostingAppsPageBundles`: `mxcli test --attach` exits 1 with `this change compiles to other Java classes, which the running runtime cannot load without a restart, and --attach cannot restart it`, although the attach only injects a test microflow. 10.24, 11.6, 11.12, 11.13, 11.14 and 11.17 are green","cause":"The project.jar guard of ako/mxcli#2640 (d43db2c1, merged the day before) counted any entry whose CRC or size changed as new Java. Mendix generates a call stub per microflow in each module's proxies/microflows/Microflows class, and on 11.15/11.16 the attach's build (the dev loop's incremental build, then a cold one on a private serve because web/dist lost its pages) recompiles it, so the injected test microflow changes mxtest/proxies/microflows/Microflows.class. The guard's comment assumed the injection adds no Java. The test needs a cached mxbuild and a runtime, so only the nightly runs it","file":"`cmd/mxcli/testrunner/jar_guard.go` (`isMicroflowProxy`, left out of `jarEntries`), `cmd/mxcli/testrunner/jar_guard_2640_test.go`","insight":"Measure what changed before deciding what a change means: a diagnostic build of the guard printing the differing entries showed exactly one, `mxtest/proxies/microflows/Microflows.class` 860 -> 1128 bytes, of 163. A microflow proxy is no Java the running runtime needs (it runs microflows by name, and the test endpoint calls Core.microflowCall); only Java calling the new stub would need it, and that Java is a changed class of its own, which the comparison still sees. When a guard gates the attach, run the attach integration test on every prebuilt-client version (11.14-11.17) before merging. Controls: the unit test's proxy-only case fails with the filter stubbed (changed=true); the integration test with the fix passes on 11.16.0 and 11.15.0 (the failing legs) and on 11.17.0","refs":["ako/mxcli nightly run 46132208195","mendixlabs/mxcli nightly run 46132550380","ako/mxcli#2640","mendixlabs/mxcli#1973"],"test":"cmd/mxcli/testrunner/jar_guard_2640_test.go; cmd/mxcli/cmd_test_attach_bundle_integration_test.go"} From dd04f8eeaba8a4195f604efb2bae79d3fc8f7b7d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 13:40:09 +0000 Subject: [PATCH 13/19] fix: alter page set (OnChange: ...) on a built-in input (#2602) `set (OnChange: call microflow ...) on txtAmount` was refused by check and exec as "not a pluggable widget and has no named action slots", though create page writes and describe prints the text box's OnChangeAction, and the refusal pointed at `set (Action: ...)`, which a text box does not have. OnEnter / OnLeave / OnEnterKeyPress were in the same state. A built-in widget's event action is now written into its stored key (OnChangeAction, OnEnterAction, OnLeaveAction, OnEnterKeyPressAction), by the MDL name or the stored one, and only where the stored widget holds that key; otherwise the refusal names the event actions it has. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...1-28-alter-set-onchange-builtin-input.json | 1 + .claude/skills/mendix/alter-page/SKILL.md | 4 +- CHANGELOG.md | 1 + cmd/mxcli/syntax/features_page.go | 2 +- mdl/backend/mutation.go | 5 +- mdl/backend/pagemutator/mutator.go | 68 +++++++++++++++- .../pagemutator/mutator_event_action_test.go | 80 +++++++++++++++++++ mdl/executor/cmd_alter_page.go | 3 +- 8 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-backend/2026-11-28-alter-set-onchange-builtin-input.json create mode 100644 mdl/backend/pagemutator/mutator_event_action_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-backend/2026-11-28-alter-set-onchange-builtin-input.json b/.claude/skills/fix-issue/findings/mdl-backend/2026-11-28-alter-set-onchange-builtin-input.json new file mode 100644 index 000000000..0733bc608 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-backend/2026-11-28-alter-set-onchange-builtin-input.json @@ -0,0 +1 @@ +{"area": "mdl-backend", "date": "2026-11-28", "refs": ["ako/mxcli#2602", "mendixlabs/mxcli#1953"], "symptom": "`alter page … set (OnChange: call microflow …) on txtAmount` was refused by check and exec as \"not a pluggable widget and has no named action slots\", though create page writes and describe prints the text box's OnChange; the refusal pointed at `set (Action: …)`, which addresses a click action a text box does not have. OnEnter / OnLeave / OnEnterKeyPress were in the same state.", "file": "mdl/backend/pagemutator/mutator.go (SetWidgetNamedAction, setBuiltInEventAction)", "cause": "Every action-valued SET key other than the click keyword went to SetWidgetNamedAction, which only knew pluggable widgets' Object.Properties slots and refused any widget without an Object.", "fix": "A built-in widget's event action is written into its stored key (OnChangeAction, OnEnterAction, OnLeaveAction, OnEnterKeyPressAction), addressed by the MDL name create page reads or the stored name, and only where the stored widget holds that key; otherwise refused naming the event actions it has.", "insight": "The dispatch was decided by key shape (click keyword vs anything else) when the widget kind is what decides where an action lives. The write-only-where-the-key-exists rule from SetWidgetAction carries over: Studio Pro throws on an unknown property while mxbuild builds clean.", "test": "mdl/backend/pagemutator/mutator_event_action_test.go TestSetWidgetNamedAction_BuiltInInputEvents_2602 (each event, both spellings, other events untouched) and _BuiltInWithoutTheEvent_2602 (text area, no OnEnterKeyPress) failed with the issue's message before the fix. Live (issue repro on testdata/expr-checker): check passes, exec alters, second exec unchanged, describe shows OCH_Updated and the new OnLeave; mx check 11.17.0's only error is CE0535 from the repro's bare `column`, the same on main without the alter."} diff --git a/.claude/skills/mendix/alter-page/SKILL.md b/.claude/skills/mendix/alter-page/SKILL.md index 7462e73ec..3b1359fb2 100644 --- a/.claude/skills/mendix/alter-page/SKILL.md +++ b/.claude/skills/mendix/alter-page/SKILL.md @@ -181,8 +181,7 @@ set (Action: call microflow Module.ACT_Other) on btnSave set (Action: SAVE CHANGES CLOSE PAGE) on btnSave set (Action: SHOW PAGE Module.DetailPage) on btnEdit --- Retarget ONE named action slot of a pluggable widget, by the widget's own --- property key (the same key `create page` takes: `createFileAction: …`). +-- ONE named action slot of a pluggable widget, by its property key (as `create page` takes it): set ('createFileAction': call microflow Module.ACT_CreateFile) on fileUploader1 set ('onSelectionChange': show page Module.Detail) on dgOrders @@ -214,6 +213,7 @@ so a silent write would build cleanly and then fail to open. |----------|-------------|------------|---------| | `Action` (alias `onClick`) | Widgets with an on-click action: ACTIONBUTTON, LINKBUTTON, CONTAINER, LISTVIEW, STATICIMAGE, DYNAMICIMAGE — and a pluggable widget's click slot (GALLERY / DATAGRID row click). A gallery row click on a single-click selection is refused under `mdl 1;` (MDL-WIDGET36): add `onClickTrigger: 'double'` to the SET, or `replace` the gallery with `Selection: None` | Any `create page` action expression | `set (Action: call microflow M.ACT_Go) on card1` | | `''` | Pluggable widgets — any **action-typed** property (File Uploader `createFileAction`, DataGrid 2 `onSelectionChange`, …) | Any `create page` action expression | `set ('createFileAction': call microflow M.ACT_Create) on fileUploader1` — refused, naming the widget's action slots, if the key is not action-typed | +| `OnChange`, `OnEnter`, `OnLeave`, `OnEnterKeyPress` | Built-in inputs: TEXTBOX, TEXTAREA, DATEPICKER, DROPDOWN, CHECKBOX, RADIOBUTTONS (`OnEnterKeyPress`: TEXTBOX only). The stored names (`OnChangeAction`, …) work too | Any `create page` action expression | `set (OnChange: call microflow M.OCH_Amount(Entry = $currentObject)) on txtAmount` — refused, naming the widget's event actions, if it has no such event | | `caption` | ACTIONBUTTON, LINKBUTTON | String | `set (caption: 'Submit') on btnSave` | | `content` | DYNAMICTEXT | String | `set (content: 'New Heading') on txtTitle` | | `RenderMode` | DYNAMICTEXT | Text, Paragraph, H1–H6 (any case; another value is refused, naming the set) | `set (RenderMode: H2) on txtTitle` | diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd0d5f55..430174b4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`alter page … set (OnChange: …)` works on built-in inputs** (ako/mxcli#2602, upstream mendixlabs/mxcli#1953) — `check` and `exec` refused it on a text box as "not a pluggable widget", though `create page` writes the same action and `describe` prints it. The refusal pointed at `set (Action: …)`, which fails too, because a text box has no click action. `OnChange`, `OnEnter`, `OnLeave` and, on a text box, `OnEnterKeyPress` are now set in place under either their MDL name or their stored name, so the widget's other settings are kept. A widget without that event is refused, naming the event actions it has. - **true-right-false-down: nested false branches share the first row** (ako/mxcli#2650, upstream mendixlabs/mxcli#1978) — each `else` column of a nested decision started below every column nested inside its true branch. A flow with four guards put the outermost false branch at y = 1080 while the decisions sat at y = 200. Each column already stands at its own decision's x, so a column now starts on the first row under its decision. It drops lower only when something its true branch drew actually stands in the column's way. - **true-right-false-down: an `if` without `else` keeps TRUE on the line** (ako/mxcli#2636, upstream mendixlabs/mxcli#1971) — with `if-else: true-right-else-column`, an `if` without `else` whose true branch carries on was still drawn the default way round. The true branch went into a lane below the split, and the empty false branch ran to the merge on the main line. This happened both in `create` and in `mxcli layout flows`, which also swapped explicit `@anchor(true: (from: right))` back. Under that style, such an `if` is now laid out like one with an empty `else`: true on the line, and false running from the split's bottom into the merge's bottom. The model is unchanged, and `describe` still prints no `else`. Guards, whose true branch ends the flow, keep following the `guard` setting. - **mxcli no longer writes `@mxcli-layout:` into a flow's documentation** (ako/mxcli#2635, upstream mendixlabs/mxcli#1970) — in a project with a `layout-config.yaml`, every flow mxcli laid out gained an `@mxcli-layout: …` line in its Documentation, even when its style was the project's. Studio Pro showed it, generated documentation copied it, and it could not be removed through MDL, because the next write appended it again. The style is now never stored in the flow: `describe` judges positions against the project style, the one `create or modify` rebuilds in, so a round trip stays exact. A flow drawn in another style prints the `@position` lines that keep it. A line written by an older release is honoured once and then removed by the next write of the flow or by `mxcli layout flows`. diff --git a/cmd/mxcli/syntax/features_page.go b/cmd/mxcli/syntax/features_page.go index e6962c91b..75dabd98b 100644 --- a/cmd/mxcli/syntax/features_page.go +++ b/cmd/mxcli/syntax/features_page.go @@ -350,7 +350,7 @@ LIST IMPACT OF htmlelement; "drop template", "insert template", "list view template", "add parameter", "drop parameter", "page parameter", "add parameters", }, - Syntax: "ALTER PAGE Module.Name { -- the generic ALTER: set / insert / replace / drop\n SET (property: value) ON widgetName; -- widget property names: any casing\n SET ('Row size': 'Small') ON lvOrders; -- an Atlas DESIGN property of that widget's\n -- type; quoted and case-sensitive.\n -- `list design properties for ` lists\n -- them. ON/OFF for a toggle, where OFF\n -- REMOVES the entry.\n -- A multi-select ('Hide on') or compound\n -- ('Spacing') one needs the inline\n -- DesignProperties: (...) form, because a\n -- SET assignment carries one value.\n SET (Action: CALL MICROFLOW Module.MF) ON btnSave; -- any CREATE PAGE action form\n SET ('createFileAction': CALL MICROFLOW Module.MF) ON fileUploader1;\n -- a pluggable widget's NAMED action slot,\n -- by the widget's own key; refused on a\n -- key that is not action-typed\n SET (DataSource: $Param) ON dvOrder; -- parameter/microflow/nanoflow/selection;\n -- DATABASE and association are REPLACE-only,\n -- and a data view takes no database source\n SET (RenderMode: H2) ON txtTitle; -- dynamic text: Text | Paragraph | H1..H6\n SET (NativeTextStyle: Heading2) ON txtTitle; -- dynamic text on a native page:\n -- Text | Heading1..Heading6\n SET (prop1: val1, prop2: val2) ON widgetName;\n SET (Title: 'New Title'); -- page-level (case-sensitive): no ON\n SET (Documentation: 'What this page is for.');\n SET (Class: 'css-class'); -- page-level CSS class / style\n SET (Style: 'css: rule');\n SET (PopupWidth: 800, PopupHeight: 480, PopupResizable: true); -- page-level pop-up\n SET ('Background color': 'Background Primary'); -- the page's own design\n -- property: no ON; OFF removes a toggle\n INSERT AFTER widgetName { };\n INSERT BEFORE widgetName { };\n INSERT INTO containerName { };\n INSERT INTO layoutGridName { ROW { COLUMN { } } }; -- appends rows;\n -- a row has no stored name, so only INTO\n -- the grid places one (not BEFORE/AFTER)\n INSERT INTO tabContainerName { TABPAGE tp (Caption: 'Two') { } };\n DROP name1, name2;\n DROP TEMPLATE FOR Module.Specialization IN listViewName;\n REPLACE widgetName WITH { };\n MOVE widgetName AFTER|BEFORE|INTO otherName; -- moves the stored widget as it is\n WRAP widgetName IN { dataview dvX (DataSource: $Param) { } }; -- puts a new container\n -- (container | dataview | groupbox, named)\n -- where the widget is, and moves the widget\n -- into it. Neither rebuilds the widget, so a\n -- legacy classic Data grid can be wrapped\n ADD PARAMETERS $Order: Module.Order; -- or a primitive: $Count: Integer.\n -- A page with a Url needs a {Order}\n -- segment: SET (Url: '…/{Order}') in the\n -- same statement (CE5601 otherwise).\n -- A snippet takes entities only (MDL087).\n DROP PARAMETERS $Order; -- refused while a data source or an\n -- expression on the page still uses it\n ADD VARIABLES $show: Boolean = true;\n DROP VARIABLES $show;\n};\n-- A target is a widget name, or a DataGrid 2 column by what it shows:\n-- grid column(Attr), grid column('Caption'), @n when two match; or a\n-- navigation list item: nav item(widgetInIt), nav item('Text'), nav item@n. The old spellings `SET p = v`,\n-- `SET p: v` (no parentheses) and `DROP WIDGET a` still run and warn\n-- (MDL-DEPR101..103).\n\n-- The BULK form: one design property on every widget of a TYPE.\nALTER PAGES [IN Module]\n SET 'Compact' = ON, 'Striped' = ON\n WHERE WIDGETTYPE = datagrid -- the MDL keyword, which resolves to\n -- exactly one widget id. A full id in\n -- quotes works too. NOT a name: a widget\n -- name is unique only within its page.\n [DRY RUN]; -- run this FIRST. It reports the matches\n -- against a discardable copy and writes\n -- nothing.", + Syntax: "ALTER PAGE Module.Name { -- the generic ALTER: set / insert / replace / drop\n SET (property: value) ON widgetName; -- widget property names: any casing\n SET ('Row size': 'Small') ON lvOrders; -- an Atlas DESIGN property of that widget's\n -- type; quoted and case-sensitive.\n -- `list design properties for ` lists\n -- them. ON/OFF for a toggle, where OFF\n -- REMOVES the entry.\n -- A multi-select ('Hide on') or compound\n -- ('Spacing') one needs the inline\n -- DesignProperties: (...) form, because a\n -- SET assignment carries one value.\n SET (Action: CALL MICROFLOW Module.MF) ON btnSave; -- any CREATE PAGE action form\n SET ('createFileAction': CALL MICROFLOW Module.MF) ON fileUploader1;\n -- a pluggable widget's NAMED action slot,\n -- by the widget's own key; refused on a\n -- key that is not action-typed\n SET (OnChange: CALL MICROFLOW Module.OCH(Entry = $currentObject)) ON txtAmount;\n -- a built-in input's event: OnChange,\n -- OnEnter, OnLeave, OnEnterKeyPress\n SET (DataSource: $Param) ON dvOrder; -- parameter/microflow/nanoflow/selection;\n -- DATABASE and association are REPLACE-only,\n -- and a data view takes no database source\n SET (RenderMode: H2) ON txtTitle; -- dynamic text: Text | Paragraph | H1..H6\n SET (NativeTextStyle: Heading2) ON txtTitle; -- dynamic text on a native page:\n -- Text | Heading1..Heading6\n SET (prop1: val1, prop2: val2) ON widgetName;\n SET (Title: 'New Title'); -- page-level (case-sensitive): no ON\n SET (Documentation: 'What this page is for.');\n SET (Class: 'css-class'); -- page-level CSS class / style\n SET (Style: 'css: rule');\n SET (PopupWidth: 800, PopupHeight: 480, PopupResizable: true); -- page-level pop-up\n SET ('Background color': 'Background Primary'); -- the page's own design\n -- property: no ON; OFF removes a toggle\n INSERT AFTER widgetName { };\n INSERT BEFORE widgetName { };\n INSERT INTO containerName { };\n INSERT INTO layoutGridName { ROW { COLUMN { } } }; -- appends rows;\n -- a row has no stored name, so only INTO\n -- the grid places one (not BEFORE/AFTER)\n INSERT INTO tabContainerName { TABPAGE tp (Caption: 'Two') { } };\n DROP name1, name2;\n DROP TEMPLATE FOR Module.Specialization IN listViewName;\n REPLACE widgetName WITH { };\n MOVE widgetName AFTER|BEFORE|INTO otherName; -- moves the stored widget as it is\n WRAP widgetName IN { dataview dvX (DataSource: $Param) { } }; -- puts a new container\n -- (container | dataview | groupbox, named)\n -- where the widget is, and moves the widget\n -- into it. Neither rebuilds the widget, so a\n -- legacy classic Data grid can be wrapped\n ADD PARAMETERS $Order: Module.Order; -- or a primitive: $Count: Integer.\n -- A page with a Url needs a {Order}\n -- segment: SET (Url: '…/{Order}') in the\n -- same statement (CE5601 otherwise).\n -- A snippet takes entities only (MDL087).\n DROP PARAMETERS $Order; -- refused while a data source or an\n -- expression on the page still uses it\n ADD VARIABLES $show: Boolean = true;\n DROP VARIABLES $show;\n};\n-- A target is a widget name, or a DataGrid 2 column by what it shows:\n-- grid column(Attr), grid column('Caption'), @n when two match; or a\n-- navigation list item: nav item(widgetInIt), nav item('Text'), nav item@n. The old spellings `SET p = v`,\n-- `SET p: v` (no parentheses) and `DROP WIDGET a` still run and warn\n-- (MDL-DEPR101..103).\n\n-- The BULK form: one design property on every widget of a TYPE.\nALTER PAGES [IN Module]\n SET 'Compact' = ON, 'Striped' = ON\n WHERE WIDGETTYPE = datagrid -- the MDL keyword, which resolves to\n -- exactly one widget id. A full id in\n -- quotes works too. NOT a name: a widget\n -- name is unique only within its page.\n [DRY RUN]; -- run this FIRST. It reports the matches\n -- against a discardable copy and writes\n -- nothing.", Example: "ALTER PAGE Module.EditPage {\n SET (Caption: 'Save & Close', ButtonStyle: Success) ON btnSave;\n INSERT AFTER txtName {\n TEXTBOX txtMiddleName (Label: 'Middle Name', Attribute: MiddleName)\n };\n DROP txtUnused;\n};", SeeAlso: []string{"page.create", "page.show", "snippet.alter"}, }) diff --git a/mdl/backend/mutation.go b/mdl/backend/mutation.go index 0d2f2b177..5b90f787b 100644 --- a/mdl/backend/mutation.go +++ b/mdl/backend/mutation.go @@ -107,7 +107,10 @@ type PageMutator interface { // SetWidgetNamedAction writes an action into a pluggable widget's action // slot addressed by the widget's own property key (e.g. the File Uploader's - // createFileAction). Refuses a key that is not an action-typed property. + // createFileAction), or into one of a built-in input's event actions + // (OnChange, OnEnter, OnLeave, OnEnterKeyPress — by that name or the stored + // one) where the stored widget has it (ako/mxcli#2602). Refuses a key that + // is neither. SetWidgetNamedAction(widgetRef string, propertyKey string, action pages.ClientAction) error // SetColumnProperty sets a property on a column within a grid widget. diff --git a/mdl/backend/pagemutator/mutator.go b/mdl/backend/pagemutator/mutator.go index 050312945..18837c461 100644 --- a/mdl/backend/pagemutator/mutator.go +++ b/mdl/backend/pagemutator/mutator.go @@ -327,9 +327,7 @@ func (m *Mutator) SetWidgetNamedAction(widgetRef, propertyKey string, action pag } obj := bsonnav.DGetDoc(result.widget, "Object") if obj == nil { - return fmt.Errorf("widget %q (%s) is not a pluggable widget and has no named action slots — "+ - "a built-in widget's click action is set with `set (Action: …) on %s`", - widgetRef, widgetTypeName(result.widget), widgetRef) + return m.setBuiltInEventAction(result.widget, widgetRef, propertyKey, action) } keys, kinds := pluggablePropertyTypes(result.widget) @@ -369,6 +367,70 @@ func (m *Mutator) SetWidgetNamedAction(widgetRef, propertyKey string, action pag widgetRef, propertyKey, slotList(actionSlots)) } +// builtInEventActions are the event actions a built-in input stores beside its +// click action: the MDL name CREATE PAGE reads (`OnChange:`) and the key the +// widget stores it under. Studio Pro's Events section, in its order. +var builtInEventActions = []struct{ key, stored string }{ + {"OnChange", "OnChangeAction"}, + {"OnEnter", "OnEnterAction"}, + {"OnLeave", "OnLeaveAction"}, + {"OnEnterKeyPress", "OnEnterKeyPressAction"}, +} + +// setBuiltInEventAction writes one of a built-in widget's event actions — a +// text box's OnChangeAction, say — addressed by its MDL name or its stored +// one. Before ako/mxcli#2602 every such key was refused as "not a pluggable +// widget", and the refusal pointed at `set (Action: …)`, which addresses the +// click action a text box does not have. +// +// The key is written only where the stored widget holds it, for the reason +// SetWidgetAction gives: Studio Pro throws on a property its type does not +// know, while mxbuild builds it clean. +func (m *Mutator) setBuiltInEventAction(widget bson.D, widgetRef, propertyKey string, action pages.ClientAction) error { + var has []string + stored := "" + for _, ev := range builtInEventActions { + present := false + for _, e := range widget { + if e.Key == ev.stored { + present = true + break + } + } + if present { + has = append(has, ev.key) + } + if strings.EqualFold(propertyKey, ev.key) || strings.EqualFold(propertyKey, ev.stored) { + stored = ev.stored + if !present { + stored = "-" + } + } + } + switch stored { + case "": + hint := "a built-in widget's click action is set with `set (Action: …) on " + widgetRef + "`" + if len(has) > 0 { + hint = "its event actions are: " + strings.Join(has, ", ") + "; " + hint + } + return fmt.Errorf("widget %q (%s) is not a pluggable widget and has no action %q — %s", + widgetRef, widgetTypeName(widget), propertyKey, hint) + case "-": + events := "none" + if len(has) > 0 { + events = strings.Join(has, ", ") + } + return fmt.Errorf("widget %q (%s) has no %s action — its event actions are: %s", + widgetRef, widgetTypeName(widget), propertyKey, events) + } + serialized := m.deps.SerializeClientAction(action) + if serialized == nil { + return fmt.Errorf("unsupported action type %T", action) + } + bsonnav.DSet(widget, stored, serialized) + return nil +} + // pluggablePropertyTypes maps a pluggable widget's PropertyType IDs to their // keys and to their value types ("Action", "Integer", …). func pluggablePropertyTypes(widget bson.D) (keys, kinds map[string]string) { diff --git a/mdl/backend/pagemutator/mutator_event_action_test.go b/mdl/backend/pagemutator/mutator_event_action_test.go new file mode 100644 index 000000000..14d53eff3 --- /dev/null +++ b/mdl/backend/pagemutator/mutator_event_action_test.go @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: Apache-2.0 + +package pagemutator + +import ( + "strings" + "testing" + + "go.mongodb.org/mongo-driver/v2/bson" + + "github.com/mendixlabs/mxcli/mdl/backend/bsonnav" + "github.com/mendixlabs/mxcli/model" + "github.com/mendixlabs/mxcli/sdk/pages" +) + +// ako/mxcli#2602: `alter page … set (OnChange: …) on txtAmount` was refused +// as "not a pluggable widget", though CREATE PAGE writes and DESCRIBE prints +// the text box's own OnChangeAction. A built-in input's event actions are +// written into the key the stored widget holds, by the MDL name or the stored +// one, as CREATE PAGE reads them. + +func textBoxWithEvents(name string, keys ...string) bson.D { + w := bson.D{{Key: "$Type", Value: "Forms$TextBox"}, {Key: "Name", Value: name}} + for _, k := range keys { + w = append(w, bson.E{Key: k, Value: noAction()}) + } + return w +} + +func storedAction(t *testing.T, m *Mutator, widget, key string) bson.D { + t.Helper() + result := m.widgetFinder(m.rawData, widget) + if result == nil { + t.Fatalf("widget %q not found", widget) + } + return bsonnav.DGetDoc(result.widget, key) +} + +func TestSetWidgetNamedAction_BuiltInInputEvents_2602(t *testing.T) { + all := []string{"OnChangeAction", "OnEnterAction", "OnLeaveAction", "OnEnterKeyPressAction"} + for _, c := range []struct{ key, stored string }{ + {"OnChange", "OnChangeAction"}, + {"onchange", "OnChangeAction"}, + {"OnChangeAction", "OnChangeAction"}, + {"OnEnter", "OnEnterAction"}, + {"OnLeave", "OnLeaveAction"}, + {"OnEnterKeyPress", "OnEnterKeyPressAction"}, + } { + t.Run(c.key, func(t *testing.T) { + m := New(makeRawPage(textBoxWithEvents("txtAmount", all...)), model.ID("u"), &stubActionDeps{serialized: microflowMarker}) + if err := m.SetWidgetNamedAction("txtAmount", c.key, &pages.MicroflowClientAction{MicroflowName: "M.F"}); err != nil { + t.Fatalf("set %s: %v", c.key, err) + } + for _, k := range all { + got := bsonnav.DGetString(storedAction(t, m, "txtAmount", k), "$Type") + want := "Forms$NoAction" + if k == c.stored { + want = "Forms$MicroflowClientAction" + } + if got != want { + t.Errorf("%s = %s, want %s", k, got, want) + } + } + }) + } +} + +func TestSetWidgetNamedAction_BuiltInWithoutTheEvent_2602(t *testing.T) { + // A text area has no OnEnterKeyPressAction: refused with that reason, and + // nothing written under a key Studio Pro would not know. + ta := bson.D{{Key: "$Type", Value: "Forms$TextArea"}, {Key: "Name", Value: "taNotes"}, {Key: "OnChangeAction", Value: noAction()}} + m := New(makeRawPage(ta), model.ID("u"), &stubActionDeps{serialized: microflowMarker}) + err := m.SetWidgetNamedAction("taNotes", "OnEnterKeyPress", &pages.MicroflowClientAction{MicroflowName: "M.F"}) + if err == nil || !strings.Contains(err.Error(), "OnEnterKeyPress") || !strings.Contains(err.Error(), "OnChange") { + t.Fatalf("got %v, want a refusal naming the missing event and the ones the widget has", err) + } + if storedAction(t, m, "taNotes", "OnEnterKeyPressAction") != nil { + t.Error("wrote OnEnterKeyPressAction on a text area") + } +} diff --git a/mdl/executor/cmd_alter_page.go b/mdl/executor/cmd_alter_page.go index 6a53b3894..7425ea749 100644 --- a/mdl/executor/cmd_alter_page.go +++ b/mdl/executor/cmd_alter_page.go @@ -559,7 +559,8 @@ func applySetProperties(ctx *ExecContext, mutator backend.PageMutator, op *ast.S } } else if isActionValue { // Any other key carrying an action is a pluggable widget's NAMED - // action slot — `set 'createFileAction' = microflow M.F` (#995). + // action slot — `set 'createFileAction' = microflow M.F` (#995) — + // or a built-in input's event action, `set (OnChange: …)` (#2602). // Same builder as `Action`; the mutator checks the key is an // action-typed property of the stored widget. Through // SetWidgetProperty it would be stringified into a PrimitiveValue. From e828d0ccdb3aca4e84948824c999437115f5dabd Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 14:08:05 +0000 Subject: [PATCH 14/19] check: reject call external action naming an action the contract lacks (CE7251, MDL111) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82tETa46YQmMS58pQjL --- ...xternal-action-not-in-contract-ce7251.json | 1 + CHANGELOG.md | 1 + .../validate_external_action_names.go | 148 ++++++++++++++++++ .../validate_external_action_names_test.go | 119 ++++++++++++++ mdl/executor/validate_program.go | 2 + 5 files changed, 271 insertions(+) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-28-external-action-not-in-contract-ce7251.json create mode 100644 mdl/executor/validate_external_action_names.go create mode 100644 mdl/executor/validate_external_action_names_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-external-action-not-in-contract-ce7251.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-external-action-not-in-contract-ce7251.json new file mode 100644 index 000000000..0bc7777b9 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-external-action-not-in-contract-ce7251.json @@ -0,0 +1 @@ +{"area": "mdl/executor", "date": "2026-11-28", "refs": ["ako/mxcli#1258"], "ce": ["CE7251", "CE0117"], "symptom": "`call external action M.Client.NotThere`, or the right action name in another case (`dothing` for `DoThing`), passed `check -p` and `exec`; `mx check` reported CE7251 \"Service 'M.Client' does not contain action 'dothing'.\" plus CE0117 on the output variable.", "file": "mdl/executor/validate_external_action_names.go ValidateExternalActionNames (MDL111), wired in validate_program.go; tests validate_external_action_names_test.go", "cause": "The flow builder's externalActionContract matches the action case-insensitively (strings.EqualFold) to type the result and the parameters, and the writer stores the name as typed, so a wrong-case name was typed correctly and written wrong; an absent name was simply written.", "insight": "**A lenient lookup in the builder is a strict one waiting to fail downstream.** The builder's EqualFold made a wrong-case action look resolved (its return type was found), which is exactly why nothing complained; Mendix compares the stored name exactly. The rule reads the contract stored on the project's consumed service (types.ParseEdmx over Metadata), and does not judge a service the script creates, alters or drops, whose contract is not the stored one. Needs `check -p`, so there is no no-project .fail fixture; proven end to end on a project with the contract imported (check -p and exec refuse NotThere and dothing, accept DoThing)."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd0d5f55..3ccfd4707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`check -p` rejects `call external action` naming an action the service does not have** (ako/mxcli#1258) — an action missing from the consumed service's contract, or the right name in another case, passed `check` and `exec`, and the build reported CE7251 "Service … does not contain action …". New MDL111, which reads the contract stored on the project's consumed service and lists the actions it has. Action names are case-sensitive. A service the script itself creates or changes is not judged. Measured on MxBuild 11.16.1. - **true-right-false-down: nested false branches share the first row** (ako/mxcli#2650, upstream mendixlabs/mxcli#1978) — each `else` column of a nested decision started below every column nested inside its true branch. A flow with four guards put the outermost false branch at y = 1080 while the decisions sat at y = 200. Each column already stands at its own decision's x, so a column now starts on the first row under its decision. It drops lower only when something its true branch drew actually stands in the column's way. - **true-right-false-down: an `if` without `else` keeps TRUE on the line** (ako/mxcli#2636, upstream mendixlabs/mxcli#1971) — with `if-else: true-right-else-column`, an `if` without `else` whose true branch carries on was still drawn the default way round. The true branch went into a lane below the split, and the empty false branch ran to the merge on the main line. This happened both in `create` and in `mxcli layout flows`, which also swapped explicit `@anchor(true: (from: right))` back. Under that style, such an `if` is now laid out like one with an empty `else`: true on the line, and false running from the split's bottom into the merge's bottom. The model is unchanged, and `describe` still prints no `else`. Guards, whose true branch ends the flow, keep following the `guard` setting. - **mxcli no longer writes `@mxcli-layout:` into a flow's documentation** (ako/mxcli#2635, upstream mendixlabs/mxcli#1970) — in a project with a `layout-config.yaml`, every flow mxcli laid out gained an `@mxcli-layout: …` line in its Documentation, even when its style was the project's. Studio Pro showed it, generated documentation copied it, and it could not be removed through MDL, because the next write appended it again. The style is now never stored in the flow: `describe` judges positions against the project style, the one `create or modify` rebuilds in, so a round trip stays exact. A flow drawn in another style prints the `@position` lines that keep it. A line written by an older release is honoured once and then removed by the next write of the flow or by `mxcli layout flows`. diff --git a/mdl/executor/validate_external_action_names.go b/mdl/executor/validate_external_action_names.go new file mode 100644 index 000000000..d4e5c4968 --- /dev/null +++ b/mdl/executor/validate_external_action_names.go @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "fmt" + "sort" + "strings" + + "github.com/mendixlabs/mxcli/mdl/ast" + "github.com/mendixlabs/mxcli/mdl/backend" + "github.com/mendixlabs/mxcli/mdl/linter" + "github.com/mendixlabs/mxcli/mdl/types" +) + +// externalActionNameRule is the rule ID for "`call external action` names an action +// the consumed service's contract does not have". +const externalActionNameRule = "MDL111" + +// `call external action M.Client.Action` must name an action of the consumed +// service's contract, exactly. Measured on MxBuild 11.16.1 against a contract with +// one action, DoThing: +// +// DoThing clean +// NotThere CE7251 "Service 'M.Client' does not contain action 'NotThere'." +// dothing CE7251 (action names are case-sensitive) +// +// with CE0117 on the output variable either way. check and exec accepted both: the +// builder matches the name case-insensitively to type the result, and writes it as +// typed. +// +// The contract is the one stored on the project's consumed service. A service the +// script creates, alters or drops is not judged (its contract is not the stored +// one), nor is one with no stored contract, nor anything without a project. +func ValidateExternalActionNames(prog *ast.Program, open func() backend.FullBackend) []linter.Violation { + if prog == nil || open == nil { + return nil + } + changed := map[string]bool{} + var calls []struct { + flow ast.QualifiedName + stmt *ast.CallExternalActionStmt + } + for _, stmt := range prog.Statements { + switch s := stmt.(type) { + case *ast.CreateODataClientStmt: + changed[strings.ToLower(s.Name.String())] = true + case *ast.AlterODataClientStmt: + changed[strings.ToLower(s.Name.String())] = true + case *ast.DropODataClientStmt: + changed[strings.ToLower(s.Name.String())] = true + case *ast.CreateMicroflowStmt: + name := s.Name + forEachMicroflowStatement(s.Body, func(ms ast.MicroflowStatement) { + if c, ok := ms.(*ast.CallExternalActionStmt); ok && c.ActionName != "" { + calls = append(calls, struct { + flow ast.QualifiedName + stmt *ast.CallExternalActionStmt + }{name, c}) + } + }) + } + } + if len(calls) == 0 { + return nil + } + contracts := projectConsumedContracts(open) + if len(contracts) == 0 { + return nil + } + + var out []linter.Violation + for _, c := range calls { + svc := qualifyIn(c.flow.Module, c.stmt.ServiceName.String()) + key := strings.ToLower(svc) + if changed[key] { + continue + } + actions, ok := contracts[key] + if !ok { + continue + } + if actions[c.stmt.ActionName] { + continue + } + names := make([]string, 0, len(actions)) + for a := range actions { + names = append(names, a) + } + sort.Strings(names) + fix := fmt.Sprintf("%s has no actions.", svc) + if len(names) > 0 { + fix = fmt.Sprintf("Use one of %s's actions, spelled exactly (names are case-sensitive): %s.", svc, strings.Join(names, ", ")) + } + out = append(out, linter.Violation{ + RuleID: externalActionNameRule, + Severity: linter.SeverityError, + Message: fmt.Sprintf("microflow %s: `call external action %s.%s` names an action the service's contract does not have — "+ + "mxbuild reports CE7251 \"Service '%s' does not contain action '%s'\"", + c.flow, svc, c.stmt.ActionName, svc, c.stmt.ActionName), + Location: linter.Location{Module: c.flow.Module, DocumentType: "microflow", DocumentName: c.flow.Name}, + Suggestion: fix, + }) + } + return out +} + +// projectConsumedContracts is the action names of each project consumed service +// that stores a contract, keyed by lower-cased qualified name. A service whose +// contract does not parse is left out, so it is not judged. +func projectConsumedContracts(open func() backend.FullBackend) map[string]map[string]bool { + out := map[string]map[string]bool{} + b := open() + if b == nil { + return out + } + modules, err := b.ListModules() + if err != nil { + return out + } + names := map[string]string{} + for _, m := range modules { + if m != nil { + names[string(m.ID)] = m.Name + } + } + services, err := b.ListConsumedODataServices() + if err != nil { + return out + } + for _, svc := range services { + if svc == nil || svc.Metadata == "" || names[string(svc.ContainerID)] == "" { + continue + } + doc, err := types.ParseEdmx(svc.Metadata) + if err != nil || doc == nil { + continue + } + actions := map[string]bool{} + for _, a := range doc.Actions { + if a != nil && a.Name != "" { + actions[a.Name] = true + } + } + out[strings.ToLower(names[string(svc.ContainerID)]+"."+svc.Name)] = actions + } + return out +} diff --git a/mdl/executor/validate_external_action_names_test.go b/mdl/executor/validate_external_action_names_test.go new file mode 100644 index 000000000..d1b7d23b1 --- /dev/null +++ b/mdl/executor/validate_external_action_names_test.go @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "strings" + "testing" + + "github.com/mendixlabs/mxcli/mdl/backend" + "github.com/mendixlabs/mxcli/mdl/backend/mock" + "github.com/mendixlabs/mxcli/model" +) + +// `call external action M.Client.Action` must name an action the consumed service's +// contract has, exactly. Measured on MxBuild 11.16.1 against a contract with one +// action, DoThing: `DoThing` clean; `NotThere` and `dothing` (the right name in +// another case) CE7251 "Service 'M.Client' does not contain action 'dothing'.", with +// CE0117 on the output variable. check and exec accepted both: the builder matches +// the name case-insensitively to type the result but writes it as typed. +const externalActionContract = ` + + + + + + + + + + + +` + +func externalActionBackend() func() backend.FullBackend { + mod := &model.Module{BaseElement: model.BaseElement{ID: "mod-pj"}, Name: "Pj"} + svc := &model.ConsumedODataService{ContainerID: mod.ID, Name: "Client", Metadata: externalActionContract} + mb := &mock.MockBackend{ + IsConnectedFunc: func() bool { return true }, + ListModulesFunc: func() ([]*model.Module, error) { return []*model.Module{mod}, nil }, + ListConsumedODataServicesFunc: func() ([]*model.ConsumedODataService, error) { return []*model.ConsumedODataService{svc}, nil }, + } + return func() backend.FullBackend { return mb } +} + +func externalActionFlow(action string) string { + return `mdl 1; +create microflow Pj.MF () returns boolean begin + $R = call external action Pj.Client.` + action + ` (Input = 'x'); + return true; +end; +` +} + +func TestValidateExternalActionNames(t *testing.T) { + open := externalActionBackend() + cases := []struct { + name, action string + want bool + }{ + {"an action the contract has (control)", "DoThing", false}, + {"an action it does not have", "NotThere", true}, + {"the right name in another case", "dothing", true}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + got := ValidateExternalActionNames(mustBuild(t, externalActionFlow(c.action)), open) + if !c.want { + if len(got) != 0 { + t.Fatalf("want none, got %+v", got) + } + return + } + if len(got) != 1 { + t.Fatalf("want one, got %v: %+v", rulesOf(got), got) + } + v := got[0] + if v.RuleID != externalActionNameRule || !strings.Contains(v.Message, "CE7251") || + !strings.Contains(v.Message, c.action) || !strings.Contains(v.Suggestion, "DoThing") { + t.Errorf("violation: %+v", v) + } + }) + } +} + +// Not judged: no project, a service the project does not have, a service the +// script creates or changes (its contract is not the stored one), a service with no +// stored contract. +func TestValidateExternalActionNames_NotJudged(t *testing.T) { + if got := ValidateExternalActionNames(mustBuild(t, externalActionFlow("NotThere")), nil); len(got) != 0 { + t.Errorf("no project: want none, got %+v", got) + } + open := externalActionBackend() + other := strings.Replace(externalActionFlow("NotThere"), "Pj.Client.", "Pj.Elsewhere.", 1) + if got := ValidateExternalActionNames(mustBuild(t, other), open); len(got) != 0 { + t.Errorf("unknown service: want none, got %+v", got) + } + recreated := `mdl 1; +create or modify consumed odata service Pj.Client (ODataVersion: OData4, MetadataUrl: './x.xml'); +` + strings.TrimPrefix(externalActionFlow("NotThere"), "mdl 1;\n") + if got := ValidateExternalActionNames(mustBuild(t, recreated), open); len(got) != 0 { + t.Errorf("a service the script rewrites: want none, got %+v", got) + } +} + +// A nanoflow cannot call an external action, so only microflows are walked; the +// call inside a branch is found. +func TestValidateExternalActionNames_Nested(t *testing.T) { + src := `mdl 1; +create microflow Pj.MF ($B: boolean) returns boolean begin + if $B then + $R = call external action Pj.Client.NotThere (Input = 'x'); + end if; + return true; +end; +` + if got := ValidateExternalActionNames(mustBuild(t, src), externalActionBackend()); len(got) != 1 { + t.Errorf("a call inside an if: want one, got %+v", got) + } +} diff --git a/mdl/executor/validate_program.go b/mdl/executor/validate_program.go index 575885e70..7d498e1ca 100644 --- a/mdl/executor/validate_program.go +++ b/mdl/executor/validate_program.go @@ -447,6 +447,8 @@ func ValidateProgram(prog *ast.Program, projectPath string) []linter.Violation { violations = append(violations, ValidateMappingHandlerTypes(prog, project)...) // A `split type` without its subject's own entity, with a duplicate, or with an entity that is not a specialization (CE0090/CE0771/CE0774). violations = append(violations, ValidateInheritanceSplits(prog, project)...) + // `call external action` naming an action the consumed service's contract does not have (CE7251). + violations = append(violations, ValidateExternalActionNames(prog, project)...) // Flag a REST client operation whose Body/Response mapping clause has no // `{ ... }` body — Mendix cannot reference a mapping document from an From c8290858b209406bb711e70b98bf3b98a266e816 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 14:14:01 +0000 Subject: [PATCH 15/19] feat: @size(w, h) on activities and decisions (#2589) A Studio Pro-resized activity or decision is stored as its Size. Describe printed nothing for it and MDL could not set it, so drop + create from the description reset every box to the default and a generated flow could not be sized. @size, until now a loop's box, now sizes an activity or a decision too; describe prints it for a box that is not the builder's default. In place, `create or modify` resizes the stored box when the script states another @size (a new Resize mutator op that keeps the centre), and a statement without one keeps its stored box, as one without @position keeps its place. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...6-11-28-size-on-activities-and-splits.json | 1 + CHANGELOG.md | 1 + cmd/mxcli/syntax/features_microflow.go | 4 +- docs-site/src/language/microflow-structure.md | 7 ++ mdl/backend/mfmutator/splice.go | 25 +++++ mdl/backend/microflow_mutation.go | 4 + mdl/executor/cmd_flow_modify.go | 11 ++- mdl/executor/cmd_flow_modify_patch.go | 48 +++++++++- .../cmd_microflows_builder_annotations.go | 16 +++- mdl/executor/cmd_microflows_layout_test.go | 2 +- mdl/executor/cmd_microflows_show_helpers.go | 28 ++++++ mdl/executor/flow_built_match_layout.go | 14 ++- mdl/executor/flow_declared_match.go | 5 +- mdl/executor/flowlayout_size_test.go | 92 +++++++++++++++++++ 14 files changed, 248 insertions(+), 10 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-28-size-on-activities-and-splits.json create mode 100644 mdl/executor/flowlayout_size_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-size-on-activities-and-splits.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-size-on-activities-and-splits.json new file mode 100644 index 000000000..e0576c2c8 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-size-on-activities-and-splits.json @@ -0,0 +1 @@ +{"area": "mdl-executor", "date": "2026-11-28", "refs": ["ako/mxcli#2589", "mendixlabs/mxcli#1947"], "symptom": "A Studio Pro-resized activity or decision (ActionActivity 260;90, ExclusiveSplit 220;120) described with no size and MDL had no annotation for it, so drop + create from the description reset every box to 120x60 / 90x60 and a generated flow could not be sized. Once @size was written, a changed @size in `create or modify` still reported Unchanged.", "file": "mdl/executor/cmd_microflows_builder_annotations.go (applyAnnotations), cmd_microflows_show_helpers.go (resizedBox), cmd_flow_modify_patch.go (resizedNode), flow_declared_match.go (positionFields), flow_built_match_layout.go (layoutStatements.sizes), mdl/backend/mfmutator/splice.go (Resize)", "cause": "@size was parsed into ActivityAnnotations.Size but only loops and merges read it; describe printed it only for loops. In place, three gates hid a size change: builtAsStored's comparison up to layout sets an object's Size aside when the script states no position for it, sameExceptPositions treated Size as a difference that sent the pair to a gap that redraws nothing, and moved() read the left-over Size as 'a node inside the Log is moved'.", "fix": "The builder sets Size on ActionActivity / ExclusiveSplit / InheritanceSplit from @size; describe prints @size for a box that is not the builder's default, independent of whether the position is derived. In place, Size counts as a node-placement field like Position: movedNode records a Resize (a new mutator op that keeps the centre) or, for a loop, fitLoop; a stated @size is compared even when the position is the layout pass's.", "insight": "An annotation's write path is three paths: create, describe, and the in-place splice — and the splice has gates (built-as-stored, the LCS pairing modes, moved()) that each have a list of geometry fields. A new geometry field has to be added to each, or the splice reports Unchanged over a real change. A test that only does drop + create proves the first two.", "test": "mdl/executor/flowlayout_size_test.go TestSizeAnnotationOnActivitiesAndSplits_2589 (written, printed only for non-default boxes, drop + create from the description keeps the geometry) and TestSizeAnnotationResizesInPlace_2589 (a changed @size resizes only that box; control: a script without @size keeps the stored box). Both failed before the fix: sizes not written; then 'Unchanged'; then MDL-V1-REBUILD 'a node inside the Log is moved'."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 94c8fd31d..05afef222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`@size(w, h)` on activities and decisions** (ako/mxcli#2589, upstream mendixlabs/mxcli#1947) — Studio Pro stores a resized activity or decision as its size. `describe` did not print it and MDL could not set it, so a drop and create from the description reset every box to the default, and a generated flow could not be given a size. `@size`, until now a loop's box, now sizes an activity or a decision too. `describe` prints it for a box that is not the default 120×60 or 90×60. `create or modify` resizes the stored box when the script states another `@size`, and a statement without one keeps its stored box. - **`alter page … set (OnChange: …)` works on built-in inputs** (ako/mxcli#2602, upstream mendixlabs/mxcli#1953) — `check` and `exec` refused it on a text box as "not a pluggable widget", though `create page` writes the same action and `describe` prints it. The refusal pointed at `set (Action: …)`, which fails too, because a text box has no click action. `OnChange`, `OnEnter`, `OnLeave` and, on a text box, `OnEnterKeyPress` are now set in place under either their MDL name or their stored name, so the widget's other settings are kept. A widget without that event is refused, naming the event actions it has. - **`test --attach` runs again on Mendix 11.15 and 11.16** — since the project.jar guard (ako/mxcli#2640), every attach on those versions was refused with "this change compiles to other Java classes": their build recompiles the generated microflow proxy, and the test microflow the attach injects adds a call stub to MxTest's `proxies/microflows/Microflows` class. The runtime runs microflows by name, so the guard no longer counts a microflow proxy as a Java change; the running app's jar is still put back, and any other changed class is still refused. - **true-right-false-down: nested false branches share the first row** (ako/mxcli#2650, upstream mendixlabs/mxcli#1978) — each `else` column of a nested decision started below every column nested inside its true branch. A flow with four guards put the outermost false branch at y = 1080 while the decisions sat at y = 200. Each column already stands at its own decision's x, so a column now starts on the first row under its decision. It drops lower only when something its true branch drew actually stands in the column's way. diff --git a/cmd/mxcli/syntax/features_microflow.go b/cmd/mxcli/syntax/features_microflow.go index 742d11bdd..0b9182bcb 100644 --- a/cmd/mxcli/syntax/features_microflow.go +++ b/cmd/mxcli/syntax/features_microflow.go @@ -1017,7 +1017,9 @@ func init() { "@merge(x, y) -- the implicit merge that closes a split\n" + "@merge(x, y, w, h) -- … and its box, when not the default 40x40\n" + "@size(w, h) -- a LOOP's box, a `while true`'s loop-head merge,\n" + - " -- or a `merge