@grow-codes/grafana-loki 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +81 -0
- package/README.md +47 -2
- package/lib/chunk-553Q2KB5.cjs +564 -0
- package/lib/chunk-553Q2KB5.cjs.map +1 -0
- package/lib/chunk-KTHP35QG.js +526 -0
- package/lib/chunk-KTHP35QG.js.map +1 -0
- package/lib/index.cjs +3874 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +1342 -0
- package/lib/index.d.ts +1342 -0
- package/lib/index.js +3621 -0
- package/lib/index.js.map +1 -0
- package/lib/query-CofVHbt1.d.cts +471 -0
- package/lib/query-CofVHbt1.d.ts +471 -0
- package/lib/testing/index.cjs +674 -0
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +296 -0
- package/lib/testing/index.d.ts +296 -0
- package/lib/testing/index.js +649 -0
- package/lib/testing/index.js.map +1 -0
- package/package.json +118 -4
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk553Q2KB5_cjs = require('../chunk-553Q2KB5.cjs');
|
|
4
|
+
var util = require('util');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
// src/testing/core-ops.ts
|
|
9
|
+
var coreOps = {
|
|
10
|
+
ops: {
|
|
11
|
+
health: (client) => client.health(),
|
|
12
|
+
ping: (client) => client.ping(),
|
|
13
|
+
serverVersion: (client) => client.serverVersion(),
|
|
14
|
+
close: (client) => client.close()
|
|
15
|
+
},
|
|
16
|
+
dispose: (client) => client.close()
|
|
17
|
+
};
|
|
18
|
+
function toPlain(value) {
|
|
19
|
+
if (value instanceof Map) {
|
|
20
|
+
return Object.fromEntries([...value.entries()].map(([k, v]) => [String(k), toPlain(v)]));
|
|
21
|
+
}
|
|
22
|
+
if (value instanceof Set) return [...value].map(toPlain);
|
|
23
|
+
if (Array.isArray(value)) return value.map(toPlain);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function subsetEquals(actual, expected) {
|
|
27
|
+
const a = toPlain(actual);
|
|
28
|
+
if (Array.isArray(expected)) {
|
|
29
|
+
return Array.isArray(a) && a.length === expected.length && expected.every((e, i) => subsetEquals(a[i], e));
|
|
30
|
+
}
|
|
31
|
+
if (expected !== null && typeof expected === "object") {
|
|
32
|
+
if (a === null || typeof a !== "object" || Array.isArray(a)) return false;
|
|
33
|
+
const obj = a;
|
|
34
|
+
return Object.entries(expected).every(([k, v]) => subsetEquals(obj[k], v));
|
|
35
|
+
}
|
|
36
|
+
return util.isDeepStrictEqual(a, expected);
|
|
37
|
+
}
|
|
38
|
+
function sizeOf(value) {
|
|
39
|
+
if (Array.isArray(value)) return value.length;
|
|
40
|
+
if (value instanceof Map || value instanceof Set) return value.size;
|
|
41
|
+
if (typeof value === "string") return value.length;
|
|
42
|
+
if (value !== null && typeof value === "object") {
|
|
43
|
+
const obj = value;
|
|
44
|
+
if (Array.isArray(obj.spans)) return obj.spans.length;
|
|
45
|
+
if (Array.isArray(obj.records)) return obj.records.length;
|
|
46
|
+
return Object.keys(obj).length;
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`cannot count a ${value === null ? "null" : typeof value}`);
|
|
49
|
+
}
|
|
50
|
+
function stringForms(value) {
|
|
51
|
+
const forms = [];
|
|
52
|
+
try {
|
|
53
|
+
forms.push(String(value));
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const json = JSON.stringify(toPlain(value));
|
|
58
|
+
if (typeof json === "string") forms.push(json);
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
forms.push(util.inspect(value, { depth: 20, maxArrayLength: null, maxStringLength: null }));
|
|
62
|
+
return forms;
|
|
63
|
+
}
|
|
64
|
+
function sortKey(item) {
|
|
65
|
+
if (typeof item === "string") return item;
|
|
66
|
+
if (item !== null && typeof item === "object") {
|
|
67
|
+
const obj = item;
|
|
68
|
+
if (typeof obj.name === "string") return obj.name;
|
|
69
|
+
if (typeof obj.id === "string") return obj.id;
|
|
70
|
+
}
|
|
71
|
+
return String(item);
|
|
72
|
+
}
|
|
73
|
+
function containsValue(actual, needle) {
|
|
74
|
+
if (typeof actual === "string") return typeof needle === "string" && actual.includes(needle);
|
|
75
|
+
const list = actual instanceof Map ? [...actual.keys()] : actual instanceof Set ? [...actual] : actual;
|
|
76
|
+
if (Array.isArray(list))
|
|
77
|
+
return list.some(
|
|
78
|
+
(item) => util.isDeepStrictEqual(item, needle) || needle !== null && typeof needle === "object" && subsetEquals(item, needle)
|
|
79
|
+
);
|
|
80
|
+
if (actual !== null && typeof actual === "object" && typeof needle === "string")
|
|
81
|
+
return needle in actual;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
function typeName(value) {
|
|
85
|
+
if (Array.isArray(value)) return "array";
|
|
86
|
+
if (value === null) return "null";
|
|
87
|
+
return typeof value;
|
|
88
|
+
}
|
|
89
|
+
function checkTree(value, tree) {
|
|
90
|
+
const spans = value?.spans;
|
|
91
|
+
if (!Array.isArray(spans)) throw new Error("tree: result has no spans");
|
|
92
|
+
const list = spans;
|
|
93
|
+
for (const [parentName, children] of Object.entries(tree)) {
|
|
94
|
+
const parents = list.filter((s) => s.name === parentName);
|
|
95
|
+
if (parents.length === 0) throw new Error(`tree: no span named "${parentName}"`);
|
|
96
|
+
const ids = new Set(parents.map((p) => p.spanId));
|
|
97
|
+
const actual = list.filter((s) => s.parentSpanId !== void 0 && ids.has(s.parentSpanId)).map((s) => s.name);
|
|
98
|
+
const absent = children.filter((c) => !actual.includes(c));
|
|
99
|
+
if (absent.length > 0) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`tree: "${parentName}" lacks children ${JSON.stringify(absent)} (has ${JSON.stringify(actual)})`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function describe(value) {
|
|
107
|
+
return util.inspect(value, { depth: 4, breakLength: Infinity });
|
|
108
|
+
}
|
|
109
|
+
function checkExpectations(value, expect) {
|
|
110
|
+
if (expect.reveal !== void 0) {
|
|
111
|
+
const v = value;
|
|
112
|
+
if (typeof v?.reveal !== "function") throw new Error("reveal: result is not a SecretValue");
|
|
113
|
+
if (v.reveal() !== expect.reveal)
|
|
114
|
+
throw new Error("reveal: value differs from the expected text");
|
|
115
|
+
}
|
|
116
|
+
if ("equals" in expect && !subsetEquals(value, expect.equals)) {
|
|
117
|
+
throw new Error(`equals: expected ${describe(expect.equals)}, got ${describe(value)}`);
|
|
118
|
+
}
|
|
119
|
+
if (expect.null === true && value !== null && value !== void 0)
|
|
120
|
+
throw new Error(`null: got ${describe(value)}`);
|
|
121
|
+
if (expect.notNull === true && (value === null || value === void 0))
|
|
122
|
+
throw new Error("notNull: got null");
|
|
123
|
+
if (expect.true === true && value !== true) throw new Error(`true: got ${describe(value)}`);
|
|
124
|
+
if (expect.false === true && value !== false) throw new Error(`false: got ${describe(value)}`);
|
|
125
|
+
if ("contains" in expect && !containsValue(value, expect.contains)) {
|
|
126
|
+
throw new Error(`contains: ${describe(expect.contains)} not found in ${describe(value)}`);
|
|
127
|
+
}
|
|
128
|
+
if ("notContains" in expect && containsValue(value, expect.notContains)) {
|
|
129
|
+
throw new Error(`notContains: ${describe(expect.notContains)} found`);
|
|
130
|
+
}
|
|
131
|
+
if (expect.count !== void 0 && sizeOf(value) !== expect.count) {
|
|
132
|
+
throw new Error(`count: expected ${expect.count}, got ${sizeOf(value)}`);
|
|
133
|
+
}
|
|
134
|
+
if (expect.minCount !== void 0 && sizeOf(value) < expect.minCount) {
|
|
135
|
+
throw new Error(`minCount: expected >= ${expect.minCount}, got ${sizeOf(value)}`);
|
|
136
|
+
}
|
|
137
|
+
if (expect.sorted === true) {
|
|
138
|
+
if (!Array.isArray(value)) throw new Error("sorted: result is not an array");
|
|
139
|
+
const keys = value.map(sortKey);
|
|
140
|
+
for (let i = 1; i < keys.length; i++) {
|
|
141
|
+
if (keys[i - 1] > keys[i])
|
|
142
|
+
throw new Error(`sorted: "${keys[i - 1]}" before "${keys[i]}"`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (expect.type !== void 0 && typeName(value) !== expect.type) {
|
|
146
|
+
throw new Error(`type: expected ${expect.type}, got ${typeName(value)}`);
|
|
147
|
+
}
|
|
148
|
+
if (expect.stringForm !== void 0) {
|
|
149
|
+
const forms = stringForms(value);
|
|
150
|
+
const { contains, notContains } = expect.stringForm;
|
|
151
|
+
if (notContains !== void 0 && forms.some((f) => f.includes(notContains))) {
|
|
152
|
+
throw new Error("stringForm: the string form contains a forbidden value");
|
|
153
|
+
}
|
|
154
|
+
if (contains !== void 0 && !forms.some((f) => f.includes(contains))) {
|
|
155
|
+
throw new Error(`stringForm: no string form contains ${JSON.stringify(contains)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (expect.tree !== void 0) checkTree(value, expect.tree);
|
|
159
|
+
}
|
|
160
|
+
async function pollForExpectation(fn, args, context, options = {}) {
|
|
161
|
+
const expect = context.step.expect;
|
|
162
|
+
if (expect === void 0 || expect.error !== void 0) return fn();
|
|
163
|
+
const expectation = context.substitute(expect);
|
|
164
|
+
let last;
|
|
165
|
+
try {
|
|
166
|
+
return await chunk553Q2KB5_cjs.pollUntil(
|
|
167
|
+
async () => {
|
|
168
|
+
last = { value: await fn() };
|
|
169
|
+
return last.value;
|
|
170
|
+
},
|
|
171
|
+
(value) => {
|
|
172
|
+
try {
|
|
173
|
+
checkExpectations(value, expectation);
|
|
174
|
+
return true;
|
|
175
|
+
} catch {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : options.defaultTimeoutMs ?? 6e4,
|
|
181
|
+
intervalMs: typeof args.intervalMs === "number" ? args.intervalMs : 1e3,
|
|
182
|
+
operation: options.operation ?? "poll"
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (error instanceof chunk553Q2KB5_cjs.TimeoutError && last !== void 0) return last.value;
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/testing/logging-ops.ts
|
|
192
|
+
function replaceIndex(value, index) {
|
|
193
|
+
if (typeof value === "string") return value.replaceAll("#{i}", String(index));
|
|
194
|
+
if (Array.isArray(value)) return value.map((v) => replaceIndex(v, index));
|
|
195
|
+
if (value !== null && typeof value === "object") {
|
|
196
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, replaceIndex(v, index)]));
|
|
197
|
+
}
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
function logInputFromArgs(args) {
|
|
201
|
+
if (typeof args.message !== "string")
|
|
202
|
+
throw new chunk553Q2KB5_cjs.ValidationError("logging op: message must be a string");
|
|
203
|
+
const input = { message: args.message };
|
|
204
|
+
if (args.severity !== void 0) {
|
|
205
|
+
const severity = typeof args.severity === "string" || typeof args.severity === "number" ? chunk553Q2KB5_cjs.parseSeverity(args.severity) : null;
|
|
206
|
+
if (severity === null) throw new chunk553Q2KB5_cjs.ValidationError("logging op: invalid severity");
|
|
207
|
+
input.severity = severity;
|
|
208
|
+
} else {
|
|
209
|
+
input.severity = 9 /* Info */;
|
|
210
|
+
}
|
|
211
|
+
if (typeof args.attributes === "object" && args.attributes !== null) {
|
|
212
|
+
input.attributes = chunk553Q2KB5_cjs.toAttributes(args.attributes);
|
|
213
|
+
}
|
|
214
|
+
if (typeof args.traceId === "string") input.traceId = args.traceId;
|
|
215
|
+
if (typeof args.spanId === "string") input.spanId = args.spanId;
|
|
216
|
+
return input;
|
|
217
|
+
}
|
|
218
|
+
function requireQuery(target) {
|
|
219
|
+
if (target.query === null)
|
|
220
|
+
throw new chunk553Q2KB5_cjs.UnsupportedError("logging: this service has no query client");
|
|
221
|
+
return target.query;
|
|
222
|
+
}
|
|
223
|
+
async function searchAll(query, text, want) {
|
|
224
|
+
const records = [];
|
|
225
|
+
let cursor;
|
|
226
|
+
do {
|
|
227
|
+
const page = await query.search(text, {
|
|
228
|
+
limit: Math.min(Math.max(want, 100), 1e3),
|
|
229
|
+
...cursor === void 0 ? {} : { cursor }
|
|
230
|
+
});
|
|
231
|
+
records.push(...page.records);
|
|
232
|
+
cursor = page.nextCursor;
|
|
233
|
+
} while (cursor !== void 0 && records.length < want);
|
|
234
|
+
return records;
|
|
235
|
+
}
|
|
236
|
+
var loggingOps = {
|
|
237
|
+
ops: {
|
|
238
|
+
send: (target, args) => {
|
|
239
|
+
target.client.send(logInputFromArgs(args));
|
|
240
|
+
},
|
|
241
|
+
sendBatch: (target, args) => {
|
|
242
|
+
const count = typeof args.count === "number" ? args.count : 1;
|
|
243
|
+
const records = [];
|
|
244
|
+
for (let i = 0; i < count; i++)
|
|
245
|
+
records.push(logInputFromArgs(replaceIndex(args, i)));
|
|
246
|
+
target.client.sendBatch(records);
|
|
247
|
+
},
|
|
248
|
+
flush: (target, args) => target.client.flush(typeof args.timeoutMs === "number" ? args.timeoutMs : void 0),
|
|
249
|
+
stats: (target) => target.client.stats(),
|
|
250
|
+
searchUntil: async (target, args) => {
|
|
251
|
+
const query = requireQuery(target);
|
|
252
|
+
const text = typeof args.query === "string" ? args.query : "";
|
|
253
|
+
const minCount = typeof args.minCount === "number" ? args.minCount : 1;
|
|
254
|
+
let last = [];
|
|
255
|
+
try {
|
|
256
|
+
return await chunk553Q2KB5_cjs.pollUntil(
|
|
257
|
+
async () => {
|
|
258
|
+
last = await searchAll(query, text, minCount);
|
|
259
|
+
return last;
|
|
260
|
+
},
|
|
261
|
+
(records) => records.length >= minCount,
|
|
262
|
+
{
|
|
263
|
+
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : 3e4,
|
|
264
|
+
intervalMs: typeof args.intervalMs === "number" ? args.intervalMs : 1e3,
|
|
265
|
+
operation: "logging.searchUntil"
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (error instanceof chunk553Q2KB5_cjs.TimeoutError) return last;
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
dispose: (target) => target.client.close()
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// src/testing/ops.ts
|
|
278
|
+
var builtinOps = Object.freeze({
|
|
279
|
+
core: coreOps,
|
|
280
|
+
logging: loggingOps
|
|
281
|
+
});
|
|
282
|
+
var registry = /* @__PURE__ */ new Map();
|
|
283
|
+
function registerOps(category, ops) {
|
|
284
|
+
const normalized = isCategoryOps(ops) ? ops : { ops };
|
|
285
|
+
const prev = registry.get(category);
|
|
286
|
+
registry.set(category, prev === void 0 ? normalized : mergeOps(prev, normalized));
|
|
287
|
+
}
|
|
288
|
+
function resetRegisteredOps() {
|
|
289
|
+
registry.clear();
|
|
290
|
+
}
|
|
291
|
+
function isCategoryOps(value) {
|
|
292
|
+
return typeof value.ops === "object" && typeof value.ops !== "function";
|
|
293
|
+
}
|
|
294
|
+
function mergeOps(base, over) {
|
|
295
|
+
const merged = { ops: { ...base.ops, ...over.ops } };
|
|
296
|
+
const dispose = over.dispose ?? base.dispose;
|
|
297
|
+
const variables = over.variables ?? base.variables;
|
|
298
|
+
if (dispose !== void 0) merged.dispose = dispose;
|
|
299
|
+
if (variables !== void 0) merged.variables = variables;
|
|
300
|
+
return merged;
|
|
301
|
+
}
|
|
302
|
+
function resolveOps(category, extra) {
|
|
303
|
+
let ops = builtinOps[category];
|
|
304
|
+
const registered = registry.get(category);
|
|
305
|
+
if (registered !== void 0) ops = ops === void 0 ? registered : mergeOps(ops, registered);
|
|
306
|
+
const more = extra?.[category];
|
|
307
|
+
if (more !== void 0) {
|
|
308
|
+
const normalized = isCategoryOps(more) ? more : { ops: more };
|
|
309
|
+
ops = ops === void 0 ? normalized : mergeOps(ops, normalized);
|
|
310
|
+
}
|
|
311
|
+
return ops;
|
|
312
|
+
}
|
|
313
|
+
function randomRunId() {
|
|
314
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
315
|
+
let out = "";
|
|
316
|
+
for (let i = 0; i < 8; i++)
|
|
317
|
+
out += alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
318
|
+
return out;
|
|
319
|
+
}
|
|
320
|
+
function loadScenarios(scenariosDir) {
|
|
321
|
+
const files = fs.readdirSync(scenariosDir).filter((f) => f.endsWith(".json"));
|
|
322
|
+
const scenarios = files.map((f) => {
|
|
323
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(scenariosDir, f), "utf8"));
|
|
324
|
+
if (typeof parsed.id !== "string" || typeof parsed.category !== "string" || !Array.isArray(parsed.steps)) {
|
|
325
|
+
throw new Error(`invalid scenario file ${f}`);
|
|
326
|
+
}
|
|
327
|
+
return parsed;
|
|
328
|
+
});
|
|
329
|
+
return scenarios.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
330
|
+
}
|
|
331
|
+
var VAR = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
332
|
+
var WHOLE_VAR = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;
|
|
333
|
+
function substitute(value, vars) {
|
|
334
|
+
const lookup = (name) => {
|
|
335
|
+
if (!(name in vars)) throw new Error(`unknown variable \${${name}}`);
|
|
336
|
+
return vars[name];
|
|
337
|
+
};
|
|
338
|
+
const walk = (v) => {
|
|
339
|
+
if (typeof v === "string") {
|
|
340
|
+
const whole = WHOLE_VAR.exec(v);
|
|
341
|
+
if (whole !== null) return lookup(whole[1]);
|
|
342
|
+
return v.replace(VAR, (_m, name) => String(lookup(name)));
|
|
343
|
+
}
|
|
344
|
+
if (Array.isArray(v)) return v.map(walk);
|
|
345
|
+
if (v !== null && typeof v === "object") {
|
|
346
|
+
return Object.fromEntries(
|
|
347
|
+
Object.entries(v).map(([k, x]) => [
|
|
348
|
+
k.replace(VAR, (_m, name) => String(lookup(name))),
|
|
349
|
+
walk(x)
|
|
350
|
+
])
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
return v;
|
|
354
|
+
};
|
|
355
|
+
return walk(value);
|
|
356
|
+
}
|
|
357
|
+
function capabilitySet(options, category) {
|
|
358
|
+
const caps = options.capabilities;
|
|
359
|
+
if (caps === void 0) return /* @__PURE__ */ new Set();
|
|
360
|
+
if (Array.isArray(caps)) return new Set(caps);
|
|
361
|
+
return new Set(caps[category] ?? []);
|
|
362
|
+
}
|
|
363
|
+
function missing(requires, caps) {
|
|
364
|
+
return (requires ?? []).filter((r) => !caps.has(r));
|
|
365
|
+
}
|
|
366
|
+
function message(err) {
|
|
367
|
+
if (err instanceof Error) {
|
|
368
|
+
const code = err.code;
|
|
369
|
+
return typeof code === "string" ? `${code}: ${err.message}` : err.message;
|
|
370
|
+
}
|
|
371
|
+
return String(err);
|
|
372
|
+
}
|
|
373
|
+
function planScenarios(options) {
|
|
374
|
+
const categories = new Set(options.categories ?? Object.keys(options.factories));
|
|
375
|
+
for (const c of categories) {
|
|
376
|
+
if (options.factories[c] === void 0) {
|
|
377
|
+
throw new Error(`conformance: no factory for category "${c}"`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return loadScenarios(options.scenariosDir).filter((s) => categories.has(s.category)).filter((s) => options.only === void 0 || options.only.includes(s.id)).map((scenario) => {
|
|
381
|
+
const lacking = missing(scenario.requires, capabilitySet(options, scenario.category));
|
|
382
|
+
return lacking.length > 0 ? { scenario, skipReason: `missing capabilities: ${lacking.join(", ")}` } : { scenario };
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
async function runScenario(scenario, options) {
|
|
386
|
+
const started = performance.now();
|
|
387
|
+
const caps = capabilitySet(options, scenario.category);
|
|
388
|
+
const result = {
|
|
389
|
+
id: scenario.id,
|
|
390
|
+
category: scenario.category,
|
|
391
|
+
status: "passed",
|
|
392
|
+
steps: [],
|
|
393
|
+
durationMs: 0
|
|
394
|
+
};
|
|
395
|
+
const lacking = missing(scenario.requires, caps);
|
|
396
|
+
if (lacking.length > 0) {
|
|
397
|
+
result.status = "skipped";
|
|
398
|
+
result.skipReason = `missing capabilities: ${lacking.join(", ")}`;
|
|
399
|
+
return result;
|
|
400
|
+
}
|
|
401
|
+
const category = resolveOps(scenario.category, options.ops);
|
|
402
|
+
const factory = options.factories[scenario.category];
|
|
403
|
+
if (category === void 0 || factory === void 0) {
|
|
404
|
+
result.status = "failed";
|
|
405
|
+
result.error = category === void 0 ? `no op handlers for category "${scenario.category}"` : `no factory for category "${scenario.category}"`;
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
const run = (options.runId ?? randomRunId)();
|
|
409
|
+
const vars = { ...options.variables, run };
|
|
410
|
+
const prefix = substitute(options.prefix ?? "grow-conformance/${run}/", vars);
|
|
411
|
+
vars.prefix = prefix;
|
|
412
|
+
const cleanups = [];
|
|
413
|
+
let currentStep = scenario.steps[0] ?? { op: "" };
|
|
414
|
+
const context = {
|
|
415
|
+
scenario,
|
|
416
|
+
get step() {
|
|
417
|
+
return currentStep;
|
|
418
|
+
},
|
|
419
|
+
run,
|
|
420
|
+
prefix,
|
|
421
|
+
vars,
|
|
422
|
+
capabilities: caps,
|
|
423
|
+
substitute: (v) => substitute(v, vars),
|
|
424
|
+
onCleanup: (fn) => {
|
|
425
|
+
cleanups.push(fn);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
let target;
|
|
429
|
+
try {
|
|
430
|
+
target = await factory({
|
|
431
|
+
scenario,
|
|
432
|
+
run,
|
|
433
|
+
prefix,
|
|
434
|
+
...scenario.batchOptions === void 0 ? {} : { batchOptions: scenario.batchOptions }
|
|
435
|
+
});
|
|
436
|
+
Object.assign(vars, category.variables?.(target) ?? {}, { ...options.variables, run, prefix });
|
|
437
|
+
for (const [index, step] of scenario.steps.entries()) {
|
|
438
|
+
currentStep = step;
|
|
439
|
+
const stepStart = performance.now();
|
|
440
|
+
const stepResult = { index, op: step.op, status: "passed", durationMs: 0 };
|
|
441
|
+
result.steps.push(stepResult);
|
|
442
|
+
const stepLacking = missing(step.requires, caps);
|
|
443
|
+
if (stepLacking.length > 0) {
|
|
444
|
+
stepResult.status = "skipped";
|
|
445
|
+
stepResult.skipReason = `missing capabilities: ${stepLacking.join(", ")}`;
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
const handler = category.ops[step.op];
|
|
450
|
+
if (handler === void 0)
|
|
451
|
+
throw new Error(`unknown op "${step.op}" for category ${scenario.category}`);
|
|
452
|
+
const args = substitute(step.args ?? {}, vars);
|
|
453
|
+
const expectation = step.expect === void 0 ? void 0 : substitute(step.expect, vars);
|
|
454
|
+
let value;
|
|
455
|
+
let thrown;
|
|
456
|
+
let failed = false;
|
|
457
|
+
try {
|
|
458
|
+
value = await handler(target, args, context);
|
|
459
|
+
} catch (err) {
|
|
460
|
+
failed = true;
|
|
461
|
+
thrown = err;
|
|
462
|
+
}
|
|
463
|
+
if (expectation?.error !== void 0) {
|
|
464
|
+
if (!failed) throw new Error(`expected error ${expectation.error} but the op succeeded`);
|
|
465
|
+
const code = thrown.code;
|
|
466
|
+
if (code !== expectation.error) {
|
|
467
|
+
throw new Error(`expected error ${expectation.error}, got ${message(thrown)}`);
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
if (failed) throw thrown;
|
|
471
|
+
if (expectation !== void 0) checkExpectations(value, expectation);
|
|
472
|
+
if (step.save !== void 0) vars[step.save] = value;
|
|
473
|
+
}
|
|
474
|
+
} catch (err) {
|
|
475
|
+
stepResult.status = "failed";
|
|
476
|
+
stepResult.error = message(err);
|
|
477
|
+
result.status = "failed";
|
|
478
|
+
result.error = `step ${index} (${step.op}): ${stepResult.error}`;
|
|
479
|
+
break;
|
|
480
|
+
} finally {
|
|
481
|
+
stepResult.durationMs = performance.now() - stepStart;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
} catch (err) {
|
|
485
|
+
result.status = "failed";
|
|
486
|
+
result.error = `setup: ${message(err)}`;
|
|
487
|
+
} finally {
|
|
488
|
+
if (target !== void 0 && category.dispose !== void 0) {
|
|
489
|
+
try {
|
|
490
|
+
await category.dispose(target, context);
|
|
491
|
+
} catch (err) {
|
|
492
|
+
if (result.status !== "failed") {
|
|
493
|
+
result.status = "failed";
|
|
494
|
+
result.error = `dispose: ${message(err)}`;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
for (const fn of cleanups.reverse()) {
|
|
499
|
+
try {
|
|
500
|
+
await fn();
|
|
501
|
+
} catch {
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
result.durationMs = performance.now() - started;
|
|
505
|
+
}
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
async function runConformance(options) {
|
|
509
|
+
const results = [];
|
|
510
|
+
for (const { scenario } of planScenarios(options)) {
|
|
511
|
+
results.push(await runScenario(scenario, options));
|
|
512
|
+
}
|
|
513
|
+
const count = (s) => results.filter((r) => r.status === s).length;
|
|
514
|
+
const failed = count("failed");
|
|
515
|
+
return { ok: failed === 0, passed: count("passed"), failed, skipped: count("skipped"), results };
|
|
516
|
+
}
|
|
517
|
+
function formatReport(report) {
|
|
518
|
+
const lines = report.results.map((r) => {
|
|
519
|
+
const extra = r.status === "failed" ? ` \u2014 ${r.error ?? ""}` : r.status === "skipped" ? ` \u2014 ${r.skipReason ?? ""}` : "";
|
|
520
|
+
const skippedSteps = r.steps.filter((s) => s.status === "skipped").map((s) => `${s.op}#${s.index}`);
|
|
521
|
+
const stepNote = skippedSteps.length > 0 ? ` (skipped steps: ${skippedSteps.join(", ")})` : "";
|
|
522
|
+
return `${r.status.toUpperCase().padEnd(7)} ${r.id}${extra}${stepNote}`;
|
|
523
|
+
});
|
|
524
|
+
lines.push(`passed ${report.passed}, failed ${report.failed}, skipped ${report.skipped}`);
|
|
525
|
+
return lines.join("\n");
|
|
526
|
+
}
|
|
527
|
+
function assertConformance(report) {
|
|
528
|
+
if (!report.ok) throw new Error(`conformance failed:
|
|
529
|
+
${formatReport(report)}`);
|
|
530
|
+
}
|
|
531
|
+
function conformanceCases(options) {
|
|
532
|
+
return planScenarios(options).map(({ scenario, skipReason }) => ({
|
|
533
|
+
id: scenario.id,
|
|
534
|
+
category: scenario.category,
|
|
535
|
+
...skipReason === void 0 ? {} : { skip: skipReason },
|
|
536
|
+
run: async () => {
|
|
537
|
+
const result = await runScenario(scenario, options);
|
|
538
|
+
if (result.status === "failed")
|
|
539
|
+
throw new Error(`${scenario.id}: ${result.error ?? "failed"}`);
|
|
540
|
+
return result;
|
|
541
|
+
}
|
|
542
|
+
}));
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// src/testing/memory-logs.ts
|
|
546
|
+
var MemoryLogExporter = class {
|
|
547
|
+
/** Records accepted so far, in export order. */
|
|
548
|
+
records = [];
|
|
549
|
+
/** Every batch passed to `export`, as received. */
|
|
550
|
+
batches = [];
|
|
551
|
+
/** `gzip` flag of every export call. */
|
|
552
|
+
gzipFlags = [];
|
|
553
|
+
shutdownCalls = 0;
|
|
554
|
+
delayMs;
|
|
555
|
+
#script = [];
|
|
556
|
+
constructor(options = {}) {
|
|
557
|
+
this.delayMs = options.delayMs ?? 0;
|
|
558
|
+
}
|
|
559
|
+
/** Makes the next export calls throw `error` (`times` calls, default 1). */
|
|
560
|
+
failNext(error, times = 1) {
|
|
561
|
+
for (let i = 0; i < times; i++) this.#script.push({ throw: error });
|
|
562
|
+
return this;
|
|
563
|
+
}
|
|
564
|
+
/** Makes the next export call return a custom result (records are not stored). */
|
|
565
|
+
resultNext(result) {
|
|
566
|
+
this.#script.push({ result });
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
569
|
+
async export(records, opts) {
|
|
570
|
+
this.batches.push(records);
|
|
571
|
+
this.gzipFlags.push(opts.gzip);
|
|
572
|
+
if (this.delayMs > 0) await delay(this.delayMs, opts.signal);
|
|
573
|
+
if (opts.signal?.aborted === true) throw new chunk553Q2KB5_cjs.CancelledError("memory.export: cancelled");
|
|
574
|
+
const next = this.#script.shift();
|
|
575
|
+
if (next !== void 0) {
|
|
576
|
+
if ("throw" in next) throw next.throw;
|
|
577
|
+
return next.result(records);
|
|
578
|
+
}
|
|
579
|
+
for (const record of records)
|
|
580
|
+
this.records.push(chunk553Q2KB5_cjs.logRecordFromJson(JSON.parse(JSON.stringify(chunk553Q2KB5_cjs.logRecordToJson(record)))));
|
|
581
|
+
return { accepted: records.length, rejected: 0 };
|
|
582
|
+
}
|
|
583
|
+
shutdown() {
|
|
584
|
+
this.shutdownCalls += 1;
|
|
585
|
+
return Promise.resolve();
|
|
586
|
+
}
|
|
587
|
+
/** Forgets stored records, batches and scripted outcomes. */
|
|
588
|
+
reset() {
|
|
589
|
+
this.records.length = 0;
|
|
590
|
+
this.batches.length = 0;
|
|
591
|
+
this.gzipFlags.length = 0;
|
|
592
|
+
this.#script.length = 0;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
function delay(ms, signal) {
|
|
596
|
+
return new Promise((resolve) => {
|
|
597
|
+
const timer = setTimeout(done, ms);
|
|
598
|
+
timer.unref();
|
|
599
|
+
function done() {
|
|
600
|
+
clearTimeout(timer);
|
|
601
|
+
signal?.removeEventListener("abort", done);
|
|
602
|
+
resolve();
|
|
603
|
+
}
|
|
604
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
var MemoryLogQueryClient = class extends chunk553Q2KB5_cjs.BaseLogQueryClient {
|
|
608
|
+
#source;
|
|
609
|
+
#streams;
|
|
610
|
+
constructor(source, options = {}) {
|
|
611
|
+
super();
|
|
612
|
+
this.#source = source;
|
|
613
|
+
this.#streams = options.streams ?? ["default"];
|
|
614
|
+
}
|
|
615
|
+
search(query, opts = {}) {
|
|
616
|
+
if (opts.signal?.aborted === true)
|
|
617
|
+
return Promise.reject(new chunk553Q2KB5_cjs.CancelledError("memory.search: cancelled"));
|
|
618
|
+
const terms = query.trim() === "*" ? [] : query.toLowerCase().split(/\s+/).filter((t) => t !== "");
|
|
619
|
+
const start = opts.start?.getTime() ?? -Infinity;
|
|
620
|
+
const end = opts.end?.getTime() ?? Infinity;
|
|
621
|
+
const matches = this.#source.records.filter((r) => {
|
|
622
|
+
const t = r.timestamp.getTime();
|
|
623
|
+
if (t < start || t > end) return false;
|
|
624
|
+
const text = `${r.body}
|
|
625
|
+
${JSON.stringify(r.attributes)}`.toLowerCase();
|
|
626
|
+
return terms.every((term) => text.includes(term));
|
|
627
|
+
}).sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
|
|
628
|
+
if ((opts.order ?? "desc") === "desc") matches.reverse();
|
|
629
|
+
const offset = opts.cursor === void 0 ? 0 : Number.parseInt(opts.cursor, 10) || 0;
|
|
630
|
+
const limit = opts.limit ?? 100;
|
|
631
|
+
const records = matches.slice(offset, offset + limit);
|
|
632
|
+
const result = { records, total: matches.length };
|
|
633
|
+
if (offset + limit < matches.length) result.nextCursor = String(offset + limit);
|
|
634
|
+
return Promise.resolve(result);
|
|
635
|
+
}
|
|
636
|
+
listStreams() {
|
|
637
|
+
return Promise.resolve([...this.#streams]);
|
|
638
|
+
}
|
|
639
|
+
listLabels() {
|
|
640
|
+
const labels = /* @__PURE__ */ new Set();
|
|
641
|
+
for (const r of this.#source.records) {
|
|
642
|
+
for (const key of Object.keys(r.attributes)) labels.add(key);
|
|
643
|
+
for (const key of Object.keys(r.resource)) labels.add(key);
|
|
644
|
+
}
|
|
645
|
+
return Promise.resolve([...labels].sort());
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
exports.MemoryLogExporter = MemoryLogExporter;
|
|
650
|
+
exports.MemoryLogQueryClient = MemoryLogQueryClient;
|
|
651
|
+
exports.assertConformance = assertConformance;
|
|
652
|
+
exports.builtinOps = builtinOps;
|
|
653
|
+
exports.checkExpectations = checkExpectations;
|
|
654
|
+
exports.conformanceCases = conformanceCases;
|
|
655
|
+
exports.coreOps = coreOps;
|
|
656
|
+
exports.formatReport = formatReport;
|
|
657
|
+
exports.loadScenarios = loadScenarios;
|
|
658
|
+
exports.logInputFromArgs = logInputFromArgs;
|
|
659
|
+
exports.loggingOps = loggingOps;
|
|
660
|
+
exports.planScenarios = planScenarios;
|
|
661
|
+
exports.pollForExpectation = pollForExpectation;
|
|
662
|
+
exports.randomRunId = randomRunId;
|
|
663
|
+
exports.registerOps = registerOps;
|
|
664
|
+
exports.resetRegisteredOps = resetRegisteredOps;
|
|
665
|
+
exports.resolveOps = resolveOps;
|
|
666
|
+
exports.runConformance = runConformance;
|
|
667
|
+
exports.runScenario = runScenario;
|
|
668
|
+
exports.sizeOf = sizeOf;
|
|
669
|
+
exports.stringForms = stringForms;
|
|
670
|
+
exports.subsetEquals = subsetEquals;
|
|
671
|
+
exports.substitute = substitute;
|
|
672
|
+
exports.toPlain = toPlain;
|
|
673
|
+
//# sourceMappingURL=index.cjs.map
|
|
674
|
+
//# sourceMappingURL=index.cjs.map
|