@http-forge/core 0.6.2-2.beta.4 → 0.6.2-2.beta.5
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/dist/index.js
CHANGED
|
@@ -494,10 +494,10 @@ ${d.join(`
|
|
|
494
494
|
<tr>
|
|
495
495
|
<td class="kv-key">${$t(r.name??"(unnamed)")}</td>
|
|
496
496
|
<td class="kv-val">${$t(r.value??"")}</td>
|
|
497
|
-
</tr>`).join("")}</table>`}function xN(t,e){if(t==null||t==="")return'<span class="dim">\u2014 empty \u2014</span>';let r=EN(t);return`<pre class="code">${$t(r)}</pre>`}var Dc,Fc,jc,$x=ae(()=>{"use strict";Dc=ve(require("fs/promises")),Fc=ve(require("path"));Np();jc=class{constructor(e){this.basePath=e}basePath;async generate(e,r){let n=Fc.join(this.basePath,e,r),i=JSON.parse(await Dc.readFile(Fc.join(n,"manifest.json"),"utf-8")),s=await this.loadAllSummaries(n,i.totalIndexPages),o=await this.loadAllDetails(n,s),l=this.buildHtml(i,s,o),c=Fc.join(n,"report.html");return await Dc.writeFile(c,l,"utf-8"),c}async loadAllSummaries(e,r){let n=[];for(let i=1;i<=r;i++){let s=Fc.join(e,"index",`page-${String(i).padStart(4,"0")}.json`);try{let o=JSON.parse(await Dc.readFile(s,"utf-8"));n.push(...o.summaries)}catch{}}return n}async loadAllDetails(e,r){let n=new Map;for(let i of r){let s=Sl(i.i,i.it,i.r),o=`${i.i}-${i.it}`;try{let l=JSON.parse(await Dc.readFile(Fc.join(e,"results",s),"utf-8"));n.set(o,l)}catch{}}return n}groupByIterCollectionFolder(e){let r=[],n=
|
|
497
|
+
</tr>`).join("")}</table>`}function xN(t,e){if(t==null||t==="")return'<span class="dim">\u2014 empty \u2014</span>';let r=EN(t);return`<pre class="code">${$t(r)}</pre>`}var Dc,Fc,jc,$x=ae(()=>{"use strict";Dc=ve(require("fs/promises")),Fc=ve(require("path"));Np();jc=class{constructor(e){this.basePath=e}basePath;async generate(e,r){let n=Fc.join(this.basePath,e,r),i=JSON.parse(await Dc.readFile(Fc.join(n,"manifest.json"),"utf-8")),s=await this.loadAllSummaries(n,i.totalIndexPages),o=await this.loadAllDetails(n,s),l=this.buildHtml(i,s,o),c=Fc.join(n,"report.html");return await Dc.writeFile(c,l,"utf-8"),c}async loadAllSummaries(e,r){let n=[];for(let i=1;i<=r;i++){let s=Fc.join(e,"index",`page-${String(i).padStart(4,"0")}.json`);try{let o=JSON.parse(await Dc.readFile(s,"utf-8"));n.push(...o.summaries)}catch{}}return n}async loadAllDetails(e,r){let n=new Map;for(let i of r){let s=Sl(i.i,i.it,i.r),o=`${i.i}-${i.it}`;try{let l=JSON.parse(await Dc.readFile(Fc.join(e,"results",s),"utf-8"));n.set(o,l)}catch{}}return n}groupByIterCollectionFolder(e){let r=[],n=null,i=null,s=null;for(let o of e){let l=o.cn||"",c=o.gp||o.fp||"",d=o.gt;(!n||n.it!==o.it)&&(n={it:o.it,groups:[]},r.push(n),i=null,s=null);let p=`${d||""}\0${c}`;(!i||p!==s)&&(i={cn:l,fp:c,gt:d,items:[]},n.groups.push(i),s=p),i.items.push(o)}return r}groupLabel(e,r,n,i){let s=String(i).padStart(2,"0"),o="";return n==="block"?o=$t(r||"(unnamed block)"):r&&(o=r.split("/").map(c=>$t(c.replace(/^\s*\d+\s*-\s*/,""))).join("/")),o||(o="(root)"),`${s} - ${o}`}renderGroupedDetails(e,r,n){let i=r.config.iterations>1;return this.groupByIterCollectionFolder(e).map(s=>{let o=s.groups.map((d,p)=>{let m=d.items.filter(v=>v.p).length,y=d.items.length,b=m<y,q=d.items.map(n).join(""),C=d.gt==="block"?"\u{1F9E9}":"\u{1F4C1}";return`
|
|
498
498
|
<details class="group-block${b?" group-fail":""}" open>
|
|
499
499
|
<summary class="group-head">
|
|
500
|
-
<span class="group-title"
|
|
500
|
+
<span class="group-title">${C} ${this.groupLabel(d.cn,d.fp,d.gt,p+1)}</span>
|
|
501
501
|
<span class="group-count ${b?"fail":"dim"}">(${m}/${y})</span>
|
|
502
502
|
</summary>
|
|
503
503
|
<div class="group-body">${q}</div>
|
|
@@ -508,7 +508,7 @@ ${d.join(`
|
|
|
508
508
|
<span class="dim iter-count">(${l}/${c} passed)</span>
|
|
509
509
|
</summary>
|
|
510
510
|
<div class="iter-body">${o}</div>
|
|
511
|
-
</details>`}).join("")}renderGroupedTimeline(e,r,n){let i=r.config.iterations>1,s=8;return this.groupByIterCollectionFolder(e).map(o=>{let l="";return i&&(l+=`<tr class="group-row iter-row"><td colspan="${s}">Iteration ${o.it}</td></tr>`),o.groups.forEach((c,d)=>{l+=`<tr class="group-row folder-row"><td colspan="${s}"
|
|
511
|
+
</details>`}).join("")}renderGroupedTimeline(e,r,n){let i=r.config.iterations>1,s=8;return this.groupByIterCollectionFolder(e).map(o=>{let l="";return i&&(l+=`<tr class="group-row iter-row"><td colspan="${s}">Iteration ${o.it}</td></tr>`),o.groups.forEach((c,d)=>{let p=c.gt==="block"?"\u{1F9E9}":"\u{1F4C1}";l+=`<tr class="group-row folder-row"><td colspan="${s}">${p} ${this.groupLabel(c.cn,c.fp,c.gt,d+1)}</td></tr>`,l+=c.items.map(n).join("")}),l}).join("")}buildHtml(e,r,n){let i=_l(e.stats.totalDuration),s=e.stats.failed===0,o=Object.entries(e.requestStats).map(([,b])=>{let q=M5(b.passed,b.count);return`
|
|
512
512
|
<tr${b.failed>0?' class="row-fail"':""}>
|
|
513
513
|
<td>${$t(b.name)}</td>
|
|
514
514
|
<td>${b.count}</td>
|
|
@@ -1012,7 +1012,7 @@ ${d.join(`
|
|
|
1012
1012
|
});
|
|
1013
1013
|
</script>
|
|
1014
1014
|
</body>
|
|
1015
|
-
</html>`}}});function Rl(t,e){if(t.length===0)return 0;let r=Math.ceil(e/100*t.length)-1;return t[Math.max(0,Math.min(r,t.length-1))]}var ir,dn,Cl,Nx=ae(()=>{"use strict";ir=ve(require("fs/promises")),dn=ve(require("path"));Un();_d();$x();Np();Cl=class{constructor(e){this.configService=e;let r=e.getRunnerConfig();this.basePath=e.getResultsPath(),this.indexPageSize=r.indexPageSize,this.recentErrorsLimit=r.recentErrorsLimit}configService;basePath;currentRunPath=null;currentRunId=null;currentSuiteId=null;currentManifest=null;currentIndexPage=[];currentPageNumber=1;indexPageSize;recentErrors=[];recentErrorsLimit;resultIndex=0;requestDurations={};getBasePath(){return this.basePath}async initializeRun(e,r,n,i){let s=this.generateRunId();return this.currentRunId=s,this.currentSuiteId=e,this.currentRunPath=dn.join(this.basePath,e,s),await ir.mkdir(dn.join(this.currentRunPath,"results"),{recursive:!0}),await ir.mkdir(dn.join(this.currentRunPath,"index"),{recursive:!0}),this.currentManifest={version:"1.0",runId:s,suiteId:e,suiteName:r,environment:n,startTime:new Date().toISOString(),status:"running",config:i,stats:{totalRequests:0,passed:0,failed:0,skipped:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0},requestStats:{},totalIndexPages:0,indexPageSize:this.indexPageSize},this.currentIndexPage=[],this.currentPageNumber=1,this.recentErrors=[],this.resultIndex=0,this.requestDurations={},await this.saveManifest(),s}async saveResult(e,r){if(!this.currentRunPath||!this.currentManifest)throw new Error("No active run. Call initializeRun first.");this.resultIndex++;let n=Date.now(),i=String(e).padStart(4,"0"),s=String(this.resultIndex).padStart(6,"0"),o=Ht(r.requestId),l=`result-${s}-iter-${i}-${o}.json`,c=dn.join(this.currentRunPath,"results",l),d={index:this.resultIndex,iteration:e,requestId:r.requestId,name:r.name,method:r.executedRequest.method,url:r.executedRequest.url,folderPath:r.folderPath||"",collectionName:r.collectionName||"",status:r.response.status,statusText:r.response.statusText||"",duration:r.duration,passed:r.passed,timestamp:n,request:{method:r.executedRequest.method,url:r.executedRequest.url,headers:r.executedRequest.headers,query:r.executedRequest.query,params:r.executedRequest.params,body:r.executedRequest.body},response:{headers:r.response.headers,body:r.response.body,time:r.response.time,size:r.response.size,cookies:r.response.cookies},assertions:r.assertions.map(b=>({name:b.name,passed:b.passed,message:b.message||null})),error:r.error||null,consoleOutput:r.consoleOutput,modifiedVariables:r.modifiedVariables,modifiedEnvironmentVariables:r.modifiedEnvironmentVariables,modifiedCollectionVariables:r.modifiedCollectionVariables,nextRequest:r.nextRequest??null,visualizerData:r.visualizerData};await ir.writeFile(c,JSON.stringify(fg(d),null,2),"utf-8");let p=r.assertions.filter(b=>b.passed).length,m=r.assertions.filter(b=>!b.passed).length,y={i:this.resultIndex,it:e,n:r.name,m:dv[r.executedRequest.method.toUpperCase()]??0,s:r.response.status,d:r.duration,p:r.passed,ap:p,af:m,r:r.requestId,e:r.passed?null:r.error||null,fp:r.folderPath||"",cn:r.collectionName||""};return this.currentIndexPage.push(y),this.currentIndexPage.length>=this.indexPageSize&&await this.writeCurrentIndexPage(),this.updateStats(r),this.requestDurations[r.requestId]||(this.requestDurations[r.requestId]=[]),this.requestDurations[r.requestId].push(r.duration),r.passed||(this.recentErrors.unshift({timestamp:n,iteration:e,requestName:r.name,status:r.response.status,error:r.error||`Status ${r.response.status}`,resultFile:l}),this.recentErrors.length>this.recentErrorsLimit&&this.recentErrors.pop()),y}async finalizeRun(e="completed",r=!0){if(!this.currentManifest)return null;this.currentIndexPage.length>0&&await this.writeCurrentIndexPage(),this.currentManifest.endTime=new Date().toISOString(),this.currentManifest.status=e,this.currentManifest.totalIndexPages=this.currentPageNumber-1,this.currentManifest.stats.totalRequests>0&&(this.currentManifest.stats.avgDuration=Math.round(this.currentManifest.stats.totalDuration/this.currentManifest.stats.totalRequests)),this.currentManifest.stats.minDuration===Number.MAX_SAFE_INTEGER&&(this.currentManifest.stats.minDuration=0);for(let c in this.currentManifest.requestStats){let d=this.currentManifest.requestStats[c],p=this.requestDurations[c]||[];d.count>0&&(d.avgDuration=Math.round(d.totalDuration/d.count)),d.minDuration===Number.MAX_SAFE_INTEGER&&(d.minDuration=0),p.length>0&&(p.sort((m,y)=>m-y),d.p50=Rl(p,50),d.p90=Rl(p,90),d.p95=Rl(p,95),d.p99=Rl(p,99))}let n=Object.values(this.requestDurations).flat();n.length>0&&(n.sort((c,d)=>c-d),this.currentManifest.stats.p50=Rl(n,50),this.currentManifest.stats.p95=Rl(n,95),this.currentManifest.stats.p99=Rl(n,99)),this.requestDurations={},await this.saveManifest();let i=null,s=this.currentRunPath,o=this.currentSuiteId,l=this.currentRunId;if(this.currentRunPath=null,this.currentRunId=null,this.currentSuiteId=null,this.currentManifest=null,this.currentIndexPage=[],this.recentErrors=[],this.resultIndex=0,r&&o&&l&&s)try{i=await new jc(this.basePath).generate(o,l)}catch(c){console.warn("[ResultStorage] HTML report generation failed:",c)}return i}getCurrentStats(){return this.currentManifest?{stats:{...this.currentManifest.stats},requestStats:{...this.currentManifest.requestStats},recentErrors:[...this.recentErrors]}:null}getCurrentRunId(){return this.currentRunId}getCurrentSuiteId(){return this.currentSuiteId}async getResultDetails(e,r,n){let i=dn.join(this.basePath,e,r,"results",n),s=await ir.readFile(i,"utf-8");return JSON.parse(s)}async getIndexPage(e,r,n){let i=dn.join(this.basePath,e,r,"index",`page-${String(n).padStart(4,"0")}.json`),s=await ir.readFile(i,"utf-8");return JSON.parse(s)}async getManifest(e,r){let n=dn.join(this.basePath,e,r,"manifest.json"),i=await ir.readFile(n,"utf-8");return JSON.parse(i)}async listRuns(e){let r=dn.join(this.basePath,e);try{let n=await ir.readdir(r),i=[];for(let s of n.sort().reverse())try{let o=await this.getManifest(e,s);i.push(o)}catch{}return i}catch{return[]}}async listSuites(){try{return(await ir.readdir(this.basePath,{withFileTypes:!0})).filter(r=>r.isDirectory()).map(r=>r.name)}catch{return[]}}async deleteRun(e,r){let n=dn.join(this.basePath,e,r);await ir.rm(n,{recursive:!0,force:!0})}async cleanupOldRuns(){let r=this.configService.getRunnerConfig().resultsRetentionDays;if(r===0)return{deleted:0,freed:0};let n=new Date;n.setDate(n.getDate()-r);let i=0,s=0,o=await this.listSuites();for(let l of o){let c=await this.listRuns(l);for(let d of c)if(new Date(d.startTime)<n){let p=dn.join(this.basePath,l,d.runId),m=await this.getDirectorySize(p);await ir.rm(p,{recursive:!0,force:!0}),i++,s+=m}}return{deleted:i,freed:s}}generateRunId(){let e=new Date,r=e.toISOString().slice(0,10).replace(/-/g,""),n=e.toTimeString().slice(0,8).replace(/:/g,""),i=String(e.getMilliseconds()).padStart(3,"0");return`run-${r}-${n}-${i}`}async saveManifest(){if(!this.currentRunPath||!this.currentManifest)return;let e=dn.join(this.currentRunPath,"manifest.json");await ir.writeFile(e,JSON.stringify(this.currentManifest,null,2),"utf-8")}async writeCurrentIndexPage(){if(!this.currentRunPath||this.currentIndexPage.length===0)return;let e=`page-${String(this.currentPageNumber).padStart(4,"0")}.json`,r=dn.join(this.currentRunPath,"index",e),n={page:this.currentPageNumber,startIndex:(this.currentPageNumber-1)*this.indexPageSize+1,count:this.currentIndexPage.length,summaries:this.currentIndexPage};await ir.writeFile(r,JSON.stringify(n),"utf-8"),this.currentPageNumber++,this.currentIndexPage=[]}updateStats(e){if(!this.currentManifest)return;let r=this.currentManifest.stats,n=this.currentManifest.requestStats;r.totalRequests++,r.totalDuration+=e.duration,r.minDuration=Math.min(r.minDuration,e.duration),r.maxDuration=Math.max(r.maxDuration,e.duration),e.passed?r.passed++:r.failed++,n[e.requestId]||(n[e.requestId]={name:e.name,count:0,passed:0,failed:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0});let i=n[e.requestId];i.count++,i.totalDuration+=e.duration,i.minDuration=Math.min(i.minDuration,e.duration),i.maxDuration=Math.max(i.maxDuration,e.duration),e.passed?i.passed++:i.failed++}async getDirectorySize(e){let r=0;try{let n=await ir.readdir(e,{withFileTypes:!0});for(let i of n){let s=dn.join(e,i.name);if(i.isDirectory())r+=await this.getDirectorySize(s);else{let o=await ir.stat(s);r+=o.size}}}catch{}return r}}});function Lc(t){return typeof t=="string"?t:""+JSON.stringify(t)}function xl(t){if(typeof t=="string"&&t.charCodeAt(0)===30)try{return JSON.parse(t.slice(1))}catch{return t}return t}function hv(t){if(!t)return{};let e={};for(let[r,n]of Object.entries(t))e[r]=xl(n);return e}var Mx=ae(()=>{"use strict"});var as,Mp,Fx,mv,gv,yv,qN=ae(()=>{"use strict";as=ve(require("fs")),Mp=ve(require("path")),Fx=class{watchers=[];constructor(e,r){let n=this.globToPath(e,r);try{let i=as.watch(n,{recursive:!0},(s,o)=>{if(o){let l=Mp.join(n,o);this.notifyChange(l)}});this.watchers.push(i)}catch{}}globToPath(e,r){return r.includes("**")?e:Mp.join(e,r.replace(/\*/g,""))}notifyChange(e){}onDidChange(e){return{dispose:()=>{}}}onDidCreate(e){return{dispose:()=>{}}}onDidDelete(e){return{dispose:()=>{}}}dispose(){for(let e of this.watchers)e.close();this.watchers=[]}},mv=class{createFileWatcher(e,r){return new Fx(e,r)}},gv=class{data={};storeFile;constructor(e){this.storeFile=e,this.load()}load(){try{if(as.existsSync(this.storeFile)){let e=as.readFileSync(this.storeFile,"utf-8");this.data=JSON.parse(e)}}catch{}}save(){try{let e=Mp.dirname(this.storeFile);as.mkdirSync(e,{recursive:!0}),as.writeFileSync(this.storeFile,JSON.stringify(this.data,null,2),"utf-8")}catch{}}get(e,r){let n=this.data[e];return n!==void 0?n:r}async update(e,r){r===void 0?delete this.data[e]:this.data[e]=r,this.save()}},yv=class{async showInformation(e){console.log(`[INFO] ${e}`)}async showWarning(e){console.warn(`[WARN] ${e}`)}async showError(e){console.error(`[ERROR] ${e}`)}}});function Dx(t){let e=El.resolve(t.workspaceFolder),{appInfo:r}=t,n=Yo.createFresh(),i=El.join(e,".http-forge",".cache","stores","global-state.json"),s=t.globalStorePath?El.isAbsolute(t.globalStorePath)?t.globalStorePath:El.resolve(e,t.globalStorePath):i,o={workspaceFolder:e,fileWatcherFactory:new mv,notificationService:new yv,globalStore:new gv(s),applicationInfo:r||{name:"http-forge-cli",version:"0.1.0"},persistOverrides:!1};return Rp(n,o),n}function qn(t){return Dx({workspaceFolder:t})}var El,vv=ae(()=>{"use strict";El=ve(require("path"));Sx();_x();qN()});function j5(t){let e=[];return t.map(r=>{let n=_n(r,e);return e.push(n),n})}function ON(t,e,r,n){let i=t.find(d=>d.id===e);if(i)return{item:i,tier:"id"};let s=j5(t.map(d=>d.name)),o=t.filter((d,p)=>s[p]===e);if(o.length===1)return{item:o[0],tier:"slug"};if(o.length>1)throw new Zo(r,e,o.map(d=>({id:d.id,name:d.name,path:n(d)})));let l=e.toLowerCase(),c=t.filter(d=>d.name.toLowerCase()===l);if(c.length===1)return{item:c[0],tier:"name"};throw c.length>1?new Zo(r,e,c.map(d=>({id:d.id,name:d.name,path:n(d)}))):new Error(`${r.charAt(0).toUpperCase()}${r.slice(1)} "${e}" not found`)}function bv(t,e){let{item:r,tier:n}=ON(t,e,"collection",()=>"");return{collection:r,tier:n}}function Sv(t,e){let r=e.split("/").map(o=>o.trim()).filter(o=>o.length>0),n=t.items,i=[],s=[];for(let o of r){let l=n.filter(m=>m.type==="folder"),c=i.join("/"),{item:d,tier:p}=ON(l,o,"folder",m=>c?`${c}/${m.name}`:m.name);i.push(d.name),s.push(p),n=d.items??[]}return{folderPath:i.map(vr).join("/"),tiers:s}}function IN(t,e,r){let n=[];for(let i of t)if(i.type==="request"){let s=_n(i.name,n);n.push(s),r.push({item:i,folderPath:e,slug:s})}for(let i of t)if(i.type==="folder"){let s=i,o=e?`${e}/${vr(s.name)}`:vr(s.name);IN(s.items??[],o,r)}}function wv(t,e,r){let n=[];IN(t.items,"",n);let i=r?r.replace(/\/+$/,""):void 0,s=i?n.filter(y=>y.folderPath===i||y.folderPath.startsWith(`${i}/`)):n,o=y=>y.folderPath?`${y.folderPath}/${y.item.name}`:y.item.name,l=s.find(y=>y.item.id===e);if(l)return{request:l.item,tier:"id",folderPath:l.folderPath};let c=s.filter(y=>y.slug===e);if(c.length===1)return{request:c[0].item,tier:"slug",folderPath:c[0].folderPath};if(c.length>1)throw new Zo("request",e,c.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let d=e.toLowerCase(),p=s.filter(y=>y.item.name.toLowerCase()===d);if(p.length===1)return{request:p[0].item,tier:"name",folderPath:p[0].folderPath};if(p.length>1)throw new Zo("request",e,p.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let m=i?` under folder "${i}"`:"";throw new Error(`Request "${e}" not found in collection "${t.name}"${m}`)}var Zo,jx=ae(()=>{"use strict";Pa();Oi();Zo=class extends Error{constructor(r,n,i){super(`Ambiguous ${r} reference "${n}" matches ${i.length} items:
|
|
1015
|
+
</html>`}}});function Rl(t,e){if(t.length===0)return 0;let r=Math.ceil(e/100*t.length)-1;return t[Math.max(0,Math.min(r,t.length-1))]}var ir,dn,Cl,Nx=ae(()=>{"use strict";ir=ve(require("fs/promises")),dn=ve(require("path"));Un();_d();$x();Np();Cl=class{constructor(e){this.configService=e;let r=e.getRunnerConfig();this.basePath=e.getResultsPath(),this.indexPageSize=r.indexPageSize,this.recentErrorsLimit=r.recentErrorsLimit}configService;basePath;currentRunPath=null;currentRunId=null;currentSuiteId=null;currentManifest=null;currentIndexPage=[];currentPageNumber=1;indexPageSize;recentErrors=[];recentErrorsLimit;resultIndex=0;requestDurations={};getBasePath(){return this.basePath}async initializeRun(e,r,n,i){let s=this.generateRunId();return this.currentRunId=s,this.currentSuiteId=e,this.currentRunPath=dn.join(this.basePath,e,s),await ir.mkdir(dn.join(this.currentRunPath,"results"),{recursive:!0}),await ir.mkdir(dn.join(this.currentRunPath,"index"),{recursive:!0}),this.currentManifest={version:"1.0",runId:s,suiteId:e,suiteName:r,environment:n,startTime:new Date().toISOString(),status:"running",config:i,stats:{totalRequests:0,passed:0,failed:0,skipped:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0},requestStats:{},totalIndexPages:0,indexPageSize:this.indexPageSize},this.currentIndexPage=[],this.currentPageNumber=1,this.recentErrors=[],this.resultIndex=0,this.requestDurations={},await this.saveManifest(),s}async saveResult(e,r){if(!this.currentRunPath||!this.currentManifest)throw new Error("No active run. Call initializeRun first.");this.resultIndex++;let n=Date.now(),i=String(e).padStart(4,"0"),s=String(this.resultIndex).padStart(6,"0"),o=Ht(r.requestId),l=`result-${s}-iter-${i}-${o}.json`,c=dn.join(this.currentRunPath,"results",l),d={index:this.resultIndex,iteration:e,requestId:r.requestId,name:r.name,method:r.executedRequest.method,url:r.executedRequest.url,folderPath:r.folderPath||"",groupPath:r.groupPath||r.folderPath||"",groupType:r.groupType,collectionName:r.collectionName||"",status:r.response.status,statusText:r.response.statusText||"",duration:r.duration,passed:r.passed,timestamp:n,request:{method:r.executedRequest.method,url:r.executedRequest.url,headers:r.executedRequest.headers,query:r.executedRequest.query,params:r.executedRequest.params,body:r.executedRequest.body},response:{headers:r.response.headers,body:r.response.body,time:r.response.time,size:r.response.size,cookies:r.response.cookies},assertions:r.assertions.map(b=>({name:b.name,passed:b.passed,message:b.message||null})),error:r.error||null,consoleOutput:r.consoleOutput,modifiedVariables:r.modifiedVariables,modifiedEnvironmentVariables:r.modifiedEnvironmentVariables,modifiedCollectionVariables:r.modifiedCollectionVariables,nextRequest:r.nextRequest??null,visualizerData:r.visualizerData};await ir.writeFile(c,JSON.stringify(fg(d),null,2),"utf-8");let p=r.assertions.filter(b=>b.passed).length,m=r.assertions.filter(b=>!b.passed).length,y={i:this.resultIndex,it:e,n:r.name,m:dv[r.executedRequest.method.toUpperCase()]??0,s:r.response.status,d:r.duration,p:r.passed,ap:p,af:m,r:r.requestId,e:r.passed?null:r.error||null,fp:r.folderPath||"",gp:r.groupPath||r.folderPath||"",gt:r.groupType,cn:r.collectionName||""};return this.currentIndexPage.push(y),this.currentIndexPage.length>=this.indexPageSize&&await this.writeCurrentIndexPage(),this.updateStats(r),this.requestDurations[r.requestId]||(this.requestDurations[r.requestId]=[]),this.requestDurations[r.requestId].push(r.duration),r.passed||(this.recentErrors.unshift({timestamp:n,iteration:e,requestName:r.name,status:r.response.status,error:r.error||`Status ${r.response.status}`,resultFile:l}),this.recentErrors.length>this.recentErrorsLimit&&this.recentErrors.pop()),y}async finalizeRun(e="completed",r=!0){if(!this.currentManifest)return null;this.currentIndexPage.length>0&&await this.writeCurrentIndexPage(),this.currentManifest.endTime=new Date().toISOString(),this.currentManifest.status=e,this.currentManifest.totalIndexPages=this.currentPageNumber-1,this.currentManifest.stats.totalRequests>0&&(this.currentManifest.stats.avgDuration=Math.round(this.currentManifest.stats.totalDuration/this.currentManifest.stats.totalRequests)),this.currentManifest.stats.minDuration===Number.MAX_SAFE_INTEGER&&(this.currentManifest.stats.minDuration=0);for(let c in this.currentManifest.requestStats){let d=this.currentManifest.requestStats[c],p=this.requestDurations[c]||[];d.count>0&&(d.avgDuration=Math.round(d.totalDuration/d.count)),d.minDuration===Number.MAX_SAFE_INTEGER&&(d.minDuration=0),p.length>0&&(p.sort((m,y)=>m-y),d.p50=Rl(p,50),d.p90=Rl(p,90),d.p95=Rl(p,95),d.p99=Rl(p,99))}let n=Object.values(this.requestDurations).flat();n.length>0&&(n.sort((c,d)=>c-d),this.currentManifest.stats.p50=Rl(n,50),this.currentManifest.stats.p95=Rl(n,95),this.currentManifest.stats.p99=Rl(n,99)),this.requestDurations={},await this.saveManifest();let i=null,s=this.currentRunPath,o=this.currentSuiteId,l=this.currentRunId;if(this.currentRunPath=null,this.currentRunId=null,this.currentSuiteId=null,this.currentManifest=null,this.currentIndexPage=[],this.recentErrors=[],this.resultIndex=0,r&&o&&l&&s)try{i=await new jc(this.basePath).generate(o,l)}catch(c){console.warn("[ResultStorage] HTML report generation failed:",c)}return i}getCurrentStats(){return this.currentManifest?{stats:{...this.currentManifest.stats},requestStats:{...this.currentManifest.requestStats},recentErrors:[...this.recentErrors]}:null}getCurrentRunId(){return this.currentRunId}getCurrentSuiteId(){return this.currentSuiteId}async getResultDetails(e,r,n){let i=dn.join(this.basePath,e,r,"results",n),s=await ir.readFile(i,"utf-8");return JSON.parse(s)}async getIndexPage(e,r,n){let i=dn.join(this.basePath,e,r,"index",`page-${String(n).padStart(4,"0")}.json`),s=await ir.readFile(i,"utf-8");return JSON.parse(s)}async getManifest(e,r){let n=dn.join(this.basePath,e,r,"manifest.json"),i=await ir.readFile(n,"utf-8");return JSON.parse(i)}async listRuns(e){let r=dn.join(this.basePath,e);try{let n=await ir.readdir(r),i=[];for(let s of n.sort().reverse())try{let o=await this.getManifest(e,s);i.push(o)}catch{}return i}catch{return[]}}async listSuites(){try{return(await ir.readdir(this.basePath,{withFileTypes:!0})).filter(r=>r.isDirectory()).map(r=>r.name)}catch{return[]}}async deleteRun(e,r){let n=dn.join(this.basePath,e,r);await ir.rm(n,{recursive:!0,force:!0})}async cleanupOldRuns(){let r=this.configService.getRunnerConfig().resultsRetentionDays;if(r===0)return{deleted:0,freed:0};let n=new Date;n.setDate(n.getDate()-r);let i=0,s=0,o=await this.listSuites();for(let l of o){let c=await this.listRuns(l);for(let d of c)if(new Date(d.startTime)<n){let p=dn.join(this.basePath,l,d.runId),m=await this.getDirectorySize(p);await ir.rm(p,{recursive:!0,force:!0}),i++,s+=m}}return{deleted:i,freed:s}}generateRunId(){let e=new Date,r=e.toISOString().slice(0,10).replace(/-/g,""),n=e.toTimeString().slice(0,8).replace(/:/g,""),i=String(e.getMilliseconds()).padStart(3,"0");return`run-${r}-${n}-${i}`}async saveManifest(){if(!this.currentRunPath||!this.currentManifest)return;let e=dn.join(this.currentRunPath,"manifest.json");await ir.writeFile(e,JSON.stringify(this.currentManifest,null,2),"utf-8")}async writeCurrentIndexPage(){if(!this.currentRunPath||this.currentIndexPage.length===0)return;let e=`page-${String(this.currentPageNumber).padStart(4,"0")}.json`,r=dn.join(this.currentRunPath,"index",e),n={page:this.currentPageNumber,startIndex:(this.currentPageNumber-1)*this.indexPageSize+1,count:this.currentIndexPage.length,summaries:this.currentIndexPage};await ir.writeFile(r,JSON.stringify(n),"utf-8"),this.currentPageNumber++,this.currentIndexPage=[]}updateStats(e){if(!this.currentManifest)return;let r=this.currentManifest.stats,n=this.currentManifest.requestStats;r.totalRequests++,r.totalDuration+=e.duration,r.minDuration=Math.min(r.minDuration,e.duration),r.maxDuration=Math.max(r.maxDuration,e.duration),e.passed?r.passed++:r.failed++,n[e.requestId]||(n[e.requestId]={name:e.name,count:0,passed:0,failed:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0});let i=n[e.requestId];i.count++,i.totalDuration+=e.duration,i.minDuration=Math.min(i.minDuration,e.duration),i.maxDuration=Math.max(i.maxDuration,e.duration),e.passed?i.passed++:i.failed++}async getDirectorySize(e){let r=0;try{let n=await ir.readdir(e,{withFileTypes:!0});for(let i of n){let s=dn.join(e,i.name);if(i.isDirectory())r+=await this.getDirectorySize(s);else{let o=await ir.stat(s);r+=o.size}}}catch{}return r}}});function Lc(t){return typeof t=="string"?t:""+JSON.stringify(t)}function xl(t){if(typeof t=="string"&&t.charCodeAt(0)===30)try{return JSON.parse(t.slice(1))}catch{return t}return t}function hv(t){if(!t)return{};let e={};for(let[r,n]of Object.entries(t))e[r]=xl(n);return e}var Mx=ae(()=>{"use strict"});var as,Mp,Fx,mv,gv,yv,qN=ae(()=>{"use strict";as=ve(require("fs")),Mp=ve(require("path")),Fx=class{watchers=[];constructor(e,r){let n=this.globToPath(e,r);try{let i=as.watch(n,{recursive:!0},(s,o)=>{if(o){let l=Mp.join(n,o);this.notifyChange(l)}});this.watchers.push(i)}catch{}}globToPath(e,r){return r.includes("**")?e:Mp.join(e,r.replace(/\*/g,""))}notifyChange(e){}onDidChange(e){return{dispose:()=>{}}}onDidCreate(e){return{dispose:()=>{}}}onDidDelete(e){return{dispose:()=>{}}}dispose(){for(let e of this.watchers)e.close();this.watchers=[]}},mv=class{createFileWatcher(e,r){return new Fx(e,r)}},gv=class{data={};storeFile;constructor(e){this.storeFile=e,this.load()}load(){try{if(as.existsSync(this.storeFile)){let e=as.readFileSync(this.storeFile,"utf-8");this.data=JSON.parse(e)}}catch{}}save(){try{let e=Mp.dirname(this.storeFile);as.mkdirSync(e,{recursive:!0}),as.writeFileSync(this.storeFile,JSON.stringify(this.data,null,2),"utf-8")}catch{}}get(e,r){let n=this.data[e];return n!==void 0?n:r}async update(e,r){r===void 0?delete this.data[e]:this.data[e]=r,this.save()}},yv=class{async showInformation(e){console.log(`[INFO] ${e}`)}async showWarning(e){console.warn(`[WARN] ${e}`)}async showError(e){console.error(`[ERROR] ${e}`)}}});function Dx(t){let e=El.resolve(t.workspaceFolder),{appInfo:r}=t,n=Yo.createFresh(),i=El.join(e,".http-forge",".cache","stores","global-state.json"),s=t.globalStorePath?El.isAbsolute(t.globalStorePath)?t.globalStorePath:El.resolve(e,t.globalStorePath):i,o={workspaceFolder:e,fileWatcherFactory:new mv,notificationService:new yv,globalStore:new gv(s),applicationInfo:r||{name:"http-forge-cli",version:"0.1.0"},persistOverrides:!1};return Rp(n,o),n}function qn(t){return Dx({workspaceFolder:t})}var El,vv=ae(()=>{"use strict";El=ve(require("path"));Sx();_x();qN()});function j5(t){let e=[];return t.map(r=>{let n=_n(r,e);return e.push(n),n})}function ON(t,e,r,n){let i=t.find(d=>d.id===e);if(i)return{item:i,tier:"id"};let s=j5(t.map(d=>d.name)),o=t.filter((d,p)=>s[p]===e);if(o.length===1)return{item:o[0],tier:"slug"};if(o.length>1)throw new Zo(r,e,o.map(d=>({id:d.id,name:d.name,path:n(d)})));let l=e.toLowerCase(),c=t.filter(d=>d.name.toLowerCase()===l);if(c.length===1)return{item:c[0],tier:"name"};throw c.length>1?new Zo(r,e,c.map(d=>({id:d.id,name:d.name,path:n(d)}))):new Error(`${r.charAt(0).toUpperCase()}${r.slice(1)} "${e}" not found`)}function bv(t,e){let{item:r,tier:n}=ON(t,e,"collection",()=>"");return{collection:r,tier:n}}function Sv(t,e){let r=e.split("/").map(o=>o.trim()).filter(o=>o.length>0),n=t.items,i=[],s=[];for(let o of r){let l=n.filter(m=>m.type==="folder"),c=i.join("/"),{item:d,tier:p}=ON(l,o,"folder",m=>c?`${c}/${m.name}`:m.name);i.push(d.name),s.push(p),n=d.items??[]}return{folderPath:i.map(vr).join("/"),tiers:s}}function IN(t,e,r){let n=[];for(let i of t)if(i.type==="request"){let s=_n(i.name,n);n.push(s),r.push({item:i,folderPath:e,slug:s})}for(let i of t)if(i.type==="folder"){let s=i,o=e?`${e}/${vr(s.name)}`:vr(s.name);IN(s.items??[],o,r)}}function wv(t,e,r){let n=[];IN(t.items,"",n);let i=r?r.replace(/\/+$/,""):void 0,s=i?n.filter(y=>y.folderPath===i||y.folderPath.startsWith(`${i}/`)):n,o=y=>y.folderPath?`${y.folderPath}/${y.item.name}`:y.item.name,l=s.find(y=>y.item.id===e);if(l)return{request:l.item,tier:"id",folderPath:l.folderPath};let c=s.filter(y=>y.slug===e);if(c.length===1)return{request:c[0].item,tier:"slug",folderPath:c[0].folderPath};if(c.length>1)throw new Zo("request",e,c.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let d=e.toLowerCase(),p=s.filter(y=>y.item.name.toLowerCase()===d);if(p.length===1)return{request:p[0].item,tier:"name",folderPath:p[0].folderPath};if(p.length>1)throw new Zo("request",e,p.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let m=i?` under folder "${i}"`:"";throw new Error(`Request "${e}" not found in collection "${t.name}"${m}`)}var Zo,jx=ae(()=>{"use strict";Pa();Oi();Zo=class extends Error{constructor(r,n,i){super(`Ambiguous ${r} reference "${n}" matches ${i.length} items:
|
|
1016
1016
|
`+i.map(s=>` - ${s.name} (id: ${s.id}, path: ${s.path||"/"})`).join(`
|
|
1017
1017
|
`)+`
|
|
1018
1018
|
Disambiguate by passing the id or slug.`);this.kind=r;this.value=n;this.candidates=i;this.name="AmbiguousRefError"}kind;value;candidates}});var Dp={};Rs(Dp,{runCollection:()=>Vs,runFolder:()=>W5,runRequest:()=>Rv,runSuite:()=>Fp});function Ux(t){let e=[t.testSuite,t.collection,t.environmentConfig,t.config,t.console];for(let r of e)try{r?.dispose?.()}catch{}}function kN(t){return t==="1"||t==="true"||t==="yes"||t==="on"}function L5(){return kN(process.env.HTTP_FORGE_ENFORCE_MAX_REQUESTS)}function U5(){let t=process.env.HTTP_FORGE_MAX_REQUESTS;if(!t||t.trim()==="")return 50;let e=Number(t);if(!Number.isFinite(e)||e<=0)throw new Error("HTTP_FORGE_MAX_REQUESTS must be a positive number when provided");return Math.floor(e)}function AN(t,e=[]){return kN(process.env.HTTP_FORGE_GENERATE_REPORTS)||e.includes("html")?!0:t.includes("report")}function Lx(t){if(typeof t!="string")return t;try{return JSON.parse(t)}catch{return t}}function H5(t){return t?Object.fromEntries(Object.entries(t).filter(([e])=>e.toLowerCase()!=="set-cookie")):{}}function TN(t){return gi(H5(t))}function $N(t){return u_((t??[]).map(e=>({name:e.name,value:e.value})))}function PN(t){return t.replace(/[^a-zA-Z0-9_-]/g,"_")}function NN(t){let e=["none","inherit","basic","bearer","apikey","oauth2"],r=t.auth?.type&&e.includes(t.auth.type)?t.auth.type:void 0;return{id:t.id,name:t.name,method:t.method,url:t.url,headers:Array.isArray(t.headers)?t.headers.reduce((n,i)=>(i.enabled&&i.key&&(n[i.key]=i.value??""),n),{}):t.headers,query:Array.isArray(t.query)?t.query.reduce((n,i)=>(i.enabled&&i.key&&(n[i.key]=i.value??""),n),{}):t.query,params:t.params?Object.entries(t.params).reduce((n,[i,s])=>(n[i]=typeof s=="string"?s:s.value??"",n),{}):void 0,body:t.body??null,scripts:t.scripts,settings:t.settings,auth:{type:r==="inherit"?"none":r,bearerToken:t.auth?.bearerToken,basicAuth:t.auth?.basicAuth,apikey:t.auth?.apikey,oauth2:t.auth?.oauth2}}}function MN(t,e){let r={...t};return e.headers&&(r.headers={...t.headers??{},...e.headers}),e.query&&(r.query=e.query),e.body!==void 0&&(r.body={type:"raw",raw:e.body,contentType:"application/json"}),r}function _v(t){return t?Object.fromEntries(Object.entries(t).map(([e,r])=>[e,String(r)])):{}}function FN(t,e,r){if(t&&t.type&&t.type!=="inherit")return t.type==="none"?void 0:t;for(let n=e.length-1;n>=0;n--){let i=e[n];if(i?.type&&i.type!=="inherit")return i.type==="none"?void 0:i}if(r&&r.type&&r.type!=="inherit")return r.type==="none"?void 0:r}function Hx(t,e,r=t.items,n=[],i=[]){for(let s of r){if(s.type==="request"&&s.id===e)return{request:s,folderScriptsChain:[...n],folderAuthChain:[...i]};if(s.type==="folder"){let o=s,l=o.scripts?[...n,o.scripts]:[...n],c=o.auth?[...i,o.auth]:[...i],d=Hx(t,e,o.items??[],l,c);if(d)return d}}}function DN(t,e=t.items,r=[],n=[]){let i=[];for(let s of e)if(s.type==="request")i.push({request:s,folderScriptsChain:[...r],folderPath:n.map(vr).join("/")});else{let o=s,l=o.scripts?[...r,o.scripts]:[...r],c=[...n,o.name];i.push(...DN(t,o.items??[],l,c))}return i}function B5(t,e,r=!0){if(!e)return t;let n=e.replace(/\/+$/,"");return t.filter(({folderPath:i})=>r?i===n||i.startsWith(`${n}/`):i===n)}function V5(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function jN(t,e){if(e.collectionId){let r=t.getCollection(e.collectionId);if(!r)throw new Error(`Collection "${e.collectionId}" not found`);return r}if(e.collectionRef){let{collection:r,tier:n}=bv(t.getAllCollections(),e.collectionRef);return e.onResolve?.({kind:"collection",value:e.collectionRef,tier:n,id:r.id}),r}throw new Error("A collection reference is required (collectionId or collectionRef)")}function LN(t,e){if(e.folderPath)return e.folderPath;if(e.folderRef){let{folderPath:r}=Sv(t,e.folderRef);return e.onResolve?.({kind:"folder",value:e.folderRef,tier:"name",id:r,path:r}),r}}async function UN(t,e,r,n){let i=r.environment??t.environmentConfig.getSelectedEnvironment(),s=r.iterations??e.config?.iterations??1,o=r.stopOnError??e.config?.stopOnError??!1,l=r.delay??e.config?.delayBetweenRequests??0,c=Math.max(1,Math.min(50,r.concurrency??1)),d=r.requestFilter,p=r.include??[],m=r.reporters??[],y=m.includes("junit"),b=_v(r.variables),q=L5(),C=AN(p,m),v=Math.max(1,Math.min(1e4,Number(r.maxNodeLoopIterations??100))),_={vars:{...b}};function E(te){if(typeof te=="string")return te;if(Array.isArray(te))return te.filter(Pe=>typeof Pe=="string").join(`
|
package/dist/index.mjs
CHANGED
|
@@ -494,10 +494,10 @@ ${d.join(`
|
|
|
494
494
|
<tr>
|
|
495
495
|
<td class="kv-key">${$t(r.name??"(unnamed)")}</td>
|
|
496
496
|
<td class="kv-val">${$t(r.value??"")}</td>
|
|
497
|
-
</tr>`).join("")}</table>`}function sN(t,e){if(t==null||t==="")return'<span class="dim">\u2014 empty \u2014</span>';let r=oN(t);return`<pre class="code">${$t(r)}</pre>`}var cp,yx=ae(()=>{"use strict";up();cp=class{constructor(e){this.basePath=e}basePath;async generate(e,r){let n=uc.join(this.basePath,e,r),i=JSON.parse(await cc.readFile(uc.join(n,"manifest.json"),"utf-8")),s=await this.loadAllSummaries(n,i.totalIndexPages),o=await this.loadAllDetails(n,s),l=this.buildHtml(i,s,o),c=uc.join(n,"report.html");return await cc.writeFile(c,l,"utf-8"),c}async loadAllSummaries(e,r){let n=[];for(let i=1;i<=r;i++){let s=uc.join(e,"index",`page-${String(i).padStart(4,"0")}.json`);try{let o=JSON.parse(await cc.readFile(s,"utf-8"));n.push(...o.summaries)}catch{}}return n}async loadAllDetails(e,r){let n=new Map;for(let i of r){let s=sc(i.i,i.it,i.r),o=`${i.i}-${i.it}`;try{let l=JSON.parse(await cc.readFile(uc.join(e,"results",s),"utf-8"));n.set(o,l)}catch{}}return n}groupByIterCollectionFolder(e){let r=[],n=
|
|
497
|
+
</tr>`).join("")}</table>`}function sN(t,e){if(t==null||t==="")return'<span class="dim">\u2014 empty \u2014</span>';let r=oN(t);return`<pre class="code">${$t(r)}</pre>`}var cp,yx=ae(()=>{"use strict";up();cp=class{constructor(e){this.basePath=e}basePath;async generate(e,r){let n=uc.join(this.basePath,e,r),i=JSON.parse(await cc.readFile(uc.join(n,"manifest.json"),"utf-8")),s=await this.loadAllSummaries(n,i.totalIndexPages),o=await this.loadAllDetails(n,s),l=this.buildHtml(i,s,o),c=uc.join(n,"report.html");return await cc.writeFile(c,l,"utf-8"),c}async loadAllSummaries(e,r){let n=[];for(let i=1;i<=r;i++){let s=uc.join(e,"index",`page-${String(i).padStart(4,"0")}.json`);try{let o=JSON.parse(await cc.readFile(s,"utf-8"));n.push(...o.summaries)}catch{}}return n}async loadAllDetails(e,r){let n=new Map;for(let i of r){let s=sc(i.i,i.it,i.r),o=`${i.i}-${i.it}`;try{let l=JSON.parse(await cc.readFile(uc.join(e,"results",s),"utf-8"));n.set(o,l)}catch{}}return n}groupByIterCollectionFolder(e){let r=[],n=null,i=null,s=null;for(let o of e){let l=o.cn||"",c=o.gp||o.fp||"",d=o.gt;(!n||n.it!==o.it)&&(n={it:o.it,groups:[]},r.push(n),i=null,s=null);let p=`${d||""}\0${c}`;(!i||p!==s)&&(i={cn:l,fp:c,gt:d,items:[]},n.groups.push(i),s=p),i.items.push(o)}return r}groupLabel(e,r,n,i){let s=String(i).padStart(2,"0"),o="";return n==="block"?o=$t(r||"(unnamed block)"):r&&(o=r.split("/").map(c=>$t(c.replace(/^\s*\d+\s*-\s*/,""))).join("/")),o||(o="(root)"),`${s} - ${o}`}renderGroupedDetails(e,r,n){let i=r.config.iterations>1;return this.groupByIterCollectionFolder(e).map(s=>{let o=s.groups.map((d,p)=>{let m=d.items.filter(v=>v.p).length,y=d.items.length,b=m<y,q=d.items.map(n).join(""),C=d.gt==="block"?"\u{1F9E9}":"\u{1F4C1}";return`
|
|
498
498
|
<details class="group-block${b?" group-fail":""}" open>
|
|
499
499
|
<summary class="group-head">
|
|
500
|
-
<span class="group-title"
|
|
500
|
+
<span class="group-title">${C} ${this.groupLabel(d.cn,d.fp,d.gt,p+1)}</span>
|
|
501
501
|
<span class="group-count ${b?"fail":"dim"}">(${m}/${y})</span>
|
|
502
502
|
</summary>
|
|
503
503
|
<div class="group-body">${q}</div>
|
|
@@ -508,7 +508,7 @@ ${d.join(`
|
|
|
508
508
|
<span class="dim iter-count">(${l}/${c} passed)</span>
|
|
509
509
|
</summary>
|
|
510
510
|
<div class="iter-body">${o}</div>
|
|
511
|
-
</details>`}).join("")}renderGroupedTimeline(e,r,n){let i=r.config.iterations>1,s=8;return this.groupByIterCollectionFolder(e).map(o=>{let l="";return i&&(l+=`<tr class="group-row iter-row"><td colspan="${s}">Iteration ${o.it}</td></tr>`),o.groups.forEach((c,d)=>{l+=`<tr class="group-row folder-row"><td colspan="${s}"
|
|
511
|
+
</details>`}).join("")}renderGroupedTimeline(e,r,n){let i=r.config.iterations>1,s=8;return this.groupByIterCollectionFolder(e).map(o=>{let l="";return i&&(l+=`<tr class="group-row iter-row"><td colspan="${s}">Iteration ${o.it}</td></tr>`),o.groups.forEach((c,d)=>{let p=c.gt==="block"?"\u{1F9E9}":"\u{1F4C1}";l+=`<tr class="group-row folder-row"><td colspan="${s}">${p} ${this.groupLabel(c.cn,c.fp,c.gt,d+1)}</td></tr>`,l+=c.items.map(n).join("")}),l}).join("")}buildHtml(e,r,n){let i=il(e.stats.totalDuration),s=e.stats.failed===0,o=Object.entries(e.requestStats).map(([,b])=>{let q=x5(b.passed,b.count);return`
|
|
512
512
|
<tr${b.failed>0?' class="row-fail"':""}>
|
|
513
513
|
<td>${$t(b.name)}</td>
|
|
514
514
|
<td>${b.count}</td>
|
|
@@ -1012,7 +1012,7 @@ ${d.join(`
|
|
|
1012
1012
|
});
|
|
1013
1013
|
</script>
|
|
1014
1014
|
</body>
|
|
1015
|
-
</html>`}}});import*as nr from"fs/promises";import*as cn from"path";function sl(t,e){if(t.length===0)return 0;let r=Math.ceil(e/100*t.length)-1;return t[Math.max(0,Math.min(r,t.length-1))]}var fc,vx=ae(()=>{"use strict";jn();od();yx();up();fc=class{constructor(e){this.configService=e;let r=e.getRunnerConfig();this.basePath=e.getResultsPath(),this.indexPageSize=r.indexPageSize,this.recentErrorsLimit=r.recentErrorsLimit}configService;basePath;currentRunPath=null;currentRunId=null;currentSuiteId=null;currentManifest=null;currentIndexPage=[];currentPageNumber=1;indexPageSize;recentErrors=[];recentErrorsLimit;resultIndex=0;requestDurations={};getBasePath(){return this.basePath}async initializeRun(e,r,n,i){let s=this.generateRunId();return this.currentRunId=s,this.currentSuiteId=e,this.currentRunPath=cn.join(this.basePath,e,s),await nr.mkdir(cn.join(this.currentRunPath,"results"),{recursive:!0}),await nr.mkdir(cn.join(this.currentRunPath,"index"),{recursive:!0}),this.currentManifest={version:"1.0",runId:s,suiteId:e,suiteName:r,environment:n,startTime:new Date().toISOString(),status:"running",config:i,stats:{totalRequests:0,passed:0,failed:0,skipped:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0},requestStats:{},totalIndexPages:0,indexPageSize:this.indexPageSize},this.currentIndexPage=[],this.currentPageNumber=1,this.recentErrors=[],this.resultIndex=0,this.requestDurations={},await this.saveManifest(),s}async saveResult(e,r){if(!this.currentRunPath||!this.currentManifest)throw new Error("No active run. Call initializeRun first.");this.resultIndex++;let n=Date.now(),i=String(e).padStart(4,"0"),s=String(this.resultIndex).padStart(6,"0"),o=Vt(r.requestId),l=`result-${s}-iter-${i}-${o}.json`,c=cn.join(this.currentRunPath,"results",l),d={index:this.resultIndex,iteration:e,requestId:r.requestId,name:r.name,method:r.executedRequest.method,url:r.executedRequest.url,folderPath:r.folderPath||"",collectionName:r.collectionName||"",status:r.response.status,statusText:r.response.statusText||"",duration:r.duration,passed:r.passed,timestamp:n,request:{method:r.executedRequest.method,url:r.executedRequest.url,headers:r.executedRequest.headers,query:r.executedRequest.query,params:r.executedRequest.params,body:r.executedRequest.body},response:{headers:r.response.headers,body:r.response.body,time:r.response.time,size:r.response.size,cookies:r.response.cookies},assertions:r.assertions.map(b=>({name:b.name,passed:b.passed,message:b.message||null})),error:r.error||null,consoleOutput:r.consoleOutput,modifiedVariables:r.modifiedVariables,modifiedEnvironmentVariables:r.modifiedEnvironmentVariables,modifiedCollectionVariables:r.modifiedCollectionVariables,nextRequest:r.nextRequest??null,visualizerData:r.visualizerData};await nr.writeFile(c,JSON.stringify(q0(d),null,2),"utf-8");let p=r.assertions.filter(b=>b.passed).length,m=r.assertions.filter(b=>!b.passed).length,y={i:this.resultIndex,it:e,n:r.name,m:dx[r.executedRequest.method.toUpperCase()]??0,s:r.response.status,d:r.duration,p:r.passed,ap:p,af:m,r:r.requestId,e:r.passed?null:r.error||null,fp:r.folderPath||"",cn:r.collectionName||""};return this.currentIndexPage.push(y),this.currentIndexPage.length>=this.indexPageSize&&await this.writeCurrentIndexPage(),this.updateStats(r),this.requestDurations[r.requestId]||(this.requestDurations[r.requestId]=[]),this.requestDurations[r.requestId].push(r.duration),r.passed||(this.recentErrors.unshift({timestamp:n,iteration:e,requestName:r.name,status:r.response.status,error:r.error||`Status ${r.response.status}`,resultFile:l}),this.recentErrors.length>this.recentErrorsLimit&&this.recentErrors.pop()),y}async finalizeRun(e="completed",r=!0){if(!this.currentManifest)return null;this.currentIndexPage.length>0&&await this.writeCurrentIndexPage(),this.currentManifest.endTime=new Date().toISOString(),this.currentManifest.status=e,this.currentManifest.totalIndexPages=this.currentPageNumber-1,this.currentManifest.stats.totalRequests>0&&(this.currentManifest.stats.avgDuration=Math.round(this.currentManifest.stats.totalDuration/this.currentManifest.stats.totalRequests)),this.currentManifest.stats.minDuration===Number.MAX_SAFE_INTEGER&&(this.currentManifest.stats.minDuration=0);for(let c in this.currentManifest.requestStats){let d=this.currentManifest.requestStats[c],p=this.requestDurations[c]||[];d.count>0&&(d.avgDuration=Math.round(d.totalDuration/d.count)),d.minDuration===Number.MAX_SAFE_INTEGER&&(d.minDuration=0),p.length>0&&(p.sort((m,y)=>m-y),d.p50=sl(p,50),d.p90=sl(p,90),d.p95=sl(p,95),d.p99=sl(p,99))}let n=Object.values(this.requestDurations).flat();n.length>0&&(n.sort((c,d)=>c-d),this.currentManifest.stats.p50=sl(n,50),this.currentManifest.stats.p95=sl(n,95),this.currentManifest.stats.p99=sl(n,99)),this.requestDurations={},await this.saveManifest();let i=null,s=this.currentRunPath,o=this.currentSuiteId,l=this.currentRunId;if(this.currentRunPath=null,this.currentRunId=null,this.currentSuiteId=null,this.currentManifest=null,this.currentIndexPage=[],this.recentErrors=[],this.resultIndex=0,r&&o&&l&&s)try{i=await new cp(this.basePath).generate(o,l)}catch(c){console.warn("[ResultStorage] HTML report generation failed:",c)}return i}getCurrentStats(){return this.currentManifest?{stats:{...this.currentManifest.stats},requestStats:{...this.currentManifest.requestStats},recentErrors:[...this.recentErrors]}:null}getCurrentRunId(){return this.currentRunId}getCurrentSuiteId(){return this.currentSuiteId}async getResultDetails(e,r,n){let i=cn.join(this.basePath,e,r,"results",n),s=await nr.readFile(i,"utf-8");return JSON.parse(s)}async getIndexPage(e,r,n){let i=cn.join(this.basePath,e,r,"index",`page-${String(n).padStart(4,"0")}.json`),s=await nr.readFile(i,"utf-8");return JSON.parse(s)}async getManifest(e,r){let n=cn.join(this.basePath,e,r,"manifest.json"),i=await nr.readFile(n,"utf-8");return JSON.parse(i)}async listRuns(e){let r=cn.join(this.basePath,e);try{let n=await nr.readdir(r),i=[];for(let s of n.sort().reverse())try{let o=await this.getManifest(e,s);i.push(o)}catch{}return i}catch{return[]}}async listSuites(){try{return(await nr.readdir(this.basePath,{withFileTypes:!0})).filter(r=>r.isDirectory()).map(r=>r.name)}catch{return[]}}async deleteRun(e,r){let n=cn.join(this.basePath,e,r);await nr.rm(n,{recursive:!0,force:!0})}async cleanupOldRuns(){let r=this.configService.getRunnerConfig().resultsRetentionDays;if(r===0)return{deleted:0,freed:0};let n=new Date;n.setDate(n.getDate()-r);let i=0,s=0,o=await this.listSuites();for(let l of o){let c=await this.listRuns(l);for(let d of c)if(new Date(d.startTime)<n){let p=cn.join(this.basePath,l,d.runId),m=await this.getDirectorySize(p);await nr.rm(p,{recursive:!0,force:!0}),i++,s+=m}}return{deleted:i,freed:s}}generateRunId(){let e=new Date,r=e.toISOString().slice(0,10).replace(/-/g,""),n=e.toTimeString().slice(0,8).replace(/:/g,""),i=String(e.getMilliseconds()).padStart(3,"0");return`run-${r}-${n}-${i}`}async saveManifest(){if(!this.currentRunPath||!this.currentManifest)return;let e=cn.join(this.currentRunPath,"manifest.json");await nr.writeFile(e,JSON.stringify(this.currentManifest,null,2),"utf-8")}async writeCurrentIndexPage(){if(!this.currentRunPath||this.currentIndexPage.length===0)return;let e=`page-${String(this.currentPageNumber).padStart(4,"0")}.json`,r=cn.join(this.currentRunPath,"index",e),n={page:this.currentPageNumber,startIndex:(this.currentPageNumber-1)*this.indexPageSize+1,count:this.currentIndexPage.length,summaries:this.currentIndexPage};await nr.writeFile(r,JSON.stringify(n),"utf-8"),this.currentPageNumber++,this.currentIndexPage=[]}updateStats(e){if(!this.currentManifest)return;let r=this.currentManifest.stats,n=this.currentManifest.requestStats;r.totalRequests++,r.totalDuration+=e.duration,r.minDuration=Math.min(r.minDuration,e.duration),r.maxDuration=Math.max(r.maxDuration,e.duration),e.passed?r.passed++:r.failed++,n[e.requestId]||(n[e.requestId]={name:e.name,count:0,passed:0,failed:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0});let i=n[e.requestId];i.count++,i.totalDuration+=e.duration,i.minDuration=Math.min(i.minDuration,e.duration),i.maxDuration=Math.max(i.maxDuration,e.duration),e.passed?i.passed++:i.failed++}async getDirectorySize(e){let r=0;try{let n=await nr.readdir(e,{withFileTypes:!0});for(let i of n){let s=cn.join(e,i.name);if(i.isDirectory())r+=await this.getDirectorySize(s);else{let o=await nr.stat(s);r+=o.size}}}catch{}return r}}});function fp(t){return typeof t=="string"?t:""+JSON.stringify(t)}function dc(t){if(typeof t=="string"&&t.charCodeAt(0)===30)try{return JSON.parse(t.slice(1))}catch{return t}return t}function bx(t){if(!t)return{};let e={};for(let[r,n]of Object.entries(t))e[r]=dc(n);return e}var Sx=ae(()=>{"use strict"});import*as es from"fs";import*as dp from"path";var wx,Ay,Ty,$y,aN=ae(()=>{"use strict";wx=class{watchers=[];constructor(e,r){let n=this.globToPath(e,r);try{let i=es.watch(n,{recursive:!0},(s,o)=>{if(o){let l=dp.join(n,o);this.notifyChange(l)}});this.watchers.push(i)}catch{}}globToPath(e,r){return r.includes("**")?e:dp.join(e,r.replace(/\*/g,""))}notifyChange(e){}onDidChange(e){return{dispose:()=>{}}}onDidCreate(e){return{dispose:()=>{}}}onDidDelete(e){return{dispose:()=>{}}}dispose(){for(let e of this.watchers)e.close();this.watchers=[]}},Ay=class{createFileWatcher(e,r){return new wx(e,r)}},Ty=class{data={};storeFile;constructor(e){this.storeFile=e,this.load()}load(){try{if(es.existsSync(this.storeFile)){let e=es.readFileSync(this.storeFile,"utf-8");this.data=JSON.parse(e)}}catch{}}save(){try{let e=dp.dirname(this.storeFile);es.mkdirSync(e,{recursive:!0}),es.writeFileSync(this.storeFile,JSON.stringify(this.data,null,2),"utf-8")}catch{}}get(e,r){let n=this.data[e];return n!==void 0?n:r}async update(e,r){r===void 0?delete this.data[e]:this.data[e]=r,this.save()}},$y=class{async showInformation(e){console.log(`[INFO] ${e}`)}async showWarning(e){console.warn(`[WARN] ${e}`)}async showError(e){console.error(`[ERROR] ${e}`)}}});import*as ol from"path";function lN(t){let e=ol.resolve(t.workspaceFolder),{appInfo:r}=t,n=rl.createFresh(),i=ol.join(e,".http-forge",".cache","stores","global-state.json"),s=t.globalStorePath?ol.isAbsolute(t.globalStorePath)?t.globalStorePath:ol.resolve(e,t.globalStorePath):i,o={workspaceFolder:e,fileWatcherFactory:new Ay,notificationService:new $y,globalStore:new Ty(s),applicationInfo:r||{name:"http-forge-cli",version:"0.1.0"},persistOverrides:!1};return _y(n,o),n}function Yn(t){return lN({workspaceFolder:t})}var Ny=ae(()=>{"use strict";DC();jC();aN()});function O5(t){let e=[];return t.map(r=>{let n=Ln(r,e);return e.push(n),n})}function uN(t,e,r,n){let i=t.find(d=>d.id===e);if(i)return{item:i,tier:"id"};let s=O5(t.map(d=>d.name)),o=t.filter((d,p)=>s[p]===e);if(o.length===1)return{item:o[0],tier:"slug"};if(o.length>1)throw new al(r,e,o.map(d=>({id:d.id,name:d.name,path:n(d)})));let l=e.toLowerCase(),c=t.filter(d=>d.name.toLowerCase()===l);if(c.length===1)return{item:c[0],tier:"name"};throw c.length>1?new al(r,e,c.map(d=>({id:d.id,name:d.name,path:n(d)}))):new Error(`${r.charAt(0).toUpperCase()}${r.slice(1)} "${e}" not found`)}function _x(t,e){let{item:r,tier:n}=uN(t,e,"collection",()=>"");return{collection:r,tier:n}}function Rx(t,e){let r=e.split("/").map(o=>o.trim()).filter(o=>o.length>0),n=t.items,i=[],s=[];for(let o of r){let l=n.filter(m=>m.type==="folder"),c=i.join("/"),{item:d,tier:p}=uN(l,o,"folder",m=>c?`${c}/${m.name}`:m.name);i.push(d.name),s.push(p),n=d.items??[]}return{folderPath:i.map(Ir).join("/"),tiers:s}}function cN(t,e,r){let n=[];for(let i of t)if(i.type==="request"){let s=Ln(i.name,n);n.push(s),r.push({item:i,folderPath:e,slug:s})}for(let i of t)if(i.type==="folder"){let s=i,o=e?`${e}/${Ir(s.name)}`:Ir(s.name);cN(s.items??[],o,r)}}function Cx(t,e,r){let n=[];cN(t.items,"",n);let i=r?r.replace(/\/+$/,""):void 0,s=i?n.filter(y=>y.folderPath===i||y.folderPath.startsWith(`${i}/`)):n,o=y=>y.folderPath?`${y.folderPath}/${y.item.name}`:y.item.name,l=s.find(y=>y.item.id===e);if(l)return{request:l.item,tier:"id",folderPath:l.folderPath};let c=s.filter(y=>y.slug===e);if(c.length===1)return{request:c[0].item,tier:"slug",folderPath:c[0].folderPath};if(c.length>1)throw new al("request",e,c.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let d=e.toLowerCase(),p=s.filter(y=>y.item.name.toLowerCase()===d);if(p.length===1)return{request:p[0].item,tier:"name",folderPath:p[0].folderPath};if(p.length>1)throw new al("request",e,p.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let m=i?` under folder "${i}"`:"";throw new Error(`Request "${e}" not found in collection "${t.name}"${m}`)}var al,xx=ae(()=>{"use strict";ma();Ei();al=class extends Error{constructor(r,n,i){super(`Ambiguous ${r} reference "${n}" matches ${i.length} items:
|
|
1015
|
+
</html>`}}});import*as nr from"fs/promises";import*as cn from"path";function sl(t,e){if(t.length===0)return 0;let r=Math.ceil(e/100*t.length)-1;return t[Math.max(0,Math.min(r,t.length-1))]}var fc,vx=ae(()=>{"use strict";jn();od();yx();up();fc=class{constructor(e){this.configService=e;let r=e.getRunnerConfig();this.basePath=e.getResultsPath(),this.indexPageSize=r.indexPageSize,this.recentErrorsLimit=r.recentErrorsLimit}configService;basePath;currentRunPath=null;currentRunId=null;currentSuiteId=null;currentManifest=null;currentIndexPage=[];currentPageNumber=1;indexPageSize;recentErrors=[];recentErrorsLimit;resultIndex=0;requestDurations={};getBasePath(){return this.basePath}async initializeRun(e,r,n,i){let s=this.generateRunId();return this.currentRunId=s,this.currentSuiteId=e,this.currentRunPath=cn.join(this.basePath,e,s),await nr.mkdir(cn.join(this.currentRunPath,"results"),{recursive:!0}),await nr.mkdir(cn.join(this.currentRunPath,"index"),{recursive:!0}),this.currentManifest={version:"1.0",runId:s,suiteId:e,suiteName:r,environment:n,startTime:new Date().toISOString(),status:"running",config:i,stats:{totalRequests:0,passed:0,failed:0,skipped:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0},requestStats:{},totalIndexPages:0,indexPageSize:this.indexPageSize},this.currentIndexPage=[],this.currentPageNumber=1,this.recentErrors=[],this.resultIndex=0,this.requestDurations={},await this.saveManifest(),s}async saveResult(e,r){if(!this.currentRunPath||!this.currentManifest)throw new Error("No active run. Call initializeRun first.");this.resultIndex++;let n=Date.now(),i=String(e).padStart(4,"0"),s=String(this.resultIndex).padStart(6,"0"),o=Vt(r.requestId),l=`result-${s}-iter-${i}-${o}.json`,c=cn.join(this.currentRunPath,"results",l),d={index:this.resultIndex,iteration:e,requestId:r.requestId,name:r.name,method:r.executedRequest.method,url:r.executedRequest.url,folderPath:r.folderPath||"",groupPath:r.groupPath||r.folderPath||"",groupType:r.groupType,collectionName:r.collectionName||"",status:r.response.status,statusText:r.response.statusText||"",duration:r.duration,passed:r.passed,timestamp:n,request:{method:r.executedRequest.method,url:r.executedRequest.url,headers:r.executedRequest.headers,query:r.executedRequest.query,params:r.executedRequest.params,body:r.executedRequest.body},response:{headers:r.response.headers,body:r.response.body,time:r.response.time,size:r.response.size,cookies:r.response.cookies},assertions:r.assertions.map(b=>({name:b.name,passed:b.passed,message:b.message||null})),error:r.error||null,consoleOutput:r.consoleOutput,modifiedVariables:r.modifiedVariables,modifiedEnvironmentVariables:r.modifiedEnvironmentVariables,modifiedCollectionVariables:r.modifiedCollectionVariables,nextRequest:r.nextRequest??null,visualizerData:r.visualizerData};await nr.writeFile(c,JSON.stringify(q0(d),null,2),"utf-8");let p=r.assertions.filter(b=>b.passed).length,m=r.assertions.filter(b=>!b.passed).length,y={i:this.resultIndex,it:e,n:r.name,m:dx[r.executedRequest.method.toUpperCase()]??0,s:r.response.status,d:r.duration,p:r.passed,ap:p,af:m,r:r.requestId,e:r.passed?null:r.error||null,fp:r.folderPath||"",gp:r.groupPath||r.folderPath||"",gt:r.groupType,cn:r.collectionName||""};return this.currentIndexPage.push(y),this.currentIndexPage.length>=this.indexPageSize&&await this.writeCurrentIndexPage(),this.updateStats(r),this.requestDurations[r.requestId]||(this.requestDurations[r.requestId]=[]),this.requestDurations[r.requestId].push(r.duration),r.passed||(this.recentErrors.unshift({timestamp:n,iteration:e,requestName:r.name,status:r.response.status,error:r.error||`Status ${r.response.status}`,resultFile:l}),this.recentErrors.length>this.recentErrorsLimit&&this.recentErrors.pop()),y}async finalizeRun(e="completed",r=!0){if(!this.currentManifest)return null;this.currentIndexPage.length>0&&await this.writeCurrentIndexPage(),this.currentManifest.endTime=new Date().toISOString(),this.currentManifest.status=e,this.currentManifest.totalIndexPages=this.currentPageNumber-1,this.currentManifest.stats.totalRequests>0&&(this.currentManifest.stats.avgDuration=Math.round(this.currentManifest.stats.totalDuration/this.currentManifest.stats.totalRequests)),this.currentManifest.stats.minDuration===Number.MAX_SAFE_INTEGER&&(this.currentManifest.stats.minDuration=0);for(let c in this.currentManifest.requestStats){let d=this.currentManifest.requestStats[c],p=this.requestDurations[c]||[];d.count>0&&(d.avgDuration=Math.round(d.totalDuration/d.count)),d.minDuration===Number.MAX_SAFE_INTEGER&&(d.minDuration=0),p.length>0&&(p.sort((m,y)=>m-y),d.p50=sl(p,50),d.p90=sl(p,90),d.p95=sl(p,95),d.p99=sl(p,99))}let n=Object.values(this.requestDurations).flat();n.length>0&&(n.sort((c,d)=>c-d),this.currentManifest.stats.p50=sl(n,50),this.currentManifest.stats.p95=sl(n,95),this.currentManifest.stats.p99=sl(n,99)),this.requestDurations={},await this.saveManifest();let i=null,s=this.currentRunPath,o=this.currentSuiteId,l=this.currentRunId;if(this.currentRunPath=null,this.currentRunId=null,this.currentSuiteId=null,this.currentManifest=null,this.currentIndexPage=[],this.recentErrors=[],this.resultIndex=0,r&&o&&l&&s)try{i=await new cp(this.basePath).generate(o,l)}catch(c){console.warn("[ResultStorage] HTML report generation failed:",c)}return i}getCurrentStats(){return this.currentManifest?{stats:{...this.currentManifest.stats},requestStats:{...this.currentManifest.requestStats},recentErrors:[...this.recentErrors]}:null}getCurrentRunId(){return this.currentRunId}getCurrentSuiteId(){return this.currentSuiteId}async getResultDetails(e,r,n){let i=cn.join(this.basePath,e,r,"results",n),s=await nr.readFile(i,"utf-8");return JSON.parse(s)}async getIndexPage(e,r,n){let i=cn.join(this.basePath,e,r,"index",`page-${String(n).padStart(4,"0")}.json`),s=await nr.readFile(i,"utf-8");return JSON.parse(s)}async getManifest(e,r){let n=cn.join(this.basePath,e,r,"manifest.json"),i=await nr.readFile(n,"utf-8");return JSON.parse(i)}async listRuns(e){let r=cn.join(this.basePath,e);try{let n=await nr.readdir(r),i=[];for(let s of n.sort().reverse())try{let o=await this.getManifest(e,s);i.push(o)}catch{}return i}catch{return[]}}async listSuites(){try{return(await nr.readdir(this.basePath,{withFileTypes:!0})).filter(r=>r.isDirectory()).map(r=>r.name)}catch{return[]}}async deleteRun(e,r){let n=cn.join(this.basePath,e,r);await nr.rm(n,{recursive:!0,force:!0})}async cleanupOldRuns(){let r=this.configService.getRunnerConfig().resultsRetentionDays;if(r===0)return{deleted:0,freed:0};let n=new Date;n.setDate(n.getDate()-r);let i=0,s=0,o=await this.listSuites();for(let l of o){let c=await this.listRuns(l);for(let d of c)if(new Date(d.startTime)<n){let p=cn.join(this.basePath,l,d.runId),m=await this.getDirectorySize(p);await nr.rm(p,{recursive:!0,force:!0}),i++,s+=m}}return{deleted:i,freed:s}}generateRunId(){let e=new Date,r=e.toISOString().slice(0,10).replace(/-/g,""),n=e.toTimeString().slice(0,8).replace(/:/g,""),i=String(e.getMilliseconds()).padStart(3,"0");return`run-${r}-${n}-${i}`}async saveManifest(){if(!this.currentRunPath||!this.currentManifest)return;let e=cn.join(this.currentRunPath,"manifest.json");await nr.writeFile(e,JSON.stringify(this.currentManifest,null,2),"utf-8")}async writeCurrentIndexPage(){if(!this.currentRunPath||this.currentIndexPage.length===0)return;let e=`page-${String(this.currentPageNumber).padStart(4,"0")}.json`,r=cn.join(this.currentRunPath,"index",e),n={page:this.currentPageNumber,startIndex:(this.currentPageNumber-1)*this.indexPageSize+1,count:this.currentIndexPage.length,summaries:this.currentIndexPage};await nr.writeFile(r,JSON.stringify(n),"utf-8"),this.currentPageNumber++,this.currentIndexPage=[]}updateStats(e){if(!this.currentManifest)return;let r=this.currentManifest.stats,n=this.currentManifest.requestStats;r.totalRequests++,r.totalDuration+=e.duration,r.minDuration=Math.min(r.minDuration,e.duration),r.maxDuration=Math.max(r.maxDuration,e.duration),e.passed?r.passed++:r.failed++,n[e.requestId]||(n[e.requestId]={name:e.name,count:0,passed:0,failed:0,totalDuration:0,avgDuration:0,minDuration:Number.MAX_SAFE_INTEGER,maxDuration:0});let i=n[e.requestId];i.count++,i.totalDuration+=e.duration,i.minDuration=Math.min(i.minDuration,e.duration),i.maxDuration=Math.max(i.maxDuration,e.duration),e.passed?i.passed++:i.failed++}async getDirectorySize(e){let r=0;try{let n=await nr.readdir(e,{withFileTypes:!0});for(let i of n){let s=cn.join(e,i.name);if(i.isDirectory())r+=await this.getDirectorySize(s);else{let o=await nr.stat(s);r+=o.size}}}catch{}return r}}});function fp(t){return typeof t=="string"?t:""+JSON.stringify(t)}function dc(t){if(typeof t=="string"&&t.charCodeAt(0)===30)try{return JSON.parse(t.slice(1))}catch{return t}return t}function bx(t){if(!t)return{};let e={};for(let[r,n]of Object.entries(t))e[r]=dc(n);return e}var Sx=ae(()=>{"use strict"});import*as es from"fs";import*as dp from"path";var wx,Ay,Ty,$y,aN=ae(()=>{"use strict";wx=class{watchers=[];constructor(e,r){let n=this.globToPath(e,r);try{let i=es.watch(n,{recursive:!0},(s,o)=>{if(o){let l=dp.join(n,o);this.notifyChange(l)}});this.watchers.push(i)}catch{}}globToPath(e,r){return r.includes("**")?e:dp.join(e,r.replace(/\*/g,""))}notifyChange(e){}onDidChange(e){return{dispose:()=>{}}}onDidCreate(e){return{dispose:()=>{}}}onDidDelete(e){return{dispose:()=>{}}}dispose(){for(let e of this.watchers)e.close();this.watchers=[]}},Ay=class{createFileWatcher(e,r){return new wx(e,r)}},Ty=class{data={};storeFile;constructor(e){this.storeFile=e,this.load()}load(){try{if(es.existsSync(this.storeFile)){let e=es.readFileSync(this.storeFile,"utf-8");this.data=JSON.parse(e)}}catch{}}save(){try{let e=dp.dirname(this.storeFile);es.mkdirSync(e,{recursive:!0}),es.writeFileSync(this.storeFile,JSON.stringify(this.data,null,2),"utf-8")}catch{}}get(e,r){let n=this.data[e];return n!==void 0?n:r}async update(e,r){r===void 0?delete this.data[e]:this.data[e]=r,this.save()}},$y=class{async showInformation(e){console.log(`[INFO] ${e}`)}async showWarning(e){console.warn(`[WARN] ${e}`)}async showError(e){console.error(`[ERROR] ${e}`)}}});import*as ol from"path";function lN(t){let e=ol.resolve(t.workspaceFolder),{appInfo:r}=t,n=rl.createFresh(),i=ol.join(e,".http-forge",".cache","stores","global-state.json"),s=t.globalStorePath?ol.isAbsolute(t.globalStorePath)?t.globalStorePath:ol.resolve(e,t.globalStorePath):i,o={workspaceFolder:e,fileWatcherFactory:new Ay,notificationService:new $y,globalStore:new Ty(s),applicationInfo:r||{name:"http-forge-cli",version:"0.1.0"},persistOverrides:!1};return _y(n,o),n}function Yn(t){return lN({workspaceFolder:t})}var Ny=ae(()=>{"use strict";DC();jC();aN()});function O5(t){let e=[];return t.map(r=>{let n=Ln(r,e);return e.push(n),n})}function uN(t,e,r,n){let i=t.find(d=>d.id===e);if(i)return{item:i,tier:"id"};let s=O5(t.map(d=>d.name)),o=t.filter((d,p)=>s[p]===e);if(o.length===1)return{item:o[0],tier:"slug"};if(o.length>1)throw new al(r,e,o.map(d=>({id:d.id,name:d.name,path:n(d)})));let l=e.toLowerCase(),c=t.filter(d=>d.name.toLowerCase()===l);if(c.length===1)return{item:c[0],tier:"name"};throw c.length>1?new al(r,e,c.map(d=>({id:d.id,name:d.name,path:n(d)}))):new Error(`${r.charAt(0).toUpperCase()}${r.slice(1)} "${e}" not found`)}function _x(t,e){let{item:r,tier:n}=uN(t,e,"collection",()=>"");return{collection:r,tier:n}}function Rx(t,e){let r=e.split("/").map(o=>o.trim()).filter(o=>o.length>0),n=t.items,i=[],s=[];for(let o of r){let l=n.filter(m=>m.type==="folder"),c=i.join("/"),{item:d,tier:p}=uN(l,o,"folder",m=>c?`${c}/${m.name}`:m.name);i.push(d.name),s.push(p),n=d.items??[]}return{folderPath:i.map(Ir).join("/"),tiers:s}}function cN(t,e,r){let n=[];for(let i of t)if(i.type==="request"){let s=Ln(i.name,n);n.push(s),r.push({item:i,folderPath:e,slug:s})}for(let i of t)if(i.type==="folder"){let s=i,o=e?`${e}/${Ir(s.name)}`:Ir(s.name);cN(s.items??[],o,r)}}function Cx(t,e,r){let n=[];cN(t.items,"",n);let i=r?r.replace(/\/+$/,""):void 0,s=i?n.filter(y=>y.folderPath===i||y.folderPath.startsWith(`${i}/`)):n,o=y=>y.folderPath?`${y.folderPath}/${y.item.name}`:y.item.name,l=s.find(y=>y.item.id===e);if(l)return{request:l.item,tier:"id",folderPath:l.folderPath};let c=s.filter(y=>y.slug===e);if(c.length===1)return{request:c[0].item,tier:"slug",folderPath:c[0].folderPath};if(c.length>1)throw new al("request",e,c.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let d=e.toLowerCase(),p=s.filter(y=>y.item.name.toLowerCase()===d);if(p.length===1)return{request:p[0].item,tier:"name",folderPath:p[0].folderPath};if(p.length>1)throw new al("request",e,p.map(y=>({id:y.item.id,name:y.item.name,path:o(y)})));let m=i?` under folder "${i}"`:"";throw new Error(`Request "${e}" not found in collection "${t.name}"${m}`)}var al,xx=ae(()=>{"use strict";ma();Ei();al=class extends Error{constructor(r,n,i){super(`Ambiguous ${r} reference "${n}" matches ${i.length} items:
|
|
1016
1016
|
`+i.map(s=>` - ${s.name} (id: ${s.id}, path: ${s.path||"/"})`).join(`
|
|
1017
1017
|
`)+`
|
|
1018
1018
|
Disambiguate by passing the id or slug.`);this.kind=r;this.value=n;this.candidates=i;this.name="AmbiguousRefError"}kind;value;candidates}});var hp={};io(hp,{runCollection:()=>Ns,runFolder:()=>$5,runRequest:()=>Fy,runSuite:()=>pp});function qx(t){let e=[t.testSuite,t.collection,t.environmentConfig,t.config,t.console];for(let r of e)try{r?.dispose?.()}catch{}}function dN(t){return t==="1"||t==="true"||t==="yes"||t==="on"}function I5(){return dN(process.env.HTTP_FORGE_ENFORCE_MAX_REQUESTS)}function P5(){let t=process.env.HTTP_FORGE_MAX_REQUESTS;if(!t||t.trim()==="")return 50;let e=Number(t);if(!Number.isFinite(e)||e<=0)throw new Error("HTTP_FORGE_MAX_REQUESTS must be a positive number when provided");return Math.floor(e)}function pN(t,e=[]){return dN(process.env.HTTP_FORGE_GENERATE_REPORTS)||e.includes("html")?!0:t.includes("report")}function Ex(t){if(typeof t!="string")return t;try{return JSON.parse(t)}catch{return t}}function k5(t){return t?Object.fromEntries(Object.entries(t).filter(([e])=>e.toLowerCase()!=="set-cookie")):{}}function hN(t){return Wi(k5(t))}function mN(t){return R0((t??[]).map(e=>({name:e.name,value:e.value})))}function fN(t){return t.replace(/[^a-zA-Z0-9_-]/g,"_")}function gN(t){let e=["none","inherit","basic","bearer","apikey","oauth2"],r=t.auth?.type&&e.includes(t.auth.type)?t.auth.type:void 0;return{id:t.id,name:t.name,method:t.method,url:t.url,headers:Array.isArray(t.headers)?t.headers.reduce((n,i)=>(i.enabled&&i.key&&(n[i.key]=i.value??""),n),{}):t.headers,query:Array.isArray(t.query)?t.query.reduce((n,i)=>(i.enabled&&i.key&&(n[i.key]=i.value??""),n),{}):t.query,params:t.params?Object.entries(t.params).reduce((n,[i,s])=>(n[i]=typeof s=="string"?s:s.value??"",n),{}):void 0,body:t.body??null,scripts:t.scripts,settings:t.settings,auth:{type:r==="inherit"?"none":r,bearerToken:t.auth?.bearerToken,basicAuth:t.auth?.basicAuth,apikey:t.auth?.apikey,oauth2:t.auth?.oauth2}}}function yN(t,e){let r={...t};return e.headers&&(r.headers={...t.headers??{},...e.headers}),e.query&&(r.query=e.query),e.body!==void 0&&(r.body={type:"raw",raw:e.body,contentType:"application/json"}),r}function My(t){return t?Object.fromEntries(Object.entries(t).map(([e,r])=>[e,String(r)])):{}}function vN(t,e,r){if(t&&t.type&&t.type!=="inherit")return t.type==="none"?void 0:t;for(let n=e.length-1;n>=0;n--){let i=e[n];if(i?.type&&i.type!=="inherit")return i.type==="none"?void 0:i}if(r&&r.type&&r.type!=="inherit")return r.type==="none"?void 0:r}function Ox(t,e,r=t.items,n=[],i=[]){for(let s of r){if(s.type==="request"&&s.id===e)return{request:s,folderScriptsChain:[...n],folderAuthChain:[...i]};if(s.type==="folder"){let o=s,l=o.scripts?[...n,o.scripts]:[...n],c=o.auth?[...i,o.auth]:[...i],d=Ox(t,e,o.items??[],l,c);if(d)return d}}}function bN(t,e=t.items,r=[],n=[]){let i=[];for(let s of e)if(s.type==="request")i.push({request:s,folderScriptsChain:[...r],folderPath:n.map(Ir).join("/")});else{let o=s,l=o.scripts?[...r,o.scripts]:[...r],c=[...n,o.name];i.push(...bN(t,o.items??[],l,c))}return i}function A5(t,e,r=!0){if(!e)return t;let n=e.replace(/\/+$/,"");return t.filter(({folderPath:i})=>r?i===n||i.startsWith(`${n}/`):i===n)}function T5(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function SN(t,e){if(e.collectionId){let r=t.getCollection(e.collectionId);if(!r)throw new Error(`Collection "${e.collectionId}" not found`);return r}if(e.collectionRef){let{collection:r,tier:n}=_x(t.getAllCollections(),e.collectionRef);return e.onResolve?.({kind:"collection",value:e.collectionRef,tier:n,id:r.id}),r}throw new Error("A collection reference is required (collectionId or collectionRef)")}function wN(t,e){if(e.folderPath)return e.folderPath;if(e.folderRef){let{folderPath:r}=Rx(t,e.folderRef);return e.onResolve?.({kind:"folder",value:e.folderRef,tier:"name",id:r,path:r}),r}}async function _N(t,e,r,n){let i=r.environment??t.environmentConfig.getSelectedEnvironment(),s=r.iterations??e.config?.iterations??1,o=r.stopOnError??e.config?.stopOnError??!1,l=r.delay??e.config?.delayBetweenRequests??0,c=Math.max(1,Math.min(50,r.concurrency??1)),d=r.requestFilter,p=r.include??[],m=r.reporters??[],y=m.includes("junit"),b=My(r.variables),q=I5(),C=pN(p,m),v=Math.max(1,Math.min(1e4,Number(r.maxNodeLoopIterations??100))),_={vars:{...b}};function E(te){if(typeof te=="string")return te;if(Array.isArray(te))return te.filter(Ie=>typeof Ie=="string").join(`
|
|
@@ -25,8 +25,8 @@ export declare class HtmlReportGenerator {
|
|
|
25
25
|
/** Load every result file for every request (pass + fail). */
|
|
26
26
|
private loadAllDetails;
|
|
27
27
|
/**
|
|
28
|
-
* Group summaries by iteration, then by (collection +
|
|
29
|
-
* preserving execution order
|
|
28
|
+
* Group summaries by iteration, then by contiguous (collection + group path)
|
|
29
|
+
* segments while preserving exact execution order.
|
|
30
30
|
*/
|
|
31
31
|
private groupByIterCollectionFolder;
|
|
32
32
|
/**
|
|
@@ -41,6 +41,10 @@ export interface ResultSummary {
|
|
|
41
41
|
e: string | null;
|
|
42
42
|
/** Folder path (fp) - slash-separated; omitted/empty for root-level requests */
|
|
43
43
|
fp?: string;
|
|
44
|
+
/** Display group path (gp) - block label or folder path used for grouped results */
|
|
45
|
+
gp?: string;
|
|
46
|
+
/** Display grouping source (gt) - block label vs root-folder grouping */
|
|
47
|
+
gt?: 'folder' | 'block';
|
|
44
48
|
/** Collection name (cn) - omitted/empty when unknown */
|
|
45
49
|
cn?: string;
|
|
46
50
|
}
|
|
@@ -181,6 +185,10 @@ export interface FullResultDetails {
|
|
|
181
185
|
url: string;
|
|
182
186
|
/** Folder path within the collection (slash-separated; empty for root) */
|
|
183
187
|
folderPath?: string;
|
|
188
|
+
/** Display group path used by suite results (block label or folder path) */
|
|
189
|
+
groupPath?: string;
|
|
190
|
+
/** Display grouping source used by suite results */
|
|
191
|
+
groupType?: 'folder' | 'block';
|
|
184
192
|
/** Name of the collection this request belongs to */
|
|
185
193
|
collectionName?: string;
|
|
186
194
|
/** HTTP status code */
|
package/dist/types/types.d.ts
CHANGED
|
@@ -687,6 +687,10 @@ export interface ExecutionResult {
|
|
|
687
687
|
error?: string;
|
|
688
688
|
/** Folder path of the request within its collection (slash-separated; empty for root) */
|
|
689
689
|
folderPath?: string;
|
|
690
|
+
/** Display grouping path used by suite results (block label or folder path) */
|
|
691
|
+
groupPath?: string;
|
|
692
|
+
/** Display grouping source used by suite results */
|
|
693
|
+
groupType?: 'folder' | 'block';
|
|
690
694
|
/** Name of the collection this request belongs to (for multi-collection suite reports) */
|
|
691
695
|
collectionName?: string;
|
|
692
696
|
/** Postman-compatible: pm.execution.setNextRequest() value. null = stop runner. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@http-forge/core",
|
|
3
|
-
"version": "0.6.22.beta.
|
|
3
|
+
"version": "0.6.22.beta.5",
|
|
4
4
|
"description": "Headless Postman-compatible API testing engine for Node.js, CI/CD, OpenAPI workflows, and HTTP Forge automation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|