Skip to content

feat(plan): add mxcli plan to predict conflicts between several MDL scripts - #2019

Open
italo-kalil-cesar wants to merge 21 commits into
mendixlabs:mainfrom
italo-kalil-cesar:pr/plan-command
Open

italo-kalil-cesar wants to merge 21 commits into
mendixlabs:mainfrom
italo-kalil-cesar:pr/plan-command

Conversation

@italo-kalil-cesar

@italo-kalil-cesar italo-kalil-cesar commented Dec 2, 2026 •

Copy link
Copy Markdown

Closes #2012

Marked ready for review. The direction (a new top-level command, versus a mode of check) is the open question in the issue.

What was wrong

When several people or agents write MDL scripts against the same project, nothing tells you before mxcli exec a.mdl b.mdl ... that two of them set the same property of the same element, rewrite the same document, or depend on each other in the wrong order. The conflict is only found (or silently lost) after the model has been written.

What changes

New command mxcli plan a.mdl b.mdl [...], backed by a new package mdl/plan. It needs no project and executes nothing: it parses the scripts (in the order given, which is the order they would be applied) and predicts from the AST what each one touches and where two collide.

  • CONFLICT: the same property of the same element is set by two scripts, a document is rewritten by both, a script uses what another one drops or renames before it, or needs a document created by a script that comes after it.
  • ORDER: both are fine but the apply order decides the result.
  • DEPENDS: a script uses a document another one creates (order is right).

Changes to different elements of the same document compose and are not reported. Statement types the planner does not model are listed; --strict exits 3 for them when there is no conflict. Exit 1 on a conflict, 2 on a usage or parse error. --findings-only prints only the findings.

Commits: (1) mdl/plan and its tests, (2) the command, a docs-site page and the CHANGELOG entry, (3) the issue number in the CHANGELOG. plan.go imports mdl/ast and mdl/visitor; nothing else from mxcli.

Known limits (also in the docs page)

It is a warning tool, not a guarantee that scripts do not conflict.

  • Inserts in an alter of a microflow/nanoflow become CONFLICT (in a page/workflow they become ORDER).
  • replace body of $L collides with any other alter of the same flow (probable false positive).
  • A string with a dot and no space counts as a reference (false positive).
  • alter entity + drop entity of the same entity gives no finding.
  • Only module:* statements end up in the not-modelled list.
  • Missing test coverage in plan_test.go: page insert/move/wrap/layout, workflow outcome/path, navigation/menu, security, domain-model associations.
  • The command itself has no test (it calls os.Exit); only the package is tested.

Tests

  • go test ./mdl/plan: passes (more than 70 generic cases in plan_test.go; no case uses a real project).
  • Manual run of the built binary on small generic scripts: no conflict (exit 0), conflict (exit 1), --strict with a not-modelled statement (exit 3), parse error (exit 2), --findings-only, and a single argument (exit 2).

Run locally

Done by hand on Windows (no make): go build ./cmd/mxcli, go vet ./cmd/mxcli ./mdl/plan, gofmt -l cmd/mxcli mdl/plan (empty), go test ./mdl/plan, go test ./mdl/conformance (docs examples parse; passes), scripts/check-test-timeouts.sh (passes). Not run here: make lint-go itself, make check-findings (no bug fix, no finding added). CI should cover those.

Studio Pro validation

N/A: the command does not read or write a project.

Agentic testing

The scripts used for the manual run were written and executed by the agent that prepared this PR; no agent-authored test beyond mdl/plan/plan_test.go is included.

Update: more tests

Five test-only commits were added on top (plan.go and the command are unchanged):

  • cmd/mxcli/cmd_plan_test.go: the command itself, run in a child process: exit 0, 1 (with and without --findings-only), 2 (parse error, fewer than two scripts, missing file) and 3 (--strict).
  • mdl/plan: page alters (insert, move, wrap, replace, layout, parameters, variables, snippets), workflow, navigation and menu, security grants, associations and rename, three or more scripts, cycles, nanoflow callees, and AnalyzeFiles (BOM, parse error, missing file, duplicate names). Package coverage is now about 94%.

The tests that pin behaviour that looks wrong have SUSPECT in their name and describe it in a comment; none was fixed here: an anchor matches by substring (drop w1 collides with insert after w10), drop T1 outcome 'X' with drop T1 gives no finding, a workflow boundary event never collides, create association M.A_B followed by create entity M.A_B is reported as a conflict, and rename ... dry run before the create is reported as a wrong order. Still not covered: alter settings / project security, generic alter entity, move/drop of enumerations and constants, and the branch operations of workflows.

Update 2: coverage to 100%, and three planner fixes

  • Coverage of mdl/plan is now 100% of statements (new plan_coverage_test.go). Every uncovered branch was either reachable from an MDL script (a test of the behaviour) or only by building the AST by hand (a direct unit test). Four defensive guards (firstTarget's unexported-field skip, two in createdName, one in removedName) have no path from the parser today; I kept them and tested them directly.
  • I ran the suspect behaviours listed above against the real binary and exec, and fixed three (one commit each, with the tests that documented them now asserting the right result):
    • An anchor is matched by widget, not by substring: drop w1 no longer collides with insert after w10 (they compose); drop w10 still collides with an insert after it.
    • A reference nested more than about ten levels deep is no longer missed (the walk's depth limit was 40 steps and each level costs about four; a pointer already visited already stops cycles, so the limit is only a backstop now).
    • Two ALTER PAGES ... SET LAYOUT over the same pages (same module, same WHERE LAYOUT filter) are a CONFLICT whatever their target layouts are: run in series the second overwrites the first. Another module or another filter still composes; a project-wide statement and a one-module one are not compared to each other.
  • Checked and left as is: a fragment defined by two scripts is a CONFLICT, and that is right for a batch: in one process the second CREATE FRAGMENT F fails with "fragment already exists" and the batch is rolled back (separate exec processes compose, since a fragment dies with its process). The test now says so.
  • Still open, all of them loud failures (an error and a rollback) rather than a silent overwrite: drop template for ... in lv is not modelled and never collides with a drop of that list view; a drop of an outcome or condition of an activity does not collide with a drop of the activity itself, although one order fails with "target not found"; a move between modules is not modelled (a move to another folder composes, which is right).

Update 3: moves, nesting and an optional project

Six more commits (all in mdl/plan and cmd/mxcli/cmd_plan*; coverage of mdl/plan is still 100%; each commit passes go test ./mdl/plan on its own). Each ordering below was checked against exec on a copy of testdata/pedapp.

  • A dropped list view template (drop template for X in lv) now counts as a change of that list view: it collides with a drop, replace, wrap or move of the lv, and with a second drop of the same template; other templates, other list views and other properties still compose.
  • Dropping a workflow activity collides with its outcomes, paths and branches (only the ancestor that destroys counts, and only in a workflow).
  • Moves. Every MOVE is keyed by document type and name, so a move to a folder and a move to another module of the same document meet. Moving to a folder composes with an alter and does not change the name; moving to another module collides with an alter or drop of the old name, and also creates the new name (so a create of it in another script, or a script using it before the move, is reported). A test walks every document type MOVE accepts (32 types and 5 aliases) and checks that its key equals the key of the create and drop of the same type; no divergence was found.
  • A folder moved into another module (move folder M.F to Other) cannot be modelled without knowing what the folder holds: it is listed as not modelled (--strict exits 3). New, optional: mxcli plan --use-project -p app.mpr a.mdl b.mdl reads the folder's documents from the project (read-only, no lock) and plans one move per document. Without the flag plan never opens a project, as before. Anything it cannot resolve stays not modelled. The folder is read as it is on disk now; documents that earlier scripts put in it or take out are not seen.
  • Widget nesting. A drop or replace of a widget collides with a touch on any widget shown inside it, when the scripts themselves show the tree (create page, create snippet, insert, replace, wrap, move into). Wrap and move of the ancestor do not collide (checked: they compose). Without a script that shows the tree, nesting of an existing page is still unknown, since that needs the page's widget tree from the project.
  • Docs: docs-site/src/tools/plan.md describes --use-project and the limits below.

Still not modelled, and each fails loudly (an error and a rollback), never a silent overwrite: a move of a folder inside one module has no entity equivalent; create or replace ... folder 'X' with an explicit folder is not compared with a move; a move followed by a drop of the new name is reported as a conflict although it works; associations that start to cross modules after a move.

italo-kalil-cesar and others added 3 commits December 1, 2026 22:56
Add a package that reads several MDL scripts, in the order they would be
applied, and predicts from the AST alone what each one touches and where two
of them collide. It needs no project and executes nothing.

Findings are CONFLICT (same property of the same element, a document
rewritten by both, a script using what another drops or renames earlier or
needing a document created by a later one), ORDER (the order decides the
result) and DEPENDS (a script uses a document another one creates). Changes
to different elements of one document compose and are not reported.
Statement types the planner does not model are listed separately.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Wire mdl/plan into a new command: `mxcli plan a.mdl b.mdl ...` reads the
scripts in the order given and prints what each touches and where two of
them collide, without a project and without executing anything.

Exit status is 1 on a conflict, 2 on a usage or parse error, and 3 with
--strict when a statement type is not modelled and there is no conflict.
--findings-only prints only the findings.

Add a docs-site page (with the known limits) and a CHANGELOG entry.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
italo-kalil-cesar and others added 18 commits December 2, 2026 13:49
Add behaviour tests for ALTER SETTINGS and ALTER PROJECT SECURITY, MOVE,
CREATE FRAGMENT, bulk statements named by something other than Name,
create or modify entity, the legacy drop condition, OnClick menu edits,
the depth limit of the reference walk and the Write output. Defensive and
contract tests cover branches the parser cannot reach. Behaviour that looks
wrong is documented with SUSPECT in the test name; plan.go is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A drop of w1 was reported as colliding with an insert after w10, because the anchor test was strings.Contains over the anchor text. The two compose (w1 is dropped and the widget lands after w10): run in series with exec they do. An insert's Elem is already the widget it anchors on, so comparing the Elem is enough and a drop of w10 still collides with an insert after w10. The test that documented the false positive now asserts that the two compose.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
refsOf stopped walking at depth 40, but each level of nesting in a statement costs about four steps (pointer, interface, struct, slice), so a reference under roughly ten nested blocks or widgets was missed and a script using an entity another one drops went unreported. A pointer already visited stops a cycle, so the limit only needs to be a backstop; it is now 10000. Run without --no-check, exec refuses such a script anyway (nothing is written), so this closes a gap in the warning, not in the safety net.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Two ALTER PAGES ... SET LAYOUT statements over the same pages overwrite each other, the last one wins and the result depends on the order, but they were keyed by the target layout, so the planner saw different units and reported nothing. The touch is now keyed by the pages the statement covers (the module, or every module, and the WHERE LAYOUT filter), so a repeat over the same pages is a CONFLICT like the single-page SET Layout, while another module or another filter still composes. A project-wide statement and a one-module statement are not compared to each other. The fragment test now says why its CONFLICT is right: in a batch (one process) the second CREATE FRAGMENT of a name fails with 'fragment already exists' and the batch is rolled back.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A "drop template for X in lv" was recorded as a guess on the whole page,
and a guess is never destructive, so it never met a script that dropped,
replaced, moved or wrapped the list view. Applied after such a script it
fails ("widget lv not found") and the batch is rolled back, yet the plan
said the scripts compose in any order.

It is now a set of template:<specialization> on the list view: it collides
with drop/replace/wrap/move of that list view and with a second drop of the
same template, and still composes with other properties, other list views,
other templates of the same list view and inserts beside its widgets.
The catch-all branch for unknown page operations is now covered with a nil
operation, the only value the parser never produces.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…paths and branches with it

An outcome, path or branch of a workflow activity is the element act:T1/outcome:B, which is neither equal to act:T1 nor part of an anchor, so a drop or replace of the activity never met a drop of one of its outcomes (or a legacy drop condition ... on the activity). Run with the activity drop first the outcome drop fails (alter target T1 not found) and the batch is rolled back; run the other way round the outcome change is silently moot. The plan said the scripts compose in any order.

A drop, replace, wrap or move of an activity now collides with a change of anything it owns, in a workflow only (a menu caption may contain a slash). The reverse is not a collision: a drop of an outcome says nothing about its task, and a set on the task or a drop of a different outcome or another activity still composes. The case that documented the gap as SUSPECT now asserts the conflict, and drop condition and drop path get the same checks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…or the other scripts

A MOVE statement carries no document-type word in its name, so it was keyed by the bare name (:M.P) and never met an alter or a drop of the page (page:M.P). Moved into another module the page is Other.P, so an alter or drop of M.P applied after the move fails (page not found) and the batch is rolled back, yet the plan said the scripts compose in any order.

A move whose target module differs from the document's own is now keyed by the document type and name, the same unit as the alter, drop and create statements, and collides with them (an entity is keyed in its domain model and as entity:M.E, where ALTER ENTITY lives). The document type is the MOVE spelling without its spaces. A move to a folder or to the module the document is already in keeps its name and composes, as before, and a create or replace of the freed old name composes with the move in either order. The two SUSPECT cases now assert the correct behaviour for a folder move, and the cross-module cases are new.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A move to a folder was keyed by the bare name, apart from the create, drop and alter of the same document, so a move into another module followed by a move of the old name to a folder (which fails at exec: page not found) went unnoticed. Key every MOVE by document type and name. A move within the module becomes movefolder, which composes with alters, rewrites, drops after it and grants, collides with another move of the document, and fails after a move into another module.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ment

A move into another module touched only the old name, so a script that created Other.P, dropped it, moved something else into it or used it before the move went unnoticed, although the move fails at exec when the name is taken and the user fails when the name does not exist yet. The move now also creates the document under its new name (for an entity, in the domain model of the target module), so the rules of any other create apply: a clash is a CONFLICT, a user applied after is DEPENDS and one applied before is a CONFLICT.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… document type

Only five document types had been checked against the create and drop of the same type. Walk every type the MOVE accepts (the registry the parser reads, so a type added later is checked too) and assert that the move is keyed with the same kind word as the CREATE and the DROP of that type, built from the statement as the parser or the AST gives it, and that the R10 and AI model aliases read as their canonical type. No divergence was found among the 32 types; building block and icon collection have no create or drop in MDL, and entity lives in its domain model and is checked against create entity, drop entity and alter entity.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…or plan it from the project

A MOVE FOLDER into another module moves every document in the folder, which the scripts do not say, so plan treated it like the move of one folder and missed every collision with the documents inside it. Without a project it is now listed as not modelled, with the statement and the reason (so --strict exits 3). With the new --use-project flag, plan opens the project given by -p read-only (without a lock, and never unless asked for, so plan still needs no project) and plans one move per document the folder holds there now, folders below it included; a document type MOVE does not know, or a folder the project cannot list, keeps the statement not modelled. Documents that scripts applied earlier put in the folder are not known to it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…it along

Dropping or replacing a widget takes the widgets inside it along, but the planner only compared touches of the very same widget name, so dropping a container did not collide with a change of the list view inside it (for example dropping its template). Read the nesting the scripts write out (create page and snippet bodies, placeholders, insert, replace, wrap and move into) into a tree per page or snippet, and make a drop or replace of a widget collide with a change of any widget shown inside it, in either order, except an inner drop applied before the outer one. Wrapping or moving the outer widget leaves the inner ones findable, as exec confirms, so they compose. A widget the replacement brings again stays. Without a script that shows the nesting nothing is known of the page as the project has it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… nesting

Document the new --use-project option, the folder move that is not modelled without it, and the limits that remain: the new name of a moved document, create or replace with a folder, associations of a moved entity, the folder contents as the project has them now, and widget nesting known only from the scripts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: mxcli plan - predict conflicts between several MDL scripts from the AST, before running them

1 participant