@flemist/test-variants 5.0.16 → 5.0.18
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/README.md +15 -6
- 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/common/test-variants/-test/invariants/LogInvariant.d.ts +3 -0
- package/build/common/test-variants/iterator/types.d.ts +2 -2
- package/build/common/test-variants/log/format.d.ts +6 -0
- package/build/common/test-variants/run/createRunState.d.ts +1 -1
- package/build/common/test-variants/run/resolveRunOptions.d.ts +1 -0
- package/build/common/test-variants/run/types.d.ts +5 -0
- package/build/common/test-variants/types.d.ts +6 -1
- package/build/createTestVariants-B-tIuCMH.js +4 -0
- package/build/createTestVariants-BiAcjV3Y.mjs +1136 -0
- package/build/node/index.cjs +1 -1
- package/build/node/index.mjs +121 -80
- package/package.json +1 -1
- package/build/createTestVariants-CHE7urh4.js +0 -4
- package/build/createTestVariants-o9_knZSz.mjs +0 -1109
package/build/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../createTestVariants-B-tIuCMH.js"),q=require("path"),V=require("@flemist/simple-utils"),_=require("@flemist/simple-utils/node"),J=require("fs");function D(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const A=D(q),h=D(J);async function B(e){const t=await h.promises.stat(e).catch(()=>null);if(t==null)return[];if(!t.isDirectory())throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);return(await h.promises.readdir(e)).filter(s=>s.endsWith(".json")).sort((s,l)=>s>l?-1:s<l?1:0).map(s=>A.join(e,s))}async function C(e,t){const n=await h.promises.readFile(e,"utf-8");let r;try{r=JSON.parse(n)}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 R(e){const t=Math.random().toString(36).substring(2);return V.formatDateFileName(e.sessionDate,"UTC")+"_"+t+".json"}async function U(e,t,n){let r;if(n){const s=n(e);typeof s=="string"?r=s:r=JSON.stringify(s,null,2)}else r=JSON.stringify(e,null,2);await h.promises.mkdir(A.dirname(t),{recursive:!0}),await h.promises.writeFile(t,r,"utf-8")}function z(e,t){const n=Math.max(e.length,t.length);for(let r=0;r<n;r++){const s=e[r],l=t[r];if(s==null){if(l==null)continue;return 1}if(l==null||s<l)return-1;if(s>l)return 1}return 0}class W{options;filePath;lastSavedArgs=null;constructor(t){this.options=t;const n=new Date;this.filePath=A.resolve(t.dir,t.getFilePath?.({sessionDate:n})??R({sessionDate:n}))}async save(t){V.deepEqualJsonLike(t,this.lastSavedArgs)||(this.lastSavedArgs={...t},await _.fileLock({filePath:this.filePath,func:()=>U(t,this.filePath,this.options.argsToJson)}))}async replay(t){const{testRun:n,variantsIterator:r,testOptions:s,findBestErrorEnabled:l,state:a,logOptions:c,timeControllerInternal:v}=t,M=this.options.useToFindBestError,I=this.options.limitArg??!1,k=this.options.extendTemplates??!1,L=this.options.attemptsPerVariant??1,x=new Map;function T(i){let o=x.get(i);return o===void 0&&(o=r.calcIndexes(i,{includeLimit:!1,limitArg:I}),x.set(i,o)),o}const d=await B(this.options.dir);if(d.length===0)return;const u=[];for(let i=0,o=d.length;i<o;i++){const m=d[i],p=await C(m,this.options.jsonToArgs);k&&r.extendTemplates(p),T(p)!=null?u.push(p):c.replay&&c.func("replay",`[test-variants] replay skipped, args not in template; file: ${m}`)}if(u.length===0)return;const O=c.replay,P=c.replay&&c.progress,S=v.now(),j=a.tests,F=a.iterationsAsync,y=g.getMemoryUsage();if(O){let i=`[test-variants] replay, files: ${u.length}/${d.length}`;y!=null&&(i+=`, memory: ${g.formatBytes(y)}`),c.func("replay",i)}function N(i,o){return z(T(i),T(o))}u.sort(N);let b=S,$=y;for(let i=0,o=u.length;i<o;i++){const m=u[i];for(let p=0;p<L;p++){if(P){const f=v.now();if(f-b>=P){b=f;const w=f-S,E=g.formatTestStats(a.tests-j,w,a.maxTestDuration,a.iterationsAsync-F,$);E.memory!=null&&($=E.memory),c.func("progress",`[test-variants] replay, ${E.message}`)}}try{const f=a.tests;a.tests++;const w=n(m,f,s);V.isPromiseLike(w)&&await w}catch(f){if(M&&l){r.addLimit({args:m,error:f});break}throw f}}}if(O){const i=v.now()-S,o=g.formatTestStats(a.tests-j,i,a.maxTestDuration,a.iterationsAsync-F,y);c.func("replay",`[test-variants] replay end, ${o.message}`)}}}function G(e){return new W(e)}function H(e){const t=g.createTestVariants(e);return function(r){const s=t(r);return function(a){return s({...a,createSaveErrorVariantsStore:G})}}}exports.createTestVariants=H;
|
package/build/node/index.mjs
CHANGED
|
@@ -1,144 +1,185 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import * as
|
|
3
|
-
import { formatDateFileName as
|
|
4
|
-
import { fileLock as
|
|
5
|
-
import * as
|
|
6
|
-
async function
|
|
7
|
-
const t = await
|
|
1
|
+
import { g as N, f as J, a as j, c as B } from "../createTestVariants-BiAcjV3Y.mjs";
|
|
2
|
+
import * as V from "path";
|
|
3
|
+
import { formatDateFileName as C, deepEqualJsonLike as R, isPromiseLike as b } from "@flemist/simple-utils";
|
|
4
|
+
import { fileLock as U } from "@flemist/simple-utils/node";
|
|
5
|
+
import * as h from "fs";
|
|
6
|
+
async function q(e) {
|
|
7
|
+
const t = await h.promises.stat(e).catch(() => null);
|
|
8
8
|
if (t == null)
|
|
9
9
|
return [];
|
|
10
10
|
if (!t.isDirectory())
|
|
11
11
|
throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);
|
|
12
|
-
return (await
|
|
12
|
+
return (await h.promises.readdir(e)).filter((r) => r.endsWith(".json")).sort((r, l) => r > l ? -1 : r < l ? 1 : 0).map((r) => V.join(e, r));
|
|
13
13
|
}
|
|
14
|
-
async function
|
|
15
|
-
const
|
|
16
|
-
let
|
|
14
|
+
async function W(e, t) {
|
|
15
|
+
const i = await h.promises.readFile(e, "utf-8");
|
|
16
|
+
let s;
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
s = JSON.parse(i);
|
|
19
19
|
} catch {
|
|
20
20
|
throw new Error(`[saveErrorVariants] invalid JSON in file: ${e}`);
|
|
21
21
|
}
|
|
22
22
|
if (t)
|
|
23
23
|
try {
|
|
24
|
-
return t(
|
|
24
|
+
return t(s);
|
|
25
25
|
} catch {
|
|
26
26
|
throw new Error(
|
|
27
27
|
`[saveErrorVariants] jsonToArgs failed for file: ${e}`
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
return
|
|
30
|
+
return s;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function _(e) {
|
|
33
33
|
const t = Math.random().toString(36).substring(2);
|
|
34
|
-
return
|
|
34
|
+
return C(e.sessionDate, "UTC") + "_" + t + ".json";
|
|
35
35
|
}
|
|
36
|
-
async function
|
|
37
|
-
let
|
|
38
|
-
if (
|
|
39
|
-
const
|
|
40
|
-
typeof
|
|
36
|
+
async function z(e, t, i) {
|
|
37
|
+
let s;
|
|
38
|
+
if (i) {
|
|
39
|
+
const r = i(e);
|
|
40
|
+
typeof r == "string" ? s = r : s = JSON.stringify(r, null, 2);
|
|
41
41
|
} else
|
|
42
|
-
|
|
43
|
-
await
|
|
42
|
+
s = JSON.stringify(e, null, 2);
|
|
43
|
+
await h.promises.mkdir(V.dirname(t), { recursive: !0 }), await h.promises.writeFile(t, s, "utf-8");
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
for (let
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
45
|
+
function G(e, t) {
|
|
46
|
+
const i = Math.max(e.length, t.length);
|
|
47
|
+
for (let s = 0; s < i; s++) {
|
|
48
|
+
const r = e[s], l = t[s];
|
|
49
|
+
if (r == null) {
|
|
50
|
+
if (l == null)
|
|
51
51
|
continue;
|
|
52
52
|
return 1;
|
|
53
53
|
}
|
|
54
|
-
if (
|
|
54
|
+
if (l == null || r < l)
|
|
55
55
|
return -1;
|
|
56
|
-
if (
|
|
56
|
+
if (r > l)
|
|
57
57
|
return 1;
|
|
58
58
|
}
|
|
59
59
|
return 0;
|
|
60
60
|
}
|
|
61
|
-
class
|
|
61
|
+
class H {
|
|
62
62
|
options;
|
|
63
63
|
filePath;
|
|
64
64
|
lastSavedArgs = null;
|
|
65
65
|
constructor(t) {
|
|
66
66
|
this.options = t;
|
|
67
|
-
const
|
|
68
|
-
this.filePath =
|
|
67
|
+
const i = /* @__PURE__ */ new Date();
|
|
68
|
+
this.filePath = V.resolve(
|
|
69
69
|
t.dir,
|
|
70
|
-
t.getFilePath?.({ sessionDate:
|
|
70
|
+
t.getFilePath?.({ sessionDate: i }) ?? _({ sessionDate: i })
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
async save(t) {
|
|
74
|
-
|
|
74
|
+
R(t, this.lastSavedArgs) || (this.lastSavedArgs = { ...t }, await U({
|
|
75
75
|
filePath: this.filePath,
|
|
76
|
-
func: () =>
|
|
76
|
+
func: () => z(t, this.filePath, this.options.argsToJson)
|
|
77
77
|
}));
|
|
78
78
|
}
|
|
79
79
|
async replay(t) {
|
|
80
80
|
const {
|
|
81
|
-
testRun:
|
|
82
|
-
variantsIterator:
|
|
83
|
-
testOptions:
|
|
84
|
-
findBestErrorEnabled:
|
|
85
|
-
state:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
testRun: i,
|
|
82
|
+
variantsIterator: s,
|
|
83
|
+
testOptions: r,
|
|
84
|
+
findBestErrorEnabled: l,
|
|
85
|
+
state: a,
|
|
86
|
+
logOptions: c,
|
|
87
|
+
timeControllerInternal: w
|
|
88
|
+
} = t, D = this.options.useToFindBestError, L = this.options.limitArg ?? !1, M = this.options.extendTemplates ?? !1, O = this.options.attemptsPerVariant ?? 1, x = /* @__PURE__ */ new Map();
|
|
89
|
+
function v(n) {
|
|
90
|
+
let o = x.get(n);
|
|
91
|
+
return o === void 0 && (o = s.calcIndexes(n, {
|
|
90
92
|
includeLimit: !1,
|
|
91
|
-
limitArg:
|
|
92
|
-
}),
|
|
93
|
+
limitArg: L
|
|
94
|
+
}), x.set(n, o)), o;
|
|
93
95
|
}
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
const g = await q(this.options.dir);
|
|
97
|
+
if (g.length === 0)
|
|
98
|
+
return;
|
|
99
|
+
const u = [];
|
|
100
|
+
for (let n = 0, o = g.length; n < o; n++) {
|
|
101
|
+
const m = g[n], p = await W(
|
|
102
|
+
m,
|
|
98
103
|
this.options.jsonToArgs
|
|
99
104
|
);
|
|
100
|
-
|
|
105
|
+
M && s.extendTemplates(p), v(p) != null ? u.push(p) : c.replay && c.func(
|
|
106
|
+
"replay",
|
|
107
|
+
`[test-variants] replay skipped, args not in template; file: ${m}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (u.length === 0)
|
|
111
|
+
return;
|
|
112
|
+
const A = c.replay, S = c.replay && c.progress, E = w.now(), F = a.tests, P = a.iterationsAsync, y = N();
|
|
113
|
+
if (A) {
|
|
114
|
+
let n = `[test-variants] replay, files: ${u.length}/${g.length}`;
|
|
115
|
+
y != null && (n += `, memory: ${J(y)}`), c.func("replay", n);
|
|
101
116
|
}
|
|
102
|
-
function
|
|
103
|
-
return
|
|
117
|
+
function k(n, o) {
|
|
118
|
+
return G(v(n), v(o));
|
|
104
119
|
}
|
|
105
|
-
u.sort(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
u.sort(k);
|
|
121
|
+
let $ = E, I = y;
|
|
122
|
+
for (let n = 0, o = u.length; n < o; n++) {
|
|
123
|
+
const m = u[n];
|
|
124
|
+
for (let p = 0; p < O; p++) {
|
|
125
|
+
if (S) {
|
|
126
|
+
const f = w.now();
|
|
127
|
+
if (f - $ >= S) {
|
|
128
|
+
$ = f;
|
|
129
|
+
const d = f - E, T = j(
|
|
130
|
+
a.tests - F,
|
|
131
|
+
d,
|
|
132
|
+
a.maxTestDuration,
|
|
133
|
+
a.iterationsAsync - P,
|
|
134
|
+
I
|
|
135
|
+
);
|
|
136
|
+
T.memory != null && (I = T.memory), c.func("progress", `[test-variants] replay, ${T.message}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
109
139
|
try {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
} catch (
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
args:
|
|
118
|
-
error:
|
|
140
|
+
const f = a.tests;
|
|
141
|
+
a.tests++;
|
|
142
|
+
const d = i(m, f, r);
|
|
143
|
+
b(d) && await d;
|
|
144
|
+
} catch (f) {
|
|
145
|
+
if (D && l) {
|
|
146
|
+
s.addLimit({
|
|
147
|
+
args: m,
|
|
148
|
+
error: f
|
|
119
149
|
});
|
|
120
150
|
break;
|
|
121
151
|
}
|
|
122
|
-
throw
|
|
152
|
+
throw f;
|
|
123
153
|
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (A) {
|
|
157
|
+
const n = w.now() - E, o = j(
|
|
158
|
+
a.tests - F,
|
|
159
|
+
n,
|
|
160
|
+
a.maxTestDuration,
|
|
161
|
+
a.iterationsAsync - P,
|
|
162
|
+
y
|
|
163
|
+
);
|
|
164
|
+
c.func("replay", `[test-variants] replay end, ${o.message}`);
|
|
124
165
|
}
|
|
125
166
|
}
|
|
126
167
|
}
|
|
127
|
-
function
|
|
128
|
-
return new
|
|
168
|
+
function K(e) {
|
|
169
|
+
return new H(e);
|
|
129
170
|
}
|
|
130
|
-
function
|
|
131
|
-
const t =
|
|
132
|
-
return function(
|
|
133
|
-
const
|
|
134
|
-
return function(
|
|
135
|
-
return
|
|
136
|
-
...
|
|
137
|
-
createSaveErrorVariantsStore:
|
|
171
|
+
function Z(e) {
|
|
172
|
+
const t = B(e);
|
|
173
|
+
return function(s) {
|
|
174
|
+
const r = t(s);
|
|
175
|
+
return function(a) {
|
|
176
|
+
return r({
|
|
177
|
+
...a,
|
|
178
|
+
createSaveErrorVariantsStore: K
|
|
138
179
|
});
|
|
139
180
|
};
|
|
140
181
|
};
|
|
141
182
|
}
|
|
142
183
|
export {
|
|
143
|
-
|
|
184
|
+
Z as createTestVariants
|
|
144
185
|
};
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";const J=require("@flemist/time-controller"),x=require("@flemist/simple-utils"),j=require("@flemist/abort-controller-fast"),Y=require("@flemist/time-limits");class ge extends Error{}function oe(){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 He=1e3,F=[];function Je(e){return x.formatAny(e,{pretty:!0,maxDepth:5,maxItems:50})}function Xe(...e){const r=e.map(t=>typeof t=="string"?t:Je(t)).join(" ");F.push(r),F.length>He&&F.shift(),console.log(r)}function Ze(){return F.join(`
|
|
2
|
-
`)}globalThis.__getStressTestLogLast=Ze;const pe=(e,r)=>{Xe(r)},he=e=>x.formatAny(e,{pretty:!0,maxDepth:20,maxItems:100,maxStringLength:5e3,dontExpandClassInstances:!0,dontExpandFunctions:!0}),I={start:!0,progress:5e3,completed:!0,error:!0,modeChange:!0,debug:!1,func:pe,format:he},Ke={start:!1,progress:!1,completed:!1,error:!1,modeChange:!1,debug:!1,func:pe,format:he};function be(e){return e===!1?Ke:e===!0||!e?I:{start:e.start??I.start,progress:e.progress??I.progress,completed:e.completed??I.completed,error:e.error??I.error,modeChange:e.modeChange??I.modeChange,debug:e.debug??I.debug,func:e.func??I.func,format:e.format??I.format}}function Qe(e,r){const t=e.now();return{startTime:t,startMemory:r,debugMode:!1,tests:0,iterations:0,iterationsAsync:0,maxTestDuration:0,prevLogTime:t,prevLogMemory:r,pendingModeChange:null,prevGcTime:t,prevGcIterations:0,prevGcIterationsAsync:0}}class A extends j.AbortError{}class Ye{_timeController;_subject;_interval;_timer;constructor(r,t){this._interval=r,this._timeController=t??J.timeControllerDefault,this._subject=new x.Subject({startStopNotifier:()=>(this.update(),()=>{this._timeController.clearTimeout(this._timer)})})}update(){this._subject.emit(this._timeController.now()),this._timer=this._timeController.setTimeout(()=>this.update(),this._interval)}get interval(){return this._interval}set interval(r){this._interval=r,this._timer&&(this._timeController.clearTimeout(this._timer),this.update())}subscribe(r){return this._subject.subscribe(r)}}const et=50,tt=5;function rt(e,r){return e==null?null:typeof e=="number"?e:e(r)??null}function ue(e,r){return typeof e=="number"?{iterationsAsync:0,iterationsSync:e}:e!=null&&typeof e=="object"?e:r?{iterationsAsync:1,iterationsSync:0}:{iterationsAsync:0,iterationsSync:1}}function nt(e,r){const t=r.log,o=r.pauseDebuggerOnError??!0,i=r.onStart,s=r.onEnd,n=r.state;let l=null,u=0;function m(y,b,f){l==null&&(l={error:y,args:b,tests:f},t.error&&t.func("error",`[test-variants] error variant: ${t.format(b)}
|
|
3
|
-
tests: ${f}
|
|
4
|
-
${t.format(y)}`));const h=Date.now();if(o)debugger;if(Date.now()-h>et&&u<tt){t.func("debug",`[test-variants] debug iteration: ${u}`),u++;return}const w=l;throw l=null,r.onError&&r.onError(w),w.error}const d=new Ye(100);return function(b,f,h){i&&i({args:b,tests:f});const E=rt(r.timeout,b),w=Date.now();let g=h,S=null;E&&(S=new j.AbortControllerFast,g={abortSignal:x.combineAbortSignals(h.abortSignal,S.signal),timeController:h.timeController});function M(){S.abort(new ge(`[test-variants] test timeout ${E}ms exceeded`))}function C(){const v=Date.now()-w;v>n.maxTestDuration&&(n.maxTestDuration=v)}try{let v=e(b,g);if(x.isPromiseLike(v)){let P=null;return S&&(P=d.subscribe(()=>{Date.now()-w>E&&(M(),P())}),v=Promise.race([v,x.abortSignalToPromise(S.signal)])),v.then(O=>{P?.(),C();const D=ue(O,!0);return s&&s({args:b,tests:f,result:D}),D},O=>(P?.(),C(),s&&!(O instanceof A)&&s({args:b,tests:f,error:O}),m(O,b,f)))}C(),S&&Date.now()-w>E&&(M(),S.signal.throwIfAborted());const k=ue(v,!1);return s&&s({args:b,tests:f,result:k}),k}catch(v){return C(),v instanceof A?void 0:(s&&s({args:b,tests:f,error:v}),m(v,b,f))}}}function W(e,r,t){for(let o=0,i=e.length;o<i;o++)if(t?t(e[o],r):e[o]===r)return o;return-1}function ce(e,r,t,o){const i=Object.keys(e.templates),s={},n=[],l=[],u=[],m=i.length;for(let d=0;d<m;d++){const y=i[d];s[y]=void 0,n.push(-1),l.push(void 0),u.push(null)}return{args:s,argsNames:i,indexes:n,argValues:l,argLimits:u,attempts:0,templates:e,limitArgOnError:t,equals:r,includeErrorVariant:o??!1}}function $(e,r){const t=e.templates.templates[r],o=e.templates.extra[r];let i;if(typeof t=="function"?i=t(e.args):i=t,o==null)return i;let s=null;const n=o.length;for(let l=0;l<n;l++){const u=o[l];W(i,u,e.equals)<0&&(s==null?s=[...i,u]:s.push(u))}return s??i}function V(e,r,t){const o=e.argValues[r].length;if(o===0)return-1;const i=e.argLimits[r];if(i==null)return o-1;let s=e.limitArgOnError;if(typeof s=="function"){const n=e.argsNames[r];s=s({name:n,values:e.argValues[r],maxValueIndex:i})}return!t||s?Math.min(i,o-1):o-1}function L(e){const r=e.indexes.length;for(let t=0;t<r;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 N(e){const r=e.indexes.length;for(let t=0;t<r;t++)e.indexes[t]=-1,e.argValues[t]=void 0,e.args[e.argsNames[t]]=void 0}function ye(e){let r=!1,t=!0;const o=e.indexes.length;let i=o,s=!1,n=0;for(;n<o;n++){const l=e.argValues[n]==null;(l||s)&&(l&&(r=!0),e.argValues[n]=$(e,e.argsNames[n]));const u=V(e,n,n>i);if(u<0){t=!1,e.indexes[n]=-1;break}l&&(e.indexes[n]=0,e.args[e.argsNames[n]]=e.argValues[n][0]),(s||e.indexes[n]>u)&&(e.indexes[n]=u,e.args[e.argsNames[n]]=e.argValues[n][u],s=!0),i===o&&e.indexes[n]<u&&(i=n)}if(L(e))return N(e),!1;if(r&&t)return!0;for(n--;n>=0;n--){if(e.argValues[n]==null)continue;let l=n>i;const u=V(e,n,l),m=e.indexes[n]+1;if(m<=u){e.indexes[n]=m,e.args[e.argsNames[n]]=e.argValues[n][m],m<u&&(l=!0);for(let d=n+1;d<o;d++)e.args[e.argsNames[d]]=void 0;for(n++;n<o;n++){e.argValues[n]=$(e,e.argsNames[n]);const d=V(e,n,l);if(d<0)break;e.indexes[n]=0,e.args[e.argsNames[n]]=e.argValues[n][0],d>0&&(l=!0)}if(n>=o)return L(e)?(N(e),!1):!0}}return N(e),!1}function ee(e){L(e)&&N(e);let r=!1,t=!0;const o=e.indexes.length;let i=o,s=!1,n=0;for(;n<o;n++){const l=e.argValues[n]==null;(l||s)&&(l&&(r=!0),e.argValues[n]=$(e,e.argsNames[n]));const u=V(e,n,n>i);if(u<0){t=!1,e.indexes[n]=-1;break}l&&(e.indexes[n]=u,e.args[e.argsNames[n]]=e.argValues[n][u]),(s||e.indexes[n]>u)&&(e.indexes[n]=u,e.args[e.argsNames[n]]=e.argValues[n][u],s=!0),i===o&&e.indexes[n]<u&&(i=n)}if((r||s)&&t&&!L(e))return!0;for(n--;n>=0;n--){if(e.argValues[n]==null)continue;let l=n>i;const u=V(e,n,l);let m=e.indexes[n]-1;if(m>u&&(m=u),m>=0){e.indexes[n]=m,e.args[e.argsNames[n]]=e.argValues[n][m],m<u&&(l=!0);for(let d=n+1;d<o;d++)e.args[e.argsNames[d]]=void 0;for(n++;n<o;n++){e.argValues[n]=$(e,e.argsNames[n]);const d=V(e,n,l);if(d<0)break;e.indexes[n]=d,e.args[e.argsNames[n]]=e.argValues[n][d],d>0&&(l=!0)}if(n>=o)return!0}}return N(e),!1}function it(e,r){N(e);const t=e.argsNames,o=t.length;let i=!1;for(let s=0;s<o;s++){const n=t[s],l=r[n];if(l===void 0)return null;e.argValues[s]=$(e,n);const u=V(e,s,i);if(u<0)return null;const m=W(e.argValues[s],l,e.equals);if(m<0||m>u)return null;e.indexes[s]=m,e.args[e.argsNames[s]]=e.argValues[s][m],e.indexes[s]<u&&(i=!0)}return L(e)?null:e.indexes.slice()}function ot(e){const r=e.indexes.length;if(r===0)return!1;let t=!1;for(let o=0;o<r;o++){e.argValues[o]=$(e,e.argsNames[o]);const i=V(e,o,t);if(i<0)return Math.random()<.5?ye(e):ee(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 L(e)?ee(e):!0}function R(e){return e.mode==="forward"||e.mode==="backward"}function st(e,r,t,o){const i=r[t],s=e.templates[t];if(typeof s!="function"){if(W(s,i,o)>=0)return;s.push(i);return}const n=e.extra[t];if(n==null){e.extra[t]=[i];return}W(n,i,o)>=0||n.push(i)}function at(e,r,t){for(const o in r)if(Object.prototype.hasOwnProperty.call(r,o)){if(o==="seed")continue;st(e,r,o,t)}}function fe(e,r){for(const t in r)if(Object.prototype.hasOwnProperty.call(r,t)){if(t==="seed")continue;if(!e[t])return!1}return!0}const lt=[{mode:"forward"}];function ut(e){const{argsTemplates:r,equals:t,limitArgOnError:o,includeErrorVariant:i,getSeed:s,iterationModes:n,onModeChange:l,limitCompletionCount:u,limitTests:m,limitTime:d}=e,y=e.timeController??J.timeControllerDefault,b={templates:x.deepCloneJsonLike(r),extra:{}},f=n==null||n.length===0?lt:n,h=[];let E=null,w=null,g=0,S=0,M=!1,C=0;function v(){M||(M=!0,C=y.now(),k(),g=0,D(),O())}function k(){for(let a=0,c=f.length;a<c;a++)h.push(P())}function P(){return{navigationState:ce(b,t??null,o??null,i??null),cycleCount:0,completedCount:0,testsInLastTurn:0,tryNextVariantAttempts:0,startTime:null}}function O(){E=ce(b,t??null,!1,!1)}function D(){l?.({mode:f[g],modeIndex:g,tests:S})}function we(a){v(),fe(b.templates,a)&&at(b,a,t)}function ae(a,c){return v(),fe(b.templates,a)?(E.limitArgOnError=c?.limitArg??o??null,E.includeErrorVariant=c?.includeLimit??i??!1,it(E,a)):null}function Te(a){const c=a?.args;if(c==null)return;v();const p=ae(c);if(p!=null){w={args:c,error:a?.error,tests:a?.tests??S},E.argLimits=p;for(let T=0,B=h.length;T<B;T++){const K=h[T].navigationState;K.argLimits=p}}}function Me(){return v(),Ce()}function Ce(){for(;;){if(!Ie())return null;for(;;){const a=Ge();if(a!=null)return h[g].testsInLastTurn++,S++,a;if(_e()){if(!Ne())return null;De();break}}}}function Ie(){return!(Ve()||Ae()||U()&&(Oe()||!Le())||!Pe())}function Ve(){return m!=null&&S>=m}function Ae(){return d!=null&&y.now()-C>=d}function Oe(){if(!U())throw new Error("Unexpected behavior");return u!=null&&u<=0}function Le(){if(!U())throw new Error("Unexpected behavior");for(let a=0,c=f.length;a<c;a++)if(_(f[a])&&X(a))return!0;return!1}function Pe(){for(let a=0,c=f.length;a<c;a++)if(X(a))return!0;return!1}function _e(){g++;const a=g>=f.length;return a&&(g=0),D(),a}function Ne(){if(U()){const a=$e();if(u!=null&&a>=u)return!1}return!0}function U(){for(let a=0,c=f.length;a<c;a++)if(R(f[a]))return!0;return!1}function $e(){let a=!1,c=1/0;for(let p=0,T=h.length;p<T;p++){const B=h[p],K=f[p];R(K)&&(a=!0,X(p)&&B.completedCount<c&&(c=B.completedCount))}if(!a)throw new Error("Unexpected behavior");return c}function X(a){const c=f[a],p=h[a];return c.limitTests!=null&&c.limitTests<=0||_(c)&&(c.cycles!=null&&c.cycles<=0||c.attemptsPerVariant!=null&&c.attemptsPerVariant<=0)?!1:p.tryNextVariantAttempts<2}function De(){g=0;for(let a=0,c=h.length;a<c;a++){const p=h[a];p.testsInLastTurn=0,p.startTime=null}}function Ge(){let a=0;for(;a<2;){if(!qe())return null;const c=Fe();if(c!=null)return c;if(_(f[g])&&Re())return null;a++}return null}function qe(){const a=f[g];return!(ke()||Ue()||_(a)&&!Be(g))}function ke(){const a=f[g],c=h[g];return a.limitTests!=null&&c.testsInLastTurn>=a.limitTests}function Ue(){const a=f[g],c=h[g];return a.limitTime!=null&&c.startTime!=null&&y.now()-c.startTime>=a.limitTime}function _(a){return R(a)}function Be(a){const c=f[a],p=h[a];if(!_(c))throw new Error("Unexpected behavior");return p.cycleCount<(c.cycles??1)}function Re(){const a=f[g],c=h[g];if(!_(a))throw new Error("Unexpected behavior");return c.cycleCount++,c.cycleCount>=(a.cycles??1)?(c.cycleCount=0,c.completedCount++,!0):!1}function Fe(){const a=f[g],c=h[g],p=c.navigationState;if(G(a)){if(Z())return null;const T=je();if(T!=null)return c.startTime==null&&(c.startTime=y.now()),T}return ze()?(c.tryNextVariantAttempts=0,G(a)&&We(),c.startTime==null&&(c.startTime=y.now()),le(p.args)):(c.tryNextVariantAttempts++,null)}function je(){const a=f[g],p=h[g].navigationState;if(!G(a))throw new Error("Unexpected behavior");if(Z())throw new Error("Unexpected behavior");const T=a.attemptsPerVariant??1;return p.attempts>0&&p.attempts<T?L(p)?null:(p.attempts++,le(p.args)):null}function We(){const a=f[g],p=h[g].navigationState;if(!G(a))throw new Error("Unexpected behavior");if(Z())throw new Error("Unexpected behavior");p.attempts=1}function G(a){return R(a)}function Z(){const a=f[g];if(!G(a))throw new Error("Unexpected behavior");return(a.attemptsPerVariant??1)<=0}function ze(){const a=f[g],p=h[g].navigationState;switch(a.mode){case"forward":return ye(p);case"backward":return ee(p);case"random":return ot(p);default:throw new Error(`Unknown mode: ${a.mode}`)}}function le(a){const c={...a};return s!=null&&(c.seed=s({tests:S})),c}return{get limit(){return w},get modeIndex(){return g},get modeConfigs(){return f},get modeStates(){return h},get tests(){return S},calcIndexes:ae,extendTemplates:we,addLimit:Te,next:Me}}function se(e){if(e==null||e<=0)throw new Error(`Iterations = ${e}`);e--;const r=x.waitMicrotasks().then(()=>e);return e<=0?r:r.then(se)}function ct(e,r,t){const o=r.limit?{error:r.limit.error,args:r.limit.args,tests:r.limit.tests}:null;if(o&&!t)throw o.error;return{iterations:e.iterations,bestError:o}}const me=2**31;function ft(e){if(e==null)return{parallel:1,sequentialOnError:!1};if(typeof e=="boolean")return{parallel:e?me:1,sequentialOnError:!1};if(typeof e=="number")return{parallel:e>0?e:1,sequentialOnError:!1};const r=e.count;let t=1;return r===!0?t=me:typeof r=="number"&&r>0&&(t=r),{parallel:t,sequentialOnError:e.sequentialOnError??!1}}function mt(e){const r=e?.saveErrorVariants,t=r&&e.createSaveErrorVariantsStore?e.createSaveErrorVariantsStore(r):null,o=e?.findBestError,{parallel:i,sequentialOnError:s}=ft(e?.parallel);return{store:t,GC_Iterations:e?.GC_Iterations??1e6,GC_IterationsAsync:e?.GC_IterationsAsync??1e4,GC_Interval:e?.GC_Interval??1e3,logOptions:be(e?.log),abortSignalExternal:e?.abortSignal,findBestError:o,dontThrowIfError:o?.dontThrowIfError,timeController:e?.timeController??J.timeControllerDefault,parallel:i,sequentialOnError:s}}function z(e,r,t){const{options:o,variantsIterator:i}=e,s=i.limit?.args??r;if(!o.store)return;const n=o.store.save(s);if(t)return n}function dt(e,r,t,o){const{abortControllerParallel:i,state:s,options:n}=e,{logOptions:l}=n;if(e.options.findBestError)e.variantsIterator.addLimit({args:r,error:t,tests:o}),s.debugMode=!1,z(e,r,!1),n.sequentialOnError&&!i.signal.aborted?(l.debug&&l.func("debug","[test-variants] sequentialOnError: aborting parallel, switching to sequential"),i.abort(new A)):l.debug&&l.func("debug","[test-variants] parallel error in findBestError mode, continuing with new limits");else{if(i.signal.aborted)return;z(e,r,!1),i.abort(t)}}function de(e,r,t,o){const{state:i}=e;if(e.options.findBestError){e.variantsIterator.addLimit({args:r,error:t,tests:o});const n=z(e,r,!0);if(n)return n.then(()=>{i.debugMode=!1});i.debugMode=!1;return}const s=z(e,r,!0);if(s)return s.then(()=>{throw t});throw t}function gt(e,r){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&&r-e.state.prevGcTime>=i}async function pt(e,r){e.prevGcIterations=e.iterations,e.prevGcIterationsAsync=e.iterationsAsync,e.prevGcTime=r,await se(1)}function q(e){const r=e/1e3;if(r<60)return`${r.toFixed(1)}s`;const t=r/60;return t<60?`${t.toFixed(1)}m`:`${(t/60).toFixed(1)}h`}function te(e){const r=e/1073741824;if(r>=1)return r>=10?`${Math.round(r)}GB`:`${r.toFixed(1)}GB`;const t=e/(1024*1024);return t>=10?`${Math.round(t)}MB`:`${t.toFixed(1)}MB`}function ht(e,r){if(!e)return`mode[${r}]: null`;let t=`mode[${r}]: ${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=${q(e.limitTime)}`),e.limitTests!=null&&(t+=`, limitTests=${e.limitTests}`),t}function ve(e,r){const t=e-r,o=t>=0?"+":"";return`${te(e)} (${o}${te(t)})`}function bt(e,r){if(!e.start)return;let t="[test-variants] start";r!=null&&(t+=`, memory: ${te(r)}`),e.func("start",t)}function yt(e){const{options:r,state:t}=e,{logOptions:o,timeController:i}=r;if(!o.completed)return;const s=i.now()-t.startTime;let n=`[test-variants] end, tests: ${t.tests} (${q(s)}), maxTime: ${q(t.maxTestDuration)}, async: ${t.iterationsAsync}`;if(t.startMemory!=null){const l=oe();l!=null&&(n+=`, memory: ${ve(l,t.startMemory)}`)}o.func("completed",n)}function Se(e){const{options:r,state:t}=e,{logOptions:o}=r,i=t.pendingModeChange;!o.modeChange||i==null||(o.func("modeChange",`[test-variants] ${ht(i.mode,i.modeIndex)}`),t.pendingModeChange=null)}function vt(e){const{options:r,state:t}=e,{logOptions:o,timeController:i}=r,s=i.now();if(!o.progress||s-t.prevLogTime<o.progress)return!1;Se(e);const n=s-t.startTime;let l=`[test-variants] tests: ${t.tests} (${q(n)}), maxTime: ${q(t.maxTestDuration)}, async: ${t.iterationsAsync}`;if(t.prevLogMemory!=null){const u=oe();u!=null&&(l+=`, memory: ${ve(u,t.prevLogMemory)}`,t.prevLogMemory=u)}return o.func("progress",l),t.prevLogTime=s,!0}function re(e,r){e.debugMode=!1,r&&(e.iterationsAsync+=r.iterationsAsync,e.iterations+=r.iterationsSync+r.iterationsAsync)}function ne(e){e.state.debugMode=!0,e.abortControllerParallel.abort(new A)}function xe(e,r){const{testRun:t,testOptions:o,state:i}=e,s=i.tests;i.tests++;try{const n=t(r,s,o);if(x.isPromiseLike(n))return n.then(l=>{if(!l){ne(e);return}re(i,l)},l=>de(e,r,l,s));if(!n){ne(e);return}re(i,n)}catch(n){return n instanceof A?void 0:de(e,r,n,s)}}function St(e,r){const{pool:t,abortSignal:o,testRun:i,testOptionsParallel:s,state:n}=e;if(!t)return;const l=n.tests;n.tests++,(async()=>{try{if(o.aborted)return;let u=i(r,l,s);if(x.isPromiseLike(u)&&(u=await u),!u){ne(e);return}re(n,u)}catch(u){if(u instanceof A)return;dt(e,r,u,l)}finally{t.release(1)}})()}function Ee(e){const{options:r,state:t}=e,{logOptions:o,timeController:i,GC_Interval:s}=r;if(!o.progress&&!s)return;vt(e);const n=i.now();if(gt(e,n))return pt(t,n)}function H(e){return e.options.abortSignalExternal?.aborted??!1}function ie(e){return e.abortSignal.aborted}async function Q(e,r){const{pool:t,state:o,options:i}=e,{parallel:s,logOptions:n}=i;let l=null;for(;!H(e);){const u=t&&!ie(e);let m=!1;u&&(t.hold(1)||await Y.poolWait({pool:t,count:1,hold:!0}),m=!0);try{if(r!=null?(l=r,r=null):e.state.debugMode||(l=e.variantsIterator.next()),l==null)break;const d=Ee(e);if(x.isPromiseLike(d)&&await d,H(e))continue;if(u)St(e,l),m=!1;else{n.debug&&t&&ie(e)&&n.func("debug",`[test-variants] parallel aborted, running sequential: tests=${o.tests}`);const y=xe(e,l);x.isPromiseLike(y)&&await y}}finally{m&&t.release(1)}}t&&(await Y.poolWait({pool:t,count:s,hold:!0}),t.release(s))}function xt(e){const{pool:r,state:t,options:o}=e,{logOptions:i}=o;if(r)return Q(e);let s=null;for(;!H(e)&&(e.state.debugMode||(s=e.variantsIterator.next()),s!=null);){const n=Ee(e);if(x.isPromiseLike(n))return n.then(()=>Q(e,s));if(H(e))continue;i.debug&&ie(e)&&i.func("debug",`[test-variants] parallel aborted, running sequential: tests=${t.tests}`);const l=xe(e,s);if(x.isPromiseLike(l))return l.then(()=>Q(e))}}async function Et(e,r,t,o){const i=mt(o),{store:s,logOptions:n,abortSignalExternal:l,findBestError:u,dontThrowIfError:m,timeController:d,parallel:y}=i,b=new j.AbortControllerFast,f=new j.AbortControllerFast,h=x.combineAbortSignals(l,b.signal),E=x.combineAbortSignals(h,f.signal),w={abortSignal:h,timeController:d},g={abortSignal:E,timeController:d};s&&await s.replay({testRun:e,variantsIterator:r,testOptions:w,findBestErrorEnabled:!!u,state:t});const S=y<=1?null:new Y.Pool(y);bt(n,t.startMemory);const M={options:i,testRun:e,variantsIterator:r,testOptions:w,testOptionsParallel:g,abortControllerGlobal:b,abortControllerParallel:f,abortSignal:E,pool:S,state:t};Se(M);try{await xt(M),E.throwIfAborted()}catch(C){throw b.abort(new A),C}return h.throwIfAborted(),b.abort(new A),yt(M),await se(1),ct(t,r,m)}function wt(e){return function(t){return async function(i){const s=be(i?.log),n=i?.timeController??J.timeControllerDefault,l=oe(),u=Qe(n,l),m=nt(e,{onStart:i?.onStart,onEnd:i?.onEnd,onError:i?.onError,log:s,pauseDebuggerOnError:i?.pauseDebuggerOnError,timeout:i?.timeout,state:u}),d=i?.onModeChange;function y(f){u.pendingModeChange=f,d?.(f)}const b=ut({argsTemplates:t,getSeed:i?.getSeed,iterationModes:i?.iterationModes,equals:i?.findBestError?.equals,limitArgOnError:i?.findBestError?.limitArgOnError,includeErrorVariant:i?.findBestError?.includeErrorVariant,timeController:n,onModeChange:y,limitCompletionCount:i?.cycles??1,limitTests:i?.limitTests,limitTime:i?.limitTime});return Et(m,b,u,i)}}}exports.TimeoutError=ge;exports.createTestVariants=wt;
|