@flemist/test-variants 5.0.5 → 5.0.7
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.d.ts +1 -1
- package/build/common/index.mjs +1 -1
- package/build/common/test-variants/iterator/types.d.ts +6 -3
- package/build/common/test-variants/run/RunContext.d.ts +3 -3
- package/build/common/test-variants/run/types.d.ts +5 -5
- package/build/common/test-variants/types.d.ts +1 -1
- package/build/{createTestVariants-BXmWQaT8.mjs → createTestVariants-BzKl5Eff.mjs} +4 -2
- package/build/createTestVariants-DdR2pUe_.js +4 -0
- package/build/node/index.cjs +1 -1
- package/build/node/index.d.ts +1 -1
- package/build/node/index.mjs +1 -1
- package/package.json +1 -1
- package/build/createTestVariants-BYmqvvhv.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.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { type ErrorEvent, type GenerateErrorVariantFilePathOptions, type GetSeedParams, type LimitArgOnError, type LimitArgOnErrorOptions, type ModeChangeEvent, type ModeConfig, type OnErrorCallback, type OnModeChangeCallback, type ParallelOptions, type SaveErrorVariantsOptions, type TestVariantsBestError, type FindBestErrorOptions, type TestVariantsLogOptions, type TestVariantsRunOptions, type TestVariantsResult, type
|
|
1
|
+
export { type ErrorEvent, type GenerateErrorVariantFilePathOptions, type GetSeedParams, type LimitArgOnError, type LimitArgOnErrorOptions, type ModeChangeEvent, type ModeConfig, type OnErrorCallback, type OnModeChangeCallback, type ParallelOptions, type SaveErrorVariantsOptions, type TestVariantsBestError, type FindBestErrorOptions, type TestVariantsLogOptions, type TestVariantsRunOptions, type TestVariantsResult, type TestVariantsState, type TestVariantsTestResult, } from './test-variants/types';
|
|
2
2
|
export { createTestVariants } from './test-variants/createTestVariants';
|
package/build/common/index.mjs
CHANGED
|
@@ -85,7 +85,7 @@ export type TestVariantsTemplateFunc<Args extends Obj, Value> = (args: Args) =>
|
|
|
85
85
|
export type TestVariantsTemplate<Args extends Obj, Value> = TestVariantsTemplateValues<Value> | TestVariantsTemplateFunc<Args, Value>;
|
|
86
86
|
export type ArgName<Args extends Obj> = Extract<keyof Args, string>;
|
|
87
87
|
export type TestVariantsTemplates<Args extends Obj> = {
|
|
88
|
-
[key in
|
|
88
|
+
[key in keyof Args]: TestVariantsTemplate<Args, Args[key]>;
|
|
89
89
|
};
|
|
90
90
|
export type TestVariantsTemplatesExtra<Args extends Obj> = {
|
|
91
91
|
[key in ArgName<Args>]?: Mutable<TestVariantsTemplateValues<Args[key]>>;
|
|
@@ -109,5 +109,8 @@ export type VariantNavigationState<Args extends Obj> = {
|
|
|
109
109
|
};
|
|
110
110
|
/** Extended templates type that allows additional args beyond the base Args type */
|
|
111
111
|
export type TestVariantsTemplatesExt<Args extends Obj, ArgsExtra extends Obj> = TestVariantsTemplates<{
|
|
112
|
-
[key in
|
|
113
|
-
}
|
|
112
|
+
[key in keyof Args | keyof ArgsExtra]: key extends keyof Args ? Args[key] : key extends keyof ArgsExtra ? ArgsExtra[key] : never;
|
|
113
|
+
}> & {
|
|
114
|
+
/** Use getSeed option instead */
|
|
115
|
+
seed?: never;
|
|
116
|
+
};
|
|
@@ -2,7 +2,7 @@ import { IAbortSignalFast, IAbortControllerFast } from '@flemist/abort-controlle
|
|
|
2
2
|
import { Obj } from '@flemist/simple-utils';
|
|
3
3
|
import { IPool } from '@flemist/time-limits';
|
|
4
4
|
import { VariantsIterator } from '../iterator/types';
|
|
5
|
-
import {
|
|
5
|
+
import { TestVariantsState } from '../types';
|
|
6
6
|
import { RunState } from './createRunState';
|
|
7
7
|
import { RunOptionsResolved } from './resolveRunOptions';
|
|
8
8
|
import { TestVariantsTestRun } from './types';
|
|
@@ -11,8 +11,8 @@ export type RunContext<Args extends Obj> = {
|
|
|
11
11
|
options: RunOptionsResolved<Args>;
|
|
12
12
|
testRun: TestVariantsTestRun<Args>;
|
|
13
13
|
variantsIterator: VariantsIterator<Args>;
|
|
14
|
-
testOptions:
|
|
15
|
-
testOptionsParallel:
|
|
14
|
+
testOptions: TestVariantsState;
|
|
15
|
+
testOptionsParallel: TestVariantsState;
|
|
16
16
|
abortControllerGlobal: IAbortControllerFast;
|
|
17
17
|
abortControllerParallel: IAbortControllerFast;
|
|
18
18
|
abortSignal: IAbortSignalFast;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { PromiseOrValue } from '@flemist/async-utils';
|
|
2
2
|
import { Obj, RequiredNonNullable } from '@flemist/simple-utils';
|
|
3
3
|
import { TestVariantsTemplatesExt, VariantsIterator } from '../iterator/types';
|
|
4
|
-
import { ArgsWithSeed, OnErrorCallback, SaveErrorVariantsOptions,
|
|
4
|
+
import { ArgsWithSeed, OnErrorCallback, SaveErrorVariantsOptions, TestVariantsState, TestVariantsLogOptions, TestVariantsResult, TestVariantsRunOptions } from '../types';
|
|
5
5
|
/** Result of test run (internal format with separate sync/async counts) */
|
|
6
6
|
export type TestFuncResult = void | {
|
|
7
7
|
iterationsAsync: number;
|
|
8
8
|
iterationsSync: number;
|
|
9
9
|
};
|
|
10
10
|
/** Test run function (internal - wraps user's test with error handling) */
|
|
11
|
-
export type TestVariantsTestRun<Args extends Obj> = (args: ArgsWithSeed<Args>, tests: number, options:
|
|
11
|
+
export type TestVariantsTestRun<Args extends Obj> = (args: ArgsWithSeed<Args>, tests: number, options: TestVariantsState) => PromiseOrValue<TestFuncResult>;
|
|
12
12
|
/** Result of user's test function (number treated as iterationsSync) */
|
|
13
13
|
export type TestVariantsTestResult = number | void | TestFuncResult;
|
|
14
14
|
/** User's test function */
|
|
15
|
-
export type TestVariantsTest<Args extends Obj> = (args: ArgsWithSeed<Args>, options:
|
|
15
|
+
export type TestVariantsTest<Args extends Obj> = (args: ArgsWithSeed<Args>, options: TestVariantsState) => PromiseOrValue<TestVariantsTestResult>;
|
|
16
16
|
/**
|
|
17
17
|
* Store for saving and loading error-causing parameter combinations.
|
|
18
18
|
* Node.js implementation uses file system. Browser returns null (not supported).
|
|
@@ -38,7 +38,7 @@ export type SaveErrorVariantsStoreReplayOptions<Args extends Obj> = {
|
|
|
38
38
|
/** Iterator to add limits to */
|
|
39
39
|
variantsIterator: VariantsIterator<Args>;
|
|
40
40
|
/** Options passed to test function */
|
|
41
|
-
testOptions:
|
|
41
|
+
testOptions: TestVariantsState;
|
|
42
42
|
/** Whether findBestError is enabled */
|
|
43
43
|
findBestErrorEnabled?: null | boolean;
|
|
44
44
|
};
|
|
@@ -56,4 +56,4 @@ export type TestVariantsCreateTestRunOptions<Args extends Obj> = {
|
|
|
56
56
|
pauseDebuggerOnError?: null | boolean;
|
|
57
57
|
};
|
|
58
58
|
export type TestVariantsCall<Args extends Obj> = <SavedArgs = Args>(options?: null | TestVariantsRunOptionsInternal<Args, SavedArgs>) => PromiseOrValue<TestVariantsResult<Args>>;
|
|
59
|
-
export type TestVariantsSetArgs<Args extends Obj> = <ArgsExtra extends Obj>(args: TestVariantsTemplatesExt<Omit<Args, 'seed'>,
|
|
59
|
+
export type TestVariantsSetArgs<Args extends Obj> = <ArgsExtra extends Obj>(args: TestVariantsTemplatesExt<Omit<Args, 'seed'>, ArgsExtra>) => TestVariantsCall<Args>;
|
|
@@ -99,7 +99,7 @@ export type SaveErrorVariantsOptions<Args extends Obj, SavedArgs = Args> = {
|
|
|
99
99
|
extendTemplates?: null | boolean;
|
|
100
100
|
};
|
|
101
101
|
/** Options passed to test function */
|
|
102
|
-
export type
|
|
102
|
+
export type TestVariantsState = {
|
|
103
103
|
abortSignal: IAbortSignalFast;
|
|
104
104
|
timeController: ITimeController;
|
|
105
105
|
};
|
|
@@ -6,7 +6,7 @@ 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") {
|
|
@@ -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}`
|
|
@@ -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.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Obj } from '@flemist/simple-utils';
|
|
2
2
|
import { TestVariantsSetArgs } from '../common/test-variants/types';
|
|
3
3
|
import { TestVariantsTest } from '../common/test-variants/run/types';
|
|
4
|
-
export { type ErrorEvent, type GenerateErrorVariantFilePathOptions, type GetSeedParams, type LimitArgOnError, type LimitArgOnErrorOptions, type ModeChangeEvent, type ModeConfig, type OnErrorCallback, type OnModeChangeCallback, type SaveErrorVariantsOptions, type TestVariantsBestError, type FindBestErrorOptions, type TestVariantsLogOptions, type TestVariantsRunOptions, type TestVariantsResult, type
|
|
4
|
+
export { type ErrorEvent, type GenerateErrorVariantFilePathOptions, type GetSeedParams, type LimitArgOnError, type LimitArgOnErrorOptions, type ModeChangeEvent, type ModeConfig, type OnErrorCallback, type OnModeChangeCallback, type SaveErrorVariantsOptions, type TestVariantsBestError, type FindBestErrorOptions, type TestVariantsLogOptions, type TestVariantsRunOptions, type TestVariantsResult, type TestVariantsState, type TestVariantsTestResult, } from '../common';
|
|
5
5
|
export type { TestVariantsSetArgs } from '../common/test-variants/types';
|
|
6
6
|
export type { TestVariantsCall } from '../common/test-variants/types';
|
|
7
7
|
export type { TestVariantsTemplatesExt } from '../common/test-variants/types';
|
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 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&&Function("debugger")(),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;
|