fix: resolve page context tree for ALTER PAGE and check --references by engalar · Pull Request #158 · mendixlabs/mxcli · GitHub
Skip to content

fix: resolve page context tree for ALTER PAGE and check --references#158

Merged
ako merged 1 commit intomendixlabs:mainfrom
engalar:fix/page-context-tree
Apr 9, 2026
Merged

fix: resolve page context tree for ALTER PAGE and check --references#158
ako merged 1 commit intomendixlabs:mainfrom
engalar:fix/page-context-tree

Conversation

@engalar
Copy link
Copy Markdown
Contributor

@engalar engalar commented Apr 9, 2026

Summary

  • ALTER PAGE REPLACE/INSERT failed when widgets referenced page parameters (DataSource: $Param) or sibling widgets (DataSource: SELECTION widget) because buildWidgetsBson created a pageBuilder with empty paramScope and widgetScope
  • mxcli check --references had no validation for page-internal context consistency (parameter refs, selection refs, attribute bindings without data container)

Changes

  • buildWidgetsBson now accepts the raw page BSON and pre-populates context via extractPageParamsFromBSON (page params → paramScope/paramEntityNames) and extractWidgetScopeFromBSON (widget tree → widgetScope)
  • New validatePageContextTree in mxcli check --references catches:
    • PARAMETER DataSource referencing undeclared page params
    • SELECTION DataSource referencing nonexistent widget names
    • Attribute bindings outside any data container context

Addresses #122, #157 (§1 ALTER PAGE REPLACE param resolution, §2 ALTER PAGE INSERT SELECTION resolution)

Test plan

  • 7 unit tests for BSON extraction (extractPageParamsFromBSON, extractWidgetScopeFromBSON)
  • 7 unit tests for page context tree validation (validatePageContextTree)
  • mxcli check --references verified with valid and invalid MDL scripts against baseline project
  • Full test suite passes, no regressions

…endixlabs#122, mendixlabs#157)

ALTER PAGE REPLACE/INSERT operations failed when widgets referenced page
parameters (DataSource: $Param) or sibling widgets (DataSource: SELECTION
widget) because buildWidgetsBson created an empty pageBuilder context.

Now extractPageParamsFromBSON and extractWidgetScopeFromBSON pre-populate
the builder's paramScope and widgetScope from the raw page BSON.

Also adds validatePageContextTree to mxcli check --references, catching:
- PARAMETER DataSource refs to undeclared page params
- SELECTION DataSource refs to nonexistent widget names
- Attribute bindings outside any data container context
Copy link
Copy Markdown
Collaborator

@ako ako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix with clear root cause. Two well-separated parts:

  1. ALTER PAGE context resolution: Extracts param scope and widget scope from existing page BSON before building new widgets. The BSON walker correctly handles page/snippet formats and nested containers (LayoutGrid, TabPages, CustomWidget properties, FooterWidgets).

  2. check --references validation: validatePageContextTree is a clean AST-only pass — no MPR needed. Catches undeclared parameter refs, nonexistent selection refs, and attribute bindings without data container context.

Good test coverage (14 tests) including nil/edge cases.

LGTM.

@ako ako merged commit 76b4342 into mendixlabs:main Apr 9, 2026
2 checks passed
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.

2 participants