@flemist/test-variants 3.0.2 → 5.0.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.
Files changed (118) hide show
  1. package/README.md +283 -49
  2. package/build/browser/index.cjs +1 -0
  3. package/build/browser/index.d.ts +1 -0
  4. package/build/browser/index.mjs +4 -0
  5. package/build/common/-test/freezeProps.d.ts +2 -0
  6. package/build/common/garbage-collect/garbageCollect.d.ts +5 -0
  7. package/build/common/helpers/log.d.ts +5 -0
  8. package/build/common/index.cjs +1 -0
  9. package/build/common/index.d.ts +2 -0
  10. package/build/common/index.mjs +4 -0
  11. package/build/common/test-variants/-test/caches.d.ts +1 -0
  12. package/build/common/test-variants/-test/constants.d.ts +8 -0
  13. package/build/common/test-variants/-test/estimations/estimateCallCount.d.ts +4 -0
  14. package/build/common/test-variants/-test/estimations/estimateModeChanges.d.ts +4 -0
  15. package/build/common/test-variants/-test/generators/findBestError.d.ts +4 -0
  16. package/build/common/test-variants/-test/generators/primitives.d.ts +16 -0
  17. package/build/common/test-variants/-test/generators/run.d.ts +9 -0
  18. package/build/common/test-variants/-test/generators/template.d.ts +3 -0
  19. package/build/common/test-variants/-test/generators/testFunc.d.ts +3 -0
  20. package/build/common/test-variants/-test/helpers/CallController.d.ts +28 -0
  21. package/build/common/test-variants/-test/helpers/ErrorVariantController.d.ts +17 -0
  22. package/build/common/test-variants/-test/helpers/TestError.d.ts +2 -0
  23. package/build/common/test-variants/-test/helpers/deepEqualJsonLikeWithoutSeed.d.ts +1 -0
  24. package/build/common/test-variants/-test/helpers/deepFreezeJsonLike.d.ts +1 -0
  25. package/build/common/test-variants/-test/helpers/forEachVariant.d.ts +4 -0
  26. package/build/common/test-variants/-test/helpers/getMaxAttemptsPerVariant.d.ts +2 -0
  27. package/build/common/test-variants/-test/helpers/getParallelLimit.d.ts +7 -0
  28. package/build/common/test-variants/-test/helpers/getVariantArgs.d.ts +12 -0
  29. package/build/common/test-variants/-test/helpers/runWithTimeController.d.ts +7 -0
  30. package/build/common/test-variants/-test/invariants/CallCountInvariant.d.ts +18 -0
  31. package/build/common/test-variants/-test/invariants/CallOptionsInvariant.d.ts +32 -0
  32. package/build/common/test-variants/-test/invariants/ErrorBehaviorInvariant.d.ts +32 -0
  33. package/build/common/test-variants/-test/invariants/FindBestErrorInvariant.d.ts +37 -0
  34. package/build/common/test-variants/-test/invariants/IterationsInvariant.d.ts +21 -0
  35. package/build/common/test-variants/-test/invariants/LimitTimeInvariant.d.ts +26 -0
  36. package/build/common/test-variants/-test/invariants/LogInvariant.d.ts +126 -0
  37. package/build/common/test-variants/-test/invariants/OnErrorInvariant.d.ts +38 -0
  38. package/build/common/test-variants/-test/invariants/OnModeChangeInvariant.d.ts +32 -0
  39. package/build/common/test-variants/-test/invariants/ParallelInvariant.d.ts +25 -0
  40. package/build/common/test-variants/-test/log.d.ts +3 -0
  41. package/build/common/test-variants/-test/types.d.ts +34 -0
  42. package/build/common/test-variants/-test/variants.d.ts +3 -0
  43. package/build/common/test-variants/createTestRun.d.ts +3 -0
  44. package/build/common/test-variants/createTestVariants.d.ts +4 -0
  45. package/build/common/test-variants/iterator/createVariantsIterator.d.ts +4 -0
  46. package/build/common/test-variants/iterator/helpers/findValueIndex.d.ts +2 -0
  47. package/build/common/test-variants/iterator/helpers/mode.d.ts +3 -0
  48. package/build/common/test-variants/iterator/helpers/template.d.ts +7 -0
  49. package/build/common/test-variants/iterator/types.d.ts +102 -0
  50. package/build/common/test-variants/iterator/variant-navigation/-test/helpers/caches.d.ts +1 -0
  51. package/build/common/test-variants/iterator/variant-navigation/-test/helpers/check.d.ts +2 -0
  52. package/build/common/test-variants/iterator/variant-navigation/-test/helpers/create.d.ts +3 -0
  53. package/build/common/test-variants/iterator/variant-navigation/-test/helpers/format.d.ts +6 -0
  54. package/build/common/test-variants/iterator/variant-navigation/-test/helpers/parse.d.ts +8 -0
  55. package/build/common/test-variants/iterator/variant-navigation/-test/helpers/variants.d.ts +12 -0
  56. package/build/common/test-variants/iterator/variant-navigation/variantNavigation.d.ts +28 -0
  57. package/build/common/test-variants/log/format.d.ts +7 -0
  58. package/build/common/test-variants/log/getMemoryUsage.d.ts +2 -0
  59. package/build/common/test-variants/log/logOptions.d.ts +8 -0
  60. package/build/common/test-variants/run/AbortErrorSilent.d.ts +3 -0
  61. package/build/common/test-variants/run/RunContext.d.ts +21 -0
  62. package/build/common/test-variants/run/createRunResult.d.ts +6 -0
  63. package/build/common/test-variants/run/createRunState.d.ts +23 -0
  64. package/build/common/test-variants/run/errorHandlers.d.ts +20 -0
  65. package/build/common/test-variants/run/gcManager.d.ts +6 -0
  66. package/build/common/test-variants/run/resolveRunOptions.d.ts +23 -0
  67. package/build/common/test-variants/run/runIterationLoop.d.ts +9 -0
  68. package/build/common/test-variants/run/runLogger.d.ts +9 -0
  69. package/build/common/test-variants/run/types.d.ts +57 -0
  70. package/build/common/test-variants/testVariantsRun.d.ts +6 -0
  71. package/build/common/test-variants/types.d.ts +183 -0
  72. package/build/createTestVariants-BL9wiuRD.mjs +1014 -0
  73. package/build/createTestVariants-CpzwjKTs.js +4 -0
  74. package/build/node/index.cjs +1 -0
  75. package/build/node/index.d.ts +8 -0
  76. package/build/node/index.mjs +102 -0
  77. package/build/node/test-variants/createSaveErrorVariantsStore.d.ts +5 -0
  78. package/{dist/lib → build/node}/test-variants/saveErrorVariants.d.ts +4 -3
  79. package/package.json +109 -68
  80. package/dist/bundle/browser.js +0 -650
  81. package/dist/lib/garbage-collect/garbageCollect.cjs +0 -30
  82. package/dist/lib/garbage-collect/garbageCollect.d.ts +0 -2
  83. package/dist/lib/garbage-collect/garbageCollect.mjs +0 -26
  84. package/dist/lib/index.cjs +0 -23
  85. package/dist/lib/index.d.ts +0 -7
  86. package/dist/lib/index.mjs +0 -13
  87. package/dist/lib/test-variants/argsToString.cjs +0 -17
  88. package/dist/lib/test-variants/argsToString.d.ts +0 -2
  89. package/dist/lib/test-variants/argsToString.mjs +0 -13
  90. package/dist/lib/test-variants/createTestVariants.cjs +0 -91
  91. package/dist/lib/test-variants/createTestVariants.d.ts +0 -8
  92. package/dist/lib/test-variants/createTestVariants.mjs +0 -87
  93. package/dist/lib/test-variants/createTestVariants.perf.cjs +0 -44
  94. package/dist/lib/test-variants/createTestVariants.perf.d.ts +0 -1
  95. package/dist/lib/test-variants/createTestVariants.perf.mjs +0 -42
  96. package/dist/lib/test-variants/prime.cjs +0 -65
  97. package/dist/lib/test-variants/prime.d.ts +0 -3
  98. package/dist/lib/test-variants/prime.mjs +0 -59
  99. package/dist/lib/test-variants/prime.perf.cjs +0 -30
  100. package/dist/lib/test-variants/prime.perf.d.ts +0 -1
  101. package/dist/lib/test-variants/prime.perf.mjs +0 -28
  102. package/dist/lib/test-variants/saveErrorVariants.cjs +0 -97
  103. package/dist/lib/test-variants/saveErrorVariants.mjs +0 -69
  104. package/dist/lib/test-variants/testVariantsCreateTestRun.cjs +0 -80
  105. package/dist/lib/test-variants/testVariantsCreateTestRun.d.ts +0 -22
  106. package/dist/lib/test-variants/testVariantsCreateTestRun.mjs +0 -76
  107. package/dist/lib/test-variants/testVariantsIterable.cjs +0 -70
  108. package/dist/lib/test-variants/testVariantsIterable.d.ts +0 -15
  109. package/dist/lib/test-variants/testVariantsIterable.mjs +0 -66
  110. package/dist/lib/test-variants/testVariantsIterator.cjs +0 -359
  111. package/dist/lib/test-variants/testVariantsIterator.d.ts +0 -67
  112. package/dist/lib/test-variants/testVariantsIterator.mjs +0 -355
  113. package/dist/lib/test-variants/testVariantsRun.cjs +0 -289
  114. package/dist/lib/test-variants/testVariantsRun.d.ts +0 -50
  115. package/dist/lib/test-variants/testVariantsRun.mjs +0 -265
  116. package/dist/lib/test-variants/types.cjs +0 -2
  117. package/dist/lib/test-variants/types.d.ts +0 -20
  118. package/dist/lib/test-variants/types.mjs +0 -1
@@ -0,0 +1,1014 @@
1
+ import { timeControllerDefault as K } from "@flemist/time-controller";
2
+ import { formatAny as W, deepCloneJsonLike as je } from "@flemist/simple-utils";
3
+ import { isPromiseLike as M, waitMicrotasks as We, combineAbortSignals as oe } from "@flemist/async-utils";
4
+ import { AbortError as ze, AbortControllerFast as ie } from "@flemist/abort-controller-fast";
5
+ import { poolWait as se, Pool as He } from "@flemist/time-limits";
6
+ function Q() {
7
+ if (typeof process < "u" && process.memoryUsage)
8
+ try {
9
+ return process.memoryUsage().heapUsed;
10
+ } catch {
11
+ }
12
+ if (typeof performance < "u") {
13
+ const e = performance.memory;
14
+ if (e)
15
+ try {
16
+ return e.usedJSHeapSize;
17
+ } catch {
18
+ }
19
+ }
20
+ return null;
21
+ }
22
+ const Je = 1e3, q = [];
23
+ function Xe(e) {
24
+ return W(e, { pretty: !0, maxDepth: 5, maxItems: 50 });
25
+ }
26
+ function Ze(...e) {
27
+ const n = e.map((t) => typeof t == "string" ? t : Xe(t)).join(" ");
28
+ q.push(n), q.length > Je && q.shift(), console.log(n);
29
+ }
30
+ function Ke() {
31
+ return q.join(`
32
+ `);
33
+ }
34
+ globalThis.__getStressTestLogLast = Ke;
35
+ const fe = (e, n) => {
36
+ Ze(n);
37
+ }, w = {
38
+ start: !0,
39
+ progress: 5e3,
40
+ completed: !0,
41
+ error: !0,
42
+ modeChange: !0,
43
+ debug: !1,
44
+ func: fe
45
+ }, Qe = {
46
+ start: !1,
47
+ progress: !1,
48
+ completed: !1,
49
+ error: !1,
50
+ modeChange: !1,
51
+ debug: !1,
52
+ func: fe
53
+ };
54
+ function de(e) {
55
+ return e === !1 ? Qe : 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
+ };
64
+ }
65
+ function Ye(e, n) {
66
+ const t = e.now();
67
+ return {
68
+ startTime: t,
69
+ startMemory: n,
70
+ debugMode: !1,
71
+ tests: 0,
72
+ iterations: 0,
73
+ iterationsAsync: 0,
74
+ prevLogTime: t,
75
+ prevLogMemory: n,
76
+ pendingModeChange: null,
77
+ prevGcTime: t,
78
+ prevGcIterations: 0,
79
+ prevGcIterationsAsync: 0
80
+ };
81
+ }
82
+ class T extends ze {
83
+ }
84
+ const et = 50, tt = 5;
85
+ function ae(e, n) {
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
+ }
88
+ function rt(e, n) {
89
+ const t = n.log;
90
+ let o = null, i = 0;
91
+ function s(r, l, u) {
92
+ o == null && (o = { error: r, args: l, tests: u }, t.error && t.func(
93
+ "error",
94
+ `[test-variants] error variant: ${W(l, { pretty: !0 })}
95
+ tests: ${u}
96
+ ${W(r)}`
97
+ ));
98
+ const d = Date.now();
99
+ if (Date.now() - d > et && i < tt) {
100
+ t.func(
101
+ "debug",
102
+ `[test-variants] debug iteration: ${i}`
103
+ ), i++;
104
+ return;
105
+ }
106
+ const h = o;
107
+ throw o = null, n.onError && n.onError(h), h.error;
108
+ }
109
+ return function(l, u, d) {
110
+ try {
111
+ const f = e(l, d);
112
+ return M(f) ? f.then(
113
+ (h) => ae(h, !0),
114
+ (h) => s(h, l, u)
115
+ ) : ae(f, !1);
116
+ } catch (f) {
117
+ return f instanceof T ? void 0 : s(f, l, u);
118
+ }
119
+ };
120
+ }
121
+ function U(e, n, t) {
122
+ for (let o = 0, i = e.length; o < i; o++)
123
+ if (t ? t(e[o], n) : e[o] === n)
124
+ return o;
125
+ return -1;
126
+ }
127
+ function le(e, n, t, o) {
128
+ const i = Object.keys(e.templates), s = {}, r = [], l = [], u = [], d = i.length;
129
+ for (let f = 0; f < d; f++) {
130
+ const h = i[f];
131
+ s[h] = void 0, r.push(-1), l.push(void 0), u.push(null);
132
+ }
133
+ return {
134
+ args: s,
135
+ argsNames: i,
136
+ indexes: r,
137
+ argValues: l,
138
+ argLimits: u,
139
+ attempts: 0,
140
+ templates: e,
141
+ limitArgOnError: t,
142
+ equals: n,
143
+ includeErrorVariant: o ?? !1
144
+ };
145
+ }
146
+ function C(e, n) {
147
+ const t = e.templates.templates[n], o = e.templates.extra[n];
148
+ let i;
149
+ if (typeof t == "function" ? i = t(e.args) : i = t, o == null)
150
+ return i;
151
+ let s = null;
152
+ const r = o.length;
153
+ for (let l = 0; l < r; l++) {
154
+ const u = o[l];
155
+ U(i, u, e.equals) < 0 && (s == null ? s = [...i, u] : s.push(u));
156
+ }
157
+ return s ?? i;
158
+ }
159
+ function E(e, n, t) {
160
+ const o = e.argValues[n].length, i = e.argLimits[n];
161
+ if (i == null)
162
+ return o - 1;
163
+ let s = e.limitArgOnError;
164
+ if (typeof s == "function") {
165
+ const r = e.argsNames[n];
166
+ s = s({
167
+ name: r,
168
+ values: e.argValues[n],
169
+ maxValueIndex: i
170
+ });
171
+ }
172
+ return !t || s ? Math.min(i, o - 1) : o - 1;
173
+ }
174
+ function N(e) {
175
+ const n = e.indexes.length;
176
+ for (let t = 0; t < n; t++) {
177
+ const o = e.argLimits[t];
178
+ if (o == null)
179
+ return !1;
180
+ const i = e.indexes[t];
181
+ if (i > o)
182
+ return !0;
183
+ if (i < o)
184
+ return !1;
185
+ }
186
+ return !e.includeErrorVariant;
187
+ }
188
+ function A(e) {
189
+ const n = e.indexes.length;
190
+ for (let t = 0; t < n; t++)
191
+ e.indexes[t] = -1, e.argValues[t] = void 0, e.args[e.argsNames[t]] = void 0;
192
+ }
193
+ function me(e) {
194
+ let n = !1, t = !0;
195
+ const o = e.indexes.length;
196
+ let i = o, s = !1, r = 0;
197
+ for (; r < o; r++) {
198
+ const l = e.argValues[r] == null;
199
+ (l || s) && (l && (n = !0), e.argValues[r] = C(
200
+ e,
201
+ e.argsNames[r]
202
+ ));
203
+ const u = E(
204
+ e,
205
+ r,
206
+ r > i
207
+ );
208
+ if (u < 0) {
209
+ t = !1, e.indexes[r] = -1;
210
+ break;
211
+ }
212
+ l && (e.indexes[r] = 0, e.args[e.argsNames[r]] = e.argValues[r][0]), (s || e.indexes[r] > u) && (e.indexes[r] = u, e.args[e.argsNames[r]] = e.argValues[r][u], s = !0), i === o && e.indexes[r] < u && (i = r);
213
+ }
214
+ if (N(e))
215
+ return A(e), !1;
216
+ if (n && t)
217
+ return !0;
218
+ for (r--; r >= 0; r--) {
219
+ if (e.argValues[r] == null)
220
+ continue;
221
+ let l = r > i;
222
+ const u = E(e, r, l), d = e.indexes[r] + 1;
223
+ if (d <= u) {
224
+ e.indexes[r] = d, e.args[e.argsNames[r]] = e.argValues[r][d], d < u && (l = !0);
225
+ for (let f = r + 1; f < o; f++)
226
+ e.args[e.argsNames[f]] = void 0;
227
+ for (r++; r < o; r++) {
228
+ e.argValues[r] = C(
229
+ e,
230
+ e.argsNames[r]
231
+ );
232
+ const f = E(e, r, l);
233
+ if (f < 0)
234
+ break;
235
+ e.indexes[r] = 0, e.args[e.argsNames[r]] = e.argValues[r][0], f > 0 && (l = !0);
236
+ }
237
+ if (r >= o)
238
+ return N(e) ? (A(e), !1) : !0;
239
+ }
240
+ }
241
+ return A(e), !1;
242
+ }
243
+ function z(e) {
244
+ N(e) && A(e);
245
+ let n = !1, t = !0;
246
+ const o = e.indexes.length;
247
+ let i = o, s = !1, r = 0;
248
+ for (; r < o; r++) {
249
+ const l = e.argValues[r] == null;
250
+ (l || s) && (l && (n = !0), e.argValues[r] = C(
251
+ e,
252
+ e.argsNames[r]
253
+ ));
254
+ const u = E(
255
+ e,
256
+ r,
257
+ r > i
258
+ );
259
+ if (u < 0) {
260
+ t = !1, e.indexes[r] = -1;
261
+ break;
262
+ }
263
+ l && (e.indexes[r] = u, e.args[e.argsNames[r]] = e.argValues[r][u]), (s || e.indexes[r] > u) && (e.indexes[r] = u, e.args[e.argsNames[r]] = e.argValues[r][u], s = !0), i === o && e.indexes[r] < u && (i = r);
264
+ }
265
+ if ((n || s) && t && !N(e))
266
+ return !0;
267
+ for (r--; r >= 0; r--) {
268
+ if (e.argValues[r] == null)
269
+ continue;
270
+ let l = r > i;
271
+ const u = E(e, r, l);
272
+ let d = e.indexes[r] - 1;
273
+ if (d > u && (d = u), d >= 0) {
274
+ e.indexes[r] = d, e.args[e.argsNames[r]] = e.argValues[r][d], d < u && (l = !0);
275
+ for (let f = r + 1; f < o; f++)
276
+ e.args[e.argsNames[f]] = void 0;
277
+ for (r++; r < o; r++) {
278
+ e.argValues[r] = C(
279
+ e,
280
+ e.argsNames[r]
281
+ );
282
+ const f = E(e, r, l);
283
+ if (f < 0)
284
+ break;
285
+ e.indexes[r] = f, e.args[e.argsNames[r]] = e.argValues[r][f], f > 0 && (l = !0);
286
+ }
287
+ if (r >= o)
288
+ return !0;
289
+ }
290
+ }
291
+ return A(e), !1;
292
+ }
293
+ function nt(e, n) {
294
+ A(e);
295
+ const t = e.argsNames, o = t.length, i = [];
296
+ for (let s = 0; s < o; s++) {
297
+ const r = t[s], l = n[r];
298
+ if (l === void 0)
299
+ return null;
300
+ e.argValues[s] = C(e, r);
301
+ const u = E(e, s, !0);
302
+ if (u < 0)
303
+ return null;
304
+ const d = U(
305
+ e.argValues[s],
306
+ l,
307
+ e.equals
308
+ );
309
+ if (d < 0 || d > u)
310
+ return null;
311
+ i.push(d), e.indexes[s] = d, e.args[e.argsNames[s]] = e.argValues[s][0];
312
+ }
313
+ return i;
314
+ }
315
+ function ot(e) {
316
+ const n = e.indexes.length;
317
+ if (n === 0)
318
+ return !1;
319
+ let t = !1;
320
+ for (let o = 0; o < n; o++) {
321
+ e.argValues[o] = C(e, e.argsNames[o]);
322
+ const i = E(e, o, t);
323
+ if (i < 0)
324
+ return Math.random() < 0.5 ? me(e) : z(e);
325
+ 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);
326
+ }
327
+ return N(e) ? z(e) : !0;
328
+ }
329
+ function _(e) {
330
+ return e.mode === "forward" || e.mode === "backward";
331
+ }
332
+ function it(e, n, t, o) {
333
+ const i = n[t], s = e.templates[t];
334
+ if (typeof s != "function") {
335
+ if (U(s, i, o) >= 0)
336
+ return;
337
+ s.push(i);
338
+ return;
339
+ }
340
+ const r = e.extra[t];
341
+ if (r == null) {
342
+ e.extra[t] = [i];
343
+ return;
344
+ }
345
+ U(r, i, o) >= 0 || r.push(i);
346
+ }
347
+ function st(e, n, t) {
348
+ for (const o in n)
349
+ if (Object.prototype.hasOwnProperty.call(n, o)) {
350
+ if (o === "seed")
351
+ continue;
352
+ it(e, n, o, t);
353
+ }
354
+ }
355
+ function at(e, n) {
356
+ for (const t in n)
357
+ if (Object.prototype.hasOwnProperty.call(n, t)) {
358
+ if (t === "seed")
359
+ continue;
360
+ if (!e[t])
361
+ return !1;
362
+ }
363
+ return !0;
364
+ }
365
+ const lt = [{ mode: "forward" }];
366
+ function ut(e) {
367
+ const {
368
+ argsTemplates: n,
369
+ equals: t,
370
+ limitArgOnError: o,
371
+ includeErrorVariant: i,
372
+ getSeed: s,
373
+ iterationModes: r,
374
+ onModeChange: l,
375
+ limitCompletionCount: u,
376
+ limitTests: d,
377
+ limitTime: f
378
+ } = e, h = e.timeController ?? K, y = {
379
+ templates: je(n),
380
+ extra: {}
381
+ }, p = r == null || r.length === 0 ? lt : r, b = [];
382
+ let x = null, O = null, m = 0, S = 0, V = !1, P = 0;
383
+ function te() {
384
+ V || (V = !0, P = h.now(), ve(), m = 0, re());
385
+ }
386
+ function ve() {
387
+ for (let a = 0, c = p.length; a < c; a++)
388
+ b.push(Se());
389
+ }
390
+ function Se() {
391
+ return {
392
+ navigationState: le(
393
+ y,
394
+ t ?? null,
395
+ o ?? null,
396
+ i ?? null
397
+ ),
398
+ cycleCount: 0,
399
+ completedCount: 0,
400
+ testsInLastTurn: 0,
401
+ tryNextVariantAttempts: 0,
402
+ startTime: null
403
+ };
404
+ }
405
+ function re() {
406
+ l?.({
407
+ mode: p[m],
408
+ modeIndex: m,
409
+ tests: S
410
+ });
411
+ }
412
+ function we(a) {
413
+ const c = a?.args;
414
+ if (c == null || (te(), !at(y.templates, c)))
415
+ return;
416
+ st(y, c, t), x == null && (x = le(
417
+ y,
418
+ t ?? null,
419
+ // ignore limitArgOnError for correct lexicographic comparison of new limit
420
+ !1,
421
+ // ignore includeErrorVariant for correct lexicographic comparison of new limit
422
+ !1
423
+ ));
424
+ const g = nt(x, c);
425
+ if (g != null) {
426
+ O = {
427
+ args: c,
428
+ error: a?.error,
429
+ tests: a?.tests ?? S
430
+ };
431
+ for (let v = 0, G = b.length; v < G; v++) {
432
+ const F = b[v].navigationState;
433
+ F.argLimits = g;
434
+ }
435
+ }
436
+ }
437
+ function Ee() {
438
+ return te(), xe();
439
+ }
440
+ function xe() {
441
+ for (; ; ) {
442
+ if (!Me())
443
+ return null;
444
+ for (; ; ) {
445
+ const a = $e();
446
+ if (a != null)
447
+ return b[m].testsInLastTurn++, S++, a;
448
+ if (Oe()) {
449
+ if (!Le())
450
+ return null;
451
+ Pe();
452
+ break;
453
+ }
454
+ }
455
+ }
456
+ }
457
+ function Me() {
458
+ return !(Te() || Ve() || $() && (Ie() || !Ae()) || !Ce());
459
+ }
460
+ function Te() {
461
+ return d != null && S >= d;
462
+ }
463
+ function Ve() {
464
+ return f != null && h.now() - P >= f;
465
+ }
466
+ function Ie() {
467
+ if (!$())
468
+ throw new Error("Unexpected behavior");
469
+ return u != null && u <= 0;
470
+ }
471
+ function Ae() {
472
+ if (!$())
473
+ throw new Error("Unexpected behavior");
474
+ for (let a = 0, c = p.length; a < c; a++)
475
+ if (I(p[a]) && R(a))
476
+ return !0;
477
+ return !1;
478
+ }
479
+ function Ce() {
480
+ for (let a = 0, c = p.length; a < c; a++)
481
+ if (R(a))
482
+ return !0;
483
+ return !1;
484
+ }
485
+ function Oe() {
486
+ m++;
487
+ const a = m >= p.length;
488
+ return a && (m = 0), re(), a;
489
+ }
490
+ function Le() {
491
+ if ($()) {
492
+ const a = Ne();
493
+ if (u != null && a >= u)
494
+ return !1;
495
+ }
496
+ return !0;
497
+ }
498
+ function $() {
499
+ for (let a = 0, c = p.length; a < c; a++)
500
+ if (_(p[a]))
501
+ return !0;
502
+ return !1;
503
+ }
504
+ function Ne() {
505
+ let a = !1, c = 1 / 0;
506
+ for (let g = 0, v = b.length; g < v; g++) {
507
+ const G = b[g], F = p[g];
508
+ _(F) && (a = !0, R(g) && G.completedCount < c && (c = G.completedCount));
509
+ }
510
+ if (!a)
511
+ throw new Error("Unexpected behavior");
512
+ return c;
513
+ }
514
+ function R(a) {
515
+ const c = p[a], g = b[a];
516
+ return c.limitTests != null && c.limitTests <= 0 || I(c) && (c.cycles != null && c.cycles <= 0 || c.attemptsPerVariant != null && c.attemptsPerVariant <= 0) ? !1 : g.tryNextVariantAttempts < 2;
517
+ }
518
+ function Pe() {
519
+ m = 0;
520
+ for (let a = 0, c = b.length; a < c; a++) {
521
+ const g = b[a];
522
+ g.testsInLastTurn = 0, g.startTime = null;
523
+ }
524
+ }
525
+ function $e() {
526
+ let a = 0;
527
+ for (; a < 2; ) {
528
+ if (!Ge())
529
+ return null;
530
+ const c = Be();
531
+ if (c != null)
532
+ return c;
533
+ if (I(p[m]) && De())
534
+ return null;
535
+ a++;
536
+ }
537
+ return null;
538
+ }
539
+ function Ge() {
540
+ const a = p[m];
541
+ return !(_e() || qe() || I(a) && !Ue(m));
542
+ }
543
+ function _e() {
544
+ const a = p[m], c = b[m];
545
+ return a.limitTests != null && c.testsInLastTurn >= a.limitTests;
546
+ }
547
+ function qe() {
548
+ const a = p[m], c = b[m];
549
+ return a.limitTime != null && c.startTime != null && h.now() - c.startTime >= a.limitTime;
550
+ }
551
+ function I(a) {
552
+ return _(a);
553
+ }
554
+ function Ue(a) {
555
+ const c = p[a], g = b[a];
556
+ if (!I(c))
557
+ throw new Error("Unexpected behavior");
558
+ return g.cycleCount < (c.cycles ?? 1);
559
+ }
560
+ function De() {
561
+ const a = p[m], c = b[m];
562
+ if (!I(a))
563
+ throw new Error("Unexpected behavior");
564
+ return c.cycleCount++, c.cycleCount >= (a.cycles ?? 1) ? (c.cycleCount = 0, c.completedCount++, !0) : !1;
565
+ }
566
+ function Be() {
567
+ const a = p[m], c = b[m], g = c.navigationState;
568
+ if (L(a)) {
569
+ if (k())
570
+ return null;
571
+ const v = Re();
572
+ if (v != null)
573
+ return c.startTime == null && (c.startTime = h.now()), v;
574
+ }
575
+ return Fe() ? (c.tryNextVariantAttempts = 0, L(a) && ke(), c.startTime == null && (c.startTime = h.now()), ne(g.args)) : (c.tryNextVariantAttempts++, null);
576
+ }
577
+ function Re() {
578
+ const a = p[m], g = b[m].navigationState;
579
+ if (!L(a))
580
+ throw new Error("Unexpected behavior");
581
+ if (k())
582
+ throw new Error("Unexpected behavior");
583
+ const v = a.attemptsPerVariant ?? 1;
584
+ return g.attempts > 0 && g.attempts < v ? (g.attempts++, ne(g.args)) : null;
585
+ }
586
+ function ke() {
587
+ const a = p[m], g = b[m].navigationState;
588
+ if (!L(a))
589
+ throw new Error("Unexpected behavior");
590
+ if (k())
591
+ throw new Error("Unexpected behavior");
592
+ g.attempts = 1;
593
+ }
594
+ function L(a) {
595
+ return _(a);
596
+ }
597
+ function k() {
598
+ const a = p[m];
599
+ if (!L(a))
600
+ throw new Error("Unexpected behavior");
601
+ return (a.attemptsPerVariant ?? 1) <= 0;
602
+ }
603
+ function Fe() {
604
+ const a = p[m], g = b[m].navigationState;
605
+ switch (a.mode) {
606
+ case "forward":
607
+ return me(g);
608
+ case "backward":
609
+ return z(g);
610
+ case "random":
611
+ return ot(g);
612
+ default:
613
+ throw new Error(`Unknown mode: ${a.mode}`);
614
+ }
615
+ }
616
+ function ne(a) {
617
+ const c = { ...a };
618
+ return s != null && (c.seed = s({ tests: S })), c;
619
+ }
620
+ return {
621
+ get limit() {
622
+ return O;
623
+ },
624
+ get modeIndex() {
625
+ return m;
626
+ },
627
+ get modeConfigs() {
628
+ return p;
629
+ },
630
+ get modeStates() {
631
+ return b;
632
+ },
633
+ get tests() {
634
+ return S;
635
+ },
636
+ addLimit: we,
637
+ next: Ee
638
+ };
639
+ }
640
+ function Y(e) {
641
+ if (e == null || e <= 0)
642
+ throw new Error(`Iterations = ${e}`);
643
+ e--;
644
+ const n = We().then(() => e);
645
+ return e <= 0 ? n : n.then(Y);
646
+ }
647
+ function ct(e, n, t) {
648
+ const o = n.limit ? {
649
+ error: n.limit.error,
650
+ args: n.limit.args,
651
+ tests: n.limit.tests
652
+ } : null;
653
+ if (o && !t)
654
+ throw o.error;
655
+ return {
656
+ iterations: e.iterations,
657
+ bestError: o
658
+ };
659
+ }
660
+ const ue = 2 ** 31;
661
+ function ft(e) {
662
+ if (e == null)
663
+ return { parallel: 1, sequentialOnError: !1 };
664
+ if (typeof e == "boolean")
665
+ return {
666
+ parallel: e ? ue : 1,
667
+ sequentialOnError: !1
668
+ };
669
+ if (typeof e == "number")
670
+ return { parallel: e > 0 ? e : 1, sequentialOnError: !1 };
671
+ const n = e.count;
672
+ let t = 1;
673
+ return n === !0 ? t = ue : typeof n == "number" && n > 0 && (t = n), {
674
+ parallel: t,
675
+ sequentialOnError: e.sequentialOnError ?? !1
676
+ };
677
+ }
678
+ function dt(e) {
679
+ const n = e?.saveErrorVariants, t = n && e.createSaveErrorVariantsStore ? e.createSaveErrorVariantsStore(n) : null, o = e?.findBestError, { parallel: i, sequentialOnError: s } = ft(
680
+ e?.parallel
681
+ );
682
+ return {
683
+ store: t,
684
+ GC_Iterations: e?.GC_Iterations ?? 1e6,
685
+ GC_IterationsAsync: e?.GC_IterationsAsync ?? 1e4,
686
+ GC_Interval: e?.GC_Interval ?? 1e3,
687
+ logOptions: de(e?.log),
688
+ abortSignalExternal: e?.abortSignal,
689
+ findBestError: o,
690
+ dontThrowIfError: o?.dontThrowIfError,
691
+ timeController: e?.timeController ?? K,
692
+ parallel: i,
693
+ sequentialOnError: s
694
+ };
695
+ }
696
+ function D(e, n, t) {
697
+ const { options: o, variantsIterator: i } = e, s = i.limit?.args ?? n;
698
+ if (!o.store)
699
+ return;
700
+ const r = o.store.save(s);
701
+ if (t)
702
+ return r;
703
+ }
704
+ function mt(e, n, t, o) {
705
+ const { abortControllerParallel: i, state: s, options: r } = e, { logOptions: l } = r;
706
+ if (e.options.findBestError)
707
+ e.variantsIterator.addLimit({ args: n, error: t, tests: o }), s.debugMode = !1, D(e, n, !1), r.sequentialOnError && !i.signal.aborted ? (l.debug && l.func(
708
+ "debug",
709
+ "[test-variants] sequentialOnError: aborting parallel, switching to sequential"
710
+ ), i.abort(new T())) : l.debug && l.func(
711
+ "debug",
712
+ "[test-variants] parallel error in findBestError mode, continuing with new limits"
713
+ );
714
+ else {
715
+ if (i.signal.aborted)
716
+ return;
717
+ D(e, n, !1), i.abort(t);
718
+ }
719
+ }
720
+ function ce(e, n, t, o) {
721
+ const { state: i } = e;
722
+ if (e.options.findBestError) {
723
+ e.variantsIterator.addLimit({ args: n, error: t, tests: o });
724
+ const r = D(e, n, !0);
725
+ if (r)
726
+ return r.then(() => {
727
+ i.debugMode = !1;
728
+ });
729
+ i.debugMode = !1;
730
+ return;
731
+ }
732
+ const s = D(e, n, !0);
733
+ if (s)
734
+ return s.then(() => {
735
+ throw t;
736
+ });
737
+ throw t;
738
+ }
739
+ function gt(e, n) {
740
+ const { GC_Iterations: t, GC_IterationsAsync: o, GC_Interval: i } = e.options;
741
+ 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;
742
+ }
743
+ async function pt(e, n) {
744
+ e.prevGcIterations = e.iterations, e.prevGcIterationsAsync = e.iterationsAsync, e.prevGcTime = n, await Y(1);
745
+ }
746
+ function ee(e) {
747
+ const n = e / 1e3;
748
+ if (n < 60)
749
+ return `${n.toFixed(1)}s`;
750
+ const t = n / 60;
751
+ return t < 60 ? `${t.toFixed(1)}m` : `${(t / 60).toFixed(1)}h`;
752
+ }
753
+ function H(e) {
754
+ const n = e / 1073741824;
755
+ if (n >= 1)
756
+ return n >= 10 ? `${Math.round(n)}GB` : `${n.toFixed(1)}GB`;
757
+ const t = e / (1024 * 1024);
758
+ return t >= 10 ? `${Math.round(t)}MB` : `${t.toFixed(1)}MB`;
759
+ }
760
+ function ht(e, n) {
761
+ if (!e)
762
+ return `mode[${n}]: null`;
763
+ let t = `mode[${n}]: ${e.mode}`;
764
+ 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=${ee(e.limitTime)}`), e.limitTests != null && (t += `, limitTests=${e.limitTests}`), t;
765
+ }
766
+ function ge(e, n) {
767
+ const t = e - n, o = t >= 0 ? "+" : "";
768
+ return `${H(e)} (${o}${H(t)})`;
769
+ }
770
+ function bt(e, n) {
771
+ if (!e.start)
772
+ return;
773
+ let t = "[test-variants] start";
774
+ n != null && (t += `, memory: ${H(n)}`), e.func("start", t);
775
+ }
776
+ function yt(e) {
777
+ const { options: n, state: t } = e, { logOptions: o, timeController: i } = n;
778
+ if (!o.completed)
779
+ return;
780
+ const s = i.now() - t.startTime;
781
+ let r = `[test-variants] end, tests: ${t.tests} (${ee(s)}), async: ${t.iterationsAsync}`;
782
+ if (t.startMemory != null) {
783
+ const l = Q();
784
+ l != null && (r += `, memory: ${ge(l, t.startMemory)}`);
785
+ }
786
+ o.func("completed", r);
787
+ }
788
+ function pe(e) {
789
+ const { options: n, state: t } = e, { logOptions: o } = n, i = t.pendingModeChange;
790
+ !o.modeChange || i == null || (o.func(
791
+ "modeChange",
792
+ `[test-variants] ${ht(i.mode, i.modeIndex)}`
793
+ ), t.pendingModeChange = null);
794
+ }
795
+ function vt(e) {
796
+ const { options: n, state: t } = e, { logOptions: o, timeController: i } = n, s = i.now();
797
+ if (!o.progress || s - t.prevLogTime < o.progress)
798
+ return !1;
799
+ pe(e);
800
+ const r = s - t.startTime;
801
+ let l = `[test-variants] tests: ${t.tests} (${ee(r)}), async: ${t.iterationsAsync}`;
802
+ if (t.prevLogMemory != null) {
803
+ const u = Q();
804
+ u != null && (l += `, memory: ${ge(u, t.prevLogMemory)}`, t.prevLogMemory = u);
805
+ }
806
+ return o.func("progress", l), t.prevLogTime = s, !0;
807
+ }
808
+ function J(e, n) {
809
+ e.debugMode = !1, n && (e.iterationsAsync += n.iterationsAsync, e.iterations += n.iterationsSync + n.iterationsAsync);
810
+ }
811
+ function X(e) {
812
+ e.state.debugMode = !0, e.abortControllerParallel.abort(new T());
813
+ }
814
+ function he(e, n) {
815
+ const { testRun: t, testOptions: o, state: i } = e, s = i.tests;
816
+ i.tests++;
817
+ try {
818
+ const r = t(n, s, o);
819
+ if (M(r))
820
+ return r.then(
821
+ (l) => {
822
+ if (!l) {
823
+ X(e);
824
+ return;
825
+ }
826
+ J(i, l);
827
+ },
828
+ (l) => ce(e, n, l, s)
829
+ );
830
+ if (!r) {
831
+ X(e);
832
+ return;
833
+ }
834
+ J(i, r);
835
+ } catch (r) {
836
+ return r instanceof T ? void 0 : ce(e, n, r, s);
837
+ }
838
+ }
839
+ function St(e, n) {
840
+ const { pool: t, abortSignal: o, testRun: i, testOptionsParallel: s, state: r } = e;
841
+ if (!t)
842
+ return;
843
+ const l = r.tests;
844
+ r.tests++, (async () => {
845
+ try {
846
+ if (o.aborted)
847
+ return;
848
+ let u = i(n, l, s);
849
+ if (M(u) && (u = await u), !u) {
850
+ X(e);
851
+ return;
852
+ }
853
+ J(r, u);
854
+ } catch (u) {
855
+ if (u instanceof T)
856
+ return;
857
+ mt(e, n, u, l);
858
+ } finally {
859
+ t.release(1);
860
+ }
861
+ })();
862
+ }
863
+ function be(e) {
864
+ const { options: n, state: t } = e, { logOptions: o, timeController: i, GC_Interval: s } = n;
865
+ if (!o.progress && !s)
866
+ return;
867
+ vt(e);
868
+ const r = i.now();
869
+ if (gt(e, r))
870
+ return pt(t, r);
871
+ }
872
+ function B(e) {
873
+ return e.options.abortSignalExternal?.aborted ?? !1;
874
+ }
875
+ function Z(e) {
876
+ return e.abortSignal.aborted;
877
+ }
878
+ function ye(e, n) {
879
+ return e.state.debugMode ? n : e.variantsIterator.next();
880
+ }
881
+ async function j(e, n) {
882
+ const { pool: t, state: o, options: i } = e, { parallel: s, logOptions: r } = i;
883
+ let l = n ?? null;
884
+ for (; !B(e); ) {
885
+ const u = t && !Z(e);
886
+ let d = !1;
887
+ u && (t.hold(1) || await se({ pool: t, count: 1, hold: !0 }), d = !0);
888
+ try {
889
+ if (l == null && (l = ye(e, l), l == null))
890
+ break;
891
+ const f = be(e);
892
+ if (M(f) && await f, B(e)) {
893
+ l = null;
894
+ continue;
895
+ }
896
+ if (u)
897
+ St(e, l), d = !1;
898
+ else {
899
+ r.debug && t && Z(e) && r.func(
900
+ "debug",
901
+ `[test-variants] parallel aborted, running sequential: tests=${o.tests}`
902
+ );
903
+ const h = he(e, l);
904
+ M(h) && await h;
905
+ }
906
+ l = null;
907
+ } finally {
908
+ d && t.release(1);
909
+ }
910
+ }
911
+ t && (await se({ pool: t, count: s, hold: !0 }), t.release(s));
912
+ }
913
+ function wt(e) {
914
+ const { pool: n, state: t, options: o } = e, { logOptions: i } = o;
915
+ if (n)
916
+ return j(e);
917
+ let s = null;
918
+ for (; !B(e) && (s = ye(e, s), s != null); ) {
919
+ const r = be(e);
920
+ if (M(r)) {
921
+ const u = s;
922
+ return r.then(() => j(e, u));
923
+ }
924
+ if (B(e))
925
+ continue;
926
+ i.debug && Z(e) && i.func(
927
+ "debug",
928
+ `[test-variants] parallel aborted, running sequential: tests=${t.tests}`
929
+ );
930
+ const l = he(e, s);
931
+ if (M(l))
932
+ return l.then(() => j(e));
933
+ }
934
+ }
935
+ async function Et(e, n, t, o) {
936
+ const i = dt(o), {
937
+ store: s,
938
+ logOptions: r,
939
+ abortSignalExternal: l,
940
+ findBestError: u,
941
+ dontThrowIfError: d,
942
+ timeController: f,
943
+ parallel: h
944
+ } = i, y = new ie(), p = new ie(), b = oe(
945
+ l,
946
+ y.signal
947
+ ), x = oe(
948
+ b,
949
+ p.signal
950
+ ), O = {
951
+ abortSignal: b,
952
+ timeController: f
953
+ }, m = {
954
+ abortSignal: x,
955
+ timeController: f
956
+ };
957
+ s && await s.replay({
958
+ testRun: e,
959
+ variantsIterator: n,
960
+ testOptions: O,
961
+ findBestErrorEnabled: !!u
962
+ });
963
+ const S = h <= 1 ? null : new He(h);
964
+ bt(r, t.startMemory);
965
+ const V = {
966
+ options: i,
967
+ testRun: e,
968
+ variantsIterator: n,
969
+ testOptions: O,
970
+ testOptionsParallel: m,
971
+ abortControllerGlobal: y,
972
+ abortControllerParallel: p,
973
+ abortSignal: x,
974
+ pool: S,
975
+ state: t
976
+ };
977
+ pe(V);
978
+ try {
979
+ await wt(V), x.throwIfAborted();
980
+ } catch (P) {
981
+ throw y.abort(new T()), P;
982
+ }
983
+ return b.throwIfAborted(), y.abort(new T()), yt(V), await Y(1), ct(t, n, d);
984
+ }
985
+ function Ct(e) {
986
+ return function(t) {
987
+ return async function(i) {
988
+ const s = de(i?.log), r = rt(e, {
989
+ onError: i?.onError,
990
+ log: s
991
+ }), l = i?.timeController ?? K, u = Q(), d = Ye(l, u), f = i?.onModeChange;
992
+ function h(p) {
993
+ d.pendingModeChange = p, f?.(p);
994
+ }
995
+ const y = ut({
996
+ argsTemplates: t,
997
+ getSeed: i?.getSeed,
998
+ iterationModes: i?.iterationModes,
999
+ equals: i?.findBestError?.equals,
1000
+ limitArgOnError: i?.findBestError?.limitArgOnError,
1001
+ includeErrorVariant: i?.findBestError?.includeErrorVariant,
1002
+ timeController: l,
1003
+ onModeChange: h,
1004
+ limitCompletionCount: i?.cycles ?? 1,
1005
+ limitTests: i?.limitTests,
1006
+ limitTime: i?.limitTime
1007
+ });
1008
+ return Et(r, y, d, i);
1009
+ };
1010
+ };
1011
+ }
1012
+ export {
1013
+ Ct as c
1014
+ };