From 8a47b0b5cb920260b74c4c8844e1a0928a484b93 Mon Sep 17 00:00:00 2001 From: Uraz Akgultan Date: Fri, 28 Aug 2026 16:05:35 +0200 Subject: [PATCH 01/18] feat(navigation): create NativePhone navigation profiles --- .../skills/mendix/manage-navigation/SKILL.md | 63 +++++++--- CHANGELOG.md | 13 ++ cmd/mxcli/syntax/features_misc.go | 20 ++- docs/01-project/MDL_QUICK_REFERENCE.md | 4 +- .../modelsdk/navigation_profile_add.go | 108 +++++++++++++++- .../modelsdk/navigation_profile_add_test.go | 116 ++++++++++++++++++ mdl/backend/navigation.go | 10 +- mdl/executor/cmd_navigation.go | 14 ++- mdl/types/navigation_profile_kind.go | 38 +++++- 9 files changed, 348 insertions(+), 38 deletions(-) diff --git a/.claude/skills/mendix/manage-navigation/SKILL.md b/.claude/skills/mendix/manage-navigation/SKILL.md index f1d7764d46..9abd807d8d 100644 --- a/.claude/skills/mendix/manage-navigation/SKILL.md +++ b/.claude/skills/mendix/manage-navigation/SKILL.md @@ -10,19 +10,20 @@ description: "Inspect and change navigation profiles in MDL — home pages, menu | lines | section | |---|---| -| 32-41 | When to Use This Skill | -| 42-60 | Navigation Concepts | -| 61-78 | Show Commands (Read-Only) | -| 79-382 | CREATE OR MODIFY NAVIGATION | -| 383-421 | Change One Item: ALTER NAVIGATION | -| 422-432 | Round-Trip Workflow | -| 433-454 | Catalog Queries | -| 455-494 | Common Patterns | -| 495-547 | Menu Documents (standalone, reusable) | -| 548-618 | Offline Profiles | -| 619-635 | Checklist | -| 636-639 | Offline synchronization (`CREATE NAVIGATION … SYNC (…)`) | -| 640-642 | Menu documents (CREATE OR MODIFY/DESCRIBE/DROP MENU) | +| 33-42 | When to Use This Skill | +| 43-63 | Navigation Concepts | +| 64-81 | Show Commands (Read-Only) | +| 82-385 | CREATE OR MODIFY NAVIGATION | +| 386-424 | Change One Item: ALTER NAVIGATION | +| 425-435 | Round-Trip Workflow | +| 436-457 | Catalog Queries | +| 458-497 | Common Patterns | +| 498-550 | Menu Documents (standalone, reusable) | +| 551-621 | Offline Profiles | +| 622-650 | Native Profiles | +| 651-668 | Checklist | +| 669-672 | Offline synchronization (`CREATE NAVIGATION … SYNC (…)`) | +| 673-675 | Menu documents (CREATE OR MODIFY/DESCRIBE/DROP MENU) | # Navigation Management Skill @@ -49,7 +50,9 @@ Use when the user asks to: | `Phone` | `PhoneOffline` | | `Tablet` | `TabletOffline` | - An invented name (`Mobile`, `Desktop`) is an error, not a new profile: Mendix routes on **User-Agent** to its own kinds, so a profile the platform does not define can never be reached. Native profiles are a different document type and are not creatable from MDL. + An invented name (`Mobile`, `Desktop`) is an error, not a new profile: Mendix routes on **User-Agent** to its own kinds, so a profile the platform does not define can never be reached. + + Native profiles are a different document type (`Navigation$NativeNavigationProfile`, no `Kind` property — identified purely by `$Type` + `Name`) and have their own, separate closed set: currently just `NativePhone`. `create or modify navigation NativePhone` creates it the same way the web kinds are created. Hybrid is not supported (no reference document exists for it). A freshly created NativePhone profile has no bottom bar menu items — `create navigation NativePhone (menu (...))` does not fill them in yet, so a page whose layout requires a bottom bar (CE6108) needs its bottom bar item added in Studio Pro until that gap closes. - **Offline Profiles** — An offline profile makes the app work without a connection (a PWA with a local database that syncs). It is not a different document — same properties as its online twin — but it **constrains every page it can reach**, see below. - **Home Page** — The default page shown after login. Can be a PAGE or MICROFLOW. - **Role-Based Home Pages** — Override the default home page per user role (e.g., admins see a dashboard, users see a task list). @@ -616,12 +619,42 @@ starts empty and Studio Pro fills it from the entities the reachable pages use; only rows that differ from the defaults (`syncMode: Online`, no constraint) are stored. MDL does not author per-entity sync modes — set those in Studio Pro. +## Native Profiles + +`NativePhone` is created the same way: + +```sql +create navigation NativePhone + home page NativeMobile.Home_Native; +``` + +It is a different document type (`Navigation$NativeNavigationProfile`) from the +web kinds above — no `Kind` property, identified purely by `$Type` + `Name` — +but the statement and the create-then-fill flow are the same. + +**The bottom bar menu is not filled in yet.** Unlike the web `menu (...)` block, +`create navigation NativePhone (menu (...))` does not write bottom bar items for +a native profile — a separate, already-tracked gap. If the home page's layout +has "Bottom bar" enabled, Mendix requires that page to appear in the profile's +bottom bar menu and reports **CE6108** ("If the bottom bar is enabled on a home +page, then that page must be included in the bottom bar menu of the native +navigation profile...") until it is added in Studio Pro. Point the home page at +a layout with no bottom bar, or add the bottom bar item in Studio Pro, to avoid +it. + +A profile with no home page at all (`create navigation NativePhone;` with +nothing else) is a valid **empty** profile — Mendix requires a home page before +the profile can actually route anywhere, reported as **CE0527** ("Select a +default home page for this profile in the navigation document") until one is +set, same as leaving a web profile's home page unset. + ## Checklist -- [ ] Profile name is one of Mendix's web kinds (`Responsive`/`Phone`/`Tablet`, or their `*Offline` twins) — an invented name is an error, not a new profile +- [ ] Profile name is one of Mendix's web kinds (`Responsive`/`Phone`/`Tablet`, or their `*Offline` twins), or the native kind (`NativePhone`) — an invented name is an error, not a new profile - [ ] For an **offline** profile, no page it can reach binds an attribute across more than one association (CE6206) - [ ] For an **offline** profile, `progressive web app ( Precaching: true )` is set — without it no page opens offline - [ ] `app title` is set — a new project's browser tab reads `Mendix - ` otherwise +- [ ] For a **native** profile, the home page's layout does not require a bottom bar entry mxcli cannot yet write (CE6108) — or add that entry in Studio Pro - [ ] All PAGE/MICROFLOW targets are fully qualified (`Module.Name`) - [ ] Role references in `for` clauses are fully qualified (`Module.Role`) - [ ] Menu items are in `{ }` with no `;` between them; sub-menu items in `menu 'caption' { ... }` diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c7d59eeb..b6b283d707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1443,6 +1443,19 @@ Headline: **Widgets become first-class MDL rather than a second dialect.** Every - **`make digest-status` measures how far the bug-pattern digest has fallen behind**, per area — coverage is computed rather than quoted, because a figure written into prose is stale the next time anyone appends a finding. +- **`create navigation NativePhone`** — the native counterpart to web navigation + profile creation (`f2e7c67a`, `b032ec05`). A native profile has no `Kind` + property at all (`Navigation$NativeNavigationProfile`, identified purely by + `$Type` + `Name`), so it gets its own builder rather than a branch in the web + one. Unlike the web kinds, no live Studio Pro create-and-read-back exists for + native profiles (PED/MCP explicitly rejects native profile authoring), so the + shape is pinned against a real Studio-Pro-authored NativePhone profile instead + — see the doc comment on `newNativeProfileBson`. `UpdateNavigationProfile` + does not yet write bottom bar menu items for native profiles (a separate, + tracked gap): a home page whose layout requires a bottom bar entry needs it + added in Studio Pro until that gap closes (CE6108). Hybrid remains + unsupported — no reference document exists for it either. + ### Changed - **A generated domain model is laid out, not stacked in one row** — every `CREATE ENTITY` with no `@Position` used the same *y*, so a 40-entity model opened in Studio Pro as a single horizontal line 6,950px wide with the boxes overlapping, since the 150px step is narrower than an entity box. Unreadable at any zoom (reported against a 40-entity model on 11.13). diff --git a/cmd/mxcli/syntax/features_misc.go b/cmd/mxcli/syntax/features_misc.go index ecb762084b..18db217f80 100644 --- a/cmd/mxcli/syntax/features_misc.go +++ b/cmd/mxcli/syntax/features_misc.go @@ -428,10 +428,11 @@ DISCONNECT;`, -- Browse the available names with: -- LIST ICON COLLECTIONS / DESCRIBE ICON COLLECTION Module.Name -- --- is one of Mendix's fixed web kinds, and the profile is CREATED if --- the project does not have it yet: --- Responsive Phone Tablet online --- ResponsiveOffline PhoneOffline TabletOffline offline +-- is one of Mendix's fixed web or native kinds, and the profile is +-- CREATED if the project does not have it yet: +-- Responsive Phone Tablet online (web) +-- ResponsiveOffline PhoneOffline TabletOffline offline (web) +-- NativePhone native -- -- SYNC configures offline synchronization, and an offline profile downloads -- NOTHING until its entities have one -- a profile with no SYNC block builds, @@ -481,7 +482,11 @@ DISCONNECT;`, -- -- An OFFLINE profile restricts every page it can reach -- an attribute may be -- bound across at most ONE association hop (CE6206). Creating one reports the --- documents in the project that already exceed that.`, +-- documents in the project that already exceed that. +-- +-- A NATIVE profile (Navigation$NativeNavigationProfile, no Kind property) does +-- not yet get its MENU block written -- a home page whose layout requires a +-- bottom bar entry needs it added in Studio Pro until that gap closes (CE6108).`, Example: `mdl 1; CREATE OR MODIFY NAVIGATION Responsive APP TITLE 'Order Desk' @@ -501,7 +506,10 @@ CREATE OR MODIFY NAVIGATION TabletOffline HOME PAGE Maintenance.Request_Overview { MENU ITEM 'Requests' ( OnClick: SHOW PAGE Maintenance.Request_Overview ) - };`, + }; + +CREATE OR MODIFY NAVIGATION NativePhone + HOME PAGE MyModule.Home_Native;`, SeeAlso: []string{"navigation.show"}, }) diff --git a/docs/01-project/MDL_QUICK_REFERENCE.md b/docs/01-project/MDL_QUICK_REFERENCE.md index 9be42e1d8f..4c5a52ddf0 100644 --- a/docs/01-project/MDL_QUICK_REFERENCE.md +++ b/docs/01-project/MDL_QUICK_REFERENCE.md @@ -931,8 +931,10 @@ alter workflow Module.OrderApproval { | Offline sync | `sync ( sync Mod.Entity all; ... )` | A clause of CREATE NAVIGATION. Modes: `online`, `all`, `where ''`, `never`, `none`, `none preserve data`. **Not** Studio Pro's captions — its "All Objects" is `all`, its "By XPath" is `where`. An offline profile downloads nothing without this | | Progressive web app | `progressive web app ( Precaching: true )` / `progressive web app off` | A clause of CREATE NAVIGATION: Studio Pro's *Progressive web app* settings. An offline profile without them gets no service worker, so no page opens offline (mendixlabs/mxcli#1377). Keys: `Precaching` (default false), `InstallPrompt` (default true); omitted, the stored settings stay | | Application title / icon | `app title 'Order Desk'` · `app icon Mod.Images.Logo` / `app icon none` | Clauses of CREATE NAVIGATION: Studio Pro's *Application title* (the browser tab's `Mendix - ` prefix in a new project) and *Application icon*. The title is written in the project's default language, other languages kept; the icon is an image, resolved by `check --references` and exec, and must be a square PNG at least 512 px wide (CE6859; exec refuses another). Omitted, both stay as stored (ako/mxcli#1756) | -| Profile kinds | `Responsive` · `Phone` · `Tablet` · `ResponsiveOffline` · `PhoneOffline` · `TabletOffline` | A closed set. An invented name (`Mobile`) is an error, not a new profile: the runtime routes on User-Agent to Mendix's own kinds. Native profiles are a different document type and are not creatable | +| Profile kinds (web) | `Responsive` · `Phone` · `Tablet` · `ResponsiveOffline` · `PhoneOffline` · `TabletOffline` | A closed set. An invented name (`Mobile`) is an error, not a new profile: the runtime routes on User-Agent to Mendix's own kinds | +| Profile kinds (native) | `NativePhone` | A separate closed set — different document type (`Navigation$NativeNavigationProfile`, no `Kind` property). Hybrid is not creatable (no reference document exists for it) | | Offline profiles | `create or modify navigation TabletOffline ...;` | Same properties as the online twin, but every page the profile can reach may bind an attribute across **at most one** association hop (**CE6206**). Creating one reports the documents that already exceed that | +| Native profiles | `create or modify navigation NativePhone home page MyModule.Home_Native;` | Bottom bar menu items are not yet written by `create`/`UpdateNavigationProfile` — a home page whose layout requires one needs it added in Studio Pro (**CE6108**) | Menu items are the profile's children, in `{ }` after its clauses, with no `;` between them: `menu item 'Caption' ( OnClick: show page M.P, Icon: … )`, where diff --git a/mdl/backend/modelsdk/navigation_profile_add.go b/mdl/backend/modelsdk/navigation_profile_add.go index 42f740c1e0..01521f963d 100644 --- a/mdl/backend/modelsdk/navigation_profile_add.go +++ b/mdl/backend/modelsdk/navigation_profile_add.go @@ -43,9 +43,10 @@ func (b *Backend) AddNavigationProfile(navDocID model.ID, name string) error { if b.writer == nil { return fmt.Errorf("AddNavigationProfile: not connected for writing") } - kind, ok := types.CanonicalProfileKind(name) + kind, isNative, ok := resolveProfileKind(name) if !ok { - return fmt.Errorf("cannot create navigation profile %q: Mendix's web profiles are %s", name, strings.Join(types.WebProfileKindNames(), ", ")) + return fmt.Errorf("cannot create navigation profile %q: Mendix's web profiles are %s, and its native profiles are %s", + name, strings.Join(types.WebProfileKindNames(), ", "), strings.Join(types.NativeProfileKindNames(), ", ")) } raw, err := b.reader.GetRawUnitBytes(string(navDocID)) @@ -71,7 +72,12 @@ func (b *Backend) AddNavigationProfile(navDocID model.ID, name string) error { } } - profile := newWebProfileBson(kind) + var profile bson.D + if isNative { + profile = newNativeProfileBson(kind) + } else { + profile = newWebProfileBson(kind) + } if !b.declaresThrowPartialSyncError() { profile = withoutKey(profile, "ThrowPartialSyncError") } @@ -105,6 +111,22 @@ func withoutKey(d bson.D, key string) bson.D { return out } +// resolveProfileKind maps a user-written profile name to its canonical Kind (web) +// or Name (native) and reports which family it belongs to. The two lookups are +// kept apart rather than merged into one map: a web profile is identified by its +// Kind property, a native profile has no Kind at all and is identified purely by +// $Type + Name (see the doc comment on newNativeProfileBson) — blurring the two +// would make it easy to build a profile with the wrong shape for its own $Type. +func resolveProfileKind(name string) (kind string, isNative bool, ok bool) { + if k, ok := types.CanonicalProfileKind(name); ok { + return k, false, true + } + if k, ok := types.CanonicalNativeProfileKind(name); ok { + return k, true, true + } + return "", false, false +} + // newWebProfileBson builds an empty profile of the given kind, with every key a // Studio Pro-authored one carries and nothing it does not. // @@ -153,3 +175,83 @@ func newWebProfileBson(kind string) bson.D { {Key: "ThrowPartialSyncError", Value: true}, } } + +// newNativeProfileBson builds an empty NativePhone profile. +// +// Unlike the web kinds, this shape is NOT pinned by adding a profile through +// Studio Pro's own model API and reading back what it materialised — that +// channel does not exist for native profiles at all, on any machine: PED/MCP +// explicitly rejects native profile authoring (docs/03-development/ +// PED_MCP_CAPABILITIES.md, mdl/backend/mcp/navigation.go), independent of this +// repo's own environment. The best available evidence instead is a real +// Studio-Pro-authored NativePhone profile from native-pwa-migrator's +// fixtures/native-phone-minimal (a raw BSON dump of the .mxunit file, not a PED +// read) — but that document is a CONFIGURED profile, not a freshly-created one, +// so it proves the key set, $Type names, and storage keys, not which values are +// Studio Pro's create-time defaults versus this fixture author's choices. +// +// A native profile has no Kind property at all (confirmed against +// modelsdk/gen/navigation/types.go: NativeNavigationProfile carries no `kind` +// field, unlike NavigationProfile) — it is distinguished purely by $Type + Name. +// +// Per-field provenance, so a future re-pin knows what to re-check: +// - Name, $Type: definitional. +// - OfflineEntityConfigs, RoleBasedNativeHomePages: the fixture's own document +// carries these EMPTY (marker 3 / marker 1 respectively) even though it is +// otherwise configured — direct evidence of the unconfigured state, not an +// inference. +// - NativeHomePage: written explicit nil here, NOT the fixture's configured +// home page — this is exactly what UpdateNavigationProfile fills in +// afterwards (mirrors NotFoundHomepage/ProgressiveWebAppSettings on the web +// side: an unset single child is an explicit null, never an empty +// placeholder sub-document). Backed by a real signal in the decoder, not a +// guess: NativeNavigationProfile.InitFromRaw only sets nativeHomePage +// `if child, err := codec.DecodeChild(raw, "NativeHomePage"); err == nil`, +// i.e. the shipped read path already treats a missing/null NativeHomePage as +// an ordinary, non-error state. +// - BottomBarItems: empty, marker 2 — the fixture's own (non-empty) BottomBarItems +// uses marker 2, and the marker is per-field-type rather than count-dependent +// (proven by newWebProfileBson itself: HomeItems/AppTitle.Items/ +// OfflineEntityConfigs are all empty in that SAME reference document yet use +// three different markers — 3, 3, 3 vs Menu.Items' 1 — so an empty +// collection keeps its type's marker rather than switching to some +// "generic empty" one). UpdateNavigationProfile does not patch BottomBarItems +// for native profiles (a separate, already-tracked gap), so this value +// persists until Studio Pro or a future writer sets it. +// - ApplyScreenTransition, EncryptionDbEnabled, LocalFileEncryptionEnabled, +// LoggingEnabled, NativeNavigationEnabled, OtaEnabled, +// SessionCookieEncryptionEnabled: false, and ScreenNavigationTransition/ +// PopupNavigationTransition: "SystemDefault" — carried from the fixture. +// These are opt-in toggles a minimal fixture is unlikely to have touched, +// but that is inference, not measurement. +// - NetworkTimeoutMs (60000) and ThrowPartialSyncError (false): carried from +// the fixture as observed values. Flagged as the least-certain fields here — +// unlike the booleans above, there is no structural reason to expect these +// specific values are Studio Pro's create-time defaults rather than this +// fixture author's settings that happen not to have been touched. +// - HermesEnabled: deliberately OMITTED. modelsdk/gen exposes a setter for it, +// but the fixture's real document does not carry this key at all — writing +// a value here would be exactly the "assembled from a guess" failure mode +// this whole feature exists to avoid. +func newNativeProfileBson(kind string) bson.D { + return bson.D{ + {Key: "$ID", Value: navID()}, + {Key: "$Type", Value: "Navigation$NativeNavigationProfile"}, + {Key: "ApplyScreenTransition", Value: false}, + {Key: "BottomBarItems", Value: bson.A{int32(2)}}, + {Key: "EncryptionDbEnabled", Value: false}, + {Key: "LocalFileEncryptionEnabled", Value: false}, + {Key: "LoggingEnabled", Value: false}, + {Key: "Name", Value: kind}, + {Key: "NativeHomePage", Value: nil}, + {Key: "NativeNavigationEnabled", Value: false}, + {Key: "NetworkTimeoutMs", Value: int32(60000)}, + {Key: "OfflineEntityConfigs", Value: bson.A{int32(3)}}, + {Key: "OtaEnabled", Value: false}, + {Key: "PopupNavigationTransition", Value: "SystemDefault"}, + {Key: "RoleBasedNativeHomePages", Value: bson.A{int32(1)}}, + {Key: "ScreenNavigationTransition", Value: "SystemDefault"}, + {Key: "SessionCookieEncryptionEnabled", Value: false}, + {Key: "ThrowPartialSyncError", Value: false}, + } +} diff --git a/mdl/backend/modelsdk/navigation_profile_add_test.go b/mdl/backend/modelsdk/navigation_profile_add_test.go index a546faf9b4..67a5b76b87 100644 --- a/mdl/backend/modelsdk/navigation_profile_add_test.go +++ b/mdl/backend/modelsdk/navigation_profile_add_test.go @@ -112,6 +112,122 @@ func TestNoKindCarriesProgressiveWebAppSettings(t *testing.T) { } } +func TestResolveProfileKind(t *testing.T) { + for _, tc := range []struct { + name string + wantKind string + wantNative bool + wantOK bool + }{ + {"phone", "Phone", false, true}, + {" Responsive ", "Responsive", false, true}, + {"TabletOffline", "TabletOffline", false, true}, + {"nativephone", "NativePhone", true, true}, + {" NativePhone ", "NativePhone", true, true}, + {"Mobile", "", false, false}, + {"Hybrid", "", false, false}, + } { + kind, isNative, ok := resolveProfileKind(tc.name) + if ok != tc.wantOK || kind != tc.wantKind || isNative != tc.wantNative { + t.Errorf("resolveProfileKind(%q) = (%q, %v, %v), want (%q, %v, %v)", + tc.name, kind, isNative, ok, tc.wantKind, tc.wantNative, tc.wantOK) + } + } +} + +func TestNewNativeProfileMatchesTheFixtureKeySet(t *testing.T) { + // Every key native-pwa-migrator's fixtures/native-phone-minimal carries on its + // real, Studio-Pro-authored NativePhone profile, and nothing it does not — + // same discipline as TestNewWebProfileMatchesTheStudioProKeySet, except this + // reference is a configured document (see newNativeProfileBson's doc comment + // for why no fresher one exists). A key mxcli invents, or one it omits, is + // the failure that passes mx check and then will not open in Studio Pro. + want := []string{ + "$ID", "$Type", "ApplyScreenTransition", "BottomBarItems", + "EncryptionDbEnabled", "LocalFileEncryptionEnabled", "LoggingEnabled", + "Name", "NativeHomePage", "NativeNavigationEnabled", "NetworkTimeoutMs", + "OfflineEntityConfigs", "OtaEnabled", "PopupNavigationTransition", + "RoleBasedNativeHomePages", "ScreenNavigationTransition", + "SessionCookieEncryptionEnabled", "ThrowPartialSyncError", + } + got := newNativeProfileBson("NativePhone") + if len(got) != len(want) { + t.Errorf("NativePhone: %d keys, want %d", len(got), len(want)) + } + for _, k := range want { + if _, ok := profileKey(got, k); !ok { + t.Errorf("NativePhone: missing key %q", k) + } + } + if v, _ := profileKey(got, "Name"); v != "NativePhone" { + t.Errorf("NativePhone: Name = %v", v) + } + if v, _ := profileKey(got, "$Type"); v != "Navigation$NativeNavigationProfile" { + t.Errorf("NativePhone: $Type = %v", v) + } + // A native profile has no Kind property at all — confirmed against + // modelsdk/gen/navigation/types.go, which gives NativeNavigationProfile no + // `kind` field. Unlike the web builder, Kind must never appear here. + if _, ok := profileKey(got, "Kind"); ok { + t.Error("NativePhone: has a Kind key, but native profiles have none") + } +} + +func TestNativeProfileStartsWithNoHomePage(t *testing.T) { + // UpdateNavigationProfile's navPatchNativeProfile only overwrites + // NativeHomePage when the CREATE statement gives one — so a bare + // `create navigation NativePhone;` leaves this constructor's value in place. + // It must be an explicit null, not the fixture's configured home page. + v, ok := profileKey(newNativeProfileBson("NativePhone"), "NativeHomePage") + if !ok { + t.Fatal("NativePhone: no NativeHomePage key at all") + } + if v != nil { + t.Errorf("NativePhone: NativeHomePage = %#v, want an explicit null", v) + } +} + +func TestNativeProfileStartsWithEmptyChildCollections(t *testing.T) { + // OfflineEntityConfigs and RoleBasedNativeHomePages are stored EMPTY on the + // fixture's own (otherwise configured) document — direct evidence of the + // unconfigured state. BottomBarItems is never touched by + // UpdateNavigationProfile for native profiles (a separate, tracked gap), so + // it must start empty here rather than carrying the fixture's configured + // bottom bar item forward. + for _, tc := range []struct { + key string + marker int32 + }{ + {"OfflineEntityConfigs", 3}, + {"RoleBasedNativeHomePages", 1}, + {"BottomBarItems", 2}, + } { + v, ok := profileKey(newNativeProfileBson("NativePhone"), tc.key) + if !ok { + t.Fatalf("NativePhone: no %s key at all", tc.key) + } + arr, ok := v.(bson.A) + if !ok { + t.Fatalf("NativePhone: %s is %T, want bson.A", tc.key, v) + } + if len(arr) != 1 { + t.Errorf("NativePhone: %s has %d entries beyond the marker, want 0", tc.key, len(arr)-1) + } + if len(arr) == 1 && arr[0] != tc.marker { + t.Errorf("NativePhone: %s marker = %v, want %d", tc.key, arr[0], tc.marker) + } + } +} + +func TestNativeProfileHasNoHermesEnabledKey(t *testing.T) { + // modelsdk/gen exposes a HermesEnabled setter, but the fixture's real + // document does not carry this key — writing a value here would be exactly + // the "assembled from a guess" failure mode this feature exists to avoid. + if _, ok := profileKey(newNativeProfileBson("NativePhone"), "HermesEnabled"); ok { + t.Error("NativePhone: has a HermesEnabled key, but the reference document does not") + } +} + func TestOfflineProfilesStartWithNoEntityConfigs(t *testing.T) { // Studio Pro DERIVES the offline entity list from the pages the profile // reaches; only rows that deviate from the defaults are stored. An empty diff --git a/mdl/backend/navigation.go b/mdl/backend/navigation.go index d3e6daaa9e..d76f7dfa92 100644 --- a/mdl/backend/navigation.go +++ b/mdl/backend/navigation.go @@ -12,10 +12,12 @@ type NavigationBackend interface { ListNavigationDocuments() ([]*types.NavigationDocument, error) GetNavigation() (*types.NavigationDocument, error) UpdateNavigationProfile(navDocID model.ID, profileName string, spec types.NavigationProfileSpec) error - // AddNavigationProfile appends a new WEB navigation profile (Responsive, - // Phone or Tablet). Mendix's set is fixed, so this takes a kind rather than - // an arbitrary name. Callers create then update: this leaves the profile - // empty and UpdateNavigationProfile fills it. + // AddNavigationProfile appends a new web (Responsive, Phone, Tablet, or their + // *Offline twins) or native (NativePhone) navigation profile. Mendix's set is + // fixed for both families, so this takes a kind/name rather than an + // arbitrary one. Callers create then update: this leaves the profile empty + // (or, for native, with its home page/menu still unset) and + // UpdateNavigationProfile fills it. AddNavigationProfile(navDocID model.ID, name string) error // OpenNavigationProfileForMutation loads the navigation document and diff --git a/mdl/executor/cmd_navigation.go b/mdl/executor/cmd_navigation.go index 5b794576da..e45c8d1790 100644 --- a/mdl/executor/cmd_navigation.go +++ b/mdl/executor/cmd_navigation.go @@ -90,14 +90,18 @@ func execCreateNavigation(ctx *ExecContext, s *ast.CreateNavigationStmt) error { // User-Agent — not on viewport width — so a device-specific front end could // not be built from MDL at all (ako/mxcli-maintenance §7). // - // Mendix's web profiles are a closed set, so an unknown name is still an - // error: creating "Phone" is adding the profile the platform defines, - // while creating "Mobile" would be inventing one that can never route. + // Mendix's web and native profiles are both closed sets, so an unknown + // name is still an error: creating "Phone" or "NativePhone" is adding a + // profile the platform defines, while creating "Mobile" would be + // inventing one that can never route. kind, ok := types.CanonicalProfileKind(s.ProfileName) + if !ok { + kind, ok = types.CanonicalNativeProfileKind(s.ProfileName) + } if !ok { return mdlerrors.NewNotFoundMsg("navigation profile", s.ProfileName, - fmt.Sprintf("navigation profile not found: %s (available: %s; Mendix's web profiles are %s)", - s.ProfileName, profileNames(nav), strings.Join(types.WebProfileKindNames(), ", "))) + fmt.Sprintf("navigation profile not found: %s (available: %s; Mendix's web profiles are %s, and its native profiles are %s)", + s.ProfileName, profileNames(nav), strings.Join(types.WebProfileKindNames(), ", "), strings.Join(types.NativeProfileKindNames(), ", "))) } if err := ctx.Backend.AddNavigationProfile(nav.ID, kind); err != nil { return mdlerrors.NewBackend("create navigation profile", err) diff --git a/mdl/types/navigation_profile_kind.go b/mdl/types/navigation_profile_kind.go index 890810195f..67ff505c47 100644 --- a/mdl/types/navigation_profile_kind.go +++ b/mdl/types/navigation_profile_kind.go @@ -14,10 +14,12 @@ import "strings" // changes is what the platform then demands of every page the profile reaches — // see the CE6206 warning MDL-OFFLINE01 raises. // -// The native profiles (Navigation$NativeNavigationProfile, a different $Type) -// and the Hybrid kinds are deliberately absent: no reference document was -// available for either, and a profile assembled from a guess is the failure mode -// that builds clean and then will not open in Studio Pro. +// The native profile (Navigation$NativeNavigationProfile, a different $Type) is +// deliberately absent from THIS table — see nativeProfileKinds below for its own +// table and the reason it is kept separate. The Hybrid kinds (web and native +// alike) are absent from both: no reference document is available for Hybrid at +// all, and a profile assembled from a guess is the failure mode that builds +// clean and then will not open in Studio Pro. var webProfileKinds = map[string]string{ "responsive": "Responsive", "phone": "Phone", @@ -53,3 +55,31 @@ func IsOfflineProfileKind(kind string) bool { func WebProfileKindNames() []string { return []string{"Responsive", "Phone", "Tablet", "ResponsiveOffline", "PhoneOffline", "TabletOffline"} } + +// nativeProfileKinds are the Navigation$NativeNavigationProfile names a NATIVE +// profile can take. Kept apart from webProfileKinds rather than merged into one +// table: a web profile is identified by its Kind property, a native profile has +// no Kind at all and is identified purely by $Type + Name — a lookup that +// returned a "kind" for both would make it easy to hand a native name to the web +// builder (or vice versa) and get a document with the wrong shape for its $Type. +// +// Only NativePhone is here. Hybrid is a different $Type again and, like the web +// Hybrid kinds, has no reference document to pin its shape against — see the +// doc comment on webProfileKinds. +var nativeProfileKinds = map[string]string{ + "nativephone": "NativePhone", +} + +// CanonicalNativeProfileKind maps a user-written profile name to the Name Mendix +// stores for a native profile, reporting whether it is one mxcli can create. It +// is the native counterpart of CanonicalProfileKind, not a branch inside it, for +// the reason given on nativeProfileKinds. +func CanonicalNativeProfileKind(name string) (string, bool) { + k, ok := nativeProfileKinds[strings.ToLower(strings.TrimSpace(name))] + return k, ok +} + +// NativeProfileKindNames lists the creatable native kinds for error messages. +func NativeProfileKindNames() []string { + return []string{"NativePhone"} +} From 12c12f08114dd19820f8cc76db9a36f68d4d03bb Mon Sep 17 00:00:00 2001 From: Uraz Akgultan Date: Mon, 31 Aug 2026 09:06:04 +0200 Subject: [PATCH 02/18] feat(navigation): write bottom bar menu items for NativePhone profiles --- .../skills/mendix/manage-navigation/SKILL.md | 53 +++-- CHANGELOG.md | 13 +- cmd/mxcli/syntax/features_misc.go | 14 +- docs/01-project/MDL_QUICK_REFERENCE.md | 4 +- .../modelsdk/navigation_bottombar_test.go | 200 ++++++++++++++++++ .../modelsdk/navigation_native_test.go | 10 +- .../navigation_omitted_clause_test.go | 5 +- .../modelsdk/navigation_profile_add_test.go | 8 +- mdl/backend/modelsdk/navigation_write.go | 130 +++++++++++- mdl/executor/cmd_navigation.go | 74 +++---- .../cmd_navigation_icon_roundtrip_test.go | 8 +- mdl/executor/cmd_navigation_icon_test.go | 27 +++ mdl/executor/cmd_navigation_native_test.go | 21 +- 13 files changed, 480 insertions(+), 87 deletions(-) create mode 100644 mdl/backend/modelsdk/navigation_bottombar_test.go diff --git a/.claude/skills/mendix/manage-navigation/SKILL.md b/.claude/skills/mendix/manage-navigation/SKILL.md index 9abd807d8d..3190b87651 100644 --- a/.claude/skills/mendix/manage-navigation/SKILL.md +++ b/.claude/skills/mendix/manage-navigation/SKILL.md @@ -20,10 +20,10 @@ description: "Inspect and change navigation profiles in MDL — home pages, menu | 458-497 | Common Patterns | | 498-550 | Menu Documents (standalone, reusable) | | 551-621 | Offline Profiles | -| 622-650 | Native Profiles | -| 651-668 | Checklist | -| 669-672 | Offline synchronization (`CREATE NAVIGATION … SYNC (…)`) | -| 673-675 | Menu documents (CREATE OR MODIFY/DESCRIBE/DROP MENU) | +| 622-671 | Native Profiles | +| 672-689 | Checklist | +| 690-693 | Offline synchronization (`CREATE NAVIGATION … SYNC (…)`) | +| 694-696 | Menu documents (CREATE OR MODIFY/DESCRIBE/DROP MENU) | # Navigation Management Skill @@ -52,7 +52,7 @@ Use when the user asks to: An invented name (`Mobile`, `Desktop`) is an error, not a new profile: Mendix routes on **User-Agent** to its own kinds, so a profile the platform does not define can never be reached. - Native profiles are a different document type (`Navigation$NativeNavigationProfile`, no `Kind` property — identified purely by `$Type` + `Name`) and have their own, separate closed set: currently just `NativePhone`. `create or modify navigation NativePhone` creates it the same way the web kinds are created. Hybrid is not supported (no reference document exists for it). A freshly created NativePhone profile has no bottom bar menu items — `create navigation NativePhone (menu (...))` does not fill them in yet, so a page whose layout requires a bottom bar (CE6108) needs its bottom bar item added in Studio Pro until that gap closes. + Native profiles are a different document type (`Navigation$NativeNavigationProfile`, no `Kind` property — identified purely by `$Type` + `Name`) and have their own, separate closed set: currently just `NativePhone`. `create or modify navigation NativePhone` creates it the same way the web kinds are created. Hybrid is not supported (no reference document exists for it). A freshly created NativePhone profile has no bottom bar menu items — fill them with a `{ }` block (flat, `OnClick: show page` only, no `Icon:` — see "Native Profiles" below) if the home page's layout requires a bottom bar (CE6108). - **Offline Profiles** — An offline profile makes the app work without a connection (a PWA with a local database that syncs). It is not a different document — same properties as its online twin — but it **constrains every page it can reach**, see below. - **Home Page** — The default page shown after login. Can be a PAGE or MICROFLOW. - **Role-Based Home Pages** — Override the default home page per user role (e.g., admins see a dashboard, users see a task list). @@ -624,7 +624,7 @@ stored. MDL does not author per-entity sync modes — set those in Studio Pro. `NativePhone` is created the same way: ```sql -create navigation NativePhone +create or modify navigation NativePhone home page NativeMobile.Home_Native; ``` @@ -632,15 +632,36 @@ It is a different document type (`Navigation$NativeNavigationProfile`) from the web kinds above — no `Kind` property, identified purely by `$Type` + `Name` — but the statement and the create-then-fill flow are the same. -**The bottom bar menu is not filled in yet.** Unlike the web `menu (...)` block, -`create navigation NativePhone (menu (...))` does not write bottom bar items for -a native profile — a separate, already-tracked gap. If the home page's layout -has "Bottom bar" enabled, Mendix requires that page to appear in the profile's -bottom bar menu and reports **CE6108** ("If the bottom bar is enabled on a home -page, then that page must be included in the bottom bar menu of the native -navigation profile...") until it is added in Studio Pro. Point the home page at -a layout with no bottom bar, or add the bottom bar item in Studio Pro, to avoid -it. +**The bottom bar is the profile's `{ }` block, reusing the same item syntax as +the web kinds — but it is flat and page-only.** A native profile's bottom bar +(`NativePages$BottomBarItem`) has no sub-menus and stores only a page, unlike +the web `Menu`, so: + +```sql +create or modify navigation NativePhone + home page NativeMobile.Home_Native + { + menu item 'Home' ( OnClick: show page NativeMobile.Home_Native ) + }; +``` + +- Every item needs `OnClick: show page …` — any other action (`call microflow`, + `call nanoflow`, `sign out`, …) and an item with no action are rejected (the + native bottom bar has no other action). A page argument is rejected too. +- Nested `menu 'caption' { … }` sub-items are rejected — Mendix's bottom bar + menu cannot nest. +- `Icon:` is rejected. mxcli's icon property only ever builds a + `Forms$IconCollectionIcon` here, and that has never been confirmed as valid + for a native bottom bar item (the one real reference document uses a + `Forms$GlyphIcon`, a different, unauthored-by-MDL shape). Add the icon in + Studio Pro. + +If the home page's layout has "Bottom bar" enabled, Mendix requires that page +to appear in the profile's bottom bar menu and reports **CE6108** ("If the +bottom bar is enabled on a home page, then that page must be included in the +bottom bar menu of the native navigation profile...") until it does. Either +include the page in the `{ }` block as above, or point the home page at a +layout with no bottom bar. A profile with no home page at all (`create navigation NativePhone;` with nothing else) is a valid **empty** profile — Mendix requires a home page before @@ -654,7 +675,7 @@ set, same as leaving a web profile's home page unset. - [ ] For an **offline** profile, no page it can reach binds an attribute across more than one association (CE6206) - [ ] For an **offline** profile, `progressive web app ( Precaching: true )` is set — without it no page opens offline - [ ] `app title` is set — a new project's browser tab reads `Mendix - ` otherwise -- [ ] For a **native** profile, the home page's layout does not require a bottom bar entry mxcli cannot yet write (CE6108) — or add that entry in Studio Pro +- [ ] For a **native** profile whose home page's layout requires a bottom bar (CE6108), the `{ }` block includes that page — flat items only, `OnClick: show page` only, no `Icon:` (add icons in Studio Pro) - [ ] All PAGE/MICROFLOW targets are fully qualified (`Module.Name`) - [ ] Role references in `for` clauses are fully qualified (`Module.Role`) - [ ] Menu items are in `{ }` with no `;` between them; sub-menu items in `menu 'caption' { ... }` diff --git a/CHANGELOG.md b/CHANGELOG.md index b6b283d707..8c823ffbd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1451,10 +1451,15 @@ Headline: **Widgets become first-class MDL rather than a second dialect.** Every native profiles (PED/MCP explicitly rejects native profile authoring), so the shape is pinned against a real Studio-Pro-authored NativePhone profile instead — see the doc comment on `newNativeProfileBson`. `UpdateNavigationProfile` - does not yet write bottom bar menu items for native profiles (a separate, - tracked gap): a home page whose layout requires a bottom bar entry needs it - added in Studio Pro until that gap closes (CE6108). Hybrid remains - unsupported — no reference document exists for it either. + now writes bottom bar menu items too (`NativePages$BottomBarItem`), reusing + the profile's `{ }` block as the web kinds do — so a home page whose layout + requires a bottom bar can be added to it directly, clearing **CE6108** + instead of needing Studio Pro. The native bottom bar is flat and page-only, + unlike the web `Menu`: a nested `MENU 'caption' { … }` group, an `OnClick` + other than `SHOW PAGE`, or an `Icon:` on a native menu item is rejected rather than + guessed at — see the doc comment on `navBottomBarItemBson` for why icons + specifically are not supported yet. Hybrid remains unsupported — no + reference document exists for it either. ### Changed diff --git a/cmd/mxcli/syntax/features_misc.go b/cmd/mxcli/syntax/features_misc.go index 18db217f80..7a3f0f2f98 100644 --- a/cmd/mxcli/syntax/features_misc.go +++ b/cmd/mxcli/syntax/features_misc.go @@ -484,9 +484,12 @@ DISCONNECT;`, -- bound across at most ONE association hop (CE6206). Creating one reports the -- documents in the project that already exceed that. -- --- A NATIVE profile (Navigation$NativeNavigationProfile, no Kind property) does --- not yet get its MENU block written -- a home page whose layout requires a --- bottom bar entry needs it added in Studio Pro until that gap closes (CE6108).`, +-- A NATIVE profile (Navigation$NativeNavigationProfile, no Kind property) has +-- a { } block too -- its bottom bar -- but it is FLAT and PAGE-ONLY +-- (NativePages$BottomBarItem): no nested MENU groups, no OnClick other than +-- SHOW PAGE, no Icon: (add icons in Studio Pro -- IconCollectionIcon is +-- unconfirmed for a native bottom bar item). A home page whose layout has +-- "Bottom bar" enabled must appear in this block, or Mendix reports CE6108.`, Example: `mdl 1; CREATE OR MODIFY NAVIGATION Responsive APP TITLE 'Order Desk' @@ -509,7 +512,10 @@ CREATE OR MODIFY NAVIGATION TabletOffline }; CREATE OR MODIFY NAVIGATION NativePhone - HOME PAGE MyModule.Home_Native;`, + HOME PAGE MyModule.Home_Native + { + MENU ITEM 'Home' ( OnClick: SHOW PAGE MyModule.Home_Native ) + };`, SeeAlso: []string{"navigation.show"}, }) diff --git a/docs/01-project/MDL_QUICK_REFERENCE.md b/docs/01-project/MDL_QUICK_REFERENCE.md index 4c5a52ddf0..b25f919ef4 100644 --- a/docs/01-project/MDL_QUICK_REFERENCE.md +++ b/docs/01-project/MDL_QUICK_REFERENCE.md @@ -925,7 +925,7 @@ alter workflow Module.OrderApproval { | Show menu tree | `list navigation menu [Profile];` | One row per item, with the **Address** `alter navigation` takes (`'Admin' > 'Users'`, `'Home'@2`) | | Show home pages | `list navigation homes;` | Home page assignments across profiles | | Describe navigation | `describe navigation [Profile];` | Full MDL output (round-trippable) | -| Native home | `home nanoflow Mod.Flow` | A native profile's flow home; mxcli writes a native profile's home pages and sync only | +| Native home | `home nanoflow Mod.Flow` | A native profile's flow home; mxcli writes a native profile's home pages, sync and bottom bar only | | Create/modify navigation | `create or modify navigation Profile ...;` | Writes the clauses it states (a `{ }` block replaces the whole menu) — and **creates** the profile if the project does not have it | | Alter navigation | `alter navigation Profile { insert after 'Home' { menu item … } drop 'Old'; … };` | Edits one profile in place: `insert before\|after\|into { … }`, `insert { … }`, `replace with { … }`, `move before\|after\|into `, `drop , …`, `set ( Caption:, OnClick:, Icon: \| none ) on `, `set home page\|microflow M.X [for Role]`, `drop home page for Role`, `set/drop login page`, `set/drop not found page`. `` is a caption path `'Admin' > 'Users'` (`@n` among equal captions). Untouched items stay as stored; a refusal writes nothing | | Offline sync | `sync ( sync Mod.Entity all; ... )` | A clause of CREATE NAVIGATION. Modes: `online`, `all`, `where ''`, `never`, `none`, `none preserve data`. **Not** Studio Pro's captions — its "All Objects" is `all`, its "By XPath" is `where`. An offline profile downloads nothing without this | @@ -934,7 +934,7 @@ alter workflow Module.OrderApproval { | Profile kinds (web) | `Responsive` · `Phone` · `Tablet` · `ResponsiveOffline` · `PhoneOffline` · `TabletOffline` | A closed set. An invented name (`Mobile`) is an error, not a new profile: the runtime routes on User-Agent to Mendix's own kinds | | Profile kinds (native) | `NativePhone` | A separate closed set — different document type (`Navigation$NativeNavigationProfile`, no `Kind` property). Hybrid is not creatable (no reference document exists for it) | | Offline profiles | `create or modify navigation TabletOffline ...;` | Same properties as the online twin, but every page the profile can reach may bind an attribute across **at most one** association hop (**CE6206**). Creating one reports the documents that already exceed that | -| Native profiles | `create or modify navigation NativePhone home page MyModule.Home_Native;` | Bottom bar menu items are not yet written by `create`/`UpdateNavigationProfile` — a home page whose layout requires one needs it added in Studio Pro (**CE6108**) | +| Native profiles | `create or modify navigation NativePhone home page MyModule.Home_Native { menu item 'Home' ( OnClick: show page MyModule.Home_Native ) };` | The `{ }` block is the bottom bar: flat and page-only — no sub-menus, no `OnClick` other than `show page`, no `Icon:`. Needed when the home page's layout requires a bottom bar (**CE6108**) | Menu items are the profile's children, in `{ }` after its clauses, with no `;` between them: `menu item 'Caption' ( OnClick: show page M.P, Icon: … )`, where diff --git a/mdl/backend/modelsdk/navigation_bottombar_test.go b/mdl/backend/modelsdk/navigation_bottombar_test.go new file mode 100644 index 0000000000..9e5f92ccfe --- /dev/null +++ b/mdl/backend/modelsdk/navigation_bottombar_test.go @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: Apache-2.0 + +// Pinned against native-pwa-migrator's fixtures/native-phone-minimal: a real +// Studio-Pro-authored NativePhone profile whose one BottomBarItem is +// +// { $Type: "NativePages$BottomBarItem", +// Caption: { $Type: "Texts$Text", Items: [3, [{ $Type: "Texts$Translation", +// LanguageCode: "en_US", Text: "Home" }]] }, +// Icon: { $Type: "Forms$GlyphIcon", Code: 57377 }, +// Page: "NativeMobile.Home_Native" } +// +// (marker re-verified directly against the fixture's raw BSON, not copied from +// navCaptionBson — see navBottomBarCaptionBson's doc comment). mxcli never +// writes Icon (see navBottomBarItemBson's doc comment), so these tests check +// the four keys mxcli owns and the two malformed-input rejections that keep it +// from guessing a shape Studio Pro has never confirmed. +package modelsdkbackend + +import ( + "fmt" + "testing" + + "go.mongodb.org/mongo-driver/v2/bson" + + "github.com/mendixlabs/mxcli/mdl/types" + "github.com/mendixlabs/mxcli/sdk/pages" +) + +func TestNavBottomBarItemBson_MatchesTheFixtureShape(t *testing.T) { + got, err := navBottomBarItemBson(types.NavMenuItemSpec{Caption: "Home", Page: "NativeMobile.Home_Native"}) + if err != nil { + t.Fatalf("navBottomBarItemBson: %v", err) + } + if v, _ := profileKey(got, "$Type"); v != "NativePages$BottomBarItem" { + t.Errorf("$Type = %v", v) + } + if v, _ := profileKey(got, "Page"); v != "NativeMobile.Home_Native" { + t.Errorf("Page = %v", v) + } + // Never written — see navBottomBarItemBson's doc comment. + if v, ok := profileKey(got, "Icon"); !ok || v != nil { + t.Errorf("Icon = %#v, want an explicit null", v) + } + + caption, ok := profileKey(got, "Caption") + if !ok { + t.Fatal("no Caption key at all") + } + captionDoc, ok := caption.(bson.D) + if !ok { + t.Fatalf("Caption is %T, want bson.D", caption) + } + if v, _ := profileKey(captionDoc, "$Type"); v != "Texts$Text" { + t.Errorf("Caption.$Type = %v", v) + } + items, ok := profileKey(captionDoc, "Items") + if !ok { + t.Fatal("Caption: no Items key at all") + } + arr, ok := items.(bson.A) + if !ok || len(arr) != 2 { + t.Fatalf("Caption.Items = %#v, want [marker, translation]", items) + } + if arr[0] != int32(3) { + t.Errorf("Caption.Items marker = %v, want 3 (measured on the fixture, not navCaptionBson's 1)", arr[0]) + } + translation, ok := arr[1].(bson.D) + if !ok { + t.Fatalf("Caption.Items[1] is %T, want bson.D", arr[1]) + } + if v, _ := profileKey(translation, "$Type"); v != "Texts$Translation" { + t.Errorf("Translation.$Type = %v", v) + } + if v, _ := profileKey(translation, "Text"); v != "Home" { + t.Errorf("Translation.Text = %v", v) + } +} + +func TestNavBottomBarItemBson_RejectsSubItems(t *testing.T) { + _, err := navBottomBarItemBson(types.NavMenuItemSpec{ + Caption: "Home", Page: "M.Home", + Items: []types.NavMenuItemSpec{{Caption: "Sub", Page: "M.Sub"}}, + }) + if err == nil { + t.Fatal("expected an error for a nested item — the native bottom bar is flat") + } +} + +func TestNavBottomBarItemBson_RejectsMicroflow(t *testing.T) { + _, err := navBottomBarItemBson(types.NavMenuItemSpec{Caption: "Home", Microflow: "M.DoStuff"}) + if err == nil { + t.Fatal("expected an error for a microflow target — BottomBarItem has no microflow action") + } +} + +func TestNavBottomBarItemBson_RequiresAPage(t *testing.T) { + _, err := navBottomBarItemBson(types.NavMenuItemSpec{Caption: "Home"}) + if err == nil { + t.Fatal("expected an error when neither a page nor a microflow is given") + } +} + +func TestNavBottomBarItemBson_RejectsIcon(t *testing.T) { + _, err := navBottomBarItemBson(types.NavMenuItemSpec{ + Caption: "Home", Page: "M.Home", Icon: "Atlas_Core.Atlas.home", + }) + if err == nil { + t.Fatal("expected an error for ICON — Forms$IconCollectionIcon is unconfirmed for native bottom bar items") + } +} + +func TestNavPatchNativeProfile_LeavesBottomBarItemsAloneWithoutAMenuBlock(t *testing.T) { + // Mirrors navPatchWebProfile's own rule for Menu: a CREATE OR REPLACE + // NAVIGATION statement with no MENU clause must not wipe an existing menu. + before := newNativeProfileBson("NativePhone") + wantBefore, ok := profileKey(before, "BottomBarItems") + if !ok { + t.Fatal("fixture setup: no BottomBarItems key at all") + } + got, err := navPatchNativeProfile(before, types.NavigationProfileSpec{HasMenu: false}) + if err != nil { + t.Fatalf("navPatchNativeProfile: %v", err) + } + gotAfter, ok := profileKey(got, "BottomBarItems") + if !ok { + t.Fatal("BottomBarItems key vanished") + } + if fmt.Sprintf("%v", wantBefore) != fmt.Sprintf("%v", gotAfter) { + t.Errorf("BottomBarItems changed without a MENU clause: %v -> %v", wantBefore, gotAfter) + } +} + +func TestNavPatchNativeProfile_BuildsBottomBarItemsFromMenuItems(t *testing.T) { + doc := newNativeProfileBson("NativePhone") + got, err := navPatchNativeProfile(doc, types.NavigationProfileSpec{ + HasMenu: true, + MenuItems: []types.NavMenuItemSpec{{Caption: "Home", Page: "NativeMobile.Home_Native"}}, + }) + if err != nil { + t.Fatalf("navPatchNativeProfile: %v", err) + } + v, ok := profileKey(got, "BottomBarItems") + if !ok { + t.Fatal("no BottomBarItems key at all") + } + arr, ok := v.(bson.A) + if !ok || len(arr) != 2 { + t.Fatalf("BottomBarItems = %#v, want [marker, item]", v) + } + if arr[0] != int32(2) { + t.Errorf("BottomBarItems marker = %v, want 2", arr[0]) + } + item, ok := arr[1].(bson.D) + if !ok { + t.Fatalf("BottomBarItems[1] is %T, want bson.D", arr[1]) + } + if v, _ := profileKey(item, "$Type"); v != "NativePages$BottomBarItem" { + t.Errorf("item $Type = %v", v) + } +} + +func TestNavPatchNativeProfile_PropagatesABottomBarItemError(t *testing.T) { + doc := newNativeProfileBson("NativePhone") + _, err := navPatchNativeProfile(doc, types.NavigationProfileSpec{ + HasMenu: true, + MenuItems: []types.NavMenuItemSpec{{Caption: "Bad", Microflow: "M.DoStuff"}}, + }) + if err == nil { + t.Fatal("expected the microflow-target error to propagate out of navPatchNativeProfile") + } +} + +// The executor hands an item's OnClick over as a built client action +// (ako/mxcli#980), not as the legacy Page field, so the bottom bar's page is +// read from a show-page action — and every other action is refused rather than +// written as an item with no page. +func TestNavBottomBarItemBson_ReadsThePageFromTheAction(t *testing.T) { + got, err := navBottomBarItemBson(types.NavMenuItemSpec{Caption: "Home", + Action: &pages.PageClientAction{PageName: "NativeMobile.Home_Native"}}) + if err != nil { + t.Fatalf("navBottomBarItemBson: %v", err) + } + if v, _ := profileKey(got, "Page"); v != "NativeMobile.Home_Native" { + t.Errorf("Page = %v, want the show-page action's page", v) + } + + for name, spec := range map[string]types.NavMenuItemSpec{ + "microflow action": {Caption: "X", Action: &pages.MicroflowClientAction{MicroflowName: "M.F"}}, + "nanoflow action": {Caption: "X", Action: &pages.NanoflowClientAction{NanoflowName: "M.N"}}, + "sign out": {Caption: "X", SignOut: true}, + "page argument": {Caption: "X", Action: &pages.PageClientAction{PageName: "M.P", + ParameterMappings: []*pages.PageClientParameterMapping{{}}}}, + "no action": {Caption: "X", Action: &pages.NoClientAction{}}, + "kept action": {Caption: "X", KeepAction: []byte{0}}, + } { + if _, err := navBottomBarItemBson(spec); err == nil { + t.Errorf("%s: accepted, want a refusal", name) + } + } +} diff --git a/mdl/backend/modelsdk/navigation_native_test.go b/mdl/backend/modelsdk/navigation_native_test.go index cf08d3bc64..267003a3f7 100644 --- a/mdl/backend/modelsdk/navigation_native_test.go +++ b/mdl/backend/modelsdk/navigation_native_test.go @@ -57,14 +57,20 @@ func TestNativeProfile_ReadsBottomBarActionAndIcon(t *testing.T) { func TestNativeProfile_WritesSync(t *testing.T) { doc := bson.D{{Key: "$Type", Value: "Navigation$NativeNavigationProfile"}, {Key: "Name", Value: "NativePhone"}, {Key: "OfflineEntityConfigs", Value: bson.A{navMarkerItems}}} - out := navPatchNativeProfile(doc, types.NavigationProfileSpec{HasSync: true, + out, err := navPatchNativeProfile(doc, types.NavigationProfileSpec{HasSync: true, OfflineEntities: []types.NavOfflineEntitySpec{{Entity: "M.Order", SyncMode: "All"}}}) + if err != nil { + t.Fatal(err) + } cfgs := navGetArray(out, "OfflineEntityConfigs") if len(cfgs) != 2 || navGetString(cfgs[1].(bson.D), "Entity") != "M.Order" { t.Errorf("sync not written: %v", cfgs) } // CONTROL: no sync block leaves the stored list alone. - out = navPatchNativeProfile(doc, types.NavigationProfileSpec{}) + out, err = navPatchNativeProfile(doc, types.NavigationProfileSpec{}) + if err != nil { + t.Fatal(err) + } if len(navGetArray(out, "OfflineEntityConfigs")) != 1 { t.Errorf("a statement without sync changed the list") } diff --git a/mdl/backend/modelsdk/navigation_omitted_clause_test.go b/mdl/backend/modelsdk/navigation_omitted_clause_test.go index 44b13a4808..f2100c62ee 100644 --- a/mdl/backend/modelsdk/navigation_omitted_clause_test.go +++ b/mdl/backend/modelsdk/navigation_omitted_clause_test.go @@ -167,9 +167,12 @@ func TestNavPatchNativeProfile_OmittedRoleHomesKeepStored(t *testing.T) { {Key: "Name", Value: "NativePhone"}, {Key: "RoleBasedNativeHomePages", Value: bson.A{navMarkerHomeItems, roleHome}}, } - out := navPatchNativeProfile(doc, types.NavigationProfileSpec{ + out, err := navPatchNativeProfile(doc, types.NavigationProfileSpec{ HomePages: []types.NavHomePageSpec{{IsPage: true, Target: "M.Home"}}, }) + if err != nil { + t.Fatal(err) + } items := navGetArray(out, "RoleBasedNativeHomePages") if len(items) != 2 || navGetString(items[1].(bson.D), "HomePagePage") != "M.UserHome" { t.Errorf("role-based native home page not kept: %v", items) diff --git a/mdl/backend/modelsdk/navigation_profile_add_test.go b/mdl/backend/modelsdk/navigation_profile_add_test.go index 67a5b76b87..7d99107634 100644 --- a/mdl/backend/modelsdk/navigation_profile_add_test.go +++ b/mdl/backend/modelsdk/navigation_profile_add_test.go @@ -190,10 +190,10 @@ func TestNativeProfileStartsWithNoHomePage(t *testing.T) { func TestNativeProfileStartsWithEmptyChildCollections(t *testing.T) { // OfflineEntityConfigs and RoleBasedNativeHomePages are stored EMPTY on the // fixture's own (otherwise configured) document — direct evidence of the - // unconfigured state. BottomBarItems is never touched by - // UpdateNavigationProfile for native profiles (a separate, tracked gap), so - // it must start empty here rather than carrying the fixture's configured - // bottom bar item forward. + // unconfigured state. BottomBarItems is only rewritten by + // UpdateNavigationProfile when the CREATE statement has a MENU block (see + // navPatchNativeProfile), so a freshly created profile must start empty here + // rather than carrying the fixture's configured bottom bar item forward. for _, tc := range []struct { key string marker int32 diff --git a/mdl/backend/modelsdk/navigation_write.go b/mdl/backend/modelsdk/navigation_write.go index 4f8412a630..dc43371a6e 100644 --- a/mdl/backend/modelsdk/navigation_write.go +++ b/mdl/backend/modelsdk/navigation_write.go @@ -12,6 +12,7 @@ import ( "github.com/mendixlabs/mxcli/mdl/bsonutil" "github.com/mendixlabs/mxcli/mdl/types" "github.com/mendixlabs/mxcli/model" + "github.com/mendixlabs/mxcli/sdk/pages" ) // UpdateNavigationProfile patches a navigation profile's home pages, login page, @@ -82,7 +83,11 @@ func (b *Backend) UpdateNavigationProfile(navDocID model.ID, profileName string, } found = true if navGetString(profDoc, "$Type") == "Navigation$NativeNavigationProfile" { - profiles[i] = navPatchNativeProfile(profDoc, spec) + patched, perr := navPatchNativeProfile(profDoc, spec) + if perr != nil { + return fmt.Errorf("UpdateNavigationProfile: %w", perr) + } + profiles[i] = patched } else { patched, err := navPatchWebProfile(profDoc, spec) if err != nil { @@ -324,7 +329,7 @@ func navGetDoc(doc bson.D, key string) bson.D { return nil } -func navPatchNativeProfile(doc bson.D, spec types.NavigationProfileSpec) bson.D { +func navPatchNativeProfile(doc bson.D, spec types.NavigationProfileSpec) (bson.D, error) { // Patch a copy: navSetField writes in place, and a caller's stored profile // must not change under it when no field is appended. doc = append(bson.D(nil), doc...) @@ -369,13 +374,128 @@ func navPatchNativeProfile(doc bson.D, spec types.NavigationProfileSpec) bson.D // A native profile stores its offline configs as a web profile does. The // executor refuses the clauses this writer cannot apply to a native - // profile (its bottom bar, login and not-found pages, on sync error), so - // none is ignored in silence (ako/mxcli#980). + // profile (login and not-found pages, on sync error), so none is ignored + // in silence (ako/mxcli#980). if spec.HasSync { doc = navSetField(doc, "OfflineEntityConfigs", navOfflineConfigs(navGetArray(doc, "OfflineEntityConfigs"), spec.OfflineEntities)) } - return doc + if spec.HasMenu { + barItems := bson.A{int32(2)} + for _, mi := range spec.MenuItems { + bar, err := navBottomBarItemBson(mi) + if err != nil { + return nil, err + } + barItems = append(barItems, bar) + } + doc = navSetField(doc, "BottomBarItems", barItems) + } + return doc, nil +} + +// navBottomBarItemBson builds a NativePages$BottomBarItem from a menu item spec. +// +// Mendix's native bottom bar is flat and page-only — NativePages$BottomBarItem +// (modelsdk/gen/nativepages) has no Items property (no sub-menus, unlike the web +// Menu's Menus$MenuItem) and its only navigation target is Page, a by-name +// reference to Forms$Page (its pre-8.15.0 Action property, which could carry a +// microflow action, is gone on every Mendix version this project targets — see +// nativepages.VersionInfos). A spec built from MDL's shared NavMenuItemSpec can +// carry either of those, so both are rejected explicitly rather than silently +// dropped, matching this project's "no silent unsupported migrations" stance. +// +// Icon is deliberately never written here. The one real reference document +// (native-pwa-migrator's fixtures/native-phone-minimal) has a Forms$GlyphIcon on +// its bottom bar item, but that is this fixture author's choice, not a Studio +// Pro create-time default — nativepages.VersionInfos does not mark "caption"'s +// sibling "icon" as Required, and the web Menu's ICON clause only ever builds a +// Forms$IconCollectionIcon (navMenuIconBson), which has never been confirmed to +// be a valid choice for a native BottomBarItem specifically (a different +// convention on the native side is exactly what the fixture's GlyphIcon shows). +// Emitting an unconfirmed shape risks the failure this project exists to avoid — +// a document that builds clean and will not open in Studio Pro — so an ICON +// clause on a native menu item is rejected until a real Studio-Pro-authored +// IconCollectionIcon bottom bar item is found to pin it against. +func navBottomBarItemBson(mi types.NavMenuItemSpec) (bson.D, error) { + if len(mi.Items) > 0 { + return nil, fmt.Errorf("native bottom bar item %q: sub-items are not supported — Mendix's native bottom bar menu is flat", mi.Caption) + } + page, err := navBottomBarPage(mi) + if err != nil { + return nil, err + } + if mi.Icon != "" { + return nil, fmt.Errorf("native bottom bar item %q: ICON is not supported yet — Forms$IconCollectionIcon is unconfirmed for native bottom bar items; set it in Studio Pro", mi.Caption) + } + return bson.D{ + {Key: "$ID", Value: navID()}, + {Key: "$Type", Value: "NativePages$BottomBarItem"}, + {Key: "Caption", Value: navBottomBarCaptionBson(mi.Caption)}, + {Key: "Icon", Value: nil}, + {Key: "Page", Value: page}, + }, nil +} + +// navBottomBarPage is the page a bottom bar item opens. The executor hands the +// item's OnClick over as a built client action (ako/mxcli#980), a caller other +// than the executor only the legacy Page target; either way the only action a +// BottomBarItem can store is a by-name Page, so every other one — a microflow, +// nanoflow, sign out, an action kept from storage — is refused rather than +// written as nothing. +func navBottomBarPage(mi types.NavMenuItemSpec) (string, error) { + refuse := func(what string) (string, error) { + return "", fmt.Errorf("native bottom bar item %q: %s is not supported — the native bottom bar can only open a page", mi.Caption, what) + } + switch { + case len(mi.KeepAction) > 0: + return refuse("a stored action the item does not restate") + case mi.Microflow != "": + return refuse("a microflow target") + case mi.SignOut: + return refuse("sign out") + } + page := mi.Page + switch a := mi.Action.(type) { + case nil, *pages.NoClientAction: + case *pages.PageClientAction: + if len(a.ParameterMappings) > 0 { + return refuse("a page argument") + } + page = a.PageName + default: + return refuse(fmt.Sprintf("the action %T", a)) + } + if page == "" { + return "", fmt.Errorf("native bottom bar item %q: a page target is required — the native bottom bar has no other action", mi.Caption) + } + return page, nil +} + +// navBottomBarCaptionBson builds a BottomBarItem's Caption (Texts$Text). +// +// Deliberately NOT navCaptionBson: that helper's Items marker is 1, but the +// native-phone-minimal fixture's own Texts$Text.Items — on this same +// BottomBarItem's Caption, on its sibling MenuItem's Caption, and on the web +// profile's AppTitle — is uniformly marker 3 (confirmed by dumping the fixture's +// raw BSON), matching modelsdk/codec's own default for an unregistered PartList +// child type (Texts$Translation has no codec.RegisterListMarker override). +// navCaptionBson's marker 1 was not re-verified here — it is a separate, +// pre-existing write path (web menu captions) outside this change's scope. +func navBottomBarCaptionBson(text string) bson.D { + return bson.D{ + {Key: "$ID", Value: navID()}, + {Key: "$Type", Value: "Texts$Text"}, + {Key: "Items", Value: bson.A{ + int32(3), + bson.D{ + {Key: "$ID", Value: navID()}, + {Key: "$Type", Value: "Texts$Translation"}, + {Key: "LanguageCode", Value: model.AuthoringLanguage()}, + {Key: "Text", Value: text}, + }, + }}, + } } // navMergeRoleHomes is a profile's role-based home pages after a statement that diff --git a/mdl/executor/cmd_navigation.go b/mdl/executor/cmd_navigation.go index e45c8d1790..4597d18fff 100644 --- a/mdl/executor/cmd_navigation.go +++ b/mdl/executor/cmd_navigation.go @@ -203,10 +203,10 @@ func warnOfflineWithoutPWA(ctx *ExecContext, s *ast.CreateNavigationStmt, kind s // checkProfileClauses refuses what the statement says that the profile cannot // take, before anything is written (ako/mxcli#980). // -// A native profile's writer sets its home pages and offline sync and nothing -// else, so a menu block, login or not-found page or on-sync-error clause on one -// was dropped in silence: the statement reported "updated" and the bottom bar -// stayed as it was. Its flow home is a nanoflow — `home microflow` there is +// A native profile's writer sets its home pages, offline sync and bottom bar +// (the { } block) and nothing else, so a login or not-found page or +// on-sync-error clause on one was dropped in silence: the statement reported +// "updated" and the profile stayed as it was. Its flow home is a nanoflow — `home microflow` there is // what describe used to print, so it is read as the nanoflow and warned about — // while a web profile's is a microflow, so `home nanoflow` there is refused. func checkProfileClauses(ctx *ExecContext, s *ast.CreateNavigationStmt, isNative bool) error { @@ -224,8 +224,6 @@ func checkProfileClauses(ctx *ExecContext, s *ast.CreateNavigationStmt, isNative "and leaving it out is how it used to be dropped without a word — remove it from the statement and set it in Studio Pro", s.ProfileName, what) } switch { - case s.HasMenuBlock: - return refuse("its bottom bar (the { } block)") case s.LoginPage != nil: return refuse("login page") case s.NotFoundPage != nil: @@ -821,25 +819,11 @@ func outputNavigationProfile(ctx *ExecContext, p *types.NavigationProfile) { } } - // A native profile's bottom bar is not written by mxcli, so it is not a - // { } block exec would have to refuse: it is listed as comments, each item - // as it would read (ako/mxcli#980). - if p.IsNative && len(p.MenuItems) > 0 { - fmt.Fprintln(ctx.Output, " -- bottom bar (not written by mxcli; set it in Studio Pro):") - var bar strings.Builder - printMenuMDL(ctx, &bar, p.MenuItems, 0, "CREATE NAVIGATION") - for _, line := range strings.Split(strings.TrimRight(bar.String(), "\n"), "\n") { - fmt.Fprintf(ctx.Output, " -- %s\n", strings.TrimPrefix(line, "-- ")) - } - fmt.Fprintln(ctx.Output, ";") - fmt.Fprintln(ctx.Output) - return - } - - // Menu items: the profile's children, in { } after its clauses (R2). + // Menu items: the profile's children, in { } after its clauses (R2). A + // native profile's are its bottom bar, written by the same block. if len(p.MenuItems) > 0 { fmt.Fprintln(ctx.Output, "{") - printMenuMDL(ctx, ctx.Output, p.MenuItems, 1, "CREATE NAVIGATION") + printMenuMDLFor(ctx, ctx.Output, p.MenuItems, 1, "CREATE NAVIGATION", p.IsNative) fmt.Fprintln(ctx.Output, "};") } else { fmt.Fprintln(ctx.Output, ";") @@ -883,7 +867,17 @@ func menuItemTarget(item *types.NavMenuItem) string { // (renderClientActionMDL), so every kind a menu item stores — a nanoflow call, // open link, create object — and every `with ( … )` setting prints, and what // MDL cannot express is said in a comment rather than left out (ako/mxcli#980). +// +// native is true for a NativePhone profile's bottom bar: CREATE NAVIGATION +// cannot author ANY icon there yet (see navBottomBarItemBson), so every icon — +// including an IconCollectionIcon, which the web Menu can reproduce — gets the +// "not reproducible" note instead of an Icon: property. func printMenuMDL(ctx *ExecContext, w io.Writer, items []*types.NavMenuItem, depth int, reproducer string) { + printMenuMDLFor(ctx, w, items, depth, reproducer, false) +} + +// printMenuMDLFor is printMenuMDL with the native flag above. +func printMenuMDLFor(ctx *ExecContext, w io.Writer, items []*types.NavMenuItem, depth int, reproducer string, native bool) { indent := strings.Repeat(" ", depth) for _, item := range items { var props []string @@ -899,7 +893,7 @@ func printMenuMDL(ctx *ExecContext, w io.Writer, items []*types.NavMenuItem, dep // has no OnClick on one, so the rewrite keeps it only as stored. actionNote = fmt.Sprintf("-- menu %s: its action (%s) belongs to a sub-menu and has no MDL form there", menuCaptionNote(item.Caption), onClick) } - if icon := menuItemIconMDL(item); icon != "" { + if icon := menuItemIconMDL(item, native); icon != "" { props = append(props, "Icon: "+icon) } propList := "" @@ -909,12 +903,12 @@ func printMenuMDL(ctx *ExecContext, w io.Writer, items []*types.NavMenuItem, dep if len(item.Items) > 0 { // Sub-menu container fmt.Fprintf(w, "%smenu %s%s {\n", indent, mdlQuote(ctx, item.Caption), propList) - printMenuMDL(ctx, w, item.Items, depth+1, reproducer) + printMenuMDLFor(ctx, w, item.Items, depth+1, reproducer, native) fmt.Fprintf(w, "%s}\n", indent) } else { fmt.Fprintf(w, "%smenu item %s%s\n", indent, mdlQuote(ctx, item.Caption), propList) } - if note := menuItemIconNote(item, reproducer); note != "" { + if note := menuItemIconNote(item, reproducer, native); note != "" { fmt.Fprintf(w, "%s%s\n", indent, note) } if actionNote != "" { @@ -945,8 +939,13 @@ func legacyMenuItemOnClick(item *types.NavMenuItem) string { // All three of Mendix's icon elements have a form now. Only the collection one // used to, so DESCRIBE emitted a comment for a glyph or image icon — and since // CREATE NAVIGATION is a full replacement, re-running that output DELETED the -// icon it had just declined to describe. -func menuItemIconMDL(item *types.NavMenuItem) string { +// icon it had just declined to describe. A native bottom bar item cannot +// reproduce any icon yet (navBottomBarItemBson rejects ICON unconditionally), +// so it always falls through to the note. +func menuItemIconMDL(item *types.NavMenuItem, native bool) string { + if native { + return "" + } switch types.MenuIconKindOf(item.IconType) { case types.MenuIconGlyph: // The code is the whole identity of a glyph. Without it there is nothing @@ -972,18 +971,21 @@ func menuItemIconMDL(item *types.NavMenuItem) string { // menuItemIconNote flags an icon DESCRIBE still cannot round-trip, so re-running // the output loses it visibly rather than silently. // -// All three icon elements are reproducible now, so this fires only on what is -// genuinely beyond the language: a stored $Type this build does not know, or a -// variant whose payload is missing (a glyph with no Code, a named icon with no -// name) — where emitting a clause would rebuild a DIFFERENT icon rather than the -// same one. Guessing between polymorphic variants is the failure mode that -// produces a document mxbuild accepts and Studio Pro cannot open. -func menuItemIconNote(item *types.NavMenuItem, reproducer string) string { +// All three icon elements are reproducible now on a web menu item, so this +// fires only on what is genuinely beyond the language: a stored $Type this +// build does not know, or a variant whose payload is missing (a glyph with no +// Code, a named icon with no name) — where emitting a clause would rebuild a +// DIFFERENT icon rather than the same one. On a native bottom bar item no icon +// at all is reproducible yet (navBottomBarItemBson rejects ICON +// unconditionally), so every icon there gets this note. Guessing between +// polymorphic variants is the failure mode that produces a document mxbuild +// accepts and Studio Pro cannot open. +func menuItemIconNote(item *types.NavMenuItem, reproducer string, native bool) string { if item.IconType == "" { return "" } // If there is a clause for it, there is nothing to flag. - if menuItemIconMDL(item) != "" { + if menuItemIconMDL(item, native) != "" { return "" } target := item.Icon diff --git a/mdl/executor/cmd_navigation_icon_roundtrip_test.go b/mdl/executor/cmd_navigation_icon_roundtrip_test.go index 2b9f6d519d..b462316ad2 100644 --- a/mdl/executor/cmd_navigation_icon_roundtrip_test.go +++ b/mdl/executor/cmd_navigation_icon_roundtrip_test.go @@ -60,14 +60,14 @@ func TestMenuIconMDL_RoundTripsEveryVariant(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - got := menuItemIconMDL(&tc.item) + got := menuItemIconMDL(&tc.item, false) if got != tc.want { t.Fatalf("menuItemIconMDL = %q, want %q", got, tc.want) } // It must also re-parse to the same kind, or DESCRIBE emits something // that reads back as a different icon — which is what the bare form // would have done for an image icon. - if note := menuItemIconNote(&tc.item, "CREATE NAVIGATION"); note != "" { + if note := menuItemIconNote(&tc.item, "CREATE NAVIGATION", false); note != "" { t.Errorf("still flagged as unreproducible: %q", note) } }) @@ -86,10 +86,10 @@ func TestMenuIconMDL_DeclinesWhatItCannotRebuild(t *testing.T) { // A $Type this build does not know must never be guessed at. {IconType: "Forms$SomeFutureIcon", Icon: "M.X.y"}, } { - if got := menuItemIconMDL(&item); got != "" { + if got := menuItemIconMDL(&item, false); got != "" { t.Errorf("%s: emitted %q, want no clause", item.IconType, got) } - if note := menuItemIconNote(&item, "CREATE NAVIGATION"); !strings.Contains(note, "not reproducible") { + if note := menuItemIconNote(&item, "CREATE NAVIGATION", false); !strings.Contains(note, "not reproducible") { t.Errorf("%s: dropped silently instead of being flagged: %q", item.IconType, note) } } diff --git a/mdl/executor/cmd_navigation_icon_test.go b/mdl/executor/cmd_navigation_icon_test.go index 1a8de1055b..02935c7c0a 100644 --- a/mdl/executor/cmd_navigation_icon_test.go +++ b/mdl/executor/cmd_navigation_icon_test.go @@ -19,6 +19,13 @@ func menuMDL(items []*types.NavMenuItem) string { return b.String() } +// nativeMenuMDL is menuMDL for a NativePhone profile's bottom bar. +func nativeMenuMDL(items []*types.NavMenuItem) string { + var b bytes.Buffer + printMenuMDLFor(nil, &b, items, 0, "CREATE NAVIGATION", true) + return b.String() +} + // DESCRIBE emits re-executable MDL, so an icon it read must come back out — the // alternative is output that silently rewrites the menu when replayed. The // hyphenated segment has to be re-quoted: `align-center` lexes as HYPHENATED_ID, @@ -137,6 +144,26 @@ func TestPrintMenuMDL_StillFlagsWhatItCannotRebuild(t *testing.T) { } } +// A native profile's bottom bar cannot author ANY icon yet (navBottomBarItemBson +// rejects ICON unconditionally) — including an IconCollectionIcon, which the web +// Menu reproduces fine. DESCRIBE must flag it instead of emitting a clause that +// would fail on replay. +func TestPrintMenuMDL_NativeNeverEmitsAnIconClause(t *testing.T) { + got := nativeMenuMDL([]*types.NavMenuItem{{ + Caption: "Home", + Page: "NativeMobile.Home_Native", + Icon: "Atlas_Core.Atlas.home", + IconType: "Forms$IconCollectionIcon", + }}) + stmt := strings.SplitN(got, "\n", 2)[0] + if strings.Contains(stmt, " icon ") { + t.Errorf("emitted an ICON clause for a native bottom bar item, which replay would reject: %q", got) + } + if !strings.Contains(got, "-- icon") || !strings.Contains(got, "Atlas_Core.Atlas.home") { + t.Errorf("the unreproducible native icon was dropped silently: %q", got) + } +} + // No icon means no clause and no note — the common case must stay clean. func TestPrintMenuMDL_SilentWhenThereIsNoIcon(t *testing.T) { got := menuMDL([]*types.NavMenuItem{{Caption: "Dashboard", Page: "M.Dash"}}) diff --git a/mdl/executor/cmd_navigation_native_test.go b/mdl/executor/cmd_navigation_native_test.go index 5866c5a012..8f1c6e7816 100644 --- a/mdl/executor/cmd_navigation_native_test.go +++ b/mdl/executor/cmd_navigation_native_test.go @@ -38,11 +38,11 @@ func runNav(t *testing.T, mb *mock.MockBackend, script string) (string, error) { return buf.String(), err } -// ako/mxcli#980: the native writer applies home pages and sync only, so a menu -// block (the bottom bar), login / not-found page or on-sync-error on a native -// profile was dropped while exec reported "updated". It is refused now. +// ako/mxcli#980: the native writer applies home pages, sync and the bottom bar +// only, so a login / not-found page or on-sync-error on a native profile was +// dropped while exec reported "updated". It is refused now. func TestNativeProfile_RefusesWhatItsWriterCannotApply(t *testing.T) { - for _, clause := range []string{"{ menu item 'X' ( OnClick: show page M.P ) }", "login page M.Login", "not found page M.NF", "on sync error continue"} { + for _, clause := range []string{"login page M.Login", "not found page M.NF", "on sync error continue"} { wrote := false mb := nativeNav() mb.UpdateNavigationProfileFunc = func(model.ID, string, types.NavigationProfileSpec) error { wrote = true; return nil } @@ -51,16 +51,19 @@ func TestNativeProfile_RefusesWhatItsWriterCannotApply(t *testing.T) { t.Errorf("%q: err=%v wrote=%v, want a refusal and no write", clause, err, wrote) } } - // CONTROL: home and sync are what the native writer applies. + // CONTROL: home, sync and the bottom bar are what the native writer applies. var got types.NavigationProfileSpec mb := nativeNav() mb.UpdateNavigationProfileFunc = func(_ model.ID, _ string, spec types.NavigationProfileSpec) error { got = spec; return nil } - if _, err := runNav(t, mb, "create or modify navigation NativePhone home nanoflow M.Home_NF sync ( sync M.Order all; );"); err != nil { + if _, err := runNav(t, mb, "create or modify navigation NativePhone home nanoflow M.Home_NF sync ( sync M.Order all; ) { menu item 'X' ( OnClick: show page M.P ) };"); err != nil { t.Fatal(err) } if !got.HasSync || len(got.HomePages) != 1 || got.HomePages[0].IsPage { t.Errorf("spec = %+v", got) } + if !got.HasMenu || len(got.MenuItems) != 1 || got.MenuItems[0].Caption != "X" { + t.Errorf("bottom bar not passed to the writer: %+v", got.MenuItems) + } } // `home nanoflow` is a native profile's; on a web profile it is refused, and @@ -77,7 +80,7 @@ func TestNavigationHomeNanoflow(t *testing.T) { } // Describe of a native profile names its nanoflow home `home nanoflow` and -// lists the bottom bar as comments, so its own output re-runs. +// emits the bottom bar as the profile's { } block, so its own output re-runs. func TestDescribeNativeProfile_ReRuns(t *testing.T) { mb := nativeNav() ctx, buf := newMockCtx(t, withBackend(mb)) @@ -86,8 +89,8 @@ func TestDescribeNativeProfile_ReRuns(t *testing.T) { if !strings.Contains(out, "home nanoflow M.Home_NF") || strings.Contains(out, "home microflow") { t.Errorf("native home:\n%s", out) } - if !strings.Contains(out, "-- menu item 'Reports' ( OnClick: show page M.Reports )") { - t.Errorf("bottom bar not listed as comments:\n%s", out) + if !strings.Contains(out, "{\n menu item 'Reports' ( OnClick: show page M.Reports )\n};") { + t.Errorf("bottom bar not emitted as a { } block:\n%s", out) } mb.UpdateNavigationProfileFunc = func(model.ID, string, types.NavigationProfileSpec) error { return nil } if _, err := runNav(t, mb, out); err != nil { From 597a95de51e9d4913c4fad1a24c4b900413aa52a Mon Sep 17 00:00:00 2001 From: Uraz Akgultan Date: Mon, 31 Aug 2026 17:08:59 +0200 Subject: [PATCH 03/18] fix(navigation): correct Texts.Items marker for MENU ITEM captions --- .../modelsdk/navigation_caption_test.go | 71 +++++++++++++++++++ mdl/backend/modelsdk/navigation_write.go | 22 +++--- 2 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 mdl/backend/modelsdk/navigation_caption_test.go diff --git a/mdl/backend/modelsdk/navigation_caption_test.go b/mdl/backend/modelsdk/navigation_caption_test.go new file mode 100644 index 0000000000..97a3acb99e --- /dev/null +++ b/mdl/backend/modelsdk/navigation_caption_test.go @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: Apache-2.0 + +// Pinned against native-pwa-migrator's fixtures/native-phone-minimal — its +// Responsive profile's Menu.Items[…].Caption (this exact call site), its +// AppTitle, and its NativePhone profile's BottomBarItem.Caption are all +// { $Type: "Texts$Text", Items: [3, [{ $Type: "Texts$Translation", … }]] }. +// Walking every Texts$Text.Items occurrence in that fixture and a second, +// unrelated fixture (expr-checker-minimal) found marker 3 in all 7300+ +// occurrences and zero exceptions — see navCaptionBson's doc comment. +package modelsdkbackend + +import ( + "testing" + + "go.mongodb.org/mongo-driver/bson" + + "github.com/mendixlabs/mxcli/mdl/types" +) + +func TestNavCaptionBson_MatchesTheFixtureShape(t *testing.T) { + got := navCaptionBson("Home") + if v, _ := profileKey(got, "$Type"); v != "Texts$Text" { + t.Errorf("$Type = %v", v) + } + items, ok := profileKey(got, "Items") + if !ok { + t.Fatal("no Items key at all") + } + arr, ok := items.(bson.A) + if !ok || len(arr) != 2 { + t.Fatalf("Items = %#v, want [marker, translation]", items) + } + if arr[0] != int32(3) { + t.Errorf("Items marker = %v, want 3 (measured on the fixture, not the old 1)", arr[0]) + } + translation, ok := arr[1].(bson.D) + if !ok { + t.Fatalf("Items[1] is %T, want bson.D", arr[1]) + } + if v, _ := profileKey(translation, "$Type"); v != "Texts$Translation" { + t.Errorf("Translation.$Type = %v", v) + } + if v, _ := profileKey(translation, "Text"); v != "Home" { + t.Errorf("Translation.Text = %v", v) + } +} + +// The regression this fixes is on the caption, only reachable through the +// full menu item — assert on the wiring, not just the helper. +func TestNavMenuItemBson_CaptionMarkerMatchesTheFixture(t *testing.T) { + item := navMenuItemBson(types.NavMenuItemSpec{Caption: "Home", Page: "M.Home"}) + caption, ok := profileKey(item, "Caption") + if !ok { + t.Fatal("no Caption key at all") + } + captionDoc, ok := caption.(bson.D) + if !ok { + t.Fatalf("Caption is %T, want bson.D", caption) + } + items, ok := profileKey(captionDoc, "Items") + if !ok { + t.Fatal("Caption: no Items key at all") + } + arr, ok := items.(bson.A) + if !ok || len(arr) == 0 { + t.Fatalf("Caption.Items = %#v", items) + } + if arr[0] != int32(3) { + t.Errorf("Caption.Items marker = %v, want 3", arr[0]) + } +} diff --git a/mdl/backend/modelsdk/navigation_write.go b/mdl/backend/modelsdk/navigation_write.go index dc43371a6e..4ecb85fd3e 100644 --- a/mdl/backend/modelsdk/navigation_write.go +++ b/mdl/backend/modelsdk/navigation_write.go @@ -474,14 +474,10 @@ func navBottomBarPage(mi types.NavMenuItemSpec) (string, error) { // navBottomBarCaptionBson builds a BottomBarItem's Caption (Texts$Text). // -// Deliberately NOT navCaptionBson: that helper's Items marker is 1, but the -// native-phone-minimal fixture's own Texts$Text.Items — on this same -// BottomBarItem's Caption, on its sibling MenuItem's Caption, and on the web -// profile's AppTitle — is uniformly marker 3 (confirmed by dumping the fixture's -// raw BSON), matching modelsdk/codec's own default for an unregistered PartList -// child type (Texts$Translation has no codec.RegisterListMarker override). -// navCaptionBson's marker 1 was not re-verified here — it is a separate, -// pre-existing write path (web menu captions) outside this change's scope. +// Written separately from navCaptionBson (rather than calling it) because this +// helper predates that one's marker fix and the two write paths (native bottom +// bar vs. web menu items) are independent; both now emit the same marker-3 +// shape — see navCaptionBson's doc comment. func navBottomBarCaptionBson(text string) bson.D { return bson.D{ {Key: "$ID", Value: navID()}, @@ -631,6 +627,16 @@ func navMenuIconBson(spec types.NavMenuItemSpec) interface{} { return append(doc, bson.E{Key: "Image", Value: spec.Icon}) } +// navCaptionBson builds a web MENU ITEM's caption (Texts$Text). +// +// Items marker is 3, not 1: confirmed by walking every Texts$Text.Items +// occurrence (7300+ across two real Studio-Pro-authored fixtures, including +// this exact call site — a web profile's Menu.Items[…].Caption — plus that +// same profile's AppTitle and a NativePhone profile's BottomBarItem.Caption, +// see navBottomBarCaptionBson) — marker 3 in every single case, matching +// modelsdk/codec's own default for an unregistered PartList child type +// (Texts$Translation has no codec.RegisterListMarker override — see +// modelsdk/codec/defaults.go's lookupListMarker). func navCaptionBson(text string) bson.D { return bson.D{ {Key: "$ID", Value: navID()}, From fd147dff79872ec5478317561476d56a10354177 Mon Sep 17 00:00:00 2001 From: Uraz Akgultan Date: Mon, 31 Aug 2026 22:07:30 +0200 Subject: [PATCH 04/18] feat(navigation): read and write glyph icons on native bottom bar items --- .../skills/mendix/manage-navigation/SKILL.md | 14 ++--- CHANGELOG.md | 13 +++-- cmd/mxcli/syntax/features_misc.go | 9 +-- docs/01-project/MDL_QUICK_REFERENCE.md | 6 +- .../modelsdk/navigation_bottombar_test.go | 46 ++++++++++++--- .../modelsdk/navigation_caption_test.go | 7 ++- mdl/backend/modelsdk/navigation_write.go | 47 ++++++++++----- mdl/executor/cmd_navigation.go | 22 +++---- mdl/executor/cmd_navigation_icon_test.go | 58 ++++++++++++++++--- 9 files changed, 161 insertions(+), 61 deletions(-) diff --git a/.claude/skills/mendix/manage-navigation/SKILL.md b/.claude/skills/mendix/manage-navigation/SKILL.md index 3190b87651..a48f104860 100644 --- a/.claude/skills/mendix/manage-navigation/SKILL.md +++ b/.claude/skills/mendix/manage-navigation/SKILL.md @@ -641,7 +641,7 @@ the web `Menu`, so: create or modify navigation NativePhone home page NativeMobile.Home_Native { - menu item 'Home' ( OnClick: show page NativeMobile.Home_Native ) + menu item 'Home' ( OnClick: show page NativeMobile.Home_Native, Icon: glyph 57377 ) }; ``` @@ -650,11 +650,11 @@ create or modify navigation NativePhone native bottom bar has no other action). A page argument is rejected too. - Nested `menu 'caption' { … }` sub-items are rejected — Mendix's bottom bar menu cannot nest. -- `Icon:` is rejected. mxcli's icon property only ever builds a - `Forms$IconCollectionIcon` here, and that has never been confirmed as valid - for a native bottom bar item (the one real reference document uses a - `Forms$GlyphIcon`, a different, unauthored-by-MDL shape). Add the icon in - Studio Pro. +- `Icon: glyph ` is the one confirmed icon shape for a native bottom bar + item — a numeric code, matching the one real reference document + (`Forms$GlyphIcon`). A collection or image icon (`Forms$IconCollectionIcon`/ + `Forms$ImageIcon`) is rejected — that shape has never been confirmed as + valid here; add it in Studio Pro instead. If the home page's layout has "Bottom bar" enabled, Mendix requires that page to appear in the profile's bottom bar menu and reports **CE6108** ("If the @@ -675,7 +675,7 @@ set, same as leaving a web profile's home page unset. - [ ] For an **offline** profile, no page it can reach binds an attribute across more than one association (CE6206) - [ ] For an **offline** profile, `progressive web app ( Precaching: true )` is set — without it no page opens offline - [ ] `app title` is set — a new project's browser tab reads `Mendix - ` otherwise -- [ ] For a **native** profile whose home page's layout requires a bottom bar (CE6108), the `{ }` block includes that page — flat items only, `OnClick: show page` only, no `Icon:` (add icons in Studio Pro) +- [ ] For a **native** profile whose home page's layout requires a bottom bar (CE6108), the `{ }` block includes that page — flat items only, `OnClick: show page` only; `Icon: glyph ` is supported, a collection or image icon is not (add those in Studio Pro) - [ ] All PAGE/MICROFLOW targets are fully qualified (`Module.Name`) - [ ] Role references in `for` clauses are fully qualified (`Module.Role`) - [ ] Menu items are in `{ }` with no `;` between them; sub-menu items in `menu 'caption' { ... }` diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c823ffbd0..59874c93b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1455,11 +1455,14 @@ Headline: **Widgets become first-class MDL rather than a second dialect.** Every the profile's `{ }` block as the web kinds do — so a home page whose layout requires a bottom bar can be added to it directly, clearing **CE6108** instead of needing Studio Pro. The native bottom bar is flat and page-only, - unlike the web `Menu`: a nested `MENU 'caption' { … }` group, an `OnClick` - other than `SHOW PAGE`, or an `Icon:` on a native menu item is rejected rather than - guessed at — see the doc comment on `navBottomBarItemBson` for why icons - specifically are not supported yet. Hybrid remains unsupported — no - reference document exists for it either. + unlike the web `Menu`: a nested `MENU 'caption' { … }` group or an `OnClick` + other than `SHOW PAGE` is rejected rather than guessed at. Its icon is a + numeric glyph code — `Icon: glyph ` — round-tripping through + `Forms$GlyphIcon`, the one shape confirmed against a real Studio-Pro-authored + NativePhone profile; a collection or image icon (`Forms$IconCollectionIcon`/ + `Forms$ImageIcon`) remains unconfirmed for a native item and is rejected — + see the doc comment on `navBottomBarItemBson`. Hybrid remains unsupported — + no reference document exists for it either. ### Changed diff --git a/cmd/mxcli/syntax/features_misc.go b/cmd/mxcli/syntax/features_misc.go index 7a3f0f2f98..1665c67e27 100644 --- a/cmd/mxcli/syntax/features_misc.go +++ b/cmd/mxcli/syntax/features_misc.go @@ -487,9 +487,10 @@ DISCONNECT;`, -- A NATIVE profile (Navigation$NativeNavigationProfile, no Kind property) has -- a { } block too -- its bottom bar -- but it is FLAT and PAGE-ONLY -- (NativePages$BottomBarItem): no nested MENU groups, no OnClick other than --- SHOW PAGE, no Icon: (add icons in Studio Pro -- IconCollectionIcon is --- unconfirmed for a native bottom bar item). A home page whose layout has --- "Bottom bar" enabled must appear in this block, or Mendix reports CE6108.`, +-- SHOW PAGE. Its icon is a numeric glyph code -- Icon: GLYPH -- not a +-- qualified name; a collection or image icon is unconfirmed for a native +-- bottom bar item and rejected. A home page whose layout has "Bottom bar" +-- enabled must appear in this block, or Mendix reports CE6108.`, Example: `mdl 1; CREATE OR MODIFY NAVIGATION Responsive APP TITLE 'Order Desk' @@ -514,7 +515,7 @@ CREATE OR MODIFY NAVIGATION TabletOffline CREATE OR MODIFY NAVIGATION NativePhone HOME PAGE MyModule.Home_Native { - MENU ITEM 'Home' ( OnClick: SHOW PAGE MyModule.Home_Native ) + MENU ITEM 'Home' ( OnClick: SHOW PAGE MyModule.Home_Native, Icon: GLYPH 57377 ) };`, SeeAlso: []string{"navigation.show"}, }) diff --git a/docs/01-project/MDL_QUICK_REFERENCE.md b/docs/01-project/MDL_QUICK_REFERENCE.md index b25f919ef4..f9c458691c 100644 --- a/docs/01-project/MDL_QUICK_REFERENCE.md +++ b/docs/01-project/MDL_QUICK_REFERENCE.md @@ -934,7 +934,7 @@ alter workflow Module.OrderApproval { | Profile kinds (web) | `Responsive` · `Phone` · `Tablet` · `ResponsiveOffline` · `PhoneOffline` · `TabletOffline` | A closed set. An invented name (`Mobile`) is an error, not a new profile: the runtime routes on User-Agent to Mendix's own kinds | | Profile kinds (native) | `NativePhone` | A separate closed set — different document type (`Navigation$NativeNavigationProfile`, no `Kind` property). Hybrid is not creatable (no reference document exists for it) | | Offline profiles | `create or modify navigation TabletOffline ...;` | Same properties as the online twin, but every page the profile can reach may bind an attribute across **at most one** association hop (**CE6206**). Creating one reports the documents that already exceed that | -| Native profiles | `create or modify navigation NativePhone home page MyModule.Home_Native { menu item 'Home' ( OnClick: show page MyModule.Home_Native ) };` | The `{ }` block is the bottom bar: flat and page-only — no sub-menus, no `OnClick` other than `show page`, no `Icon:`. Needed when the home page's layout requires a bottom bar (**CE6108**) | +| Native profiles | `create or modify navigation NativePhone home page MyModule.Home_Native { menu item 'Home' ( OnClick: show page MyModule.Home_Native ) };` | The `{ }` block is the bottom bar: flat and page-only — no sub-menus, no `OnClick` other than `show page`. Its icon is `Icon: glyph ` (a numeric code); a collection or image icon is unconfirmed for a native item and rejected. Needed when the home page's layout requires a bottom bar (**CE6108**) | Menu items are the profile's children, in `{ }` after its clauses, with no `;` between them: `menu item 'Caption' ( OnClick: show page M.P, Icon: … )`, where @@ -1020,6 +1020,10 @@ navigation` is a **full replacement**, re-running that output DELETED the icon the comment had just declined to describe. A `$Type` this build does not know is still flagged rather than guessed at. +On a **native** bottom bar item, only `Icon: glyph ` is a confirmed, +round-tripping shape (see the Native profiles row above) -- a collection or +image icon there is rejected. + ## Project Settings | Statement | Syntax | Notes | diff --git a/mdl/backend/modelsdk/navigation_bottombar_test.go b/mdl/backend/modelsdk/navigation_bottombar_test.go index 9e5f92ccfe..49405c4408 100644 --- a/mdl/backend/modelsdk/navigation_bottombar_test.go +++ b/mdl/backend/modelsdk/navigation_bottombar_test.go @@ -10,10 +10,11 @@ // Page: "NativeMobile.Home_Native" } // // (marker re-verified directly against the fixture's raw BSON, not copied from -// navCaptionBson — see navBottomBarCaptionBson's doc comment). mxcli never -// writes Icon (see navBottomBarItemBson's doc comment), so these tests check -// the four keys mxcli owns and the two malformed-input rejections that keep it -// from guessing a shape Studio Pro has never confirmed. +// navCaptionBson — see navBottomBarCaptionBson's doc comment). mxcli writes +// Icon only as a Forms$GlyphIcon (see navBottomBarItemBson's doc comment), so +// these tests check the four keys mxcli owns, glyph-icon acceptance, and the +// rejections that keep it from guessing a shape Studio Pro has never +// confirmed. package modelsdkbackend import ( @@ -37,7 +38,8 @@ func TestNavBottomBarItemBson_MatchesTheFixtureShape(t *testing.T) { if v, _ := profileKey(got, "Page"); v != "NativeMobile.Home_Native" { t.Errorf("Page = %v", v) } - // Never written — see navBottomBarItemBson's doc comment. + // No icon given — Icon stays an explicit null. See + // TestNavBottomBarItemBson_AcceptsGlyphIcon for the non-nil case. if v, ok := profileKey(got, "Icon"); !ok || v != nil { t.Errorf("Icon = %#v, want an explicit null", v) } @@ -101,11 +103,37 @@ func TestNavBottomBarItemBson_RequiresAPage(t *testing.T) { } func TestNavBottomBarItemBson_RejectsIcon(t *testing.T) { - _, err := navBottomBarItemBson(types.NavMenuItemSpec{ - Caption: "Home", Page: "M.Home", Icon: "Atlas_Core.Atlas.home", + for name, spec := range map[string]types.NavMenuItemSpec{ + "collection icon": {Caption: "Home", Page: "M.Home", Icon: "Atlas_Core.Atlas.home"}, + "image icon": {Caption: "Home", Page: "M.Home", Icon: "M.Images.Logo", IconKind: types.MenuIconImage}, + } { + if _, err := navBottomBarItemBson(spec); err == nil { + t.Errorf("%s: expected an error — only a glyph icon is confirmed for native bottom bar items", name) + } + } +} + +// Matches the fixture's exact shape: { $Type: "Forms$GlyphIcon", Code: 57377 }. +func TestNavBottomBarItemBson_AcceptsGlyphIcon(t *testing.T) { + got, err := navBottomBarItemBson(types.NavMenuItemSpec{ + Caption: "Home", Page: "NativeMobile.Home_Native", IconKind: types.MenuIconGlyph, IconCode: 57377, }) - if err == nil { - t.Fatal("expected an error for ICON — Forms$IconCollectionIcon is unconfirmed for native bottom bar items") + if err != nil { + t.Fatalf("navBottomBarItemBson: %v", err) + } + icon, ok := profileKey(got, "Icon") + if !ok || icon == nil { + t.Fatal("Icon key missing or null, want a Forms$GlyphIcon") + } + d, ok := icon.(bson.D) + if !ok { + t.Fatalf("Icon is %T, want bson.D", icon) + } + if v, _ := profileKey(d, "$Type"); v != "Forms$GlyphIcon" { + t.Errorf("Icon.$Type = %v, want Forms$GlyphIcon", v) + } + if v, _ := profileKey(d, "Code"); v != int32(57377) { + t.Errorf("Icon.Code = %v (%T), want int32 57377", v, v) } } diff --git a/mdl/backend/modelsdk/navigation_caption_test.go b/mdl/backend/modelsdk/navigation_caption_test.go index 97a3acb99e..13db52c107 100644 --- a/mdl/backend/modelsdk/navigation_caption_test.go +++ b/mdl/backend/modelsdk/navigation_caption_test.go @@ -12,7 +12,7 @@ package modelsdkbackend import ( "testing" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" "github.com/mendixlabs/mxcli/mdl/types" ) @@ -48,7 +48,10 @@ func TestNavCaptionBson_MatchesTheFixtureShape(t *testing.T) { // The regression this fixes is on the caption, only reachable through the // full menu item — assert on the wiring, not just the helper. func TestNavMenuItemBson_CaptionMarkerMatchesTheFixture(t *testing.T) { - item := navMenuItemBson(types.NavMenuItemSpec{Caption: "Home", Page: "M.Home"}) + item, err := navMenuItemBson(types.NavMenuItemSpec{Caption: "Home", Page: "M.Home"}) + if err != nil { + t.Fatalf("navMenuItemBson: %v", err) + } caption, ok := profileKey(item, "Caption") if !ok { t.Fatal("no Caption key at all") diff --git a/mdl/backend/modelsdk/navigation_write.go b/mdl/backend/modelsdk/navigation_write.go index 4ecb85fd3e..8172389cc6 100644 --- a/mdl/backend/modelsdk/navigation_write.go +++ b/mdl/backend/modelsdk/navigation_write.go @@ -405,18 +405,16 @@ func navPatchNativeProfile(doc bson.D, spec types.NavigationProfileSpec) (bson.D // carry either of those, so both are rejected explicitly rather than silently // dropped, matching this project's "no silent unsupported migrations" stance. // -// Icon is deliberately never written here. The one real reference document -// (native-pwa-migrator's fixtures/native-phone-minimal) has a Forms$GlyphIcon on -// its bottom bar item, but that is this fixture author's choice, not a Studio -// Pro create-time default — nativepages.VersionInfos does not mark "caption"'s -// sibling "icon" as Required, and the web Menu's ICON clause only ever builds a -// Forms$IconCollectionIcon (navMenuIconBson), which has never been confirmed to -// be a valid choice for a native BottomBarItem specifically (a different -// convention on the native side is exactly what the fixture's GlyphIcon shows). -// Emitting an unconfirmed shape risks the failure this project exists to avoid — -// a document that builds clean and will not open in Studio Pro — so an ICON -// clause on a native menu item is rejected until a real Studio-Pro-authored -// IconCollectionIcon bottom bar item is found to pin it against. +// Icon: the one real reference document (native-pwa-migrator's +// fixtures/native-phone-minimal) has a Forms$GlyphIcon on its bottom bar item +// — a numeric Code, not a qualified name — so that is the one shape written +// here, from `Icon: glyph ` (IconKind glyph). A collection or image icon +// is still rejected: neither has been confirmed as a valid choice for a native +// BottomBarItem specifically — the fixture's GlyphIcon is exactly the different +// convention that makes them unconfirmed. Emitting an unconfirmed shape risks +// the failure this project exists to avoid — a document that builds clean and +// will not open in Studio Pro — so they stay rejected until a real +// Studio-Pro-authored example of either is found to pin against. func navBottomBarItemBson(mi types.NavMenuItemSpec) (bson.D, error) { if len(mi.Items) > 0 { return nil, fmt.Errorf("native bottom bar item %q: sub-items are not supported — Mendix's native bottom bar menu is flat", mi.Caption) @@ -425,18 +423,37 @@ func navBottomBarItemBson(mi types.NavMenuItemSpec) (bson.D, error) { if err != nil { return nil, err } - if mi.Icon != "" { - return nil, fmt.Errorf("native bottom bar item %q: ICON is not supported yet — Forms$IconCollectionIcon is unconfirmed for native bottom bar items; set it in Studio Pro", mi.Caption) + icon, err := navBottomBarIconBson(mi) + if err != nil { + return nil, err } return bson.D{ {Key: "$ID", Value: navID()}, {Key: "$Type", Value: "NativePages$BottomBarItem"}, {Key: "Caption", Value: navBottomBarCaptionBson(mi.Caption)}, - {Key: "Icon", Value: nil}, + {Key: "Icon", Value: icon}, {Key: "Page", Value: page}, }, nil } +// navBottomBarIconBson is a bottom bar item's Icon: a Forms$GlyphIcon for a +// glyph, nil for no icon. That is the one icon shape pinned against a real +// Studio-Pro-authored document — see the fixture comment on +// navigation_bottombar_test.go — so a collection or image icon is refused. +func navBottomBarIconBson(mi types.NavMenuItemSpec) (any, error) { + switch { + case mi.IconKind == types.MenuIconGlyph: + return bson.D{ + {Key: "$ID", Value: navID()}, + {Key: "$Type", Value: "Forms$GlyphIcon"}, + {Key: "Code", Value: int32(mi.IconCode)}, + }, nil + case mi.Icon != "" || mi.IconKind != types.MenuIconNone: + return nil, fmt.Errorf("native bottom bar item %q: only a glyph icon is supported — a collection or image icon is unconfirmed for native bottom bar items; use Icon: glyph , or set it in Studio Pro", mi.Caption) + } + return nil, nil +} + // navBottomBarPage is the page a bottom bar item opens. The executor hands the // item's OnClick over as a built client action (ako/mxcli#980), a caller other // than the executor only the legacy Page target; either way the only action a diff --git a/mdl/executor/cmd_navigation.go b/mdl/executor/cmd_navigation.go index 4597d18fff..5b76b90832 100644 --- a/mdl/executor/cmd_navigation.go +++ b/mdl/executor/cmd_navigation.go @@ -868,10 +868,10 @@ func menuItemTarget(item *types.NavMenuItem) string { // open link, create object — and every `with ( … )` setting prints, and what // MDL cannot express is said in a comment rather than left out (ako/mxcli#980). // -// native is true for a NativePhone profile's bottom bar: CREATE NAVIGATION -// cannot author ANY icon there yet (see navBottomBarItemBson), so every icon — -// including an IconCollectionIcon, which the web Menu can reproduce — gets the -// "not reproducible" note instead of an Icon: property. +// native is true for a NativePhone profile's bottom bar: CREATE NAVIGATION can +// author only a glyph icon there (see navBottomBarItemBson), so a collection or +// image icon — which the web Menu can reproduce — gets the "not reproducible" +// note instead of an Icon: property. func printMenuMDL(ctx *ExecContext, w io.Writer, items []*types.NavMenuItem, depth int, reproducer string) { printMenuMDLFor(ctx, w, items, depth, reproducer, false) } @@ -939,11 +939,11 @@ func legacyMenuItemOnClick(item *types.NavMenuItem) string { // All three of Mendix's icon elements have a form now. Only the collection one // used to, so DESCRIBE emitted a comment for a glyph or image icon — and since // CREATE NAVIGATION is a full replacement, re-running that output DELETED the -// icon it had just declined to describe. A native bottom bar item cannot -// reproduce any icon yet (navBottomBarItemBson rejects ICON unconditionally), -// so it always falls through to the note. +// icon it had just declined to describe. A native bottom bar item can +// reproduce only a glyph icon (navBottomBarItemBson); a collection or image +// icon there falls through to the note. func menuItemIconMDL(item *types.NavMenuItem, native bool) string { - if native { + if native && types.MenuIconKindOf(item.IconType) != types.MenuIconGlyph { return "" } switch types.MenuIconKindOf(item.IconType) { @@ -975,9 +975,9 @@ func menuItemIconMDL(item *types.NavMenuItem, native bool) string { // fires only on what is genuinely beyond the language: a stored $Type this // build does not know, or a variant whose payload is missing (a glyph with no // Code, a named icon with no name) — where emitting a clause would rebuild a -// DIFFERENT icon rather than the same one. On a native bottom bar item no icon -// at all is reproducible yet (navBottomBarItemBson rejects ICON -// unconditionally), so every icon there gets this note. Guessing between +// DIFFERENT icon rather than the same one. On a native bottom bar item only a +// glyph icon is reproducible (navBottomBarItemBson); a collection or image +// icon there gets this note too. Guessing between // polymorphic variants is the failure mode that produces a document mxbuild // accepts and Studio Pro cannot open. func menuItemIconNote(item *types.NavMenuItem, reproducer string, native bool) string { diff --git a/mdl/executor/cmd_navigation_icon_test.go b/mdl/executor/cmd_navigation_icon_test.go index 02935c7c0a..fedb563837 100644 --- a/mdl/executor/cmd_navigation_icon_test.go +++ b/mdl/executor/cmd_navigation_icon_test.go @@ -10,6 +10,7 @@ import ( "github.com/mendixlabs/mxcli/mdl/ast" "github.com/mendixlabs/mxcli/mdl/types" "github.com/mendixlabs/mxcli/mdl/visitor" + "github.com/mendixlabs/mxcli/model" ) // menuMDL renders items through the DESCRIBE emitter. @@ -144,11 +145,11 @@ func TestPrintMenuMDL_StillFlagsWhatItCannotRebuild(t *testing.T) { } } -// A native profile's bottom bar cannot author ANY icon yet (navBottomBarItemBson -// rejects ICON unconditionally) — including an IconCollectionIcon, which the web -// Menu reproduces fine. DESCRIBE must flag it instead of emitting a clause that -// would fail on replay. -func TestPrintMenuMDL_NativeNeverEmitsAnIconClause(t *testing.T) { +// A native profile's bottom bar cannot author an IconCollectionIcon +// (navBottomBarItemBson accepts only a glyph) even though the web Menu +// reproduces one fine. DESCRIBE must flag it instead of emitting a property +// that would fail on replay. +func TestPrintMenuMDL_NativeNeverEmitsAnIconCollectionIcon(t *testing.T) { got := nativeMenuMDL([]*types.NavMenuItem{{ Caption: "Home", Page: "NativeMobile.Home_Native", @@ -156,14 +157,57 @@ func TestPrintMenuMDL_NativeNeverEmitsAnIconClause(t *testing.T) { IconType: "Forms$IconCollectionIcon", }}) stmt := strings.SplitN(got, "\n", 2)[0] - if strings.Contains(stmt, " icon ") { - t.Errorf("emitted an ICON clause for a native bottom bar item, which replay would reject: %q", got) + if strings.Contains(stmt, "Icon:") { + t.Errorf("emitted an Icon: property for a native bottom bar item, which replay would reject: %q", got) } if !strings.Contains(got, "-- icon") || !strings.Contains(got, "Atlas_Core.Atlas.home") { t.Errorf("the unreproducible native icon was dropped silently: %q", got) } } +// A native bottom bar item's glyph IS reproducible — the one icon shape +// navBottomBarItemBson accepts — so it gets `Icon: glyph `, not a note, +// and that output parses back to the same glyph. +func TestPrintMenuMDL_NativeRoundTripsAGlyphIcon(t *testing.T) { + got := nativeMenuMDL([]*types.NavMenuItem{{ + Caption: "Home", + Page: "NativeMobile.Home_Native", + IconType: "Forms$GlyphIcon", + IconCode: 57377, + }}) + want := "menu item 'Home' ( OnClick: show page NativeMobile.Home_Native, Icon: glyph 57377 )\n" + if got != want { + t.Errorf("got %q, want %q", got, want) + } + + script := "create or modify navigation NativePhone {\n" + got + "};" + prog, errs := visitor.Build(script) + if len(errs) > 0 { + t.Fatalf("DESCRIBE emitted output its own parser rejects:\n%s\nerrors: %v", script, errs) + } + stmt, ok := prog.Statements[0].(*ast.CreateNavigationStmt) + if !ok || len(stmt.MenuItems) != 1 { + t.Fatalf("re-parsed to %T", prog.Statements[0]) + } + if it := stmt.MenuItems[0]; it.IconKind != types.MenuIconGlyph || it.IconCode != 57377 { + t.Errorf("round trip changed the glyph: got (%v, %d), want (glyph, 57377)", it.IconKind, it.IconCode) + } +} + +// Exec hands a native item's glyph to the writer as IconKind/IconCode, the +// same fields a web item's glyph travels in. +func TestExecNativeNavigation_PassesTheGlyphIcon(t *testing.T) { + var got types.NavigationProfileSpec + mb := nativeNav() + mb.UpdateNavigationProfileFunc = func(_ model.ID, _ string, spec types.NavigationProfileSpec) error { got = spec; return nil } + if _, err := runNav(t, mb, "create or modify navigation NativePhone { menu item 'Home' ( OnClick: show page M.P, Icon: glyph 57377 ) };"); err != nil { + t.Fatal(err) + } + if len(got.MenuItems) != 1 || got.MenuItems[0].IconKind != types.MenuIconGlyph || got.MenuItems[0].IconCode != 57377 { + t.Errorf("spec.MenuItems = %+v, want one item with a glyph 57377", got.MenuItems) + } +} + // No icon means no clause and no note — the common case must stay clean. func TestPrintMenuMDL_SilentWhenThereIsNoIcon(t *testing.T) { got := menuMDL([]*types.NavMenuItem{{Caption: "Dashboard", Page: "M.Dash"}}) From a8569cb54da0eb00caeec680a808bb1f8b1bf651 Mon Sep 17 00:00:00 2001 From: Uraz Akgultan Date: Tue, 1 Sep 2026 07:47:09 +0200 Subject: [PATCH 05/18] fix(version): stamp local dev builds with git revision instead of a bare fallback --- cmd/mxcli/main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cmd/mxcli/main.go b/cmd/mxcli/main.go index 11f083c2d4..291977b33d 100644 --- a/cmd/mxcli/main.go +++ b/cmd/mxcli/main.go @@ -9,6 +9,7 @@ import ( "io" "os" "path/filepath" + "runtime/debug" "strings" "github.com/mendixlabs/mxcli/mdl/backend" @@ -335,9 +336,51 @@ func executeMDL(projectPath, mdlCmd string, setup ...func(*executor.Executor)) { } } +// devVersionFromBuildInfo derives a version string from Go's automatic VCS +// build stamping, which `go build`/`go run` populate from the surrounding git +// checkout even when no -ldflags -X main.Version=... was passed (`make build`'s +// LDFLAGS sets Version explicitly via `git describe` for release-style builds; +// this is the fallback for a bare `go build ./cmd/mxcli` during local mxcli +// development). Without this, an unstamped build silently fell back to the +// literal "0.1.0" below, which is indistinguishable from a real release and +// carries no git identity at all — a real gap surfaced by +// native-pwa-migrator's mxcli version-check tests expecting to trace a binary +// back to a source revision. Returns "" if no VCS revision is available (e.g. +// building outside a git checkout), leaving the "0.1.0" fallback as an +// explicitly-unidentifiable last resort. +func devVersionFromBuildInfo() string { + info, ok := debug.ReadBuildInfo() + if !ok { + return "" + } + var revision string + var modified bool + for _, setting := range info.Settings { + switch setting.Key { + case "vcs.revision": + revision = setting.Value + case "vcs.modified": + modified = setting.Value == "true" + } + } + if revision == "" { + return "" + } + short := revision + if len(short) > 8 { + short = short[:8] + } + if modified { + return "0.0.0-dev+g" + short + ".dirty" + } + return "0.0.0-dev+g" + short +} + func init() { if Version != "" { version = Version + } else if dev := devVersionFromBuildInfo(); dev != "" { + version = dev } if BuildTime != "" { rootCmd.Version = version + " (" + BuildTime + ")" From 965402902614c1b08ffa5009926c785eee8cd0d8 Mon Sep 17 00:00:00 2001 From: Uraz Akgultan Date: Wed, 4 Nov 2026 08:46:53 +0100 Subject: [PATCH 06/18] docs(navigation): add the mdl 1 header to the native profile examples The skills conformance test (TestSkillsTeachMDL1) requires every complete script in a skill to start with `mdl 1;`. The two NativePhone examples added on this branch predated that rule on main. Co-Authored-By: Claude Opus 5.5 --- .claude/skills/mendix/manage-navigation/SKILL.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.claude/skills/mendix/manage-navigation/SKILL.md b/.claude/skills/mendix/manage-navigation/SKILL.md index a48f104860..bf8e8effc2 100644 --- a/.claude/skills/mendix/manage-navigation/SKILL.md +++ b/.claude/skills/mendix/manage-navigation/SKILL.md @@ -20,10 +20,10 @@ description: "Inspect and change navigation profiles in MDL — home pages, menu | 458-497 | Common Patterns | | 498-550 | Menu Documents (standalone, reusable) | | 551-621 | Offline Profiles | -| 622-671 | Native Profiles | -| 672-689 | Checklist | -| 690-693 | Offline synchronization (`CREATE NAVIGATION … SYNC (…)`) | -| 694-696 | Menu documents (CREATE OR MODIFY/DESCRIBE/DROP MENU) | +| 622-673 | Native Profiles | +| 674-691 | Checklist | +| 692-695 | Offline synchronization (`CREATE NAVIGATION … SYNC (…)`) | +| 696-698 | Menu documents (CREATE OR MODIFY/DESCRIBE/DROP MENU) | # Navigation Management Skill @@ -624,6 +624,7 @@ stored. MDL does not author per-entity sync modes — set those in Studio Pro. `NativePhone` is created the same way: ```sql +mdl 1; create or modify navigation NativePhone home page NativeMobile.Home_Native; ``` @@ -638,6 +639,7 @@ the web kinds — but it is flat and page-only.** A native profile's bottom bar the web `Menu`, so: ```sql +mdl 1; create or modify navigation NativePhone home page NativeMobile.Home_Native { From 578c5a6bab472954b0d8f5fc2bf4931c36c0d640 Mon Sep 17 00:00:00 2001 From: karahanharunn Date: Fri, 20 Nov 2026 08:53:45 +0100 Subject: [PATCH 07/18] Describe a native mobile widget by its own keyword Co-Authored-By: Claude Opus 5.5 --- ...ative-widget-described-as-web-keyword.json | 1 + CHANGELOG.md | 1 + mdl/executor/cmd_pages_describe_output.go | 10 ++ mdl/executor/cmd_pages_describe_pluggable.go | 13 +- .../describe_native_widget_keyword_test.go | 136 ++++++++++++++++++ 5 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-widget-described-as-web-keyword.json create mode 100644 mdl/executor/describe_native_widget_keyword_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-widget-described-as-web-keyword.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-widget-described-as-web-keyword.json new file mode 100644 index 0000000000..619e2f74d5 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-widget-described-as-web-keyword.json @@ -0,0 +1 @@ +{"area": "mdl/executor", "date": "2026-11-17", "symptom": "with Native Mobile Resources installed, describe printed a native widget left at its defaults under the last segment of its id: `nativegallery`/`nativebadge`/`nativeimage` came out as the web `gallery`/`badge`/`image` (re-run rebuilt the page with the WEB widget, check clean), and `activityindicator`, `backgroundgradient`, `notifications`, `qrcode`, `repeater`, `safeareaview`, `signature` were refused on re-run (MDL-WIDGET25); a native gallery with a data source was described as the web gallery too", "cause": "extractCustomWidgetType's default returned the id's last segment, which routes describe — `gallery`/`image` landed in the web widgets' dedicated branches — and the bare branch (a pluggable widget with no non-default content) printed that segment instead of asking pluggableWidgetHeader, which the generic branch already used", "file": "mdl/executor/cmd_pages_describe_pluggable.go (extractCustomWidgetType), mdl/executor/cmd_pages_describe_output.go (bare custom-widget branch)", "fix": "a last segment naming a dedicated branch is routed as `customwidget`; the bare branch names a widget with no branch of its own through pluggableWidgetHeader (definition keyword where it round-trips, else the id form)", "insight": "#1463 fixed the native/web keyword collision at init and load time but not on the way out: describe had a second, independent name derivation. Probing every widget of a package (39 pages, describe -> check -> exec) found it in minutes where the one-widget repro hid it: only widgets left at their defaults took the bare branch, so a widget with any setting described correctly", "refs": [], "test": "mdl/executor/describe_native_widget_keyword_test.go"} diff --git a/CHANGELOG.md b/CHANGELOG.md index a4aae40112..f3df806ee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **`check` rejects a value of the wrong type in a `declare`, `set` or `return`** (ako/mxcli#1258) — `declare $X Integer = 'abc';`, `set $X = 'abc';` and a `return` of the wrong type in a flow with a return type passed `check` and `exec` and failed the build with CE0117 (Mendix CLI 2: CE0844). The value is now checked against the declared primitive type with the rule already used for call arguments: Integer and Long pass into each other and widen to Decimal, every other primitive mismatch is reported as E009. `empty` into a Boolean, enumerations, objects, lists and values of unknown kind stay silent, and a computed Decimal into an Integer or Long by `declare` or `set` is left to MDL041. Measured on MxBuild 11.16.1 over 216 microflows. - **`check` rejects an expression that reads a variable nothing defines** (ako/mxcli#1258) — `return $Nope + 1;` with no `$Nope` anywhere passed `check` and `exec` and failed the build with CE0109 "Undefined variable". New MDL098, for the expressions of return, if, declare, set, create/change members, log, show message and validation feedback, in microflows and nanoflows. A name counts as defined if a parameter or any statement of the flow produces it, or it is one MxBuild accepts with no declaration (`$currentUser`, `$currentSession`, `$latestError`, `$latestHttpResponse`, `$latestSoapFault`, `$currentIndex`, `$currentObject`). Measured on MxBuild 11.16.1. - **`check` rejects `returns T as $R` when a path ends the flow without `$R`** (ako/mxcli#1258) — MDL003 exempts the AS clause because the end event returns `$R`, which holds only while `$R` has a value there. A flow with a path off its end and no top-level `$R` passed `check` and `exec` and failed the build with CE0109 "Undefined variable" (or CE0108 when `$R` is defined only inside a branch or loop). New MDL097, microflow and nanoflow. Measured on MxBuild 11.16.1. +- **`describe` names a native mobile widget by its own keyword** — a native widget left at its defaults was described under the last part of its id. So `nativegallery`, `nativebadge` and `nativeimage` came out as the web `gallery`, `badge` and `image`, and re-running the description replaced them with the web widget while `check` passed. Seven more (`activityindicator`, `qrcode`, `repeater`, `safeareaview`, `signature`, `notifications`, `backgroundgradient`) came out under names no widget has, and were refused on re-run (MDL-WIDGET25). A native gallery with a data source was described as the web gallery as well. Each is now described by the keyword `widget init` gave it, or as `pluggablewidget ''` when the project has no definition for it. Measured with Native Mobile Resources 12.6.0 on 11.13.0: all 39 native widgets now describe, pass `check` and re-run as Unchanged. - **`fix widgets` and `fix design-properties` use the project's own Mendix version of `mx`** (ako/mxcli#2321) — they took the version as a preference, so on macOS an `mx` on PATH or another Studio Pro install ran, and `mx update-widgets` refused with "Project is in different Mendix version". They now take an `mx` of exactly the project's version. On Linux that version is downloaded when it is missing. On macOS and Windows, where no matching `mx` is installed, they say which version is needed and how to pass it with `--mx`. - **Parallel `mxcli exec` runs on one project no longer lose each other's writes** (ako/mxcli#2326) — measured with 8 parallel scripts: every process reported success and 2 to 6 of the 16 entities were missing (the reporter saw all of them fail instead). A script, or a `-c`, that writes now holds the project's lock (`.mxcli/write.lock`) for its whole run. A second writer waits up to 60 seconds, then changes nothing and exits 75, naming the holder. A lock left by a crashed run is taken over. Read-only runs take no lock. With the lock, all 16 entities land in every round. - **`run restart` names the secret it cannot replay** (ako/mxcli#2313) — a restart refused because of a literal secret printed only a generic `--db-password @env:` hint. The `--constant X=@env:VAR` references are recorded and replayed, so the hint read as if they were not. The refusal now lists each flag stored redacted, such as `--constant Helpdesk.OpenRouterKey` or `--db-password`, and says that the values given as references are replayed. diff --git a/mdl/executor/cmd_pages_describe_output.go b/mdl/executor/cmd_pages_describe_output.go index 8ad3693098..a8b5f3d8d3 100644 --- a/mdl/executor/cmd_pages_describe_output.go +++ b/mdl/executor/cmd_pages_describe_output.go @@ -1033,6 +1033,16 @@ func outputWidgetMDLV3(ctx *ExecContext, w rawWidget, indent int) { } } else { header := fmt.Sprintf("%s %s", widgetType, mdlIdent(w.Name)) + // A widget with no branch of its own is named the way the + // generic branch names it — its definition's keyword where that + // round-trips, else the id form. widgetType is the id's last + // segment, which names the web widget for a native one + // (`badge`) or no widget at all (`activityindicator`), so a + // native widget left at its defaults re-ran as the web widget + // or was refused. + if !isKnownCustomWidgetType(widgetType) && w.WidgetID != "" { + header = pluggableWidgetHeader(ctx.GetWidgetRegistry(), w.WidgetID, w.Name) + } props := []string{} if w.Caption != "" { props = append(props, fmt.Sprintf("Label: %s", mdlQuote(ctx, w.Caption))) diff --git a/mdl/executor/cmd_pages_describe_pluggable.go b/mdl/executor/cmd_pages_describe_pluggable.go index 3937e295e5..eb56e08201 100644 --- a/mdl/executor/cmd_pages_describe_pluggable.go +++ b/mdl/executor/cmd_pages_describe_pluggable.go @@ -130,12 +130,17 @@ func extractCustomWidgetType(ctx *ExecContext, w map[string]any) string { case "com.mendix.widget.web.image.Image": return "image" default: - // Extract last part of widget ID and uppercase it + // The last part of the widget ID, lowercased. It routes describe, + // so it must not name a dedicated branch: those were written for + // the web widgets matched above, and another widget ending in the + // same segment — the native Gallery and Image — was described as + // the web one and rebuilt as it on re-run. parts := strings.Split(widgetID, ".") - if len(parts) > 0 { - return strings.ToLower(parts[len(parts)-1]) + seg := strings.ToLower(parts[len(parts)-1]) + if isKnownCustomWidgetType(seg) { + return "customwidget" } - return strings.ToLower(widgetID) + return seg } } return "" diff --git a/mdl/executor/describe_native_widget_keyword_test.go b/mdl/executor/describe_native_widget_keyword_test.go new file mode 100644 index 0000000000..b5269b27c8 --- /dev/null +++ b/mdl/executor/describe_native_widget_keyword_test.go @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "bytes" + "strings" + "testing" +) + +// A native mobile widget is described under the keyword `widget init` gave it +// (`nativegallery`, `nativeactivityindicator`, …), or — with no definition to +// resolve against — the `pluggablewidget ''` form. Never under the last +// segment of its id. +// +// Measured on PedApp (11.13.0) with Native Mobile Resources 12.6.0 installed: +// a native widget with no setting away from its default took the bare branch +// of describe, which printed the id's last segment. Three of those segments +// are WEB keywords — `gallery`, `badge`, `image` — so re-running the +// description rebuilt the page with the web widget in place of the native one, +// and `check` passed it. Seven more (`activityindicator`, `qrcode`, …) named no +// widget at all and were refused (MDL-WIDGET25). `gallery` and `image` were +// worse still: they are matched on that segment to the WEB widget's dedicated +// branch, so a native gallery with a data source was described as the web one +// too. +func TestDescribeNativeWidget_UsesItsOwnKeyword(t *testing.T) { + registry := LoadWidgetRegistry("") + if registry == nil { + t.Fatal("no registry — the embedded definitions must load, or this test proves nothing") + } + natives := map[string]string{ + "com.mendix.widget.native.gallery.Gallery": "nativegallery", + "com.mendix.widget.native.badge.Badge": "nativebadge", + "com.mendix.widget.native.image.Image": "nativeimage", + "com.mendix.widget.native.activityindicator.ActivityIndicator": "nativeactivityindicator", + "com.mendix.widget.native.qrcode.QRCode": "nativeqrcode", + "com.mendix.widget.native.repeater.Repeater": "nativerepeater", + } + for id, kw := range natives { + def := &WidgetDefinition{WidgetID: id, MDLName: strings.ToUpper(kw), WidgetKind: "pluggable"} + registry.byWidgetID[id] = def + registry.byMDLName[strings.ToUpper(kw)] = def + } + + for id, kw := range natives { + t.Run(kw, func(t *testing.T) { + got := describeBareCustomWidget(t, registry, id, "w1") + if want := kw + " w1"; !strings.HasPrefix(got, want) { + t.Errorf("described as %q, want %q — the keyword that builds %s", got, want, id) + } + }) + } +} + +// Without a project the registry holds only the embedded (web) definitions, so +// a native widget has no keyword to resolve to: the id form is the one that +// builds it again. The last segment would name the web widget or nothing. +func TestDescribeNativeWidget_NoDefinitionUsesTheIDForm(t *testing.T) { + registry := LoadWidgetRegistry("") + for _, id := range []string{ + "com.mendix.widget.native.gallery.Gallery", + "com.mendix.widget.native.badge.Badge", + "com.mendix.widget.native.signature.Signature", + } { + got := describeBareCustomWidget(t, registry, id, "w1") + if want := "pluggablewidget '" + id + "' w1"; !strings.HasPrefix(got, want) { + t.Errorf("described as %q, want %q", got, want) + } + } +} + +// The control: the web widgets keep their keyword — gallery and image through +// their dedicated branches, the badge through the definition `widget init` +// writes for it (without one, it takes the id form, as it does when it has +// settings). +func TestDescribeWebWidget_KeepsItsKeyword(t *testing.T) { + registry := LoadWidgetRegistry("") + badge := &WidgetDefinition{WidgetID: "com.mendix.widget.custom.badge.Badge", MDLName: "BADGE", WidgetKind: "pluggable"} + registry.byWidgetID[badge.WidgetID] = badge + registry.byMDLName["BADGE"] = badge + for id, kw := range map[string]string{ + "com.mendix.widget.web.gallery.Gallery": "gallery", + "com.mendix.widget.web.image.Image": "image", + "com.mendix.widget.custom.badge.Badge": "badge", + } { + got := describeBareCustomWidget(t, registry, id, "w1") + if want := kw + " w1"; !strings.HasPrefix(got, want) { + t.Errorf("%s described as %q, want %q", id, got, want) + } + } +} + +// extractCustomWidgetType picks the dedicated describe branch. Only the web +// widget a branch was written for may land in it. +func TestExtractCustomWidgetType_NativeIDIsNotTheWebWidget(t *testing.T) { + for _, id := range []string{ + "com.mendix.widget.native.gallery.Gallery", + "com.mendix.widget.native.image.Image", + "com.acme.widgets.combobox.Combobox", + } { + got := extractCustomWidgetType(nil, map[string]any{"Type": map[string]any{"WidgetId": id}}) + if isKnownCustomWidgetType(got) { + t.Errorf("%s routed to the dedicated %q branch, which describes a different widget", id, got) + } + } + // Control: the web gallery is still routed to its branch. + if got := extractCustomWidgetType(nil, map[string]any{"Type": map[string]any{ + "WidgetId": "com.mendix.widget.web.gallery.Gallery"}}); got != "gallery" { + t.Errorf("web gallery routed to %q, want gallery", got) + } +} + +// describeBareCustomWidget describes a stored pluggable widget that holds no +// setting away from its default. +func describeBareCustomWidget(t *testing.T, registry *WidgetRegistry, widgetID, name string) string { + t.Helper() + stored := map[string]any{ + "$Type": "CustomWidgets$CustomWidget", + "Name": name, + "Type": map[string]any{ + "WidgetId": widgetID, + "ObjectType": map[string]any{"PropertyTypes": []any{int32(3)}}, + }, + "Object": map[string]any{"Properties": []any{int32(3)}}, + } + var buf bytes.Buffer + ctx := (&Executor{}).newExecContext(nil) + ctx.Output = &buf + ctx.widgetRegistry, ctx.widgetRegistryLoaded = registry, true + raws := parseRawWidget(ctx, stored) + if len(raws) != 1 { + t.Fatalf("parsed %d widgets, want 1", len(raws)) + } + outputWidgetMDLV3(ctx, raws[0], 0) + return strings.TrimSpace(buf.String()) +} From d61b2730077e14954e15898a738f6a7cb5ee5d3f Mon Sep 17 00:00:00 2001 From: karahanharunn Date: Fri, 20 Nov 2026 08:53:46 +0100 Subject: [PATCH 08/18] Read the native Image's switch-computed hide list from its editorConfig Co-Authored-By: Claude Opus 5.5 --- ...e-image-editorconfig-switch-hide-list.json | 1 + mdl/executor/editorconfig_extract.go | 12 +++ mdl/executor/editorconfig_iife_switch.go | 99 +++++++++++++++++++ mdl/executor/editorconfig_iife_switch_test.go | 96 ++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-image-editorconfig-switch-hide-list.json create mode 100644 mdl/executor/editorconfig_iife_switch.go create mode 100644 mdl/executor/editorconfig_iife_switch_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-image-editorconfig-switch-hide-list.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-image-editorconfig-switch-hide-list.json new file mode 100644 index 0000000000..74ecaab410 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-image-editorconfig-switch-hide-list.json @@ -0,0 +1 @@ +{"area": "mdl/executor", "date": "2026-11-17", "symptom": "every native Image (Native Mobile Resources 12.6.0) mxcli created failed mx check 11.13.0 with CE0463 — its `imageUrl` text template was written with a template where mx update-widgets writes none", "cause": "the Image's editorConfig hides the image-source properties it is not using with hidePropertiesIn(t, v, function(s){switch(s){case \"image\": return L.filter(p => \"imageObject\" !== p); …; default: return L}}(v.datasource)) — a list computed by a switch in an immediately-invoked function, which the extractor could not read, so no rule hid imageUrl under the default source", "file": "mdl/executor/editorconfig_iife_switch.go (iifeSwitchHideRules), mdl/executor/editorconfig_extract.go (extractVisibilityRulesFromJS)", "fix": "read that exact shape — unguarded, at a function's statement level, each case keeping one member of a known string-array constant, default the whole list — as one `notin` rule per member over the cases that keep it; any other shape stays unread", "insight": "diffing the stored widget against a copy run through `mx update-widgets` named the exact property (Object.imageUrl TextTemplate set vs null) — but the Type was identical, so the cause was visibility, not the definition. A CE0463 with a clean Type diff points at editorConfig", "refs": [], "test": "mdl/executor/editorconfig_iife_switch_test.go"} diff --git a/mdl/executor/editorconfig_extract.go b/mdl/executor/editorconfig_extract.go index 28e910141f..b96da3476d 100644 --- a/mdl/executor/editorconfig_extract.go +++ b/mdl/executor/editorconfig_extract.go @@ -161,6 +161,18 @@ func extractVisibilityRulesFromJS(js string) ([]types.WidgetVisibilityRule, edit stats.SkippedComplex++ continue } + // A list computed by a switch (the native Image's image source). + if lifted, ok := iifeSwitchHideRules(js, callStart, args, consts); ok { + stats.Recognized++ + for _, r := range lifted { + sig := "\x00" + r.PropertyKey + "\x00" + r.HiddenWhen.PropertyKey + r.HiddenWhen.Operator + r.HiddenWhen.Value + if !seen[sig] { + seen[sig] = true + rules = append(rules, r) + } + } + continue + } listKey, keys, condKeys, ok := hideTargetKeys(args, consts) if !ok || (len(keys) == 0 && len(condKeys) == 0) { stats.SkippedComplex++ diff --git a/mdl/executor/editorconfig_iife_switch.go b/mdl/executor/editorconfig_iife_switch.go new file mode 100644 index 0000000000..74ea476a8e --- /dev/null +++ b/mdl/executor/editorconfig_iife_switch.go @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "regexp" + "strings" + + "github.com/mendixlabs/mxcli/mdl/types" +) + +// A hide call whose list is computed by a switch in an immediately-invoked +// function — the native Image's (Native Mobile Resources): +// +// return x.hidePropertiesIn(t, v, function(s){switch(s){ +// case "image": return L.filter(function(p){return "imageObject" !== p}); +// case "imageUrl": return L.filter(function(p){return "imageUrl" !== p}); +// default: return L }}(v.datasource)) +// +// Each case hides the whole list L but one member, and the default hides all +// of it. So a member is hidden unless the switched property holds one of the +// cases that keeps it: `notin` over those cases. +// +// Only that exact shape is read, and only at a function's own statement level +// with nothing guarding it. Anything else — a default other than L, a case +// keeping more than one member, a guard before the call — is left unread, +// which degrades to "not hidden" as every unread hide does. +var ( + iifeSwitchRE = regexp.MustCompile(`^function\(([\w$]+)\)\{switch\(([\w$]+)\)\{(.*)\}\}\(([\w$]+\.[\w$]+)\)$`) + iifeCaseRE = regexp.MustCompile(`^case"([^"]*)":return ([\w$]+)\.filter\(function\(([\w$]+)\)\{return(?:"([^"]*)"!==([\w$]+)|([\w$]+)!=="([^"]*)")\}\)$`) + iifeDefRE = regexp.MustCompile(`^default:return ([\w$]+)$`) + unguardedRE = regexp.MustCompile(`return\s*(?:[\w$]+\.)?$`) +) + +func iifeSwitchHideRules(js string, callStart int, args string, consts map[string][]string) ([]types.WidgetVisibilityRule, bool) { + parts := splitTopLevelCommas(args) + if len(parts) != 3 { + return nil, false + } + m := iifeSwitchRE.FindStringSubmatch(strings.TrimSpace(parts[2])) + if m == nil || m[1] != m[2] { + return nil, false + } + // Unguarded: `return [receiver.]hide…(` opening a function's statement. + loc := unguardedRE.FindStringIndex(js[:callStart]) + if loc == nil || !atFunctionStatementLevel(js, loc[0]) { + return nil, false + } + key, scope, ok := resolveRef(m[4], enclosingAliases(js, callStart), "") + if !ok || scope != "" { + return nil, false + } + + list, keeps := "", map[string][]string{} // member -> case values keeping it + sawDefault := false + for _, arm := range strings.Split(m[3], ";") { + if d := iifeDefRE.FindStringSubmatch(arm); d != nil { + if sawDefault || (list != "" && d[1] != list) { + return nil, false + } + list, sawDefault = d[1], true + continue + } + c := iifeCaseRE.FindStringSubmatch(arm) + if c == nil { + return nil, false + } + param, kept, ref := c[3], c[4], c[5] + if kept == "" { + kept, ref = c[7], c[6] + } + if ref != param || (list != "" && c[2] != list) { + return nil, false + } + list = c[2] + keeps[kept] = append(keeps[kept], c[1]) + } + members, known := consts[list] + if !sawDefault || !known { + return nil, false + } + inList := map[string]bool{} + for _, k := range members { + inList[k] = true + } + for k := range keeps { + if !inList[k] { + return nil, false // a case keeps something the list does not hold + } + } + var rules []types.WidgetVisibilityRule + for _, k := range members { + rules = append(rules, types.WidgetVisibilityRule{ + PropertyKey: k, + HiddenWhen: &types.WidgetVisibilityCondition{PropertyKey: key, Operator: "notin", Value: strings.Join(keeps[k], ",")}, + }) + } + return rules, true +} diff --git a/mdl/executor/editorconfig_iife_switch_test.go b/mdl/executor/editorconfig_iife_switch_test.go new file mode 100644 index 0000000000..2eba69cc80 --- /dev/null +++ b/mdl/executor/editorconfig_iife_switch_test.go @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "testing" + + "github.com/mendixlabs/mxcli/mdl/types" +) + +// The native Image (Native Mobile Resources 12.6.0) hides the image-source +// properties it is not using with a hide call whose list is computed by a +// switch, inside an immediately-invoked function: +// +// hidePropertiesIn(t, v, function(s){switch(s){ +// case "image": return L.filter(p => "imageObject" !== p); +// case "imageUrl": return L.filter(p => "imageUrl" !== p); +// case "icon": return L.filter(p => "imageIcon" !== p); +// default: return L }}(v.datasource)) +// +// The extractor read no list there and skipped the call, so `imageUrl` — a +// text template, hidden under the default source `image` — was written with +// a template where mx update-widgets writes none: CE0463 on every native +// image mxcli created (mx check 11.13.0). +// +// The source below is the widget's own getProperties, minified as shipped, +// cut after the call that matters. +const nativeImageGetProperties = `var dataSourceProperties=["imageObject","imageUrl","imageIcon"];` + + `exports.getProperties=function(values,defaultProperties){var _values$imageIcon,_values$imageIcon2;` + + `return distExports.hidePropertiesIn(defaultProperties,values,function(sourceProperty){switch(sourceProperty){` + + `case"image":return dataSourceProperties.filter(function(prop){return"imageObject"!==prop});` + + `case"imageUrl":return dataSourceProperties.filter(function(prop){return"imageUrl"!==prop});` + + `case"icon":return dataSourceProperties.filter(function(prop){return"imageIcon"!==prop});` + + `default:return dataSourceProperties}}(values.datasource)),` + + `"image"!==values.datasource&&distExports.hidePropertyIn(defaultProperties,values,"defaultImageDynamic")}` + +func TestExtractVisibility_SwitchComputedHideList(t *testing.T) { + rules, _ := extractVisibilityRulesFromJS(nativeImageGetProperties) + hidden := func(key string, values map[string]string) bool { + for _, r := range rules { + if r.PropertyKey != key || r.ListPropertyKey != "" { + continue + } + fires, _ := r.Fires(func(c types.WidgetVisibilityCondition) (string, bool) { + v, ok := values[c.PropertyKey] + return v, ok + }) + if fires { + return true + } + } + return false + } + for _, tc := range []struct { + source string + visible string + hidden []string + }{ + {"image", "imageObject", []string{"imageUrl", "imageIcon"}}, + {"imageUrl", "imageUrl", []string{"imageObject", "imageIcon"}}, + {"icon", "imageIcon", []string{"imageObject", "imageUrl"}}, + } { + values := map[string]string{"datasource": tc.source} + if hidden(tc.visible, values) { + t.Errorf("datasource=%s: %s is the property the source uses, but a rule hides it", tc.source, tc.visible) + } + for _, k := range tc.hidden { + if !hidden(k, values) { + t.Errorf("datasource=%s: %s is hidden by the editor, but no rule says so (rules: %+v)", tc.source, k, rules) + } + } + } + // Control: the plain guarded hide beside it is still read. + if !hidden("defaultImageDynamic", map[string]string{"datasource": "icon"}) { + t.Error("the guarded hidePropertyIn next to the switch is no longer read") + } +} + +// A computed list whose shape is not the one above is not guessed at: a +// default that is not the full list, or a case that keeps two members, could +// hide a property the editor shows. +func TestExtractVisibility_SwitchComputedHideList_OtherShapesNotLifted(t *testing.T) { + for name, js := range map[string]string{ + "default is not the list": `var L=["a","b"];exports.getProperties=function(v,t){return x.hidePropertiesIn(t,v,function(s){switch(s){` + + `case"x":return L.filter(function(p){return"a"!==p});default:return[]}}(v.mode))}`, + "under a guard": `var L=["a","b"];exports.getProperties=function(v,t){return v.on&&x.hidePropertiesIn(t,v,function(s){switch(s){` + + `case"x":return L.filter(function(p){return"a"!==p});default:return L}}(v.mode))}`, + } { + rules, _ := extractVisibilityRulesFromJS(js) + for _, r := range rules { + if r.PropertyKey == "a" || r.PropertyKey == "b" { + t.Errorf("%s: lifted %+v", name, r) + } + } + } +} From 08daffe6e94b3306420f68e0497f40cfe4cea2fd Mon Sep 17 00:00:00 2001 From: karahanharunn Date: Fri, 20 Nov 2026 08:53:47 +0100 Subject: [PATCH 09/18] Write allowUpload, onChange and raw enum captions into generated widget types Co-Authored-By: Claude Opus 5.5 --- ...get-type-allowupload-onchange-caption.json | 1 + CHANGELOG.md | 6 ++ modelsdk/widgets/augment.go | 13 ++- modelsdk/widgets/mpk/mpk.go | 20 ++++- modelsdk/widgets/mpk/native_attrs_test.go | 58 ++++++++++++++ .../widgets/native_definition_attrs_test.go | 79 +++++++++++++++++++ 6 files changed, 171 insertions(+), 6 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/modelsdk/2026-11-17-generated-widget-type-allowupload-onchange-caption.json create mode 100644 modelsdk/widgets/mpk/native_attrs_test.go create mode 100644 modelsdk/widgets/native_definition_attrs_test.go diff --git a/.claude/skills/fix-issue/findings/modelsdk/2026-11-17-generated-widget-type-allowupload-onchange-caption.json b/.claude/skills/fix-issue/findings/modelsdk/2026-11-17-generated-widget-type-allowupload-onchange-caption.json new file mode 100644 index 0000000000..611ed05165 --- /dev/null +++ b/.claude/skills/fix-issue/findings/modelsdk/2026-11-17-generated-widget-type-allowupload-onchange-caption.json @@ -0,0 +1 @@ +{"area": "modelsdk", "date": "2026-11-17", "symptom": "native Signature, Bottom sheet and Maps (Native Mobile Resources 12.6.0) created by mxcli failed mx check 11.13.0 with CE0463 on every instance", "cause": "the definition generated from the .mpk differed from mx update-widgets in three attributes: AllowUpload false where the image property declares allowUpload=\"true\" (not parsed at all); OnChangeProperty \"\" where the attribute declares onChange (parsed, but createDefaultValueType hard-coded \"\"); an enumeration caption trimmed where Mendix stores the element text verbatim, trailing newline and indentation included", "file": "modelsdk/widgets/mpk/mpk.go (AllowUpload, EnumValue.RawCaption), modelsdk/widgets/augment.go (createDefaultValueType, buildEnumValuesArray, syncDefinitionAttrs)", "fix": "parse allowUpload; write p.AllowUpload and p.OnChange into the generated ValueType and sync AllowUpload onto augmented templates; keep the raw caption beside the trimmed one and write the raw one", "insight": "mx check runs on macOS through Docker: debian:bookworm-slim plus libicu72, libuuid1, libfreetype6, fontconfig, with LD_PRELOAD of libuuid.so.1 and libfreetype.so.6 (libSkiaSharp does not link uuid). A baseline mx check of the untouched fixture is what separates the 4 new CE0463 from the 105 the fixture already had", "refs": [], "test": "modelsdk/widgets/native_definition_attrs_test.go, modelsdk/widgets/mpk/native_attrs_test.go"} diff --git a/CHANGELOG.md b/CHANGELOG.md index f3df806ee0..86066a61fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **`check` rejects an expression that reads a variable nothing defines** (ako/mxcli#1258) — `return $Nope + 1;` with no `$Nope` anywhere passed `check` and `exec` and failed the build with CE0109 "Undefined variable". New MDL098, for the expressions of return, if, declare, set, create/change members, log, show message and validation feedback, in microflows and nanoflows. A name counts as defined if a parameter or any statement of the flow produces it, or it is one MxBuild accepts with no declaration (`$currentUser`, `$currentSession`, `$latestError`, `$latestHttpResponse`, `$latestSoapFault`, `$currentIndex`, `$currentObject`). Measured on MxBuild 11.16.1. - **`check` rejects `returns T as $R` when a path ends the flow without `$R`** (ako/mxcli#1258) — MDL003 exempts the AS clause because the end event returns `$R`, which holds only while `$R` has a value there. A flow with a path off its end and no top-level `$R` passed `check` and `exec` and failed the build with CE0109 "Undefined variable" (or CE0108 when `$R` is defined only inside a branch or loop). New MDL097, microflow and nanoflow. Measured on MxBuild 11.16.1. - **`describe` names a native mobile widget by its own keyword** — a native widget left at its defaults was described under the last part of its id. So `nativegallery`, `nativebadge` and `nativeimage` came out as the web `gallery`, `badge` and `image`, and re-running the description replaced them with the web widget while `check` passed. Seven more (`activityindicator`, `qrcode`, `repeater`, `safeareaview`, `signature`, `notifications`, `backgroundgradient`) came out under names no widget has, and were refused on re-run (MDL-WIDGET25). A native gallery with a data source was described as the web gallery as well. Each is now described by the keyword `widget init` gave it, or as `pluggablewidget ''` when the project has no definition for it. Measured with Native Mobile Resources 12.6.0 on 11.13.0: all 39 native widgets now describe, pass `check` and re-run as Unchanged. +- **Native Image, Signature, Bottom sheet and Maps widgets build without CE0463** — with Native Mobile Resources 12.6.0 installed, each of these widgets that mxcli created failed `mx check` 11.13.0 with "The definition of this widget has changed". There were four causes: + - **Image:** the widget's editor hides the image-source settings it is not using, with a list worked out by a `switch`. mxcli could not read that, so it wrote the Image URL text, which Mendix leaves empty. + - **Signature:** `allowUpload` on its image setting was not read. + - **Bottom sheet:** the `onChange` of its trigger attribute was not written. + - **Maps:** an option caption was trimmed, while Mendix stores it exactly as the package writes it. + All 39 native widgets now pass `mx check` without CE0463. - **`fix widgets` and `fix design-properties` use the project's own Mendix version of `mx`** (ako/mxcli#2321) — they took the version as a preference, so on macOS an `mx` on PATH or another Studio Pro install ran, and `mx update-widgets` refused with "Project is in different Mendix version". They now take an `mx` of exactly the project's version. On Linux that version is downloaded when it is missing. On macOS and Windows, where no matching `mx` is installed, they say which version is needed and how to pass it with `--mx`. - **Parallel `mxcli exec` runs on one project no longer lose each other's writes** (ako/mxcli#2326) — measured with 8 parallel scripts: every process reported success and 2 to 6 of the 16 entities were missing (the reporter saw all of them fail instead). A script, or a `-c`, that writes now holds the project's lock (`.mxcli/write.lock`) for its whole run. A second writer waits up to 60 seconds, then changes nothing and exits 75, naming the holder. A lock left by a crashed run is taken over. Read-only runs take no lock. With the lock, all 16 entities land in every round. - **`run restart` names the secret it cannot replay** (ako/mxcli#2313) — a restart refused because of a literal secret printed only a generic `--db-password @env:` hint. The `--constant X=@env:VAR` references are recorded and replayed, so the hint read as if they were not. The refusal now lists each flag stored redacted, such as `--constant Helpdesk.OpenRouterKey` or `--db-password`, and says that the values given as references are replayed. diff --git a/modelsdk/widgets/augment.go b/modelsdk/widgets/augment.go index 744efe86fa..a49cc0905b 100644 --- a/modelsdk/widgets/augment.go +++ b/modelsdk/widgets/augment.go @@ -676,11 +676,16 @@ func reconcileEnumValues(node any, byKey map[string][]mpk.EnumValue) { func buildEnumValuesArray(opts []mpk.EnumValue) []any { arr := []any{float64(2)} for _, o := range opts { + // The caption as the package writes it: Mendix stores it verbatim. + caption := o.RawCaption + if caption == "" { + caption = o.Caption + } arr = append(arr, map[string]any{ "$ID": placeholderID(), "$Type": "CustomWidgets$WidgetEnumerationValue", "_Key": o.Key, - "Caption": o.Caption, + "Caption": caption, }) } return arr @@ -852,6 +857,7 @@ func createDefaultValueType(vtID string, bsonType string, p mpk.PropertyDef) map "$Type": "CustomWidgets$WidgetValueType", "ActionVariables": buildActionVariablesArray(p.ActionVariables), "AllowNonPersistableEntities": false, + "AllowUpload": p.AllowUpload, "AllowedTypes": allowedTypes, "AssociationTypes": []any{float64(1)}, "DataSourceProperty": "", @@ -865,7 +871,7 @@ func createDefaultValueType(vtID string, bsonType string, p mpk.PropertyDef) map "IsPath": "No", "Multiline": false, "ObjectType": nil, - "OnChangeProperty": "", + "OnChangeProperty": p.OnChange, "ParameterIsList": false, "PathType": "None", "Required": p.Required, @@ -1352,6 +1358,9 @@ func syncDefinitionAttrs(propTypes []any, props []mpk.PropertyDef) { if _, ok := target["OnChangeProperty"]; ok { target["OnChangeProperty"] = p.OnChange } + if _, ok := target["AllowUpload"]; ok { + target["AllowUpload"] = p.AllowUpload + } }) } diff --git a/modelsdk/widgets/mpk/mpk.go b/modelsdk/widgets/mpk/mpk.go index 2137f59b07..f74ed66f66 100644 --- a/modelsdk/widgets/mpk/mpk.go +++ b/modelsdk/widgets/mpk/mpk.go @@ -28,7 +28,11 @@ type PropertyDef struct { // OnChange names the sibling action property Studio Pro runs when this // property changes. Part of the widget DEFINITION, so a stale value makes // Mendix report CE0463 "definition of this widget has changed" (#716). - OnChange string + OnChange string + // AllowUpload is an image/file property's allowUpload="true": part of the + // widget DEFINITION (ValueType.AllowUpload), CE0463 when it differs + // (Native Mobile Resources 12.6.0's Signature). + AllowUpload bool DefaultValue string // for enumeration/boolean/integer types // DefaultType is the KIND of the default — `defaultType` in the widget XML, // e.g. an action defaulting to a nanoflow call ("CallNanoflow") or a @@ -76,7 +80,12 @@ type ActionVariable struct { // EnumValue is one option of an enumeration-typed widget property. type EnumValue struct { Key string - Caption string + Caption string // trimmed, for display + // RawCaption is the caption as the package writes it. Mendix stores that + // text verbatim — a multi-line element keeps its trailing newline and + // indentation — and a trimmed copy in the definition is CE0463 (Native + // Mobile Resources 12.6.0's Maps). + RawCaption string } // Translation is one localized caption/template string of a widget property. @@ -236,6 +245,7 @@ type xmlProperty struct { DefaultType string `xml:"defaultType,attr"` Required string `xml:"required,attr"` OnChange string `xml:"onChange,attr"` + AllowUpload string `xml:"allowUpload,attr"` IsList string `xml:"isList,attr"` Multiline string `xml:"multiline,attr"` DataSource string `xml:"dataSource,attr"` @@ -447,7 +457,7 @@ func walkPropertyGroup(pg xmlPropGroup, parentCategory string, def *WidgetDefini } var enumValues []EnumValue for _, ev := range p.EnumValues { - enumValues = append(enumValues, EnumValue{Key: ev.Key, Caption: strings.TrimSpace(ev.Caption)}) + enumValues = append(enumValues, EnumValue{Key: ev.Key, Caption: strings.TrimSpace(ev.Caption), RawCaption: ev.Caption}) } prop := PropertyDef{ Key: p.Key, @@ -462,6 +472,7 @@ func walkPropertyGroup(pg xmlPropGroup, parentCategory string, def *WidgetDefini // caused within-key CE0463 drift on augment-added keys (issue #600). Required: p.Required != "false", OnChange: p.OnChange, + AllowUpload: p.AllowUpload == "true", DefaultValue: p.DefaultValue, DefaultType: p.DefaultType, IsList: p.IsList == "true", @@ -540,7 +551,7 @@ func collectNestedProperties(pg xmlPropGroup, parent *PropertyDef, parentCategor } var enumValues []EnumValue for _, ev := range p.EnumValues { - enumValues = append(enumValues, EnumValue{Key: ev.Key, Caption: strings.TrimSpace(ev.Caption)}) + enumValues = append(enumValues, EnumValue{Key: ev.Key, Caption: strings.TrimSpace(ev.Caption), RawCaption: ev.Caption}) } child := PropertyDef{ Key: p.Key, @@ -555,6 +566,7 @@ func collectNestedProperties(pg xmlPropGroup, parent *PropertyDef, parentCategor // caused within-key CE0463 drift on augment-added keys (issue #600). Required: p.Required != "false", OnChange: p.OnChange, + AllowUpload: p.AllowUpload == "true", DefaultValue: p.DefaultValue, DefaultType: p.DefaultType, IsList: p.IsList == "true", diff --git a/modelsdk/widgets/mpk/native_attrs_test.go b/modelsdk/widgets/mpk/native_attrs_test.go new file mode 100644 index 0000000000..01077dc12b --- /dev/null +++ b/modelsdk/widgets/mpk/native_attrs_test.go @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: Apache-2.0 + +package mpk + +import "testing" + +// `allowUpload` is read from an image/file property, and an enumeration +// option's caption is kept as written: Mendix stores it verbatim, and a +// trimmed copy is CE0463 (Native Mobile Resources 12.6.0's Maps). The trimmed +// caption stays for display. +func TestParse_ReadsAllowUploadAndRawEnumCaption(t *testing.T) { + const widgetXML = ` + + W + + + + Image + + + Plain + + + Location + + Based on address + Based on latitude and longitude + + + + + +` + + def := parseWidgetXML(t, widgetXML) + byKey := map[string]PropertyDef{} + for _, p := range def.Properties { + byKey[p.Key] = p + } + if !byKey["imageSource"].AllowUpload { + t.Error("imageSource: allowUpload=\"true\" not read") + } + if byKey["plainImage"].AllowUpload { + t.Error("control: plainImage declares no allowUpload") + } + var latlng EnumValue + for _, ev := range byKey["locationType"].EnumValues { + if ev.Key == "latlng" { + latlng = ev + } + } + if want := "Based on latitude and longitude\n "; latlng.RawCaption != want { + t.Errorf("RawCaption = %q, want %q", latlng.RawCaption, want) + } + if latlng.Caption != "Based on latitude and longitude" { + t.Errorf("Caption = %q, want the trimmed text for display", latlng.Caption) + } +} diff --git a/modelsdk/widgets/native_definition_attrs_test.go b/modelsdk/widgets/native_definition_attrs_test.go new file mode 100644 index 0000000000..1176735a93 --- /dev/null +++ b/modelsdk/widgets/native_definition_attrs_test.go @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: Apache-2.0 + +package widgets + +import ( + "testing" + + "github.com/mendixlabs/mxcli/modelsdk/widgets/mpk" +) + +// Three properties of the definition mxcli generated from a package differed +// from what mx update-widgets writes, each one CE0463 on every instance +// (mx check 11.13.0, Native Mobile Resources 12.6.0): +// +// Signature imageSource type="image" allowUpload="true" AllowUpload false, want true +// Bottom sheet triggerAttribute onChange="triggerAttributeChange" OnChangeProperty "", want the key +// Maps markers/… Based on latitude and longitude +// caption trimmed, want it verbatim +// +// The parser already read onChange; the generator wrote "" regardless. +// allowUpload was not read at all. And the parser trimmed an option's caption, +// which Mendix stores as written — trailing newline and indentation included. +func TestGenerateFromMPK_DefinitionAttrsAsDeclared(t *testing.T) { + ResetPlaceholderCounter() + const latlng = "Based on latitude and longitude\n " + def := &mpk.WidgetDefinition{ + ID: "com.example.W", Name: "W", Version: "1.0.0", + Properties: []mpk.PropertyDef{ + {Key: "imageSource", Type: "image", Required: true, AllowUpload: true}, + {Key: "plainImage", Type: "image"}, + {Key: "triggerAttribute", Type: "attribute", OnChange: "triggerAttributeChange", AllowedTypes: []string{"Boolean"}}, + {Key: "triggerAttributeChange", Type: "action"}, + {Key: "locationType", Type: "enumeration", DefaultValue: "address", EnumValues: []mpk.EnumValue{ + {Key: "address", Caption: "Based on address", RawCaption: "Based on address"}, + {Key: "latlng", Caption: "Based on latitude and longitude", RawCaption: latlng}, + }}, + }, + } + vts := valueTypesByKey(t, GenerateFromMPK(def)) + + if got := vts["imageSource"]["AllowUpload"]; got != true { + t.Errorf("imageSource AllowUpload = %v, want true (allowUpload=\"true\")", got) + } + if got := vts["plainImage"]["AllowUpload"]; got != false { + t.Errorf("control: plainImage AllowUpload = %v, want false", got) + } + if got := vts["triggerAttribute"]["OnChangeProperty"]; got != "triggerAttributeChange" { + t.Errorf("triggerAttribute OnChangeProperty = %q, want triggerAttributeChange", got) + } + if got := vts["triggerAttributeChange"]["OnChangeProperty"]; got != "" { + t.Errorf("control: an action's OnChangeProperty = %q, want empty", got) + } + enum, _ := vts["locationType"]["EnumerationValues"].([]any) + captions := map[string]any{} + for _, e := range enum { + if m, ok := e.(map[string]any); ok { + captions[m["_Key"].(string)] = m["Caption"] + } + } + if captions["latlng"] != latlng { + t.Errorf("latlng caption = %q, want it as written in the package, %q", captions["latlng"], latlng) + } + if captions["address"] != "Based on address" { + t.Errorf("control: address caption = %q", captions["address"]) + } +} + +func valueTypesByKey(t *testing.T, tmpl *WidgetTemplate) map[string]map[string]any { + t.Helper() + pts := tmpl.Type["ObjectType"].(map[string]any)["PropertyTypes"].([]any) + out := map[string]map[string]any{} + for _, pt := range pts[1:] { + m := pt.(map[string]any) + if vt, ok := m["ValueType"].(map[string]any); ok { + out[m["PropertyKey"].(string)] = vt + } + } + return out +} From 4883fac1a473afdceeb5e8eedcef8841cd409a04 Mon Sep 17 00:00:00 2001 From: karahanharunn Date: Fri, 20 Nov 2026 08:53:50 +0100 Subject: [PATCH 10/18] Accept a native widget's own editable setting in check Co-Authored-By: Claude Opus 5.5 --- ...1-17-native-own-editable-read-as-core.json | 1 + CHANGELOG.md | 1 + .../native_editable_own_property_test.go | 84 +++++++++++++++++++ mdl/executor/pluggable_own_core_name.go | 40 +++++---- mdl/executor/validate_widgets.go | 13 ++- 5 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-own-editable-read-as-core.json create mode 100644 mdl/executor/native_editable_own_property_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-own-editable-read-as-core.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-own-editable-read-as-core.json new file mode 100644 index 0000000000..13b899dc73 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-17-native-own-editable-read-as-core.json @@ -0,0 +1 @@ +{"area": "mdl/executor", "date": "2026-11-17", "symptom": "`check` refused `nativeslider s1 (editable: 'default')` with \"`Editable: default` is not an Editable value [MDL-WIDGET19]\" — the form describe prints — so a native page with a slider, range slider, rating or toggle buttons could not be described and re-run", "cause": "those native widgets declare an `editable` enumeration of their own (default | never) and no Editability system property; exec writes `editable:` to that key (the CustomWidget's Editable stays Always), but validateConsumableConditional judged the name as the core Editable", "file": "mdl/executor/validate_widgets.go (validateConsumableConditional), mdl/executor/pluggable_own_core_name.go (defDeclaresOwnKey)", "fix": "skip the core Editable value check when the widget's definition maps an `editable` key of its own; validatePluggableEnumValues judges the value against the package's keys", "insight": "same class as ako/mxcli#2180 (a widget's own key spelled like a core name), but `editable` is deliberately not in pages.coreNamesPluggableKeysShadow because a CustomWidget stores Editable itself — so only check was wrong; exec already wrote the own key. Dumping the stored CustomWidget (Editable: Always) settled which layer to touch", "refs": ["ako/mxcli#2180"], "test": "mdl/executor/native_editable_own_property_test.go"} diff --git a/CHANGELOG.md b/CHANGELOG.md index 86066a61fc..1aa2d5e6e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **Bottom sheet:** the `onChange` of its trigger attribute was not written. - **Maps:** an option caption was trimmed, while Mendix stores it exactly as the package writes it. All 39 native widgets now pass `mx check` without CE0463. +- **`check` accepts a native widget's own `editable` setting** — the native Slider, Range slider, Rating and Toggle buttons have an `editable` setting of their own (`default` or `never`). `check` read it as the core Editable and refused `editable: 'default'` (MDL-WIDGET19), which is how `describe` prints it, so such a page could not be described and run again. The value is now checked against the widget's own values, as exec already wrote it. - **`fix widgets` and `fix design-properties` use the project's own Mendix version of `mx`** (ako/mxcli#2321) — they took the version as a preference, so on macOS an `mx` on PATH or another Studio Pro install ran, and `mx update-widgets` refused with "Project is in different Mendix version". They now take an `mx` of exactly the project's version. On Linux that version is downloaded when it is missing. On macOS and Windows, where no matching `mx` is installed, they say which version is needed and how to pass it with `--mx`. - **Parallel `mxcli exec` runs on one project no longer lose each other's writes** (ako/mxcli#2326) — measured with 8 parallel scripts: every process reported success and 2 to 6 of the 16 entities were missing (the reporter saw all of them fail instead). A script, or a `-c`, that writes now holds the project's lock (`.mxcli/write.lock`) for its whole run. A second writer waits up to 60 seconds, then changes nothing and exits 75, naming the holder. A lock left by a crashed run is taken over. Read-only runs take no lock. With the lock, all 16 entities land in every round. - **`run restart` names the secret it cannot replay** (ako/mxcli#2313) — a restart refused because of a literal secret printed only a generic `--db-password @env:` hint. The `--constant X=@env:VAR` references are recorded and replayed, so the hint read as if they were not. The refusal now lists each flag stored redacted, such as `--constant Helpdesk.OpenRouterKey` or `--db-password`, and says that the values given as references are replayed. diff --git a/mdl/executor/native_editable_own_property_test.go b/mdl/executor/native_editable_own_property_test.go new file mode 100644 index 0000000000..f119ed6db9 --- /dev/null +++ b/mdl/executor/native_editable_own_property_test.go @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "strings" + "testing" + + "github.com/mendixlabs/mxcli/mdl/ast" + "github.com/mendixlabs/mxcli/mdl/visitor" +) + +// The native Slider, Range slider, Rating and Toggle buttons declare a property +// of their own keyed `editable` — an enumeration, `default` | `never` — and not +// the Editability system property. exec writes `editable:` to that property +// (measured on PedApp 11.13.0 with Native Mobile Resources 12.6.0: the +// CustomWidget's own Editable stays Always), and describe prints it back as +// `editable: 'default'`. check read the name as the core Editable and refused +// the value: "`Editable: default` is not an Editable value [MDL-WIDGET19]" — so +// a native page with a slider could not be described and re-run. +// +// The value is the widget's own enumeration, judged against the keys its +// package declares, as a PDS Button's own `buttonStyle` is (ako/mxcli#2180). +func TestCheckNativeOwnEditable_JudgedByTheWidgetsOwnEnumeration(t *testing.T) { + def := &WidgetDefinition{ + WidgetID: "com.mendix.widget.native.slider.Slider", + MDLName: "nativeslider", + WidgetKind: "pluggable", + PropertyMappings: []PropertyMapping{ + {PropertyKey: "valueAttribute", Source: "Attribute", Operation: "attribute"}, + {PropertyKey: "editable", Value: "default", Operation: "primitive"}, + }, + enumKeys: map[string][]string{"editable": {"default", "never"}}, + } + reg := &WidgetRegistry{ + byMDLName: map[string]*WidgetDefinition{"NATIVESLIDER": def}, + byWidgetID: map[string]*WidgetDefinition{def.WidgetID: def}, + } + + for _, value := range []string{"'default'", "'never'", "never"} { + got := checkRules(t, reg, "nativeslider s1 (editable: "+value+")") + if hasNativeRule(got, "MDL-WIDGET19") { + t.Errorf("editable: %s is the native slider's own enumeration key, but check said %v", value, got) + } + } + // A key the widget does not declare is still refused — by its own list. + got := checkRules(t, reg, "nativeslider s1 (editable: 'sometimes')") + if hasNativeRule(got, "MDL-WIDGET19") || !hasNativeRule(got, widgetEnumRefused.Code) { + t.Errorf("editable: 'sometimes' on a nativeslider: want %s naming its own keys, got %v", widgetEnumRefused.Code, got) + } + // Control: a core input keeps MDL-WIDGET19. + got = checkRules(t, reg, "textbox tb (Attribute: Name, Editable: 'default')") + if !hasNativeRule(got, "MDL-WIDGET19") { + t.Errorf("a textbox with `Editable: default` must keep MDL-WIDGET19, got %v", got) + } +} + +// checkRules runs the widget checks over one widget and returns "RULE: message" +// for each violation. +func checkRules(t *testing.T, reg *WidgetRegistry, widget string) []string { + t.Helper() + prog, errs := visitor.Build("create page M.P (Title: 'P', Layout: Atlas_Core.NativePhone_Default) {\n " + widget + "\n};") + if len(errs) > 0 { + t.Fatalf("parse %q: %v", widget, errs[0]) + } + stmt, ok := prog.Statements[0].(*ast.CreatePageStmtV3) + if !ok { + t.Fatalf("parsed %T, want a page", prog.Statements[0]) + } + var out []string + for _, v := range validateWidgetTree(stmt.Widgets, reg, "page M.P") { + out = append(out, v.RuleID+": "+v.Message) + } + return out +} + +func hasNativeRule(got []string, rule string) bool { + for _, g := range got { + if strings.HasPrefix(g, rule) { + return true + } + } + return false +} diff --git a/mdl/executor/pluggable_own_core_name.go b/mdl/executor/pluggable_own_core_name.go index 82fa7df0ff..972b6d7314 100644 --- a/mdl/executor/pluggable_own_core_name.go +++ b/mdl/executor/pluggable_own_core_name.go @@ -23,21 +23,7 @@ import ( // Icon-typed `icon`, as on the Star rating) is in KnownProperties, and the core // reading stays, as before. func defOwnsCoreName(def *WidgetDefinition, name string) bool { - if def == nil || !pages.PluggableKeyShadowsCoreName(name) { - return false - } - sets := [][]PropertyMapping{def.PropertyMappings} - for _, m := range def.Modes { - sets = append(sets, m.PropertyMappings) - } - for _, set := range sets { - for _, m := range set { - if strings.EqualFold(m.PropertyKey, name) { - return true - } - } - } - return false + return pages.PluggableKeyShadowsCoreName(name) && defDeclaresOwnKey(def, name) } // templateOwnsCoreName is defOwnsCoreName asked of the template being built: @@ -55,3 +41,27 @@ func templateOwnsCoreName(propertyTypeIDs map[string]pages.PropertyTypeIDEntry, } return false } + +// defDeclaresOwnKey reports whether def maps a property key of its own spelled +// key, in any case — in its top-level mappings or any mode's. Unlike +// defOwnsCoreName it does not ask whether the name shadows a core property in +// general: `editable` does not (a CustomWidget stores its own Editable), but on +// a widget declaring an `editable` enumeration and no Editability system +// property, `editable:` is that enumeration. +func defDeclaresOwnKey(def *WidgetDefinition, key string) bool { + if def == nil { + return false + } + sets := [][]PropertyMapping{def.PropertyMappings} + for _, m := range def.Modes { + sets = append(sets, m.PropertyMappings) + } + for _, set := range sets { + for _, m := range set { + if strings.EqualFold(m.PropertyKey, key) { + return true + } + } + } + return false +} diff --git a/mdl/executor/validate_widgets.go b/mdl/executor/validate_widgets.go index 82d3885063..5f0f36816e 100644 --- a/mdl/executor/validate_widgets.go +++ b/mdl/executor/validate_widgets.go @@ -1539,7 +1539,7 @@ func violation18(locationPrefix string, w *ast.WidgetV3, msg string) linter.Viol // // The grammar fix removes the known trigger. This rule is the general guard: the // next function name promoted to a lexer token fails loudly here instead. -func validateConsumableConditional(w *ast.WidgetV3, locationPrefix string) []linter.Violation { +func validateConsumableConditional(w *ast.WidgetV3, def *WidgetDefinition, locationPrefix string) []linter.Violation { var out []linter.Violation for _, p := range []struct{ plain, routed string }{ {"Visible", "VisibleIf"}, @@ -1558,7 +1558,14 @@ func validateConsumableConditional(w *ast.WidgetV3, locationPrefix string) []lin // Visible takes any string as its condition; Editable takes an enum // word, a boolean or a condition, and refuses what is none of them // here, because the writer has nowhere to put it. - if p.plain == "Editable" { + // + // Not on a pluggable widget declaring an `editable` key of its own + // (the native Slider, Range slider, Rating and Toggle buttons: + // `default` | `never`, and no Editability system property). exec + // writes the value there, and validatePluggableEnumValues judges + // it against the keys the package declares, as for a PDS Button's + // own buttonStyle (ako/mxcli#2180). + if p.plain == "Editable" && !defDeclaresOwnKey(def, "editable") { if problem := editableValueProblem(w); problem != "" { out = append(out, linter.Violation{ RuleID: "MDL-WIDGET19", @@ -1635,7 +1642,7 @@ func validateStaticWidgetOf(w *ast.WidgetV3, def *WidgetDefinition, locationPref out = append(out, *v) } - out = append(out, validateConsumableConditional(w, locationPrefix)...) + out = append(out, validateConsumableConditional(w, def, locationPrefix)...) // A DataView cannot use a database data source — a data view shows one object, // so Mendix offers only Context / Microflow / Nanoflow / Listen sources. From 2d5f403a94921611176c4bd6b18c8449c71c7d19 Mon Sep 17 00:00:00 2001 From: karahanharunn Date: Fri, 20 Nov 2026 08:53:53 +0100 Subject: [PATCH 11/18] Warn about a required pluggable-widget setting left unset (MDL-WIDGET56) Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 + mdl/executor/validate_widget_required.go | 197 ++++++++++++++++++ mdl/executor/validate_widget_required_test.go | 166 +++++++++++++++ mdl/executor/validate_widgets.go | 3 + 4 files changed, 370 insertions(+) create mode 100644 mdl/executor/validate_widget_required.go create mode 100644 mdl/executor/validate_widget_required_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa2d5e6e2..48878a9153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **`alter page … set (attribute: …)` binds a built-in input the way `create page` does** (ako/mxcli#2278) — on a text box, text area, date picker, drop-down, check box or radio buttons, `Assoc/Attr` (and even a bare `Attr`) was stored as a null attribute reference, leaving the input unbound while ALTER reported success, and the fully qualified `"Mod"."Assoc"/"Mod"."Entity"/"Attr"` was stored as one flat name (mxbuild CE1613). The value is now resolved by create page's resolver against the widget's data container, association steps included; a path that does not resolve is refused, and `check` judges it as it judges create page — MDL-ATTRPATH01 for the qualified form, MDL-ATTRPATH02 for `Mod.Entity/Attr`. - **A pluggable widget's attribute bound over an association is stored as an association path** (ako/mxcli#2279) — `switch sw (Attribute: Order_Owner/Active)` was written as the flat attribute `Order.Order_Owner/Active`, which mxbuild rejects with CE1613. It is now the final attribute plus its association steps, the shape Studio Pro stores and a built-in input already wrote, in the short and the fully qualified spelling alike. A property linked to no datasource holds one object's value, so a reference-set hop or a reference followed from its non-owner end (CE7247 on mxbuild 11.16.0), and a path that does not resolve, are refused by exec and by `check`. +### Added + +- **`check` warns about a required pluggable-widget setting left unset** (MDL-WIDGET56) — a native gallery without a data source, a slider without an attribute or a repeater without content passed `check` and exec, then failed the build with CE0642 ("Property 'X' is required"), or CE4899 for a text. `check` now reads the installed package and warns about each required setting the script leaves out. A setting with a usable default, or one the widget hides in its current configuration, is not reported. Measured on the 39 native widgets placed with no settings: `check` reports exactly the 30 settings that `mx check` 11.13.0 reports. + ### Changed - **`check` and `exec` refuse an agent with a `Model` but no `SelectedModel`** (ako/mxcli#2289) — MDL-AGENT02 is now an error, not a warning, when the agent names a `Model`: Studio Pro reports it as AE018 ("Model version is required for an agent"), and Agent Editor 2.2+ refuses to import any agent at startup while one is present. **Behaviour change:** a script that `exec` used to apply with a warning is now refused until it states `SelectedModel: ''` (or is run with `--no-check`). It stays a warning for an agent with no `Model`. A `create or modify` that leaves the key out still keeps a stored selected model and is not flagged, and the project check stays silent for AgentEditorCommons before 2.2. The skill, syntax help, docs and examples now give every agent with a `Model` a `SelectedModel`. diff --git a/mdl/executor/validate_widget_required.go b/mdl/executor/validate_widget_required.go new file mode 100644 index 0000000000..9e9cbe2722 --- /dev/null +++ b/mdl/executor/validate_widget_required.go @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "fmt" + "path/filepath" + "strings" + + "github.com/mendixlabs/mxcli/mdl/ast" + "github.com/mendixlabs/mxcli/mdl/linter" + "github.com/mendixlabs/mxcli/mdl/types" + "github.com/mendixlabs/mxcli/modelsdk/widgets/mpk" +) + +// widgetRequiredRule warns about a required pluggable-widget property left unset. +const widgetRequiredRule = "MDL-WIDGET56" + +// validateWidgetRequired warns (MDL-WIDGET56) about a property the widget's +// package marks required that the script leaves unset: mxbuild fails the build +// with CE0642 ("Property 'X' is required"), or CE4899 for a text template. +// Measured with Native Mobile Resources 12.6.0 on mx check 11.13.0: 29 of the +// 39 native widgets placed bare passed check and exec, and failed there. +// +// Set means a value, a filled slot, or at least one list item. A property with +// a usable default needs nothing — an enumeration, a boolean or number, an +// expression or string with a defaultValue, a text template with shipped +// translations — and neither does one the widget's editorConfig hides under +// the configuration, which mx does not require. +// +// Needs the installed package (the project); a warning, because the hidden +// rules are lifted from editorConfig.js and an unread one could leave a +// hidden property looking required. +func validateWidgetRequired(w *ast.WidgetV3, registry *WidgetRegistry, locationPrefix string) []linter.Violation { + def := lookupWidgetDef(w, registry) + if def == nil { + return nil + } + props := requiredTopLevelProps(registryProjectPath(registry), def.WidgetID) + if len(props) == 0 { + return nil + } + values, explicit := widgetValueMap(w, def) + rules := visibilityRulesFor(def, registry) + slots, lists := filledSlotsAndLists(w, def) + + var out []linter.Violation + for _, p := range props { + if propertyHasDefault(p) { + continue + } + key := strings.ToLower(p.Key) + switch { + case p.Type == "widgets" && slots[key]: + continue + case p.Type == "object" && lists[key]: + continue + case explicit[key]: + continue + } + if hiddenByConfiguration(rules, p.Key, values) { + continue + } + code := "CE0642" + if p.Type == "textTemplate" { + code = "CE4899" + } + out = append(out, linter.Violation{ + RuleID: widgetRequiredRule, + Severity: linter.SeverityWarning, + Message: fmt.Sprintf("%s: %s: `%s` (%s) is required and not set — mxbuild fails the build with %s", + locationPrefix, widgetLabel(w.Name, def.MDLName), p.Key, p.Caption, code), + Suggestion: requiredSuggestion(p, def), + }) + } + return out +} + +func requiredSuggestion(p mpk.PropertyDef, def *WidgetDefinition) string { + switch p.Type { + case "widgets": + if kw := childSlotKeyword(def, strings.ToLower(p.Key)); kw != "" { + return fmt.Sprintf("add a `%s { … }` block with at least one widget", kw) + } + case "object": + for _, ol := range def.ObjectLists { + if strings.EqualFold(ol.PropertyKey, p.Key) { + return fmt.Sprintf("add at least one `%s` item", strings.ToLower(ol.MDLContainer)) + } + } + } + return fmt.Sprintf("set `%s:`", p.Key) +} + +// requiredTopLevelProps returns the widget's required, non-system top-level +// properties as its installed package declares them; nil without one. +func requiredTopLevelProps(projectPath, widgetID string) []mpk.PropertyDef { + if projectPath == "" || widgetID == "" { + return nil + } + mpkPath, err := mpk.FindMPK(filepath.Dir(projectPath), widgetID) + if err != nil || mpkPath == "" { + return nil + } + wd, err := mpk.ParseMPKForWidget(mpkPath, widgetID) + if err != nil || wd == nil { + return nil + } + var out []mpk.PropertyDef + for _, p := range wd.Properties { + if p.Required && !p.IsSystem { + out = append(out, p) + } + } + return out +} + +// propertyHasDefault reports whether a required property is satisfied without +// the script naming it. +func propertyHasDefault(p mpk.PropertyDef) bool { + switch p.Type { + case "boolean", "integer", "decimal", "enumeration": + return true + case "expression", "string": + return p.DefaultValue != "" + case "textTemplate": + return len(p.Translations) > 0 + case "attribute", "association", "datasource", "widgets", "object", "image", "file", "icon": + return false + } + // action, selection and any other kind: not measured as required-when-unset. + return true +} + +// hiddenByConfiguration reports whether a top-level visibility rule determinably +// hides key under values. +func hiddenByConfiguration(rules []types.WidgetVisibilityRule, key string, values map[string]string) bool { + for _, r := range rules { + if r.Nested() || r.HiddenWhen == nil || !strings.EqualFold(r.PropertyKey, key) { + continue + } + fires, determinable := r.Fires(func(c types.WidgetVisibilityCondition) (string, bool) { + v, ok := values[strings.ToLower(c.PropertyKey)] + return v, ok + }) + if determinable && fires { + return true + } + } + return false +} + +// filledSlotsAndLists reports which widgets slots hold a widget and which +// object lists hold an item, routed the way the engine routes children +// (applyChildSlots, applyObjectLists): a container keyword, `container +// `, or loose children into the default slot. +func filledSlotsAndLists(w *ast.WidgetV3, def *WidgetDefinition) (slots, lists map[string]bool) { + slots, lists = map[string]bool{}, map[string]bool{} + slotByKeyword := map[string]string{} + all := append([]ChildSlotMapping(nil), def.ChildSlots...) + for _, m := range def.Modes { + all = append(all, m.ChildSlots...) + } + for _, s := range all { + slotByKeyword[strings.ToLower(s.MDLContainer)] = strings.ToLower(s.PropertyKey) + } + listByKeyword := map[string]string{} + for _, ol := range def.ObjectLists { + listByKeyword[strings.ToLower(ol.MDLContainer)] = strings.ToLower(ol.PropertyKey) + } + loose := false + for _, c := range w.Children { + if c == nil { + continue + } + t := strings.ToLower(c.Type) + if key, ok := listByKeyword[t]; ok { + lists[key] = true + continue + } + key, ok := slotByKeyword[t] + if !ok && t == "container" { + key, ok = slotByKeyword[strings.ToLower(c.Name)] + } + if ok { + if len(c.Children) > 0 { + slots[key] = true + } + continue + } + loose = true + } + if key, ok := slotByKeyword[defaultSlotContainer]; ok && loose { + slots[key] = true + } + return slots, lists +} diff --git a/mdl/executor/validate_widget_required_test.go b/mdl/executor/validate_widget_required_test.go new file mode 100644 index 0000000000..2386a54775 --- /dev/null +++ b/mdl/executor/validate_widget_required_test.go @@ -0,0 +1,166 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "archive/zip" + "fmt" + "io" + "os" + "path/filepath" + "sort" + "strings" + "testing" + + "github.com/mendixlabs/mxcli/mdl/ast" + "github.com/mendixlabs/mxcli/mdl/types" + "github.com/mendixlabs/mxcli/mdl/visitor" + mmpk "github.com/mendixlabs/mxcli/modelsdk/widgets/mpk" + "github.com/mendixlabs/mxcli/sdk/widgets/mpk" +) + +// A pluggable widget property the package marks required, left unset, fails +// the build with CE0642 ("Property 'X' is required") or, for a text template, +// CE4899. check said nothing: measured with Native Mobile Resources 12.6.0 on +// mx check 11.13.0, 29 of the 39 native widgets placed bare passed check and +// exec and failed mx check — a gallery with no data source, a slider with no +// attribute, a repeater with no content. +// +// What counts as set: a value, a filled slot, at least one list item. What +// needs nothing: a value with a usable default (an enumeration, a boolean, an +// expression with a defaultValue, a text template with shipped translations), +// and a property the widget's editorConfig hides under the configuration — +// mx does not require what the editor does not show. +const requiredWidgetXML = ` + + Req + + + + Data source + Value attribute + + Content + Items + Label + + Title + Hint + Hint + Minimum + + Mode + PlainURL + URL attribute + + Optional + + + + +` + +func requiredWidgetRegistry(t *testing.T) (*WidgetRegistry, *WidgetDefinition) { + t.Helper() + dir := t.TempDir() + if err := os.MkdirAll(filepath.Join(dir, "widgets"), 0o755); err != nil { + t.Fatal(err) + } + mpkPath := filepath.Join(dir, "widgets", "Req.mpk") + f, err := os.Create(mpkPath) + if err != nil { + t.Fatal(err) + } + zw := zip.NewWriter(f) + for entry, body := range map[string]string{ + "package.xml": ``, + "Req.xml": requiredWidgetXML, + } { + w, err := zw.Create(entry) + if err != nil { + t.Fatal(err) + } + if _, err := io.WriteString(w, body); err != nil { + t.Fatal(err) + } + } + if err := zw.Close(); err != nil { + t.Fatal(err) + } + if err := f.Close(); err != nil { + t.Fatal(err) + } + mpk.ClearCache() + mmpk.ClearCache() + t.Cleanup(func() { mpk.ClearCache(); mmpk.ClearCache() }) + + m, err := mpk.ParseMPK(mpkPath) + if err != nil { + t.Fatal(err) + } + def := GenerateDefJSON(m, "reqwidget") + // The editor hides urlAttribute unless mode is "url". + def.PropertyVisibility = []types.WidgetVisibilityRule{{ + PropertyKey: "urlAttribute", + HiddenWhen: &types.WidgetVisibilityCondition{PropertyKey: "mode", Operator: "ne", Value: "url"}, + }} + reg := &WidgetRegistry{ + byMDLName: map[string]*WidgetDefinition{"REQWIDGET": def}, + byWidgetID: map[string]*WidgetDefinition{def.WidgetID: def}, + projectPath: filepath.Join(dir, "App.mpr"), + } + return reg, def +} + +func requiredReported(t *testing.T, reg *WidgetRegistry, widget string) []string { + t.Helper() + prog, errs := visitor.Build("create page M.P (Title: 'P', Layout: M.L) {\n" + widget + "\n};") + if len(errs) > 0 { + t.Fatalf("parse: %v\n%s", errs[0], widget) + } + var got []string + for _, v := range validateWidgetTree(prog.Statements[0].(*ast.CreatePageStmtV3).Widgets, reg, "page M.P") { + if v.RuleID != widgetRequiredRule { + continue + } + // "page M.P: widget `r1` (reqwidget): `key` (Caption) is required …" + parts := strings.Split(v.Message, "`") + if len(parts) < 4 { + t.Fatalf("message shape: %s", v.Message) + } + got = append(got, parts[3]) + } + sort.Strings(got) + return got +} + +func TestWidgetRequired_UnsetRequiredPropertiesReported(t *testing.T) { + reg, _ := requiredWidgetRegistry(t) + got := strings.Join(requiredReported(t, reg, "reqwidget r1"), ",") + if want := "content,ds,items,title,valueAttribute"; got != want { + t.Errorf("reported %s, want %s — a default, a translation, an enumeration, a hidden and an optional property need nothing", got, want) + } +} + +func TestWidgetRequired_SetPropertiesNotReported(t *testing.T) { + reg, def := requiredWidgetRegistry(t) + if len(def.ObjectLists) != 1 || len(def.ChildSlots) != 1 { + t.Fatalf("definition: %d lists, %d slots — the test widget's shape changed", len(def.ObjectLists), len(def.ChildSlots)) + } + widget := fmt.Sprintf(`reqwidget r1 (ds: database from M.E, valueAttribute: Score, title: 'T') { + %s { dynamictext t1 (Content: 'x') } + %s i1 (itemLabel: 'a') +}`, def.ChildSlots[0].MDLContainer, def.ObjectLists[0].MDLContainer) + if got := requiredReported(t, reg, widget); len(got) != 0 { + t.Errorf("reported %v for a widget that sets every required property:\n%s", got, widget) + } +} + +// A property the configuration shows again is required again. +func TestWidgetRequired_ShownByConfigurationIsRequired(t *testing.T) { + reg, _ := requiredWidgetRegistry(t) + got := requiredReported(t, reg, "reqwidget r1 (mode: url)") + if !strings.Contains(strings.Join(got, ","), "urlAttribute") { + t.Errorf("mode: url shows urlAttribute, so it is required; reported %v", got) + } +} diff --git a/mdl/executor/validate_widgets.go b/mdl/executor/validate_widgets.go index 5f0f36816e..e34fd160ad 100644 --- a/mdl/executor/validate_widgets.go +++ b/mdl/executor/validate_widgets.go @@ -285,6 +285,9 @@ func validateWidgetTreeIn(widgets []*ast.WidgetV3, registry *WidgetRegistry, loc out = append(out, validatePluggableTemplateParams(w, locationPrefix)...) } out = append(out, validateWidgetVisibility(w, registry, locationPrefix)...) + // A required property the package declares, left unset: CE0642 / + // CE4899 at build time (MDL-WIDGET56). + out = append(out, validateWidgetRequired(w, registry, locationPrefix)...) // #1519: several attributes for a widget with one attribute slot — the // drop-down filter. exec refuses it; so does check. if m, attrs, over := singleAttributeOverflow(lookupWidgetDef(w, registry), w); over { From def365572a532ca6c4e95b0e77ae9fb1089b016a Mon Sep 17 00:00:00 2001 From: karahanharunn Date: Fri, 20 Nov 2026 08:53:54 +0100 Subject: [PATCH 12/18] Warn about a pluggable widget on a page of the other platform (MDL-WIDGET55) Co-Authored-By: Claude Opus 5.5 --- .claude/skills/mendix/custom-widgets/SKILL.md | 2 +- .../reference/native-widgets.md | 17 +++ CHANGELOG.md | 6 +- mdl/executor/validate_design_properties.go | 29 +++- mdl/executor/validate_program.go | 5 + mdl/executor/validate_widget_platform.go | 118 +++++++++++++++ mdl/executor/validate_widget_platform_test.go | 143 ++++++++++++++++++ 7 files changed, 307 insertions(+), 13 deletions(-) create mode 100644 .claude/skills/mendix/custom-widgets/reference/native-widgets.md create mode 100644 mdl/executor/validate_widget_platform.go create mode 100644 mdl/executor/validate_widget_platform_test.go diff --git a/.claude/skills/mendix/custom-widgets/SKILL.md b/.claude/skills/mendix/custom-widgets/SKILL.md index 08efda6fb0..72a4e17a52 100644 --- a/.claude/skills/mendix/custom-widgets/SKILL.md +++ b/.claude/skills/mendix/custom-widgets/SKILL.md @@ -146,7 +146,7 @@ If a widget you have installed is not found, extract its definition: mxcli widget init -p app.mpr ``` -The keyword is the widget id's last segment; a **native** widget (`com.mendix.widget.native.*`) is prefixed `native` (`nativeimage`, `nativebadge`). +The keyword is the widget id's last segment; a **native** widget (`com.mendix.widget.native.*`) is prefixed `native` (`nativeimage`, `nativebadge`). Native widgets' required settings, platform, slots and own `editable`: [reference/native-widgets.md](reference/native-widgets.md). A project definition never takes a built-in keyword (`image`, `radiobuttons`, …) for another widget id: it warns and stays `pluggablewidget ''`; delete a stale native `image.def.json` / `radiobuttons.def.json` and re-run `widget init` (mendixlabs/mxcli#1463). ## Built-in Pluggable Widgets diff --git a/.claude/skills/mendix/custom-widgets/reference/native-widgets.md b/.claude/skills/mendix/custom-widgets/reference/native-widgets.md new file mode 100644 index 0000000000..3410986086 --- /dev/null +++ b/.claude/skills/mendix/custom-widgets/reference/native-widgets.md @@ -0,0 +1,17 @@ +# Native mobile widgets + +Supporting reference for [custom-widgets](../SKILL.md). + +The 39 widgets of Native Mobile Resources (`nativegallery`, `nativeslider`, `nativebottomsheet`, `nativebarchart`, …) need no template in mxcli. After `widget init`, each one is built from the project's own `.mpk` file. + +- **Set what the widget requires.** `check` warns (MDL-WIDGET56) about each required setting left out: a gallery's data source, a slider's attribute, a repeater's `template { … }` content, a chart's series. mxbuild fails the build on each with CE0642. +- **Use them on native pages only.** `check` warns (MDL-WIDGET55) about a native widget on a web page, and about a web widget (`combobox`, `datagrid`, `image`, …) on a native page. +- **Slot names come from the definition.** A native gallery's item slot is `template { … }`, not `content`; `check` lists a widget's slots when one is wrong (MDL-WIDGET26). +- **Slider, Range slider, Rating, Toggle buttons:** `editable:` is the widget's own setting, `default` or `never`. It is not the core `Editable`. + +```sql +nativegallery g1 (datasource: database from Module.Item, phoneColumns: 2) { + template { dynamictext t1 (Content: '{1}', ContentParams: ({1} = Title)) } +} +nativeslider s1 (valueAttribute: Score, editable: never) +``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 48878a9153..102e89d923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added +- **`check` warns about a required pluggable-widget setting left unset** (MDL-WIDGET56) — a native gallery without a data source, a slider without an attribute or a repeater without content passed `check` and exec, then failed the build with CE0642 ("Property 'X' is required"), or CE4899 for a text. `check` now reads the installed package and warns about each required setting the script leaves out. A setting with a usable default, or one the widget hides in its current configuration, is not reported. Measured on the 39 native widgets placed with no settings: `check` reports exactly the 30 settings that `mx check` 11.13.0 reports. +- **`check` warns about a pluggable widget on a page of the other platform** (MDL-WIDGET55) — a web widget such as `combobox`, `datagrid` or `image` on a native page, or a native one such as `nativeslider` or `nativegallery` on a web page. Both passed `check` and exec before. The platform comes from the widget's package (embedded template or the project's `.mpk`). A page is judged only when its layout's platform is known, from the script or the project. It is a warning: what mxbuild reports for either case is not measured. - **Lint `MPR017`: a Boolean flag a decision tests but which can only ever hold one value** (ako/mxcli#2403) — the branch it guards is unreachable, and the flow reads as though it has a safety interlock when it has none. Nothing else reports it: the model is valid and the build is clean. The test is the attribute's **reachable value set** — its default plus every literal any Create/Change activity assigns — not "is it ever written". The defect this comes from is a reset flag that *is* written, only ever to `false`, so a "never written" rule would have missed the case it was raised for; and a default of `true` with the only write `false` is two values, so that guard can change state once and is correctly not reported. Four exclusions keep a write the rule cannot see from reading as no write: bound to a page widget (a user may type into it), assigned from an expression rather than a literal, calculated, or not read in any condition. Writes are collected from every module including Marketplace ones, while only the project's own attributes are reported. Boolean only for now — enumerating "the literals I could see" is a far weaker claim for other types. @@ -102,10 +104,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **`alter page … set (attribute: …)` binds a built-in input the way `create page` does** (ako/mxcli#2278) — on a text box, text area, date picker, drop-down, check box or radio buttons, `Assoc/Attr` (and even a bare `Attr`) was stored as a null attribute reference, leaving the input unbound while ALTER reported success, and the fully qualified `"Mod"."Assoc"/"Mod"."Entity"/"Attr"` was stored as one flat name (mxbuild CE1613). The value is now resolved by create page's resolver against the widget's data container, association steps included; a path that does not resolve is refused, and `check` judges it as it judges create page — MDL-ATTRPATH01 for the qualified form, MDL-ATTRPATH02 for `Mod.Entity/Attr`. - **A pluggable widget's attribute bound over an association is stored as an association path** (ako/mxcli#2279) — `switch sw (Attribute: Order_Owner/Active)` was written as the flat attribute `Order.Order_Owner/Active`, which mxbuild rejects with CE1613. It is now the final attribute plus its association steps, the shape Studio Pro stores and a built-in input already wrote, in the short and the fully qualified spelling alike. A property linked to no datasource holds one object's value, so a reference-set hop or a reference followed from its non-owner end (CE7247 on mxbuild 11.16.0), and a path that does not resolve, are refused by exec and by `check`. -### Added - -- **`check` warns about a required pluggable-widget setting left unset** (MDL-WIDGET56) — a native gallery without a data source, a slider without an attribute or a repeater without content passed `check` and exec, then failed the build with CE0642 ("Property 'X' is required"), or CE4899 for a text. `check` now reads the installed package and warns about each required setting the script leaves out. A setting with a usable default, or one the widget hides in its current configuration, is not reported. Measured on the 39 native widgets placed with no settings: `check` reports exactly the 30 settings that `mx check` 11.13.0 reports. - ### Changed - **`check` and `exec` refuse an agent with a `Model` but no `SelectedModel`** (ako/mxcli#2289) — MDL-AGENT02 is now an error, not a warning, when the agent names a `Model`: Studio Pro reports it as AE018 ("Model version is required for an agent"), and Agent Editor 2.2+ refuses to import any agent at startup while one is present. **Behaviour change:** a script that `exec` used to apply with a warning is now refused until it states `SelectedModel: ''` (or is run with `--no-check`). It stays a warning for an agent with no `Model`. A `create or modify` that leaves the key out still keeps a stored selected model and is not flagged, and the project check stays silent for AgentEditorCommons before 2.2. The skill, syntax help, docs and examples now give every agent with a `Model` a `SelectedModel`. diff --git a/mdl/executor/validate_design_properties.go b/mdl/executor/validate_design_properties.go index e5dcd73b99..44f2cb20f9 100644 --- a/mdl/executor/validate_design_properties.go +++ b/mdl/executor/validate_design_properties.go @@ -77,8 +77,20 @@ func ValidateDesignProperties(prog *ast.Program, projectPath string, project fun // nativeLayoutResolver answers whether a layout, by qualified name, is native: // one the script creates with a native layout type, or one the project holds. -// The project is read once, on the first question. +// The project is read once, on the first question. A layout it cannot resolve +// is answered web. func nativeLayoutResolver(prog *ast.Program, project func() backend.FullBackend) func(string) bool { + resolve := layoutPlatformResolver(prog, project) + return func(qn string) bool { + native, _ := resolve(qn) + return native + } +} + +// layoutPlatformResolver is nativeLayoutResolver that also says whether it +// knows: known is false for a layout neither the script nor the project holds, +// for a caller that must not guess. +func layoutPlatformResolver(prog *ast.Program, project func() backend.FullBackend) func(string) (native, known bool) { native := map[string]bool{} for _, stmt := range prog.Statements { if s, ok := stmt.(*ast.CreateLayoutStmt); ok { @@ -88,25 +100,25 @@ func nativeLayoutResolver(prog *ast.Program, project func() backend.FullBackend) } } loaded := project == nil - return func(qn string) bool { + return func(qn string) (bool, bool) { if n, ok := native[qn]; ok { - return n + return n, true } if loaded { - return false + return false, false } loaded = true b := project() if b == nil { - return false + return false, false } layouts, err := b.ListLayouts() if err != nil { - return false + return false, false } h, err := NewContainerHierarchyFromBackend(b) if err != nil { - return false + return false, false } for _, l := range layouts { name := h.GetModuleName(h.FindModuleID(l.ContainerID)) + "." + l.Name @@ -114,7 +126,8 @@ func nativeLayoutResolver(prog *ast.Program, project func() backend.FullBackend) native[name] = l.Native } } - return native[qn] + n, ok := native[qn] + return n, ok } } diff --git a/mdl/executor/validate_program.go b/mdl/executor/validate_program.go index 6df059a4e4..1d1f51eda9 100644 --- a/mdl/executor/validate_program.go +++ b/mdl/executor/validate_program.go @@ -261,6 +261,11 @@ func ValidateProgram(prog *ast.Program, projectPath string) []linter.Violation { // can say which layouts are native. violations = append(violations, ValidatePageLayoutGrid(prog, projectNativeLayouts(project))...) + // A pluggable widget whose package declares the other platform than its + // page's — a web combobox on a native page, a native slider on a web one + // (MDL-WIDGET55). Judged only where both platforms are known. + violations = append(violations, ValidateWidgetPlatforms(prog, projectPath, project)...) + // A widget data source constraint whose one-hop comparand is the wrong type // (MDL-XPATH02) or names its association unqualified (MDL-XPATH01) — // CE0161 at build time (mendixlabs/mxcli#1466). The script's declarations diff --git a/mdl/executor/validate_widget_platform.go b/mdl/executor/validate_widget_platform.go new file mode 100644 index 0000000000..29d1cd7566 --- /dev/null +++ b/mdl/executor/validate_widget_platform.go @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "fmt" + "path/filepath" + "strings" + + "github.com/mendixlabs/mxcli/mdl/ast" + "github.com/mendixlabs/mxcli/mdl/backend" + "github.com/mendixlabs/mxcli/mdl/linter" + mwidgets "github.com/mendixlabs/mxcli/modelsdk/widgets" + "github.com/mendixlabs/mxcli/modelsdk/widgets/mpk" +) + +// widgetPlatformRule warns about a pluggable widget on a page of the other +// platform. +const widgetPlatformRule = "MDL-WIDGET55" + +// ValidateWidgetPlatforms warns (MDL-WIDGET55) about a pluggable widget whose +// package declares a platform other than its page's: a web widget +// (`combobox`, `datagrid`, `image`, …) on a native page, or a native one +// (`nativeslider`, `nativegallery`, …) on a web page. The client of the other +// platform does not render it. +// +// Measured on PedApp (11.13.0) with Native Mobile Resources 12.6.0: both +// directions passed check and exec. It is a warning, not an error: what +// mxbuild reports for either is not measured. +// +// A page is judged only when its layout's platform is known — created by the +// script, or held by the project — and a widget only when its platform is: +// from its embedded template, or the project's installed package. +func ValidateWidgetPlatforms(prog *ast.Program, projectPath string, project func() backend.FullBackend) []linter.Violation { + return validateWidgetPlatforms(prog, LoadWidgetRegistry(projectPath), projectPath, project) +} + +func validateWidgetPlatforms(prog *ast.Program, registry *WidgetRegistry, projectPath string, project func() backend.FullBackend) []linter.Violation { + if registry == nil { + return nil + } + layoutPlatform := layoutPlatformResolver(prog, project) + platforms := map[string]string{} + platformOf := func(widgetID string) string { + p, ok := platforms[widgetID] + if !ok { + p = pluggableWidgetPlatform(widgetID, projectPath) + platforms[widgetID] = p + } + return p + } + + var out []linter.Violation + for _, stmt := range prog.Statements { + page, ok := stmt.(*ast.CreatePageStmtV3) + if !ok || page.Layout == "" { + continue + } + native, known := layoutPlatform(page.Layout) + if !known { + continue + } + pagePlatform, otherPlatform := "Web", "Native" + if native { + pagePlatform, otherPlatform = "Native", "Web" + } + forEachWidget(page, func(w *ast.WidgetV3, where string) { + def := lookupWidgetDef(w, registry) + if def == nil { + return + } + if !strings.EqualFold(platformOf(def.WidgetID), otherPlatform) { + return + } + out = append(out, linter.Violation{ + RuleID: widgetPlatformRule, + Severity: linter.SeverityWarning, + Message: fmt.Sprintf("page %s: `%s %s` is a %s widget (%s) on a %s page, which the %s client does not render", + page.Name.String(), strings.ToLower(w.Type), w.Name, strings.ToLower(otherPlatform), def.WidgetID, + strings.ToLower(pagePlatform), strings.ToLower(pagePlatform)), + Suggestion: platformSuggestion(native), + }) + }) + } + return out +} + +func platformSuggestion(nativePage bool) string { + if nativePage { + return "use the native widget instead (`widget init -p app.mpr` lists the installed `native…` keywords; " + + "`staticimage` / `dynamicimage` for an image), or put the widget on a web page" + } + return "use the web widget instead, or put the widget on a native page" +} + +// pluggableWidgetPlatform is the platform a pluggable widget's package +// declares — Web, Native or All — read from its embedded template, else the +// project's installed .mpk; "" when neither knows the widget. +func pluggableWidgetPlatform(widgetID, projectPath string) string { + if tmpl, err := mwidgets.GetTemplate(widgetID); err == nil && tmpl != nil { + if p, ok := tmpl.Type["SupportedPlatform"].(string); ok && p != "" { + return p + } + return "Web" // an absent supportedPlatform is Web + } + if projectPath == "" { + return "" + } + mpkPath, err := mpk.FindMPK(filepath.Dir(projectPath), widgetID) + if err != nil || mpkPath == "" { + return "" + } + def, err := mpk.ParseMPKForWidget(mpkPath, widgetID) + if err != nil || def == nil { + return "" + } + return def.SupportedPlatform +} diff --git a/mdl/executor/validate_widget_platform_test.go b/mdl/executor/validate_widget_platform_test.go new file mode 100644 index 0000000000..641443f347 --- /dev/null +++ b/mdl/executor/validate_widget_platform_test.go @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "archive/zip" + "io" + "os" + "path/filepath" + "sort" + "strings" + "testing" + + "github.com/mendixlabs/mxcli/mdl/visitor" + "github.com/mendixlabs/mxcli/modelsdk/widgets/mpk" +) + +// A pluggable widget package declares the platform it renders on +// (supportedPlatform: Web, Native or All; absent means Web). check never +// compared it with the page's: measured on PedApp (11.13.0) with Native Mobile +// Resources 12.6.0, `combobox` and `datagrid` on a NativePhone page and +// `nativeslider` / `nativegallery` on an Atlas_Default page all passed check +// and exec. A web widget on a native page is a widget the native client does +// not render, and the reverse the same for the browser. +const nativeSliderXML = ` + + Slider + + + + Value + + + + +` + +// writeNativeWidgetProject writes a project directory holding the native +// slider's package and returns the .mpr path. +func writeNativeWidgetProject(t *testing.T) string { + t.Helper() + dir := t.TempDir() + if err := os.MkdirAll(filepath.Join(dir, "widgets"), 0o755); err != nil { + t.Fatal(err) + } + f, err := os.Create(filepath.Join(dir, "widgets", "com.mendix.widget.native.Slider.mpk")) + if err != nil { + t.Fatal(err) + } + zw := zip.NewWriter(f) + for entry, body := range map[string]string{ + "package.xml": ``, + "Slider.xml": nativeSliderXML, + } { + w, err := zw.Create(entry) + if err != nil { + t.Fatal(err) + } + if _, err := io.WriteString(w, body); err != nil { + t.Fatal(err) + } + } + if err := zw.Close(); err != nil { + t.Fatal(err) + } + if err := f.Close(); err != nil { + t.Fatal(err) + } + mpk.ClearCache() + t.Cleanup(mpk.ClearCache) + return filepath.Join(dir, "App.mpr") +} + +func platformRegistry() *WidgetRegistry { + reg := LoadWidgetRegistry("") + def := &WidgetDefinition{WidgetID: "com.mendix.widget.native.slider.Slider", MDLName: "nativeslider", WidgetKind: "pluggable", + PropertyMappings: []PropertyMapping{{PropertyKey: "valueAttribute", Source: "Attribute", Operation: "attribute"}}} + reg.byMDLName["NATIVESLIDER"] = def + reg.byWidgetID[def.WidgetID] = def + return reg +} + +func platformViolations(t *testing.T, mprPath, src string) []string { + t.Helper() + prog, errs := visitor.Build(src) + if len(errs) > 0 { + t.Fatalf("parse: %v", errs[0]) + } + var got []string + for _, v := range validateWidgetPlatforms(prog, platformRegistry(), mprPath, nil) { + if v.RuleID != widgetPlatformRule { + t.Errorf("rule %s, want %s", v.RuleID, widgetPlatformRule) + } + got = append(got, v.Message) + } + sort.Strings(got) + return got +} + +func TestWidgetPlatform_WebWidgetOnNativePage(t *testing.T) { + mpr := writeNativeWidgetProject(t) + got := platformViolations(t, mpr, `create layout M.NL (LayoutType: Default) { placeholder Main }; +create page M.P (Title: 'N', Layout: M.NL) { + container c { + combobox cb1 + } + image img1 (Image: 'M.Images.logo') + nativeslider s1 +};`) + joined := strings.Join(got, "\n") + if len(got) != 2 || !strings.Contains(joined, "cb1") || !strings.Contains(joined, "img1") { + t.Fatalf("want the web combobox (nested in a container) and the web image reported, got:\n%s", joined) + } + if strings.Contains(joined, "s1") { + t.Errorf("the native slider belongs on a native page:\n%s", joined) + } +} + +func TestWidgetPlatform_NativeWidgetOnWebPage(t *testing.T) { + mpr := writeNativeWidgetProject(t) + got := platformViolations(t, mpr, `create layout M.WL (LayoutType: Responsive) { placeholder Main }; +create page M.P (Title: 'W', Layout: M.WL) { + nativeslider s1 + combobox cb1 +};`) + joined := strings.Join(got, "\n") + if len(got) != 1 || !strings.Contains(joined, "s1") { + t.Fatalf("want only the native slider reported, got:\n%s", joined) + } +} + +// A layout whose platform nothing can tell — neither the script nor a project — +// is not judged: guessing web would report every native widget on a native page. +func TestWidgetPlatform_UnknownLayoutIsNotJudged(t *testing.T) { + mpr := writeNativeWidgetProject(t) + got := platformViolations(t, mpr, `create page M.P (Title: 'X', Layout: Atlas_Core.NativePhone_Default) { + nativeslider s1 + combobox cb1 +};`) + if len(got) != 0 { + t.Fatalf("a page on an unresolved layout must not be judged, got:\n%s", strings.Join(got, "\n")) + } +} From c19340fef6f819ff7de06d5db2f8edb7d44134f3 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 23:09:12 +0000 Subject: [PATCH 13/18] check: type an if by its branches, a date token among them (#2508) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `if … then [%CurrentDateTime%] else $P/CreatedAt` assigned to a DateTime member was refused as a String (E009): argKind typed only a top-level date token, and an if went to inferKind, which calls every token a String. An if is now typed through argKind branch by branch: empty or unknown branches say nothing, disagreeing ones are unknown. mxbuild 11.12.6 builds the reported microflow with 0 errors; a DateTime if assigned to a String is now refused, as it should be. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...-21-if-date-token-branch-typed-string.json | 1 + CHANGELOG.md | 1 + mdl/exprcheck/func_checker.go | 32 ++++++++++++- .../target_kind_if_token_2508_test.go | 47 +++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-other/2026-11-21-if-date-token-branch-typed-string.json create mode 100644 mdl/exprcheck/target_kind_if_token_2508_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-other/2026-11-21-if-date-token-branch-typed-string.json b/.claude/skills/fix-issue/findings/mdl-other/2026-11-21-if-date-token-branch-typed-string.json new file mode 100644 index 0000000000..749da0c3ba --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-other/2026-11-21-if-date-token-branch-typed-string.json @@ -0,0 +1 @@ +{"area": "mdl/exprcheck", "date": "2026-11-21", "refs": ["ako/mxcli#2508"], "ce": ["CE0117"], "symptom": "`change $P (CreatedAt = if $P/CreatedAt = empty then [%CurrentDateTime%] else $P/CreatedAt)` failed check with E009 \"the value assigned to it is a String\"; mxbuild builds it (0 errors). The bare `change $P (CreatedAt = [%CurrentDateTime%])` passed.", "file": "mdl/exprcheck/func_checker.go argKind. Test: mdl/exprcheck/target_kind_if_token_2508_test.go", "cause": "argKind typed a top-level date token as DateTime and sent everything else to inferKind, which calls every token a String; an `if` reached inferKind, whose first known branch (the token) made the whole `if` a String.", "insight": "**A refinement applied only at the root does not reach into the expressions that contain it**: argKind's token rule had to recurse into `if` branches and parentheses. Combine branches so that `empty`/unknown say nothing and disagreement is unknown, never a provable mismatch. The same change makes the reverse case — a DateTime `if` assigned to a String — refused, which it was not before."} diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc99899e1..557a1ef0c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] ### Fixed +- **`check` types an `if` with a date token in a branch as a DateTime** (ako/mxcli#2508) — `if $P/CreatedAt = empty then [%CurrentDateTime%] else $P/CreatedAt` assigned to a DateTime member was refused as a String (E009), and mxbuild builds it. An `if` is now typed by its branches, a date token among them. - **A published REST service rewrite says which operations it removes** (ako/mxcli#2449, mendixlabs/mxcli#1903) — `create or modify published rest service` naming only a new operation deleted the stored ones, and exec said only "Modified". `check` and exec now warn with the operations removed (MDL-REST06), and `check` refuses `alter … add resource` with a stored resource's name and `drop resource` of a missing one, as exec does. - **`import … link` works through a self-association stored as a table** (ako/mxcli#1686) — both junction columns were named after the one entity, so the insert failed (`column "myfirstmodule$personid" … does not exist`). The column names now come from `mendixsystem$association`, and without a row a self-association's two are numbered as Mendix names them (`…personid1` parent, `…personid2` child, measured on 11.12.6). - **A statement appended after an activity with an error handler goes after the handler's rejoin** (ako/mxcli#2489) — `create or modify microflow` spliced it between the activity and the merge its handler rejoins, so the error path skipped the new statement, and the next exec of the unchanged script was refused (MDL-V1-REBUILD). It now goes after the merge, and the script re-runs unchanged. diff --git a/mdl/exprcheck/func_checker.go b/mdl/exprcheck/func_checker.go index 8a5025258d..f38ab23100 100644 --- a/mdl/exprcheck/func_checker.go +++ b/mdl/exprcheck/func_checker.go @@ -361,13 +361,41 @@ func checkCallExpr(c *CallExpr, ctx Context) []Hint { // DateTimes and [%CurrentUser%] is an object. Rather than change what every // other rule sees, the argument check types the date tokens and tolerates the // rest. +// +// An `if` is typed by its branches through this function, not inferKind: +// `if … then [%CurrentDateTime%] else $X/Date` was a String to inferKind and +// refused for a DateTime member, which mxbuild builds (ako/mxcli#2508). A +// branch that is `empty` or unknown says nothing, so the other decides; two +// branches that disagree are unknown, never a provable mismatch. func argKind(e RobustExpr, ctx Context) TypeKind { - if t, ok := unwrapParens(e).(*TokenExpr); ok { - name := strings.TrimSuffix(t.Token, "UTC") + switch n := unwrapParens(e).(type) { + case *TokenExpr: + name := strings.TrimSuffix(n.Token, "UTC") if name == "CurrentDateTime" || strings.HasPrefix(name, "BeginOf") || strings.HasPrefix(name, "EndOf") { return KindDateTime } return KindUnknown + case *IfThenElseExpr: + var then, els TypeKind = KindUnknown, KindUnknown + if n.Then != nil { + then = argKind(n.Then, ctx) + } + if n.Else != nil { + els = argKind(n.Else, ctx) + } + silent := func(k TypeKind) bool { return k == KindUnknown || k == KindEmpty } + switch { + case silent(then) && silent(els): + if then == KindEmpty && els == KindEmpty { + return KindEmpty + } + return KindUnknown + case silent(then): + return els + case silent(els), then == els: + return then + } + return KindUnknown } return inferKind(e, ctx) } diff --git a/mdl/exprcheck/target_kind_if_token_2508_test.go b/mdl/exprcheck/target_kind_if_token_2508_test.go new file mode 100644 index 0000000000..6517f77852 --- /dev/null +++ b/mdl/exprcheck/target_kind_if_token_2508_test.go @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 + +package exprcheck + +import "testing" + +// ako/mxcli#2508: `change $P (CreatedAt = if $P/CreatedAt = empty then +// [%CurrentDateTime%] else $P/CreatedAt)` was refused as E009 "the value +// assigned to it is a String", and mxbuild builds it (0 errors, in a running +// app for a month). A bare token was typed by argKind; inside an `if` its +// branch went to inferKind, which calls every token a String. +func TestIfWithDateTokenBranchIsADateTime_2508(t *testing.T) { + vars := mapScope{"pDateTime": KindDateTime, "pString": KindString, "pBoolean": KindBoolean} + hit := func(src string, target TypeKind) bool { + _, hs := (&parserImpl{}).Parse(src, Context{SlotPath: "DeclareStmt.InitialValue", Microflow: "Mx.F", Scope: vars, Target: target}) + for _, h := range hs { + if h.Code == "E009" { + return true + } + } + return false + } + for _, src := range []string{ + "if $pBoolean then [%CurrentDateTime%] else $pDateTime", + "if $pBoolean then $pDateTime else [%CurrentDateTime%]", + "if $pBoolean then ([%BeginOfCurrentDay%]) else empty", + "if $pBoolean then empty else [%EndOfCurrentMonthUTC%]", + "if $pBoolean then (if $pBoolean then [%CurrentDateTime%] else $pDateTime) else $pDateTime", + } { + if hit(src, KindDateTime) { + t.Errorf("%s: refused for a DateTime target, which mxbuild accepts", src) + } + } + // Controls: what is provably not a DateTime is still refused. + for _, src := range []string{ + "if $pBoolean then 'a' else $pString", + "if $pBoolean then 'a' else 'b'", + } { + if !hit(src, KindDateTime) { + t.Errorf("%s: a String if was not refused for a DateTime target", src) + } + } + // A date-token if is still a mismatch for a String target. + if !hit("if $pBoolean then [%CurrentDateTime%] else $pDateTime", KindString) { + t.Error("a DateTime if was not refused for a String target") + } +} From cbbfdeef9a6078a9ac36b56d77c1acb3e939b273 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 23:11:27 +0000 Subject: [PATCH 14/18] widget describe: say when an editorConfig's hide rules were not read (#2507) A widget whose editorConfig.js hides properties through its own helper (a local hideProperties(...) filtering by key) printed "Dynamic property rules (0): (none discovered)", indistinguishable from a widget that hides nothing. describe now says the editorConfig.js is there and none of its hide calls is one mxcli reads, and what that means (a hidden property set to other than its default is CE0463). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...et-describe-unread-editorconfig-rules.json | 1 + CHANGELOG.md | 1 + mdl/executor/widget_describe.go | 26 +++++++++++-- .../widget_rule_coverage_2507_test.go | 38 +++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/mdl-executor/2026-11-21-widget-describe-unread-editorconfig-rules.json create mode 100644 mdl/executor/widget_rule_coverage_2507_test.go diff --git a/.claude/skills/fix-issue/findings/mdl-executor/2026-11-21-widget-describe-unread-editorconfig-rules.json b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-21-widget-describe-unread-editorconfig-rules.json new file mode 100644 index 0000000000..3bf0672785 --- /dev/null +++ b/.claude/skills/fix-issue/findings/mdl-executor/2026-11-21-widget-describe-unread-editorconfig-rules.json @@ -0,0 +1 @@ +{"area": "mdl-executor", "date": "2026-11-21", "refs": ["ako/mxcli#2507"], "ce": ["CE0463"], "symptom": "`mxcli widget describe` of project-local widgets (com.knightshift.widgets.ChessBoard / ChessClock) said `Dynamic property rules (0): (none discovered)` although each .mpk's editorConfig.js hides property groups through a local `hideProperties(…)` helper; script values in those hidden properties were CE0463 for a month.", "file": "mdl/executor/widget_describe.go rulesFromProject / ruleCoverageText. Test: mdl/executor/widget_rule_coverage_2507_test.go", "cause": "The extractor counts only the toolkit helpers (hidePropertyIn, hidePropertiesIn, hideNestedPropertiesIn); a local helper gives total 0, and a 0 total printed no coverage line at all, indistinguishable from a widget with no editorConfig.", "insight": "**Report \"rules exist, not read\" separately from \"no rules\"**: a zero count with no denominator is read as a fact about the widget. Checking for the editorConfig.js itself is the cheap way to give the zero a denominator."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 557a1ef0c3..613b82deb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] ### Fixed +- **`widget describe` says when a widget's hide rules could not be read** (ako/mxcli#2507) — a widget whose editorConfig.js hides properties through its own helper listed "(none discovered)", which read as "hides nothing", and a script value in such a property was CE0463 with no pointer to why. It now says the editorConfig.js is there and none of its hide calls is one mxcli reads. - **`check` types an `if` with a date token in a branch as a DateTime** (ako/mxcli#2508) — `if $P/CreatedAt = empty then [%CurrentDateTime%] else $P/CreatedAt` assigned to a DateTime member was refused as a String (E009), and mxbuild builds it. An `if` is now typed by its branches, a date token among them. - **A published REST service rewrite says which operations it removes** (ako/mxcli#2449, mendixlabs/mxcli#1903) — `create or modify published rest service` naming only a new operation deleted the stored ones, and exec said only "Modified". `check` and exec now warn with the operations removed (MDL-REST06), and `check` refuses `alter … add resource` with a stored resource's name and `drop resource` of a missing one, as exec does. - **`import … link` works through a self-association stored as a table** (ako/mxcli#1686) — both junction columns were named after the one entity, so the insert failed (`column "myfirstmodule$personid" … does not exist`). The column names now come from `mendixsystem$association`, and without a row a self-association's two are numbered as Mendix names them (`…personid1` parent, `…personid2` child, measured on 11.12.6). diff --git a/mdl/executor/widget_describe.go b/mdl/executor/widget_describe.go index 4d6874e224..1c1baf02b2 100644 --- a/mdl/executor/widget_describe.go +++ b/mdl/executor/widget_describe.go @@ -378,11 +378,29 @@ func isSystemPropKey(key string) bool { // config, returning the rules and a coverage note (recognized / total hide-calls). func rulesFromProject(mpkPath, widgetID string) ([]DescribedRule, string) { rules, recognized, total := ExtractWidgetVisibilityStats(mpkPath, widgetID) - coverage := "" - if total > 0 { - coverage = fmt.Sprintf("%d of %d editor hide-rules recognized", recognized, total) + present := total > 0 + if !present { + js, err := mmpk.ReadEditorConfig(mpkPath, widgetID) + present = err == nil && strings.TrimSpace(js) != "" } - return rulesToDescribed(rules), coverage + return rulesToDescribed(rules), ruleCoverageText(present, recognized, total) +} + +// ruleCoverageText says how far the listed rules can be trusted. A widget that +// ships an editorConfig.js whose hide calls are none of the toolkit helpers +// mxcli reads — a local `hideProperties(…)` that filters by key — listed +// "(none discovered)" and nothing else, which reads as "the widget hides +// nothing" (ako/mxcli#2507). It says the rules exist and were not read. +func ruleCoverageText(editorConfigPresent bool, recognized, total int) string { + switch { + case total > 0: + return fmt.Sprintf("%d of %d editor hide-rules recognized", recognized, total) + case editorConfigPresent: + return "the widget ships an editorConfig.js, but none of its hide calls is one mxcli reads " + + "(hidePropertyIn, hidePropertiesIn, hideNestedPropertiesIn): any property it hides is unknown here, " + + "and a hidden property set to other than its default is CE0463" + } + return "" } func rulesFromDef(rules []types.WidgetVisibilityRule) []DescribedRule { diff --git a/mdl/executor/widget_rule_coverage_2507_test.go b/mdl/executor/widget_rule_coverage_2507_test.go new file mode 100644 index 0000000000..6df87df7ab --- /dev/null +++ b/mdl/executor/widget_rule_coverage_2507_test.go @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executor + +import ( + "strings" + "testing" +) + +// ako/mxcli#2507 (1): `widget describe` of a widget whose editorConfig.js +// hides properties through a local helper said "Dynamic property rules (0) … +// (none discovered)", which reads as "hides nothing". The CE0463 it caused +// went unexplained for a month. +func TestRuleCoverageSaysUnreadRulesExist_2507(t *testing.T) { + got := ruleCoverageText(true, 0, 0) + for _, want := range []string{"editorConfig.js", "none of its hide calls", "CE0463"} { + if !strings.Contains(got, want) { + t.Errorf("coverage %q lacks %q", got, want) + } + } + // Controls: no editorConfig says nothing; recognised calls keep the count. + if got := ruleCoverageText(false, 0, 0); got != "" { + t.Errorf("no editorConfig: %q", got) + } + if got := ruleCoverageText(true, 2, 3); got != "2 of 3 editor hide-rules recognized" { + t.Errorf("counted: %q", got) + } +} + +// The local helper the report's widgets use is not counted as a hide call: +// that is what makes total 0 while rules exist. +func TestLocalHideHelperIsNotAToolkitCall_2507(t *testing.T) { + js := `function hideProperties(p,keys){return p.map(function(g){return g})} exports.getProperties=function(v,p){"none"===v.playerColor&&hideProperties(p,["notationLanguage","showNotationInput"]);return p}` + rules, stats := extractVisibilityRulesFromJS(js) + if len(rules) != 0 || stats.TotalHideCalls != 0 { + t.Fatalf("rules %v, stats %+v: the premise of the coverage line changed", rules, stats) + } +} From d36523ed01189ed7074361a0854d488b06721170 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 22:50:03 +0000 Subject: [PATCH 15/18] fix(report traceability): document anchors reach their callees, calculated attributes their retrievers Two footprints were narrower than a microflow anchor's: - a published REST service (and a page, workflow, scheduled event, published or consumed service, mapping) got only the microflows it names, without their same-module callees, so a test that calls a handler's sub-microflow directly proved nothing; - a calculated attribute got only its calculation microflow, which the runtime runs and no flow calls, so no test could ever be linked. Its footprint is now its entity's calculation microflows plus the microflows that retrieve the entity (the runtime calculates it on retrieval), marked approximate. The shared-helper cut still applies to both. Fixes ako/mxcli#2504 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qTgUsRMETmzvjS27w --- ...ity-footprint-narrower-than-microflow.json | 1 + cmd/mxcli/projectreport/traceability.go | 52 ++++++++++++++++- cmd/mxcli/projectreport/traceability_test.go | 58 +++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-traceability-footprint-narrower-than-microflow.json diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-traceability-footprint-narrower-than-microflow.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-traceability-footprint-narrower-than-microflow.json new file mode 100644 index 0000000000..e7b8df3f47 --- /dev/null +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-traceability-footprint-narrower-than-microflow.json @@ -0,0 +1 @@ +{"area": "cmd/mxcli", "date": "2026-11-21", "symptom": "report traceability shows 0 microflow tests for a requirement anchored on a published REST service whose handler's sub-microflow a test calls, and can never link a test to a calculated attribute", "cause": "document anchors (REST service, page, workflow, …) got only the microflows they name, without the same-module callee expansion a microflow anchor gets; a calculated attribute got only its calculation microflow, which no flow calls", "file": "`cmd/mxcli/projectreport/traceability.go` (footprint, sameModuleClosure, calculatedFootprint)", "insight": "Every anchor kind should reach the same depth: the expansion belongs after the per-kind query, not in one case. For a calculated attribute the 'caller' is the runtime on retrieval, so the retrievers of its entity are the honest (approximate) footprint", "refs": ["ako/mxcli#2504"], "test": "TestTraceabilityFootprintReachesCalleesAndCalculation"} diff --git a/cmd/mxcli/projectreport/traceability.go b/cmd/mxcli/projectreport/traceability.go index 83ab1c13c1..24e904071c 100644 --- a/cmd/mxcli/projectreport/traceability.go +++ b/cmd/mxcli/projectreport/traceability.go @@ -166,6 +166,11 @@ func footprint(q Querier, a brain.AnchorResult, mfModule map[string]string, g Ca OR (r.RefKind = 'retrieve' AND EXISTS (SELECT 1 FROM entities e WHERE e.QualifiedName = '` + lit + `' AND upper(COALESCE(e.EntityType, '')) LIKE '%VIEW%')))` case "attribute", "association": + if strings.ToLower(a.Kind) == "attribute" { + if out, ok, err := calculatedFootprint(q, lit); ok || err != nil { + return out, true, err + } + } out, err := refSources(q, `SELECT DISTINCT SourceName AS TargetName FROM refs WHERE SourceType = 'MICROFLOW' AND TargetName = '`+lit+`'`) if err != nil || len(out) > 0 || strings.ToLower(a.Kind) != "attribute" { return out, false, err @@ -184,7 +189,50 @@ func footprint(q Querier, a brain.AnchorResult, mfModule map[string]string, g Ca return nil, false, nil } out, err := refSources(q, sql) - return out, false, err + // The microflows a document runs do their work through their callees, as + // an anchored microflow does: give them the same same-module expansion, + // or a test that calls a REST handler's sub-microflow directly proves + // nothing (ako/mxcli#2504). The shared-helper cut applies afterwards. + return sameModuleClosure(out, mfModule, g), false, err +} + +// sameModuleClosure is the given microflows plus what each calls, within the +// calling microflow's own module. +func sameModuleClosure(ms []string, mfModule map[string]string, g CallGraph) []string { + seen := map[string]bool{} + var out []string + for _, root := range ms { + mod := mfModule[root] + for _, m := range g.Closure([]string{root}) { + if (m == root || mfModule[m] == mod) && !seen[m] { + seen[m] = true + out = append(out, m) + } + } + } + return out +} + +// calculatedFootprint is a calculated attribute's footprint: its entity's +// calculation microflows, which the runtime runs and no flow calls, and the +// microflows that retrieve the entity — the runtime calculates the attribute +// when the object is retrieved. Approximate by nature (ako/mxcli#2504). ok is +// false for an attribute that is not calculated. +func calculatedFootprint(q Querier, attr string) ([]string, bool, error) { + i := strings.LastIndexByte(attr, '.') + if i <= 0 { + return nil, false, nil + } + entity, name := attr[:i], attr[i+1:] + rs, err := rows(q, `SELECT COALESCE(IsCalculated, 0) AS C FROM attributes WHERE EntityQualifiedName = '`+entity+`' AND Name = '`+name+`'`) + if err != nil || len(rs) == 0 || (rs[0]["C"] != "1" && !strings.EqualFold(rs[0]["C"], "true")) { + return nil, false, err + } + out, err := refSources(q, `SELECT DISTINCT TargetName FROM refs WHERE SourceName = '`+entity+`' AND RefKind = 'calculate' AND TargetType = 'MICROFLOW' + UNION SELECT DISTINCT SourceName AS TargetName FROM refs WHERE SourceType = 'MICROFLOW' AND TargetName = '`+entity+`' AND RefKind = 'retrieve' + UNION SELECT DISTINCT SourceName AS TargetName FROM refs WHERE SourceType = 'MICROFLOW' AND TargetName = '`+attr+`'`) + sort.Strings(out) + return out, true, err } func refSources(q Querier, sql string) ([]string, error) { @@ -460,7 +508,7 @@ func citesID(e brain.Entry, id string) bool { var TraceabilityMethod = []string{ "Requirements, decisions and open questions are read from the project brain (`docs/brain/`) with `brain list`; each requirement's anchor resolutions come from the same check `brain plan` uses, so \"built\" is defined in one place.", "Status is derived, never ticked off: built when every anchor resolves in the model; not built when one does not; not traceable without anchors; partial or changed when a decision says ``Partly meets requirement ``: …`` or ``Changes requirement ``: …`` (validated by `brain check`).", - "Footprint: the microflows that implement a requirement — an anchored microflow plus its same-module callees; microflows a page, workflow, scheduled event or published service anchor calls; microflows that write an anchored entity or retrieve an anchored view entity; microflows that use an anchored attribute or association. Helpers with more than three callers are left out.", + "Footprint: the microflows that implement a requirement — an anchored microflow plus its same-module callees; microflows a page, workflow, scheduled event or published service anchor calls, plus their same-module callees; microflows that write an anchored entity or retrieve an anchored view entity; microflows that use an anchored attribute or association. A calculated attribute's footprint is its entity's calculation microflows and the microflows that retrieve the entity, since the runtime calculates it on retrieval (approximate). Helpers with more than three callers are left out.", "A microflow test proves a requirement when what it calls, with their call closure, touches the footprint. A journey proves it when a footprint microflow appears in its spans, or its log names an anchored page.", "Decisions bear on a requirement when they share an anchor (module anchors excluded) or cite its id; open questions also when filed on its slice.", "Milestones come from the plan: a slice's frontmatter (`milestone:`), or a requirement's ``Milestone: `` `` line (`mxcli brain milestone`); without any, each slice is a milestone. They are ordered by first appearance, walking the slices in name order.", diff --git a/cmd/mxcli/projectreport/traceability_test.go b/cmd/mxcli/projectreport/traceability_test.go index c4ad5be44e..4fd28826cd 100644 --- a/cmd/mxcli/projectreport/traceability_test.go +++ b/cmd/mxcli/projectreport/traceability_test.go @@ -249,3 +249,61 @@ func TestTraceabilityAgreesWithBrainPlan(t *testing.T) { } } } + +// Two footprints were narrower than a microflow anchor's (ako/mxcli#2504): +// - a published REST service's footprint was its operations' microflows +// only, without their same-module callees, so a test that calls the +// handler's sub-microflow directly proved nothing; +// - a calculated attribute's footprint was its calculation microflow, which +// the runtime runs and no flow calls. The runtime calculates it when the +// object is retrieved, so the microflows that retrieve its entity are its +// (approximate) footprint. +func TestTraceabilityFootprintReachesCalleesAndCalculation(t *testing.T) { + f := newFixture(t) + f.module("Agenda", "") + f.module("Toets", "") + f.module("Util", "") + for _, m := range []string{"Agenda.PRS_Rooster", "Agenda.SUB_Agenda_Ics", "Util.SUB_Format", "Toets.CAL_Publiek", "Toets.ACT_Toon"} { + f.microflow(m, true, "") + } + f.exec(`INSERT INTO published_rest_operations_data (Id, ServiceQualifiedName, ResourceName, HttpMethod, Path, Microflow, ModuleName) + VALUES ('op', 'Agenda.PRS_Agenda', 'rooster', 'GET', '/rooster', 'Agenda.PRS_Rooster', 'Agenda')`) + f.call("Agenda.PRS_Rooster", "Agenda.SUB_Agenda_Ics") + f.call("Agenda.PRS_Rooster", "Util.SUB_Format") // another module: not this requirement's work + f.exec(`INSERT INTO attributes_data (Id, Name, EntityQualifiedName, ModuleName, DataType, IsCalculated) + VALUES ('at', 'PubliekeTekst', 'Toets.Toetsresultaat', 'Toets', 'String', 1)`) + f.ref("Toets.Toetsresultaat", "ENTITY", "Toets.CAL_Publiek", "MICROFLOW", "calculate") + f.ref("Toets.ACT_Toon", "MICROFLOW", "Toets.Toetsresultaat", "ENTITY", "retrieve") + + in := TraceabilityInput{ + Requirements: []brain.RequirementResult{ + req("aaaaaa", "01", "Calendar feed", true, anchor("@Agenda.PRS_Agenda", "published_rest_service", brain.Resolved)), + req("bbbbbb", "01", "Public text", true, anchor("@Toets.Toetsresultaat.PubliekeTekst", "attribute", brain.Resolved)), + }, + Evidence: &TestsData{HasResults: true, Tests: []TestInfo{ + {Name: "ics export", Reached: []string{"Agenda.SUB_Agenda_Ics"}}, + {Name: "shows the result", Reached: []string{"Toets.ACT_Toon"}}, + }}, + } + d, err := CollectTraceability(f.cat, in) + if err != nil { + t.Fatal(err) + } + got := map[string]TraceRequirement{} + for _, r := range d.Milestones[0].Requirements { + got[r.ID] = r + } + if fp := got["aaaaaa"].Footprint; !reflect.DeepEqual(fp, []string{"Agenda.PRS_Rooster", "Agenda.SUB_Agenda_Ics"}) { + t.Errorf("REST footprint = %v, want the handler and its same-module callee", fp) + } + if ts := got["aaaaaa"].Tests; !reflect.DeepEqual(ts, []string{"ics export"}) { + t.Errorf("REST requirement tests = %v, want the test that calls the callee", ts) + } + r := got["bbbbbb"] + if !r.FootprintApprox || !reflect.DeepEqual(r.Footprint, []string{"Toets.ACT_Toon", "Toets.CAL_Publiek"}) { + t.Errorf("calculated attribute footprint = %v (approx %v), want its calculation and the flows that retrieve its entity", r.Footprint, r.FootprintApprox) + } + if !reflect.DeepEqual(r.Tests, []string{"shows the result"}) { + t.Errorf("calculated attribute tests = %v", r.Tests) + } +} From df51923d121ff4ca7c7af96f1a75a04cc5f2684b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 08:53:18 +0000 Subject: [PATCH 16/18] docker check, fix widgets: say which values update-widgets resets (#2507) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A CE0463 caused by a script value in a property the widget's editorConfig hides was labelled "stale widget definition — fix widgets fixes it"; update-widgets clears it by resetting the value to the widget's default (the type stays byte-identical), so fix widgets dropped what the script set without a word. Widget property values are now compared before and after the tool, by key, with $IDs, pointers and key order removed. docker check labels such a CE0463 with the properties it resets and does not offer fix widgets for it; fix widgets lists every value it replaced. Measured on mxchess (11.15.0): the spectator board's notationLanguage, showNotationInput are named, and the clean project reports nothing. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qrr1WnXxq1eRn7qRJ --- ...463-hidden-value-reset-by-fix-widgets.json | 1 + CHANGELOG.md | 1 + cmd/mxcli/cmd_fix.go | 12 ++ cmd/mxcli/docker/check.go | 53 ++++- cmd/mxcli/docker/harvest.go | 18 ++ cmd/mxcli/docker/widget_values.go | 198 ++++++++++++++++++ cmd/mxcli/docker/widget_values_2507_test.go | 103 +++++++++ docs-site/src/tools/docker-check.md | 1 + 8 files changed, 383 insertions(+), 4 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/cmd-mxcli/2026-11-22-ce0463-hidden-value-reset-by-fix-widgets.json create mode 100644 cmd/mxcli/docker/widget_values.go create mode 100644 cmd/mxcli/docker/widget_values_2507_test.go diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-22-ce0463-hidden-value-reset-by-fix-widgets.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-22-ce0463-hidden-value-reset-by-fix-widgets.json new file mode 100644 index 0000000000..4ecf879a5f --- /dev/null +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-22-ce0463-hidden-value-reset-by-fix-widgets.json @@ -0,0 +1 @@ +{"area": "cmd-mxcli", "date": "2026-11-22", "refs": ["ako/mxcli#2507"], "ce": ["CE0463"], "symptom": "A page script set `notationLanguage` and `showNotationInput` on a spectator ChessBoard (`playerColor: '''none'''`), which the widget's editorConfig hides: CE0463 at 'previewBoard', labelled by docker check \"stale widget definition — `mxcli fix widgets` fixes it\". fix widgets cleared it by resetting both to their defaults and said only \"1 unit(s) changed\"; the next diff showed the values pending again.", "file": "cmd/mxcli/docker/widget_values.go widgetPropertyValues / widgetValueChanges (used by check.go recheckCE0463 and harvest.go applyHarvest → HarvestResult.ValueChanges, printed by cmd_fix.go reportFix). Test: cmd/mxcli/docker/widget_values_2507_test.go", "cause": "The re-check decided stale vs persisting only by whether the CE0463 cleared after update-widgets; update-widgets clears this one by resetting values (the widget's type stays byte-identical), which nothing compared.", "insight": "**Compare widget values by property key with $IDs, pointers and key order removed**: update-widgets re-saves a DataGrid2 DataSource with its keys sorted, and without the key-order normalisation 24 of mxchess's widgets read as changed. In fix widgets, compare only the units the harvest writes, and control on the clean project: 0 units changed, no values listed (measured on mxchess, 11.15.0)."} diff --git a/CHANGELOG.md b/CHANGELOG.md index 613b82deb5..8190af8d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] ### Fixed +- **`docker check` and `fix widgets` say when update-widgets resets a value instead of resyncing a widget** (ako/mxcli#2507) — a CE0463 caused by a script value in a property the widget's editorConfig hides was labelled "stale widget definition — `mxcli fix widgets` fixes it", and `fix widgets` cleared it by resetting the value to the widget's default without a word. `docker check` now names the properties update-widgets resets on that widget, and `fix widgets` lists every value it replaced. - **`widget describe` says when a widget's hide rules could not be read** (ako/mxcli#2507) — a widget whose editorConfig.js hides properties through its own helper listed "(none discovered)", which read as "hides nothing", and a script value in such a property was CE0463 with no pointer to why. It now says the editorConfig.js is there and none of its hide calls is one mxcli reads. - **`check` types an `if` with a date token in a branch as a DateTime** (ako/mxcli#2508) — `if $P/CreatedAt = empty then [%CurrentDateTime%] else $P/CreatedAt` assigned to a DateTime member was refused as a String (E009), and mxbuild builds it. An `if` is now typed by its branches, a date token among them. - **A published REST service rewrite says which operations it removes** (ako/mxcli#2449, mendixlabs/mxcli#1903) — `create or modify published rest service` naming only a new operation deleted the stored ones, and exec said only "Modified". `check` and exec now warn with the operations removed (MDL-REST06), and `check` refuses `alter … add resource` with a stored resource's name and `drop resource` of a missing one, as exec does. diff --git a/cmd/mxcli/cmd_fix.go b/cmd/mxcli/cmd_fix.go index f9031eb900..e8e1cbb972 100644 --- a/cmd/mxcli/cmd_fix.go +++ b/cmd/mxcli/cmd_fix.go @@ -159,6 +159,18 @@ func reportFix(out io.Writer, what string, res *docker.HarvestResult) { for _, r := range res.Removed { fmt.Fprintf(out, " Note: the tool removed a unit this did not remove: %s\n", r) } + // A value the tool changed is one the project set and no longer has — + // update-widgets resets a property the widget's editorConfig hides + // (ako/mxcli#2507). Said, so a script that sets it is fixed at the source. + if n := len(res.ValueChanges); n > 0 { + fmt.Fprintf(out, " Values reset: %d widget(s) had property values the tool replaced with the widget's defaults:\n", n) + for _, c := range res.ValueChanges { + fmt.Fprintf(out, " %s\n", c) + } + fmt.Fprintln(out, " These are typically properties the widget hides for the values given (its editorConfig). A") + fmt.Fprintln(out, " script that sets them will set them again: leave them out of it, or change the values") + fmt.Fprintln(out, " that hide them.") + } if n := len(res.LeftAsStored); n > 0 { fmt.Fprintf(out, " Left as stored: %d unit(s) the tool re-saved that hold no widget (re-encoded only):\n", n) for _, u := range res.LeftAsStored { diff --git a/cmd/mxcli/docker/check.go b/cmd/mxcli/docker/check.go index d7386e6cd3..9cdf93b165 100644 --- a/cmd/mxcli/docker/check.go +++ b/cmd/mxcli/docker/check.go @@ -50,7 +50,10 @@ type CheckOptions struct { // The two labels a CE0463 of the stored project gets from the re-check. const ( - staleCE0463Label = "stale widget definition — `mxcli fix widgets` fixes it" + staleCE0463Label = "stale widget definition — `mxcli fix widgets` fixes it" + // resetCE0463Label is a CE0463 update-widgets clears by resetting values the + // project set: a property the widget hides, not a stale type (#2507). + resetCE0463Label = "a value in a property the widget hides — update-widgets clears it by resetting" persistingCE0463Label = "persists after update-widgets" ) @@ -217,6 +220,12 @@ func recheckCE0463(w io.Writer, out *pathRewriter, mxPath, workMpr, projectPath len(stored), plural(len(stored), "error", "errors")) fmt.Fprintln(w, " `mx update-widgets` to tell stale widget definitions from other causes...") + // The copy's widget values before the resync, so the re-check can say + // which ones update-widgets resets (ako/mxcli#2507). + valuesBefore := widgetValues{} + if units, _, rerr := readAllUnits(workMpr); rerr == nil { + valuesBefore = widgetPropertyValues(units) + } var uwOut bytes.Buffer if err := updateWidgetsCmd(mxPath, workMpr, &uwOut, &uwOut); err != nil { // Its output says why (mendixlabs/mxcli#1629: another patch version). @@ -235,6 +244,15 @@ func recheckCE0463(w io.Writer, out *pathRewriter, mxPath, workMpr, projectPath return } + var resets []widgetValueChange + if units, _, rerr := readAllUnits(workMpr); rerr == nil { + resets = widgetValueChanges(valuesBefore, widgetPropertyValues(units)) + } + resetOn := map[string][]string{} + for _, c := range resets { + resetOn[c.Widget] = append(resetOn[c.Widget], strings.Join(c.Properties, ", ")) + } + remaining := map[string]int{} for _, l := range ce0463Lines(after.String()) { remaining[l]++ @@ -247,23 +265,39 @@ func recheckCE0463(w io.Writer, out *pathRewriter, mxPath, workMpr, projectPath } total[l]++ } - stale, persisting := 0, 0 + // reset counts the CE0463s update-widgets cleared by resetting a value the + // project set; they are not stale definitions, and `fix widgets` is not + // their fix (ako/mxcli#2507). + stale, persisting, reset := 0, 0, 0 fmt.Fprintln(w, "CE0463 in the stored project:") for _, l := range order { n := total[l] p := min(remaining[l], n) s := n - p - stale += s persisting += p at := ce0463Location(l) if s > 0 { - fmt.Fprintf(w, " at %s%s: %s\n", at, countOf(s, n), staleCE0463Label) + if props := resetOn[ce0463WidgetName(at)]; len(props) > 0 { + reset += s + fmt.Fprintf(w, " at %s%s: %s %s\n", at, countOf(s, n), resetCE0463Label, strings.Join(props, "; ")) + } else { + stale += s + fmt.Fprintf(w, " at %s%s: %s\n", at, countOf(s, n), staleCE0463Label) + } } if p > 0 { fmt.Fprintf(w, " at %s%s: %s\n", at, countOf(p, n), persistingCE0463Label) } } + if reset > 0 { + fmt.Fprintf(w, "%s not a stale widget definition: update-widgets clears %s by replacing the values\n", + plural(reset, "That one is", "Those are"), plural(reset, "it", "them")) + fmt.Fprintln(w, " named above with the widget's defaults — properties its editorConfig hides for the values") + fmt.Fprintln(w, " given. `fix widgets` would drop them from the project, and a script that sets them brings") + fmt.Fprintln(w, " the error back. Leave them out of the script, or change the values that hide them.") + } switch { + case stale == 0 && persisting == 0: case persisting == 0 && stale == 1: fmt.Fprintln(w, "It is a stale widget definition. This updates it in the project, as Studio Pro's") fmt.Fprintln(w, " \"Update all widgets\" does:") @@ -536,3 +570,14 @@ func AnyCachedMxPath() string { // LocalMxForVersion is localMxForVersion: an installed or cached mx of exactly // version, or "". func LocalMxForVersion(version string) string { return localMxForVersion(version) } + +// ce0463WidgetName is the widget name in a CE0463 location, the quoted part of +// "Chess Board 'previewBoard'"; "" when there is none. +func ce0463WidgetName(at string) string { + i := strings.Index(at, "'") + j := strings.LastIndex(at, "'") + if i < 0 || j <= i { + return "" + } + return at[i+1 : j] +} diff --git a/cmd/mxcli/docker/harvest.go b/cmd/mxcli/docker/harvest.go index 14d6d1fa07..822caa2c41 100644 --- a/cmd/mxcli/docker/harvest.go +++ b/cmd/mxcli/docker/harvest.go @@ -33,6 +33,12 @@ type HarvestResult struct { // something this mechanism was not built for and the caller should say so. Added []string Removed []string + // ValueChanges names the pluggable widget property values the tool + // changed, as against the project before it ran. update-widgets resets a + // value in a property the widget's editorConfig hides, which is how it + // clears such a CE0463, and the value the project set is gone + // (ako/mxcli#2507). Empty when only types were resynced. + ValueChanges []string // LeftAsStored names units the tool re-saved with a real difference that // were not written back, as " ", because the tool has no business // with that kind of document (harvestScope). @@ -226,6 +232,12 @@ func applyHarvest(projectPath string, fixed map[string]harvestedUnit, order []st return nil, fmt.Errorf("read the restored project: %w", err) } + // The units written, as stored and as written: their widget values are + // compared below. Only written units — a unit the tool re-saved with no + // real difference is not written, and comparing its raw output listed + // widgets the project never lost a value on. + wroteBefore := map[string]harvestedUnit{} + wroteAfter := map[string]harvestedUnit{} for _, id := range order { h := fixed[id] prev, ok := stored[id] @@ -249,6 +261,12 @@ func applyHarvest(projectPath string, fixed map[string]harvestedUnit, order []st return nil, fmt.Errorf("write unit %s: %w", id, err) } res.UnitsWritten++ + wroteBefore[id] = prev + wroteAfter[id] = harvestedUnit{contents: out, unitType: prev.unitType} + } + // What the tool changed in the values the project set (ako/mxcli#2507). + for _, c := range widgetValueChanges(widgetPropertyValues(wroteBefore), widgetPropertyValues(wroteAfter)) { + res.ValueChanges = append(res.ValueChanges, c.String()) } for id, s := range stored { diff --git a/cmd/mxcli/docker/widget_values.go b/cmd/mxcli/docker/widget_values.go new file mode 100644 index 0000000000..d497af91af --- /dev/null +++ b/cmd/mxcli/docker/widget_values.go @@ -0,0 +1,198 @@ +// SPDX-License-Identifier: Apache-2.0 + +package docker + +import ( + "bytes" + "fmt" + "sort" + "strings" + + "go.mongodb.org/mongo-driver/v2/bson" +) + +// widgetValueChange names the properties of one pluggable widget whose values +// differ between two states of a project. +// +// `mx update-widgets` clears a CE0463 caused by a value in a property the +// widget's editorConfig hides by resetting the property to its default: the +// stored type stays byte-identical and only the values move (measured on +// 11.15.0, ako/mxcli#2507). So a "stale widget definition" label, and a quiet +// `fix widgets`, dropped the values a script had set. Comparing the values +// before and after the tool is what tells a resync from a reset. +type widgetValueChange struct { + Document string // the unit's Name (a page, snippet or layout) + Widget string // the widget's Name + Properties []string // property keys, sorted +} + +func (c widgetValueChange) String() string { + return fmt.Sprintf("%s on '%s' (%s)", strings.Join(c.Properties, ", "), c.Widget, c.Document) +} + +// widgetValues are a project's pluggable widget property values: widget → +// property key → the value in a form that ignores $IDs and pointers. +type widgetValues map[widgetRef]map[string]string + +type widgetRef struct{ unit, document, widget string } + +// widgetPropertyValues reads every CustomWidgets$CustomWidget in the units. +func widgetPropertyValues(units map[string]harvestedUnit) widgetValues { + out := widgetValues{} + for id, u := range units { + if !bytes.Contains(u.contents, []byte("CustomWidgets$CustomWidget")) { + continue + } + var doc bson.D + if err := bson.Unmarshal(u.contents, &doc); err != nil { + continue + } + name, _ := docString(doc, "Name") + walkDocs(doc, func(d bson.D) { + if t, _ := docString(d, "$Type"); t != "CustomWidgets$CustomWidget" { + return + } + w, _ := docString(d, "Name") + out[widgetRef{unit: id, document: name, widget: w}] = customWidgetValues(d) + }) + } + return out +} + +// customWidgetValues maps each property of the widget's object to its value, +// by the property key its TypePointer names in the widget's own type. +func customWidgetValues(w bson.D) map[string]string { + keys := map[string]string{} + if typ, ok := docField(w, "Type").(bson.D); ok { + walkDocs(typ, func(d bson.D) { + if t, _ := docString(d, "$Type"); t != "CustomWidgets$WidgetPropertyType" { + return + } + if k, ok := docString(d, "PropertyKey"); ok { + keys[binaryKey(docField(d, "$ID"))] = k + } + }) + } + vals := map[string]string{} + obj, _ := docField(w, "Object").(bson.D) + for _, p := range docArray(obj, "Properties") { + pd, ok := p.(bson.D) + if !ok { + continue + } + key := keys[binaryKey(docField(pd, "TypePointer"))] + if key == "" { + continue + } + vals[key] = canonicalValue(docField(pd, "Value")) + } + return vals +} + +// widgetValueChanges lists the widgets whose property values differ, in a +// stable order. A widget or property that exists on one side only is not a +// value change and is not listed. +func widgetValueChanges(before, after widgetValues) []widgetValueChange { + var out []widgetValueChange + for ref, bv := range before { + av, ok := after[ref] + if !ok { + continue + } + var props []string + for k, v := range bv { + if a, ok := av[k]; ok && a != v { + props = append(props, k) + } + } + if len(props) == 0 { + continue + } + sort.Strings(props) + out = append(out, widgetValueChange{Document: ref.document, Widget: ref.widget, Properties: props}) + } + sort.Slice(out, func(i, j int) bool { + if out[i].Document != out[j].Document { + return out[i].Document < out[j].Document + } + return out[i].Widget < out[j].Widget + }) + return out +} + +// canonicalValue renders a value without the parts every re-save renews: +// $IDs, binary fields (pointers to other elements, by $ID), and key order — +// update-widgets writes a DataSource's keys sorted where Studio Pro does not, +// which listed 24 of mxchess's widgets as changed when no value was (11.15.0). +func canonicalValue(v any) string { + b, err := bson.MarshalExtJSON(bson.D{{Key: "v", Value: stripIdentity(v)}}, true, false) + if err != nil { + return fmt.Sprint(v) + } + return string(b) +} + +func stripIdentity(v any) any { + switch t := v.(type) { + case bson.D: + out := bson.D{} + for _, e := range t { + if e.Key == "$ID" { + continue + } + if _, isBin := e.Value.(bson.Binary); isBin { + continue + } + out = append(out, bson.E{Key: e.Key, Value: stripIdentity(e.Value)}) + } + sort.Slice(out, func(i, j int) bool { return out[i].Key < out[j].Key }) + return out + case bson.A: + out := bson.A{} + for _, e := range t { + out = append(out, stripIdentity(e)) + } + return out + } + return v +} + +func walkDocs(v any, fn func(bson.D)) { + switch t := v.(type) { + case bson.D: + fn(t) + for _, e := range t { + walkDocs(e.Value, fn) + } + case bson.A: + for _, e := range t { + walkDocs(e, fn) + } + } +} + +func docField(d bson.D, key string) any { + for _, e := range d { + if e.Key == key { + return e.Value + } + } + return nil +} + +func docString(d bson.D, key string) (string, bool) { + s, ok := docField(d, key).(string) + return s, ok +} + +func docArray(d bson.D, key string) bson.A { + a, _ := docField(d, key).(bson.A) + return a +} + +func binaryKey(v any) string { + if b, ok := v.(bson.Binary); ok { + return string(b.Data) + } + return "" +} diff --git a/cmd/mxcli/docker/widget_values_2507_test.go b/cmd/mxcli/docker/widget_values_2507_test.go new file mode 100644 index 0000000000..c1ac57c561 --- /dev/null +++ b/cmd/mxcli/docker/widget_values_2507_test.go @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: Apache-2.0 + +package docker + +import ( + "testing" + + "go.mongodb.org/mongo-driver/v2/bson" +) + +// ako/mxcli#2507: a CE0463 caused by a script value in a property the widget's +// editorConfig hides was labelled "stale widget definition — `mxcli fix +// widgets` fixes it". update-widgets clears it by resetting the property to +// its default, so the value the script set is dropped without a word. The +// widgets are compared before and after, by property key. + +func id2507(b byte) bson.Binary { + return bson.Binary{Subtype: 0, Data: []byte{b, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, b}} +} + +// chessBoard2507 is a CustomWidgets$CustomWidget named name whose +// showNotationInput and notationLanguage hold the given values. +func chessBoard2507(name, showInput, language string) bson.D { + propType := func(pid byte, key string) bson.D { + return bson.D{{Key: "$ID", Value: id2507(pid)}, {Key: "$Type", Value: "CustomWidgets$WidgetPropertyType"}, {Key: "PropertyKey", Value: key}} + } + prop := func(vid, pid byte, primitive string) bson.D { + return bson.D{{Key: "$ID", Value: id2507(vid)}, {Key: "$Type", Value: "CustomWidgets$WidgetProperty"}, + {Key: "TypePointer", Value: id2507(pid)}, + {Key: "Value", Value: bson.D{{Key: "$ID", Value: id2507(vid + 100)}, {Key: "$Type", Value: "CustomWidgets$WidgetValue"}, + {Key: "PrimitiveValue", Value: primitive}}}} + } + return bson.D{ + {Key: "$ID", Value: id2507(1)}, {Key: "$Type", Value: "CustomWidgets$CustomWidget"}, {Key: "Name", Value: name}, + {Key: "Type", Value: bson.D{{Key: "$Type", Value: "CustomWidgets$CustomWidgetType"}, + {Key: "ObjectType", Value: bson.D{{Key: "$Type", Value: "CustomWidgets$WidgetObjectType"}, + {Key: "PropertyTypes", Value: bson.A{int32(2), propType(10, "showNotationInput"), propType(11, "notationLanguage"), propType(12, "fen")}}}}}}, + {Key: "Object", Value: bson.D{{Key: "$Type", Value: "CustomWidgets$WidgetObject"}, + {Key: "Properties", Value: bson.A{int32(2), prop(20, 10, showInput), prop(21, 11, language), prop(22, 12, "FEN")}}}}, + } +} + +func page2507(t *testing.T, widgets ...bson.D) harvestedUnit { + t.Helper() + items := bson.A{int32(2)} + for _, w := range widgets { + items = append(items, w) + } + raw, err := bson.Marshal(bson.D{{Key: "$Type", Value: "Forms$Page"}, {Key: "Name", Value: "Settings_Edit"}, {Key: "Widgets", Value: items}}) + if err != nil { + t.Fatal(err) + } + return harvestedUnit{contents: raw, unitType: "Forms$Page"} +} + +func TestWidgetValueChangesNameTheResetProperties_2507(t *testing.T) { + before := map[string]harvestedUnit{"p": page2507(t, chessBoard2507("previewBoard", "false", "nl"), chessBoard2507("mainBoard", "true", "en"))} + // update-widgets resets the hidden properties on previewBoard only, and + // renumbers every $ID (which is no value change). + afterBoard := chessBoard2507("previewBoard", "true", "en") + afterBoard[0].Value = id2507(99) + after := map[string]harvestedUnit{"p": page2507(t, afterBoard, chessBoard2507("mainBoard", "true", "en"))} + + got := widgetValueChanges(widgetPropertyValues(before), widgetPropertyValues(after)) + if len(got) != 1 || got[0].Widget != "previewBoard" || got[0].Document != "Settings_Edit" { + t.Fatalf("changes = %+v, want previewBoard only", got) + } + if len(got[0].Properties) != 2 || got[0].Properties[0] != "notationLanguage" || got[0].Properties[1] != "showNotationInput" { + t.Errorf("properties = %v, want notationLanguage, showNotationInput", got[0].Properties) + } + // Control: the same project before and after changes nothing. + if c := widgetValueChanges(widgetPropertyValues(before), widgetPropertyValues(before)); len(c) != 0 { + t.Errorf("unchanged project reports %+v", c) + } +} + +// update-widgets re-saves values with their keys sorted (a DataGrid2's +// DataSource, measured on mxchess with 11.15.0): the same value, not a reset. +func TestKeyOrderIsNoValueChange_2507(t *testing.T) { + a := bson.D{{Key: "$Type", Value: "Forms$DataViewSource"}, {Key: "ForceFullObjects", Value: false}, {Key: "EntityRef", Value: "M.E"}} + b := bson.D{{Key: "$Type", Value: "Forms$DataViewSource"}, {Key: "EntityRef", Value: "M.E"}, {Key: "ForceFullObjects", Value: false}} + if canonicalValue(a) != canonicalValue(b) { + t.Errorf("key order made a change:\n%s\n%s", canonicalValue(a), canonicalValue(b)) + } + // Control: a different value is still one. + c := bson.D{{Key: "$Type", Value: "Forms$DataViewSource"}, {Key: "EntityRef", Value: "M.Other"}, {Key: "ForceFullObjects", Value: false}} + if canonicalValue(a) == canonicalValue(c) { + t.Error("a different entity is no change") + } +} + +func TestCE0463WidgetName_2507(t *testing.T) { + for at, want := range map[string]string{ + "Chess Board 'previewBoard'": "previewBoard", + "Data grid 2 'dgOrders'": "dgOrders", + "Page 'Home'": "Home", + "somewhere": "", + } { + if got := ce0463WidgetName(at); got != want { + t.Errorf("%q: %q, want %q", at, got, want) + } + } +} diff --git a/docs-site/src/tools/docker-check.md b/docs-site/src/tools/docker-check.md index 19e26a13d1..48e8720ecc 100644 --- a/docs-site/src/tools/docker-check.md +++ b/docs-site/src/tools/docker-check.md @@ -62,6 +62,7 @@ CE0463 of the stored project: | Label | Meaning | Fix | |---|---|---| | `` stale widget definition — `mxcli fix widgets` fixes it `` | the resync clears it | `mxcli fix widgets -p app.mpr` updates the project's widgets and keeps MPR v2 | +| `a value in a property the widget hides — update-widgets clears it by resetting ` | the resync clears it by replacing values the project set with the widget's defaults: properties its editorConfig hides for the values given. The widget's type is unchanged. | not `fix widgets`, which drops the values and leaves a script that sets them to bring the error back: leave the properties out of the script, or change the values that hide them. `mxcli widget describe` says when it could not read the widget's hide rules. | | `persists after update-widgets` | the resync does not clear it: something in the stored widget is wrong in a way a resync does not repair (if mxcli wrote the widget, that is an mxcli defect worth reporting) | not a resync; see [Pluggable Widgets](../guides/pluggable-widgets.md) | The verdict and the exit status are always the stored project's. The re-check From 5bdaf4ac5bb158447e8f6c44c3d81565c1465b12 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 09:12:06 +0000 Subject: [PATCH 17/18] Refuse to replace a native bottom bar holding items mxcli cannot restate mendixlabs/mxcli#1912 lets a menu clause write a native profile's bottom bar. It replaces BottomBarItems whole, with items of four keys pinned against one configured fixture, so a stored item with any other key, a non-glyph icon or another $Type would lose it silently. Such a bar is now refused with what it holds; an empty bar, or one of pinned-shape items, is replaced as before. Also moves the NativePhone CHANGELOG entry from the released 0.21.0 section, where the branch's September base put it, to Unreleased, and drops its commit SHAs, which do not exist in this history. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QiMsnXa9crge2qnSk9S7Zn --- CHANGELOG.md | 22 +------ .../navigation_bottombar_guard_test.go | 65 +++++++++++++++++++ mdl/backend/modelsdk/navigation_write.go | 37 +++++++++++ 3 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 mdl/backend/modelsdk/navigation_bottombar_guard_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 30c65a8eee..2b336867cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Not the fix, recorded because it looks like one: pinning the pool to a single connection also makes the catalog one database and **deadlocks**. The readers nest — `Entities()` yields from an open cursor while the loop body calls `AttributesFor()` — so the inner read waits forever for the connection the outer cursor holds, and a lint run that took seconds hung past 600s. ### Added +- **`create navigation NativePhone`, with its bottom bar** (mendixlabs/mxcli#1912) — a native profile (`Navigation$NativeNavigationProfile`, which has no `Kind`) can now be created, and the profile's `{ }` block writes its bottom bar (`NativePages$BottomBarItem`), so a home page whose layout needs a bottom bar no longer stops at **CE6108**. The bottom bar is flat and page-only: a nested group or an `OnClick` other than `show page` is refused. An icon is a glyph (`Icon: glyph `, `Forms$GlyphIcon`); a collection or image icon is refused. The shape is pinned against one Studio Pro-authored NativePhone profile (see `newNativeProfileBson`), so replacing a stored bottom bar is refused when one of its items holds anything else — another type, a key mxcli does not write, a non-glyph icon — instead of dropping it. Hybrid profiles remain unsupported. - **`alter published rest service … add operation in resource '' { … }` and `drop operation [''] in resource ''`** (ako/mxcli#2449, mendixlabs/mxcli#1903) — one operation of a stored resource, written as `create` writes it, added or removed without restating the service; the resource's other operations, and everything MDL cannot spell about them, are written back as stored. An operation the resource already has, or a resource it does not have, is refused by check and exec. - **A business event message's operations are its children, and one message can both publish and subscribe** (ako/mxcli#2490) — `message X (…) { publish (Entity: M.P); subscribe (Entity: M.C, Microflow: M.H); };` writes one message with both flags and two operations; a consumed service's subscription is `consume X (Entity: …, Microflow: …);`. Declaring a message twice, once per operation (the only way before), stored two messages of one name and the deployment failed ("An item with the same key has already been added"); `check` and `exec` now refuse it. The keyword clauses `publish entity … microflow …` and `consume X entity … microflow …` still parse as deprecated aliases (MDL-DEPR075, MDL-DEPR076), and `fmt --upgrade` rewrites them. @@ -1858,27 +1859,6 @@ Headline: **Widgets become first-class MDL rather than a second dialect.** Every - **`make digest-status` measures how far the bug-pattern digest has fallen behind**, per area — coverage is computed rather than quoted, because a figure written into prose is stale the next time anyone appends a finding. -- **`create navigation NativePhone`** — the native counterpart to web navigation - profile creation (`f2e7c67a`, `b032ec05`). A native profile has no `Kind` - property at all (`Navigation$NativeNavigationProfile`, identified purely by - `$Type` + `Name`), so it gets its own builder rather than a branch in the web - one. Unlike the web kinds, no live Studio Pro create-and-read-back exists for - native profiles (PED/MCP explicitly rejects native profile authoring), so the - shape is pinned against a real Studio-Pro-authored NativePhone profile instead - — see the doc comment on `newNativeProfileBson`. `UpdateNavigationProfile` - now writes bottom bar menu items too (`NativePages$BottomBarItem`), reusing - the profile's `{ }` block as the web kinds do — so a home page whose layout - requires a bottom bar can be added to it directly, clearing **CE6108** - instead of needing Studio Pro. The native bottom bar is flat and page-only, - unlike the web `Menu`: a nested `MENU 'caption' { … }` group or an `OnClick` - other than `SHOW PAGE` is rejected rather than guessed at. Its icon is a - numeric glyph code — `Icon: glyph ` — round-tripping through - `Forms$GlyphIcon`, the one shape confirmed against a real Studio-Pro-authored - NativePhone profile; a collection or image icon (`Forms$IconCollectionIcon`/ - `Forms$ImageIcon`) remains unconfirmed for a native item and is rejected — - see the doc comment on `navBottomBarItemBson`. Hybrid remains unsupported — - no reference document exists for it either. - ### Changed - **A generated domain model is laid out, not stacked in one row** — every `CREATE ENTITY` with no `@Position` used the same *y*, so a 40-entity model opened in Studio Pro as a single horizontal line 6,950px wide with the boxes overlapping, since the 150px step is narrower than an entity box. Unreadable at any zoom (reported against a 40-entity model on 11.13). diff --git a/mdl/backend/modelsdk/navigation_bottombar_guard_test.go b/mdl/backend/modelsdk/navigation_bottombar_guard_test.go new file mode 100644 index 0000000000..736e0d5276 --- /dev/null +++ b/mdl/backend/modelsdk/navigation_bottombar_guard_test.go @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: Apache-2.0 + +package modelsdkbackend + +import ( + "strings" + "testing" + + "go.mongodb.org/mongo-driver/v2/bson" + + "github.com/mendixlabs/mxcli/mdl/types" +) + +// A menu clause replaces a native profile's bottom bar whole. Its item shape is +// pinned against one configured fixture, so a stored item carrying anything +// else is refused rather than rewritten without it (integration of +// mendixlabs/mxcli#1912). +func TestNavPatchNativeProfile_RefusesABottomBarItCannotRestate(t *testing.T) { + pinned := func(extra ...bson.E) bson.D { + return append(bson.D{ + {Key: "$ID", Value: navID()}, + {Key: "$Type", Value: "NativePages$BottomBarItem"}, + {Key: "Caption", Value: navBottomBarCaptionBson("Home")}, + {Key: "Icon", Value: bson.D{{Key: "$Type", Value: "Forms$GlyphIcon"}, {Key: "Code", Value: int32(57377)}}}, + {Key: "Page", Value: "M.Home"}, + }, extra...) + } + profile := func(items ...bson.D) bson.D { + bar := bson.A{int32(2)} + for _, it := range items { + bar = append(bar, it) + } + return bson.D{{Key: "$Type", Value: "Navigation$NativeNavigationProfile"}, {Key: "Name", Value: "NativePhone"}, + {Key: "BottomBarItems", Value: bar}} + } + spec := types.NavigationProfileSpec{HasMenu: true, + MenuItems: []types.NavMenuItemSpec{{Caption: "Orders", Page: "M.Orders"}}} + + for _, c := range []struct { + name string + doc bson.D + want string + }{ + {"an unwritten key", profile(pinned(bson.E{Key: "Visible", Value: true})), `"Visible"`}, + {"an image icon", profile(bson.D{{Key: "$ID", Value: navID()}, {Key: "$Type", Value: "NativePages$BottomBarItem"}, + {Key: "Icon", Value: bson.D{{Key: "$Type", Value: "Forms$ImageIcon"}}}, {Key: "Page", Value: "M.Home"}}), "Forms$ImageIcon"}, + {"another item type", profile(bson.D{{Key: "$Type", Value: "NativePages$SomethingElse"}}), "NativePages$SomethingElse"}, + } { + if _, err := navPatchNativeProfile(c.doc, spec); err == nil || !strings.Contains(err.Error(), c.want) { + t.Errorf("%s: want a refusal naming %s, got %v", c.name, c.want, err) + } + } + + // Controls: an empty bottom bar and one of pinned-shape items are replaced. + for _, doc := range []bson.D{profile(), profile(pinned())} { + got, err := navPatchNativeProfile(doc, spec) + if err != nil { + t.Fatalf("refused a bottom bar it can restate: %v", err) + } + bar := navGetArray(got, "BottomBarItems") + if len(bar) != 2 || navGetString(bar[1].(bson.D), "Page") != "M.Orders" { + t.Errorf("bottom bar not replaced as the statement says: %v", bar) + } + } +} diff --git a/mdl/backend/modelsdk/navigation_write.go b/mdl/backend/modelsdk/navigation_write.go index 8172389cc6..823bbe18ce 100644 --- a/mdl/backend/modelsdk/navigation_write.go +++ b/mdl/backend/modelsdk/navigation_write.go @@ -381,6 +381,9 @@ func navPatchNativeProfile(doc bson.D, spec types.NavigationProfileSpec) (bson.D navOfflineConfigs(navGetArray(doc, "OfflineEntityConfigs"), spec.OfflineEntities)) } if spec.HasMenu { + if err := navRefuseUnwritableBottomBar(navGetArray(doc, "BottomBarItems")); err != nil { + return nil, err + } barItems := bson.A{int32(2)} for _, mi := range spec.MenuItems { bar, err := navBottomBarItemBson(mi) @@ -394,6 +397,40 @@ func navPatchNativeProfile(doc bson.D, spec types.NavigationProfileSpec) (bson.D return doc, nil } +// navBottomBarItemKeys are the keys navBottomBarItemBson writes. A menu clause +// replaces the stored bottom bar whole, so a stored item that carries anything +// else would lose it in silence. +var navBottomBarItemKeys = map[string]bool{"$ID": true, "$Type": true, "Caption": true, "Icon": true, "Page": true} + +// navRefuseUnwritableBottomBar refuses to replace a stored bottom bar holding an +// item this writer cannot restate: another $Type, a key it does not write, or +// an icon other than a glyph. Its shape was pinned against one configured +// fixture (see navBottomBarItemBson), not against what Studio Pro stores for +// every item, so an unfamiliar item is refused rather than rewritten without +// what it carries. An empty bottom bar, or one of items in the pinned shape, is +// replaced as the statement says. +func navRefuseUnwritableBottomBar(stored bson.A) error { + for _, el := range stored { + item, ok := el.(bson.D) + if !ok { + continue // the list marker + } + name := navGetString(item, "$Type") + if name != "NativePages$BottomBarItem" { + return fmt.Errorf("the native bottom bar holds a %s, which mxcli cannot write; change the bottom bar in Studio Pro", name) + } + for _, e := range item { + if !navBottomBarItemKeys[e.Key] { + return fmt.Errorf("a native bottom bar item stores %q, which mxcli does not write — replacing the bottom bar would drop it; change the bottom bar in Studio Pro", e.Key) + } + } + if icon := navGetDoc(item, "Icon"); icon != nil && navGetString(icon, "$Type") != "Forms$GlyphIcon" { + return fmt.Errorf("a native bottom bar item has a %s icon, which mxcli cannot write (only a glyph) — replacing the bottom bar would drop it; change the bottom bar in Studio Pro", navGetString(icon, "$Type")) + } + } + return nil +} + // navBottomBarItemBson builds a NativePages$BottomBarItem from a menu item spec. // // Mendix's native bottom bar is flat and page-only — NativePages$BottomBarItem From 54ce4a5b83c8b0e0127b3e427db3bf780ac8443a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 22:51:52 +0000 Subject: [PATCH 18/18] fix(report map): integration ports by outbound clients, name or documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The map flagged any module with an integration artefact — a mapping, a JSON structure, a published or consumed service — as an integration module. So a module that only publishes a calendar feed was one, while Int_HR and Int_Planning, the app's ports to HR and planning, were not: they run on mock adapters and have no client yet. A module is now an integration port when it holds outbound clients (consumed REST, OData or MCP, a database connection, business events), when its name follows a port convention (Int_*, *Connector, *Integration, *Adapter), or when its documentation says so ("Port to …", "Integration with …", "Adapter for …", "Wraps …"). Each says why, on the systems list and the page. An annotation `module:` with status `integration` or `not integration` decides where the conventions do not fit. Publishing an API alone no longer counts: the systems list shows the published service. Fixes ako/mxcli#2505 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011oK82qTgUsRMETmzvjS27w --- ...26-11-21-map-integration-ports-missed.json | 1 + .claude/skills/mendix/report-map/SKILL.md | 23 ++++-- cmd/mxcli/projectreport/softwaremap.go | 70 ++++++++++++++++--- cmd/mxcli/projectreport/softwaremap_page.go | 2 +- cmd/mxcli/projectreport/softwaremap_render.go | 18 ++++- cmd/mxcli/projectreport/softwaremap_test.go | 49 +++++++++++++ 6 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 .claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-map-integration-ports-missed.json diff --git a/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-map-integration-ports-missed.json b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-map-integration-ports-missed.json new file mode 100644 index 0000000000..6de8e22c64 --- /dev/null +++ b/.claude/skills/fix-issue/findings/cmd-mxcli/2026-11-21-map-integration-ports-missed.json @@ -0,0 +1 @@ +{"area": "cmd/mxcli", "date": "2026-11-21", "symptom": "report map flags a module that only publishes a REST feed as an integration module, and misses the app's real integration ports (Int_HR, Int_Planning) because they run on mock adapters with no client yet", "cause": "the integration flag was any integration artefact count (mappings, JSON structures, published and consumed services), and nothing else", "file": "`cmd/mxcli/projectreport/softwaremap.go` (integrationWhy, addIntegrationSystems), `softwaremap_render.go` (applyPurposes)", "insight": "Direction matters: outbound clients make a port, a published API does not. Ports are built against mocks long before the real connection exists, so name and documentation conventions — and an annotation override — are needed to find them early. Saying why each was flagged makes a wrong convention visible", "refs": ["ako/mxcli#2505"], "test": "TestMapRecognisesIntegrationPorts"} diff --git a/.claude/skills/mendix/report-map/SKILL.md b/.claude/skills/mendix/report-map/SKILL.md index f1c4462e30..be1ae1b71a 100644 --- a/.claude/skills/mendix/report-map/SKILL.md +++ b/.claude/skills/mendix/report-map/SKILL.md @@ -11,10 +11,10 @@ description: "Produce and use the software map (mxcli report map): one interacti | lines | section | |---|---| | 26-39 | Run it | -| 40-55 | Give each module a purpose | -| 56-76 | The app by feature | -| 77-94 | Reading it — and its traps | -| 95-98 | Related | +| 40-70 | Give each module a purpose | +| 71-91 | The app by feature | +| 92-109 | Reading it — and its traps | +| 110-113 | Related | # Software Map @@ -53,6 +53,21 @@ Better still, put the sentence in the model, so every tool (and Studio Pro) sees `alter module Rooster set documentation 'Builds and publishes the monthly roster.';` Lint rule QUAL002 reports app modules that have none. +**Integration ports** are the modules that talk to an outside system. The map flags a +module as one when it holds outbound clients (consumed REST, OData or MCP, a database +connection, business events), when its name follows a port convention (`Int_*`, +`*Connector`, `*Integration`, `*Adapter`), or when its documentation starts "Port to …", +"Integration with …", "Adapter for …" or "Wraps …". The last two find a port built +against a mock before its real connection exists. Each flagged module says which. +Publishing an API does not make a module an integration: the systems list shows the +published service, whose clients are outside. Where the conventions do not fit: + +```yaml +items: + "module:Legacy": {status: integration, note: "Wraps the old mainframe."} + "module:Int_Tools": {status: not integration} +``` + ## The app by feature With a project brain that has a plan (`docs/brain/plan/`), the map adds a diff --git a/cmd/mxcli/projectreport/softwaremap.go b/cmd/mxcli/projectreport/softwaremap.go index 581f4d292f..05be29b7f5 100644 --- a/cmd/mxcli/projectreport/softwaremap.go +++ b/cmd/mxcli/projectreport/softwaremap.go @@ -56,7 +56,10 @@ type MapModule struct { Purpose string `json:"purpose,omitempty"` Counts map[string]int `json:"counts"` Integration bool `json:"integration,omitempty"` - EntryPoints map[string]int `json:"entryPoints"` + // IntegrationWhy says what made it an integration port: its outbound + // clients, its name or its documentation (ako/mxcli#2505). + IntegrationWhy string `json:"integrationWhy,omitempty"` + EntryPoints map[string]int `json:"entryPoints"` } // MapEdge is module → module references, split by class. @@ -269,14 +272,13 @@ func CollectMap(q Querier, opt ScopeOptions, purposes map[string]string) (*MapDa if c == nil { c = map[string]int{} } - integ := c["import_mapping"] + c["export_mapping"] + c["consumed_rest_service"] + c["published_rest_service"] + - c["consumed_odata_service"] + c["published_odata_service"] + c["json_structure"] + c["business_event_service"] p := purpose[m] if v := purposes[m]; v != "" { p = v } + why := integrationWhy(m, c, p) modIdx[m] = len(d.Modules) - d.Modules = append(d.Modules, MapModule{Name: m, Purpose: firstSentence(p), Counts: c, Integration: integ > 0, EntryPoints: map[string]int{}}) + d.Modules = append(d.Modules, MapModule{Name: m, Purpose: firstSentence(p), Counts: c, Integration: why != "", IntegrationWhy: why, EntryPoints: map[string]int{}}) } // ---- refs, read once @@ -778,11 +780,7 @@ func collectMapLandscape(q Querier, d *MapData, appList string, flowIdx map[stri d.Systems = append(d.Systems, MapSystem{Kind: "identity", Name: m, Detail: "signs users in"}) } } - for _, m := range d.Modules { - if m.Integration { - d.Systems = append(d.Systems, MapSystem{Kind: "integration module", Name: m.Name}) - } - } + addIntegrationSystems(d) sort.SliceStable(d.Systems, func(i, j int) bool { if d.Systems[i].Kind != d.Systems[j].Kind { return d.Systems[i].Kind < d.Systems[j].Kind @@ -896,3 +894,57 @@ func buildMapIndex(q Querier, d *MapData, refRows []map[string]string, inApp fun } return out } + +var ( + // The naming conventions of integration ports: Int_HR, HRConnector, + // PlanningIntegration, PaymentAdapter. + portName = regexp.MustCompile(`(?i)^int_|(connector|integration|adapter)$`) + // Documentation that says the module is a port (#2305's module purpose). + portDoc = regexp.MustCompile(`(?i)^\s*(port (to|for)|integration (with|to|for)|adapter (to|for)|connector (to|for)|interface to|wraps )`) +) + +// integrationWhy says why a module is an integration port, "" when it is not. +// A port is a module that talks to an outside system: by its outbound clients, +// or — built against a mock before the real connection exists — by its name or +// its documentation. Publishing an API is not being an integration module: the +// module's clients are outside, and the systems list shows the service +// (ako/mxcli#2505). +func integrationWhy(name string, c map[string]int, purpose string) string { + var out []string + for _, k := range []struct{ key, label string }{ + {"consumed_rest_service", "consumed REST"}, {"consumed_odata_service", "consumed OData"}, + {"database_connection", "database connection"}, {"business_event_service", "business events"}, + {"consumed_mcp_service", "consumed MCP"}, + } { + if n := c[k.key]; n > 0 { + out = append(out, fmt.Sprintf("%d %s", n, k.label)) + } + } + if len(out) > 0 { + return "holds outbound clients: " + strings.Join(out, ", ") + } + switch { + case portName.MatchString(name): + return "named as an integration port" + case portDoc.MatchString(purpose): + return "documented as a port" + } + return "" +} + +// addIntegrationSystems lists the integration modules among the systems, +// replacing any listed before (an annotation can change the flags). +func addIntegrationSystems(d *MapData) { + kept := d.Systems[:0] + for _, s := range d.Systems { + if s.Kind != "integration module" { + kept = append(kept, s) + } + } + d.Systems = kept + for _, m := range d.Modules { + if m.Integration { + d.Systems = append(d.Systems, MapSystem{Kind: "integration module", Name: m.Name, Detail: m.IntegrationWhy}) + } + } +} diff --git a/cmd/mxcli/projectreport/softwaremap_page.go b/cmd/mxcli/projectreport/softwaremap_page.go index 1a3d952978..c4f71fe894 100644 --- a/cmd/mxcli/projectreport/softwaremap_page.go +++ b/cmd/mxcli/projectreport/softwaremap_page.go @@ -154,7 +154,7 @@ V.modules=function(){ h+=h2('Modules'); h+=table(['Module','Purpose','Entities','Flows','Pages','Entry points'],D.modules.map(function(m){ var eps=P.entryKinds.filter(function(k){return m.entryPoints[k];}).map(function(k){return ''+esc(k)+' '+m.entryPoints[k]+'';}).join(''); - return [''+esc(m.name)+''+(m.integration?' integration':''),esc(m.purpose||''), + return [''+esc(m.name)+''+(m.integration?' integration':''),esc(m.purpose||''), m.counts.entity||0,(m.counts.microflow||0)+(m.counts.nanoflow||0),m.counts.page||0,eps];})); return h; }; diff --git a/cmd/mxcli/projectreport/softwaremap_render.go b/cmd/mxcli/projectreport/softwaremap_render.go index 1f3dae2d01..f5ab8fa50a 100644 --- a/cmd/mxcli/projectreport/softwaremap_render.go +++ b/cmd/mxcli/projectreport/softwaremap_render.go @@ -31,10 +31,26 @@ var MapLimits = []string{ // applyPurposes copies annotation notes keyed module: onto modules that // have no purpose of their own, or that the person wants to overrule. func applyPurposes(d *MapData, ann *Annotations) { + changed := false for i := range d.Modules { - if n, ok := ann.Get("module:" + d.Modules[i].Name); ok && n.Note != "" { + n, ok := ann.Get("module:" + d.Modules[i].Name) + if !ok { + continue + } + if n.Note != "" { d.Modules[i].Purpose = n.Note } + // status integration / not integration decides when the conventions + // do not fit (ako/mxcli#2505). + switch strings.ToLower(n.Status) { + case "integration": + d.Modules[i].Integration, d.Modules[i].IntegrationWhy, changed = true, "annotated", true + case "not integration": + d.Modules[i].Integration, d.Modules[i].IntegrationWhy, changed = false, "", true + } + } + if changed { + addIntegrationSystems(d) } } diff --git a/cmd/mxcli/projectreport/softwaremap_test.go b/cmd/mxcli/projectreport/softwaremap_test.go index b0083aac41..7d11a01507 100644 --- a/cmd/mxcli/projectreport/softwaremap_test.go +++ b/cmd/mxcli/projectreport/softwaremap_test.go @@ -184,3 +184,52 @@ func TestSoftwareMap(t *testing.T) { _ = RenderMarkdown(&md, doc) mustContain(t, md.String(), "| constant | `OIDC.ProvisioningMicroflow` | `Core.SSO_Provision` |", "Sales → Core", "Back office") } + +// An integration port is a module that talks to an outside system: by its +// outbound clients, its name (Int_*, *Connector, *Integration, *Adapter) or +// its documentation ("Port to …"), so a port built against a mock is found +// before the real connection exists. Publishing an API is not being an +// integration module: that module's clients are outside (ako/mxcli#2505). +func TestMapRecognisesIntegrationPorts(t *testing.T) { + f := newFixture(t) + for _, m := range []string{"Int_HR", "PlanningPort", "Billing", "Agenda", "Orders", "Legacy"} { + f.module(m, "") + } + f.exec(`INSERT INTO rest_clients_data (Id, Name, QualifiedName, ModuleName) VALUES ('rc', 'Payments', 'Billing.Payments', 'Billing')`) + f.exec(`INSERT INTO published_rest_services_data (Id, Name, QualifiedName, ModuleName, Path) VALUES ('ps', 'PRS_Agenda', 'Agenda.PRS_Agenda', 'Agenda', 'rest/agenda/v1')`) + d, err := CollectMap(f.cat, ScopeOptions{}, map[string]string{"PlanningPort": "Port to the planning system, mocked for now."}) + if err != nil { + t.Fatal(err) + } + why := map[string]string{} + integ := map[string]bool{} + for _, m := range d.Modules { + integ[m.Name], why[m.Name] = m.Integration, m.IntegrationWhy + } + for m, want := range map[string]bool{"Int_HR": true, "PlanningPort": true, "Billing": true, "Agenda": false, "Orders": false} { + if integ[m] != want { + t.Errorf("%s integration = %v, want %v (%q)", m, integ[m], want, why[m]) + } + } + for m, frag := range map[string]string{"Int_HR": "named", "PlanningPort": "documented", "Billing": "consumed REST"} { + if !strings.Contains(why[m], frag) { + t.Errorf("%s: why = %q, want it to say %q", m, why[m], frag) + } + } + // An annotation decides when the conventions do not fit. + env, _ := NewEnvelope("map", "App", "now", "test", d, MapMethod, MapLimits, nil) + doc, err := RenderMap(env, &Annotations{Items: map[string]Note{ + "module:Legacy": {Status: "integration", Note: "Wraps the old mainframe."}, + "module:Int_HR": {Status: "not integration"}, + }}) + if err != nil { + t.Fatal(err) + } + var md bytes.Buffer + _ = RenderMarkdown(&md, doc) + out := md.String() + if !strings.Contains(out, "| integration module | `Legacy` | annotated |") || strings.Contains(out, "| integration module | `Int_HR` |") || + strings.Contains(out, "| integration module | `Agenda` |") { + t.Errorf("annotations set and clear the integration flag, and a published-only module is not one:\n%s", out) + } +}