@@ -7,6 +7,7 @@ package mprbackend
77
88import (
99 "errors"
10+ "reflect"
1011 "testing"
1112
1213 "github.com/mendixlabs/mxcli/mdl/types"
@@ -492,7 +493,9 @@ func TestUnconvertNavMenuItemSpec_Isolated(t *testing.T) {
492493 {Caption : "Child" , Microflow : "MF2" },
493494 },
494495 }
495- out := unconvertNavMenuItemSpec (in )
496+ // Since mpr.NavMenuItemSpec is aliased to types.NavMenuItemSpec,
497+ // unconvert is now a pass-through. Verify the alias holds.
498+ var out mpr.NavMenuItemSpec = in
496499 if out .Caption != "Parent" || out .Page != "Page1" || out .Microflow != "MF1" {
497500 t .Errorf ("field mismatch: %+v" , out )
498501 }
@@ -503,7 +506,7 @@ func TestUnconvertNavMenuItemSpec_Isolated(t *testing.T) {
503506
504507func TestUnconvertNavMenuItemSpec_NilItems (t * testing.T ) {
505508 in := types.NavMenuItemSpec {Caption : "Leaf" }
506- out := unconvertNavMenuItemSpec ( in )
509+ var out mpr. NavMenuItemSpec = in
507510 if out .Items != nil {
508511 t .Errorf ("expected nil Items for leaf: %+v" , out .Items )
509512 }
@@ -598,3 +601,51 @@ func TestUnconvertImageCollection(t *testing.T) {
598601 }
599602}
600603
604+ // ============================================================================
605+ // Field-count drift assertions
606+ // ============================================================================
607+ //
608+ // These tests catch silent field drift: if a struct gains a new field but
609+ // the convert/unconvert function is not updated, the test fails.
610+
611+ func assertFieldCount (t * testing.T , name string , v any , expected int ) {
612+ t .Helper ()
613+ actual := reflect .TypeOf (v ).NumField ()
614+ if actual != expected {
615+ t .Errorf ("%s field count changed: expected %d, got %d — update convert.go and this test" , name , expected , actual )
616+ }
617+ }
618+
619+ func TestFieldCountDrift (t * testing.T ) {
620+ // mpr → types pairs (manually copied in convert.go).
621+ // If a struct gains a field, update the convert function AND this count.
622+ assertFieldCount (t , "mpr.FolderInfo" , mpr.FolderInfo {}, 3 )
623+ assertFieldCount (t , "types.FolderInfo" , types.FolderInfo {}, 3 )
624+ assertFieldCount (t , "mpr.UnitInfo" , mpr.UnitInfo {}, 4 )
625+ assertFieldCount (t , "types.UnitInfo" , types.UnitInfo {}, 4 )
626+ assertFieldCount (t , "mpr.RenameHit" , mpr.RenameHit {}, 4 )
627+ assertFieldCount (t , "types.RenameHit" , types.RenameHit {}, 4 )
628+ assertFieldCount (t , "mpr.RawUnit" , mpr.RawUnit {}, 4 )
629+ assertFieldCount (t , "types.RawUnit" , types.RawUnit {}, 4 )
630+ assertFieldCount (t , "mpr.RawUnitInfo" , mpr.RawUnitInfo {}, 5 )
631+ assertFieldCount (t , "types.RawUnitInfo" , types.RawUnitInfo {}, 5 )
632+ assertFieldCount (t , "mpr.RawCustomWidgetType" , mpr.RawCustomWidgetType {}, 6 )
633+ assertFieldCount (t , "types.RawCustomWidgetType" , types.RawCustomWidgetType {}, 6 )
634+ assertFieldCount (t , "mpr.JavaAction" , mpr.JavaAction {}, 4 )
635+ assertFieldCount (t , "types.JavaAction" , types.JavaAction {}, 4 )
636+ assertFieldCount (t , "mpr.JavaScriptAction" , mpr.JavaScriptAction {}, 12 )
637+ assertFieldCount (t , "types.JavaScriptAction" , types.JavaScriptAction {}, 12 )
638+ assertFieldCount (t , "mpr.NavigationDocument" , mpr.NavigationDocument {}, 4 )
639+ assertFieldCount (t , "types.NavigationDocument" , types.NavigationDocument {}, 4 )
640+ assertFieldCount (t , "mpr.JsonStructure" , mpr.JsonStructure {}, 8 )
641+ assertFieldCount (t , "types.JsonStructure" , types.JsonStructure {}, 8 )
642+ assertFieldCount (t , "mpr.JsonElement" , mpr.JsonElement {}, 14 )
643+ assertFieldCount (t , "types.JsonElement" , types.JsonElement {}, 14 )
644+ assertFieldCount (t , "mpr.ImageCollection" , mpr.ImageCollection {}, 6 )
645+ assertFieldCount (t , "types.ImageCollection" , types.ImageCollection {}, 6 )
646+ assertFieldCount (t , "mpr.EntityMemberAccess" , mpr.EntityMemberAccess {}, 3 )
647+ assertFieldCount (t , "types.EntityMemberAccess" , types.EntityMemberAccess {}, 3 )
648+ assertFieldCount (t , "mpr.EntityAccessRevocation" , mpr.EntityAccessRevocation {}, 6 )
649+ assertFieldCount (t , "types.EntityAccessRevocation" , types.EntityAccessRevocation {}, 6 )
650+ }
651+
0 commit comments