@checksum-ai/runtime 1.2.11-alpha → 1.2.12-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 +1 -1
- package/cli.js +1 -1
- package/package.json +1 -1
- package/test-run-monitor.js +11 -11
package/.env
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
CHECKSUM_RUNTIME_BUILD_TIME=2025-08-
|
|
1
|
+
CHECKSUM_RUNTIME_BUILD_TIME=2025-08-24T13:40:37.610Z
|
package/cli.js
CHANGED
|
@@ -1607,7 +1607,7 @@ ${a.map(u=>[u.type,u.nestedLevel,this.getText(u.body)]).join(`,
|
|
|
1607
1607
|
${rJr}
|
|
1608
1608
|
${A}
|
|
1609
1609
|
${nJr}
|
|
1610
|
-
${(await u.getFormattedTestFileCode()).code}`)}loadVtgTestFileMirror(n){if(!n||!n.startsWith("/"))throw new Error("Currently vtg mode can only run with absolute path to file");let a=new h3e(n);return a.loadTestFromFile(),a}createActionJsonFileForExistingChecksumSpec(n,a){let u=n.testMirrors[0].translateStatementsToActions({mergeCustomCodeSteps:this.vtgSettingsService.getSettings().mergeCustomCodeSteps}),f=this.getActionJsonFilePath(a);(0,t$.writeFileSync)(f,JSON.stringify(u,null,2))}createFolderIfNotExists(n){return(0,t$.existsSync)(n)||(0,t$.mkdirSync)(n,{recursive:!0}),n}getSavePathForNewChecksumSpec(){return(0,Ule.join)(this.draftsFolderPath,"test.checksum.spec.ts")}getActionJsonFilePath(n){let a=this.getFileName(n).replace(".spec.ts",".json");return(0,Ule.join)(this.draftsFolderPath,a)}getEvalFilePath(n){let a=this.internalE2ETest?".eval.e2e.checksum.spec.ts":".eval.checksum.spec.ts";return(0,Ule.join)(this.draftsFolderPath,a)}getFileName(n){return n.split("/").pop()}};e(pvr,"VtgTestRunner");var H3t=pvr;var dvr=class dvr extends aP{constructor(a,u=!1,f=!1){super(a,u);this.vtgMode=f;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.logFilter={"upload-progress":{logEveryMS:1e3*30,lastLogTimestamp:0,logOnValueChange:!0,value:""}}}get replMode(){return this.getChecksumArg("repl")??!1}logMemoryUsage(a,u){let f=process.memoryUsage(),g=Math.round(f.heapUsed/1024/1024),A=Math.round(f.heapTotal/1024/1024),E=Math.round(f.external/1024/1024),D=Math.round(f.rss/1024/1024),F=`[Memory] ${a}: Heap: ${g}MB/${A}MB, External: ${E}MB, RSS: ${D}MB`;u&&(F+=` | Child Process: ${u.stage} - Active: ${u.activeAssets}, Completed: ${u.completedAssets}, Errored: ${u.erroredAssets}, Total: ${u.totalAssets}`),console.log(F)}async run(){if(console.log("Running without processing har and trace"),this.loadTracer(),this.validateAuthExists(),this.buildVolatileChecksumConfig(),this.vtgMode&&(this.config.options.hostReports=!1),!await this.getSession())return;this.testSuiteAnalytics=gFe.getInstance(this.testSuiteRunInfo,this.isolationMode),this.testSuiteAnalytics.genericEvent(`Project root found at ${this.projectRootDirectory}`,`Checksum root found at ${this.checksumRoot}`);let a={CHECKSUM_ROOT_FOLDER:this.checksumRoot,CHECKSUM_TEST_SUITE_INFO:JSON.stringify(this.testSuiteRunInfo)},u;try{u=await ow(this.startTestRunMonitor(this.testSuiteRunId),1e4,"test run monitor timeout"),a.CHECKSUM_UPLOAD_AGENT_PORT=u}catch{let E="Error starting test run monitor. Test results will not be available on checksum.";this.testSuiteAnalytics.testRunMonitorError({error:E}),this.log(E)}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 f=this.getNonChecksumArgs();this.vtgMode&&(await new H3t(this.getChecksumArg("id")||void 0,this.getChecksumArg("edit")||void 0,this.getChecksumArg("legacy")||!1,zy.vtg.isE2ETestMode,this.getChecksumArg("restore")||!1,this.checksumRoot,this.getInternalFilesDirPath()).initAndUpdateEnvAndPlaywrightArgs(a,f),zy.promptKillActivePlaywrightProcesses&&await this.promptKillActivePlaywrightProcesses()),this.replMode&&f.push("--debug");let g=`npx playwright test --config "${this.getPlaywrightConfigFilePath()}" ${f.map(A=>`"${A}"`).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(g,a),await this.execCmd(`node ${__dirname}/repl.js`,a)):(this.testSuiteAnalytics.testSuiteStart(),await this.execCmd(g,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 A,E;let a=e(D=>(eS("Using report folder",D),(0,gme.join)(D,"index.html")),"makeFilePath"),u,f="never";process.env.PLAYWRIGHT_HTML_OUTPUT_DIR&&(u=a(process.env.PLAYWRIGHT_HTML_OUTPUT_DIR));let g=(A=this.playwrightConfig)==null?void 0:A.reporter;if(g instanceof Array){let D=g.filter(F=>F instanceof Array&&F[0]==="html");if(!process.env.PLAYWRIGHT_HTML_OUTPUT_DIR){let F=D.find(P=>{var Q;return(Q=P[1])==null?void 0:Q.outputFolder});F&&(u=a((0,gme.join)(this.checksumRoot,F[1].outputFolder)))}for(let F of D){let P=(E=F[1])==null?void 0:E.open;if(P==="always"||P==="on-failure"){f=P;break}}}u||(zy.isRepoMode?u=a((0,gme.join)(zy.runtimeRoot,"playwright-report")):u=a((0,gme.join)(this.projectRootDirectory,"playwright-report"))),this.playwrightConfigOptions={openReportCriteria:f,reportPath:u}}sendReportUploadRequest(){let a=e(D=>{this.testSuiteAnalytics.testSuiteError({error:D}),this.log(D),this.completeIndicators.report=!0,this.testRunMonitorProcess.stdin.write("cli:report=false")},"makeError");if(!this.playwrightConfigOptions)return a("No playwright config options");let{reportPath:u,openReportCriteria:f}=this.playwrightConfigOptions;if(!(0,G3t.existsSync)(u))return a(`Could not find report file at ${u}`);eS("Sending report upload request",u);let g=this.saveMetadataToFile((0,gme.dirname)(u)),A={reportPath:u,pathToChecksumMetadata:g,openReportCriteria:f,didFail:this.didFail},E=Buffer.from(JSON.stringify(A)).toString("base64");this.testRunMonitorProcess.stdin.write(`cli:report=${E}`)}saveMetadataToFile(a){try{let u=(0,gme.join)(a,`checksum-metadata-${(0,fvr.randomUUID)()}.json`);return(0,G3t.writeFileSync)(u,JSON.stringify(this.playwrightIdToReportMetadata,null,2)),u}catch(u){let f=`Error saving metadata to file - ${u.message}`;this.testSuiteAnalytics.testSuiteError({error:f}),this.log(f);return}}startTestMonitorProcess(a){let f=[JSON.stringify({sessionId:a,apiURL:this.config.apiURL,apiKey:this.config.apiKey}),...this.isolationMode?["isolated"]:[]],g={command:"node",args:[(0,gme.join)(__dirname,"test-run-monitor.js"),...f]};return zy.isRepoMode&&(g.command="yarn",g.args=["test-run-monitor",...f]),Pan.spawn(g.command,g.args)}startTestRunMonitor(a){return new Promise(u=>{console.log("Starting test run monitor"),this.testRunMonitorProcess=this.startTestMonitorProcess(a),this.testRunMonitorProcess.stdout.on("data",f=>{let g=this.parseTRMMessages(f.toString().trim());if(g.length)for(let A of g){if(A.startsWith("trace")){this.logTRMMessage(A),this.handleTestRunMonitorTrace(A.substring("trace".length+1));continue}if(!A.startsWith("monitor")){this.logTRMMessage(A);continue}let E=e(()=>{let Q=A.substring("monitor".length+1),R=Q.indexOf("=");if(R===-1)return{key:Q,value:""};let[W,q]=[Q.substring(0,R),Q.substring(R+1)];return{key:W,value:q}},"getKeyAndValue"),{key:D,value:F}=E();if(!Object.values(ftr).includes(D)){this.logTRMMessage(`Received unknown monitor message: "${A}"`);continue}let P=D;this.logInterProcessEventMessage(P,F),D==="port"?u(F):this.handleTestRunMonitorMessage(P,F)}}),this.testRunMonitorProcess.on("exit",(f,g)=>{let A=`test run monitor process exited with code ${f} and signal ${g}`;this.testSuiteAnalytics.testRunMonitorError({error:A}),this.log(A)}),this.testRunMonitorProcess.stderr.on("data",f=>{let g=`TRM Error: ${f.toString().substring(0,300)}`;this.testSuiteAnalytics.testRunMonitorError({error:g}),this.log(g)}),this.testRunMonitorProcess.on("error",f=>{let g=`Error starting test run monitor: ${f.message}`;this.testSuiteAnalytics.testRunMonitorError({error:g}),this.log(g)})})}logInterProcessEventMessage(a,u){e(()=>{if(!this.logFilter[a])return!0;if(this.logFilter[a].logOnValueChange&&this.logFilter[a].value!==u)return this.logFilter[a].value=u,!0;if(this.logFilter[a].logEveryMS){let g=Date.now();if(g-this.logFilter[a].lastLogTimestamp>=this.logFilter[a].logEveryMS)return this.logFilter[a].lastLogTimestamp=g,!0}return!1},"shouldLog")()&&this.logTRMMessage(`Received monitor message: "${a}${u?`=${u}`:""}"`)}parseTRMMessages(a){let u=this.trmMessagesBuffer+a,f,g,A=e(()=>{f=u.indexOf("{trm}"),g=u.indexOf("{/trm}")},"findIndexes");A();let E=[];for(;f!==-1&&g!==-1&&g>f;){if(E.push(u.substring(f+"{trm}".length,g)),u=u.slice(g+"{/trm}".length).trim(),u.length&&!u.startsWith("{trm}"))return console.warn("Buffered data does not start with start delimiter",u),this.trmMessagesBuffer="",E;this.trmMessagesBuffer=u,A()}return E}setChecksumTestMetadata(a){let{retry:u,type:f,pwTestId:g}=a;this.playwrightIdToReportMetadata[g]||(this.playwrightIdToReportMetadata[g]={}),this.playwrightIdToReportMetadata[g][u]||(this.playwrightIdToReportMetadata[g][u]={}),this.playwrightIdToReportMetadata[g][u][f]=a}async handleTestRunMonitorTrace(a){let u=a.indexOf("="),[f,g]=u>-1?[a.substring(0,u),a.substring(u+1)]:[a,""];if(!Object.values(V6t).includes(f)){eS("Unknown trace event",f);return}try{let A=g?JSON.parse(g):{};switch(f){case"Upload Start":this.testSuiteAnalytics.uploadStart({filename:A.filename});break;case"Upload Complete":this.testSuiteAnalytics.uploadComplete({filename:A.filename});break;case"Upload Failed":this.testSuiteAnalytics.uploadFailed({filename:A.filename,error:A.error});break;case"Trace Processing Error":this.testSuiteAnalytics.traceProcessingError({error:A.error});break}}catch(A){eS(`Error parsing trace payload, ${A.message}`)}}async handleTestRunMonitorMessage(a,u){var f;switch(a){case"uploads-complete-with-errors":console.log("Error uploading test files to Checksum");try{let A=JSON.parse(u);this.testSuiteAnalytics.uploadsCompleteWithErrors(A)}catch{}this.sendProcessingError().then(()=>{this.completeIndicators.upload=!0});break;case"checksumTestMetadata":try{let A=JSON.parse(u);this.setChecksumTestMetadata(A)}catch(A){let E=`Error parsing test metadata event - ${A.message}`;this.testSuiteAnalytics.testSuiteError({error:E}),this.log(E)}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}let A=u.slice(0,u.indexOf(":"))==="true",E=u.slice(u.indexOf(":")+1),D=this.handleStats(E);if(this.testSuiteAnalytics.testSuiteEnd({passed:D.passed,failed:D.failed,bug:D.bug,total:((f=D.tests)==null?void 0:f.length)||0}),await this.sendTestRunEnd(D),this.completeIndicators.report=!0,A){let F=`${this.checksumAppUrl}/#/test-runs/${this.testSuiteRunId}`,P=`Checksum report URL: ${F}`,Q="*".repeat(P.length);console.log(`${Q}
|
|
1610
|
+
${(await u.getFormattedTestFileCode()).code}`)}loadVtgTestFileMirror(n){if(!n||!n.startsWith("/"))throw new Error("Currently vtg mode can only run with absolute path to file");let a=new h3e(n);return a.loadTestFromFile(),a}createActionJsonFileForExistingChecksumSpec(n,a){let u=n.testMirrors[0].translateStatementsToActions({mergeCustomCodeSteps:this.vtgSettingsService.getSettings().mergeCustomCodeSteps}),f=this.getActionJsonFilePath(a);(0,t$.writeFileSync)(f,JSON.stringify(u,null,2))}createFolderIfNotExists(n){return(0,t$.existsSync)(n)||(0,t$.mkdirSync)(n,{recursive:!0}),n}getSavePathForNewChecksumSpec(){return(0,Ule.join)(this.draftsFolderPath,"test.checksum.spec.ts")}getActionJsonFilePath(n){let a=this.getFileName(n).replace(".spec.ts",".json");return(0,Ule.join)(this.draftsFolderPath,a)}getEvalFilePath(n){let a=this.internalE2ETest?".eval.e2e.checksum.spec.ts":".eval.checksum.spec.ts";return(0,Ule.join)(this.draftsFolderPath,a)}getFileName(n){return n.split("/").pop()}};e(pvr,"VtgTestRunner");var H3t=pvr;var dvr=class dvr extends aP{constructor(a,u=!1,f=!1){super(a,u);this.vtgMode=f;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.logFilter={"upload-progress":{logEveryMS:1e3*30,lastLogTimestamp:0,logOnValueChange:!0,value:""}}}get replMode(){return this.getChecksumArg("repl")??!1}logMemoryUsage(a,u){let f=process.memoryUsage(),g=Math.round(f.heapUsed/1024/1024),A=Math.round(f.heapTotal/1024/1024),E=Math.round(f.external/1024/1024),D=Math.round(f.rss/1024/1024),F=`[Memory] ${a}: Heap: ${g}MB/${A}MB, External: ${E}MB, RSS: ${D}MB`;u&&(F+=` | Child Process: ${u.stage} - Active: ${u.activeAssets}, Completed: ${u.completedAssets}, Errored: ${u.erroredAssets}, Total: ${u.totalAssets}`),console.log(F)}async run(){if(console.log("Running with trace processing and cleanup"),this.loadTracer(),this.validateAuthExists(),this.buildVolatileChecksumConfig(),this.vtgMode&&(this.config.options.hostReports=!1),!await this.getSession())return;this.testSuiteAnalytics=gFe.getInstance(this.testSuiteRunInfo,this.isolationMode),this.testSuiteAnalytics.genericEvent(`Project root found at ${this.projectRootDirectory}`,`Checksum root found at ${this.checksumRoot}`);let a={CHECKSUM_ROOT_FOLDER:this.checksumRoot,CHECKSUM_TEST_SUITE_INFO:JSON.stringify(this.testSuiteRunInfo)},u;try{u=await ow(this.startTestRunMonitor(this.testSuiteRunId),1e4,"test run monitor timeout"),a.CHECKSUM_UPLOAD_AGENT_PORT=u}catch{let E="Error starting test run monitor. Test results will not be available on checksum.";this.testSuiteAnalytics.testRunMonitorError({error:E}),this.log(E)}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 f=this.getNonChecksumArgs();this.vtgMode&&(await new H3t(this.getChecksumArg("id")||void 0,this.getChecksumArg("edit")||void 0,this.getChecksumArg("legacy")||!1,zy.vtg.isE2ETestMode,this.getChecksumArg("restore")||!1,this.checksumRoot,this.getInternalFilesDirPath()).initAndUpdateEnvAndPlaywrightArgs(a,f),zy.promptKillActivePlaywrightProcesses&&await this.promptKillActivePlaywrightProcesses()),this.replMode&&f.push("--debug");let g=`npx playwright test --config "${this.getPlaywrightConfigFilePath()}" ${f.map(A=>`"${A}"`).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(g,a),await this.execCmd(`node ${__dirname}/repl.js`,a)):(this.testSuiteAnalytics.testSuiteStart(),await this.execCmd(g,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 A,E;let a=e(D=>(eS("Using report folder",D),(0,gme.join)(D,"index.html")),"makeFilePath"),u,f="never";process.env.PLAYWRIGHT_HTML_OUTPUT_DIR&&(u=a(process.env.PLAYWRIGHT_HTML_OUTPUT_DIR));let g=(A=this.playwrightConfig)==null?void 0:A.reporter;if(g instanceof Array){let D=g.filter(F=>F instanceof Array&&F[0]==="html");if(!process.env.PLAYWRIGHT_HTML_OUTPUT_DIR){let F=D.find(P=>{var Q;return(Q=P[1])==null?void 0:Q.outputFolder});F&&(u=a((0,gme.join)(this.checksumRoot,F[1].outputFolder)))}for(let F of D){let P=(E=F[1])==null?void 0:E.open;if(P==="always"||P==="on-failure"){f=P;break}}}u||(zy.isRepoMode?u=a((0,gme.join)(zy.runtimeRoot,"playwright-report")):u=a((0,gme.join)(this.projectRootDirectory,"playwright-report"))),this.playwrightConfigOptions={openReportCriteria:f,reportPath:u}}sendReportUploadRequest(){let a=e(D=>{this.testSuiteAnalytics.testSuiteError({error:D}),this.log(D),this.completeIndicators.report=!0,this.testRunMonitorProcess.stdin.write("cli:report=false")},"makeError");if(!this.playwrightConfigOptions)return a("No playwright config options");let{reportPath:u,openReportCriteria:f}=this.playwrightConfigOptions;if(!(0,G3t.existsSync)(u))return a(`Could not find report file at ${u}`);eS("Sending report upload request",u);let g=this.saveMetadataToFile((0,gme.dirname)(u)),A={reportPath:u,pathToChecksumMetadata:g,openReportCriteria:f,didFail:this.didFail},E=Buffer.from(JSON.stringify(A)).toString("base64");this.testRunMonitorProcess.stdin.write(`cli:report=${E}`)}saveMetadataToFile(a){try{let u=(0,gme.join)(a,`checksum-metadata-${(0,fvr.randomUUID)()}.json`);return(0,G3t.writeFileSync)(u,JSON.stringify(this.playwrightIdToReportMetadata,null,2)),u}catch(u){let f=`Error saving metadata to file - ${u.message}`;this.testSuiteAnalytics.testSuiteError({error:f}),this.log(f);return}}startTestMonitorProcess(a){let f=[JSON.stringify({sessionId:a,apiURL:this.config.apiURL,apiKey:this.config.apiKey}),...this.isolationMode?["isolated"]:[]],g={command:"node",args:[(0,gme.join)(__dirname,"test-run-monitor.js"),...f]};return zy.isRepoMode&&(g.command="yarn",g.args=["test-run-monitor",...f]),Pan.spawn(g.command,g.args)}startTestRunMonitor(a){return new Promise(u=>{console.log("Starting test run monitor"),this.testRunMonitorProcess=this.startTestMonitorProcess(a),this.testRunMonitorProcess.stdout.on("data",f=>{let g=this.parseTRMMessages(f.toString().trim());if(g.length)for(let A of g){if(A.startsWith("trace")){this.logTRMMessage(A),this.handleTestRunMonitorTrace(A.substring("trace".length+1));continue}if(!A.startsWith("monitor")){this.logTRMMessage(A);continue}let E=e(()=>{let Q=A.substring("monitor".length+1),R=Q.indexOf("=");if(R===-1)return{key:Q,value:""};let[W,q]=[Q.substring(0,R),Q.substring(R+1)];return{key:W,value:q}},"getKeyAndValue"),{key:D,value:F}=E();if(!Object.values(ftr).includes(D)){this.logTRMMessage(`Received unknown monitor message: "${A}"`);continue}let P=D;this.logInterProcessEventMessage(P,F),D==="port"?u(F):this.handleTestRunMonitorMessage(P,F)}}),this.testRunMonitorProcess.on("exit",(f,g)=>{let A=`test run monitor process exited with code ${f} and signal ${g}`;this.testSuiteAnalytics.testRunMonitorError({error:A}),this.log(A)}),this.testRunMonitorProcess.stderr.on("data",f=>{let g=`TRM Error: ${f.toString().substring(0,300)}`;this.testSuiteAnalytics.testRunMonitorError({error:g}),this.log(g)}),this.testRunMonitorProcess.on("error",f=>{let g=`Error starting test run monitor: ${f.message}`;this.testSuiteAnalytics.testRunMonitorError({error:g}),this.log(g)})})}logInterProcessEventMessage(a,u){e(()=>{if(!this.logFilter[a])return!0;if(this.logFilter[a].logOnValueChange&&this.logFilter[a].value!==u)return this.logFilter[a].value=u,!0;if(this.logFilter[a].logEveryMS){let g=Date.now();if(g-this.logFilter[a].lastLogTimestamp>=this.logFilter[a].logEveryMS)return this.logFilter[a].lastLogTimestamp=g,!0}return!1},"shouldLog")()&&this.logTRMMessage(`Received monitor message: "${a}${u?`=${u}`:""}"`)}parseTRMMessages(a){let u=this.trmMessagesBuffer+a,f,g,A=e(()=>{f=u.indexOf("{trm}"),g=u.indexOf("{/trm}")},"findIndexes");A();let E=[];for(;f!==-1&&g!==-1&&g>f;){if(E.push(u.substring(f+"{trm}".length,g)),u=u.slice(g+"{/trm}".length).trim(),u.length&&!u.startsWith("{trm}"))return console.warn("Buffered data does not start with start delimiter",u),this.trmMessagesBuffer="",E;this.trmMessagesBuffer=u,A()}return E}setChecksumTestMetadata(a){let{retry:u,type:f,pwTestId:g}=a;this.playwrightIdToReportMetadata[g]||(this.playwrightIdToReportMetadata[g]={}),this.playwrightIdToReportMetadata[g][u]||(this.playwrightIdToReportMetadata[g][u]={}),this.playwrightIdToReportMetadata[g][u][f]=a}async handleTestRunMonitorTrace(a){let u=a.indexOf("="),[f,g]=u>-1?[a.substring(0,u),a.substring(u+1)]:[a,""];if(!Object.values(V6t).includes(f)){eS("Unknown trace event",f);return}try{let A=g?JSON.parse(g):{};switch(f){case"Upload Start":this.testSuiteAnalytics.uploadStart({filename:A.filename});break;case"Upload Complete":this.testSuiteAnalytics.uploadComplete({filename:A.filename});break;case"Upload Failed":this.testSuiteAnalytics.uploadFailed({filename:A.filename,error:A.error});break;case"Trace Processing Error":this.testSuiteAnalytics.traceProcessingError({error:A.error});break}}catch(A){eS(`Error parsing trace payload, ${A.message}`)}}async handleTestRunMonitorMessage(a,u){var f;switch(a){case"uploads-complete-with-errors":console.log("Error uploading test files to Checksum");try{let A=JSON.parse(u);this.testSuiteAnalytics.uploadsCompleteWithErrors(A)}catch{}this.sendProcessingError().then(()=>{this.completeIndicators.upload=!0});break;case"checksumTestMetadata":try{let A=JSON.parse(u);this.setChecksumTestMetadata(A)}catch(A){let E=`Error parsing test metadata event - ${A.message}`;this.testSuiteAnalytics.testSuiteError({error:E}),this.log(E)}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}let A=u.slice(0,u.indexOf(":"))==="true",E=u.slice(u.indexOf(":")+1),D=this.handleStats(E);if(this.testSuiteAnalytics.testSuiteEnd({passed:D.passed,failed:D.failed,bug:D.bug,total:((f=D.tests)==null?void 0:f.length)||0}),await this.sendTestRunEnd(D),this.completeIndicators.report=!0,A){let F=`${this.checksumAppUrl}/#/test-runs/${this.testSuiteRunId}`,P=`Checksum report URL: ${F}`,Q="*".repeat(P.length);console.log(`${Q}
|
|
1611
1611
|
${P}
|
|
1612
1612
|
${Q}`),this.testSuiteAnalytics.reportComplete({stats:D,reportUrl:F})}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");break}case"upload-progress":{if(this.isolationMode)break;let A=parseInt(u);(A<this.uploadProgress||A>=this.uploadProgress+10||A===100&&this.uploadProgress!==100)&&(this.uploadProgress=A,console.log(`[ Uploads progress: ${this.uploadProgress}% ]`))}break;case"log":console.log(u);break;case"log-memory-usage":try{let A=JSON.parse(u);this.logMemoryUsage("Child Process Request",A)}catch(A){console.log(`Error parsing memory usage data: ${A.message}`)}break;case"trace":let g=u;if(!Object.values(V6t).includes(g))return;this.testSuiteAnalytics.genericEvent(g);break;case"playwrightConfig":try{this.playwrightConfig||(this.playwrightConfig=JSON.parse(u),this.testSuiteAnalytics.playwrightConfig({config:this.playwrightConfig}),this.loadPlaywrightConfigOptions())}catch(A){let E=`Error parsing playwright config - ${A.message}`;this.testSuiteAnalytics.playwrightConfigError({error:E}),this.log(E)}break;default:this.testSuiteAnalytics.testRunMonitorError({error:`Unhandled test run monitor message: ${a}=${u}`}),this.log(`Unhandled test run monitor message: ${a}=${u}`)}}handleStats(a){let u={};try{a&&a.length>0?(u=JSON.parse(a),u.tests=u.tests.map(f=>{let g=this.playwrightIdToReportMetadata[f.playwrightTestId];if(!g)return f;let A=!1,E=!1,D=[];return Object.keys(g??{}).forEach(F=>{var P;if(g[F]){let Q=g[F].autoRecoveryMetadata;A=Q!=null&&Q.data.autoRecoveryTriggered?!0:A,E=Q!=null&&Q.data.autoRecovered?!0:E;let R=g[F].autoRecoverySummaries;(P=R==null?void 0:R.data)!=null&&P.length&&D.push(...R.data)}}),{...f,autoRecovered:E,autoRecoveryTriggered:A,autoRecoverySummaries:D}})):(this.testSuiteAnalytics.testSuiteError({error:"No stats received from test run monitor"}),eS("No stats received from test run monitor"))}catch(f){this.testSuiteAnalytics.testSuiteError({error:`Error parsing stats - ${f.message}`}),this.log(`Error parsing stats - ${f.message}`)}return u}async handleCompleteMessage(){let a=Date.now(),u=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(f=>!this.completeIndicators[f]))eS(this.completeIndicators),--u===0&&(this.testSuiteAnalytics.completionStatus({stats:this.completeIndicators}),u=12),await _5(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,u;try{if(!this.config.options.hostReports)return this.setIsolatedMode(),!0;if(u=this.config.apiKey,!u||u==="<API key>"){let F="No API key found in checksum config - please set it in the config file - checksum.config.ts";return this.runtimeTrace(F,"Checksum Config Error"),this.log(F,!0),this.shutdown(1),!1}let f=await this.getEnvInfo(),g=JSON.stringify({...f,isHidden:!!this.config.options.hideReports}),A=await fetch(`${this.config.apiURL}/client-api/test-runs`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:u},body:g}),{uuid:E,appName:D}=await A.json();return this.testSuiteRunId=E,f.commit=f.name,f.name=D,this.testSuiteRunInfo={appName:D,commitHash:f.commitHash,envName:f.name,branch:f.branch,testSuiteRunId:E,checksumRuntimeVersion:this.checksumRuntimeVersion},!0}catch(f){let g=`Error connecting to Checksum, the report will not be hosted - ${f.message}`;return this.runtimeTrace(g,"Test Suite Init Error"),this.log(g),this.setIsolatedMode(),!0}}setIsolatedMode(){this.testSuiteRunId=process.env.CHECKSUM_TEST_SUITE_ID||(0,fvr.randomUUID)(),this.isolationMode=!0,this.completeIndicators.upload=!0,zy.testRun.monitoring.segment.debugAnalytics?this.testSuiteRunInfo=XVr(this.checksumRuntimeVersion,this.testSuiteRunId):this.testSuiteRunInfo=YVr(this.checksumRuntimeVersion,this.testSuiteRunId)}async sendTestRunEnd(a){if(!this.isolationMode)try{let u="{}";try{u=JSON.stringify({...a,endedAt:Date.now()})}catch(f){this.testSuiteAnalytics.testSuiteError({error:`Error stringifying stats ${f.message}`}),this.log(`Error stringifying stats ${f.message}`,!0)}await this.updateTestRun(`${this.config.apiURL}/client-api/test-runs/${this.testSuiteRunId}`,"PATCH",u)}catch(u){return this.testSuiteAnalytics.testSuiteError({error:`Error sending test run end ${u.message}`}),this.log(`Error sending test run end ${u.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,u,f=void 0){let g=await fetch(a,{method:u,headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:this.config.apiKey},body:f});return eS("Received update test run response from url:",a),await this.logApiResponse(g),g}async logApiResponse(a){try{if(!a.ok){let{status:f,statusText:g}=a,A=await a.text();this.testSuiteAnalytics.testSuiteError({status:f,statusText:g,error:A});return}a.headers.get("Content-Type").includes("application/json")?a.json().then(f=>{eS("API Response:",f)}):a.text().then(f=>{eS("API Response:",f)})}catch(u){this.testSuiteAnalytics.testSuiteError({error:`Error logging API response - ${u.message}`})}}logTRMMessage(a){(Array.isArray(a)?a:[a]).forEach(u=>{eS("[trm]",u)})}};e(dvr,"TestsRunner");var qXe=dvr;var _vr=class _vr extends aP{constructor(n,a=!1){super(n,a)}async run(n){switch(n){default:console.log(`
|
|
1613
1613
|
Checksum CLI
|