@flemist/test-variants 5.0.4 → 5.0.6
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/build/browser/index.cjs +1 -1
- package/build/browser/index.mjs +1 -1
- package/build/common/index.cjs +1 -1
- package/build/common/index.mjs +1 -1
- package/build/{createTestVariants-D3rpiTL9.mjs → createTestVariants-BzKl5Eff.mjs} +132 -138
- package/build/createTestVariants-DdR2pUe_.js +4 -0
- package/build/node/index.cjs +1 -1
- package/build/node/index.mjs +1 -1
- package/package.json +1 -1
- package/build/createTestVariants-cAlu7ujN.js +0 -4
package/build/browser/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../createTestVariants-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../createTestVariants-DdR2pUe_.js");exports.createTestVariants=e.createTestVariants;
|
package/build/browser/index.mjs
CHANGED
package/build/common/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../createTestVariants-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../createTestVariants-DdR2pUe_.js");exports.createTestVariants=e.createTestVariants;
|
package/build/common/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { timeControllerDefault as Q } from "@flemist/time-controller";
|
|
2
|
-
import { formatAny as z, deepCloneJsonLike as
|
|
3
|
-
import { isPromiseLike as M, waitMicrotasks as
|
|
4
|
-
import { AbortError as
|
|
5
|
-
import { poolWait as ae, Pool as
|
|
2
|
+
import { formatAny as z, deepCloneJsonLike as He } from "@flemist/simple-utils";
|
|
3
|
+
import { isPromiseLike as M, waitMicrotasks as Je, combineAbortSignals as ie } from "@flemist/async-utils";
|
|
4
|
+
import { AbortError as Xe, AbortControllerFast as se } from "@flemist/abort-controller-fast";
|
|
5
|
+
import { poolWait as ae, Pool as Ze } from "@flemist/time-limits";
|
|
6
6
|
function Y() {
|
|
7
7
|
if (typeof process < "u" && process.memoryUsage)
|
|
8
8
|
try {
|
|
9
|
-
return process.memoryUsage()
|
|
9
|
+
return process.memoryUsage.rss();
|
|
10
10
|
} catch {
|
|
11
11
|
}
|
|
12
12
|
if (typeof performance < "u") {
|
|
@@ -19,22 +19,22 @@ function Y() {
|
|
|
19
19
|
}
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
function
|
|
22
|
+
const Ke = 1e3, q = [];
|
|
23
|
+
function Qe(e) {
|
|
24
24
|
return z(e, { pretty: !0, maxDepth: 5, maxItems: 50 });
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const n = e.map((t) => typeof t == "string" ? t :
|
|
28
|
-
q.push(n), q.length >
|
|
26
|
+
function Ye(...e) {
|
|
27
|
+
const n = e.map((t) => typeof t == "string" ? t : Qe(t)).join(" ");
|
|
28
|
+
q.push(n), q.length > Ke && q.shift(), console.log(n);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function et() {
|
|
31
31
|
return q.join(`
|
|
32
32
|
`);
|
|
33
33
|
}
|
|
34
|
-
globalThis.__getStressTestLogLast =
|
|
34
|
+
globalThis.__getStressTestLogLast = et;
|
|
35
35
|
const me = (e, n) => {
|
|
36
|
-
|
|
37
|
-
},
|
|
36
|
+
Ye(n);
|
|
37
|
+
}, w = {
|
|
38
38
|
start: !0,
|
|
39
39
|
progress: 5e3,
|
|
40
40
|
completed: !0,
|
|
@@ -42,7 +42,7 @@ const me = (e, n) => {
|
|
|
42
42
|
modeChange: !0,
|
|
43
43
|
debug: !1,
|
|
44
44
|
func: me
|
|
45
|
-
},
|
|
45
|
+
}, tt = {
|
|
46
46
|
start: !1,
|
|
47
47
|
progress: !1,
|
|
48
48
|
completed: !1,
|
|
@@ -52,17 +52,17 @@ const me = (e, n) => {
|
|
|
52
52
|
func: me
|
|
53
53
|
};
|
|
54
54
|
function ge(e) {
|
|
55
|
-
return e === !1 ?
|
|
56
|
-
start: e.start ??
|
|
57
|
-
progress: e.progress ??
|
|
58
|
-
completed: e.completed ??
|
|
59
|
-
error: e.error ??
|
|
60
|
-
modeChange: e.modeChange ??
|
|
61
|
-
debug: e.debug ??
|
|
62
|
-
func: e.func ??
|
|
55
|
+
return e === !1 ? tt : e === !0 || !e ? w : {
|
|
56
|
+
start: e.start ?? w.start,
|
|
57
|
+
progress: e.progress ?? w.progress,
|
|
58
|
+
completed: e.completed ?? w.completed,
|
|
59
|
+
error: e.error ?? w.error,
|
|
60
|
+
modeChange: e.modeChange ?? w.modeChange,
|
|
61
|
+
debug: e.debug ?? w.debug,
|
|
62
|
+
func: e.func ?? w.func
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function rt(e, n) {
|
|
66
66
|
const t = e.now();
|
|
67
67
|
return {
|
|
68
68
|
startTime: t,
|
|
@@ -79,13 +79,13 @@ function nt(e, n) {
|
|
|
79
79
|
prevGcIterationsAsync: 0
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
class T extends
|
|
82
|
+
class T extends Xe {
|
|
83
83
|
}
|
|
84
|
-
const
|
|
84
|
+
const nt = 50, ot = 5;
|
|
85
85
|
function le(e, n) {
|
|
86
86
|
return typeof e == "number" ? { iterationsAsync: 0, iterationsSync: e } : e != null && typeof e == "object" ? e : n ? { iterationsAsync: 1, iterationsSync: 0 } : { iterationsAsync: 0, iterationsSync: 1 };
|
|
87
87
|
}
|
|
88
|
-
function
|
|
88
|
+
function it(e, n) {
|
|
89
89
|
const t = n.log, i = n.pauseDebuggerOnError ?? !0;
|
|
90
90
|
let o = null, a = 0;
|
|
91
91
|
function r(l, u, f) {
|
|
@@ -96,7 +96,9 @@ tests: ${f}
|
|
|
96
96
|
${z(l)}`
|
|
97
97
|
));
|
|
98
98
|
const d = Date.now();
|
|
99
|
-
if (i
|
|
99
|
+
if (i)
|
|
100
|
+
debugger;
|
|
101
|
+
if (Date.now() - d > nt && a < ot) {
|
|
100
102
|
t.func(
|
|
101
103
|
"debug",
|
|
102
104
|
`[test-variants] debug iteration: ${a}`
|
|
@@ -156,7 +158,7 @@ function O(e, n) {
|
|
|
156
158
|
}
|
|
157
159
|
return a ?? o;
|
|
158
160
|
}
|
|
159
|
-
function
|
|
161
|
+
function x(e, n, t) {
|
|
160
162
|
const i = e.argValues[n].length;
|
|
161
163
|
if (i === 0)
|
|
162
164
|
return -1;
|
|
@@ -203,7 +205,7 @@ function pe(e) {
|
|
|
203
205
|
e,
|
|
204
206
|
e.argsNames[r]
|
|
205
207
|
));
|
|
206
|
-
const u =
|
|
208
|
+
const u = x(
|
|
207
209
|
e,
|
|
208
210
|
r,
|
|
209
211
|
r > o
|
|
@@ -222,7 +224,7 @@ function pe(e) {
|
|
|
222
224
|
if (e.argValues[r] == null)
|
|
223
225
|
continue;
|
|
224
226
|
let l = r > o;
|
|
225
|
-
const u =
|
|
227
|
+
const u = x(e, r, l), f = e.indexes[r] + 1;
|
|
226
228
|
if (f <= u) {
|
|
227
229
|
e.indexes[r] = f, e.args[e.argsNames[r]] = e.argValues[r][f], f < u && (l = !0);
|
|
228
230
|
for (let d = r + 1; d < i; d++)
|
|
@@ -232,7 +234,7 @@ function pe(e) {
|
|
|
232
234
|
e,
|
|
233
235
|
e.argsNames[r]
|
|
234
236
|
);
|
|
235
|
-
const d =
|
|
237
|
+
const d = x(e, r, l);
|
|
236
238
|
if (d < 0)
|
|
237
239
|
break;
|
|
238
240
|
e.indexes[r] = 0, e.args[e.argsNames[r]] = e.argValues[r][0], d > 0 && (l = !0);
|
|
@@ -254,7 +256,7 @@ function H(e) {
|
|
|
254
256
|
e,
|
|
255
257
|
e.argsNames[r]
|
|
256
258
|
));
|
|
257
|
-
const u =
|
|
259
|
+
const u = x(
|
|
258
260
|
e,
|
|
259
261
|
r,
|
|
260
262
|
r > o
|
|
@@ -271,7 +273,7 @@ function H(e) {
|
|
|
271
273
|
if (e.argValues[r] == null)
|
|
272
274
|
continue;
|
|
273
275
|
let l = r > o;
|
|
274
|
-
const u =
|
|
276
|
+
const u = x(e, r, l);
|
|
275
277
|
let f = e.indexes[r] - 1;
|
|
276
278
|
if (f > u && (f = u), f >= 0) {
|
|
277
279
|
e.indexes[r] = f, e.args[e.argsNames[r]] = e.argValues[r][f], f < u && (l = !0);
|
|
@@ -282,7 +284,7 @@ function H(e) {
|
|
|
282
284
|
e,
|
|
283
285
|
e.argsNames[r]
|
|
284
286
|
);
|
|
285
|
-
const d =
|
|
287
|
+
const d = x(e, r, l);
|
|
286
288
|
if (d < 0)
|
|
287
289
|
break;
|
|
288
290
|
e.indexes[r] = d, e.args[e.argsNames[r]] = e.argValues[r][d], d > 0 && (l = !0);
|
|
@@ -293,7 +295,7 @@ function H(e) {
|
|
|
293
295
|
}
|
|
294
296
|
return C(e), !1;
|
|
295
297
|
}
|
|
296
|
-
function
|
|
298
|
+
function st(e, n) {
|
|
297
299
|
C(e);
|
|
298
300
|
const t = e.argsNames, i = t.length;
|
|
299
301
|
let o = !1;
|
|
@@ -302,7 +304,7 @@ function at(e, n) {
|
|
|
302
304
|
if (l === void 0)
|
|
303
305
|
return null;
|
|
304
306
|
e.argValues[a] = O(e, r);
|
|
305
|
-
const u =
|
|
307
|
+
const u = x(e, a, o);
|
|
306
308
|
if (u < 0)
|
|
307
309
|
return null;
|
|
308
310
|
const f = U(
|
|
@@ -316,14 +318,14 @@ function at(e, n) {
|
|
|
316
318
|
}
|
|
317
319
|
return V(e) ? null : e.indexes.slice();
|
|
318
320
|
}
|
|
319
|
-
function
|
|
321
|
+
function at(e) {
|
|
320
322
|
const n = e.indexes.length;
|
|
321
323
|
if (n === 0)
|
|
322
324
|
return !1;
|
|
323
325
|
let t = !1;
|
|
324
326
|
for (let i = 0; i < n; i++) {
|
|
325
327
|
e.argValues[i] = O(e, e.argsNames[i]);
|
|
326
|
-
const o =
|
|
328
|
+
const o = x(e, i, t);
|
|
327
329
|
if (o < 0)
|
|
328
330
|
return Math.random() < 0.5 ? pe(e) : H(e);
|
|
329
331
|
e.indexes[i] = Math.floor(Math.random() * (o + 1)), e.args[e.argsNames[i]] = e.argValues[i][e.indexes[i]], e.indexes[i] < o && (t = !0);
|
|
@@ -333,7 +335,7 @@ function lt(e) {
|
|
|
333
335
|
function _(e) {
|
|
334
336
|
return e.mode === "forward" || e.mode === "backward";
|
|
335
337
|
}
|
|
336
|
-
function
|
|
338
|
+
function lt(e, n, t, i) {
|
|
337
339
|
const o = n[t], a = e.templates[t];
|
|
338
340
|
if (typeof a != "function") {
|
|
339
341
|
if (U(a, o, i) >= 0)
|
|
@@ -348,12 +350,12 @@ function ut(e, n, t, i) {
|
|
|
348
350
|
}
|
|
349
351
|
U(r, o, i) >= 0 || r.push(o);
|
|
350
352
|
}
|
|
351
|
-
function
|
|
353
|
+
function ut(e, n, t) {
|
|
352
354
|
for (const i in n)
|
|
353
355
|
if (Object.prototype.hasOwnProperty.call(n, i)) {
|
|
354
356
|
if (i === "seed")
|
|
355
357
|
continue;
|
|
356
|
-
|
|
358
|
+
lt(e, n, i, t);
|
|
357
359
|
}
|
|
358
360
|
}
|
|
359
361
|
function ce(e, n) {
|
|
@@ -366,8 +368,8 @@ function ce(e, n) {
|
|
|
366
368
|
}
|
|
367
369
|
return !0;
|
|
368
370
|
}
|
|
369
|
-
const
|
|
370
|
-
function
|
|
371
|
+
const ct = [{ mode: "forward" }];
|
|
372
|
+
function ft(e) {
|
|
371
373
|
const {
|
|
372
374
|
argsTemplates: n,
|
|
373
375
|
equals: t,
|
|
@@ -380,18 +382,18 @@ function dt(e) {
|
|
|
380
382
|
limitTests: f,
|
|
381
383
|
limitTime: d
|
|
382
384
|
} = e, h = e.timeController ?? Q, y = {
|
|
383
|
-
templates:
|
|
385
|
+
templates: He(n),
|
|
384
386
|
extra: {}
|
|
385
|
-
}, p = r == null || r.length === 0 ?
|
|
387
|
+
}, p = r == null || r.length === 0 ? ct : r, b = [];
|
|
386
388
|
let E = null, L = null, g = 0, S = 0, I = !1, P = 0;
|
|
387
389
|
function $() {
|
|
388
|
-
I || (I = !0, P = h.now(),
|
|
390
|
+
I || (I = !0, P = h.now(), Ee(), g = 0, re(), we());
|
|
389
391
|
}
|
|
390
|
-
function
|
|
392
|
+
function Ee() {
|
|
391
393
|
for (let s = 0, c = p.length; s < c; s++)
|
|
392
|
-
b.push(
|
|
394
|
+
b.push(Se());
|
|
393
395
|
}
|
|
394
|
-
function
|
|
396
|
+
function Se() {
|
|
395
397
|
return {
|
|
396
398
|
navigationState: ue(
|
|
397
399
|
y,
|
|
@@ -422,13 +424,13 @@ function dt(e) {
|
|
|
422
424
|
tests: S
|
|
423
425
|
});
|
|
424
426
|
}
|
|
425
|
-
function
|
|
426
|
-
$(), ce(y.templates, s) &&
|
|
427
|
+
function xe(s) {
|
|
428
|
+
$(), ce(y.templates, s) && ut(y, s, t);
|
|
427
429
|
}
|
|
428
430
|
function ne(s, c) {
|
|
429
|
-
return $(), ce(y.templates, s) ? (E.limitArgOnError = c?.limitArg ?? i ?? null, E.includeErrorVariant = c?.includeLimit ?? o ?? !1,
|
|
431
|
+
return $(), ce(y.templates, s) ? (E.limitArgOnError = c?.limitArg ?? i ?? null, E.includeErrorVariant = c?.includeLimit ?? o ?? !1, st(E, s)) : null;
|
|
430
432
|
}
|
|
431
|
-
function
|
|
433
|
+
function Me(s) {
|
|
432
434
|
const c = s?.args;
|
|
433
435
|
if (c == null)
|
|
434
436
|
return;
|
|
@@ -446,41 +448,41 @@ function dt(e) {
|
|
|
446
448
|
}
|
|
447
449
|
}
|
|
448
450
|
}
|
|
449
|
-
function
|
|
450
|
-
return $(),
|
|
451
|
+
function Te() {
|
|
452
|
+
return $(), Ve();
|
|
451
453
|
}
|
|
452
|
-
function
|
|
454
|
+
function Ve() {
|
|
453
455
|
for (; ; ) {
|
|
454
|
-
if (!
|
|
456
|
+
if (!Ie())
|
|
455
457
|
return null;
|
|
456
458
|
for (; ; ) {
|
|
457
|
-
const s =
|
|
459
|
+
const s = _e();
|
|
458
460
|
if (s != null)
|
|
459
461
|
return b[g].testsInLastTurn++, S++, s;
|
|
460
|
-
if (
|
|
461
|
-
if (
|
|
462
|
+
if (Pe()) {
|
|
463
|
+
if (!$e())
|
|
462
464
|
return null;
|
|
463
|
-
|
|
465
|
+
De();
|
|
464
466
|
break;
|
|
465
467
|
}
|
|
466
468
|
}
|
|
467
469
|
}
|
|
468
470
|
}
|
|
469
|
-
function
|
|
470
|
-
return !(
|
|
471
|
+
function Ie() {
|
|
472
|
+
return !(Ae() || Ce() || G() && (Oe() || !Le()) || !Ne());
|
|
471
473
|
}
|
|
472
|
-
function
|
|
474
|
+
function Ae() {
|
|
473
475
|
return f != null && S >= f;
|
|
474
476
|
}
|
|
475
|
-
function
|
|
477
|
+
function Ce() {
|
|
476
478
|
return d != null && h.now() - P >= d;
|
|
477
479
|
}
|
|
478
|
-
function
|
|
480
|
+
function Oe() {
|
|
479
481
|
if (!G())
|
|
480
482
|
throw new Error("Unexpected behavior");
|
|
481
483
|
return u != null && u <= 0;
|
|
482
484
|
}
|
|
483
|
-
function
|
|
485
|
+
function Le() {
|
|
484
486
|
if (!G())
|
|
485
487
|
throw new Error("Unexpected behavior");
|
|
486
488
|
for (let s = 0, c = p.length; s < c; s++)
|
|
@@ -488,20 +490,20 @@ function dt(e) {
|
|
|
488
490
|
return !0;
|
|
489
491
|
return !1;
|
|
490
492
|
}
|
|
491
|
-
function
|
|
493
|
+
function Ne() {
|
|
492
494
|
for (let s = 0, c = p.length; s < c; s++)
|
|
493
495
|
if (k(s))
|
|
494
496
|
return !0;
|
|
495
497
|
return !1;
|
|
496
498
|
}
|
|
497
|
-
function
|
|
499
|
+
function Pe() {
|
|
498
500
|
g++;
|
|
499
501
|
const s = g >= p.length;
|
|
500
502
|
return s && (g = 0), re(), s;
|
|
501
503
|
}
|
|
502
|
-
function
|
|
504
|
+
function $e() {
|
|
503
505
|
if (G()) {
|
|
504
|
-
const s =
|
|
506
|
+
const s = Ge();
|
|
505
507
|
if (u != null && s >= u)
|
|
506
508
|
return !1;
|
|
507
509
|
}
|
|
@@ -513,7 +515,7 @@ function dt(e) {
|
|
|
513
515
|
return !0;
|
|
514
516
|
return !1;
|
|
515
517
|
}
|
|
516
|
-
function
|
|
518
|
+
function Ge() {
|
|
517
519
|
let s = !1, c = 1 / 0;
|
|
518
520
|
for (let m = 0, v = b.length; m < v; m++) {
|
|
519
521
|
const D = b[m], j = p[m];
|
|
@@ -527,66 +529,66 @@ function dt(e) {
|
|
|
527
529
|
const c = p[s], m = b[s];
|
|
528
530
|
return c.limitTests != null && c.limitTests <= 0 || A(c) && (c.cycles != null && c.cycles <= 0 || c.attemptsPerVariant != null && c.attemptsPerVariant <= 0) ? !1 : m.tryNextVariantAttempts < 2;
|
|
529
531
|
}
|
|
530
|
-
function
|
|
532
|
+
function De() {
|
|
531
533
|
g = 0;
|
|
532
534
|
for (let s = 0, c = b.length; s < c; s++) {
|
|
533
535
|
const m = b[s];
|
|
534
536
|
m.testsInLastTurn = 0, m.startTime = null;
|
|
535
537
|
}
|
|
536
538
|
}
|
|
537
|
-
function
|
|
539
|
+
function _e() {
|
|
538
540
|
let s = 0;
|
|
539
541
|
for (; s < 2; ) {
|
|
540
|
-
if (!
|
|
542
|
+
if (!qe())
|
|
541
543
|
return null;
|
|
542
|
-
const c =
|
|
544
|
+
const c = Fe();
|
|
543
545
|
if (c != null)
|
|
544
546
|
return c;
|
|
545
|
-
if (A(p[g]) &&
|
|
547
|
+
if (A(p[g]) && ke())
|
|
546
548
|
return null;
|
|
547
549
|
s++;
|
|
548
550
|
}
|
|
549
551
|
return null;
|
|
550
552
|
}
|
|
551
|
-
function
|
|
553
|
+
function qe() {
|
|
552
554
|
const s = p[g];
|
|
553
|
-
return !(
|
|
555
|
+
return !(Ue() || Be() || A(s) && !Re(g));
|
|
554
556
|
}
|
|
555
|
-
function
|
|
557
|
+
function Ue() {
|
|
556
558
|
const s = p[g], c = b[g];
|
|
557
559
|
return s.limitTests != null && c.testsInLastTurn >= s.limitTests;
|
|
558
560
|
}
|
|
559
|
-
function
|
|
561
|
+
function Be() {
|
|
560
562
|
const s = p[g], c = b[g];
|
|
561
563
|
return s.limitTime != null && c.startTime != null && h.now() - c.startTime >= s.limitTime;
|
|
562
564
|
}
|
|
563
565
|
function A(s) {
|
|
564
566
|
return _(s);
|
|
565
567
|
}
|
|
566
|
-
function
|
|
568
|
+
function Re(s) {
|
|
567
569
|
const c = p[s], m = b[s];
|
|
568
570
|
if (!A(c))
|
|
569
571
|
throw new Error("Unexpected behavior");
|
|
570
572
|
return m.cycleCount < (c.cycles ?? 1);
|
|
571
573
|
}
|
|
572
|
-
function
|
|
574
|
+
function ke() {
|
|
573
575
|
const s = p[g], c = b[g];
|
|
574
576
|
if (!A(s))
|
|
575
577
|
throw new Error("Unexpected behavior");
|
|
576
578
|
return c.cycleCount++, c.cycleCount >= (s.cycles ?? 1) ? (c.cycleCount = 0, c.completedCount++, !0) : !1;
|
|
577
579
|
}
|
|
578
|
-
function
|
|
580
|
+
function Fe() {
|
|
579
581
|
const s = p[g], c = b[g], m = c.navigationState;
|
|
580
582
|
if (N(s)) {
|
|
581
583
|
if (F())
|
|
582
584
|
return null;
|
|
583
|
-
const v =
|
|
585
|
+
const v = je();
|
|
584
586
|
if (v != null)
|
|
585
587
|
return c.startTime == null && (c.startTime = h.now()), v;
|
|
586
588
|
}
|
|
587
|
-
return
|
|
589
|
+
return ze() ? (c.tryNextVariantAttempts = 0, N(s) && We(), c.startTime == null && (c.startTime = h.now()), oe(m.args)) : (c.tryNextVariantAttempts++, null);
|
|
588
590
|
}
|
|
589
|
-
function
|
|
591
|
+
function je() {
|
|
590
592
|
const s = p[g], m = b[g].navigationState;
|
|
591
593
|
if (!N(s))
|
|
592
594
|
throw new Error("Unexpected behavior");
|
|
@@ -595,7 +597,7 @@ function dt(e) {
|
|
|
595
597
|
const v = s.attemptsPerVariant ?? 1;
|
|
596
598
|
return m.attempts > 0 && m.attempts < v ? V(m) ? null : (m.attempts++, oe(m.args)) : null;
|
|
597
599
|
}
|
|
598
|
-
function
|
|
600
|
+
function We() {
|
|
599
601
|
const s = p[g], m = b[g].navigationState;
|
|
600
602
|
if (!N(s))
|
|
601
603
|
throw new Error("Unexpected behavior");
|
|
@@ -612,7 +614,7 @@ function dt(e) {
|
|
|
612
614
|
throw new Error("Unexpected behavior");
|
|
613
615
|
return (s.attemptsPerVariant ?? 1) <= 0;
|
|
614
616
|
}
|
|
615
|
-
function
|
|
617
|
+
function ze() {
|
|
616
618
|
const s = p[g], m = b[g].navigationState;
|
|
617
619
|
switch (s.mode) {
|
|
618
620
|
case "forward":
|
|
@@ -620,7 +622,7 @@ function dt(e) {
|
|
|
620
622
|
case "backward":
|
|
621
623
|
return H(m);
|
|
622
624
|
case "random":
|
|
623
|
-
return
|
|
625
|
+
return at(m);
|
|
624
626
|
default:
|
|
625
627
|
throw new Error(`Unknown mode: ${s.mode}`);
|
|
626
628
|
}
|
|
@@ -646,19 +648,19 @@ function dt(e) {
|
|
|
646
648
|
return S;
|
|
647
649
|
},
|
|
648
650
|
calcIndexes: ne,
|
|
649
|
-
extendTemplates:
|
|
650
|
-
addLimit:
|
|
651
|
-
next:
|
|
651
|
+
extendTemplates: xe,
|
|
652
|
+
addLimit: Me,
|
|
653
|
+
next: Te
|
|
652
654
|
};
|
|
653
655
|
}
|
|
654
656
|
function ee(e) {
|
|
655
657
|
if (e == null || e <= 0)
|
|
656
658
|
throw new Error(`Iterations = ${e}`);
|
|
657
659
|
e--;
|
|
658
|
-
const n =
|
|
660
|
+
const n = Je().then(() => e);
|
|
659
661
|
return e <= 0 ? n : n.then(ee);
|
|
660
662
|
}
|
|
661
|
-
function
|
|
663
|
+
function dt(e, n, t) {
|
|
662
664
|
const i = n.limit ? {
|
|
663
665
|
error: n.limit.error,
|
|
664
666
|
args: n.limit.args,
|
|
@@ -672,7 +674,7 @@ function mt(e, n, t) {
|
|
|
672
674
|
};
|
|
673
675
|
}
|
|
674
676
|
const fe = 2 ** 31;
|
|
675
|
-
function
|
|
677
|
+
function mt(e) {
|
|
676
678
|
if (e == null)
|
|
677
679
|
return { parallel: 1, sequentialOnError: !1 };
|
|
678
680
|
if (typeof e == "boolean")
|
|
@@ -689,8 +691,8 @@ function gt(e) {
|
|
|
689
691
|
sequentialOnError: e.sequentialOnError ?? !1
|
|
690
692
|
};
|
|
691
693
|
}
|
|
692
|
-
function
|
|
693
|
-
const n = e?.saveErrorVariants, t = n && e.createSaveErrorVariantsStore ? e.createSaveErrorVariantsStore(n) : null, i = e?.findBestError, { parallel: o, sequentialOnError: a } =
|
|
694
|
+
function gt(e) {
|
|
695
|
+
const n = e?.saveErrorVariants, t = n && e.createSaveErrorVariantsStore ? e.createSaveErrorVariantsStore(n) : null, i = e?.findBestError, { parallel: o, sequentialOnError: a } = mt(
|
|
694
696
|
e?.parallel
|
|
695
697
|
);
|
|
696
698
|
return {
|
|
@@ -715,7 +717,7 @@ function B(e, n, t) {
|
|
|
715
717
|
if (t)
|
|
716
718
|
return r;
|
|
717
719
|
}
|
|
718
|
-
function
|
|
720
|
+
function pt(e, n, t, i) {
|
|
719
721
|
const { abortControllerParallel: o, state: a, options: r } = e, { logOptions: l } = r;
|
|
720
722
|
if (e.options.findBestError)
|
|
721
723
|
e.variantsIterator.addLimit({ args: n, error: t, tests: i }), a.debugMode = !1, B(e, n, !1), r.sequentialOnError && !o.signal.aborted ? (l.debug && l.func(
|
|
@@ -750,11 +752,11 @@ function de(e, n, t, i) {
|
|
|
750
752
|
});
|
|
751
753
|
throw t;
|
|
752
754
|
}
|
|
753
|
-
function
|
|
755
|
+
function ht(e, n) {
|
|
754
756
|
const { GC_Iterations: t, GC_IterationsAsync: i, GC_Interval: o } = e.options;
|
|
755
757
|
return t > 0 && e.state.iterations - e.state.prevGcIterations >= t || i > 0 && e.state.iterationsAsync - e.state.prevGcIterationsAsync >= i || o > 0 && n - e.state.prevGcTime >= o;
|
|
756
758
|
}
|
|
757
|
-
async function
|
|
759
|
+
async function bt(e, n) {
|
|
758
760
|
e.prevGcIterations = e.iterations, e.prevGcIterationsAsync = e.iterationsAsync, e.prevGcTime = n, await ee(1);
|
|
759
761
|
}
|
|
760
762
|
function te(e) {
|
|
@@ -771,7 +773,7 @@ function J(e) {
|
|
|
771
773
|
const t = e / (1024 * 1024);
|
|
772
774
|
return t >= 10 ? `${Math.round(t)}MB` : `${t.toFixed(1)}MB`;
|
|
773
775
|
}
|
|
774
|
-
function
|
|
776
|
+
function yt(e, n) {
|
|
775
777
|
if (!e)
|
|
776
778
|
return `mode[${n}]: null`;
|
|
777
779
|
let t = `mode[${n}]: ${e.mode}`;
|
|
@@ -781,13 +783,13 @@ function he(e, n) {
|
|
|
781
783
|
const t = e - n, i = t >= 0 ? "+" : "";
|
|
782
784
|
return `${J(e)} (${i}${J(t)})`;
|
|
783
785
|
}
|
|
784
|
-
function
|
|
786
|
+
function vt(e, n) {
|
|
785
787
|
if (!e.start)
|
|
786
788
|
return;
|
|
787
789
|
let t = "[test-variants] start";
|
|
788
790
|
n != null && (t += `, memory: ${J(n)}`), e.func("start", t);
|
|
789
791
|
}
|
|
790
|
-
function
|
|
792
|
+
function Et(e) {
|
|
791
793
|
const { options: n, state: t } = e, { logOptions: i, timeController: o } = n;
|
|
792
794
|
if (!i.completed)
|
|
793
795
|
return;
|
|
@@ -803,10 +805,10 @@ function be(e) {
|
|
|
803
805
|
const { options: n, state: t } = e, { logOptions: i } = n, o = t.pendingModeChange;
|
|
804
806
|
!i.modeChange || o == null || (i.func(
|
|
805
807
|
"modeChange",
|
|
806
|
-
`[test-variants] ${
|
|
808
|
+
`[test-variants] ${yt(o.mode, o.modeIndex)}`
|
|
807
809
|
), t.pendingModeChange = null);
|
|
808
810
|
}
|
|
809
|
-
function
|
|
811
|
+
function St(e) {
|
|
810
812
|
const { options: n, state: t } = e, { logOptions: i, timeController: o } = n, a = o.now();
|
|
811
813
|
if (!i.progress || a - t.prevLogTime < i.progress)
|
|
812
814
|
return !1;
|
|
@@ -868,7 +870,7 @@ function wt(e, n) {
|
|
|
868
870
|
} catch (u) {
|
|
869
871
|
if (u instanceof T)
|
|
870
872
|
return;
|
|
871
|
-
|
|
873
|
+
pt(e, n, u, l);
|
|
872
874
|
} finally {
|
|
873
875
|
t.release(1);
|
|
874
876
|
}
|
|
@@ -878,10 +880,10 @@ function ve(e) {
|
|
|
878
880
|
const { options: n, state: t } = e, { logOptions: i, timeController: o, GC_Interval: a } = n;
|
|
879
881
|
if (!i.progress && !a)
|
|
880
882
|
return;
|
|
881
|
-
|
|
883
|
+
St(e);
|
|
882
884
|
const r = o.now();
|
|
883
|
-
if (
|
|
884
|
-
return
|
|
885
|
+
if (ht(e, r))
|
|
886
|
+
return bt(t, r);
|
|
885
887
|
}
|
|
886
888
|
function R(e) {
|
|
887
889
|
return e.options.abortSignalExternal?.aborted ?? !1;
|
|
@@ -889,24 +891,19 @@ function R(e) {
|
|
|
889
891
|
function K(e) {
|
|
890
892
|
return e.abortSignal.aborted;
|
|
891
893
|
}
|
|
892
|
-
function Ee(e, n) {
|
|
893
|
-
return e.state.debugMode ? n : e.variantsIterator.next();
|
|
894
|
-
}
|
|
895
894
|
async function W(e, n) {
|
|
896
895
|
const { pool: t, state: i, options: o } = e, { parallel: a, logOptions: r } = o;
|
|
897
|
-
let l =
|
|
896
|
+
let l = null;
|
|
898
897
|
for (; !R(e); ) {
|
|
899
898
|
const u = t && !K(e);
|
|
900
899
|
let f = !1;
|
|
901
900
|
u && (t.hold(1) || await ae({ pool: t, count: 1, hold: !0 }), f = !0);
|
|
902
901
|
try {
|
|
903
|
-
if (
|
|
902
|
+
if (n != null ? (l = n, n = null) : e.state.debugMode || (l = e.variantsIterator.next()), l == null)
|
|
904
903
|
break;
|
|
905
904
|
const d = ve(e);
|
|
906
|
-
if (M(d) && await d, R(e))
|
|
907
|
-
l = null;
|
|
905
|
+
if (M(d) && await d, R(e))
|
|
908
906
|
continue;
|
|
909
|
-
}
|
|
910
907
|
if (u)
|
|
911
908
|
wt(e, l), f = !1;
|
|
912
909
|
else {
|
|
@@ -917,24 +914,21 @@ async function W(e, n) {
|
|
|
917
914
|
const h = ye(e, l);
|
|
918
915
|
M(h) && await h;
|
|
919
916
|
}
|
|
920
|
-
l = null;
|
|
921
917
|
} finally {
|
|
922
918
|
f && t.release(1);
|
|
923
919
|
}
|
|
924
920
|
}
|
|
925
921
|
t && (await ae({ pool: t, count: a, hold: !0 }), t.release(a));
|
|
926
922
|
}
|
|
927
|
-
function
|
|
923
|
+
function xt(e) {
|
|
928
924
|
const { pool: n, state: t, options: i } = e, { logOptions: o } = i;
|
|
929
925
|
if (n)
|
|
930
926
|
return W(e);
|
|
931
927
|
let a = null;
|
|
932
|
-
for (; !R(e) && (a =
|
|
928
|
+
for (; !R(e) && (e.state.debugMode || (a = e.variantsIterator.next()), a != null); ) {
|
|
933
929
|
const r = ve(e);
|
|
934
|
-
if (M(r))
|
|
935
|
-
|
|
936
|
-
return r.then(() => W(e, u));
|
|
937
|
-
}
|
|
930
|
+
if (M(r))
|
|
931
|
+
return r.then(() => W(e, a));
|
|
938
932
|
if (R(e))
|
|
939
933
|
continue;
|
|
940
934
|
o.debug && K(e) && o.func(
|
|
@@ -946,8 +940,8 @@ function Mt(e) {
|
|
|
946
940
|
return l.then(() => W(e));
|
|
947
941
|
}
|
|
948
942
|
}
|
|
949
|
-
async function
|
|
950
|
-
const o =
|
|
943
|
+
async function Mt(e, n, t, i) {
|
|
944
|
+
const o = gt(i), {
|
|
951
945
|
store: a,
|
|
952
946
|
logOptions: r,
|
|
953
947
|
abortSignalExternal: l,
|
|
@@ -974,8 +968,8 @@ async function Tt(e, n, t, i) {
|
|
|
974
968
|
testOptions: L,
|
|
975
969
|
findBestErrorEnabled: !!u
|
|
976
970
|
});
|
|
977
|
-
const S = h <= 1 ? null : new
|
|
978
|
-
|
|
971
|
+
const S = h <= 1 ? null : new Ze(h);
|
|
972
|
+
vt(r, t.startMemory);
|
|
979
973
|
const I = {
|
|
980
974
|
options: o,
|
|
981
975
|
testRun: e,
|
|
@@ -990,24 +984,24 @@ async function Tt(e, n, t, i) {
|
|
|
990
984
|
};
|
|
991
985
|
be(I);
|
|
992
986
|
try {
|
|
993
|
-
await
|
|
987
|
+
await xt(I), E.throwIfAborted();
|
|
994
988
|
} catch (P) {
|
|
995
989
|
throw y.abort(new T()), P;
|
|
996
990
|
}
|
|
997
|
-
return b.throwIfAborted(), y.abort(new T()),
|
|
991
|
+
return b.throwIfAborted(), y.abort(new T()), Et(I), await ee(1), dt(t, n, f);
|
|
998
992
|
}
|
|
999
|
-
function
|
|
993
|
+
function Lt(e) {
|
|
1000
994
|
return function(t) {
|
|
1001
995
|
return async function(o) {
|
|
1002
|
-
const a = ge(o?.log), r =
|
|
996
|
+
const a = ge(o?.log), r = it(e, {
|
|
1003
997
|
onError: o?.onError,
|
|
1004
998
|
log: a,
|
|
1005
999
|
pauseDebuggerOnError: o?.pauseDebuggerOnError
|
|
1006
|
-
}), l = o?.timeController ?? Q, u = Y(), f =
|
|
1000
|
+
}), l = o?.timeController ?? Q, u = Y(), f = rt(l, u), d = o?.onModeChange;
|
|
1007
1001
|
function h(p) {
|
|
1008
1002
|
f.pendingModeChange = p, d?.(p);
|
|
1009
1003
|
}
|
|
1010
|
-
const y =
|
|
1004
|
+
const y = ft({
|
|
1011
1005
|
argsTemplates: t,
|
|
1012
1006
|
getSeed: o?.getSeed,
|
|
1013
1007
|
iterationModes: o?.iterationModes,
|
|
@@ -1020,10 +1014,10 @@ function Nt(e) {
|
|
|
1020
1014
|
limitTests: o?.limitTests,
|
|
1021
1015
|
limitTime: o?.limitTime
|
|
1022
1016
|
});
|
|
1023
|
-
return
|
|
1017
|
+
return Mt(r, y, f, o);
|
|
1024
1018
|
};
|
|
1025
1019
|
};
|
|
1026
1020
|
}
|
|
1027
1021
|
export {
|
|
1028
|
-
|
|
1022
|
+
Lt as c
|
|
1029
1023
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";const ee=require("@flemist/time-controller"),k=require("@flemist/simple-utils"),E=require("@flemist/async-utils"),H=require("@flemist/abort-controller-fast"),J=require("@flemist/time-limits");function te(){if(typeof process<"u"&&process.memoryUsage)try{return process.memoryUsage.rss()}catch{}if(typeof performance<"u"){const e=performance.memory;if(e)try{return e.usedJSHeapSize}catch{}}return null}const ze=1e3,_=[];function He(e){return k.formatAny(e,{pretty:!0,maxDepth:5,maxItems:50})}function Je(...e){const n=e.map(t=>typeof t=="string"?t:He(t)).join(" ");_.push(n),_.length>ze&&_.shift(),console.log(n)}function Xe(){return _.join(`
|
|
2
|
+
`)}globalThis.__getStressTestLogLast=Xe;const de=(e,n)=>{Je(n)},x={start:!0,progress:5e3,completed:!0,error:!0,modeChange:!0,debug:!1,func:de},Ze={start:!1,progress:!1,completed:!1,error:!1,modeChange:!1,debug:!1,func:de};function me(e){return e===!1?Ze:e===!0||!e?x:{start:e.start??x.start,progress:e.progress??x.progress,completed:e.completed??x.completed,error:e.error??x.error,modeChange:e.modeChange??x.modeChange,debug:e.debug??x.debug,func:e.func??x.func}}function Ke(e,n){const t=e.now();return{startTime:t,startMemory:n,debugMode:!1,tests:0,iterations:0,iterationsAsync:0,prevLogTime:t,prevLogMemory:n,pendingModeChange:null,prevGcTime:t,prevGcIterations:0,prevGcIterationsAsync:0}}class T extends H.AbortError{}const Qe=50,Ye=5;function le(e,n){return typeof e=="number"?{iterationsAsync:0,iterationsSync:e}:e!=null&&typeof e=="object"?e:n?{iterationsAsync:1,iterationsSync:0}:{iterationsAsync:0,iterationsSync:1}}function et(e,n){const t=n.log,o=n.pauseDebuggerOnError??!0;let i=null,l=0;function r(a,u,f){i==null&&(i={error:a,args:u,tests:f},t.error&&t.func("error",`[test-variants] error variant: ${k.formatAny(u,{pretty:!0})}
|
|
3
|
+
tests: ${f}
|
|
4
|
+
${k.formatAny(a)}`));const d=Date.now();if(o)debugger;if(Date.now()-d>Qe&&l<Ye){t.func("debug",`[test-variants] debug iteration: ${l}`),l++;return}const y=i;throw i=null,n.onError&&n.onError(y),y.error}return function(u,f,d){try{const h=e(u,d);return E.isPromiseLike(h)?h.then(y=>le(y,!0),y=>r(y,u,f)):le(h,!1)}catch(h){return h instanceof T?void 0:r(h,u,f)}}}function U(e,n,t){for(let o=0,i=e.length;o<i;o++)if(t?t(e[o],n):e[o]===n)return o;return-1}function ae(e,n,t,o){const i=Object.keys(e.templates),l={},r=[],a=[],u=[],f=i.length;for(let d=0;d<f;d++){const h=i[d];l[h]=void 0,r.push(-1),a.push(void 0),u.push(null)}return{args:l,argsNames:i,indexes:r,argValues:a,argLimits:u,attempts:0,templates:e,limitArgOnError:t,equals:n,includeErrorVariant:o??!1}}function O(e,n){const t=e.templates.templates[n],o=e.templates.extra[n];let i;if(typeof t=="function"?i=t(e.args):i=t,o==null)return i;let l=null;const r=o.length;for(let a=0;a<r;a++){const u=o[a];U(i,u,e.equals)<0&&(l==null?l=[...i,u]:l.push(u))}return l??i}function M(e,n,t){const o=e.argValues[n].length;if(o===0)return-1;const i=e.argLimits[n];if(i==null)return o-1;let l=e.limitArgOnError;if(typeof l=="function"){const r=e.argsNames[n];l=l({name:r,values:e.argValues[n],maxValueIndex:i})}return!t||l?Math.min(i,o-1):o-1}function V(e){const n=e.indexes.length;for(let t=0;t<n;t++){const o=e.argLimits[t];if(o==null)return!1;const i=e.indexes[t];if(i>o)return!0;if(i<o)return!1}return!e.includeErrorVariant}function C(e){const n=e.indexes.length;for(let t=0;t<n;t++)e.indexes[t]=-1,e.argValues[t]=void 0,e.args[e.argsNames[t]]=void 0}function ge(e){let n=!1,t=!0;const o=e.indexes.length;let i=o,l=!1,r=0;for(;r<o;r++){const a=e.argValues[r]==null;(a||l)&&(a&&(n=!0),e.argValues[r]=O(e,e.argsNames[r]));const u=M(e,r,r>i);if(u<0){t=!1,e.indexes[r]=-1;break}a&&(e.indexes[r]=0,e.args[e.argsNames[r]]=e.argValues[r][0]),(l||e.indexes[r]>u)&&(e.indexes[r]=u,e.args[e.argsNames[r]]=e.argValues[r][u],l=!0),i===o&&e.indexes[r]<u&&(i=r)}if(V(e))return C(e),!1;if(n&&t)return!0;for(r--;r>=0;r--){if(e.argValues[r]==null)continue;let a=r>i;const u=M(e,r,a),f=e.indexes[r]+1;if(f<=u){e.indexes[r]=f,e.args[e.argsNames[r]]=e.argValues[r][f],f<u&&(a=!0);for(let d=r+1;d<o;d++)e.args[e.argsNames[d]]=void 0;for(r++;r<o;r++){e.argValues[r]=O(e,e.argsNames[r]);const d=M(e,r,a);if(d<0)break;e.indexes[r]=0,e.args[e.argsNames[r]]=e.argValues[r][0],d>0&&(a=!0)}if(r>=o)return V(e)?(C(e),!1):!0}}return C(e),!1}function X(e){V(e)&&C(e);let n=!1,t=!0;const o=e.indexes.length;let i=o,l=!1,r=0;for(;r<o;r++){const a=e.argValues[r]==null;(a||l)&&(a&&(n=!0),e.argValues[r]=O(e,e.argsNames[r]));const u=M(e,r,r>i);if(u<0){t=!1,e.indexes[r]=-1;break}a&&(e.indexes[r]=u,e.args[e.argsNames[r]]=e.argValues[r][u]),(l||e.indexes[r]>u)&&(e.indexes[r]=u,e.args[e.argsNames[r]]=e.argValues[r][u],l=!0),i===o&&e.indexes[r]<u&&(i=r)}if((n||l)&&t&&!V(e))return!0;for(r--;r>=0;r--){if(e.argValues[r]==null)continue;let a=r>i;const u=M(e,r,a);let f=e.indexes[r]-1;if(f>u&&(f=u),f>=0){e.indexes[r]=f,e.args[e.argsNames[r]]=e.argValues[r][f],f<u&&(a=!0);for(let d=r+1;d<o;d++)e.args[e.argsNames[d]]=void 0;for(r++;r<o;r++){e.argValues[r]=O(e,e.argsNames[r]);const d=M(e,r,a);if(d<0)break;e.indexes[r]=d,e.args[e.argsNames[r]]=e.argValues[r][d],d>0&&(a=!0)}if(r>=o)return!0}}return C(e),!1}function tt(e,n){C(e);const t=e.argsNames,o=t.length;let i=!1;for(let l=0;l<o;l++){const r=t[l],a=n[r];if(a===void 0)return null;e.argValues[l]=O(e,r);const u=M(e,l,i);if(u<0)return null;const f=U(e.argValues[l],a,e.equals);if(f<0||f>u)return null;e.indexes[l]=f,e.args[e.argsNames[l]]=e.argValues[l][f],e.indexes[l]<u&&(i=!0)}return V(e)?null:e.indexes.slice()}function rt(e){const n=e.indexes.length;if(n===0)return!1;let t=!1;for(let o=0;o<n;o++){e.argValues[o]=O(e,e.argsNames[o]);const i=M(e,o,t);if(i<0)return Math.random()<.5?ge(e):X(e);e.indexes[o]=Math.floor(Math.random()*(i+1)),e.args[e.argsNames[o]]=e.argValues[o][e.indexes[o]],e.indexes[o]<i&&(t=!0)}return V(e)?X(e):!0}function D(e){return e.mode==="forward"||e.mode==="backward"}function nt(e,n,t,o){const i=n[t],l=e.templates[t];if(typeof l!="function"){if(U(l,i,o)>=0)return;l.push(i);return}const r=e.extra[t];if(r==null){e.extra[t]=[i];return}U(r,i,o)>=0||r.push(i)}function it(e,n,t){for(const o in n)if(Object.prototype.hasOwnProperty.call(n,o)){if(o==="seed")continue;nt(e,n,o,t)}}function ue(e,n){for(const t in n)if(Object.prototype.hasOwnProperty.call(n,t)){if(t==="seed")continue;if(!e[t])return!1}return!0}const ot=[{mode:"forward"}];function st(e){const{argsTemplates:n,equals:t,limitArgOnError:o,includeErrorVariant:i,getSeed:l,iterationModes:r,onModeChange:a,limitCompletionCount:u,limitTests:f,limitTime:d}=e,h=e.timeController??ee.timeControllerDefault,y={templates:k.deepCloneJsonLike(n),extra:{}},p=r==null||r.length===0?ot:r,b=[];let S=null,L=null,g=0,w=0,I=!1,N=0;function $(){I||(I=!0,N=h.now(),ve(),g=0,ie(),Se())}function ve(){for(let s=0,c=p.length;s<c;s++)b.push(Ee())}function Ee(){return{navigationState:ae(y,t??null,o??null,i??null),cycleCount:0,completedCount:0,testsInLastTurn:0,tryNextVariantAttempts:0,startTime:null}}function Se(){S=ae(y,t??null,!1,!1)}function ie(){a?.({mode:p[g],modeIndex:g,tests:w})}function we(s){$(),ue(y.templates,s)&&it(y,s,t)}function oe(s,c){return $(),ue(y.templates,s)?(S.limitArgOnError=c?.limitArg??o??null,S.includeErrorVariant=c?.includeLimit??i??!1,tt(S,s)):null}function xe(s){const c=s?.args;if(c==null)return;$();const m=oe(c);if(m!=null){L={args:c,error:s?.error,tests:s?.tests??w},S.argLimits=m;for(let v=0,q=b.length;v<q;v++){const W=b[v].navigationState;W.argLimits=m}}}function Me(){return $(),Te()}function Te(){for(;;){if(!Ve())return null;for(;;){const s=qe();if(s!=null)return b[g].testsInLastTurn++,w++,s;if(Pe()){if(!Ne())return null;Ge();break}}}}function Ve(){return!(Ie()||Ae()||G()&&(Ce()||!Oe())||!Le())}function Ie(){return f!=null&&w>=f}function Ae(){return d!=null&&h.now()-N>=d}function Ce(){if(!G())throw new Error("Unexpected behavior");return u!=null&&u<=0}function Oe(){if(!G())throw new Error("Unexpected behavior");for(let s=0,c=p.length;s<c;s++)if(A(p[s])&&F(s))return!0;return!1}function Le(){for(let s=0,c=p.length;s<c;s++)if(F(s))return!0;return!1}function Pe(){g++;const s=g>=p.length;return s&&(g=0),ie(),s}function Ne(){if(G()){const s=$e();if(u!=null&&s>=u)return!1}return!0}function G(){for(let s=0,c=p.length;s<c;s++)if(D(p[s]))return!0;return!1}function $e(){let s=!1,c=1/0;for(let m=0,v=b.length;m<v;m++){const q=b[m],W=p[m];D(W)&&(s=!0,F(m)&&q.completedCount<c&&(c=q.completedCount))}if(!s)throw new Error("Unexpected behavior");return c}function F(s){const c=p[s],m=b[s];return c.limitTests!=null&&c.limitTests<=0||A(c)&&(c.cycles!=null&&c.cycles<=0||c.attemptsPerVariant!=null&&c.attemptsPerVariant<=0)?!1:m.tryNextVariantAttempts<2}function Ge(){g=0;for(let s=0,c=b.length;s<c;s++){const m=b[s];m.testsInLastTurn=0,m.startTime=null}}function qe(){let s=0;for(;s<2;){if(!De())return null;const c=Re();if(c!=null)return c;if(A(p[g])&&Be())return null;s++}return null}function De(){const s=p[g];return!(_e()||ke()||A(s)&&!Ue(g))}function _e(){const s=p[g],c=b[g];return s.limitTests!=null&&c.testsInLastTurn>=s.limitTests}function ke(){const s=p[g],c=b[g];return s.limitTime!=null&&c.startTime!=null&&h.now()-c.startTime>=s.limitTime}function A(s){return D(s)}function Ue(s){const c=p[s],m=b[s];if(!A(c))throw new Error("Unexpected behavior");return m.cycleCount<(c.cycles??1)}function Be(){const s=p[g],c=b[g];if(!A(s))throw new Error("Unexpected behavior");return c.cycleCount++,c.cycleCount>=(s.cycles??1)?(c.cycleCount=0,c.completedCount++,!0):!1}function Re(){const s=p[g],c=b[g],m=c.navigationState;if(P(s)){if(j())return null;const v=Fe();if(v!=null)return c.startTime==null&&(c.startTime=h.now()),v}return We()?(c.tryNextVariantAttempts=0,P(s)&&je(),c.startTime==null&&(c.startTime=h.now()),se(m.args)):(c.tryNextVariantAttempts++,null)}function Fe(){const s=p[g],m=b[g].navigationState;if(!P(s))throw new Error("Unexpected behavior");if(j())throw new Error("Unexpected behavior");const v=s.attemptsPerVariant??1;return m.attempts>0&&m.attempts<v?V(m)?null:(m.attempts++,se(m.args)):null}function je(){const s=p[g],m=b[g].navigationState;if(!P(s))throw new Error("Unexpected behavior");if(j())throw new Error("Unexpected behavior");m.attempts=1}function P(s){return D(s)}function j(){const s=p[g];if(!P(s))throw new Error("Unexpected behavior");return(s.attemptsPerVariant??1)<=0}function We(){const s=p[g],m=b[g].navigationState;switch(s.mode){case"forward":return ge(m);case"backward":return X(m);case"random":return rt(m);default:throw new Error(`Unknown mode: ${s.mode}`)}}function se(s){const c={...s};return l!=null&&(c.seed=l({tests:w})),c}return{get limit(){return L},get modeIndex(){return g},get modeConfigs(){return p},get modeStates(){return b},get tests(){return w},calcIndexes:oe,extendTemplates:we,addLimit:xe,next:Me}}function re(e){if(e==null||e<=0)throw new Error(`Iterations = ${e}`);e--;const n=E.waitMicrotasks().then(()=>e);return e<=0?n:n.then(re)}function lt(e,n,t){const o=n.limit?{error:n.limit.error,args:n.limit.args,tests:n.limit.tests}:null;if(o&&!t)throw o.error;return{iterations:e.iterations,bestError:o}}const ce=2**31;function at(e){if(e==null)return{parallel:1,sequentialOnError:!1};if(typeof e=="boolean")return{parallel:e?ce:1,sequentialOnError:!1};if(typeof e=="number")return{parallel:e>0?e:1,sequentialOnError:!1};const n=e.count;let t=1;return n===!0?t=ce:typeof n=="number"&&n>0&&(t=n),{parallel:t,sequentialOnError:e.sequentialOnError??!1}}function ut(e){const n=e?.saveErrorVariants,t=n&&e.createSaveErrorVariantsStore?e.createSaveErrorVariantsStore(n):null,o=e?.findBestError,{parallel:i,sequentialOnError:l}=at(e?.parallel);return{store:t,GC_Iterations:e?.GC_Iterations??1e6,GC_IterationsAsync:e?.GC_IterationsAsync??1e4,GC_Interval:e?.GC_Interval??1e3,logOptions:me(e?.log),abortSignalExternal:e?.abortSignal,findBestError:o,dontThrowIfError:o?.dontThrowIfError,timeController:e?.timeController??ee.timeControllerDefault,parallel:i,sequentialOnError:l}}function B(e,n,t){const{options:o,variantsIterator:i}=e,l=i.limit?.args??n;if(!o.store)return;const r=o.store.save(l);if(t)return r}function ct(e,n,t,o){const{abortControllerParallel:i,state:l,options:r}=e,{logOptions:a}=r;if(e.options.findBestError)e.variantsIterator.addLimit({args:n,error:t,tests:o}),l.debugMode=!1,B(e,n,!1),r.sequentialOnError&&!i.signal.aborted?(a.debug&&a.func("debug","[test-variants] sequentialOnError: aborting parallel, switching to sequential"),i.abort(new T)):a.debug&&a.func("debug","[test-variants] parallel error in findBestError mode, continuing with new limits");else{if(i.signal.aborted)return;B(e,n,!1),i.abort(t)}}function fe(e,n,t,o){const{state:i}=e;if(e.options.findBestError){e.variantsIterator.addLimit({args:n,error:t,tests:o});const r=B(e,n,!0);if(r)return r.then(()=>{i.debugMode=!1});i.debugMode=!1;return}const l=B(e,n,!0);if(l)return l.then(()=>{throw t});throw t}function ft(e,n){const{GC_Iterations:t,GC_IterationsAsync:o,GC_Interval:i}=e.options;return t>0&&e.state.iterations-e.state.prevGcIterations>=t||o>0&&e.state.iterationsAsync-e.state.prevGcIterationsAsync>=o||i>0&&n-e.state.prevGcTime>=i}async function dt(e,n){e.prevGcIterations=e.iterations,e.prevGcIterationsAsync=e.iterationsAsync,e.prevGcTime=n,await re(1)}function ne(e){const n=e/1e3;if(n<60)return`${n.toFixed(1)}s`;const t=n/60;return t<60?`${t.toFixed(1)}m`:`${(t/60).toFixed(1)}h`}function Z(e){const n=e/1073741824;if(n>=1)return n>=10?`${Math.round(n)}GB`:`${n.toFixed(1)}GB`;const t=e/(1024*1024);return t>=10?`${Math.round(t)}MB`:`${t.toFixed(1)}MB`}function mt(e,n){if(!e)return`mode[${n}]: null`;let t=`mode[${n}]: ${e.mode}`;return(e.mode==="forward"||e.mode==="backward")&&(e.cycles!=null&&(t+=`, cycles=${e.cycles}`),e.attemptsPerVariant!=null&&(t+=`, attempts=${e.attemptsPerVariant}`)),e.limitTime!=null&&(t+=`, limitTime=${ne(e.limitTime)}`),e.limitTests!=null&&(t+=`, limitTests=${e.limitTests}`),t}function pe(e,n){const t=e-n,o=t>=0?"+":"";return`${Z(e)} (${o}${Z(t)})`}function gt(e,n){if(!e.start)return;let t="[test-variants] start";n!=null&&(t+=`, memory: ${Z(n)}`),e.func("start",t)}function pt(e){const{options:n,state:t}=e,{logOptions:o,timeController:i}=n;if(!o.completed)return;const l=i.now()-t.startTime;let r=`[test-variants] end, tests: ${t.tests} (${ne(l)}), async: ${t.iterationsAsync}`;if(t.startMemory!=null){const a=te();a!=null&&(r+=`, memory: ${pe(a,t.startMemory)}`)}o.func("completed",r)}function he(e){const{options:n,state:t}=e,{logOptions:o}=n,i=t.pendingModeChange;!o.modeChange||i==null||(o.func("modeChange",`[test-variants] ${mt(i.mode,i.modeIndex)}`),t.pendingModeChange=null)}function ht(e){const{options:n,state:t}=e,{logOptions:o,timeController:i}=n,l=i.now();if(!o.progress||l-t.prevLogTime<o.progress)return!1;he(e);const r=l-t.startTime;let a=`[test-variants] tests: ${t.tests} (${ne(r)}), async: ${t.iterationsAsync}`;if(t.prevLogMemory!=null){const u=te();u!=null&&(a+=`, memory: ${pe(u,t.prevLogMemory)}`,t.prevLogMemory=u)}return o.func("progress",a),t.prevLogTime=l,!0}function K(e,n){e.debugMode=!1,n&&(e.iterationsAsync+=n.iterationsAsync,e.iterations+=n.iterationsSync+n.iterationsAsync)}function Q(e){e.state.debugMode=!0,e.abortControllerParallel.abort(new T)}function be(e,n){const{testRun:t,testOptions:o,state:i}=e,l=i.tests;i.tests++;try{const r=t(n,l,o);if(E.isPromiseLike(r))return r.then(a=>{if(!a){Q(e);return}K(i,a)},a=>fe(e,n,a,l));if(!r){Q(e);return}K(i,r)}catch(r){return r instanceof T?void 0:fe(e,n,r,l)}}function bt(e,n){const{pool:t,abortSignal:o,testRun:i,testOptionsParallel:l,state:r}=e;if(!t)return;const a=r.tests;r.tests++,(async()=>{try{if(o.aborted)return;let u=i(n,a,l);if(E.isPromiseLike(u)&&(u=await u),!u){Q(e);return}K(r,u)}catch(u){if(u instanceof T)return;ct(e,n,u,a)}finally{t.release(1)}})()}function ye(e){const{options:n,state:t}=e,{logOptions:o,timeController:i,GC_Interval:l}=n;if(!o.progress&&!l)return;ht(e);const r=i.now();if(ft(e,r))return dt(t,r)}function R(e){return e.options.abortSignalExternal?.aborted??!1}function Y(e){return e.abortSignal.aborted}async function z(e,n){const{pool:t,state:o,options:i}=e,{parallel:l,logOptions:r}=i;let a=null;for(;!R(e);){const u=t&&!Y(e);let f=!1;u&&(t.hold(1)||await J.poolWait({pool:t,count:1,hold:!0}),f=!0);try{if(n!=null?(a=n,n=null):e.state.debugMode||(a=e.variantsIterator.next()),a==null)break;const d=ye(e);if(E.isPromiseLike(d)&&await d,R(e))continue;if(u)bt(e,a),f=!1;else{r.debug&&t&&Y(e)&&r.func("debug",`[test-variants] parallel aborted, running sequential: tests=${o.tests}`);const h=be(e,a);E.isPromiseLike(h)&&await h}}finally{f&&t.release(1)}}t&&(await J.poolWait({pool:t,count:l,hold:!0}),t.release(l))}function yt(e){const{pool:n,state:t,options:o}=e,{logOptions:i}=o;if(n)return z(e);let l=null;for(;!R(e)&&(e.state.debugMode||(l=e.variantsIterator.next()),l!=null);){const r=ye(e);if(E.isPromiseLike(r))return r.then(()=>z(e,l));if(R(e))continue;i.debug&&Y(e)&&i.func("debug",`[test-variants] parallel aborted, running sequential: tests=${t.tests}`);const a=be(e,l);if(E.isPromiseLike(a))return a.then(()=>z(e))}}async function vt(e,n,t,o){const i=ut(o),{store:l,logOptions:r,abortSignalExternal:a,findBestError:u,dontThrowIfError:f,timeController:d,parallel:h}=i,y=new H.AbortControllerFast,p=new H.AbortControllerFast,b=E.combineAbortSignals(a,y.signal),S=E.combineAbortSignals(b,p.signal),L={abortSignal:b,timeController:d},g={abortSignal:S,timeController:d};l&&await l.replay({testRun:e,variantsIterator:n,testOptions:L,findBestErrorEnabled:!!u});const w=h<=1?null:new J.Pool(h);gt(r,t.startMemory);const I={options:i,testRun:e,variantsIterator:n,testOptions:L,testOptionsParallel:g,abortControllerGlobal:y,abortControllerParallel:p,abortSignal:S,pool:w,state:t};he(I);try{await yt(I),S.throwIfAborted()}catch(N){throw y.abort(new T),N}return b.throwIfAborted(),y.abort(new T),pt(I),await re(1),lt(t,n,f)}function Et(e){return function(t){return async function(i){const l=me(i?.log),r=et(e,{onError:i?.onError,log:l,pauseDebuggerOnError:i?.pauseDebuggerOnError}),a=i?.timeController??ee.timeControllerDefault,u=te(),f=Ke(a,u),d=i?.onModeChange;function h(p){f.pendingModeChange=p,d?.(p)}const y=st({argsTemplates:t,getSeed:i?.getSeed,iterationModes:i?.iterationModes,equals:i?.findBestError?.equals,limitArgOnError:i?.findBestError?.limitArgOnError,includeErrorVariant:i?.findBestError?.includeErrorVariant,timeController:a,onModeChange:h,limitCompletionCount:i?.cycles??1,limitTests:i?.limitTests,limitTime:i?.limitTime});return vt(r,y,f,i)}}}exports.createTestVariants=Et;
|
package/build/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("../createTestVariants-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("../createTestVariants-DdR2pUe_.js"),F=require("path"),O=require("@flemist/async-utils"),y=require("@flemist/simple-utils"),x=require("@flemist/simple-utils/node"),P=require("fs");function v(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const m=v(F),u=v(P);async function b(e){const t=await u.promises.stat(e).catch(()=>null);if(t==null)return[];if(!t.isDirectory())throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);return(await u.promises.readdir(e)).filter(n=>n.endsWith(".json")).sort((n,a)=>n>a?-1:n<a?1:0).map(n=>m.join(e,n))}async function A(e,t){const s=await u.promises.readFile(e,"utf-8");let r;try{r=JSON.parse(s)}catch{throw new Error(`[saveErrorVariants] invalid JSON in file: ${e}`)}if(t)try{return t(r)}catch{throw new Error(`[saveErrorVariants] jsonToArgs failed for file: ${e}`)}return r}function q(e){const t=Math.random().toString(36).substring(2);return y.formatDateFileName(e.sessionDate,"UTC")+"_"+t+".json"}async function D(e,t,s){let r;if(s){const n=s(e);typeof n=="string"?r=n:r=JSON.stringify(n,null,2)}else r=JSON.stringify(e,null,2);await u.promises.mkdir(m.dirname(t),{recursive:!0}),await u.promises.writeFile(t,r,"utf-8")}function L(e,t){const s=Math.max(e.length,t.length);for(let r=0;r<s;r++){const n=e[r],a=t[r];if(n==null){if(a==null)continue;return 1}if(a==null||n<a)return-1;if(n>a)return 1}return 0}class N{options;filePath;lastSavedArgs=null;constructor(t){this.options=t;const s=new Date;this.filePath=m.resolve(t.dir,t.getFilePath?.({sessionDate:s})??q({sessionDate:s}))}async save(t){y.deepEqualJsonLike(t,this.lastSavedArgs)||(this.lastSavedArgs={...t},await x.fileLock({filePath:this.filePath,func:()=>D(t,this.filePath,this.options.argsToJson)}))}async replay(t){const{testRun:s,variantsIterator:r,testOptions:n,findBestErrorEnabled:a}=t,h=this.options.useToFindBestError,E=this.options.limitArg??!1,V=this.options.extendTemplates??!1,S=this.options.attemptsPerVariant??1,g=new Map;function d(i){let o=g.get(i);return o===void 0&&(o=r.calcIndexes(i,{includeLimit:!1,limitArg:E}),g.set(i,o)),o}const w=await b(this.options.dir),f=[];for(let i=0,o=w.length;i<o;i++){const p=w[i],c=await A(p,this.options.jsonToArgs);V&&r.extendTemplates(c),d(c)!=null&&f.push(c)}function T(i,o){return L(d(i),d(o))}f.sort(T);for(let i=0,o=f.length;i<o;i++){const p=f[i];for(let c=0;c<S;c++)try{const l=s(p,0,n);O.isPromiseLike(l)&&await l}catch(l){if(h&&a){r.addLimit({args:p,error:l});break}throw l}}}}function k(e){return new N(e)}function _(e){const t=j.createTestVariants(e);return function(r){const n=t(r);return function(h){return n({...h,createSaveErrorVariantsStore:k})}}}exports.createTestVariants=_;
|
package/build/node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as x } from "../createTestVariants-
|
|
1
|
+
import { c as x } from "../createTestVariants-BzKl5Eff.mjs";
|
|
2
2
|
import * as d from "path";
|
|
3
3
|
import { isPromiseLike as F } from "@flemist/async-utils";
|
|
4
4
|
import { formatDateFileName as S, deepEqualJsonLike as A } from "@flemist/simple-utils";
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";const ee=require("@flemist/time-controller"),k=require("@flemist/simple-utils"),E=require("@flemist/async-utils"),H=require("@flemist/abort-controller-fast"),J=require("@flemist/time-limits");function te(){if(typeof process<"u"&&process.memoryUsage)try{return process.memoryUsage().heapUsed}catch{}if(typeof performance<"u"){const e=performance.memory;if(e)try{return e.usedJSHeapSize}catch{}}return null}const He=1e3,_=[];function Je(e){return k.formatAny(e,{pretty:!0,maxDepth:5,maxItems:50})}function Xe(...e){const n=e.map(t=>typeof t=="string"?t:Je(t)).join(" ");_.push(n),_.length>He&&_.shift(),console.log(n)}function Ze(){return _.join(`
|
|
2
|
-
`)}globalThis.__getStressTestLogLast=Ze;const de=(e,n)=>{Xe(n)},x={start:!0,progress:5e3,completed:!0,error:!0,modeChange:!0,debug:!1,func:de},Ke={start:!1,progress:!1,completed:!1,error:!1,modeChange:!1,debug:!1,func:de};function me(e){return e===!1?Ke:e===!0||!e?x:{start:e.start??x.start,progress:e.progress??x.progress,completed:e.completed??x.completed,error:e.error??x.error,modeChange:e.modeChange??x.modeChange,debug:e.debug??x.debug,func:e.func??x.func}}function Qe(e,n){const t=e.now();return{startTime:t,startMemory:n,debugMode:!1,tests:0,iterations:0,iterationsAsync:0,prevLogTime:t,prevLogMemory:n,pendingModeChange:null,prevGcTime:t,prevGcIterations:0,prevGcIterationsAsync:0}}class T extends H.AbortError{}const Ye=50,et=5;function le(e,n){return typeof e=="number"?{iterationsAsync:0,iterationsSync:e}:e!=null&&typeof e=="object"?e:n?{iterationsAsync:1,iterationsSync:0}:{iterationsAsync:0,iterationsSync:1}}function tt(e,n){const t=n.log,o=n.pauseDebuggerOnError??!0;let i=null,l=0;function r(a,u,f){i==null&&(i={error:a,args:u,tests:f},t.error&&t.func("error",`[test-variants] error variant: ${k.formatAny(u,{pretty:!0})}
|
|
3
|
-
tests: ${f}
|
|
4
|
-
${k.formatAny(a)}`));const d=Date.now();if(o&&Function("debugger")(),Date.now()-d>Ye&&l<et){t.func("debug",`[test-variants] debug iteration: ${l}`),l++;return}const y=i;throw i=null,n.onError&&n.onError(y),y.error}return function(u,f,d){try{const h=e(u,d);return E.isPromiseLike(h)?h.then(y=>le(y,!0),y=>r(y,u,f)):le(h,!1)}catch(h){return h instanceof T?void 0:r(h,u,f)}}}function U(e,n,t){for(let o=0,i=e.length;o<i;o++)if(t?t(e[o],n):e[o]===n)return o;return-1}function ae(e,n,t,o){const i=Object.keys(e.templates),l={},r=[],a=[],u=[],f=i.length;for(let d=0;d<f;d++){const h=i[d];l[h]=void 0,r.push(-1),a.push(void 0),u.push(null)}return{args:l,argsNames:i,indexes:r,argValues:a,argLimits:u,attempts:0,templates:e,limitArgOnError:t,equals:n,includeErrorVariant:o??!1}}function O(e,n){const t=e.templates.templates[n],o=e.templates.extra[n];let i;if(typeof t=="function"?i=t(e.args):i=t,o==null)return i;let l=null;const r=o.length;for(let a=0;a<r;a++){const u=o[a];U(i,u,e.equals)<0&&(l==null?l=[...i,u]:l.push(u))}return l??i}function M(e,n,t){const o=e.argValues[n].length;if(o===0)return-1;const i=e.argLimits[n];if(i==null)return o-1;let l=e.limitArgOnError;if(typeof l=="function"){const r=e.argsNames[n];l=l({name:r,values:e.argValues[n],maxValueIndex:i})}return!t||l?Math.min(i,o-1):o-1}function V(e){const n=e.indexes.length;for(let t=0;t<n;t++){const o=e.argLimits[t];if(o==null)return!1;const i=e.indexes[t];if(i>o)return!0;if(i<o)return!1}return!e.includeErrorVariant}function C(e){const n=e.indexes.length;for(let t=0;t<n;t++)e.indexes[t]=-1,e.argValues[t]=void 0,e.args[e.argsNames[t]]=void 0}function ge(e){let n=!1,t=!0;const o=e.indexes.length;let i=o,l=!1,r=0;for(;r<o;r++){const a=e.argValues[r]==null;(a||l)&&(a&&(n=!0),e.argValues[r]=O(e,e.argsNames[r]));const u=M(e,r,r>i);if(u<0){t=!1,e.indexes[r]=-1;break}a&&(e.indexes[r]=0,e.args[e.argsNames[r]]=e.argValues[r][0]),(l||e.indexes[r]>u)&&(e.indexes[r]=u,e.args[e.argsNames[r]]=e.argValues[r][u],l=!0),i===o&&e.indexes[r]<u&&(i=r)}if(V(e))return C(e),!1;if(n&&t)return!0;for(r--;r>=0;r--){if(e.argValues[r]==null)continue;let a=r>i;const u=M(e,r,a),f=e.indexes[r]+1;if(f<=u){e.indexes[r]=f,e.args[e.argsNames[r]]=e.argValues[r][f],f<u&&(a=!0);for(let d=r+1;d<o;d++)e.args[e.argsNames[d]]=void 0;for(r++;r<o;r++){e.argValues[r]=O(e,e.argsNames[r]);const d=M(e,r,a);if(d<0)break;e.indexes[r]=0,e.args[e.argsNames[r]]=e.argValues[r][0],d>0&&(a=!0)}if(r>=o)return V(e)?(C(e),!1):!0}}return C(e),!1}function X(e){V(e)&&C(e);let n=!1,t=!0;const o=e.indexes.length;let i=o,l=!1,r=0;for(;r<o;r++){const a=e.argValues[r]==null;(a||l)&&(a&&(n=!0),e.argValues[r]=O(e,e.argsNames[r]));const u=M(e,r,r>i);if(u<0){t=!1,e.indexes[r]=-1;break}a&&(e.indexes[r]=u,e.args[e.argsNames[r]]=e.argValues[r][u]),(l||e.indexes[r]>u)&&(e.indexes[r]=u,e.args[e.argsNames[r]]=e.argValues[r][u],l=!0),i===o&&e.indexes[r]<u&&(i=r)}if((n||l)&&t&&!V(e))return!0;for(r--;r>=0;r--){if(e.argValues[r]==null)continue;let a=r>i;const u=M(e,r,a);let f=e.indexes[r]-1;if(f>u&&(f=u),f>=0){e.indexes[r]=f,e.args[e.argsNames[r]]=e.argValues[r][f],f<u&&(a=!0);for(let d=r+1;d<o;d++)e.args[e.argsNames[d]]=void 0;for(r++;r<o;r++){e.argValues[r]=O(e,e.argsNames[r]);const d=M(e,r,a);if(d<0)break;e.indexes[r]=d,e.args[e.argsNames[r]]=e.argValues[r][d],d>0&&(a=!0)}if(r>=o)return!0}}return C(e),!1}function rt(e,n){C(e);const t=e.argsNames,o=t.length;let i=!1;for(let l=0;l<o;l++){const r=t[l],a=n[r];if(a===void 0)return null;e.argValues[l]=O(e,r);const u=M(e,l,i);if(u<0)return null;const f=U(e.argValues[l],a,e.equals);if(f<0||f>u)return null;e.indexes[l]=f,e.args[e.argsNames[l]]=e.argValues[l][f],e.indexes[l]<u&&(i=!0)}return V(e)?null:e.indexes.slice()}function nt(e){const n=e.indexes.length;if(n===0)return!1;let t=!1;for(let o=0;o<n;o++){e.argValues[o]=O(e,e.argsNames[o]);const i=M(e,o,t);if(i<0)return Math.random()<.5?ge(e):X(e);e.indexes[o]=Math.floor(Math.random()*(i+1)),e.args[e.argsNames[o]]=e.argValues[o][e.indexes[o]],e.indexes[o]<i&&(t=!0)}return V(e)?X(e):!0}function D(e){return e.mode==="forward"||e.mode==="backward"}function it(e,n,t,o){const i=n[t],l=e.templates[t];if(typeof l!="function"){if(U(l,i,o)>=0)return;l.push(i);return}const r=e.extra[t];if(r==null){e.extra[t]=[i];return}U(r,i,o)>=0||r.push(i)}function ot(e,n,t){for(const o in n)if(Object.prototype.hasOwnProperty.call(n,o)){if(o==="seed")continue;it(e,n,o,t)}}function ue(e,n){for(const t in n)if(Object.prototype.hasOwnProperty.call(n,t)){if(t==="seed")continue;if(!e[t])return!1}return!0}const st=[{mode:"forward"}];function lt(e){const{argsTemplates:n,equals:t,limitArgOnError:o,includeErrorVariant:i,getSeed:l,iterationModes:r,onModeChange:a,limitCompletionCount:u,limitTests:f,limitTime:d}=e,h=e.timeController??ee.timeControllerDefault,y={templates:k.deepCloneJsonLike(n),extra:{}},p=r==null||r.length===0?st:r,b=[];let S=null,L=null,g=0,w=0,A=!1,N=0;function $(){A||(A=!0,N=h.now(),Ee(),g=0,ie(),we())}function Ee(){for(let s=0,c=p.length;s<c;s++)b.push(Se())}function Se(){return{navigationState:ae(y,t??null,o??null,i??null),cycleCount:0,completedCount:0,testsInLastTurn:0,tryNextVariantAttempts:0,startTime:null}}function we(){S=ae(y,t??null,!1,!1)}function ie(){a?.({mode:p[g],modeIndex:g,tests:w})}function xe(s){$(),ue(y.templates,s)&&ot(y,s,t)}function oe(s,c){return $(),ue(y.templates,s)?(S.limitArgOnError=c?.limitArg??o??null,S.includeErrorVariant=c?.includeLimit??i??!1,rt(S,s)):null}function Me(s){const c=s?.args;if(c==null)return;$();const m=oe(c);if(m!=null){L={args:c,error:s?.error,tests:s?.tests??w},S.argLimits=m;for(let v=0,q=b.length;v<q;v++){const W=b[v].navigationState;W.argLimits=m}}}function Te(){return $(),Ve()}function Ve(){for(;;){if(!Ae())return null;for(;;){const s=De();if(s!=null)return b[g].testsInLastTurn++,w++,s;if(Ne()){if(!$e())return null;qe();break}}}}function Ae(){return!(Ie()||Ce()||G()&&(Oe()||!Le())||!Pe())}function Ie(){return f!=null&&w>=f}function Ce(){return d!=null&&h.now()-N>=d}function Oe(){if(!G())throw new Error("Unexpected behavior");return u!=null&&u<=0}function Le(){if(!G())throw new Error("Unexpected behavior");for(let s=0,c=p.length;s<c;s++)if(I(p[s])&&F(s))return!0;return!1}function Pe(){for(let s=0,c=p.length;s<c;s++)if(F(s))return!0;return!1}function Ne(){g++;const s=g>=p.length;return s&&(g=0),ie(),s}function $e(){if(G()){const s=Ge();if(u!=null&&s>=u)return!1}return!0}function G(){for(let s=0,c=p.length;s<c;s++)if(D(p[s]))return!0;return!1}function Ge(){let s=!1,c=1/0;for(let m=0,v=b.length;m<v;m++){const q=b[m],W=p[m];D(W)&&(s=!0,F(m)&&q.completedCount<c&&(c=q.completedCount))}if(!s)throw new Error("Unexpected behavior");return c}function F(s){const c=p[s],m=b[s];return c.limitTests!=null&&c.limitTests<=0||I(c)&&(c.cycles!=null&&c.cycles<=0||c.attemptsPerVariant!=null&&c.attemptsPerVariant<=0)?!1:m.tryNextVariantAttempts<2}function qe(){g=0;for(let s=0,c=b.length;s<c;s++){const m=b[s];m.testsInLastTurn=0,m.startTime=null}}function De(){let s=0;for(;s<2;){if(!_e())return null;const c=Fe();if(c!=null)return c;if(I(p[g])&&Re())return null;s++}return null}function _e(){const s=p[g];return!(ke()||Ue()||I(s)&&!Be(g))}function ke(){const s=p[g],c=b[g];return s.limitTests!=null&&c.testsInLastTurn>=s.limitTests}function Ue(){const s=p[g],c=b[g];return s.limitTime!=null&&c.startTime!=null&&h.now()-c.startTime>=s.limitTime}function I(s){return D(s)}function Be(s){const c=p[s],m=b[s];if(!I(c))throw new Error("Unexpected behavior");return m.cycleCount<(c.cycles??1)}function Re(){const s=p[g],c=b[g];if(!I(s))throw new Error("Unexpected behavior");return c.cycleCount++,c.cycleCount>=(s.cycles??1)?(c.cycleCount=0,c.completedCount++,!0):!1}function Fe(){const s=p[g],c=b[g],m=c.navigationState;if(P(s)){if(j())return null;const v=je();if(v!=null)return c.startTime==null&&(c.startTime=h.now()),v}return ze()?(c.tryNextVariantAttempts=0,P(s)&&We(),c.startTime==null&&(c.startTime=h.now()),se(m.args)):(c.tryNextVariantAttempts++,null)}function je(){const s=p[g],m=b[g].navigationState;if(!P(s))throw new Error("Unexpected behavior");if(j())throw new Error("Unexpected behavior");const v=s.attemptsPerVariant??1;return m.attempts>0&&m.attempts<v?V(m)?null:(m.attempts++,se(m.args)):null}function We(){const s=p[g],m=b[g].navigationState;if(!P(s))throw new Error("Unexpected behavior");if(j())throw new Error("Unexpected behavior");m.attempts=1}function P(s){return D(s)}function j(){const s=p[g];if(!P(s))throw new Error("Unexpected behavior");return(s.attemptsPerVariant??1)<=0}function ze(){const s=p[g],m=b[g].navigationState;switch(s.mode){case"forward":return ge(m);case"backward":return X(m);case"random":return nt(m);default:throw new Error(`Unknown mode: ${s.mode}`)}}function se(s){const c={...s};return l!=null&&(c.seed=l({tests:w})),c}return{get limit(){return L},get modeIndex(){return g},get modeConfigs(){return p},get modeStates(){return b},get tests(){return w},calcIndexes:oe,extendTemplates:xe,addLimit:Me,next:Te}}function re(e){if(e==null||e<=0)throw new Error(`Iterations = ${e}`);e--;const n=E.waitMicrotasks().then(()=>e);return e<=0?n:n.then(re)}function at(e,n,t){const o=n.limit?{error:n.limit.error,args:n.limit.args,tests:n.limit.tests}:null;if(o&&!t)throw o.error;return{iterations:e.iterations,bestError:o}}const ce=2**31;function ut(e){if(e==null)return{parallel:1,sequentialOnError:!1};if(typeof e=="boolean")return{parallel:e?ce:1,sequentialOnError:!1};if(typeof e=="number")return{parallel:e>0?e:1,sequentialOnError:!1};const n=e.count;let t=1;return n===!0?t=ce:typeof n=="number"&&n>0&&(t=n),{parallel:t,sequentialOnError:e.sequentialOnError??!1}}function ct(e){const n=e?.saveErrorVariants,t=n&&e.createSaveErrorVariantsStore?e.createSaveErrorVariantsStore(n):null,o=e?.findBestError,{parallel:i,sequentialOnError:l}=ut(e?.parallel);return{store:t,GC_Iterations:e?.GC_Iterations??1e6,GC_IterationsAsync:e?.GC_IterationsAsync??1e4,GC_Interval:e?.GC_Interval??1e3,logOptions:me(e?.log),abortSignalExternal:e?.abortSignal,findBestError:o,dontThrowIfError:o?.dontThrowIfError,timeController:e?.timeController??ee.timeControllerDefault,parallel:i,sequentialOnError:l}}function B(e,n,t){const{options:o,variantsIterator:i}=e,l=i.limit?.args??n;if(!o.store)return;const r=o.store.save(l);if(t)return r}function ft(e,n,t,o){const{abortControllerParallel:i,state:l,options:r}=e,{logOptions:a}=r;if(e.options.findBestError)e.variantsIterator.addLimit({args:n,error:t,tests:o}),l.debugMode=!1,B(e,n,!1),r.sequentialOnError&&!i.signal.aborted?(a.debug&&a.func("debug","[test-variants] sequentialOnError: aborting parallel, switching to sequential"),i.abort(new T)):a.debug&&a.func("debug","[test-variants] parallel error in findBestError mode, continuing with new limits");else{if(i.signal.aborted)return;B(e,n,!1),i.abort(t)}}function fe(e,n,t,o){const{state:i}=e;if(e.options.findBestError){e.variantsIterator.addLimit({args:n,error:t,tests:o});const r=B(e,n,!0);if(r)return r.then(()=>{i.debugMode=!1});i.debugMode=!1;return}const l=B(e,n,!0);if(l)return l.then(()=>{throw t});throw t}function dt(e,n){const{GC_Iterations:t,GC_IterationsAsync:o,GC_Interval:i}=e.options;return t>0&&e.state.iterations-e.state.prevGcIterations>=t||o>0&&e.state.iterationsAsync-e.state.prevGcIterationsAsync>=o||i>0&&n-e.state.prevGcTime>=i}async function mt(e,n){e.prevGcIterations=e.iterations,e.prevGcIterationsAsync=e.iterationsAsync,e.prevGcTime=n,await re(1)}function ne(e){const n=e/1e3;if(n<60)return`${n.toFixed(1)}s`;const t=n/60;return t<60?`${t.toFixed(1)}m`:`${(t/60).toFixed(1)}h`}function Z(e){const n=e/1073741824;if(n>=1)return n>=10?`${Math.round(n)}GB`:`${n.toFixed(1)}GB`;const t=e/(1024*1024);return t>=10?`${Math.round(t)}MB`:`${t.toFixed(1)}MB`}function gt(e,n){if(!e)return`mode[${n}]: null`;let t=`mode[${n}]: ${e.mode}`;return(e.mode==="forward"||e.mode==="backward")&&(e.cycles!=null&&(t+=`, cycles=${e.cycles}`),e.attemptsPerVariant!=null&&(t+=`, attempts=${e.attemptsPerVariant}`)),e.limitTime!=null&&(t+=`, limitTime=${ne(e.limitTime)}`),e.limitTests!=null&&(t+=`, limitTests=${e.limitTests}`),t}function pe(e,n){const t=e-n,o=t>=0?"+":"";return`${Z(e)} (${o}${Z(t)})`}function pt(e,n){if(!e.start)return;let t="[test-variants] start";n!=null&&(t+=`, memory: ${Z(n)}`),e.func("start",t)}function ht(e){const{options:n,state:t}=e,{logOptions:o,timeController:i}=n;if(!o.completed)return;const l=i.now()-t.startTime;let r=`[test-variants] end, tests: ${t.tests} (${ne(l)}), async: ${t.iterationsAsync}`;if(t.startMemory!=null){const a=te();a!=null&&(r+=`, memory: ${pe(a,t.startMemory)}`)}o.func("completed",r)}function he(e){const{options:n,state:t}=e,{logOptions:o}=n,i=t.pendingModeChange;!o.modeChange||i==null||(o.func("modeChange",`[test-variants] ${gt(i.mode,i.modeIndex)}`),t.pendingModeChange=null)}function bt(e){const{options:n,state:t}=e,{logOptions:o,timeController:i}=n,l=i.now();if(!o.progress||l-t.prevLogTime<o.progress)return!1;he(e);const r=l-t.startTime;let a=`[test-variants] tests: ${t.tests} (${ne(r)}), async: ${t.iterationsAsync}`;if(t.prevLogMemory!=null){const u=te();u!=null&&(a+=`, memory: ${pe(u,t.prevLogMemory)}`,t.prevLogMemory=u)}return o.func("progress",a),t.prevLogTime=l,!0}function K(e,n){e.debugMode=!1,n&&(e.iterationsAsync+=n.iterationsAsync,e.iterations+=n.iterationsSync+n.iterationsAsync)}function Q(e){e.state.debugMode=!0,e.abortControllerParallel.abort(new T)}function be(e,n){const{testRun:t,testOptions:o,state:i}=e,l=i.tests;i.tests++;try{const r=t(n,l,o);if(E.isPromiseLike(r))return r.then(a=>{if(!a){Q(e);return}K(i,a)},a=>fe(e,n,a,l));if(!r){Q(e);return}K(i,r)}catch(r){return r instanceof T?void 0:fe(e,n,r,l)}}function yt(e,n){const{pool:t,abortSignal:o,testRun:i,testOptionsParallel:l,state:r}=e;if(!t)return;const a=r.tests;r.tests++,(async()=>{try{if(o.aborted)return;let u=i(n,a,l);if(E.isPromiseLike(u)&&(u=await u),!u){Q(e);return}K(r,u)}catch(u){if(u instanceof T)return;ft(e,n,u,a)}finally{t.release(1)}})()}function ye(e){const{options:n,state:t}=e,{logOptions:o,timeController:i,GC_Interval:l}=n;if(!o.progress&&!l)return;bt(e);const r=i.now();if(dt(e,r))return mt(t,r)}function R(e){return e.options.abortSignalExternal?.aborted??!1}function Y(e){return e.abortSignal.aborted}function ve(e,n){return e.state.debugMode?n:e.variantsIterator.next()}async function z(e,n){const{pool:t,state:o,options:i}=e,{parallel:l,logOptions:r}=i;let a=n??null;for(;!R(e);){const u=t&&!Y(e);let f=!1;u&&(t.hold(1)||await J.poolWait({pool:t,count:1,hold:!0}),f=!0);try{if(a==null&&(a=ve(e,a),a==null))break;const d=ye(e);if(E.isPromiseLike(d)&&await d,R(e)){a=null;continue}if(u)yt(e,a),f=!1;else{r.debug&&t&&Y(e)&&r.func("debug",`[test-variants] parallel aborted, running sequential: tests=${o.tests}`);const h=be(e,a);E.isPromiseLike(h)&&await h}a=null}finally{f&&t.release(1)}}t&&(await J.poolWait({pool:t,count:l,hold:!0}),t.release(l))}function vt(e){const{pool:n,state:t,options:o}=e,{logOptions:i}=o;if(n)return z(e);let l=null;for(;!R(e)&&(l=ve(e,l),l!=null);){const r=ye(e);if(E.isPromiseLike(r)){const u=l;return r.then(()=>z(e,u))}if(R(e))continue;i.debug&&Y(e)&&i.func("debug",`[test-variants] parallel aborted, running sequential: tests=${t.tests}`);const a=be(e,l);if(E.isPromiseLike(a))return a.then(()=>z(e))}}async function Et(e,n,t,o){const i=ct(o),{store:l,logOptions:r,abortSignalExternal:a,findBestError:u,dontThrowIfError:f,timeController:d,parallel:h}=i,y=new H.AbortControllerFast,p=new H.AbortControllerFast,b=E.combineAbortSignals(a,y.signal),S=E.combineAbortSignals(b,p.signal),L={abortSignal:b,timeController:d},g={abortSignal:S,timeController:d};l&&await l.replay({testRun:e,variantsIterator:n,testOptions:L,findBestErrorEnabled:!!u});const w=h<=1?null:new J.Pool(h);pt(r,t.startMemory);const A={options:i,testRun:e,variantsIterator:n,testOptions:L,testOptionsParallel:g,abortControllerGlobal:y,abortControllerParallel:p,abortSignal:S,pool:w,state:t};he(A);try{await vt(A),S.throwIfAborted()}catch(N){throw y.abort(new T),N}return b.throwIfAborted(),y.abort(new T),ht(A),await re(1),at(t,n,f)}function St(e){return function(t){return async function(i){const l=me(i?.log),r=tt(e,{onError:i?.onError,log:l,pauseDebuggerOnError:i?.pauseDebuggerOnError}),a=i?.timeController??ee.timeControllerDefault,u=te(),f=Qe(a,u),d=i?.onModeChange;function h(p){f.pendingModeChange=p,d?.(p)}const y=lt({argsTemplates:t,getSeed:i?.getSeed,iterationModes:i?.iterationModes,equals:i?.findBestError?.equals,limitArgOnError:i?.findBestError?.limitArgOnError,includeErrorVariant:i?.findBestError?.includeErrorVariant,timeController:a,onModeChange:h,limitCompletionCount:i?.cycles??1,limitTests:i?.limitTests,limitTime:i?.limitTime});return Et(r,y,f,i)}}}exports.createTestVariants=St;
|