@flemist/test-variants 5.0.8 → 5.0.9

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-BdWikiOA.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-BiFu-zG6.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-BdWikiOA.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-BiFu-zG6.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"),S=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,customToString:n=>{if(typeof n=="function")return`function ${n.name||"anonymous"}()`}}),x={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?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,format:e.format??x.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 T 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 S.isPromiseLike(h)?h.then(y=>ae(y,!0),y=>r(y,u,f)):ae(h,!1)}catch(h){return h instanceof T?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 V(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(V(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 V(e)?(C(e),!1):!0}}return C(e),!1}function J(e){V(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&&!V(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 V(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 V(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 E=null,O=null,g=0,w=0,I=!1,N=0;function $(){I||(I=!0,N=h.now(),Se(),g=0,oe(),xe())}function Se(){for(let s=0,c=p.length;s<c;s++)b.push(Ee())}function Ee(){return{navigationState:le(y,t??null,i??null,o??null),cycleCount:0,completedCount:0,testsInLastTurn:0,tryNextVariantAttempts:0,startTime:null}}function xe(){E=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)?(E.limitArgOnError=c?.limitArg??i??null,E.includeErrorVariant=c?.includeLimit??o??!1,rt(E,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},E.argLimits=d;for(let v=0,q=b.length;v<q;v++){const j=b[v].navigationState;j.argLimits=d}}}function Te(){return $(),Ve()}function Ve(){for(;;){if(!Ie())return null;for(;;){const s=De();if(s!=null)return b[g].testsInLastTurn++,w++,s;if(Ne()){if(!$e())return null;qe();break}}}}function Ie(){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?V(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:Te}}function re(e){if(e==null||e<=0)throw new Error(`Iterations = ${e}`);e--;const n=S.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 T)):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 T)}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(S.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 T?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(S.isPromiseLike(u)&&(u=await u),!u){K(e);return}Z(r,u)}catch(u){if(u instanceof T)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(S.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);S.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(S.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(S.isPromiseLike(l))return l.then(()=>W(e))}}async function St(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=S.combineAbortSignals(l,y.signal),E=S.combineAbortSignals(b,p.signal),O={abortSignal:b,timeController:m},g={abortSignal:E,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 I={options:o,testRun:e,variantsIterator:n,testOptions:O,testOptionsParallel:g,abortControllerGlobal:y,abortControllerParallel:p,abortSignal:E,pool:w,state:t};be(I);try{await vt(I),E.throwIfAborted()}catch(N){throw y.abort(new T),N}return b.throwIfAborted(),y.abort(new T),ht(I),await re(1),lt(t,n,f)}function Et(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 St(r,y,f,o)}}}exports.createTestVariants=Et;