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..e95d9490a --- /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": ["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)"} 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"} 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/.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/.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/fix-issue/findings/mdl-executor/2026-11-28-bare-layoutgrid-column-weight-one.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-bare-layoutgrid-column-weight-one.json new file mode 100644 index 000000000..294230df4 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-bare-layoutgrid-column-weight-one.json @@ -0,0 +1 @@ +{"area": "mdl-executor", "date": "2026-11-28", "refs": ["ako/mxcli#2602"], "symptom": "A layout-grid `column { … }` with no DesktopWidth was written at Weight 1 — one twelfth of the row. On an 11.6.6 project mx check failed the row with CE0535 \"The weights of the columns in a row must add up to 12, but currently they add up to 1\"; `check` was clean. Found while reproducing #2602, whose script used a bare column.", "file": "mdl/executor/cmd_pages_builder_v3_layout.go (buildLayoutGridColumnV3, shareBareColumnWeights), validate_layoutgrid_row_weights.go (MDL-GRID01)", "cause": "buildLayoutGridColumnV3 defaulted Weight to 1, a value no Studio Pro row uses for a full-width column.", "fix": "A bare column is unset until its row shares what the stated widths leave of 12 in equal whole shares (one 12, two 6+6, beside a 6 another 6); with no whole share it stays unset, which the writer stores as auto-fill (-1). check warns (MDL-GRID01) about a row whose widths do not add up to 12 in a project below 11.12.", "insight": "The CE0535 rule is version-dependent and the obvious fix (default to AutoFill, what Studio Pro 11.14 pages use 325 times) is wrong for older projects: measured, mx on an 11.6.6 project refuses AutoFill as -1, AutoFit as -2 and 6+4 as 10, while 11.12.6 and 11.14.0 projects accept all of them. The relaxation lies between 11.6.6 and 11.12.6 and is not pinned, so the check is a warning. A scan of Studio Pro weights must read int64 (BSON 0x12): an int32-only scan found no auto-fill columns in a project that has 325.", "test": "mdl/executor/cmd_pages_layoutgrid_bare_column_test.go TestLayoutGridBareColumnsShareTheRow (failed with [1], [1 1], [6 1] before the fix) and TestValidateLayoutGridRowWeights (11.6 warns on 6+4, AutoFill, five bare; 11.12 never). Live on the 11.6.6 fixture: one bare, two bare and 6+bare pages mx check 0 errors (CE0535 each before); describe prints DesktopWidth: 6 for the shared column; check warns MDL-GRID01 on 6+4."} diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-call-ml-model-action.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-call-ml-model-action.json new file mode 100644 index 000000000..fa191887f --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-call-ml-model-action.json @@ -0,0 +1 @@ +{"area": "mdl-executor", "date": "2026-11-28", "refs": ["ako/mxcli#2623", "mendixlabs/mxcli#1964"], "symptom": "A microflow with a Call ML model activity (Microflows$MLModelCallAction) described as `-- Unsupported action: Microflows$MLModelCallAction`, so describe → exec removed the activity from the model.", "file": "sdk/microflows/microflows_actions.go (MLModelCallAction), mdl/backend/modelsdk/microflow_read_actions.go + microflow_write.go, MDLMicroflow.g4 callMlModelStatement (+ ML in MDLLexer / the keyword rule), visitor_microflow_actions.go, cmd_microflows_builder_calls.go (addCallMLModelAction, mlMappingOutputEntity), cmd_microflows_format_action.go, validate.go (mlMappings), modelsdk/mpr/reader_raw.go (mlmapping alias)", "cause": "The action had a generated metamodel type but no SDK type, no reader/writer case, no MDL statement and no describe case.", "fix": "`[$Out =] call ml model Module.Mapping($In) [on error …];` builds Microflows$MLModelCallAction with Studio Pro's exact keys (ErrorHandlingType, InputVariableName, MlMappingDocument, VariableName — no ModelCall, deleted in 9.18); describe prints it back. The output variable is typed as the mapping document's MlModelMappings.Output.Entity, read by name through a new `mlmapping` raw-unit alias. check --references refuses a mapping that does not exist (mxbuild CE1613); a nanoflow refuses the statement (MDL091). ML is a new keyword, listed in the keyword rule so it stays a name.", "insight": "With no Studio Pro project holding an ML mapping (it needs an ONNX model), the reporter's BSON was the reference: the encoded keys are compared with it exactly. Live, mxbuild 11.17.0 loaded the written activity as a 'Call ML model' activity and reported only the absent mapping (CE1613), which is the proof the shape is right short of a real model.", "test": "mdl/backend/modelsdk/microflow_ml_model_call_test.go (Studio Pro key set, read of the reporter's BSON); mdl/executor/cmd_microflows_ml_model_call_test.go (build + describe fixed point; references with a mock: existing mapping passes, missing refused — fails with the check stubbed; output entity resolved). Live on testdata/expr-checker: exec writes the issue's exact keys, describe prints the statement, second exec unchanged; mx check 11.17.0: only CE1613 for the absent mapping."} 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/.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/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-external-modify-attribute-ce6616-ce6621.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-external-modify-attribute-ce6616-ce6621.json new file mode 100644 index 000000000..98bd1c2bb --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-28-external-modify-attribute-ce6616-ce6621.json @@ -0,0 +1 @@ +{"area": "mdl/executor", "date": "2026-11-28", "refs": ["ako/mxcli#1258"], "ce": ["CE6616", "CE6621"], "symptom": "`alter entity modify attribute A ` that changed a mapped attribute's type class (Integer to Decimal, String to Integer) or a string's length away from the contract passed `check -p` and `exec`; `mx check` reported CE6616 (type) or CE6621 (max length).", "file": "mdl/executor/validate_external_modify_attribute.go ValidateExternalModifyAttribute (MDL112), wired in validate_program.go; tests validate_external_modify_attribute_test.go", "cause": "The two neighbouring statements were guarded (`create or modify external entity` refuses a type change, MDL-V1-REMOTETYPE; `add attribute` an unmapped one, CE6612) but `modify attribute` applied the new type to the stored attribute without comparing it with the service.", "insight": "**MxBuild compares attribute type CLASSES, not types: its own message says 'Integer/Long'.** Qty Edm.Int32 modified to long builds clean, so a strict type-equality rule would have refused a valid change. The rule compares classes (Integer/Long one, Decimal, Boolean, DateTime, String) and, for an Edm.String, the length against the contract's MaxLength (none or max = unlimited, which `string` and `string(unlimited)` both store as 0). It reads the contract, not the stored attribute, so a modify that repairs a drifted attribute back to the contract is not refused. A key with no MaxLength is not judged (the importer bounds it to 100 itself). Not covered here: `add attribute` on an external entity is refused by exec and by check --references, but not by plain check -p."} 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/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/.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/.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/.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/.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/.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 a5ed854d3..26954b80f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **`check -p` rejects `modify attribute` on an external entity that leaves the service's type** (ako/mxcli#1258) — changing a mapped attribute to another type class (an Edm.Int32 to `decimal`, an Edm.String to `integer`) or a string to another length than the contract's passed `check` and `exec`, and the build reported CE6616 or CE6621. New MDL112, which reads the contract stored on the consumed service. Integer and Long count as one class, as Mendix compares them, so `long` for an Edm.Int32 is accepted. Measured on MxBuild 11.16.1. +- **`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. +- **`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. +- **`@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. +- **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). - **`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. - **`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** (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. +- **Call ML model activities survive describe → exec** (ako/mxcli#2623, upstream mendixlabs/mxcli#1964) — `describe` printed a Call ML model activity as `-- Unsupported action: Microflows$MLModelCallAction`, so executing the description removed the activity. It now has a statement, `[$Out =] call ml model Module.MLModelMapping($In) [on error …];`, which writes Studio Pro's stored shape and is what `describe` prints. The output variable is typed as the mapping's output entity. `check --references` refuses a mapping that does not exist (mxbuild CE1613), and a nanoflow refuses the statement. `mxcli syntax microflow.ml-model`. +- **A layout-grid column with no `DesktopWidth` is no longer one twelfth wide** — it was written at weight 1. A project before Mendix 11.12 failed the row with CE0535 ("must add up to 12"), and 11.12 drew the column at one twelfth of the row. Bare columns now share what the row's stated widths leave of 12, as Studio Pro's row presets do: one bare column gets 12, and two get 6 each. A bare column is AutoFill when there is no whole share. `check` warns (MDL-GRID01) about a row whose widths do not add up to 12 in a project below 11.12, where mxbuild reports CE0535 (measured on 11.6.6; 11.12.6 accepts it). ## [0.34.0] - 2026-11-27 diff --git a/cmd/mxcli/cmd_git_merge.go b/cmd/mxcli/cmd_git_merge.go index 3fb321e95..fa8ce615d 100644 --- a/cmd/mxcli/cmd_git_merge.go +++ b/cmd/mxcli/cmd_git_merge.go @@ -106,7 +106,15 @@ 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). 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: 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 @@ -125,6 +133,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 +146,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 +158,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 +658,142 @@ func projectMendixVersion(mprPath string) string { return v } -// realMxMerge shells out to `mx merge -v BASE MINE THEIRS` over the three +// resolveMxForMerge, localMxForMerge and mergeMxVersion are injected for tests. +var ( + resolveMxForMerge = docker.ResolveMxForVersion + localMxForMerge = docker.LocalMxForVersion + 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. +// +// 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 != "" { + 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 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 +// 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 +1205,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/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/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 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 new file mode 100644 index 000000000..7d1596763 --- /dev/null +++ b/cmd/mxcli/gitmerge_mx_version_test.go @@ -0,0 +1,143 @@ +// 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, 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) + 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/cmd/mxcli/lsp_completions_gen.go b/cmd/mxcli/lsp_completions_gen.go index d342666e7..40baeba9e 100644 --- a/cmd/mxcli/lsp_completions_gen.go +++ b/cmd/mxcli/lsp_completions_gen.go @@ -306,6 +306,7 @@ var mdlGeneratedKeywords = []protocol.CompletionItem{ {Label: "ARTIFACT", Kind: protocol.CompletionItemKindKeyword, Detail: "Widget keyword"}, {Label: "INCLUDED", Kind: protocol.CompletionItemKindKeyword, Detail: "Widget keyword"}, {Label: "MODEL", Kind: protocol.CompletionItemKindKeyword, Detail: "Widget keyword"}, + {Label: "ML", Kind: protocol.CompletionItemKindKeyword, Detail: "Widget keyword"}, {Label: "MODELS", Kind: protocol.CompletionItemKindKeyword, Detail: "Widget keyword"}, {Label: "AGENT", Kind: protocol.CompletionItemKindKeyword, Detail: "Widget keyword"}, {Label: "AGENTS", Kind: protocol.CompletionItemKindKeyword, Detail: "Widget keyword"}, diff --git a/cmd/mxcli/syntax/features_microflow.go b/cmd/mxcli/syntax/features_microflow.go index 9333eec79..ccf84df56 100644 --- a/cmd/mxcli/syntax/features_microflow.go +++ b/cmd/mxcli/syntax/features_microflow.go @@ -95,6 +95,28 @@ func init() { SeeAlso: []string{"microflow.error-handling", "rest.call", "microflow.nanoflow"}, }) + Register(SyntaxFeature{ + Path: "microflow.ml-model", + Features: []string{"microflows/ml_model_call"}, + Summary: "CALL ML MODEL — Studio Pro's Call ML model activity, through an ML model mapping", + Keywords: []string{"ml", "ml model", "call ml model", "machine learning", "onnx", "ml mapping", "model mapping"}, + Syntax: "[$Output =] CALL ML MODEL Module.MLModelMapping($Input) [ON ERROR ...];\n\n" + + "Microflow only (MDL091 in a nanoflow). Microflows$MLModelCallAction: the\n" + + "mapping document (MLMappings$MLMappingDocument, made in Studio Pro from an\n" + + "ONNX model) names an input and an output entity; $Input is an object of the\n" + + "input entity and $Output becomes an object of the output entity.\n" + + "Describe prints the activity in this form, so describe → exec keeps it\n" + + "(ako/mxcli#2623).", + Example: "mdl 1;\n" + + "create or modify microflow Sales.ACT_PredictChurn ($Input: Sales.ChurnInput)\n" + + "returns Decimal\n" + + "begin\n" + + " $Prediction = call ml model Sales.ChurnModelMapping($Input);\n" + + " return $Prediction/Probability;\n" + + "end;", + SeeAlso: []string{"microflow.error-handling", "microflow.nanoflow"}, + }) + Register(SyntaxFeature{ Path: "microflow.metrics", Features: []string{"microflows/metrics_activities"}, @@ -307,8 +329,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"}, @@ -1015,7 +1039,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