@momo-kits/native-kits 0.169.13-beta.4 → 0.169.13-beta.4-debug

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +202 -0
  3. package/compose/compose.podspec +47 -0
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +647 -0
  12. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +1411 -0
  13. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +130 -0
  14. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +524 -0
  15. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +559 -0
  16. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +741 -0
  17. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +221 -0
  18. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +270 -0
  19. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +849 -0
  20. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +212 -0
  21. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +239 -0
  22. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +252 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +130 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +208 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +315 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +206 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +421 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +750 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +242 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +398 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +400 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
  132. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +154 -0
  133. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +1038 -0
  134. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +848 -0
  135. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +47 -0
  136. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +39 -0
  137. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +463 -0
  138. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +1146 -0
  139. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +667 -0
  140. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +240 -0
  141. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +185 -0
  142. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +200 -0
  143. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  144. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  145. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  146. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -0
  147. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  148. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  149. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  150. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  151. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +65 -0
  152. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
  153. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  154. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +143 -0
  155. package/gradle/libs.versions.toml +69 -0
  156. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  157. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  158. package/gradle.properties +24 -0
  159. package/gradlew +252 -0
  160. package/gradlew.bat +94 -0
  161. package/ios-demo/README.md +120 -0
  162. package/package.json +1 -1
  163. package/scripts/sdui-visual/README.md +64 -0
  164. package/settings.gradle.kts +64 -0
@@ -0,0 +1,252 @@
1
+ // File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt
2
+ // Created At: 2026-10-29 10:30:00 +07:00
3
+ // Created By: AI
4
+ // AI Agent: Claude Code
5
+ // Model: claude-sonnet-5-5
6
+
7
+ package vn.momo.kits.sdui
8
+
9
+ import org.junit.Assert.assertEquals
10
+ import org.junit.Assert.assertNull
11
+ import org.junit.Assert.assertTrue
12
+ import org.junit.Test
13
+ import java.io.File
14
+
15
+ // AI-GENERATED START: unit tests for SduiView's pure part (prepareSduiView) and structure validation
16
+ class SduiViewTest {
17
+ @Test fun errorLogLineCarriesCodeStageAndDetail() {
18
+ assertEquals("[SDUI] block: PARSE parse - spec is not a JSON object", errorLogLine(SduiError("parse", "PARSE", false, "spec is not a JSON object")))
19
+ assertEquals("[SDUI] block: UNSUPPORTED_VERSION validate", errorLogLine(SduiError("validate", "UNSUPPORTED_VERSION", false)))
20
+ }
21
+
22
+ private fun prep(json: String, v: Int = 1) = prepareSduiView(json, v)
23
+ private fun codeOf(r: SduiResult<*>) = (r as SduiResult.Err).error.code
24
+ private fun ok(r: SduiResult<PreparedView>) = (r as SduiResult.Ok).value
25
+
26
+ private val body = """{"type":"View","children":[{"type":"Text","props":{"children":"x"}}]}"""
27
+ private fun spec(meta: String = """{"screenName":"S"}""", extra: String = "") = """{"meta":$meta,"body":$body$extra}"""
28
+
29
+ // ---- error codes -----------------------------------------------------------------------------------------------
30
+ @Test fun tooLargeIsRejectedBeforeParsing() {
31
+ assertEquals(ErrorCode.PAYLOAD_TOO_LARGE, codeOf(prep(" ".repeat(MAX_PAYLOAD_BYTES + 1))))
32
+ // the gate counts UTF-8 bytes, not chars: 3-byte chars overflow earlier
33
+ assertEquals(ErrorCode.PAYLOAD_TOO_LARGE, codeOf(prep("€".repeat(MAX_PAYLOAD_BYTES / 3 + 1))))
34
+ }
35
+
36
+ @Test fun invalidJsonAndNonObjectAreParseErrors() {
37
+ assertEquals(ErrorCode.PARSE, codeOf(prep("{")))
38
+ assertEquals(ErrorCode.PARSE, codeOf(prep("")))
39
+ assertEquals(ErrorCode.PARSE, codeOf(prep("[1,2]")))
40
+ assertEquals(ErrorCode.PARSE, codeOf(prep("\"str\"")))
41
+ }
42
+
43
+ @Test fun minRenderVersionAboveRendererIsUnsupported() {
44
+ assertEquals(ErrorCode.UNSUPPORTED_VERSION, codeOf(prep(spec("""{"minRenderVersion":2}"""))))
45
+ assertTrue(prep(spec("""{"minRenderVersion":1}""")) is SduiResult.Ok)
46
+ assertEquals(ErrorCode.UNSUPPORTED_VERSION, codeOf(prep(spec("""{"minRenderVersion":3}"""), v = 2)))
47
+ }
48
+
49
+ @Test fun modeSectionOrAbsentIsOkScreenIsUnsupportedOtherIsShape() {
50
+ assertTrue(prep(spec("""{"mode":"section"}""")) is SduiResult.Ok)
51
+ assertTrue(prep(spec("""{}""")) is SduiResult.Ok)
52
+ assertEquals(ErrorCode.UNSUPPORTED_MODE, codeOf(prep(spec("""{"mode":"screen"}"""))))
53
+ assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep(spec("""{"mode":"wat"}"""))))
54
+ assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep(spec("""{"mode":5}"""))))
55
+ }
56
+
57
+ @Test fun bodyMustBeANode() {
58
+ assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep("""{"meta":{},"body":{"children":[]}}""")))
59
+ assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep("""{"meta":{},"body":"x"}""")))
60
+ assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep("""{"meta":{}}""")))
61
+ }
62
+
63
+ // ---- shapes ----------------------------------------------------------------------------------------------------
64
+ @Test fun bareSpecIsReadyWithDataAndStateSeed() {
65
+ val v = ok(prep("""{"meta":{"screenName":"Blk"},"data":{"a":1},"state":{"s":true},"body":$body}"""))
66
+ assertEquals("Blk", v.screenName)
67
+ assertEquals(mapOf<String, Any?>("a" to 1L), v.data)
68
+ assertEquals(mapOf<String, Any?>("s" to true), v.initialState)
69
+ assertEquals("View", v.body["type"])
70
+ }
71
+
72
+ @Test fun screenNameIsOptionalAndMetaMayBeAbsent() {
73
+ assertNull(ok(prep("""{"body":$body}""")).screenName)
74
+ assertTrue(ok(prep("""{"body":$body}""")).data.isEmpty())
75
+ }
76
+
77
+ @Test fun envelopeShapedInputIsRejectedAsSpecShape() {
78
+ val events = mutableListOf<String>()
79
+ var errorCode: Any? = null
80
+ val sink = object : TrackSink {
81
+ override val id = "rec"
82
+ override fun write(record: TrackRecord) {
83
+ events += "${record.event.name}:${record.event.step}"
84
+ if (record.event.step == "sdui_error") errorCode = record.event.fields["code"]
85
+ }
86
+ }
87
+ val tracker = Tracker(listOf(sink), "s")
88
+ var label: String? = "unset"
89
+ val r = prepareSduiView("""{"v":1,"status":"ok","spec":${spec()}}""", 1) { name -> label = name; tracker.begin(SessionCtx("sdui:view:block")) }
90
+ assertEquals(ErrorCode.SPEC_SHAPE, codeOf(r))
91
+ assertEquals(null, label) // no top-level meta: the session gets no block name
92
+ assertEquals(ErrorCode.SPEC_SHAPE, errorCode) // tracking reports the same code as onError
93
+ assertEquals(listOf("ops_info_checked:sdui_error"), events.takeLast(1))
94
+ }
95
+
96
+ @Test fun actionTypeIsAllowedAndUnknownTypeIsNotAValidationError() {
97
+ val a = """{"type":"View","actions":[{"name":"onPress","type":"startFeatureCode","params":{"featureCode":"f"}},{"name":"onPress","type":"future"}]}"""
98
+ assertTrue(prep("""{"meta":{},"body":$a}""") is SduiResult.Ok)
99
+ }
100
+
101
+ @Test fun errorsAreReportedToTheSessionOnce() {
102
+ val events = mutableListOf<String>()
103
+ val sink = object : TrackSink {
104
+ override val id = "rec"
105
+ override fun write(record: TrackRecord) { events += "${record.event.name}:${record.event.step}" }
106
+ }
107
+ val tracker = Tracker(listOf(sink), "s")
108
+ var begun = 0
109
+ var session: RenderSession? = null
110
+ prepareSduiView("{", 1) { begun++; tracker.begin(SessionCtx("sdui:view:block")).also { session = it } }
111
+ assertEquals(1, begun)
112
+ assertEquals(listOf("ops_info_checked:sdui_error"), events)
113
+ session!!.mark("render_done") // the failed prepare ended the session: a late step is dropped
114
+ assertEquals(listOf("ops_info_checked:sdui_error"), events)
115
+ }
116
+
117
+ // ---- the bundled blocks must be drawable ---------------------------------------------------------------------------
118
+ @Test fun bundledBlocksPrepareOk() {
119
+ val dir = File("../sample/shared/src/commonMain/composeResources/files/sdui/blocks")
120
+ val files = listOf("buy_insurance", "pay_premium", "community").map { File(dir, "$it.json") }
121
+ files.forEach { assertTrue("missing ${it.absolutePath}", it.exists()) }
122
+ files.forEach { f ->
123
+ val r = prep(f.readText())
124
+ assertTrue("${f.name}: ${(r as? SduiResult.Err)?.error}", r is SduiResult.Ok)
125
+ }
126
+ }
127
+
128
+ private val goodSpec = mapOf(
129
+ "meta" to mapOf("screenName" to "S"),
130
+ "body" to mapOf("type" to "View", "children" to listOf(mapOf("type" to "Text", "props" to mapOf("children" to "x")))),
131
+ )
132
+
133
+ // ---- structure validation ----------------------------------------------------------------------------------------------
134
+ @Test fun structureValidationRejectsBadSpecs() {
135
+ assertTrue(validateStructure(goodSpec).errors.isEmpty())
136
+ assertTrue(validateStructure("x").errors.isNotEmpty())
137
+ assertTrue(validateStructure(goodSpec + ("bogus" to 1L)).errors.any { "unknown top-level key" in it })
138
+ // screen-level keys SduiView would silently drop are rejected
139
+ listOf("header", "footer", "tabs", "onMount", "actions", "overlays", "components", "tracking", "localization").forEach { k ->
140
+ assertTrue(k, validateStructure(goodSpec + (k to emptyMap<String, Any?>())).errors.any { "\"$k\" is not supported in a section" in it })
141
+ }
142
+ assertTrue(validateStructure(goodSpec + ("data" to emptyMap<String, Any?>()) + ("state" to emptyMap<String, Any?>()) + ("\$schema" to "x") + ("__od" to 1L)).errors.isEmpty())
143
+ val noType = goodSpec + ("body" to mapOf("type" to "View", "children" to listOf(mapOf("props" to emptyMap<String, Any?>()))))
144
+ assertTrue(validateStructure(noType).errors.any { "without a \"type\"" in it })
145
+ fun withAction(a: Map<String, Any?>) = goodSpec + ("body" to mapOf("type" to "View", "children" to listOf(mapOf("type" to "View", "actions" to listOf(a)))))
146
+ fun actionErrors(a: Map<String, Any?>) = validateStructure(withAction(a)).errors
147
+ assertTrue(actionErrors(mapOf("name" to "onPress", "set" to mapOf("a" to 1L))).any { "unknown field \"set\"" in it })
148
+ assertTrue(actionErrors(mapOf("name" to "onPress", "navigate" to "push")).any { "unknown field \"navigate\"" in it })
149
+ assertTrue(actionErrors(mapOf("name" to "onPress", "tab" to "t")).any { "unknown field \"tab\"" in it })
150
+ assertTrue(actionErrors(mapOf("name" to "onPress", "params" to mapOf("featureCode" to "f"))).any { "actions[0].type is required" in it })
151
+ assertTrue(actionErrors(mapOf("name" to "onPress", "type" to 5L)).any { "type is required" in it })
152
+ assertTrue(validateStructure(withAction(mapOf("name" to "onPress", "storage" to "get", "key" to "k", "to" to "x"))).errors.any { "unknown field" in it })
153
+ assertTrue(actionErrors(mapOf("name" to "onPress", "type" to "startFeatureCode", "params" to mapOf("featureCode" to "f"))).isEmpty())
154
+ // fields the runtime never reads
155
+ listOf("code", "overlay", "trackOn").forEach { k ->
156
+ assertTrue(k, actionErrors(mapOf("name" to "onPress", "type" to "setState", k to "x")).any { "unknown field \"$k\"" in it })
157
+ }
158
+ }
159
+
160
+ @Test fun structureValidationChecksShapesTheRendererSilentlyIgnores() {
161
+ fun body(vararg kv: Pair<String, Any?>) = goodSpec + ("body" to mapOf("type" to "View", *kv))
162
+ fun child(vararg kv: Pair<String, Any?>) = body("children" to listOf(mapOf("type" to "View", *kv)))
163
+ val press = mapOf("name" to "onPress", "type" to "setState", "params" to mapOf("a" to 1L))
164
+ // actions must be a list
165
+ assertTrue(validateStructure(child("actions" to press)).errors.any { "body.children[0].actions must be a list of actions" in it })
166
+ assertTrue(validateStructure(body("actions" to press)).errors.any { "body.actions must be a list of actions" in it })
167
+ assertTrue(validateStructure(child("actions" to listOf(press))).errors.isEmpty())
168
+ // children must be a list of nodes
169
+ val textChildren = "children must be a list of nodes; put text in props.children"
170
+ assertTrue(validateStructure(child("children" to "hello")).errors.any { "body.children[0].$textChildren" in it })
171
+ assertTrue(validateStructure(body("children" to mapOf("type" to "Text"))).errors.any { "body.$textChildren" in it })
172
+ // repeat: `as` names the item, `item` is not read
173
+ val rep = mapOf("source" to "{xs}", "as" to "x", "index" to "i")
174
+ assertTrue(validateStructure(child("repeat" to rep)).errors.isEmpty())
175
+ assertTrue(validateStructure(child("repeat" to mapOf("source" to "{xs}", "item" to "x"))).errors.any { "unknown field \"item\" at body.children[0].repeat" in it })
176
+ // styles only: a singular `style` is unknown on nodes and on body
177
+ assertTrue(validateStructure(child("styles" to mapOf("flex" to 1L))).errors.isEmpty())
178
+ assertTrue(validateStructure(child("style" to mapOf("flex" to 1L))).errors.any { "unknown field \"style\"" in it })
179
+ assertTrue(validateStructure(body("style" to mapOf("flex" to 1L))).errors.any { "unknown field \"style\" at body" in it })
180
+ // body is drawn once, directly: repeat / visible / visibleWhen / scrollable would be silently ignored, so they are rejected there only
181
+ listOf("repeat" to mapOf("source" to "{xs}", "as" to "x"), "visible" to false, "visibleWhen" to "{a}").forEach { (k, v) ->
182
+ assertEquals(k, listOf("body.$k is not supported: the block body is always drawn once"), validateStructure(body(k to v)).errors)
183
+ assertTrue(k, validateStructure(child(k to v)).errors.isEmpty())
184
+ }
185
+ assertEquals(listOf("unknown field \"scrollable\" at body"), validateStructure(body("scrollable" to true)).errors)
186
+ // meta: stamp / autoShow are not read by SduiView; root (editor marker) / version / description are accepted and ignored
187
+ fun withMeta(k: String) = goodSpec + ("meta" to mapOf(k to true))
188
+ listOf("stamp", "autoShow").forEach { k ->
189
+ assertTrue(k, validateStructure(withMeta(k)).errors.any { "unknown field \"$k\" at meta" in it })
190
+ }
191
+ listOf("root", "version", "description").forEach { k -> assertTrue(k, validateStructure(withMeta(k)).errors.isEmpty()) }
192
+ // nesting depth: 100 levels below body pass, 101 fail with one error
193
+ fun nested(levels: Int): Map<String, Any?> {
194
+ var n: Map<String, Any?> = mapOf("type" to "View")
195
+ repeat(levels - 1) { n = mapOf("type" to "View", "children" to listOf(n)) }
196
+ return n
197
+ }
198
+ assertTrue(validateStructure(body("children" to listOf(nested(100)))).errors.isEmpty())
199
+ val deep = validateStructure(body("children" to listOf(nested(5000)))).errors
200
+ assertEquals(1, deep.count { "spec nested too deeply" in it })
201
+ }
202
+
203
+ // ---- utf8Length / parse timing ---------------------------------------------------------------------------------------
204
+ @Test fun deeplyNestedJsonIsRejectedBeforeParsing() {
205
+ assertEquals(3, jsonNestingDepth("""{"a":[{"b":1}]}"""))
206
+ assertEquals(1, jsonNestingDepth("""{"a":"[[[{{{\"]]]"}""")) // brackets inside strings (and escaped quotes) don't count
207
+ assertEquals(0, jsonNestingDepth("""]]]}}"""))
208
+ // 120k levels fits the size gate but would overflow the parser's stack (fatal on iOS): rejected as PARSE without parsing
209
+ val deep = "[".repeat(120_000) + "]".repeat(120_000)
210
+ assertEquals(ErrorCode.PARSE, codeOf(prep(deep)))
211
+ val ok = """{"meta":{},"body":{"type":"View","props":{"d":""" + "[".repeat(200) + "]".repeat(200) + "}}}"
212
+ assertTrue(prep(ok) is SduiResult.Ok)
213
+ }
214
+
215
+ @Test fun utf8LengthMatchesEncodeToByteArray() {
216
+ val cases = listOf("", "plain ascii {\"a\":1}", "Phí bảo hiểm sức khỏe Việt Nam đ", "emoji \uD83D\uDE00 \uD83C\uDDFB\uD83C\uDDF3 end", "中文 \u20AC")
217
+ cases.forEach { assertEquals(it, it.encodeToByteArray().size, utf8Length(it)) }
218
+ }
219
+
220
+ // An unpaired surrogate counts 3 bytes (U+FFFD, what Kotlin/Native's encoder writes); the JVM encoder writes 1 ('?').
221
+ @Test fun utf8LengthCountsAnUnpairedSurrogateAsThree() {
222
+ assertEquals(3, utf8Length("\uD83D")); assertEquals(3, utf8Length("\uDE00"))
223
+ assertEquals(3 + 1, utf8Length("\uD83Dx")); assertEquals(3 + 3, utf8Length("\uDE00\uD83D"))
224
+ assertEquals(4, utf8Length("\uD83D\uDE00"))
225
+ }
226
+
227
+ @Test fun parseDurationIsMeasuredAroundParsingAndPassedToTheSession() {
228
+ var t = 100L
229
+ val clock = { val v = t; t += 7; v }
230
+ val marks = ArrayList<Triple<String, Map<String, Any?>?, Long?>>()
231
+ val rec = object : RenderSession by RenderSession.NOOP {
232
+ override fun mark(step: String, extra: Map<String, Any?>?, durationMs: Long?) { marks += Triple(step, extra, durationMs) }
233
+ }
234
+ val r = prepareSduiView(spec(), 1, nowMs = clock) { rec }
235
+ assertTrue(r is SduiResult.Ok)
236
+ val parse = marks.single { it.first == "sdui_parse" }
237
+ assertEquals(7L, parse.third)
238
+ assertEquals(true, parse.second!!["ok"])
239
+ }
240
+
241
+ @Test fun realSessionUsesTheSuppliedParseDuration() {
242
+ val sink = object : TrackSink {
243
+ override val id = "rec"
244
+ val records = ArrayList<TrackRecord>()
245
+ override fun write(record: TrackRecord) { records += record }
246
+ }
247
+ val s = Tracker(listOf(sink), "sess").begin(SessionCtx("sdui:view:t"))
248
+ s.mark("sdui_parse", mapOf("ok" to true), durationMs = 42L)
249
+ assertEquals(42L, sink.records.single().event.fields["duration"])
250
+ }
251
+ }
252
+ // AI-GENERATED END: unit tests for SduiView's pure part
@@ -0,0 +1,110 @@
1
+ package vn.momo.kits.application
2
+
3
+ import androidx.compose.runtime.Immutable
4
+ import androidx.compose.runtime.staticCompositionLocalOf
5
+ import vn.momo.kits.components.TrustBannerData
6
+
7
+ @Immutable
8
+ data class FeatureFlags(
9
+ val showBaseLineDebug: Boolean? = false,
10
+ )
11
+
12
+ @Immutable
13
+ data class DesignSystemConfig(
14
+ val trustBanner: TrustBannerData? = null,
15
+ val headerBar: String? = null,
16
+ val headerGradient: String? = null,
17
+ )
18
+
19
+ @Immutable
20
+ data class MiniAppContext(
21
+ val appIcon: String = "",
22
+ val appName: Any? = null,
23
+ val appId: String = "",
24
+ val appCode: String = "",
25
+ val description: Any? = null,
26
+ val support: Map<String, Any?> = emptyMap(),
27
+ val toolkitConfig: Map<String, Any?> = emptyMap(),
28
+ val providerId: String = "",
29
+ val permissions: List<Map<String, Any>>? = emptyList(),
30
+ val features: FeatureFlags? = null,
31
+ val scaleSizeMaxRate: Float? = null,
32
+ val userScaleRate: Float? = null,
33
+ val useOSScaleRate: Boolean? = null,
34
+ ) {
35
+ companion object {
36
+
37
+ fun toMap(context: MiniAppContext?): Map<String, Any?> = mapOf(
38
+ "icon" to (context?.appIcon ?: ""),
39
+ "name" to context?.appName,
40
+ "appId" to (context?.appId ?: ""),
41
+ "code" to (context?.appCode ?: ""),
42
+ "description" to (context?.description ?: ""),
43
+ "support" to (context?.support ?: emptyMap()),
44
+ "toolkitConfig" to (context?.toolkitConfig ?: emptyMap()),
45
+ "providerId" to (context?.providerId ?: ""),
46
+ "permissions" to (context?.permissions ?: emptyList()),
47
+ )
48
+
49
+ fun merge(parent: MiniAppContext?, child: MiniAppContext?): MiniAppContext? {
50
+ if (parent == null && child == null) return null
51
+ if (parent == null) return child
52
+ if (child == null) return parent
53
+
54
+ return MiniAppContext(
55
+ appIcon = parent.appIcon.ifBlank { child.appIcon },
56
+ appName = parent.appName ?: child.appName,
57
+ appId = parent.appId.ifBlank { child.appId },
58
+ appCode = parent.appCode.ifBlank { child.appCode },
59
+ description = parent.description ?: child.description,
60
+ support = mergeMaps(parent.support, child.support),
61
+ toolkitConfig = mergeMaps(parent.toolkitConfig, child.toolkitConfig),
62
+ providerId = parent.providerId.ifBlank { child.providerId },
63
+ permissions = if (!parent.permissions.isNullOrEmpty()) parent.permissions else child.permissions,
64
+ features = mergeFeatureFlags(parent.features, child.features),
65
+ scaleSizeMaxRate = parent.scaleSizeMaxRate ?: child.scaleSizeMaxRate,
66
+ userScaleRate = parent.userScaleRate ?: child.userScaleRate,
67
+ useOSScaleRate = parent.useOSScaleRate ?: child.useOSScaleRate,
68
+ )
69
+ }
70
+
71
+ private fun mergeMaps(parent: Map<String, Any?>, child: Map<String, Any?>): Map<String, Any?> {
72
+ return child + parent
73
+ }
74
+
75
+ private fun mergeFeatureFlags(parent: FeatureFlags?, child: FeatureFlags?): FeatureFlags? {
76
+ if (parent == null && child == null) return null
77
+ if (parent == null) return child
78
+ if (child == null) return parent
79
+
80
+ return FeatureFlags(
81
+ showBaseLineDebug = parent.showBaseLineDebug ?: child.showBaseLineDebug
82
+ )
83
+ }
84
+ }
85
+ }
86
+
87
+ @Immutable
88
+ data class ComponentInformation(
89
+ val componentName: String? = null,
90
+ val componentId: String? = null,
91
+ val params: Map<String,Any?>? = null,
92
+ val action: String? = null
93
+ )
94
+
95
+ var IsShowBaseLineDebug = false
96
+
97
+ val LocalContext = staticCompositionLocalOf<MiniAppContext?> {
98
+ null
99
+ }
100
+
101
+ val LocalComponentInformation = staticCompositionLocalOf<ComponentInformation?> {
102
+ null
103
+ }
104
+
105
+ val LocalDesignSystemConfig = staticCompositionLocalOf<DesignSystemConfig?> {
106
+ null
107
+ }
108
+
109
+ @Deprecated("No longer read; wrap content in ScaleSizeScope(scaleSizeMaxRate) to cap the font scale.")
110
+ val ScaleSizeMaxRate = staticCompositionLocalOf<Float?> { null }
@@ -0,0 +1,61 @@
1
+ package vn.momo.kits.application
2
+
3
+ import androidx.compose.runtime.Immutable
4
+ import androidx.compose.runtime.getValue
5
+ import androidx.compose.runtime.mutableStateOf
6
+ import androidx.compose.runtime.setValue
7
+ import kotlinx.coroutines.CoroutineScope
8
+ import kotlinx.coroutines.Dispatchers
9
+ import kotlinx.coroutines.Job
10
+ import kotlinx.coroutines.SupervisorJob
11
+ import kotlinx.coroutines.flow.Flow
12
+ import kotlinx.coroutines.flow.MutableStateFlow
13
+ import kotlinx.coroutines.flow.StateFlow
14
+ import kotlinx.coroutines.flow.asStateFlow
15
+ import kotlinx.coroutines.launch
16
+
17
+ @Immutable
18
+ data class DesignSystemKitsConfigs(
19
+ val userScaleRate: Float = 1f,
20
+ val useOSScaleRate: Boolean = true,
21
+ val isWhiteList: Boolean = false,
22
+ val designSystemConfig: DesignSystemConfig? = null,
23
+ )
24
+
25
+ // The kit is sandboxed from the host's storage/config, so the host implements this and hands it to init().
26
+ interface DesignSystemKitsSource {
27
+ // Sync read: seeds the kit before the first frame, so there is no default-then-real flicker.
28
+ fun getConfigs(): DesignSystemKitsConfigs
29
+
30
+ val configsFlow: Flow<DesignSystemKitsConfigs>
31
+ }
32
+
33
+ // App-wide design-system inputs (font scale, whitelist, remote config). scaleSize(), defaultTheme and
34
+ // NavigationContainer fall back to these when no MiniAppContext / LocalDesignSystemConfig is provided.
35
+ object DesignSystemKits {
36
+ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
37
+ private var observeJob: Job? = null
38
+
39
+ // Snapshot state recomposes Compose readers; the StateFlow serves non-Compose observers (the host
40
+ // SwiftUI bridge), where Compose's global snapshot apply loop may never have started.
41
+ private var currentConfigs by mutableStateOf(DesignSystemKitsConfigs())
42
+ private val mutableConfigsFlow = MutableStateFlow(currentConfigs)
43
+ val configsFlow: StateFlow<DesignSystemKitsConfigs> = mutableConfigsFlow.asStateFlow()
44
+
45
+ // Idempotent: a repeated call (e.g. Activity re-creation) replaces the previous observer.
46
+ fun init(source: DesignSystemKitsSource) {
47
+ observeJob?.cancel()
48
+ setConfigs(source.getConfigs())
49
+ observeJob = scope.launch {
50
+ source.configsFlow.collect { setConfigs(it) }
51
+ }
52
+ }
53
+
54
+ // While init() is observing a source, its next emission overrides a value set here.
55
+ fun setConfigs(configs: DesignSystemKitsConfigs) {
56
+ currentConfigs = configs
57
+ mutableConfigsFlow.value = configs
58
+ }
59
+
60
+ fun getConfigs(): DesignSystemKitsConfigs = currentConfigs
61
+ }