Skip to content

Commit e525204

Browse files
jakra-mbgithub-actions[bot]
authored andcommitted
Use platform-tags in test framework to configure image
GitOrigin-RevId: e1999bf89bc0a4db1b68294d20439ff7e7c0b1a7
1 parent 1072f62 commit e525204

1,232 files changed

Lines changed: 4497 additions & 1399 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/integration/lib/utils.ts

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ function ruleMatchesPlatformTag(rule: string, platformTag: string): boolean {
106106
return rule.length === 0 || platformTag.includes(rule);
107107
}
108108

109+
export type ImageThresholdRuleMatch = {
110+
rule: string;
111+
value: number;
112+
};
113+
109114
function isValidPlatformTagRule(rule: string): boolean {
110115
return rule.length === 0 || KNOWN_PLATFORM_TAGS.some((platformTag) => platformTag.includes(rule));
111116
}
@@ -142,8 +147,7 @@ export function matchSkipTestRule(skipTestValue: unknown, platformTag: string |
142147
if (!ruleValue || typeof ruleValue !== 'object' || Array.isArray(ruleValue)) {
143148
return {
144149
validationError:
145-
`Invalid skip-test rule at index ${index}. Expected an object with ` +
146-
'"platform-tag-contains" and "reason" keys.'
150+
`Invalid skip-test rule at index ${index}. Expected an object with "platform-tag-contains" and "reason" keys.`
147151
};
148152
}
149153

@@ -152,17 +156,15 @@ export function matchSkipTestRule(skipTestValue: unknown, platformTag: string |
152156
if (!allowedSkipRuleKeys.has(key)) {
153157
return {
154158
validationError:
155-
`Unknown key "${key}" in skip-test rule at index ${index}. ` +
156-
'Allowed keys: platform-tag-contains, reason.'
159+
`Unknown key "${key}" in skip-test rule at index ${index}. Allowed keys: platform-tag-contains, reason.`
157160
};
158161
}
159162
}
160163

161164
if (!('platform-tag-contains' in skipRule) || !('reason' in skipRule)) {
162165
return {
163166
validationError:
164-
`Invalid skip-test rule at index ${index}. Missing required keys ` +
165-
'"platform-tag-contains" and/or "reason".'
167+
`Invalid skip-test rule at index ${index}. Missing required keys "platform-tag-contains" and/or "reason".`
166168
};
167169
}
168170

@@ -178,9 +180,7 @@ export function matchSkipTestRule(skipTestValue: unknown, platformTag: string |
178180
if (!isValidPlatformTagRule(rule)) {
179181
return {
180182
validationError:
181-
`Invalid platform-tag rule "${rule}" in skip-test. ` +
182-
`Rule must match at least one known platform-tag by substring. ` +
183-
`Known tags: ${KNOWN_PLATFORM_TAGS.join(', ')}`
183+
`Invalid platform-tag rule "${rule}" in skip-test. Rule must match at least one known platform-tag by substring. Known tags: ${KNOWN_PLATFORM_TAGS.join(', ')}`
184184
};
185185
}
186186
rawRules.push(rule);
@@ -200,6 +200,79 @@ export function matchSkipTestRule(skipTestValue: unknown, platformTag: string |
200200
return {match: {rules: matchedRules, reasons: matchedReasons}};
201201
}
202202

203+
type ImageThresholdRule = {
204+
'platform-tag-contains': string;
205+
threshold: number;
206+
};
207+
208+
export type ImageThresholdEvaluation = {
209+
match?: ImageThresholdRuleMatch;
210+
validationError?: string;
211+
};
212+
213+
/** Evaluates `image-threshold` rules against the platform tag. Last matching rule wins. */
214+
export function matchImageThresholdRule(imageThresholdValue: unknown, platformTag: string | undefined): ImageThresholdEvaluation {
215+
if (!platformTag) return {};
216+
if (!imageThresholdValue) return {};
217+
if (!Array.isArray(imageThresholdValue)) {
218+
return {
219+
validationError:
220+
'image-threshold must be an array of objects with "platform-tag-contains" and "threshold" keys'
221+
};
222+
}
223+
224+
const allowedKeys = new Set(['platform-tag-contains', 'threshold']);
225+
let lastMatch: ImageThresholdRuleMatch | undefined;
226+
227+
for (const [index, ruleValue] of imageThresholdValue.entries()) {
228+
if (!ruleValue || typeof ruleValue !== 'object' || Array.isArray(ruleValue)) {
229+
return {
230+
validationError:
231+
`Invalid image-threshold rule at index ${index}. Expected an object with "platform-tag-contains" and "threshold" keys.`
232+
};
233+
}
234+
235+
const ruleObj = ruleValue as Record<string, unknown>;
236+
for (const key of Object.keys(ruleObj)) {
237+
if (!allowedKeys.has(key)) {
238+
return {
239+
validationError:
240+
`Unknown key "${key}" in image-threshold rule at index ${index}. Allowed keys: platform-tag-contains, threshold.`
241+
};
242+
}
243+
}
244+
245+
if (!('platform-tag-contains' in ruleObj) || !('threshold' in ruleObj)) {
246+
return {
247+
validationError:
248+
`Invalid image-threshold rule at index ${index}. Missing required keys "platform-tag-contains" and/or "threshold".`
249+
};
250+
}
251+
252+
if (typeof ruleObj['platform-tag-contains'] !== 'string' || typeof ruleObj.threshold !== 'number') {
253+
return {
254+
validationError:
255+
`Invalid image-threshold rule at index ${index}. "platform-tag-contains" must be a string and "threshold" must be a number.`
256+
};
257+
}
258+
259+
const typedRule = ruleObj as ImageThresholdRule;
260+
const rule = typedRule['platform-tag-contains'];
261+
if (!isValidPlatformTagRule(rule)) {
262+
return {
263+
validationError:
264+
`Invalid platform-tag rule "${rule}" in image-threshold. Rule must match at least one known platform-tag by substring. Known tags: ${KNOWN_PLATFORM_TAGS.join(', ')}`
265+
};
266+
}
267+
268+
if (ruleMatchesPlatformTag(rule, platformTag)) {
269+
lastMatch = {rule, value: typedRule.threshold};
270+
}
271+
}
272+
273+
return lastMatch ? {match: lastMatch} : {};
274+
}
275+
203276
const suiteStartTime = Date.now();
204277

205278
export function sendBrowserDiagnostics() {

test/integration/query-tests/line-offset/property-function/style.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"queryGeometry": [
88
17,
99
32
10+
],
11+
"image-threshold": [
12+
{"platform-tag-contains": "native", "threshold": 0.003}
1013
]
1114
}
1215
},

test/integration/query-tests/model/basemap/style.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"metadata": {
44
"test": {
55
"height": 512,
6-
"allowed": 0.0015,
76
"operations": [
87
["addSource",
98
"trees",
@@ -30,6 +29,9 @@
3029
"queryGeometry": [
3130
165,
3231
279
32+
],
33+
"image-threshold": [
34+
{"platform-tag-contains": "", "threshold": 0.0015}
3335
]
3436
}
3537
},

test/integration/render-tests/3d-intersections/bridge-to-tunnel-transition/style.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"metadata": {
44
"test": {
55
"mapMode": "static",
6-
"allowed": 0.00035,
7-
"spriteFormat": "raster"
6+
"spriteFormat": "raster",
7+
"image-threshold": [
8+
{"platform-tag-contains": "", "threshold": 0.00035}
9+
]
810
}
911
},
1012
"center": [

test/integration/render-tests/3d-intersections/debug-elevation-ids/style.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"metadata": {
44
"test": {
55
"mapMode": "static",
6-
"allowed": 0.00035,
76
"spriteFormat": "raster",
87
"showElevationIdDebug": true,
98
"skip-test": [
109
{"platform-tag-contains": "native", "reason": "skip - Tested separately in internal tests with different data"}
10+
],
11+
"image-threshold": [
12+
{"platform-tag-contains": "", "threshold": 0.00035}
1113
]
1214
}
1315
},

test/integration/render-tests/3d-intersections/depth-segments-undefined-crash-geometry-pass/style.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"metadata": {
44
"test": {
55
"mapMode": "static",
6-
"allowed": 0.001
6+
"image-threshold": [
7+
{"platform-tag-contains": "", "threshold": 0.001}
8+
]
79
}
810
},
911
"center": [0, 0],

test/integration/render-tests/3d-intersections/elevated-circles-mixed-terrain-enabled/style.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"metadata": {
44
"test": {
55
"mapMode": "static",
6-
"allowed": 0.00025,
7-
"spriteFormat": "raster"
6+
"spriteFormat": "raster",
7+
"image-threshold": [
8+
{"platform-tag-contains": "", "threshold": 0.00025}
9+
]
810
}
911
},
1012
"center": [

test/integration/render-tests/3d-intersections/elevated-circles-mixed/style.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"metadata": {
44
"test": {
55
"mapMode": "static",
6-
"allowed": 0.00025,
7-
"spriteFormat": "raster"
6+
"spriteFormat": "raster",
7+
"image-threshold": [
8+
{"platform-tag-contains": "", "threshold": 0.00025}
9+
]
810
}
911
},
1012
"center": [

test/integration/render-tests/3d-intersections/elevated-circles-nonelevated/style.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"metadata": {
44
"test": {
55
"mapMode": "static",
6-
"allowed": 0.00025,
7-
"spriteFormat": "raster"
6+
"spriteFormat": "raster",
7+
"image-threshold": [
8+
{"platform-tag-contains": "", "threshold": 0.00025}
9+
]
810
}
911
},
1012
"center": [

test/integration/render-tests/3d-intersections/elevated-circles-tiled/style.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"metadata": {
44
"test": {
55
"mapMode": "static",
6-
"allowed": 0.00025,
7-
"spriteFormat": "raster"
6+
"spriteFormat": "raster",
7+
"image-threshold": [
8+
{"platform-tag-contains": "", "threshold": 0.00025}
9+
]
810
}
911
},
1012
"center": [

0 commit comments

Comments
 (0)