@checksum-ai/runtime 1.0.17 → 1.0.19

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.
@@ -33,14 +33,14 @@ export default getChecksumConfig({
33
33
 
34
34
  options: {
35
35
  /**
36
- * Whether to fallback to ESRA if the action selector is not found
36
+ * Whether to use Checksum Smart Selector when trying to locate elements
37
37
  */
38
- actionsESRAfallback: true,
38
+ useChecksumSelectors: true,
39
39
 
40
40
  /**
41
- * Whether to use LLM fallback if action selector is not found
41
+ * Whether to use Checksum AI when trying to locate elements
42
42
  */
43
- actionsLLMFallback: true,
43
+ useChecksumAI: true,
44
44
 
45
45
  /**
46
46
  * Whether to use mock API data when running your tests
package/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- var m=Object.create;var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var k=(c,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!y.call(c,o)&&o!==e&&u(c,o,{get:()=>t[o],enumerable:!(s=f(t,o))||s.enumerable});return c};var P=(c,t,e)=>(e=c!=null?m(w(c)):{},k(t||!c||!c.__esModule?u(e,"default",{value:c,enumerable:!0}):e,c));var n=require("fs"),l=P(require("child_process")),r=require("path");var d="checksum";var g=class{constructor(){this.UPLOAD_AGENT_PATH=(0,r.join)(__dirname,"upload-agent.js");this.CHECKSUM_API_URL="http://localhost:3000";this.didFail=!1;this.mock=!0;this.completeIndicators={upload:!1,tests:!1,report:!1};this.guardReturn=async(t,e=1e3,s="action hang guard timed out")=>{let o="guard-timed-out",i=async()=>(await this.awaitSleep(e+1e3),o),a=await Promise.race([t,i()]);if(typeof a=="string"&&a===o)throw new Error(s);return a};this.awaitSleep=t=>new Promise(e=>setTimeout(e,t))}async execute(){switch(process.argv.find(t=>t==="--help"||t==="-h")&&(await this.printHelp(process.argv[2]),process.exit(0)),process.argv[2]){case"init":this.install();break;case"test":await this.test(process.argv.slice(3));break;case"show-report":this.showReport(process.argv.slice(3));break;default:await this.printHelp()}process.exit(0)}async execCmd(t){let e=await l.spawn(t,{shell:!0,stdio:"inherit"});return new Promise((o,i)=>{e.on("exit",a=>{a===0?o(!0):i(new Error(`Checsum failed execution with code: ${a} `))})})}async getCmdOutput(t){return new Promise(function(e,s){l.exec(t,(o,i,a)=>{if(o){s(`Error executing command: ${o.message}`);return}e(i)})})}async printHelp(t){switch(t){default:console.log(`
1
+ var m=Object.create;var p=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var k=(c,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!y.call(c,o)&&o!==e&&p(c,o,{get:()=>t[o],enumerable:!(s=f(t,o))||s.enumerable});return c};var P=(c,t,e)=>(e=c!=null?m(w(c)):{},k(t||!c||!c.__esModule?p(e,"default",{value:c,enumerable:!0}):e,c));var n=require("fs"),l=P(require("child_process")),r=require("path");var d="checksum";var g=class{constructor(){this.UPLOAD_AGENT_PATH=(0,r.join)(__dirname,"upload-agent.js");this.CHECKSUM_API_URL="http://localhost:3000";this.didFail=!1;this.mock=!0;this.completeIndicators={upload:!1,tests:!1,report:!1};this.guardReturn=async(t,e=1e3,s="action hang guard timed out")=>{let o="guard-timed-out",i=async()=>(await this.awaitSleep(e+1e3),o),a=await Promise.race([t,i()]);if(typeof a=="string"&&a===o)throw new Error(s);return a};this.awaitSleep=t=>new Promise(e=>setTimeout(e,t))}async execute(){var t;switch(process.argv[2]){case"init":this.install();break;case"test":if(((t=process.argv)==null?void 0:t[3])==="--help"){await this.printHelp("test");break}await this.test(process.argv.slice(3));break;case"show-report":this.showReport(process.argv.slice(3));break;default:await this.printHelp()}process.exit(0)}async execCmd(t){let e=await l.spawn(t,{shell:!0,stdio:"inherit"});return new Promise((o,i)=>{e.on("exit",a=>{a===0?o(!0):i(new Error(`Checsum failed execution with code: ${a} `))})})}async getCmdOutput(t){return new Promise(function(e,s){l.exec(t,(o,i,a)=>{if(o){s(`Error executing command: ${o.message}`);return}e(i)})})}async printHelp(t){switch(t){default:console.log(`
2
2
  Checksum CLI
3
3
  Usage: checksum [command] [options]
4
4
 
@@ -10,7 +10,7 @@ show-report [options] [report] show HTML report
10
10
  `);break;case"test":try{let e="npx playwright test --help",s=(await this.getCmdOutput(e)).replace(/npx playwright/g,"yarn checksum").split(`
11
11
  `);s.splice(5,0," --checksum-config=<config> Checksum configuration in JSON format").join(`
12
12
  `),console.log(s.join(`
13
- `))}catch(e){console.log("Error",e.message)}break;case"show-report":try{let e="npx playwright show-report --help",s=(await this.getCmdOutput(e)).replace(/npx playwright/g,"yarn checksum");console.log(s)}catch(e){console.log("Error",e.message)}break}}async showReport(t){let e=`npx playwright show-report ${t.join(" ")}`;try{await this.execCmd(e)}catch(s){console.log("Error showing report",s.message)}}async test(t){t=this.getChecksumConfigFromCommand(t),this.setChecksumConfig(),await this.getSession();let e;try{let{uuid:o,uploadURL:i}=this.testSession;e=await this.guardReturn(this.startUploadAgent(o,i),1e4,"Upload agent timeout")}catch{console.log("Error starting upload agent. Test results will not be available on checksum.")}this.buildVolatileConfig();let s=`${e?`CHECKSUM_UPLOAD_AGENT_PORT=${e} `:""} PWDEBUG=console npx playwright test --config ${this.getPlaywrightConfigFile()} ${t.join(" ")}`;try{await this.execCmd(s)}catch(o){this.didFail=!0,console.log("Error during test",o.message)}finally{let o=this.getPlaywrightReportPath();(0,n.existsSync)(o)?this.uploadAgent.stdin.write(`cli:report=${o}`):console.log(`Could not find report file at ${o}`),this.completeIndicators.tests=!0,await this.handleCompleteMessage()}}getPlaywrightReportPath(){var o,i;let t=(0,r.join)(process.cwd(),"playwright-report"),e=require(this.getPlaywrightConfigFile()),{reporter:s}=e;return s instanceof Array&&s.length>1&&((o=s[1])!=null&&o.outputFolder)&&(t=(i=s[1])==null?void 0:i.outputFolder),process.env.PLAYWRIGHT_HTML_REPORT&&(t=process.env.PLAYWRIGHT_HTML_REPORT),(0,r.join)(t,"index.html")}getPlaywrightConfigFile(){return(0,r.join)(this.getRootDirPath(),"playwright.config.ts")}startUploadAgent(t,e){return new Promise((s,o)=>{console.log("Starting upload agent"),this.uploadAgent=l.spawn("node",[this.UPLOAD_AGENT_PATH,JSON.stringify({sessionId:t,checksumApiURL:this.CHECKSUM_API_URL,apiKey:this.config.apiKey}),...this.mock?["mock"]:[]]),this.uploadAgent.stdout.on("data",i=>{let a=i.toString().trim();if(!a.startsWith("upag:"))return;let[p,h]=a.substring(5).split("=");p==="port"?(console.log("Received port from upload agent",h),s(h)):this.handleUploadAgentMessage(p,h)}),this.uploadAgent.on("exit",(i,a)=>{console.log(`upload agent process exited with code ${i} and signal ${a}`)}),this.uploadAgent.on("error",i=>{console.error(`Error starting upload agent: ${i.message}`)})})}async handleUploadAgentMessage(t,e){switch(t){case"complete":this.sendUploadsComplete().then(()=>{this.completeIndicators.upload=!0});break;case"report-uploaded":let s=await this.sendTestrunEnd();this.completeIndicators.report=!0,s&&console.log(`*******************
13
+ `))}catch(e){console.log("Error",e.message)}break}}async showReport(t){let e=`npx playwright show-report ${t.join(" ")}`;try{await this.execCmd(e)}catch(s){console.log("Error showing report",s.message)}}async test(t){t=this.getChecksumConfigFromCommand(t),this.setChecksumConfig(),await this.getSession();let e;try{let{uuid:o,uploadURL:i}=this.testSession;e=await this.guardReturn(this.startUploadAgent(o,i),1e4,"Upload agent timeout")}catch{console.log("Error starting upload agent. Test results will not be available on checksum.")}this.buildVolatileConfig();let s=`${e?`CHECKSUM_UPLOAD_AGENT_PORT=${e} `:""} PWDEBUG=console npx playwright test --config ${this.getPlaywrightConfigFile()} ${t.join(" ")}`;try{await this.execCmd(s)}catch(o){this.didFail=!0,console.log("Error during test",o.message)}finally{let o=this.getPlaywrightReportPath();(0,n.existsSync)(o)?this.uploadAgent.stdin.write(`cli:report=${o}`):console.log(`Could not find report file at ${o}`),this.completeIndicators.tests=!0,await this.handleCompleteMessage()}}getPlaywrightReportPath(){var o,i;let t=(0,r.join)(process.cwd(),"playwright-report"),e=require(this.getPlaywrightConfigFile()),{reporter:s}=e;return s instanceof Array&&s.length>1&&((o=s[1])!=null&&o.outputFolder)&&(t=(i=s[1])==null?void 0:i.outputFolder),process.env.PLAYWRIGHT_HTML_REPORT&&(t=process.env.PLAYWRIGHT_HTML_REPORT),(0,r.join)(t,"index.html")}getPlaywrightConfigFile(){return(0,r.join)(this.getRootDirPath(),"playwright.config.ts")}startUploadAgent(t,e){return new Promise((s,o)=>{console.log("Starting upload agent"),this.uploadAgent=l.spawn("node",[this.UPLOAD_AGENT_PATH,JSON.stringify({sessionId:t,checksumApiURL:this.CHECKSUM_API_URL,apiKey:this.config.apiKey}),...this.mock?["mock"]:[]]),this.uploadAgent.stdout.on("data",i=>{let a=i.toString().trim();if(!a.startsWith("upag:"))return;let[u,h]=a.substring(5).split("=");u==="port"?(console.log("Received port from upload agent",h),s(h)):this.handleUploadAgentMessage(u,h)}),this.uploadAgent.on("exit",(i,a)=>{console.log(`upload agent process exited with code ${i} and signal ${a}`)}),this.uploadAgent.on("error",i=>{console.error(`Error starting upload agent: ${i.message}`)})})}async handleUploadAgentMessage(t,e){switch(t){case"complete":this.sendUploadsComplete().then(()=>{this.completeIndicators.upload=!0});break;case"report-uploaded":let s=await this.sendTestrunEnd();this.completeIndicators.report=!0,s&&console.log(`*******************
14
14
  * Checksum report URL: ${s}
15
15
  *******************`);break;default:console.warn(`Unhandled upload agent message: ${t}=${e}`)}}async handleCompleteMessage(){for(;;)Object.keys(this.completeIndicators).find(t=>!this.completeIndicators[t])?await this.awaitSleep(1e3):(console.log("Tests complete"),this.shutdown(this.didFail?1:0))}shutdown(t=0){this.cleanup(),process.exit(t)}buildVolatileConfig(){if(!this.volatileChecksumConfig)return;let t=this.getVolatileConfigPath(),e=`
16
16
  import { RunMode, getChecksumConfig } from "@checksum-ai/runtime";
package/index.d.ts CHANGED
@@ -15,13 +15,13 @@ export enum RunMode {
15
15
 
16
16
  export type RuntimeOptions = {
17
17
  /**
18
- * fallback to ESRA if the action selector is not found
18
+ * Whether to use Checksum Smart Selector when trying to locate elements
19
19
  */
20
- actionsESRAfallback: boolean;
20
+ useChecksumSelectors: boolean;
21
21
  /**
22
- * use LLM fallback if action selector is not found
22
+ * Whether to use Checksum AI when trying to locate elements
23
23
  */
24
- actionsLLMFallback: boolean;
24
+ useChecksumAI: boolean;
25
25
  /**
26
26
  * add new assertions
27
27
  */