@momo-kits/native-kits 0.169.13-beta.4-debug → 0.169.13-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.
- package/CLAUDE.md +1 -4
- package/compose/build.gradle.kts +1 -5
- package/compose/compose.podspec +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +12 -4
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +11 -3
- package/gradle/libs.versions.toml +0 -2
- package/gradle.properties +1 -1
- package/ios/Navigation/BottomTab/BottomTabBar.swift +14 -4
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +16 -3
- package/package.json +1 -1
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +0 -647
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +0 -1411
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +0 -130
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +0 -524
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +0 -559
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +0 -741
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +0 -221
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +0 -270
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +0 -849
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +0 -212
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +0 -239
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +0 -252
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +0 -154
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +0 -1038
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +0 -848
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +0 -47
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +0 -463
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +0 -1146
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +0 -667
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +0 -240
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +0 -185
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +0 -200
- package/scripts/sdui-visual/README.md +0 -64
- package/scripts/sdui-visual/diff.py +0 -65
- package/scripts/sdui-visual/drive.py +0 -234
- package/scripts/sdui-visual/plan.json +0 -713
- package/scripts/sdui-visual/run.sh +0 -92
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
// File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt
|
|
2
|
-
// Created At: 2026-10-27 15:50: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 androidx.compose.ui.graphics.Color
|
|
10
|
-
import androidx.compose.ui.unit.Dp
|
|
11
|
-
import androidx.compose.ui.unit.dp
|
|
12
|
-
import org.junit.Assert.assertEquals
|
|
13
|
-
import org.junit.Assert.assertFalse
|
|
14
|
-
import org.junit.Assert.assertNotNull
|
|
15
|
-
import org.junit.Assert.assertNull
|
|
16
|
-
import org.junit.Assert.assertTrue
|
|
17
|
-
import org.junit.Test
|
|
18
|
-
import androidx.compose.ui.text.TextStyle
|
|
19
|
-
import vn.momo.kits.const.Colors
|
|
20
|
-
import vn.momo.kits.const.Radius
|
|
21
|
-
import vn.momo.kits.const.Spacing
|
|
22
|
-
import vn.momo.kits.const.Typography
|
|
23
|
-
import vn.momo.kits.const.darkTheme
|
|
24
|
-
import vn.momo.kits.const.defaultTheme
|
|
25
|
-
|
|
26
|
-
// AI-GENERATED START: unit tests for token mapping, style accessors and the negative-margin arithmetic
|
|
27
|
-
class SduiStyleTest {
|
|
28
|
-
private val theme = defaultTheme
|
|
29
|
-
|
|
30
|
-
@Test fun spacingAndRadiusTokensMapToKitValues() {
|
|
31
|
-
assertEquals(Spacing.M, resolveToken("Spacing.M", theme))
|
|
32
|
-
assertEquals(Spacing.Size4XL, resolveToken("Spacing.Size4XL", theme))
|
|
33
|
-
assertEquals(Spacing.XS, resolveToken("Spacing.XS", theme))
|
|
34
|
-
assertEquals(Radius.L, resolveToken("Radius.L", theme))
|
|
35
|
-
assertEquals(Radius.S, resolveToken("Radius.S", theme))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@Test fun themeColorTokensMapToTheKitTheme() {
|
|
39
|
-
assertEquals(theme.colors.background.default, resolveToken("theme.colors.background.default", theme))
|
|
40
|
-
assertEquals(theme.colors.background.surface, resolveToken("theme.colors.background.surface", theme))
|
|
41
|
-
assertEquals(theme.colors.text.default, resolveToken("theme.colors.text.default", theme))
|
|
42
|
-
assertEquals(theme.colors.border.default, resolveToken("theme.colors.border.default", theme))
|
|
43
|
-
assertTrue(resolveToken("Colors.black_17", theme) is Color)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@Test fun unknownTokensStayAsTheirInput() {
|
|
47
|
-
assertEquals("Spacing.Nope", resolveToken("Spacing.Nope", theme))
|
|
48
|
-
assertEquals("hello", resolveToken("hello", theme))
|
|
49
|
-
assertEquals("theme.colors.nothing", resolveToken("theme.colors.nothing", theme))
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Test fun resolveValueHandlesBindingsTokensAndNesting() {
|
|
53
|
-
val sc = SduiScope(mapOf("w" to 40L, "tok" to "Spacing.L"), emptyMap())
|
|
54
|
-
val out = resolveValue(
|
|
55
|
-
mapOf("width" to "{w}", "gap" to "Spacing.XS", "pad" to "{tok}", "n" to listOf("Radius.S", 3L)), sc, theme,
|
|
56
|
-
).asMap()!!
|
|
57
|
-
assertEquals(40L, out["width"])
|
|
58
|
-
assertEquals(Spacing.XS, out["gap"])
|
|
59
|
-
assertEquals(Spacing.L, out["pad"]) // a bound token string is re-tokenised
|
|
60
|
-
assertEquals(listOf(Radius.S, 3L), out["n"])
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Test fun styleAccessors() {
|
|
64
|
-
val sty = Sty(mapOf(
|
|
65
|
-
"paddingHorizontal" to Spacing.M, "paddingTop" to 4L, "marginTop" to -16L, "width" to 32L,
|
|
66
|
-
"aspectRatio" to "375/210", "borderTopLeftRadius" to Radius.L, "flexDirection" to "row", "flex" to 1L,
|
|
67
|
-
))
|
|
68
|
-
assertEquals(Spacing.M, sty.padStart()); assertEquals(Spacing.M, sty.padEnd())
|
|
69
|
-
assertEquals(4.dp, sty.padTop())
|
|
70
|
-
assertEquals((-16).dp, sty.marTop())
|
|
71
|
-
assertEquals(0.dp, sty.marBottom())
|
|
72
|
-
assertEquals(375f / 210f, sty.aspect!!, 0.0001f)
|
|
73
|
-
assertTrue(sty.isRow); assertTrue(sty.isFlexOne); assertTrue(sty.hasWidth)
|
|
74
|
-
assertNotNull(sty.shape())
|
|
75
|
-
assertNull(Sty(emptyMap()).shape())
|
|
76
|
-
assertEquals(1.75f, parseRatio(1.75)!!, 0.0001f)
|
|
77
|
-
assertEquals(Color.Transparent, parseColor("transparent"))
|
|
78
|
-
assertNull(parseColor("nope"))
|
|
79
|
-
// CSS hex order: alpha is the LAST byte
|
|
80
|
-
assertEquals(Color(0xFFFF0000), parseColor("#f00"))
|
|
81
|
-
assertEquals(Color(0x88FF0000), parseColor("#f008"))
|
|
82
|
-
assertEquals(Color(0xFF00FF00), parseColor("#00FF00"))
|
|
83
|
-
assertEquals(Color(0x80FF0000), parseColor("#FF000080"))
|
|
84
|
-
assertEquals(Color(0x00000000), parseColor("#00000000"))
|
|
85
|
-
assertNull(parseColor("#12345"))
|
|
86
|
-
assertNull(parseColor("#GG0000"))
|
|
87
|
-
assertNull(parseColor("#-12345"))
|
|
88
|
-
assertEquals(12.dp, parseDp(12L)); assertEquals(Spacing.M, parseDp(Spacing.M) as Dp)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@Test fun shapeSelectionImageAlwaysClipsViewOnlyWithOverflowHidden() {
|
|
92
|
-
val rounded = Sty(mapOf("borderRadius" to Radius.S))
|
|
93
|
-
assertTrue(rounded.shouldClip(isImage = true)) // Image: bitmap is always rounded
|
|
94
|
-
assertFalse(rounded.shouldClip(isImage = false)) // container: children are not clipped by default
|
|
95
|
-
assertTrue(Sty(mapOf("borderRadius" to Radius.S, "overflow" to "hidden")).shouldClip(isImage = false))
|
|
96
|
-
assertFalse(Sty(emptyMap()).shouldClip(isImage = true)) // no radius: nothing to clip
|
|
97
|
-
val perCorner = Sty(mapOf("borderTopLeftRadius" to Radius.L, "borderTopRightRadius" to Radius.L))
|
|
98
|
-
assertNotNull(perCorner.shape()); assertTrue(perCorner.shouldClip(isImage = true))
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
@Test fun lineHeightsFollowKitTypographyScaledByScreenWidth() {
|
|
102
|
-
assertEquals(34f, specLineHeight("headline_default_bold", 375f)!!, 0.001f) // the kit's value is the source of truth
|
|
103
|
-
assertEquals(18f * 411.4f / 375f, specLineHeight("description_default_regular", 411.4f)!!, 0.01f)
|
|
104
|
-
assertEquals(18f, specLineHeight("description_default_regular", 375f)!!, 0.001f)
|
|
105
|
-
assertEquals(26f, specLineHeight("header_m_bold", 375f)!!, 0.001f)
|
|
106
|
-
assertEquals(20f, specLineHeight(null, 375f)!!, 0.001f) // default body_default_regular
|
|
107
|
-
assertNull(specLineHeight("nope", 375f))
|
|
108
|
-
assertEquals(20f, specLineHeight("body_default_regular_strikethrough", 375f)!!, 0.001f)
|
|
109
|
-
assertEquals(18f * 1.2f, specLineHeight("description_default_regular", 900f)!!, 0.001f) // scale is capped
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@Test fun everyKitColorResolvesAsColorsToken() {
|
|
113
|
-
assertTrue(Colors.colorList.isNotEmpty())
|
|
114
|
-
Colors.colorList.forEach { (k, c) -> assertEquals(k, c, resolveToken("Colors.$k", defaultTheme)) }
|
|
115
|
-
val codes = mutableListOf<String>()
|
|
116
|
-
val session = object : RenderSession by RenderSession.NOOP {
|
|
117
|
-
override fun nodeError(code: String, reason: String, nodePath: String, nodeType: String?, nodeId: String?) { codes += code }
|
|
118
|
-
}
|
|
119
|
-
val sink = NodeErrorSink { session }
|
|
120
|
-
sink.forNode(emptyMap(), "body") { assertEquals("Colors.nope", resolveToken("Colors.nope", defaultTheme, nodeErrors = sink)) }
|
|
121
|
-
assertEquals(listOf(NODE_ERR_UNKNOWN_TOKEN), codes)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@Test fun everyColorsFieldResolvesByName() {
|
|
125
|
-
// reflection over the object itself, not colorList: fails when kits adds a color field colorList does not carry.
|
|
126
|
-
// Color is an inline class: the getter is name-mangled ("getBlack_01-0d7_KjU") and returns the raw ULong as a long
|
|
127
|
-
val getters = Colors.javaClass.declaredMethods.filter {
|
|
128
|
-
it.parameterCount == 0 && it.name.startsWith("get") && it.returnType == java.lang.Long.TYPE
|
|
129
|
-
}
|
|
130
|
-
assertTrue("found ${getters.size}", getters.size >= 150)
|
|
131
|
-
getters.forEach { m ->
|
|
132
|
-
val name = m.name.removePrefix("get").substringBefore('-').replaceFirstChar { it.lowercase() }
|
|
133
|
-
assertEquals(name, Color((m.invoke(Colors) as Long).toULong()), resolveToken("Colors.$name", defaultTheme))
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
@Test fun flatTokensTakeExactlyOneName() {
|
|
138
|
-
for (t in listOf("Colors.black_17.x", "Spacing.M.y", "Radius.S.y", "Spacing.M.")) {
|
|
139
|
-
val codes = mutableListOf<String>()
|
|
140
|
-
val session = object : RenderSession by RenderSession.NOOP {
|
|
141
|
-
override fun nodeError(code: String, reason: String, nodePath: String, nodeType: String?, nodeId: String?) { codes += code }
|
|
142
|
-
}
|
|
143
|
-
val sink = NodeErrorSink { session }
|
|
144
|
-
sink.forNode(emptyMap(), "body") { assertEquals(t, t, resolveToken(t, defaultTheme, nodeErrors = sink)) }
|
|
145
|
-
assertEquals(t, listOf(NODE_ERR_UNKNOWN_TOKEN), codes)
|
|
146
|
-
}
|
|
147
|
-
assertEquals(Spacing.M, resolveToken("Spacing.M", defaultTheme))
|
|
148
|
-
assertEquals(Radius.S, resolveToken("Radius.S", defaultTheme))
|
|
149
|
-
assertEquals("theme.colors.primary.x", resolveToken("theme.colors.primary.x", defaultTheme))
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** Every Color field reachable from Theme.colors, as (path, value). Fails when kits adds a color SDUI does not map. */
|
|
153
|
-
private fun colorFields(obj: Any, prefix: String, out: MutableList<Pair<String, Color>>) {
|
|
154
|
-
obj.javaClass.declaredMethods
|
|
155
|
-
.filter { it.parameterCount == 0 && it.name.startsWith("get") && !java.lang.reflect.Modifier.isStatic(it.modifiers) }
|
|
156
|
-
.forEach { m ->
|
|
157
|
-
// Color is an inline class: its getter is name-mangled ("getPrimary-0d7_KjU") and returns the raw ULong
|
|
158
|
-
val name = m.name.removePrefix("get").substringBefore('-').replaceFirstChar { it.lowercase() }
|
|
159
|
-
val v = m.invoke(obj)
|
|
160
|
-
when {
|
|
161
|
-
m.returnType == java.lang.Long.TYPE -> out += "$prefix.$name" to Color((v as Long).toULong())
|
|
162
|
-
v != null && v.javaClass.name.startsWith("vn.momo.kits.const.") -> colorFields(v, "$prefix.$name", out)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@Test fun everyThemeColorFieldResolves() {
|
|
168
|
-
for (theme in listOf(defaultTheme, darkTheme)) {
|
|
169
|
-
val found = mutableListOf<Pair<String, Color>>()
|
|
170
|
-
colorFields(theme.colors, "theme.colors", found)
|
|
171
|
-
assertTrue("expected all ColorScheme fields, found ${found.size}", found.size >= 29)
|
|
172
|
-
found.forEach { (path, c) -> assertEquals(path, c, resolveToken(path, theme)) }
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
@Test fun everyTypographyGetterMapsBySnakeCaseName() {
|
|
177
|
-
val snake = Regex("[A-Z]")
|
|
178
|
-
val getters = Typography.javaClass.declaredMethods.filter {
|
|
179
|
-
it.parameterCount == 0 && it.name.startsWith("get") && it.returnType == TextStyle::class.java
|
|
180
|
-
}
|
|
181
|
-
assertTrue("found ${getters.size}", getters.size >= 18)
|
|
182
|
-
getters.forEach { m ->
|
|
183
|
-
val prop = m.name.removePrefix("get").replaceFirstChar { it.lowercase() }
|
|
184
|
-
val name = snake.replace(prop) { "_" + it.value.lowercase() }
|
|
185
|
-
assertEquals(name, m.invoke(Typography) as TextStyle, typographyOf(name))
|
|
186
|
-
assertNotNull(name, specLineHeight(name, 375f))
|
|
187
|
-
}
|
|
188
|
-
assertEquals(Typography.bodyDefaultRegular, typographyOf("nope"))
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
@Test fun negativeMarginsPullTheNodeAndSiblingsUp() {
|
|
193
|
-
// marginTop = -16dp at density 1 (px == dp). child height 36 -> reports 20 and the child is placed at y = -16.
|
|
194
|
-
assertEquals(20, SpecMargin.outerSize(36, -16, 0))
|
|
195
|
-
// available size GROWS for a negative margin , shrinks for a positive one
|
|
196
|
-
assertEquals(16, SpecMargin.constraintDelta(-16, 0))
|
|
197
|
-
assertEquals(-24, SpecMargin.constraintDelta(12, 12))
|
|
198
|
-
// any side, not only top: left/right -8 widen the child's constraints by 16 and the node reports child - 16
|
|
199
|
-
assertEquals(16, SpecMargin.constraintDelta(-8, -8))
|
|
200
|
-
assertEquals(84, SpecMargin.outerSize(100, -8, -8))
|
|
201
|
-
// never below zero
|
|
202
|
-
assertEquals(0, SpecMargin.outerSize(10, -30, 0))
|
|
203
|
-
// spec chain: banner bottom B, outer View marginTop 40, search wrapper marginTop -16 (+ its own height H)
|
|
204
|
-
val bannerBottom = 210; val outerTop = bannerBottom - 20 + 40 // layoutOffset -20 then marginTop 40
|
|
205
|
-
val searchTop = outerTop + (-16)
|
|
206
|
-
assertEquals(230, outerTop); assertEquals(214, searchTop)
|
|
207
|
-
// the sibling after the search wrapper starts at searchTop + (H - 16 reported) ... i.e. 16 earlier than without the margin
|
|
208
|
-
val h = 36
|
|
209
|
-
assertEquals(outerTop + SpecMargin.outerSize(h, -16, 0), searchTop + h)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// AI-GENERATED END: unit tests for token mapping, style accessors and the negative-margin arithmetic
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
// File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt
|
|
2
|
-
// Created At: 2026-10-27 18: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.assertFalse
|
|
11
|
-
import org.junit.Assert.assertNotNull
|
|
12
|
-
import org.junit.Assert.assertNull
|
|
13
|
-
import org.junit.Assert.assertTrue
|
|
14
|
-
import org.junit.Test
|
|
15
|
-
import kotlin.random.Random
|
|
16
|
-
|
|
17
|
-
// AI-GENERATED START: unit tests for SDUI tracking
|
|
18
|
-
class SduiTrackingTest {
|
|
19
|
-
private class FakeSink : TrackSink {
|
|
20
|
-
override val id = "fake"
|
|
21
|
-
val records = mutableListOf<TrackRecord>()
|
|
22
|
-
override fun write(record: TrackRecord) { records += record }
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private val ctx = SessionCtx("sdui:sdui/home", 1)
|
|
26
|
-
private var now = 1000L
|
|
27
|
-
private fun mk(rate: Double = 1.0, sinks: List<TrackSink>? = null): Pair<FakeSink, Tracker> {
|
|
28
|
-
val sink = FakeSink()
|
|
29
|
-
return sink to Tracker(sinks ?: listOf(sink), "sess-1", "ios", rate) { now }
|
|
30
|
-
}
|
|
31
|
-
private fun names(s: FakeSink) = s.records.map { it.event.step }
|
|
32
|
-
|
|
33
|
-
// ---- envelope -------------------------------------------------------------------------------------------------------
|
|
34
|
-
@Test fun envelopeCarriesCommonFieldsOnEveryEvent() {
|
|
35
|
-
val (sink, tracker) = mk()
|
|
36
|
-
val s = tracker.begin(SessionCtx("sdui:sdui/home", 1))
|
|
37
|
-
s.mark("sdui_parse")
|
|
38
|
-
val e = sink.records[0].envelope
|
|
39
|
-
assertEquals(s.renderId, e["renderId"]); assertEquals("sess-1", e["sessionId"])
|
|
40
|
-
assertEquals("sdui:sdui/home", e["screenId"]); assertEquals(1, e["renderVersion"])
|
|
41
|
-
assertEquals(listOf("renderId", "sessionId", "screenId", "renderVersion", "sduiVersion", "os", "t"), e.keys.toList())
|
|
42
|
-
assertEquals(SduiView.VERSION, e["sduiVersion"]); assertEquals("ios", e["os"]); assertEquals(1000L, e["t"])
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Test fun renderIdsAreUniqueAndAtLeast12Chars() {
|
|
46
|
-
val (_, tracker) = mk()
|
|
47
|
-
val ids = (1..50).map { tracker.begin(ctx).renderId }.toSet()
|
|
48
|
-
assertEquals(50, ids.size); ids.forEach { assertTrue(it.length >= 12) }
|
|
49
|
-
assertEquals(1000L.toString(36).length + 12, newRenderId(1000L, Random(1)).length)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ---- events ----------------------------------------------------------------------------------------------------------
|
|
53
|
-
@Test fun everySessionMethodMapsToItsEvent() {
|
|
54
|
-
val (sink, tracker) = mk(); val s = tracker.begin(ctx)
|
|
55
|
-
s.start("sdui_parse"); s.mark("sdui_parse", mapOf("bytesRaw" to 10))
|
|
56
|
-
s.error(SduiError("fetch", "E_X", true), "body.0")
|
|
57
|
-
s.nodeError("unsupported_type", "unsupported_type", "body.1", "Foo", "a")
|
|
58
|
-
assertTrue(sink.records.all { it.event.name == "ops_info_checked" })
|
|
59
|
-
assertEquals(listOf("sdui_parse", "sdui_error", "sdui_node_error"), names(sink))
|
|
60
|
-
assertEquals("sdui_parse", sink.records[0].event.fields["step"]); assertEquals(mapOf("bytesRaw" to 10), sink.records[0].event.fields["extra"])
|
|
61
|
-
assertEquals(
|
|
62
|
-
mapOf("step" to "sdui_node_error", "code" to "unsupported_type", "reason" to "unsupported_type", "nodePath" to "body.1", "nodeId" to "a", "nodeType" to "Foo"),
|
|
63
|
-
sink.records[2].event.fields)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@Test fun markMeasuresFromStartAndNeverGoesNegative() {
|
|
67
|
-
val (sink, tracker) = mk(); now = 1000
|
|
68
|
-
val s = tracker.begin(ctx); s.start("sdui_parse"); now = 1250; s.mark("sdui_parse")
|
|
69
|
-
assertEquals(250L, sink.records[0].event.fields["duration"])
|
|
70
|
-
now = 5000; val s2 = tracker.begin(ctx); now = 5040; s2.mark("first_paint") // never started: from session begin
|
|
71
|
-
assertEquals(40L, sink.records[1].event.fields["duration"])
|
|
72
|
-
now = 1000
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// ---- sampler ---------------------------------------------------------------------------------------------------------
|
|
76
|
-
@Test fun rateZeroDropsRenderStepsButKeepsErrorsNodeErrorsAndDiagnostics() {
|
|
77
|
-
val (sink, tracker) = mk(0.0); val s = tracker.begin(ctx)
|
|
78
|
-
s.mark("sdui_parse"); s.mark("render_done"); s.error(SduiError("fetch", "E", false)); s.nodeError("unknown_token", "unknown_token", "p")
|
|
79
|
-
assertEquals(listOf("sdui_error", "sdui_node_error"), names(sink))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
@Test fun samplerDecidesOncePerSessionAndIsDeterministic() {
|
|
83
|
-
val sample = createSampler(0.5); val first = sample("abc", "sdui_parse")
|
|
84
|
-
repeat(10) { assertEquals(first, sample("abc", "render_done")) }
|
|
85
|
-
assertEquals(first, createSampler(0.5)("abc", "sdui_parse"))
|
|
86
|
-
assertTrue(createSampler(1.0)("s", "sdui_parse"))
|
|
87
|
-
val s3 = createSampler(0.3); val kept = (0 until 2000).count { s3("session-$it", "sdui_parse") }
|
|
88
|
-
assertTrue(kept / 2000.0 > 0.2 && kept / 2000.0 < 0.4)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// ---- sanitizer -------------------------------------------------------------------------------------------------------
|
|
92
|
-
private val env = mapOf("renderId" to "r", "sessionId" to "s", "screenId" to "x", "renderVersion" to 1, "t" to 1L)
|
|
93
|
-
|
|
94
|
-
@Test fun sanitizerDropsUnknownFieldsAndUnknownEvents() {
|
|
95
|
-
val rec = TrackRecord(TrackEvent(mapOf("step" to "sdui_error", "stage" to "fetch", "code" to "E", "retryable" to true, "userName" to "Hung", "data" to mapOf("a" to 1))), env + ("phone" to "09"))
|
|
96
|
-
val out = sanitizeRecord(rec)!!
|
|
97
|
-
assertEquals(TrackEvent(mapOf("step" to "sdui_error", "stage" to "fetch", "code" to "E", "retryable" to true)), out.event)
|
|
98
|
-
assertEquals("ops_info_checked", out.event.name)
|
|
99
|
-
assertFalse(out.envelope.containsKey("phone"))
|
|
100
|
-
assertNull(sanitizeRecord(TrackRecord(TrackEvent(mapOf("step" to "nope")), env)))
|
|
101
|
-
assertNull(sanitizeRecord(TrackRecord(TrackEvent(), env)))
|
|
102
|
-
// fields of another step are not allowed through
|
|
103
|
-
val cross = sanitizeRecord(TrackRecord(TrackEvent(mapOf("step" to "sdui_node_error", "code" to "c", "stage" to "x", "duration" to 3L)), env))!!
|
|
104
|
-
assertEquals(mapOf("step" to "sdui_node_error", "code" to "c"), cross.event.fields)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@Test fun sanitizerTruncatesStringsAndDropsNonPrimitives() {
|
|
108
|
-
val long = "x".repeat(500)
|
|
109
|
-
val out = sanitizeRecord(TrackRecord(TrackEvent(mapOf("step" to "sdui_node_error", "code" to "unknown_token", "reason" to "unknown_token", "nodePath" to long, "nodeType" to mapOf("a" to 1), "nodeId" to Double.NaN)), env + ("renderId" to long)))!!
|
|
110
|
-
assertEquals(MAX_STRING, (out.event.fields["nodePath"] as String).length)
|
|
111
|
-
assertFalse(out.event.fields.containsKey("nodeType")); assertFalse(out.event.fields.containsKey("nodeId"))
|
|
112
|
-
assertEquals(MAX_STRING, (out.envelope["renderId"] as String).length)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
@Test fun extraIsFilteredByKeyAllowlistAndPrimitiveType() {
|
|
116
|
-
val out = sanitizeRecord(TrackRecord(TrackEvent(mapOf("step" to "sdui_parse", "duration" to 5L, "extra" to mapOf("bytesRaw" to 9, "secret" to "x", "ok" to mapOf("a" to 1)))), env))!!
|
|
117
|
-
assertEquals(mapOf("bytesRaw" to 9), out.event.fields["extra"])
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@Test fun recordsReachSinksAlreadySanitized() {
|
|
121
|
-
val (sink, tracker) = mk(); tracker.begin(ctx).error(SduiError("fetch", "x".repeat(300), true, detail = "user said hi"))
|
|
122
|
-
val ev = sink.records[0].event; assertEquals(MAX_STRING, (ev.fields["code"] as String).length); assertFalse(ev.fields.containsKey("detail"))
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ---- isolation -------------------------------------------------------------------------------------
|
|
126
|
-
@Test fun aThrowingSinkDoesNotBreakOthersOrTheCaller() {
|
|
127
|
-
val good = FakeSink()
|
|
128
|
-
val bad = object : TrackSink { override val id = "bad"; override fun write(record: TrackRecord) = error("x") }
|
|
129
|
-
val tracker = Tracker(listOf(bad, good), "s", clock = { now })
|
|
130
|
-
val s = tracker.begin(ctx); s.mark("sdui_parse"); s.end("success")
|
|
131
|
-
assertEquals(1, good.records.size)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ---- sinks -----------------------------------------------------------------------------------------------------------
|
|
135
|
-
private val rec = TrackRecord(TrackEvent(mapOf("step" to "sdui_parse", "duration" to 12L, "extra" to mapOf("bytesRaw" to 3))),
|
|
136
|
-
mapOf("renderId" to "r1", "sessionId" to "s", "screenId" to "sdui:x", "renderVersion" to 1, "os" to null, "t" to 7L))
|
|
137
|
-
|
|
138
|
-
@Test fun trackifySinkFlattensWithoutNulls() {
|
|
139
|
-
var got: Pair<String, Map<String, Any>>? = null
|
|
140
|
-
TrackifySink { n, p -> got = n to p }.write(rec)
|
|
141
|
-
assertEquals("ops_info_checked" to mapOf<String, Any>("renderId" to "r1", "sessionId" to "s", "screenId" to "sdui:x", "renderVersion" to 1, "t" to 7L, "step" to "sdui_parse", "duration" to 12L, "extra_bytesRaw" to 3), got)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@Test fun nothingIsReportedAfterTheSessionEnded() {
|
|
145
|
-
val (sink, tracker) = mk()
|
|
146
|
-
val s = tracker.begin(ctx)
|
|
147
|
-
s.error(SduiError("render", "RENDER", false), "body.children.0")
|
|
148
|
-
s.end("success")
|
|
149
|
-
val before = sink.records.size
|
|
150
|
-
// a late callback arrives after the session is over
|
|
151
|
-
s.error(SduiError("render", "RENDER", false), "body.children.0")
|
|
152
|
-
s.mark("render_done")
|
|
153
|
-
assertEquals(before, sink.records.size)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// ---- sdui_node_error ------------------------------------------------------------------------------------------------
|
|
157
|
-
private fun nodeErrorEvents(s: FakeSink) = s.records.filter { it.event.step == "sdui_node_error" }
|
|
158
|
-
|
|
159
|
-
@Test fun nodeErrorCarriesItsFieldsAndTheEnvelope() {
|
|
160
|
-
val (sink, tracker) = mk(); val s = tracker.begin(SessionCtx("sdui:view:b"))
|
|
161
|
-
s.nodeError("expr_failed", "expr_failed", "body.children.2", "Text", "title")
|
|
162
|
-
val r = nodeErrorEvents(sink).single()
|
|
163
|
-
assertEquals(mapOf("step" to "sdui_node_error", "code" to "expr_failed", "reason" to "expr_failed", "nodePath" to "body.children.2", "nodeId" to "title", "nodeType" to "Text"), r.event.fields)
|
|
164
|
-
assertEquals(s.renderId, r.envelope["renderId"]); assertEquals("sdui:view:b", r.envelope["screenId"])
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@Test fun nodeErrorOmitsUnknownIdAndType() {
|
|
168
|
-
val (sink, tracker) = mk(); tracker.begin(ctx).nodeError("invalid_action", "unknown_type", "body.children.0")
|
|
169
|
-
assertEquals(setOf("step", "code", "reason", "nodePath"), nodeErrorEvents(sink).single().event.fields.keys)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
@Test fun identicalNodeErrorsCountOnceButDifferentOnesDoNot() {
|
|
173
|
-
val (sink, tracker) = mk(); val s = tracker.begin(ctx)
|
|
174
|
-
repeat(5) { s.nodeError("expr_failed", "expr_failed", "body.children.0", "Text", "a") } // repeat copies share a nodePath
|
|
175
|
-
s.nodeError("unknown_token", "unknown_token", "body.children.0", "Text", "a") // other code, same node
|
|
176
|
-
s.nodeError("invalid_action", "missing_type", "body.children.0", "Text", "a")
|
|
177
|
-
s.nodeError("invalid_action", "unknown_type", "body.children.0", "Text", "a") // other reason
|
|
178
|
-
s.nodeError("expr_failed", "expr_failed", "body.children.1", "Text", "b") // other node
|
|
179
|
-
assertEquals(5, nodeErrorEvents(sink).size)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
@Test fun nodeErrorsAreNotCapped() {
|
|
183
|
-
val (sink, tracker) = mk(); val s = tracker.begin(ctx)
|
|
184
|
-
repeat(150) { s.nodeError("unsupported_type", "unsupported_type", "body.children.$it", "Foo", null) }
|
|
185
|
-
assertEquals(150, nodeErrorEvents(sink).size)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
@Test fun nodeErrorsSurviveEndWhileRenderStepsDoNot() {
|
|
189
|
-
val (sink, tracker) = mk(); val s = tracker.begin(ctx)
|
|
190
|
-
s.mark("render_done"); s.end("success")
|
|
191
|
-
s.mark("first_paint")
|
|
192
|
-
s.nodeError("unsupported_type", "unsupported_type", "body.children.9", "Foo", "late")
|
|
193
|
-
assertEquals(listOf("render_done", "sdui_node_error"), names(sink))
|
|
194
|
-
val late = nodeErrorEvents(sink).single()
|
|
195
|
-
assertEquals(s.renderId, late.envelope["renderId"])
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@Test fun nodeErrorIsNeverSampledOut() {
|
|
199
|
-
val (sink, tracker) = mk(0.0); tracker.begin(ctx).nodeError("expr_failed", "expr_failed", "body")
|
|
200
|
-
assertEquals(1, nodeErrorEvents(sink).size)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@Test fun renderDoneCarriesNoNodesTotal() {
|
|
204
|
-
val (sink, tracker) = mk(); val s = tracker.begin(ctx)
|
|
205
|
-
s.mark("render_done", mapOf("nodesTotal" to 12, "ok" to true))
|
|
206
|
-
assertEquals(mapOf("ok" to true), sink.records.single().event.fields["extra"])
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
@Test fun sentEventsCarryExactlyTheseFields() {
|
|
210
|
-
val sent = ArrayList<Pair<String, Map<String, Any>>>()
|
|
211
|
-
val tracker = Tracker(listOf(TrackifySink { n, p -> sent += n to p }), "sess-1", os = "ios", clock = { now })
|
|
212
|
-
val s = tracker.begin(ctx)
|
|
213
|
-
s.mark("sdui_parse", mapOf("ok" to true, "bytesRaw" to 10, "secret" to "x"), durationMs = 5L)
|
|
214
|
-
s.nodeError("unsupported_type", "unsupported_type", "body.children.1", "Foo", "a")
|
|
215
|
-
assertEquals(2, sent.size); assertTrue(sent.all { it.first == "ops_info_checked" })
|
|
216
|
-
val envelope = listOf("renderId", "sessionId", "screenId", "renderVersion", "sduiVersion", "os", "t")
|
|
217
|
-
assertEquals(envelope + listOf("step", "duration", "extra_ok", "extra_bytesRaw"), sent[0].second.keys.toList())
|
|
218
|
-
assertEquals(envelope + listOf("step", "code", "reason", "nodePath", "nodeId", "nodeType"), sent[1].second.keys.toList())
|
|
219
|
-
assertEquals(listOf<Any>(s.renderId, "sess-1", "sdui:sdui/home", 1, SduiView.VERSION, "ios", 1000L, "sdui_parse", 5L, true, 10), sent[0].second.values.toList())
|
|
220
|
-
assertEquals(listOf<Any>("unsupported_type", "unsupported_type", "body.children.1", "a", "Foo"), sent[1].second.values.toList().drop(8))
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
@Test fun actionIsNoLongerAStep() {
|
|
224
|
-
assertNull(sanitizeRecord(TrackRecord(TrackEvent(mapOf("step" to "sdui_action", "verb" to "set")), env)))
|
|
225
|
-
assertNull(sanitizeRecord(TrackRecord(TrackEvent(mapOf("step" to "sdui_block_skipped", "reason" to "x")), env)))
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
@Test fun defaultWiringReportsEventsToTrack() {
|
|
229
|
-
val calls = ArrayList<String>()
|
|
230
|
-
val api = fakeMaxApi { name, args -> calls += name + ":" + args.filter { it !is Function<*> }.map { if (it is Array<*>) it.toList() else it } }
|
|
231
|
-
val tracker = SduiTracking.createDefault(SduiMaxApi({ api }))
|
|
232
|
-
val s = tracker.begin(SessionCtx(screenId = "sdui:view:block"))
|
|
233
|
-
s.error(SduiError("render", "RENDER", false), "body")
|
|
234
|
-
assertTrue(calls.any { it.startsWith("track:[") && "sdui_error" in it })
|
|
235
|
-
assertTrue(calls.none { it.startsWith("showToastDebug") })
|
|
236
|
-
assertNotNull(sampleBucket("abc")); assertTrue(sampleBucket("abc") in 0.0..1.0)
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// AI-GENERATED END: unit tests for SDUI tracking
|