@checksum-ai/runtime 1.4.9-alpha → 1.4.11-alpha

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/.env CHANGED
@@ -1 +1 @@
1
- CHECKSUM_RUNTIME_BUILD_TIME=2025-11-20T15:49:27.384Z
1
+ CHECKSUM_RUNTIME_BUILD_TIME=2025-11-23T08:46:34.225Z
package/cli.js CHANGED
@@ -1696,7 +1696,7 @@ ${a.map(s=>[s.type,s.nestedLevel,this.getText(s.body)]).join(`,
1696
1696
  ${Kun}
1697
1697
  ${g}
1698
1698
  ${Yun}
1699
- ${(await s.getFormattedTestFileCode()).code}`)}loadVtgTestFileMirror(r){if(!r||!r.startsWith("/"))throw new Error("Currently vtg mode can only run with absolute path to file");let a=new owe(r);return a.loadTestFromFile(),a}createActionJsonFileForExistingChecksumSpec(r,a){let s=r.testMirrors[0].translateStatementsToActions({mergeCustomCodeSteps:this.vtgSettingsService.getSettings().mergeCustomCodeSteps}),l=this.getActionJsonFilePath(a);(0,qz.writeFileSync)(l,JSON.stringify(s,null,2))}createFolderIfNotExists(r){return(0,qz.existsSync)(r)||(0,qz.mkdirSync)(r,{recursive:!0}),r}getSavePathForNewChecksumSpec(){return(0,hfe.join)(this.draftsFolderPath,"test.checksum.spec.ts")}getActionJsonFilePath(r){let a=this.getFileName(r).replace(".spec.ts",".json");return(0,hfe.join)(this.draftsFolderPath,a)}getEvalFilePath(r){let a=this.internalE2ETest?".eval.e2e.checksum.spec.ts":".eval.checksum.spec.ts";return(0,hfe.join)(this.draftsFolderPath,a)}getFileName(r){return r.split("/").pop()}};e(qDr,"VtgTestRunner");var hkt=qDr;var yLe=require("fs"),vLe=require("path");var gkt=require("fs"),OP=$d(mD());var ILi=/^[0-9a-zA-Z]+$/,FLi=5;function Xvn(i){return i?i.length===FLi&&ILi.test(i):!1}e(Xvn,"isValidChecksumTestId");var zDr=class zDr{extract(r,a){if(!r)return;let s=r.split("/"),l=s[s.length-1];if(!l.endsWith(".checksum.spec.ts"))return;let g=l.replace(".checksum.spec.ts","").split(" - ").pop();return Xvn(g)?g:void 0}};e(zDr,"FileNameExtractionStrategy");var $Dr=zDr,WDr=class WDr{extract(r,a){if(!(!r||!(0,gkt.existsSync)(r)))try{let s=(0,gkt.readFileSync)(r,"utf-8"),l=OP.createSourceFile(r,s,OP.ScriptTarget.Latest,!0),d=new Map,g=e(b=>{if(OP.isCallExpression(b)){let E=b;if(this.isTestCall(E.expression)){let S=E.arguments[0];if(S&&OP.isCallExpression(S)&&OP.isIdentifier(S.expression)&&S.expression.text==="defineChecksumTest"){let F=this.extractDefineChecksumTestArgs(S);F&&Xvn(F.checksumTestId)&&d.set(F.testTitle,F.checksumTestId)}}}OP.forEachChild(b,g)},"visit");return g(l),a&&d.has(a)?d.get(a):d.size>0?Array.from(d.values())[0]:void 0}catch{return}}isTestCall(r){return OP.isIdentifier(r)&&r.text==="test"?!0:OP.isPropertyAccessExpression(r)?OP.isIdentifier(r.expression)&&r.expression.text==="test":!1}extractDefineChecksumTestArgs(r){let a=r.arguments;if(a.length<2)return;let s=a[0],l=a[1],d=this.extractStringLiteral(s),g=this.extractStringLiteral(l);if(d&&g)return{testTitle:d,checksumTestId:g}}extractStringLiteral(r){if(OP.isStringLiteral(r)||OP.isNoSubstitutionTemplateLiteral(r))return r.text}};e(WDr,"FileContentExtractionStrategy");var VDr=WDr,HDr=class HDr{constructor(r){this.strategies=r||[new VDr,new $Dr]}extract(r,a){for(let s of this.strategies){let l=s.extract(r,a);if(l)return l}}};e(HDr,"ChecksumTestIdExtractor");var JDr=HDr;var Zvn=new JDr;var GDr=e(i=>isNaN(i)?0:i,"getStat"),PLi=e((i,r,a)=>{if(!i)return;let s=a||r,l;if((0,vLe.isAbsolute)(i))l=i;else{let g=(0,vLe.dirname)(r);l=(0,vLe.resolve)(g,i)}return l.replace(s+"/","")},"toRelativeFilePath"),exn=e(i=>{let r=[];if(i.specs&&r.push(...i.specs),i.suites)for(let a of i.suites)r.push(...exn(a));return r},"extractSpecsFromSuite"),NLi=e(i=>{let r=[];for(let a of i.suites)r.push(...exn(a));return r},"extractFlatSpecsMap"),OLi=e((i,r,a,s,l)=>{let{expected:d,unexpected:g,flaky:b}=i.stats,E=[];NLi(i).forEach(O=>{let N=BLi(O.id,r);N&&(O.recovered=!0);let q=O.tests[0],Q=O.tags.includes("bug")||q.annotations.some(fe=>fe.type==="bug"),z=q.annotations&&q.annotations.length>0?q.annotations.map(fe=>({type:fe.type,description:fe.description||""})):[],se=O.tags||[],ue=a[O.id]||Zvn.extract(O.file,O.title);E.push({checksumTestId:ue,playwrightTestId:O.id,success:!!O.ok,recovered:N,bug:Q,annotations:z,tags:se,outcome:q.status,filePath:O.file,relativeFilePath:s?PLi(O.file,s,l):O.file})});let F={passed:GDr(b)+GDr(d),failed:GDr(g),bug:E.filter(O=>O.bug).length,recovered:E.filter(O=>O.recovered).length,tests:E};return E.forEach(O=>{O.bug&&(O.outcome==="expected"||O.outcome==="flaky"?F.passed--:O.outcome==="unexpected"&&F.failed--)}),F},"modifyStatsPerTestFile"),BLi=e((i,r)=>Object.values(r[i]||{}).some(a=>{var s,l;return(l=(s=a.autoRecoveryMetadata)==null?void 0:s.data)==null?void 0:l.autoRecovered}),"isAutoRecovered"),txn=e((i,r,a,s,l)=>{(0,yLe.cpSync)(i,i+".backup");try{let d=JSON.parse((0,yLe.readFileSync)(i,"utf-8")),g=OLi(d,r,a,s,l);return d.checksumMetadata=g,(0,yLe.writeFileSync)(i,JSON.stringify(d,null,2)),d}catch(d){return console.log("Error processing JSON report",d.message),null}},"processJSONReport");var YDr=class YDr extends IP{constructor(a,s=!1,l=!1){super(a,s);this.vtgMode=l;this.MAX_COMPLETION_WAIT=2*3600*1e3;this.didFail=!1;this.isolationMode=!1;this.trmMessagesBuffer="";this.completeIndicators={upload:!1,tests:!1,report:!1};this.uploadProgress=0;this.playwrightIdToReportMetadata={};this.pwTestIdToChecksumTestId={};this.logFilter={"upload-progress":{logEveryMS:1e3*30,lastLogTimestamp:0,logOnValueChange:!0,value:""}}}get replMode(){return this.getChecksumArg("repl")??!1}async run(){if(this.loadTracer(),this.validateAuthExists(),this.buildVolatileChecksumConfig(),this.vtgMode&&(this.config.options.hostReports=!1),!await this.getSession())return;this.testSuiteAnalytics=Hwt.getInstance(this.testSuiteRunInfo,this.isolationMode),this.testSuiteAnalytics.genericEvent(`Project root found at ${this.projectRootDirectory}`,{message:`Checksum root found at ${this.checksumRoot}`});let a={CHECKSUM_ROOT_FOLDER:this.checksumRoot,CHECKSUM_TEST_SUITE_INFO:JSON.stringify(this.testSuiteRunInfo)},s;try{s=await E8(this.startTestRunMonitor(this.testSuiteRunId),1e4,"test run monitor timeout"),a.CHECKSUM_UPLOAD_AGENT_PORT=s}catch{let b="Error starting test run monitor. Test results will not be available on checksum.";this.testSuiteAnalytics.testRunMonitorError({error:b}),this.log(b)}a.PW_TEST_HTML_REPORT_OPEN="never",this.isolationMode&&(a.CHECKSUM_ISOLATED_MODE="true"),this.testSuiteRunId&&(a.CHECKSUM_TEST_SUITE_ID=this.testSuiteRunId),this.replMode&&(a.CHECKSUM_REPL="true"),this.getChecksumArg("tm")&&(a.CHECKSUM_SHOW_TIME_MACHINE="true");let l=this.getNonChecksumArgs();this.vtgMode&&(await new hkt(this.getChecksumArg("id")||void 0,this.getChecksumArg("edit")||void 0,this.getChecksumArg("legacy")||!1,eg.vtg.isE2ETestMode,this.getChecksumArg("restore")||!1,this.checksumRoot,this.getInternalFilesDirPath()).initAndUpdateEnvAndPlaywrightArgs(a,l),eg.promptKillActivePlaywrightProcesses&&await this.promptKillActivePlaywrightProcesses()),this.replMode&&l.push("--debug");let d=`npx playwright test --config "${this.getPlaywrightConfigFilePath()}" ${l.map(g=>`"${g}"`).join(" ")}`;await this.patchPlaywright();try{console.log(`Tests running with @checksum-ai/runtime version ${this.checksumRuntimeVersion}`),this.replMode?(console.log("Running in REPL mode"),this.execCmd(d,a),await this.execCmd(`node ${__dirname}/repl.js`,a)):(this.testSuiteAnalytics.testSuiteStart(),await this.execCmd(d,a)),console.log(`Tests execution finished. Checksum is finalizing${this.isolationMode?"":" and uploading"} the report, please wait...`)}catch{this.didFail=!0,console.log("Error during test execution: Failed passing test"),this.testSuiteAnalytics.testsFailed()}finally{this.isolationMode||console.log("Waiting for test files to upload to Checksum..."),this.sendReportUploadRequest(),await this.patchPlaywright(!0),this.completeIndicators.tests=!0,await this.handleCompleteMessage()}}loadPlaywrightConfigOptions(){var S,F;let a=e(O=>(B7("Using report folder",O),(0,NK.join)(O,"index.html")),"makeFilePath"),s=e(O=>(B7("Using JSON report folder",O),(0,NK.join)(O,"report.json")),"makeJsonFilePath"),l,d,g=!1,b="never";process.env.PLAYWRIGHT_HTML_OUTPUT_DIR&&(l=a(process.env.PLAYWRIGHT_HTML_OUTPUT_DIR));let E=(S=this.playwrightConfig)==null?void 0:S.reporter;if(E instanceof Array){let O=E.filter(Q=>Q instanceof Array&&Q[0]==="html"),N=E.filter(Q=>Q instanceof Array&&Q[0]==="json");if(!process.env.PLAYWRIGHT_HTML_OUTPUT_DIR){let Q=O.find(z=>{var se;return(se=z[1])==null?void 0:se.outputFolder});Q&&(l=a((0,NK.join)(this.checksumRoot,Q[1].outputFolder)))}let q=N.find(Q=>{var z;return(z=Q[1])==null?void 0:z.outputFile});q&&(g=!0,d=(0,NK.join)(this.checksumRoot,q[1].outputFile));for(let Q of O){let z=(F=Q[1])==null?void 0:F.open;if(z==="always"||z==="on-failure"){b=z;break}}}l||(eg.isRepoMode?l=a((0,NK.join)(eg.runtimeRoot,"playwright-report")):l=a((0,NK.join)(this.projectRootDirectory,"playwright-report"))),d||(eg.isRepoMode?d=s((0,NK.join)(eg.runtimeRoot,"playwright-report")):d=s((0,NK.join)(this.projectRootDirectory,"playwright-report"))),this.playwrightConfigOptions={openReportCriteria:b,reportPath:l,jsonReportPath:d,hasJsonReporter:g}}sendReportUploadRequest(){let a=e(F=>{this.testSuiteAnalytics.testSuiteError({error:F}),this.log(F),this.completeIndicators.report=!0,this.testRunMonitorProcess.stdin.write("cli:report=false")},"makeError");if(!this.playwrightConfigOptions)return a("No playwright config options");let{reportPath:s,openReportCriteria:l,jsonReportPath:d,hasJsonReporter:g}=this.playwrightConfigOptions;if(g&&((0,Yrt.existsSync)(d)?txn(d,this.playwrightIdToReportMetadata,this.pwTestIdToChecksumTestId,this.checksumRoot,this.projectRootDirectory):console.warn(`Could not find JSON report file at ${d}`)),!(0,Yrt.existsSync)(s))return a(`Could not find report file at ${s}`);B7("Sending report upload request",s);let b=this.saveMetadataToFile((0,NK.dirname)(s)),E={reportPath:s,pathToChecksumMetadata:b,openReportCriteria:l,didFail:this.didFail,checksumRoot:this.checksumRoot,projectRoot:this.projectRootDirectory},S=Buffer.from(JSON.stringify(E)).toString("base64");this.testRunMonitorProcess.stdin.write(`cli:report=${S}`)}saveMetadataToFile(a){try{let s=(0,NK.join)(a,`checksum-metadata-${(0,KDr.randomUUID)()}.json`);return(0,Yrt.writeFileSync)(s,JSON.stringify(this.playwrightIdToReportMetadata,null,2)),s}catch(s){let l=`Error saving metadata to file - ${s.message}`;this.testSuiteAnalytics.testSuiteError({error:l}),this.log(l);return}}startTestMonitorProcess(a){let l=[JSON.stringify({sessionId:a,apiURL:this.config.apiURL,apiKey:this.config.apiKey}),...this.isolationMode?["isolated"]:[]],d={command:"node",args:[(0,NK.join)(__dirname,"test-run-monitor.js"),...l]};return eg.isRepoMode&&(d.command="yarn",d.args=["test-run-monitor",...l]),rxn.spawn(d.command,d.args)}startTestRunMonitor(a){return new Promise(s=>{console.log("Starting test run monitor"),this.testRunMonitorProcess=this.startTestMonitorProcess(a),this.testRunMonitorProcess.stdout.on("data",l=>{let d=this.parseTRMMessages(l.toString().trim());if(d.length)for(let g of d){if(g.startsWith("trace")){this.logTRMMessage(g),this.handleTestRunMonitorTrace(g.substring("trace".length+1));continue}if(!g.startsWith("monitor")){this.logTRMMessage(g);continue}let b=e(()=>{let O=g.substring("monitor".length+1),N=O.indexOf("=");if(N===-1)return{key:O,value:""};let[q,Q]=[O.substring(0,N),O.substring(N+1)];return{key:q,value:Q}},"getKeyAndValue"),{key:E,value:S}=b();if(!Object.values(Ror).includes(E)){this.logTRMMessage(`Received unknown monitor message: "${g}"`);continue}let F=E;this.logInterProcessEventMessage(F,S),E==="port"?s(S):this.handleTestRunMonitorMessage(F,S)}}),this.testRunMonitorProcess.on("exit",(l,d)=>{let g=`test run monitor process exited with code ${l} and signal ${d}`;this.testSuiteAnalytics.testRunMonitorError({error:g}),this.log(g)}),this.testRunMonitorProcess.stderr.on("data",l=>{let d=`TRM Error: ${l.toString().substring(0,300)}`;this.testSuiteAnalytics.testRunMonitorError({error:d}),this.log(d)}),this.testRunMonitorProcess.on("error",l=>{let d=`Error starting test run monitor: ${l.message}`;this.testSuiteAnalytics.testRunMonitorError({error:d}),this.log(d)})})}logInterProcessEventMessage(a,s){e(()=>{if(!this.logFilter[a])return!0;if(this.logFilter[a].logOnValueChange&&this.logFilter[a].value!==s)return this.logFilter[a].value=s,!0;if(this.logFilter[a].logEveryMS){let d=Date.now();if(d-this.logFilter[a].lastLogTimestamp>=this.logFilter[a].logEveryMS)return this.logFilter[a].lastLogTimestamp=d,!0}return!1},"shouldLog")()&&this.logTRMMessage(`Received monitor message: "${a}${s?`=${s}`:""}"`)}parseTRMMessages(a){let s=this.trmMessagesBuffer+a,l,d,g=e(()=>{l=s.indexOf("{trm}"),d=s.indexOf("{/trm}")},"findIndexes");g();let b=[];for(;l!==-1&&d!==-1&&d>l;){if(b.push(s.substring(l+"{trm}".length,d)),s=s.slice(d+"{/trm}".length).trim(),s.length&&!s.startsWith("{trm}"))return console.warn("Buffered data does not start with start delimiter",s),this.trmMessagesBuffer="",b;this.trmMessagesBuffer=s,g()}return b}setChecksumTestMetadata(a){let{retry:s,type:l,pwTestId:d,checksumTestId:g}=a;this.playwrightIdToReportMetadata[d]||(this.playwrightIdToReportMetadata[d]={}),this.playwrightIdToReportMetadata[d][s]||(this.playwrightIdToReportMetadata[d][s]={}),this.playwrightIdToReportMetadata[d][s][l]=a,this.pwTestIdToChecksumTestId[d]=g}async handleTestRunMonitorTrace(a){let s=a.indexOf("="),[l,d]=s>-1?[a.substring(0,s),a.substring(s+1)]:[a,""];if(!Object.values(Wwt).includes(l)){B7("Unknown trace event",l);return}try{let g=d?JSON.parse(d):{};switch(l){case"Upload Start":this.testSuiteAnalytics.uploadStart({filename:g.filename});break;case"Upload Complete":this.testSuiteAnalytics.uploadComplete({filename:g.filename});break;case"Upload Failed":this.testSuiteAnalytics.uploadFailed({filename:g.filename,error:g.error});break;case"Trace Processing Error":this.testSuiteAnalytics.traceProcessingError({error:g.error});break}}catch(g){B7(`Error parsing trace payload, ${g.message}`)}}async handleTestRunMonitorMessage(a,s){var l;switch(a){case"uploads-complete-with-errors":console.log("Error uploading test files to Checksum");try{let g=JSON.parse(s);this.testSuiteAnalytics.uploadsCompleteWithErrors(g)}catch{}this.sendProcessingError().then(()=>{this.completeIndicators.upload=!0});break;case"checksumTestMetadata":try{let g=JSON.parse(s);this.setChecksumTestMetadata(g)}catch(g){let b=`Error parsing test metadata event - ${g.message}`;this.testSuiteAnalytics.testSuiteError({error:b}),this.log(b)}break;case"uploads-complete":this.isolationMode||console.log("Test files uploaded successfully"),this.testSuiteAnalytics.allUploadsComplete(),this.sendUploadsComplete().then(()=>{this.completeIndicators.upload=!0});break;case"report-complete":{if(this.isolationMode){this.completeIndicators.report=!0;break}B7("Report processing and upload completed, updating cloud with test stats...");try{let g=s.slice(0,s.indexOf(":"))==="true",b=s.slice(s.indexOf(":")+1),E=this.handleStats(b);if(this.testSuiteAnalytics.testSuiteEnd({passed:E.passed,failed:E.failed,bug:E.bug,total:((l=E.tests)==null?void 0:l.length)||0}),await this.sendTestRunEnd(E),this.completeIndicators.report=!0,g){let S=`${this.checksumAppUrl}/#/test-runs/${this.testSuiteRunId}`,F=`Checksum report URL: ${S}`,O="*".repeat(F.length);console.log(`${O}
1699
+ ${(await s.getFormattedTestFileCode()).code}`)}loadVtgTestFileMirror(r){if(!r||!r.startsWith("/"))throw new Error("Currently vtg mode can only run with absolute path to file");let a=new owe(r);return a.loadTestFromFile(),a}createActionJsonFileForExistingChecksumSpec(r,a){let s=r.testMirrors[0].translateStatementsToActions({mergeCustomCodeSteps:this.vtgSettingsService.getSettings().mergeCustomCodeSteps}),l=this.getActionJsonFilePath(a);(0,qz.writeFileSync)(l,JSON.stringify(s,null,2))}createFolderIfNotExists(r){return(0,qz.existsSync)(r)||(0,qz.mkdirSync)(r,{recursive:!0}),r}getSavePathForNewChecksumSpec(){return(0,hfe.join)(this.draftsFolderPath,"test.checksum.spec.ts")}getActionJsonFilePath(r){let a=this.getFileName(r).replace(".spec.ts",".json");return(0,hfe.join)(this.draftsFolderPath,a)}getEvalFilePath(r){let a=this.internalE2ETest?".eval.e2e.checksum.spec.ts":".eval.checksum.spec.ts";return(0,hfe.join)(this.draftsFolderPath,a)}getFileName(r){return r.split("/").pop()}};e(qDr,"VtgTestRunner");var hkt=qDr;var yLe=require("fs"),vLe=require("path");var gkt=require("fs"),OP=$d(mD());var ILi=/^[0-9a-zA-Z]+$/,FLi=5;function Xvn(i){return i?i.length===FLi&&ILi.test(i):!1}e(Xvn,"isValidChecksumTestId");var zDr=class zDr{extract(r,a){if(!r)return;let s=r.split("/"),l=s[s.length-1];if(!l.endsWith(".checksum.spec.ts"))return;let g=l.replace(".checksum.spec.ts","").split(" - ").pop();return Xvn(g)?g:void 0}};e(zDr,"FileNameExtractionStrategy");var $Dr=zDr,WDr=class WDr{extract(r,a){if(!(!r||!(0,gkt.existsSync)(r)))try{let s=(0,gkt.readFileSync)(r,"utf-8"),l=OP.createSourceFile(r,s,OP.ScriptTarget.Latest,!0),d=new Map,g=e(b=>{if(OP.isCallExpression(b)){let E=b;if(this.isTestCall(E.expression)){let S=E.arguments[0];if(S&&OP.isCallExpression(S)&&OP.isIdentifier(S.expression)&&S.expression.text==="defineChecksumTest"){let F=this.extractDefineChecksumTestArgs(S);F&&Xvn(F.checksumTestId)&&d.set(F.testTitle,F.checksumTestId)}}}OP.forEachChild(b,g)},"visit");return g(l),a&&d.has(a)?d.get(a):d.size>0?Array.from(d.values())[0]:void 0}catch{return}}isTestCall(r){return OP.isIdentifier(r)&&r.text==="test"?!0:OP.isPropertyAccessExpression(r)?OP.isIdentifier(r.expression)&&r.expression.text==="test":!1}extractDefineChecksumTestArgs(r){let a=r.arguments;if(a.length<2)return;let s=a[0],l=a[1],d=this.extractStringLiteral(s),g=this.extractStringLiteral(l);if(d&&g)return{testTitle:d,checksumTestId:g}}extractStringLiteral(r){if(OP.isStringLiteral(r)||OP.isNoSubstitutionTemplateLiteral(r))return r.text}};e(WDr,"FileContentExtractionStrategy");var VDr=WDr,HDr=class HDr{constructor(r){this.strategies=r||[new VDr,new $Dr]}extract(r,a){for(let s of this.strategies){let l=s.extract(r,a);if(l)return l}}};e(HDr,"ChecksumTestIdExtractor");var JDr=HDr;var Zvn=new JDr;var GDr=e(i=>isNaN(i)?0:i,"getStat"),PLi=e((i,r,a)=>{if(!i)return;let s=a||r,l;if((0,vLe.isAbsolute)(i))l=i;else{let g=(0,vLe.dirname)(r);l=(0,vLe.resolve)(g,i)}return l.replace(s+"/","")},"toRelativeFilePath"),exn=e(i=>{let r=[];if(i.specs&&r.push(...i.specs),i.suites)for(let a of i.suites)r.push(...exn(a));return r},"extractSpecsFromSuite"),NLi=e(i=>{let r=[];for(let a of i.suites)r.push(...exn(a));return r},"extractFlatSpecsMap"),OLi=e((i,r,a,s,l)=>{let{expected:d,unexpected:g,flaky:b}=i.stats,E=[];NLi(i).forEach(O=>{let N=BLi(O.id,r);N&&(O.recovered=!0);let q=O.tests[0],Q=O.tags.includes("bug")||q.annotations.some(fe=>fe.type==="bug"),z=q.annotations&&q.annotations.length>0?q.annotations.map(fe=>({type:fe.type,description:fe.description||""})):[],se=O.tags||[],ue=a[O.id]||Zvn.extract(O.file,O.title);E.push({checksumTestId:ue,playwrightTestId:O.id,success:!!O.ok,recovered:N,bug:Q,annotations:z,tags:se,outcome:q.status,filePath:O.file,relativeFilePath:s?PLi(O.file,s,l):O.file})});let F={passed:GDr(b)+GDr(d),failed:GDr(g),bug:E.filter(O=>O.bug).length,recovered:E.filter(O=>O.recovered).length,tests:E};return E.forEach(O=>{O.bug&&(O.outcome==="expected"||O.outcome==="flaky"?F.passed--:O.outcome==="unexpected"&&F.failed--)}),F},"modifyStatsPerTestFile"),BLi=e((i,r)=>Object.values(r[i]||{}).some(a=>{var s,l;return(l=(s=a.autoRecoveryMetadata)==null?void 0:s.data)==null?void 0:l.autoRecovered}),"isAutoRecovered"),txn=e((i,r,a,s,l)=>{(0,yLe.cpSync)(i,i+".backup");try{let d=JSON.parse((0,yLe.readFileSync)(i,"utf-8")),g=OLi(d,r,a,s,l);return d.checksumMetadata=g,(0,yLe.writeFileSync)(i,JSON.stringify(d,null,2)),d}catch(d){return console.log("Error processing JSON report",d.message),null}},"processJSONReport");var YDr=class YDr extends IP{constructor(a,s=!1,l=!1){super(a,s);this.vtgMode=l;this.MAX_COMPLETION_WAIT=2*3600*1e3;this.didFail=!1;this.isolationMode=!1;this.trmMessagesBuffer="";this.completeIndicators={upload:!1,tests:!1,report:!1};this.uploadProgress=0;this.playwrightIdToReportMetadata={};this.pwTestIdToChecksumTestId={};this.logFilter={"upload-progress":{logEveryMS:1e3*30,lastLogTimestamp:0,logOnValueChange:!0,value:""}}}get replMode(){return this.getChecksumArg("repl")??!1}async run(){if(this.loadTracer(),this.validateAuthExists(),this.buildVolatileChecksumConfig(),this.vtgMode&&(this.config.options.hostReports=!1),!await this.getSession())return;this.testSuiteAnalytics=Hwt.getInstance(this.testSuiteRunInfo,this.isolationMode),this.testSuiteAnalytics.genericEvent(`Project root found at ${this.projectRootDirectory}`,{message:`Checksum root found at ${this.checksumRoot}`});let a={CHECKSUM_ROOT_FOLDER:this.checksumRoot,CHECKSUM_TEST_SUITE_INFO:JSON.stringify(this.testSuiteRunInfo)},s;try{s=await E8(this.startTestRunMonitor(this.testSuiteRunId),1e4,"test run monitor timeout"),a.CHECKSUM_UPLOAD_AGENT_PORT=s}catch{let b="Error starting test run monitor. Test results will not be available on checksum.";this.testSuiteAnalytics.testRunMonitorError({error:b}),this.log(b)}a.PW_TEST_HTML_REPORT_OPEN="never",this.isolationMode&&(a.CHECKSUM_ISOLATED_MODE="true"),this.testSuiteRunId&&(a.CHECKSUM_TEST_SUITE_ID=this.testSuiteRunId),this.replMode&&(a.CHECKSUM_REPL="true"),this.getChecksumArg("tm")&&(a.CHECKSUM_SHOW_TIME_MACHINE="true");let l=this.getNonChecksumArgs();this.vtgMode&&(await new hkt(this.getChecksumArg("id")||void 0,this.getChecksumArg("edit")||void 0,this.getChecksumArg("legacy")||!1,eg.vtg.isE2ETestMode,this.getChecksumArg("restore")||!1,this.checksumRoot,this.getInternalFilesDirPath()).initAndUpdateEnvAndPlaywrightArgs(a,l),eg.promptKillActivePlaywrightProcesses&&await this.promptKillActivePlaywrightProcesses()),this.replMode&&l.push("--debug");let d=`npx playwright test --config "${this.getPlaywrightConfigFilePath()}" ${l.map(g=>`"${g}"`).join(" ")}`;await this.patchPlaywright();try{console.log(`Tests running with @checksum-ai/runtime version ${this.checksumRuntimeVersion}`),this.replMode?(console.log("Running in REPL mode"),this.execCmd(d,a),await this.execCmd(`node ${__dirname}/repl.js`,a)):(this.testSuiteAnalytics.testSuiteStart(),await this.execCmd(d,a)),console.log(`Tests execution finished. Checksum is finalizing${this.isolationMode?"":" and uploading"} the report, please wait...`)}catch{this.didFail=!0,console.log("Error during test execution: Failed passing test"),this.testSuiteAnalytics.testsFailed()}finally{this.isolationMode||console.log("Waiting for test files to upload to Checksum..."),this.sendReportUploadRequest(),await this.patchPlaywright(!0),this.completeIndicators.tests=!0,await this.handleCompleteMessage()}}loadPlaywrightConfigOptions(){var S,F;let a=e(O=>(B7("Using report folder",O),(0,NK.join)(O,"index.html")),"makeFilePath"),s=e(O=>(B7("Using JSON report folder",O),(0,NK.join)(O,"report.json")),"makeJsonFilePath"),l,d,g=!1,b="never";process.env.PLAYWRIGHT_HTML_OUTPUT_DIR&&(l=a(process.env.PLAYWRIGHT_HTML_OUTPUT_DIR));let E=(S=this.playwrightConfig)==null?void 0:S.reporter;if(E instanceof Array){let O=E.filter(Q=>Q instanceof Array&&Q[0]==="html"),N=E.filter(Q=>Q instanceof Array&&Q[0]==="json");if(!process.env.PLAYWRIGHT_HTML_OUTPUT_DIR){let Q=O.find(z=>{var se;return(se=z[1])==null?void 0:se.outputFolder});Q&&(l=a((0,NK.join)(this.checksumRoot,Q[1].outputFolder)))}let q=N.find(Q=>{var z;return(z=Q[1])==null?void 0:z.outputFile});q&&(g=!0,d=(0,NK.join)(this.checksumRoot,q[1].outputFile));for(let Q of O){let z=(F=Q[1])==null?void 0:F.open;if(z==="always"||z==="on-failure"){b=z;break}}}l||(eg.isRepoMode?l=a((0,NK.join)(eg.runtimeRoot,"playwright-report")):l=a((0,NK.join)(this.projectRootDirectory,"playwright-report"))),d||(eg.isRepoMode?d=s((0,NK.join)(eg.runtimeRoot,"playwright-report")):d=s((0,NK.join)(this.projectRootDirectory,"playwright-report"))),this.playwrightConfigOptions={openReportCriteria:b,reportPath:l,jsonReportPath:d,hasJsonReporter:g}}sendReportUploadRequest(){let a=e(F=>{this.testSuiteAnalytics.testSuiteError({error:F}),this.log(F),this.completeIndicators.report=!0,this.testRunMonitorProcess.stdin.write("cli:report=false")},"makeError");if(!this.playwrightConfigOptions)return a("No playwright config options");let{reportPath:s,openReportCriteria:l,jsonReportPath:d,hasJsonReporter:g}=this.playwrightConfigOptions;if(g&&((0,Yrt.existsSync)(d)?txn(d,this.playwrightIdToReportMetadata,this.pwTestIdToChecksumTestId,this.checksumRoot,this.projectRootDirectory):console.warn(`Could not find JSON report file at ${d}`)),!(0,Yrt.existsSync)(s))return a(`Could not find report file at ${s}`);B7("Sending report upload request",s);let b=this.saveMetadataToFile((0,NK.dirname)(s)),E={reportPath:s,pathToChecksumMetadata:b,openReportCriteria:l,didFail:this.didFail,checksumRoot:this.checksumRoot,projectRoot:this.projectRootDirectory},S=Buffer.from(JSON.stringify(E)).toString("base64");this.testRunMonitorProcess.stdin.write(`cli:report=${S}`)}saveMetadataToFile(a){try{let s=(0,NK.join)(a,`checksum-metadata-${(0,KDr.randomUUID)()}.json`);return(0,Yrt.writeFileSync)(s,JSON.stringify(this.playwrightIdToReportMetadata,null,2)),s}catch(s){let l=`Error saving metadata to file - ${s.message}`;this.testSuiteAnalytics.testSuiteError({error:l}),this.log(l);return}}startTestMonitorProcess(a){let l=[JSON.stringify({sessionId:a,apiURL:this.config.apiURL,apiKey:this.config.apiKey}),...this.isolationMode?["isolated"]:[]],d={command:"node",args:[(0,NK.join)(__dirname,"test-run-monitor.js"),...l]};return eg.isRepoMode&&(d.command="yarn",d.args=["test-run-monitor",...l]),rxn.spawn(d.command,d.args)}startTestRunMonitor(a){return new Promise(s=>{console.log("Starting test run monitor"),this.testRunMonitorProcess=this.startTestMonitorProcess(a),this.testRunMonitorProcess.stdout.on("data",l=>{try{console.log("[DATA]",l.toString().trim());let d=this.parseTRMMessages(l.toString().trim());if(!d.length){console.log("[DATA NO MESSAGES]");return}for(let g of d){if(console.log("[DATA MESSAGE]",g),g.startsWith("trace")){this.logTRMMessage(g),this.handleTestRunMonitorTrace(g.substring("trace".length+1));continue}if(!g.startsWith("monitor")){this.logTRMMessage(g);continue}console.log("[DATA MONITOR MESSAGE]",g);let b=e(()=>{let O=g.substring("monitor".length+1),N=O.indexOf("=");if(N===-1)return{key:O,value:""};let[q,Q]=[O.substring(0,N),O.substring(N+1)];return{key:q,value:Q}},"getKeyAndValue"),{key:E,value:S}=b();if(!Object.values(Ror).includes(E)){this.logTRMMessage(`Received unknown monitor message: "${g}"`);continue}let F=E;this.logInterProcessEventMessage(F,S),E==="port"?s(S):this.handleTestRunMonitorMessage(F,S)}}catch(d){console.error("[DATA ERROR]",d)}}),this.testRunMonitorProcess.on("exit",(l,d)=>{let g=`test run monitor process exited with code ${l} and signal ${d}`;this.testSuiteAnalytics.testRunMonitorError({error:g}),this.log(g)}),this.testRunMonitorProcess.stderr.on("data",l=>{let d=`TRM Error: ${l.toString().substring(0,300)}`;this.testSuiteAnalytics.testRunMonitorError({error:d}),this.log(d)}),this.testRunMonitorProcess.on("error",l=>{let d=`Error starting test run monitor: ${l.message}`;this.testSuiteAnalytics.testRunMonitorError({error:d}),this.log(d)})})}logInterProcessEventMessage(a,s){e(()=>{if(!this.logFilter[a])return!0;if(this.logFilter[a].logOnValueChange&&this.logFilter[a].value!==s)return this.logFilter[a].value=s,!0;if(this.logFilter[a].logEveryMS){let d=Date.now();if(d-this.logFilter[a].lastLogTimestamp>=this.logFilter[a].logEveryMS)return this.logFilter[a].lastLogTimestamp=d,!0}return!1},"shouldLog")()&&this.logTRMMessage(`Received monitor message: "${a}${s?`=${s}`:""}"`)}parseTRMMessages(a){let s=this.trmMessagesBuffer+a,l,d,g=e(()=>{l=s.indexOf("{trm}"),d=s.indexOf("{/trm}")},"findIndexes");g(),console.log("[parseTRMMessages] BUFFERED DATA:",s),console.log("[parseTRMMessages] START INDEX:",l),console.log("[parseTRMMessages] END INDEX:",d);let b=[];for(;l!==-1&&d!==-1&&d>l;){if(b.push(s.substring(l+"{trm}".length,d)),s=s.slice(d+"{/trm}".length).trim(),s.length&&!s.startsWith("{trm}"))return console.warn("Buffered data does not start with start delimiter",s),this.trmMessagesBuffer="",b;this.trmMessagesBuffer=s,g()}return console.log("[parseTRMMessages] MESSAGES:",b),b}setChecksumTestMetadata(a){let{retry:s,type:l,pwTestId:d,checksumTestId:g}=a;this.playwrightIdToReportMetadata[d]||(this.playwrightIdToReportMetadata[d]={}),this.playwrightIdToReportMetadata[d][s]||(this.playwrightIdToReportMetadata[d][s]={}),this.playwrightIdToReportMetadata[d][s][l]=a,this.pwTestIdToChecksumTestId[d]=g}async handleTestRunMonitorTrace(a){let s=a.indexOf("="),[l,d]=s>-1?[a.substring(0,s),a.substring(s+1)]:[a,""];if(!Object.values(Wwt).includes(l)){B7("Unknown trace event",l);return}try{let g=d?JSON.parse(d):{};switch(l){case"Upload Start":this.testSuiteAnalytics.uploadStart({filename:g.filename});break;case"Upload Complete":this.testSuiteAnalytics.uploadComplete({filename:g.filename});break;case"Upload Failed":this.testSuiteAnalytics.uploadFailed({filename:g.filename,error:g.error});break;case"Trace Processing Error":this.testSuiteAnalytics.traceProcessingError({error:g.error});break}}catch(g){B7(`Error parsing trace payload, ${g.message}`)}}async handleTestRunMonitorMessage(a,s){var l;switch(a){case"uploads-complete-with-errors":console.log("Error uploading test files to Checksum");try{let g=JSON.parse(s);this.testSuiteAnalytics.uploadsCompleteWithErrors(g)}catch{}this.sendProcessingError().then(()=>{this.completeIndicators.upload=!0});break;case"checksumTestMetadata":try{let g=JSON.parse(s);this.setChecksumTestMetadata(g)}catch(g){let b=`Error parsing test metadata event - ${g.message}`;this.testSuiteAnalytics.testSuiteError({error:b}),this.log(b)}break;case"uploads-complete":this.isolationMode||console.log("Test files uploaded successfully"),this.testSuiteAnalytics.allUploadsComplete(),this.sendUploadsComplete().then(()=>{this.completeIndicators.upload=!0});break;case"report-complete":{if(console.log("In InterProcessEvents.ReportComplete handler"),this.isolationMode){this.completeIndicators.report=!0;break}B7("Report processing and upload completed, updating cloud with test stats...");try{let g=s.slice(0,s.indexOf(":"))==="true",b=s.slice(s.indexOf(":")+1),E=this.handleStats(b);if(this.testSuiteAnalytics.testSuiteEnd({passed:E.passed,failed:E.failed,bug:E.bug,total:((l=E.tests)==null?void 0:l.length)||0}),await this.sendTestRunEnd(E),this.completeIndicators.report=!0,g){let S=`${this.checksumAppUrl}/#/test-runs/${this.testSuiteRunId}`,F=`Checksum report URL: ${S}`,O="*".repeat(F.length);console.log(`${O}
1700
1700
  ${F}
1701
1701
  ${O}`),this.testSuiteAnalytics.reportComplete({stats:E,reportUrl:S})}else this.testSuiteAnalytics.testSuiteError({error:"An error occurred while uploading the test report to Checksum"}),this.testSuiteAnalytics.reportUploadError(),console.log("An error occurred while uploading the test report to Checksum")}catch(g){throw B7(`Error sending test run end - ${g.message}`),g}break}case"upload-progress":{if(this.isolationMode)break;let g=parseInt(s);(g<this.uploadProgress||g>=this.uploadProgress+10||g===100&&this.uploadProgress!==100)&&(this.uploadProgress=g,console.log(`[ Uploads progress: ${this.uploadProgress}% ]`))}break;case"log":console.log(s);break;case"trace":let d=s;if(!Object.values(Wwt).includes(d))return;this.testSuiteAnalytics.genericEvent(d);break;case"playwrightConfig":try{this.playwrightConfig||(this.playwrightConfig=JSON.parse(s),this.testSuiteAnalytics.playwrightConfig({config:this.playwrightConfig}),this.loadPlaywrightConfigOptions())}catch(g){let b=`Error parsing playwright config - ${g.message}`;this.testSuiteAnalytics.playwrightConfigError({error:b}),this.log(b)}break;default:this.testSuiteAnalytics.testRunMonitorError({error:`Unhandled test run monitor message: ${a}=${s}`}),this.log(`Unhandled test run monitor message: ${a}=${s}`)}}handleStats(a){let s={};try{a&&a.length>0?(s=JSON.parse(a),s.tests=s.tests.map(l=>{let d=this.playwrightIdToReportMetadata[l.playwrightTestId];if(!d)return l;let g=Object.keys(d??{}),b=!1,E=!1,S=[];g.forEach(O=>{var N;if(d[O]){let q=d[O].autoRecoverySummaries;(N=q==null?void 0:q.data)!=null&&N.length&&S.push(...q.data)}});let F=g[g.length-1];if(F&&d[F]){let O=d[F].autoRecoveryMetadata;b=(O==null?void 0:O.data.autoRecoveryTriggered)??!1,E=(O==null?void 0:O.data.autoRecovered)??!1}return{...l,recovered:E,autoRecoveryTriggered:b,autoRecoverySummaries:S}})):(this.testSuiteAnalytics.testSuiteError({error:"No stats received from test run monitor"}),B7("No stats received from test run monitor"))}catch(l){this.testSuiteAnalytics.testSuiteError({error:`Error parsing stats - ${l.message}`}),this.log(`Error parsing stats - ${l.message}`)}return s}async handleCompleteMessage(){let a=Date.now(),s=12;for(;;){if(Date.now()-a>this.MAX_COMPLETION_WAIT){console.log("Warning: Checksum wasn't able to upload all test assets or expected a file the couldn't be found. This might cause issues when viewing the report/trace."),this.testSuiteAnalytics.runtimeTimeout(),this.shutdown(1);return}if(Object.keys(this.completeIndicators).find(l=>!this.completeIndicators[l]))B7(this.completeIndicators),--s===0&&(this.testSuiteAnalytics.completionStatus({stats:this.completeIndicators}),s=12),await IT(5e3);else{this.testSuiteAnalytics.runtimeComplete(),console.log("Checksum test suite run has completed"),await this.shutdown(this.didFail?1:0);return}}}async shutdown(a=0){await this.cleanup(),process.exit(a)}async cleanup(){await super.cleanup(),this.testRunMonitorProcess&&(this.testRunMonitorProcess.stdin.write("cli:shutdown"),this.testRunMonitorProcess.kill())}async getSession(){let a,s;try{if(!this.config.options.hostReports)return this.setIsolatedMode(),!0;if(s=this.config.apiKey,!s||s==="<API key>"){let S="No API key found in checksum config - please set it in the config file - checksum.config.ts";return this.runtimeTrace(S,"Checksum Config Error"),this.log(S,!0),this.shutdown(1),!1}let l=await this.getEnvInfo(),d=JSON.stringify({...l,isHidden:!!this.config.options.hideReports}),g=await fetch(`${this.config.apiURL}/client-api/test-runs`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:s},body:d}),{uuid:b,appName:E}=await g.json();return this.testSuiteRunId=b,l.commit=l.name,l.name=E,this.testSuiteRunInfo={appName:E,commitHash:l.commitHash,envName:l.name,branch:l.branch,testSuiteRunId:b,checksumRuntimeVersion:this.checksumRuntimeVersion},!0}catch(l){let d=`Error connecting to Checksum, the report will not be hosted - ${l.message}`;return this.runtimeTrace(d,"Test Suite Init Error"),this.log(d),this.setIsolatedMode(),!0}}setIsolatedMode(){this.testSuiteRunId=process.env.CHECKSUM_TEST_SUITE_ID||(0,KDr.randomUUID)(),this.isolationMode=!0,this.completeIndicators.upload=!0,eg.testRun.monitoring.debugAnalytics?this.testSuiteRunInfo=zun(this.checksumRuntimeVersion,this.testSuiteRunId):this.testSuiteRunInfo=Jun(this.checksumRuntimeVersion,this.testSuiteRunId)}async sendTestRunEnd(a){if(!this.isolationMode){B7("Sending test run end API request");try{let s="{}";try{s=JSON.stringify({...a,endedAt:Date.now()})}catch(l){this.testSuiteAnalytics.testSuiteError({error:`Error stringifying stats ${l.message}`}),this.log(`Error stringifying stats ${l.message}`,!0),B7("Error preparing test stats for API request")}B7("Sending test run end request",s),await this.updateTestRun(`${this.config.apiURL}/client-api/test-runs/${this.testSuiteRunId}`,"PATCH",s)}catch(s){return this.testSuiteAnalytics.testSuiteError({error:`Error sending test run end ${s.message}`}),this.log(`Error sending test run end ${s.message}`,!0),null}}}async sendUploadsComplete(){if(!this.isolationMode)try{await this.updateTestRun(`${this.config.apiURL}/client-api/test-runs/${this.testSuiteRunId}/uploads-completed`,"PATCH")}catch(a){this.testSuiteAnalytics.testSuiteError({error:`Error sending test run uploads complete - ${a.message}`}),this.log(`Error sending test run uploads complete - ${a.message}`,!0)}}async sendProcessingError(){if(!this.isolationMode)try{await this.updateTestRun(`${this.config.apiURL}/client-api/test-runs/${this.testSuiteRunId}/process-error`,"PATCH")}catch(a){this.testSuiteAnalytics.testSuiteError({error:`Error sending test run processing error - ${a.message}`}),this.log(`Error sending test run processing error - ${a.message}`,!0)}}async updateTestRun(a,s,l=void 0){let d=await fetch(a,{method:s,headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:this.config.apiKey},body:l});return B7("Received update test run response from url:",a),await this.logApiResponse(d),d}async logApiResponse(a){try{if(!a.ok){let{status:l,statusText:d}=a,g=await a.text();this.testSuiteAnalytics.testSuiteError({status:l,statusText:d,error:g});return}a.headers.get("Content-Type").includes("application/json")?a.json().then(l=>{B7("API Response:",l)}):a.text().then(l=>{B7("API Response:",l)})}catch(s){this.testSuiteAnalytics.testSuiteError({error:`Error logging API response - ${s.message}`})}}logTRMMessage(a){(Array.isArray(a)?a:[a]).forEach(s=>{B7("[trm]",s)})}};e(YDr,"TestsRunner");var Xrt=YDr;var XDr=class XDr extends IP{constructor(r,a=!1){super(r,a)}async run(r){switch(r){default:console.log(`
1702
1702
  Checksum CLI
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksum-ai/runtime",
3
- "version": "1.4.9-alpha",
3
+ "version": "1.4.11-alpha",
4
4
  "description": "Checksum.ai test runtime",
5
5
  "main": "index.js",
6
6
  "dependencies": {