playwright-performance-regression 0.0.0-stage → 0.1.0-next.0
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/CHANGELOG.md +268 -0
- package/LICENSE +21 -0
- package/README.md +214 -2
- package/dist/chunk-6AB42SPF.js +254 -0
- package/dist/chunk-DYLCGMI2.js +63 -0
- package/dist/chunk-GCA73FFP.cjs +1139 -0
- package/dist/chunk-HES6BVZT.js +1097 -0
- package/dist/chunk-JEHUFIY3.js +3390 -0
- package/dist/chunk-LV3O2BAT.cjs +319 -0
- package/dist/chunk-R2NPYGB7.cjs +758 -0
- package/dist/chunk-UTTU4FUC.js +756 -0
- package/dist/cli.js +2909 -0
- package/dist/config.cjs +256 -0
- package/dist/config.d.cts +15 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +252 -0
- package/dist/fixture.cjs +16 -0
- package/dist/fixture.d.cts +22 -0
- package/dist/fixture.d.ts +22 -0
- package/dist/fixture.js +4 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +637 -0
- package/dist/index.d.ts +637 -0
- package/dist/index.js +1 -0
- package/dist/perf-api-V4PeHVE0.d.cts +22 -0
- package/dist/perf-api-V4PeHVE0.d.ts +22 -0
- package/dist/reporter.cjs +4769 -0
- package/dist/reporter.d.cts +18 -0
- package/dist/reporter.d.ts +18 -0
- package/dist/reporter.js +1409 -0
- package/dist/test.cjs +14 -0
- package/dist/test.d.cts +7 -0
- package/dist/test.d.ts +7 -0
- package/dist/test.js +10 -0
- package/package.json +146 -4
- package/schemas/common.schema.json +81 -0
- package/schemas/config.schema.json +875 -0
- package/schemas/outcome.schema.json +44 -0
- package/schemas/run-report.schema.json +505 -0
- package/schemas/samples.schema.json +169 -0
- package/schemas/thresholds.schema.json +138 -0
|
@@ -0,0 +1,1097 @@
|
|
|
1
|
+
// src/core/schema/dsl.ts
|
|
2
|
+
var Sink = class {
|
|
3
|
+
problems = [];
|
|
4
|
+
limit;
|
|
5
|
+
constructor(limit) {
|
|
6
|
+
this.limit = limit;
|
|
7
|
+
}
|
|
8
|
+
get full() {
|
|
9
|
+
return this.problems.length >= this.limit;
|
|
10
|
+
}
|
|
11
|
+
add(pointer, message, kind2 = "value", property) {
|
|
12
|
+
if (this.full) return;
|
|
13
|
+
this.problems.push(
|
|
14
|
+
property === void 0 ? { pointer, message, kind: kind2 } : { pointer, message, kind: kind2, property }
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function child(pointer, key2) {
|
|
19
|
+
return `${pointer}/${String(key2).replaceAll("~", "~0").replaceAll("/", "~1")}`;
|
|
20
|
+
}
|
|
21
|
+
function isRecord(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
function matches(schema, value, pointer = "") {
|
|
25
|
+
const sink = new Sink(1);
|
|
26
|
+
schema.check(value, pointer, sink);
|
|
27
|
+
return sink.problems.length === 0;
|
|
28
|
+
}
|
|
29
|
+
function codePoints(text) {
|
|
30
|
+
let n = 0;
|
|
31
|
+
for (const _ of text) n++;
|
|
32
|
+
return n;
|
|
33
|
+
}
|
|
34
|
+
function deepEqual(a, b) {
|
|
35
|
+
if (a === b) return true;
|
|
36
|
+
if (Array.isArray(a)) {
|
|
37
|
+
return Array.isArray(b) && a.length === b.length && a.every((x, i) => deepEqual(x, b[i]));
|
|
38
|
+
}
|
|
39
|
+
if (isRecord(a) && isRecord(b)) {
|
|
40
|
+
const keys = Object.keys(a);
|
|
41
|
+
return keys.length === Object.keys(b).length && keys.every((k) => Object.hasOwn(b, k) && deepEqual(a[k], b[k]));
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function quote(value) {
|
|
46
|
+
return JSON.stringify(value);
|
|
47
|
+
}
|
|
48
|
+
function str(options = {}) {
|
|
49
|
+
const { minLength, maxLength, pattern, format } = options;
|
|
50
|
+
return {
|
|
51
|
+
expected: "string",
|
|
52
|
+
...format === void 0 ? {} : { format },
|
|
53
|
+
accepts: (value) => typeof value === "string",
|
|
54
|
+
check(value, pointer, sink) {
|
|
55
|
+
if (typeof value !== "string") return sink.add(pointer, "must be string", "type");
|
|
56
|
+
if (minLength !== void 0 || maxLength !== void 0) {
|
|
57
|
+
const length = codePoints(value);
|
|
58
|
+
if (minLength !== void 0 && length < minLength) {
|
|
59
|
+
sink.add(pointer, `must NOT have fewer than ${minLength} characters`);
|
|
60
|
+
}
|
|
61
|
+
if (maxLength !== void 0 && length > maxLength) {
|
|
62
|
+
sink.add(pointer, `must NOT have more than ${maxLength} characters`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (pattern !== void 0 && !pattern.test(value)) {
|
|
66
|
+
sink.add(
|
|
67
|
+
pointer,
|
|
68
|
+
format === void 0 ? `must match pattern "${pattern.source}"` : `must be ${format}`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function numeric(integer, options) {
|
|
75
|
+
const { minimum, maximum } = options;
|
|
76
|
+
const type = integer ? "integer" : "number";
|
|
77
|
+
return {
|
|
78
|
+
expected: type,
|
|
79
|
+
accepts: (value) => typeof value === "number",
|
|
80
|
+
check(value, pointer, sink) {
|
|
81
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
82
|
+
return sink.add(pointer, `must be ${type}`, "type");
|
|
83
|
+
}
|
|
84
|
+
if (integer && !Number.isInteger(value)) return sink.add(pointer, "must be integer", "type");
|
|
85
|
+
if (minimum !== void 0 && value < minimum) sink.add(pointer, `must be >= ${minimum}`);
|
|
86
|
+
if (maximum !== void 0 && value > maximum) sink.add(pointer, `must be <= ${maximum}`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
var int = (options = {}) => numeric(true, options);
|
|
91
|
+
var num = (options = {}) => numeric(false, options);
|
|
92
|
+
var bool = {
|
|
93
|
+
expected: "boolean",
|
|
94
|
+
accepts: (value) => typeof value === "boolean",
|
|
95
|
+
check(value, pointer, sink) {
|
|
96
|
+
if (typeof value !== "boolean") sink.add(pointer, "must be boolean", "type");
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
var nul = {
|
|
100
|
+
expected: "null",
|
|
101
|
+
accepts: (value) => value === null,
|
|
102
|
+
check(value, pointer, sink) {
|
|
103
|
+
if (value !== null) sink.add(pointer, "must be null", "type");
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var anyObject = {
|
|
107
|
+
expected: "object",
|
|
108
|
+
accepts: isRecord,
|
|
109
|
+
check(value, pointer, sink) {
|
|
110
|
+
if (!isRecord(value)) sink.add(pointer, "must be object", "type");
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function constant(expected) {
|
|
114
|
+
return {
|
|
115
|
+
expected: quote(expected),
|
|
116
|
+
accepts: (value) => value === expected,
|
|
117
|
+
check(value, pointer, sink) {
|
|
118
|
+
if (value !== expected) sink.add(pointer, `must be equal to ${quote(expected)}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function enumOf(values) {
|
|
123
|
+
return {
|
|
124
|
+
expected: values.map(quote).join(" | "),
|
|
125
|
+
accepts: (value) => typeof value === "string" || typeof value === "number",
|
|
126
|
+
check(value, pointer, sink) {
|
|
127
|
+
if (!values.includes(value)) {
|
|
128
|
+
const kind2 = typeof value === "string" || typeof value === "number" ? "value" : "type";
|
|
129
|
+
sink.add(pointer, `must be one of ${values.map(quote).join(", ")}`, kind2);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function oneOf(...alternatives) {
|
|
135
|
+
const expected = alternatives.map((a) => a.expected).join(" or ");
|
|
136
|
+
return {
|
|
137
|
+
expected,
|
|
138
|
+
accepts: (value) => alternatives.some((a) => a.accepts(value)),
|
|
139
|
+
check(value, pointer, sink) {
|
|
140
|
+
const matching = alternatives.filter((a) => matches(a, value, pointer)).length;
|
|
141
|
+
if (matching === 1) return;
|
|
142
|
+
if (matching > 1) return sink.add(pointer, "must match exactly one allowed form");
|
|
143
|
+
const candidates = alternatives.filter((a) => a.accepts(value));
|
|
144
|
+
if (candidates.length === 1 && candidates[0] !== void 0) {
|
|
145
|
+
return candidates[0].check(value, pointer, sink);
|
|
146
|
+
}
|
|
147
|
+
sink.add(pointer, `must be ${expected}`, "type");
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
var nullable = (schema) => oneOf(schema, nul);
|
|
152
|
+
function arr(items, options = {}) {
|
|
153
|
+
const { minItems, maxItems, uniqueItems } = options;
|
|
154
|
+
return {
|
|
155
|
+
expected: "array",
|
|
156
|
+
accepts: Array.isArray,
|
|
157
|
+
check(value, pointer, sink) {
|
|
158
|
+
if (!Array.isArray(value)) return sink.add(pointer, "must be array", "type");
|
|
159
|
+
if (minItems !== void 0 && value.length < minItems) {
|
|
160
|
+
sink.add(pointer, `must NOT have fewer than ${minItems} items`);
|
|
161
|
+
}
|
|
162
|
+
if (maxItems !== void 0 && value.length > maxItems) {
|
|
163
|
+
sink.add(pointer, `must NOT have more than ${maxItems} items`);
|
|
164
|
+
}
|
|
165
|
+
if (uniqueItems === true) {
|
|
166
|
+
const duplicate = value.findIndex((x, i) => value.slice(0, i).some((y) => deepEqual(x, y)));
|
|
167
|
+
if (duplicate !== -1)
|
|
168
|
+
sink.add(pointer, `must NOT have duplicate items (item ${duplicate})`);
|
|
169
|
+
}
|
|
170
|
+
for (let i = 0; i < value.length && !sink.full; i++) {
|
|
171
|
+
items.check(value[i], child(pointer, i), sink);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function obj(properties, options = {}) {
|
|
177
|
+
const { required = [], refine } = options;
|
|
178
|
+
return {
|
|
179
|
+
expected: "object",
|
|
180
|
+
accepts: isRecord,
|
|
181
|
+
check(value, pointer, sink) {
|
|
182
|
+
if (!isRecord(value)) return sink.add(pointer, "must be object", "type");
|
|
183
|
+
for (const name of required) {
|
|
184
|
+
if (!Object.hasOwn(value, name)) sink.add(pointer, `must have required property '${name}'`);
|
|
185
|
+
}
|
|
186
|
+
for (const [name, item] of Object.entries(value)) {
|
|
187
|
+
if (sink.full) return;
|
|
188
|
+
const schema = Object.hasOwn(properties, name) ? properties[name] : void 0;
|
|
189
|
+
if (schema === void 0) {
|
|
190
|
+
sink.add(pointer, `must NOT have additional property '${name}'`, "unknown", name);
|
|
191
|
+
} else {
|
|
192
|
+
schema.check(item, child(pointer, name), sink);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
refine?.(value, pointer, sink);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function record(names, values, options = {}) {
|
|
200
|
+
const { required = [] } = options;
|
|
201
|
+
return {
|
|
202
|
+
expected: "object",
|
|
203
|
+
accepts: isRecord,
|
|
204
|
+
check(value, pointer, sink) {
|
|
205
|
+
if (!isRecord(value)) return sink.add(pointer, "must be object", "type");
|
|
206
|
+
for (const name of required) {
|
|
207
|
+
if (!Object.hasOwn(value, name)) sink.add(pointer, `must have required property '${name}'`);
|
|
208
|
+
}
|
|
209
|
+
for (const [name, item] of Object.entries(value)) {
|
|
210
|
+
if (sink.full) return;
|
|
211
|
+
if (!matches(names, name)) {
|
|
212
|
+
const detail = names.format === void 0 ? "is invalid" : `must be ${names.format}`;
|
|
213
|
+
sink.add(child(pointer, name), `property name ${detail}`, "name", name);
|
|
214
|
+
}
|
|
215
|
+
values.check(item, child(pointer, name), sink);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/core/schema/common.ts
|
|
222
|
+
var ms = num({ minimum: 0 });
|
|
223
|
+
var msOrNull = nullable(ms);
|
|
224
|
+
var msLimit = int({ minimum: 0 });
|
|
225
|
+
var ratio = num({ minimum: 0, maximum: 1 });
|
|
226
|
+
var count = int({ minimum: 0 });
|
|
227
|
+
var timestamp = str({ pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u });
|
|
228
|
+
var epochMs = int({ minimum: 0 });
|
|
229
|
+
var runId = str({ minLength: 1, maxLength: 128 });
|
|
230
|
+
var mode = enumOf(["test", "thresholds"]);
|
|
231
|
+
var envLabel = str({
|
|
232
|
+
pattern: /^[a-z0-9-]+$/u,
|
|
233
|
+
maxLength: 32,
|
|
234
|
+
format: 'a label of lowercase letters, digits and "-", like "staging"'
|
|
235
|
+
});
|
|
236
|
+
var envLabelOrNull = nullable(envLabel);
|
|
237
|
+
var kind = enumOf(["api", "custom"]);
|
|
238
|
+
var percentileName = str({
|
|
239
|
+
pattern: /^p(?:[1-9][0-9]?)(?:\.[0-9])?$/u,
|
|
240
|
+
format: 'a percentile name like "p95" or "p99.9"'
|
|
241
|
+
});
|
|
242
|
+
var key = str({ minLength: 1, maxLength: 2e3 });
|
|
243
|
+
var tool = obj(
|
|
244
|
+
{ name: str({ minLength: 1 }), version: str({ minLength: 1 }) },
|
|
245
|
+
{ required: ["name", "version"] }
|
|
246
|
+
);
|
|
247
|
+
var issue = obj(
|
|
248
|
+
{
|
|
249
|
+
code: str({ pattern: /^[A-Z][A-Z0-9_]*$/u }),
|
|
250
|
+
message: str({ minLength: 1 }),
|
|
251
|
+
hint: str({ minLength: 1 }),
|
|
252
|
+
count: int({ minimum: 1 })
|
|
253
|
+
},
|
|
254
|
+
{ required: ["code", "message"] }
|
|
255
|
+
);
|
|
256
|
+
var testsStatus = enumOf(["passed", "failed", "timedout", "interrupted"]);
|
|
257
|
+
var evaluationStatus = enumOf(["passed", "warned", "failed", "error"]);
|
|
258
|
+
var fingerprint = str({ pattern: /^[0-9a-f]{14}$/u });
|
|
259
|
+
var hostFingerprint = obj(
|
|
260
|
+
{
|
|
261
|
+
platform: str(),
|
|
262
|
+
arch: str(),
|
|
263
|
+
ci: bool,
|
|
264
|
+
cpuCount: int({ minimum: 1 }),
|
|
265
|
+
cpuModel: str()
|
|
266
|
+
},
|
|
267
|
+
{ required: ["platform", "arch", "ci", "cpuCount", "cpuModel"] }
|
|
268
|
+
);
|
|
269
|
+
var isoDate = str({ pattern: /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/u });
|
|
270
|
+
|
|
271
|
+
// src/core/config/generated/defaults.ts
|
|
272
|
+
var DEFAULT_CONFIG = {
|
|
273
|
+
run: { env: null, repeat: { test: 5, thresholds: 10 }, projects: "auto", keepReporters: [] },
|
|
274
|
+
measure: {
|
|
275
|
+
resourceTypes: ["document", "xhr", "fetch"],
|
|
276
|
+
ignoreExtensions: [
|
|
277
|
+
".js",
|
|
278
|
+
".mjs",
|
|
279
|
+
".css",
|
|
280
|
+
".map",
|
|
281
|
+
".html",
|
|
282
|
+
".png",
|
|
283
|
+
".jpg",
|
|
284
|
+
".jpeg",
|
|
285
|
+
".gif",
|
|
286
|
+
".svg",
|
|
287
|
+
".webp",
|
|
288
|
+
".avif",
|
|
289
|
+
".ico",
|
|
290
|
+
".woff",
|
|
291
|
+
".woff2",
|
|
292
|
+
".ttf",
|
|
293
|
+
".otf",
|
|
294
|
+
".eot"
|
|
295
|
+
],
|
|
296
|
+
include: [],
|
|
297
|
+
exclude: ["/socket.io/"],
|
|
298
|
+
excludeKnownThirdParty: true,
|
|
299
|
+
successStatuses: ["2xx", "3xx"],
|
|
300
|
+
pendingTimeoutMs: 2e3
|
|
301
|
+
},
|
|
302
|
+
keys: {
|
|
303
|
+
origins: {},
|
|
304
|
+
idPatterns: { number: true, uuid: true, hex: true, token: true, mixed: true, email: true },
|
|
305
|
+
extraIdPatterns: [],
|
|
306
|
+
query: "names",
|
|
307
|
+
keepQueryValues: [],
|
|
308
|
+
dropQueryParams: []
|
|
309
|
+
},
|
|
310
|
+
checks: {
|
|
311
|
+
time: {
|
|
312
|
+
median: {
|
|
313
|
+
enabled: true,
|
|
314
|
+
minSamples: 5,
|
|
315
|
+
margin: { relative: 0.4, minMs: 100, smallSampleRelative: 0.8 },
|
|
316
|
+
limit: { api: 2e3, custom: 5e3 }
|
|
317
|
+
},
|
|
318
|
+
percentile: {
|
|
319
|
+
enabled: true,
|
|
320
|
+
minSamples: 20,
|
|
321
|
+
level: "p95",
|
|
322
|
+
limit: { api: 2e3, custom: 5e3 },
|
|
323
|
+
margin: { relative: 0.4, minMs: 100, smallSampleRelative: 0.8 }
|
|
324
|
+
},
|
|
325
|
+
p99: {
|
|
326
|
+
enabled: true,
|
|
327
|
+
minSamples: 100,
|
|
328
|
+
margin: { relative: 0.2, minGapMs: 50, minGapRelative: 0.1 },
|
|
329
|
+
limit: { api: 4e3, custom: 1e4 }
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
slowShare: {
|
|
333
|
+
t: {
|
|
334
|
+
api: { min: 500, max: 2e3, medianFactor: 2 },
|
|
335
|
+
custom: { min: 1e3, max: 1e4, medianFactor: 2 }
|
|
336
|
+
},
|
|
337
|
+
apdex: {
|
|
338
|
+
enabled: true,
|
|
339
|
+
minSamples: 20,
|
|
340
|
+
margin: { absolute: 0.05, smallSampleAbsolute: 0.1 },
|
|
341
|
+
limit: { api: 0.85, custom: 0.85 }
|
|
342
|
+
},
|
|
343
|
+
wilson: {
|
|
344
|
+
enabled: true,
|
|
345
|
+
minSamples: 20,
|
|
346
|
+
margin: { factor: 1.5, add: 0.02, min: 0.03, max: 0.15, smallSampleMin: 0.1 },
|
|
347
|
+
limit: { api: 0.05, custom: 0.05 }
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
errors: {
|
|
351
|
+
enabled: true,
|
|
352
|
+
minSamples: 5,
|
|
353
|
+
statuses: ["5xx", "FAILED", "PENDING"],
|
|
354
|
+
limit: { api: 0.05, custom: 0.05 },
|
|
355
|
+
margin: { factor: 1.5, add: 0.02, min: 0.05 }
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
gate: {
|
|
359
|
+
tolerance: 0,
|
|
360
|
+
hardLimitFactor: 2,
|
|
361
|
+
defaultThresholds: "block",
|
|
362
|
+
warnOnly: false,
|
|
363
|
+
maxFailedTestShare: 0.1
|
|
364
|
+
},
|
|
365
|
+
thresholds: {
|
|
366
|
+
dir: ".",
|
|
367
|
+
filePrefix: "perf-thresholds",
|
|
368
|
+
update: "all",
|
|
369
|
+
smallSampleN: 20,
|
|
370
|
+
hysteresis: { relative: 0.1, ratio: 0.01 },
|
|
371
|
+
loosenWarnRelative: 0.5
|
|
372
|
+
},
|
|
373
|
+
report: { dir: "perf-results", html: true, rawUrls: false },
|
|
374
|
+
advanced: { maxSamplesPerKey: 5e3, seed: 1 }
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
// src/core/config/paths.ts
|
|
378
|
+
var IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
379
|
+
function formatPath(segments) {
|
|
380
|
+
let path = "";
|
|
381
|
+
for (const segment of segments) {
|
|
382
|
+
if (typeof segment === "number") path += `[${segment}]`;
|
|
383
|
+
else if (IDENTIFIER.test(segment)) path += path === "" ? segment : `.${segment}`;
|
|
384
|
+
else path += `[${JSON.stringify(segment)}]`;
|
|
385
|
+
}
|
|
386
|
+
return path;
|
|
387
|
+
}
|
|
388
|
+
function pointerSegments(pointer, document) {
|
|
389
|
+
if (pointer === "") return [];
|
|
390
|
+
const segments = [];
|
|
391
|
+
let node = document;
|
|
392
|
+
for (const raw of pointer.slice(1).split("/")) {
|
|
393
|
+
const name = raw.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
394
|
+
if (Array.isArray(node)) {
|
|
395
|
+
const index = Number(name);
|
|
396
|
+
segments.push(index);
|
|
397
|
+
node = node[index];
|
|
398
|
+
} else {
|
|
399
|
+
segments.push(name);
|
|
400
|
+
node = isRecord(node) && Object.hasOwn(node, name) ? node[name] : void 0;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return segments;
|
|
404
|
+
}
|
|
405
|
+
function valueAt(document, segments) {
|
|
406
|
+
let node = document;
|
|
407
|
+
for (const segment of segments) {
|
|
408
|
+
if (Array.isArray(node) && typeof segment === "number") node = node[segment];
|
|
409
|
+
else if (isRecord(node) && typeof segment === "string" && Object.hasOwn(node, segment)) {
|
|
410
|
+
node = node[segment];
|
|
411
|
+
} else return void 0;
|
|
412
|
+
}
|
|
413
|
+
return node;
|
|
414
|
+
}
|
|
415
|
+
function define(target, name, value) {
|
|
416
|
+
Object.defineProperty(target, name, {
|
|
417
|
+
value,
|
|
418
|
+
enumerable: true,
|
|
419
|
+
writable: true,
|
|
420
|
+
configurable: true
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
var MAX_SHOWN = 60;
|
|
424
|
+
function describeValue(value) {
|
|
425
|
+
if (value === void 0) return "undefined";
|
|
426
|
+
if (typeof value === "function") return "a function";
|
|
427
|
+
if (typeof value === "bigint") return `${value}n`;
|
|
428
|
+
if (typeof value === "symbol") return value.toString();
|
|
429
|
+
if (typeof value === "number") return String(value);
|
|
430
|
+
if (value instanceof RegExp) return String(value);
|
|
431
|
+
let text;
|
|
432
|
+
try {
|
|
433
|
+
text = JSON.stringify(value);
|
|
434
|
+
} catch {
|
|
435
|
+
text = void 0;
|
|
436
|
+
}
|
|
437
|
+
if (text === void 0) return Array.isArray(value) ? "an array" : "an object";
|
|
438
|
+
return text.length > MAX_SHOWN ? `${text.slice(0, MAX_SHOWN - 1)}\u2026` : text;
|
|
439
|
+
}
|
|
440
|
+
function editDistance(a, b) {
|
|
441
|
+
let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
442
|
+
for (let i = 1; i <= a.length; i++) {
|
|
443
|
+
const current = [i];
|
|
444
|
+
for (let j = 1; j <= b.length; j++) {
|
|
445
|
+
const substitution = (previous[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1);
|
|
446
|
+
current.push(Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, substitution));
|
|
447
|
+
}
|
|
448
|
+
previous = current;
|
|
449
|
+
}
|
|
450
|
+
return previous[b.length] ?? 0;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/core/schema/config.ts
|
|
454
|
+
var factor10 = num({ minimum: 0, maximum: 10 });
|
|
455
|
+
var unit = num({ minimum: 0, maximum: 1 });
|
|
456
|
+
var urlPattern = oneOf(
|
|
457
|
+
str({ minLength: 1 }),
|
|
458
|
+
obj(
|
|
459
|
+
{
|
|
460
|
+
regex: str({ minLength: 1 }),
|
|
461
|
+
flags: str({ pattern: /^[dgimsuyv]*$/u, format: 'regular expression flags from "dgimsuyv"' })
|
|
462
|
+
},
|
|
463
|
+
{ required: ["regex"] }
|
|
464
|
+
)
|
|
465
|
+
);
|
|
466
|
+
var limitByKind = (value) => obj({ api: value, custom: value });
|
|
467
|
+
var relativeMargin = obj({
|
|
468
|
+
relative: factor10,
|
|
469
|
+
minMs: int({ minimum: 0 }),
|
|
470
|
+
smallSampleRelative: factor10
|
|
471
|
+
});
|
|
472
|
+
var p99Margin = obj({
|
|
473
|
+
relative: factor10,
|
|
474
|
+
minGapMs: int({ minimum: 1 }),
|
|
475
|
+
minGapRelative: factor10
|
|
476
|
+
});
|
|
477
|
+
var apdexMargin = obj({ absolute: unit, smallSampleAbsolute: unit });
|
|
478
|
+
var wilsonMargin = obj({
|
|
479
|
+
factor: factor10,
|
|
480
|
+
add: unit,
|
|
481
|
+
min: unit,
|
|
482
|
+
max: unit,
|
|
483
|
+
smallSampleMin: unit
|
|
484
|
+
});
|
|
485
|
+
var errorsMargin = obj({ factor: factor10, add: unit, min: unit });
|
|
486
|
+
var tSettings = obj({
|
|
487
|
+
min: msLimit,
|
|
488
|
+
max: msLimit,
|
|
489
|
+
medianFactor: num({ minimum: 1, maximum: 10 })
|
|
490
|
+
});
|
|
491
|
+
var enabled = bool;
|
|
492
|
+
var minSamples = int({ minimum: 1 });
|
|
493
|
+
var checks = obj({
|
|
494
|
+
time: obj({
|
|
495
|
+
median: obj({ enabled, minSamples, margin: relativeMargin, limit: limitByKind(msLimit) }),
|
|
496
|
+
percentile: obj({
|
|
497
|
+
enabled,
|
|
498
|
+
minSamples,
|
|
499
|
+
level: percentileName,
|
|
500
|
+
limit: limitByKind(msLimit),
|
|
501
|
+
margin: relativeMargin
|
|
502
|
+
}),
|
|
503
|
+
p99: obj({ enabled, minSamples, margin: p99Margin, limit: limitByKind(msLimit) })
|
|
504
|
+
}),
|
|
505
|
+
slowShare: obj({
|
|
506
|
+
t: obj({ api: tSettings, custom: tSettings }),
|
|
507
|
+
apdex: obj({ enabled, minSamples, margin: apdexMargin, limit: limitByKind(ratio) }),
|
|
508
|
+
wilson: obj({ enabled, minSamples, margin: wilsonMargin, limit: limitByKind(ratio) })
|
|
509
|
+
}),
|
|
510
|
+
errors: obj({
|
|
511
|
+
enabled,
|
|
512
|
+
minSamples,
|
|
513
|
+
statuses: arr(
|
|
514
|
+
str({
|
|
515
|
+
pattern: /^(?:[1-5]xx|[1-5][0-9]{2}|FAILED|ABORTED|PENDING)$/u,
|
|
516
|
+
format: 'a status like "5xx", "429", "FAILED", "ABORTED" or "PENDING"'
|
|
517
|
+
}),
|
|
518
|
+
{
|
|
519
|
+
uniqueItems: true
|
|
520
|
+
}
|
|
521
|
+
),
|
|
522
|
+
limit: limitByKind(ratio),
|
|
523
|
+
margin: errorsMargin
|
|
524
|
+
})
|
|
525
|
+
});
|
|
526
|
+
var uniqueStrings = (minLength) => arr(str({ minLength }), { uniqueItems: true });
|
|
527
|
+
var packageConfig = obj({
|
|
528
|
+
$schema: str(),
|
|
529
|
+
run: obj({
|
|
530
|
+
env: envLabelOrNull,
|
|
531
|
+
repeat: obj({
|
|
532
|
+
test: int({ minimum: 1, maximum: 1e3 }),
|
|
533
|
+
thresholds: int({ minimum: 1, maximum: 1e3 })
|
|
534
|
+
}),
|
|
535
|
+
projects: oneOf(constant("auto"), arr(str(), { minItems: 1, uniqueItems: true })),
|
|
536
|
+
keepReporters: uniqueStrings(1)
|
|
537
|
+
}),
|
|
538
|
+
measure: obj({
|
|
539
|
+
resourceTypes: arr(
|
|
540
|
+
enumOf([
|
|
541
|
+
"document",
|
|
542
|
+
"stylesheet",
|
|
543
|
+
"image",
|
|
544
|
+
"media",
|
|
545
|
+
"font",
|
|
546
|
+
"script",
|
|
547
|
+
"texttrack",
|
|
548
|
+
"xhr",
|
|
549
|
+
"fetch",
|
|
550
|
+
"eventsource",
|
|
551
|
+
"manifest",
|
|
552
|
+
"other"
|
|
553
|
+
]),
|
|
554
|
+
{ uniqueItems: true, minItems: 1 }
|
|
555
|
+
),
|
|
556
|
+
ignoreExtensions: arr(
|
|
557
|
+
str({ pattern: /^\.[a-z0-9]+$/u, format: 'a lowercase extension with a dot, like ".js"' }),
|
|
558
|
+
{ uniqueItems: true }
|
|
559
|
+
),
|
|
560
|
+
include: arr(urlPattern),
|
|
561
|
+
exclude: arr(urlPattern),
|
|
562
|
+
excludeKnownThirdParty: bool,
|
|
563
|
+
successStatuses: arr(
|
|
564
|
+
str({
|
|
565
|
+
pattern: /^(?:[1-5]xx|[1-5][0-9]{2})$/u,
|
|
566
|
+
format: 'a status class like "2xx" or a code like "404"'
|
|
567
|
+
}),
|
|
568
|
+
{
|
|
569
|
+
uniqueItems: true,
|
|
570
|
+
minItems: 1
|
|
571
|
+
}
|
|
572
|
+
),
|
|
573
|
+
pendingTimeoutMs: int({ minimum: 0, maximum: 6e4 })
|
|
574
|
+
}),
|
|
575
|
+
keys: obj({
|
|
576
|
+
origins: record(
|
|
577
|
+
str({
|
|
578
|
+
pattern: /^https?:\/\/[^/?#]+$/u,
|
|
579
|
+
format: 'an origin without a path, like "https://api.example.com"'
|
|
580
|
+
}),
|
|
581
|
+
str({
|
|
582
|
+
pattern: /^[a-z0-9.-]*$/u,
|
|
583
|
+
maxLength: 64,
|
|
584
|
+
format: 'a label of lowercase letters, digits, "." and "-", like "api"'
|
|
585
|
+
})
|
|
586
|
+
),
|
|
587
|
+
idPatterns: obj({
|
|
588
|
+
number: bool,
|
|
589
|
+
uuid: bool,
|
|
590
|
+
hex: bool,
|
|
591
|
+
token: bool,
|
|
592
|
+
mixed: bool,
|
|
593
|
+
email: bool
|
|
594
|
+
}),
|
|
595
|
+
extraIdPatterns: arr(urlPattern),
|
|
596
|
+
query: enumOf(["names", "ignore"]),
|
|
597
|
+
keepQueryValues: uniqueStrings(1),
|
|
598
|
+
dropQueryParams: uniqueStrings(1),
|
|
599
|
+
keyBuilder: constant("[function]")
|
|
600
|
+
}),
|
|
601
|
+
checks,
|
|
602
|
+
gate: obj({
|
|
603
|
+
tolerance: oneOf(
|
|
604
|
+
int({ minimum: 0 }),
|
|
605
|
+
str({
|
|
606
|
+
pattern: /^(?:100|[0-9]{1,2}(?:\.[0-9]+)?)%$/u,
|
|
607
|
+
format: 'an integer >= 0 (ms) or a percentage like "5%"'
|
|
608
|
+
})
|
|
609
|
+
),
|
|
610
|
+
hardLimitFactor: nullable(num({ minimum: 1 })),
|
|
611
|
+
defaultThresholds: enumOf(["block", "warn"]),
|
|
612
|
+
warnOnly: bool,
|
|
613
|
+
maxFailedTestShare: unit
|
|
614
|
+
}),
|
|
615
|
+
thresholds: obj({
|
|
616
|
+
dir: str({ minLength: 1 }),
|
|
617
|
+
filePrefix: str({
|
|
618
|
+
pattern: /^[A-Za-z0-9._-]+$/u,
|
|
619
|
+
format: 'a file name prefix of letters, digits, ".", "_" and "-"'
|
|
620
|
+
}),
|
|
621
|
+
update: enumOf(["all", "new-only"]),
|
|
622
|
+
smallSampleN: int({ minimum: 1 }),
|
|
623
|
+
hysteresis: obj({ relative: unit, ratio: num({ minimum: 0, maximum: 0.01 }) }),
|
|
624
|
+
loosenWarnRelative: num({ minimum: 0, maximum: 100 })
|
|
625
|
+
}),
|
|
626
|
+
report: obj({ dir: str({ minLength: 1 }), html: bool, rawUrls: bool }),
|
|
627
|
+
advanced: obj({
|
|
628
|
+
maxSamplesPerKey: int({ minimum: 100, maximum: 1e5 }),
|
|
629
|
+
seed: int({ minimum: 0, maximum: 4294967295 })
|
|
630
|
+
})
|
|
631
|
+
});
|
|
632
|
+
var derivationSettings = obj(
|
|
633
|
+
{
|
|
634
|
+
t: obj(
|
|
635
|
+
{ min: msLimit, max: msLimit, medianFactor: num({ minimum: 1, maximum: 10 }) },
|
|
636
|
+
{ required: ["min", "max", "medianFactor"] }
|
|
637
|
+
),
|
|
638
|
+
smallSampleN: int({ minimum: 1 }),
|
|
639
|
+
margins: obj(
|
|
640
|
+
{
|
|
641
|
+
median: relativeMargin,
|
|
642
|
+
percentile: relativeMargin,
|
|
643
|
+
p99: p99Margin,
|
|
644
|
+
apdex: apdexMargin,
|
|
645
|
+
wilson: wilsonMargin,
|
|
646
|
+
errors: errorsMargin
|
|
647
|
+
},
|
|
648
|
+
{ required: ["median", "percentile", "p99", "apdex", "wilson", "errors"] }
|
|
649
|
+
)
|
|
650
|
+
},
|
|
651
|
+
{ required: ["t", "smallSampleN", "margins"] }
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
// src/core/config/validate.ts
|
|
655
|
+
var SCHEMA_FILE = "schemas/config.schema.json";
|
|
656
|
+
var MAX_SUGGESTION_DISTANCE = 2;
|
|
657
|
+
var MAX_SCHEMA_PROBLEMS = 1e3;
|
|
658
|
+
var PATTERN_LISTS = [
|
|
659
|
+
["measure", "include"],
|
|
660
|
+
["measure", "exclude"],
|
|
661
|
+
["keys", "extraIdPatterns"]
|
|
662
|
+
];
|
|
663
|
+
function issue2(code, segments, message, hint) {
|
|
664
|
+
const path = formatPath(segments);
|
|
665
|
+
return { code, path, message: `${path === "" ? "config" : path}: ${message}`, hint };
|
|
666
|
+
}
|
|
667
|
+
function isPatternItem(segments) {
|
|
668
|
+
return segments.length === 3 && typeof segments[2] === "number" && PATTERN_LISTS.some(([a, b]) => segments[0] === a && segments[1] === b);
|
|
669
|
+
}
|
|
670
|
+
function knownOptions(parent) {
|
|
671
|
+
if (isPatternItem(parent)) return ["regex", "flags"];
|
|
672
|
+
if (parent[0] === "keys" && parent[1] === "origins") return [];
|
|
673
|
+
const node = valueAt(DEFAULT_CONFIG, parent);
|
|
674
|
+
const names = isRecord(node) ? Object.keys(node) : [];
|
|
675
|
+
if (parent.length === 0) names.push("$schema");
|
|
676
|
+
if (parent.length === 1 && parent[0] === "keys") names.push("keyBuilder");
|
|
677
|
+
return names;
|
|
678
|
+
}
|
|
679
|
+
function allOptionPaths(node, prefix = []) {
|
|
680
|
+
if (!isRecord(node) || prefix[0] === "keys" && prefix[1] === "origins") return [];
|
|
681
|
+
return Object.entries(node).flatMap(([name, value]) => [
|
|
682
|
+
[...prefix, name],
|
|
683
|
+
...allOptionPaths(value, [...prefix, name])
|
|
684
|
+
]);
|
|
685
|
+
}
|
|
686
|
+
function suggestOption(parent, name) {
|
|
687
|
+
let best;
|
|
688
|
+
for (const candidate of knownOptions(parent)) {
|
|
689
|
+
const distance = editDistance(name, candidate);
|
|
690
|
+
if (distance <= MAX_SUGGESTION_DISTANCE && (best === void 0 || distance < best.distance)) {
|
|
691
|
+
best = { name: candidate, distance };
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (best !== void 0) return formatPath([...parent, best.name]);
|
|
695
|
+
const moved = allOptionPaths(DEFAULT_CONFIG).find((path) => path.at(-1) === name);
|
|
696
|
+
return moved === void 0 ? void 0 : formatPath(moved);
|
|
697
|
+
}
|
|
698
|
+
function exampleHint(segments) {
|
|
699
|
+
let example = valueAt(DEFAULT_CONFIG, segments);
|
|
700
|
+
if (example === void 0 && typeof segments.at(-1) === "number") {
|
|
701
|
+
const list = valueAt(DEFAULT_CONFIG, segments.slice(0, -1));
|
|
702
|
+
if (Array.isArray(list)) example = list[0];
|
|
703
|
+
}
|
|
704
|
+
const shown = example === void 0 || isRecord(example) ? void 0 : describeValue(example);
|
|
705
|
+
const prefix = shown === void 0 || shown.endsWith("\u2026") ? "" : `Default: ${shown}. `;
|
|
706
|
+
return `${prefix}${SCHEMA_FILE} in the package lists every option and its format.`;
|
|
707
|
+
}
|
|
708
|
+
function problemToIssue(problem, document) {
|
|
709
|
+
const segments = pointerSegments(problem.pointer, document);
|
|
710
|
+
if (problem.kind === "unknown" && problem.property !== void 0) {
|
|
711
|
+
const option = [...segments, problem.property];
|
|
712
|
+
const suggestion = suggestOption(segments, problem.property);
|
|
713
|
+
return issue2(
|
|
714
|
+
"CONFIG_UNKNOWN_OPTION",
|
|
715
|
+
option,
|
|
716
|
+
suggestion === void 0 ? "unknown option" : `unknown option. Did you mean "${suggestion}"?`,
|
|
717
|
+
suggestion === void 0 ? `Remove it or fix the name; ${SCHEMA_FILE} in the package lists every option.` : `Rename it to "${suggestion}".`
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
const got = problem.kind === "name" ? JSON.stringify(problem.property) : describeValue(valueAt(document, segments));
|
|
721
|
+
return issue2(
|
|
722
|
+
problem.kind === "type" ? "CONFIG_INVALID_TYPE" : "CONFIG_INVALID_VALUE",
|
|
723
|
+
segments,
|
|
724
|
+
`${problem.message}, got ${got}`,
|
|
725
|
+
exampleHint(segments)
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
function schemaIssues(document) {
|
|
729
|
+
const sink = new Sink(MAX_SCHEMA_PROBLEMS);
|
|
730
|
+
packageConfig.check(document, "", sink);
|
|
731
|
+
return sink.problems.map((problem) => problemToIssue(problem, document));
|
|
732
|
+
}
|
|
733
|
+
function regexIssues(document) {
|
|
734
|
+
const issues = [];
|
|
735
|
+
for (const [section, option] of PATTERN_LISTS) {
|
|
736
|
+
const list = valueAt(document, [section, option]);
|
|
737
|
+
if (!Array.isArray(list)) continue;
|
|
738
|
+
list.forEach((item, index) => {
|
|
739
|
+
if (!isRecord(item) || typeof item.regex !== "string") return;
|
|
740
|
+
const flags = typeof item.flags === "string" ? item.flags : "";
|
|
741
|
+
try {
|
|
742
|
+
new RegExp(item.regex, flags);
|
|
743
|
+
} catch (error) {
|
|
744
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
745
|
+
issues.push(
|
|
746
|
+
issue2(
|
|
747
|
+
"CONFIG_INVALID_REGEX",
|
|
748
|
+
[section, option, index],
|
|
749
|
+
`regular expression does not compile (${reason})`,
|
|
750
|
+
'Fix the expression; it uses JavaScript RegExp syntax, e.g. { "regex": "^/api/v[0-9]+/", "flags": "i" }.'
|
|
751
|
+
)
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
return issues;
|
|
757
|
+
}
|
|
758
|
+
var numberAt = (config, segments) => {
|
|
759
|
+
const value = valueAt(config, segments);
|
|
760
|
+
return typeof value === "number" ? value : void 0;
|
|
761
|
+
};
|
|
762
|
+
var RULES = [
|
|
763
|
+
["checks", "time", "median"],
|
|
764
|
+
["checks", "time", "percentile"],
|
|
765
|
+
["checks", "time", "p99"],
|
|
766
|
+
["checks", "slowShare", "apdex"],
|
|
767
|
+
["checks", "slowShare", "wilson"],
|
|
768
|
+
["checks", "errors"]
|
|
769
|
+
];
|
|
770
|
+
var KINDS = ["api", "custom"];
|
|
771
|
+
var MIN_PERCENTILE = 50;
|
|
772
|
+
function percentileLevel(name) {
|
|
773
|
+
if (typeof name !== "string" || !/^p\d+(?:\.\d)?$/u.test(name)) return void 0;
|
|
774
|
+
return Number(name.slice(1));
|
|
775
|
+
}
|
|
776
|
+
function relationalIssues(config, isSet) {
|
|
777
|
+
const errors = [];
|
|
778
|
+
const warnings = [];
|
|
779
|
+
const ordered = (low, high, hint) => {
|
|
780
|
+
const a = numberAt(config, low);
|
|
781
|
+
const b = numberAt(config, high);
|
|
782
|
+
if (a === void 0 || b === void 0 || a <= b) return;
|
|
783
|
+
const onLow = isSet(low) && !isSet(high);
|
|
784
|
+
errors.push(
|
|
785
|
+
onLow ? issue2(
|
|
786
|
+
"CONFIG_INVALID_VALUE",
|
|
787
|
+
low,
|
|
788
|
+
`must be <= ${formatPath(high)} (${b}), got ${a}`,
|
|
789
|
+
hint
|
|
790
|
+
) : issue2(
|
|
791
|
+
"CONFIG_INVALID_VALUE",
|
|
792
|
+
high,
|
|
793
|
+
`must be >= ${formatPath(low)} (${a}), got ${b}`,
|
|
794
|
+
hint
|
|
795
|
+
)
|
|
796
|
+
);
|
|
797
|
+
};
|
|
798
|
+
const limit = (rule, kind2) => ["checks", "time", rule, "limit", kind2];
|
|
799
|
+
const limitHint = "Time limits must not decrease from median to percentile to p99; raise the higher limit or lower the other one.";
|
|
800
|
+
for (const kind2 of KINDS) {
|
|
801
|
+
ordered(limit("percentile", kind2), limit("p99", kind2), limitHint);
|
|
802
|
+
ordered(limit("median", kind2), limit("percentile", kind2), limitHint);
|
|
803
|
+
}
|
|
804
|
+
const boundsHint = "Set the lower bound at most equal to the upper bound.";
|
|
805
|
+
for (const kind2 of KINDS) {
|
|
806
|
+
const t = ["checks", "slowShare", "t", kind2];
|
|
807
|
+
ordered([...t, "min"], [...t, "max"], boundsHint);
|
|
808
|
+
}
|
|
809
|
+
const wilsonMargin2 = ["checks", "slowShare", "wilson", "margin"];
|
|
810
|
+
ordered([...wilsonMargin2, "min"], [...wilsonMargin2, "max"], boundsHint);
|
|
811
|
+
const levelPath = ["checks", "time", "percentile", "level"];
|
|
812
|
+
const level = percentileLevel(valueAt(config, levelPath));
|
|
813
|
+
if (level !== void 0 && level < MIN_PERCENTILE) {
|
|
814
|
+
errors.push(
|
|
815
|
+
issue2(
|
|
816
|
+
"CONFIG_INVALID_VALUE",
|
|
817
|
+
levelPath,
|
|
818
|
+
`must be at least "p50", got ${describeValue(valueAt(config, levelPath))}`,
|
|
819
|
+
'A percentile below the median could give a lower limit than the median rule; use a level like "p90" or "p95".'
|
|
820
|
+
)
|
|
821
|
+
);
|
|
822
|
+
} else if (level === 99) {
|
|
823
|
+
warnings.push(
|
|
824
|
+
issue2(
|
|
825
|
+
"CONFIG_PERCENTILE_IS_P99",
|
|
826
|
+
levelPath,
|
|
827
|
+
"the percentile rule checks p99, the same as the p99 rule",
|
|
828
|
+
'Use a lower level such as "p95", or disable checks.time.p99.'
|
|
829
|
+
)
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
for (const rule of RULES.slice(1)) {
|
|
833
|
+
ordered(
|
|
834
|
+
["checks", "time", "median", "minSamples"],
|
|
835
|
+
[...rule, "minSamples"],
|
|
836
|
+
"The median rule needs the fewest samples; raise this minSamples or lower the median one."
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
const enabled2 = RULES.some((rule) => valueAt(config, [...rule, "enabled"]) !== false);
|
|
840
|
+
if (!enabled2 && valueAt(config, ["gate", "warnOnly"]) !== true) {
|
|
841
|
+
errors.push(
|
|
842
|
+
issue2(
|
|
843
|
+
"CONFIG_INVALID_VALUE",
|
|
844
|
+
["checks"],
|
|
845
|
+
"every rule is disabled, so nothing would be checked",
|
|
846
|
+
"Enable at least one rule in checks, or set gate.warnOnly to true."
|
|
847
|
+
)
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
const origins = valueAt(config, ["keys", "origins"]);
|
|
851
|
+
if (isRecord(origins)) {
|
|
852
|
+
const byLabel = /* @__PURE__ */ new Map();
|
|
853
|
+
for (const [origin, label] of Object.entries(origins)) {
|
|
854
|
+
if (typeof label !== "string") continue;
|
|
855
|
+
byLabel.set(label, [...byLabel.get(label) ?? [], origin]);
|
|
856
|
+
}
|
|
857
|
+
for (const [label, list] of byLabel) {
|
|
858
|
+
if (list.length < 2) continue;
|
|
859
|
+
warnings.push(
|
|
860
|
+
issue2(
|
|
861
|
+
"CONFIG_DUPLICATE_ORIGIN_LABEL",
|
|
862
|
+
["keys", "origins"],
|
|
863
|
+
`${list.map((o) => JSON.stringify(o)).join(", ")} share the label ${JSON.stringify(label)}, so their endpoint keys are merged`,
|
|
864
|
+
"Give each origin its own label unless merging their keys is intended."
|
|
865
|
+
)
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
const resourceTypes = valueAt(config, ["measure", "resourceTypes"]);
|
|
870
|
+
if (Array.isArray(resourceTypes) && resourceTypes.includes("eventsource")) {
|
|
871
|
+
warnings.push(
|
|
872
|
+
issue2(
|
|
873
|
+
"CONFIG_RESOURCE_TYPE_LONG_LIVED",
|
|
874
|
+
["measure", "resourceTypes"],
|
|
875
|
+
'includes "eventsource"; server-sent event connections usually stay open and are recorded as PENDING samples',
|
|
876
|
+
'Remove "eventsource" unless its requests finish within the test.'
|
|
877
|
+
)
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
return { errors, warnings };
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// src/core/config/resolve.ts
|
|
884
|
+
var KEY_BUILDER_SNAPSHOT = "[function]";
|
|
885
|
+
var repeatSchema = int({ minimum: 1, maximum: 1e3 });
|
|
886
|
+
function isPlainObject(value) {
|
|
887
|
+
if (!isRecord(value)) return false;
|
|
888
|
+
const prototype = Object.getPrototypeOf(value);
|
|
889
|
+
return prototype === Object.prototype || prototype === null;
|
|
890
|
+
}
|
|
891
|
+
function toJsonForm(value) {
|
|
892
|
+
if (value instanceof RegExp) return { regex: value.source, flags: value.flags };
|
|
893
|
+
if (Array.isArray(value)) return value.map(toJsonForm);
|
|
894
|
+
if (!isPlainObject(value)) return value;
|
|
895
|
+
const out = {};
|
|
896
|
+
for (const [name, item] of Object.entries(value)) {
|
|
897
|
+
if (item !== void 0) define(out, name, toJsonForm(item));
|
|
898
|
+
}
|
|
899
|
+
return out;
|
|
900
|
+
}
|
|
901
|
+
function takeKeyBuilder(document, source) {
|
|
902
|
+
const keys = valueAt(document, ["keys"]);
|
|
903
|
+
if (!isPlainObject(keys) || !Object.hasOwn(keys, "keyBuilder")) {
|
|
904
|
+
return { keyBuilder: void 0, inSnapshot: false };
|
|
905
|
+
}
|
|
906
|
+
const value = keys.keyBuilder;
|
|
907
|
+
delete keys.keyBuilder;
|
|
908
|
+
const path = ["keys", "keyBuilder"];
|
|
909
|
+
if (source === "json") {
|
|
910
|
+
return {
|
|
911
|
+
keyBuilder: void 0,
|
|
912
|
+
inSnapshot: false,
|
|
913
|
+
issue: issue2(
|
|
914
|
+
"CONFIG_INVALID_TYPE",
|
|
915
|
+
path,
|
|
916
|
+
"is not allowed in a JSON config file; a key builder must be a function",
|
|
917
|
+
"Move the config to a .ts or .js file to use a keyBuilder function, or remove the option."
|
|
918
|
+
)
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
if (source === "snapshot") {
|
|
922
|
+
if (value === KEY_BUILDER_SNAPSHOT) return { keyBuilder: void 0, inSnapshot: true };
|
|
923
|
+
return {
|
|
924
|
+
keyBuilder: void 0,
|
|
925
|
+
inSnapshot: false,
|
|
926
|
+
issue: issue2(
|
|
927
|
+
"CONFIG_INVALID_TYPE",
|
|
928
|
+
path,
|
|
929
|
+
`must be "${KEY_BUILDER_SNAPSHOT}" in a config snapshot, got ${describeValue(value)}`,
|
|
930
|
+
'The run report stores a key builder function as "[function]"; do not edit the snapshot.'
|
|
931
|
+
)
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
if (typeof value === "function") {
|
|
935
|
+
return { keyBuilder: value, inSnapshot: true };
|
|
936
|
+
}
|
|
937
|
+
return {
|
|
938
|
+
keyBuilder: void 0,
|
|
939
|
+
inSnapshot: false,
|
|
940
|
+
issue: issue2(
|
|
941
|
+
"CONFIG_INVALID_TYPE",
|
|
942
|
+
path,
|
|
943
|
+
`must be a function, got ${describeValue(value)}`,
|
|
944
|
+
"Pass a function (req) => string | undefined; return undefined to use the built-in normalization."
|
|
945
|
+
)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
function clone(value) {
|
|
949
|
+
if (Array.isArray(value)) return value.map(clone);
|
|
950
|
+
if (!isRecord(value)) return value;
|
|
951
|
+
const out = {};
|
|
952
|
+
for (const [name, item] of Object.entries(value)) define(out, name, clone(item));
|
|
953
|
+
return out;
|
|
954
|
+
}
|
|
955
|
+
function merge(base, override) {
|
|
956
|
+
if (!isRecord(base) || !isRecord(override)) return clone(override);
|
|
957
|
+
const out = {};
|
|
958
|
+
for (const [name, value] of Object.entries(base)) define(out, name, clone(value));
|
|
959
|
+
for (const [name, value] of Object.entries(override)) {
|
|
960
|
+
define(
|
|
961
|
+
out,
|
|
962
|
+
name,
|
|
963
|
+
Object.hasOwn(base, name) ? merge(base[name], value) : merge(void 0, value)
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
return out;
|
|
967
|
+
}
|
|
968
|
+
function inputOrder(document) {
|
|
969
|
+
const order = /* @__PURE__ */ new Map();
|
|
970
|
+
const visit = (node, prefix) => {
|
|
971
|
+
const entries = Array.isArray(node) ? node.map((item, index) => [index, item]) : isRecord(node) ? Object.entries(node) : [];
|
|
972
|
+
for (const [segment, value] of entries) {
|
|
973
|
+
const path = [...prefix, segment];
|
|
974
|
+
order.set(formatPath(path), order.size);
|
|
975
|
+
visit(value, path);
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
visit(document, []);
|
|
979
|
+
return order;
|
|
980
|
+
}
|
|
981
|
+
function sortByInput(issues, order) {
|
|
982
|
+
const position = (path) => {
|
|
983
|
+
let candidate = path ?? "";
|
|
984
|
+
while (candidate !== "") {
|
|
985
|
+
const found = order.get(candidate);
|
|
986
|
+
if (found !== void 0) return found;
|
|
987
|
+
const cut = Math.max(candidate.lastIndexOf("."), candidate.lastIndexOf("["));
|
|
988
|
+
candidate = cut <= 0 ? "" : candidate.slice(0, cut);
|
|
989
|
+
}
|
|
990
|
+
return Number.POSITIVE_INFINITY;
|
|
991
|
+
};
|
|
992
|
+
return issues.map((item, index) => ({ item, index, at: position(item.path) })).sort((a, b) => a.at - b.at || a.index - b.index).map(({ item }) => item);
|
|
993
|
+
}
|
|
994
|
+
function overrideIssues(overrides) {
|
|
995
|
+
const issues = [];
|
|
996
|
+
if (overrides.env !== void 0 && !matches(envLabelOrNull, overrides.env)) {
|
|
997
|
+
issues.push(
|
|
998
|
+
issue2(
|
|
999
|
+
"CONFIG_INVALID_VALUE",
|
|
1000
|
+
["run", "env"],
|
|
1001
|
+
`the environment override must be null or a label of lowercase letters, digits and "-" (at most 32 characters), got ${describeValue(overrides.env)}`,
|
|
1002
|
+
'Fix the environment label, e.g. "staging".'
|
|
1003
|
+
)
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
if (overrides.repeat !== void 0 && !matches(repeatSchema, overrides.repeat)) {
|
|
1007
|
+
issues.push(
|
|
1008
|
+
issue2(
|
|
1009
|
+
"CONFIG_INVALID_VALUE",
|
|
1010
|
+
["run", "repeat", overrides.mode ?? "test"],
|
|
1011
|
+
`the repeat override must be an integer from 1 to 1000, got ${describeValue(overrides.repeat)}`,
|
|
1012
|
+
"Fix the number of repetitions, e.g. 5."
|
|
1013
|
+
)
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
return issues;
|
|
1017
|
+
}
|
|
1018
|
+
function applyOverrides(config, overrides) {
|
|
1019
|
+
if (overrides.env !== void 0) config.run.env = overrides.env;
|
|
1020
|
+
if (overrides.repeat !== void 0) {
|
|
1021
|
+
config.run.repeat[overrides.mode === "thresholds" ? "thresholds" : "test"] = overrides.repeat;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
function snapshotPattern(pattern) {
|
|
1025
|
+
return typeof pattern === "string" ? pattern : { regex: pattern.regex, flags: pattern.flags ?? "" };
|
|
1026
|
+
}
|
|
1027
|
+
function compilePattern(pattern) {
|
|
1028
|
+
if (typeof pattern === "string") return pattern;
|
|
1029
|
+
return new RegExp(pattern.regex, (pattern.flags ?? "").replace(/[gy]/g, ""));
|
|
1030
|
+
}
|
|
1031
|
+
function resolveConfig(input, overrides) {
|
|
1032
|
+
const source = overrides.source ?? "code";
|
|
1033
|
+
const document = toJsonForm(input ?? {});
|
|
1034
|
+
const keyBuilder = takeKeyBuilder(document, source);
|
|
1035
|
+
const order = inputOrder(document);
|
|
1036
|
+
const errors = [
|
|
1037
|
+
...keyBuilder.issue === void 0 ? [] : [keyBuilder.issue],
|
|
1038
|
+
...schemaIssues(document),
|
|
1039
|
+
...regexIssues(document),
|
|
1040
|
+
...overrideIssues(overrides)
|
|
1041
|
+
];
|
|
1042
|
+
const { $schema: _schema, ...withoutSchema } = isRecord(document) ? document : {};
|
|
1043
|
+
const merged = merge(DEFAULT_CONFIG, withoutSchema);
|
|
1044
|
+
if (errors.length === 0) applyOverrides(merged, overrides);
|
|
1045
|
+
const relational = relationalIssues(merged, (path) => order.has(formatPath(path)));
|
|
1046
|
+
errors.push(...relational.errors);
|
|
1047
|
+
if (errors.length > 0) return { ok: false, issues: sortByInput(errors, order) };
|
|
1048
|
+
for (const [section, option] of PATTERN_LISTS) {
|
|
1049
|
+
const list = valueAt(merged, [section, option]);
|
|
1050
|
+
list.splice(0, list.length, ...list.map(snapshotPattern));
|
|
1051
|
+
}
|
|
1052
|
+
if (keyBuilder.inSnapshot) merged.keys.keyBuilder = KEY_BUILDER_SNAPSHOT;
|
|
1053
|
+
const snapshot = merged;
|
|
1054
|
+
const { keyBuilder: _keyBuilder, ...keys } = snapshot.keys;
|
|
1055
|
+
const copy = clone(snapshot);
|
|
1056
|
+
const config = {
|
|
1057
|
+
...copy,
|
|
1058
|
+
measure: {
|
|
1059
|
+
...copy.measure,
|
|
1060
|
+
include: snapshot.measure.include.map(compilePattern),
|
|
1061
|
+
exclude: snapshot.measure.exclude.map(compilePattern)
|
|
1062
|
+
},
|
|
1063
|
+
keys: {
|
|
1064
|
+
...clone(keys),
|
|
1065
|
+
extraIdPatterns: snapshot.keys.extraIdPatterns.map(compilePattern),
|
|
1066
|
+
keyBuilder: keyBuilder.keyBuilder
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
return {
|
|
1070
|
+
ok: true,
|
|
1071
|
+
value: {
|
|
1072
|
+
config,
|
|
1073
|
+
snapshot,
|
|
1074
|
+
warnings: sortByInput(relational.warnings, order)
|
|
1075
|
+
}
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// src/core/config/define.ts
|
|
1080
|
+
function definePerfConfig(config) {
|
|
1081
|
+
return config;
|
|
1082
|
+
}
|
|
1083
|
+
function deepFreeze(value) {
|
|
1084
|
+
if (typeof value === "object" && value !== null && !Object.isFrozen(value)) {
|
|
1085
|
+
Object.freeze(value);
|
|
1086
|
+
for (const item of Object.values(value)) deepFreeze(item);
|
|
1087
|
+
}
|
|
1088
|
+
return value;
|
|
1089
|
+
}
|
|
1090
|
+
function resolveDefaults() {
|
|
1091
|
+
const result = resolveConfig(void 0, {});
|
|
1092
|
+
if (!result.ok) throw new Error("the schema defaults are not a valid config");
|
|
1093
|
+
return result.value.config;
|
|
1094
|
+
}
|
|
1095
|
+
var perfDefaults = deepFreeze(resolveDefaults());
|
|
1096
|
+
|
|
1097
|
+
export { DEFAULT_CONFIG, Sink, anyObject, arr, bool, child, constant, count, definePerfConfig, derivationSettings, enumOf, envLabelOrNull, epochMs, evaluationStatus, fingerprint, hostFingerprint, int, isRecord, isoDate, issue, key, kind, mode, ms, msLimit, msOrNull, nul, nullable, num, obj, oneOf, packageConfig, percentileName, perfDefaults, ratio, record, resolveConfig, runId, str, testsStatus, timestamp, tool };
|