@flemist/test-variants 5.0.8 → 5.0.10

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