@checksum-ai/runtime 2.0.4 → 2.0.5-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/cli.js CHANGED
@@ -1692,7 +1692,7 @@ ${a.map(s=>[s.type,s.nestedLevel,this.getText(s.body)]).join(`,
1692
1692
  }
1693
1693
  `}e(y2n,"wrapCodeWithConsoleOverride");var _VtgEvaluatorService=class _VtgEvaluatorService{constructor(i,r,a,s,l){this.variableStoreService=i;this.settingsService=r;this.vtgTestFileMode=a;this.livePage=s;this.port=l;this.pendingPromises={};this.onExecutionResponse=e(async(i,r)=>{let{id:a,err:s,result:l}=i;this.pendingPromises[a]&&(s?this.pendingPromises[a].reject(this.deserializeError(s)):this.pendingPromises[a].resolve(l),delete this.pendingPromises[a])},"onExecutionResponse");this.listenerBody=e(async({vtg})=>{await vtg.eval(async(code,callback)=>{try{callback(null,await eval(`(async () => {
1694
1694
  ${code}
1695
- })()`))}catch(i){callback(i,null)}})},"listenerBody");this.messageParser=new F5t(this.onExecutionResponse),this.variableTransformer=new P5t}setPage(i){this.page=i,eg.vtg.isSeparateProcess&&this.createClient()}createClient(){this.client=(0,v2n.createConnection)({port:this.port},async()=>{}),this.client.on("data",i=>{this.messageParser.onMessage(this.client,i)}),this.client.on("error",i=>{VA.error("Error in evaluator service:",i)})}async getLocator(i,r){let a=await this.execute(i);return r.locator(a._selector)}async getElementHandle(i,r){let a=await this.execute(i);return r.locator(a._selector).elementHandle()}async evaluate(i){return this.execute(i)}async execute(i,r={},a={},{overrideLogs:s=!0,stepId:l="unknown"}={}){let d=i;try{d=fLe.transpileModule(d,{compilerOptions:{target:fLe.ScriptTarget.ESNext,module:fLe.ModuleKind.ESNext}}).outputText}catch(g){VA.warning("Failed to transpile code",g)}if(this.settingsService.getSettings().useVariableTransformation)try{d=this.variableTransformer.transformVariables(d)}catch(g){VA.warning("Failed to transform variables",g)}return s&&(d=y2n(d,{stepId:l})),this.vtgTestFileMode?this.executeInPlaywrightTest(d,r,a,g=>{s&&this.sendExecutionErrorToFELogger(g,l)}):this.executeOnLive(d,r)}sendExecutionErrorToFELogger(i,r){try{this.livePage.evaluate(a=>{window.checksumSendMessage("vtg",{type:"execution-console-event",data:a})},{level:"error",args:[i],timestamp:new Date(new Date().getTime()-new Date().getTimezoneOffset()*6e4).toISOString(),stepId:r,source:"BE",pageId:"unknown"}).catch(a=>{VA.warning("Error in evaluator service performing sendExecutionErrorToFELogger evaluate",a)})}catch(a){VA.warning("Error in evaluator service triggering sendExecutionErrorToFELogger",a)}}deserializeError(i){let r=typeof i=="string"?JSON.parse(i):i,a=new Error(r.message);a.name=r.name||"Error",a.stack=r.stack;for(let s of Object.keys(r))["name","message","stack"].includes(s)||(a[s]=r[s]);return a}get vtgContext(){return{page:this.page,vs:this.variableStoreService.variableStore,expect:Ttt.expect,checksumAI:e((i,r)=>r(),"checksumAI")}}async executeOnLive(i,r={}){let a={...this.vtgContext,...r},s=this.wrapCodeInContext(i,a);return await(0,eval)(s)(a)}wrapCodeInContext(i,r){return`(async ({${Object.keys(r).join(", ")}}) => { ${i} })`}async executeInPlaywrightTest(i,r={},a={},s){return new Promise((l,d)=>{if(eg.vtg.isSeparateProcess){if(!this.client){d(new Error("Client not connected"));return}let g=(0,x2n.randomUUID)();this.pendingPromises[g]={resolve:l,reject:d};let b={id:g,code:i,options:a};this.client.write(this.messageParser.makeMessage(JSON.stringify(b)))}else{let g=r?this.wrapCodeInContext(i,r)+"(context)":i;if(!this.listener)return;this.listener(g,r,(b,E)=>{b?(d(b),s==null||s(b)):l(E)})}})}async listenForExecution(i){return new Promise(r=>{this.resolveEvaluator=r,this.listener=i})}stopListening(){var i;(i=this.resolveEvaluator)==null||i.call(this)}};e(_VtgEvaluatorService,"VtgEvaluatorService");var N3r=_VtgEvaluatorService;var mRi={Playwright:[{type:"File",value:["node_modules/playwright-core/types/types.d.ts","node_modules/@playwright/test/node_modules/playwright-core/types/types.d.ts"],moduleName:"playwright-core"}],PlaywrightTest:[{type:"File",value:["node_modules/playwright/types/test.d.ts","node_modules/@playwright/test/node_modules/playwright/types/test.d.ts"],moduleName:"@playwright/test"}],Checksum:[{type:"File",value:"node_modules/@checksum-ai/runtime/index.d.ts",moduleName:"@checksum-ai/runtime"},{type:"Inline",value:"import type { IChecksumPage as CSPage, IChecksumExpect as CSExpect, ChecksumAI, IVariableStore, getLogin } from '@checksum-ai/runtime';declare global {interface IChecksumPage extends CSPage {};const page:IChecksumPage;const expect: CSExpect;const checksumAI: ChecksumAI;const login: ReturnType<typeof getLogin>}"}]};var wwe=class wwe{constructor(){this.cache=new Map}static getInstance(){return wwe.instance||(wwe.instance=new wwe),wwe.instance}get(r){return this.cache.get(r)}set(r,a){this.cache.set(r,a)}delete(r){this.cache.delete(r)}clear(){this.cache.clear()}};e(wwe,"InMemoryCache");var O3r=wwe;z5t();zvn();Xvn();o1e();var VDr=class VDr{constructor(r,a,s,l,d,g,b,E){this.newStoryId=r;this.editedFilePath=a;this.isLegacyMode=s;this.internalE2ETest=l;this.restoreFromAutoSave=d;this.checksumRoot=g;this.checksumConfig=b;this.isEditMode=!!this.editedFilePath,this.vtgInternalFilesDir=(0,hfe.join)(E,"vtg"),this.vtgSettingsService=new Brt(this.checksumRoot,new Ett(this.checksumConfig),E)}async initAndUpdateEnvAndPlaywrightArgs(r,a){if(r.CHECKSUM_VTG_INTERNAL_FILES_DIR=this.vtgInternalFilesDir,this.draftsFolderPath=(0,hfe.join)(this.vtgInternalFilesDir,this.internalE2ETest?"e2e":"drafts"),this.createFolderIfNotExists(this.draftsFolderPath),r.CHECKSUM_DRAFT_FOLDER_PATH=this.draftsFolderPath,this.isLegacyMode)return;a.unshift("--reporter=line"),r.CHECKSUM_VTG_TEST_FILE_MODE="true",this.isEditMode?r.CHECKSUM_VTG_TEST_FILE_EDIT_MODE="true":r.CHECKSUM_VTG_STORY_ID=this.newStoryId,r.PW_TEST_HTML_REPORT_OPEN="never";let s;this.isEditMode||((0,PK.writeFileSync)(this.getSavePathForNewChecksumSpec(),await vfn({body:"",testFunctionParams:["page","vs"],storyId:this.newStoryId})),this.editedFilePath=this.getSavePathForNewChecksumSpec()),this.copyCustomerEngUtils();let l=this.loadVtgTestFileMirror(this.editedFilePath);this.isEditMode&&!this.restoreFromAutoSave&&this.createActionJsonFileForExistingChecksumSpec(l,this.editedFilePath),await this.createEvalFileForExistingChecksumSpec(l,this.editedFilePath),s={mode:this.isEditMode?"edit":"start",actionsJsonFilePath:this.isEditMode&&!this.restoreFromAutoSave?this.getActionJsonFilePath(this.editedFilePath):void 0,title:l.testMirrors[0].title,internalTestId:l.testMirrors[0].internalTestId,storyId:l.testMirrors[0].storyId,evalFilePath:this.getEvalFilePath(this.editedFilePath),sourceFilePath:this.editedFilePath,restoreFromAutoSave:this.restoreFromAutoSave},r.CHECKSUM_VTG_TEST_FILE_RUN_CONFIG=JSON.stringify(s),a.push(this.getEvalFilePath(this.isEditMode?this.editedFilePath:void 0))}copyCustomerEngUtils(){let r=E6t(this.checksumRoot,10);if(!r){console.warn("Customer engineering repository was not found, using REPL will not be possible.");return}let a=(0,hfe.join)(r,eg.vtg.customerEngRepoInternalUtilsRelativePath);if(!(0,PK.existsSync)(a)){console.warn(`Internal utils file not found: ${a}, skipping copy.`);return}(0,PK.copyFileSync)(a,this.checksumAiInternalUtilsPath)}get checksumAiInternalUtilsPath(){return(0,hfe.join)(this.vtgInternalFilesDir,"checksum-ai-utils.ts")}async createEvalFileForExistingChecksumSpec(r,a){let s=new btt(r.sourceFile),l=y7r();s.transformSourceFile([new Ptt(a,l,{filterOutChecksumImports:!0}),new stt(a),new Ftt(a,l,{newRequireIdentifier:"checksumHotRequire",extraImportArguments:[$Dr.default.factory.createIdentifier("__filename")]}),new ott(r.sourceFile,r.testMirrors.map(b=>b.testBody),g7r(this.internalE2ETest?Gun:Hun),["page","vs","vtg"]),new B8t($Dr.default.NodeFlags.Let,!0)]);let d=this.getEvalFilePath(a);(0,PK.mkdirSync)((0,hfe.dirname)(d),{recursive:!0});let g=(0,PK.existsSync)(this.checksumAiInternalUtilsPath)?`globalThis.repl = require("${this.checksumAiInternalUtilsPath}").repl;`:"";(0,PK.writeFileSync)(d,`${this.internalE2ETest?'import { testingFunc } from "../../test.ts";':""}
1695
+ })()`))}catch(i){callback(i,null)}})},"listenerBody");this.messageParser=new F5t(this.onExecutionResponse),this.variableTransformer=new P5t}setPage(i){this.page=i,eg.vtg.isSeparateProcess&&this.createClient()}createClient(){this.client=(0,v2n.createConnection)({port:this.port},async()=>{}),this.client.on("data",i=>{this.messageParser.onMessage(this.client,i)}),this.client.on("error",i=>{VA.error("Error in evaluator service:",i)})}async getLocator(i,r){let a=await this.execute(i);return r.locator(a._selector)}async getElementHandle(i,r){let a=await this.execute(i);return r.locator(a._selector).elementHandle()}async evaluate(i){return this.execute(i)}async execute(i,r={},a={},{overrideLogs:s=!0,stepId:l="unknown"}={}){let d=i;try{d=fLe.transpileModule(d,{compilerOptions:{target:fLe.ScriptTarget.ESNext,module:fLe.ModuleKind.ESNext}}).outputText}catch(g){VA.warning("Failed to transpile code",g)}if(this.settingsService.getSettings().useVariableTransformation)try{d=this.variableTransformer.transformVariables(d)}catch(g){VA.warning("Failed to transform variables",g)}return s&&(d=y2n(d,{stepId:l})),this.vtgTestFileMode?this.executeInPlaywrightTest(d,r,a,g=>{s&&this.sendExecutionErrorToFELogger(g,l)}):this.executeOnLive(d,r)}sendExecutionErrorToFELogger(i,r){try{this.livePage.evaluate(a=>{window.checksumSendMessage("vtg",{type:"execution-console-event",data:a})},{level:"error",args:[i],timestamp:new Date(new Date().getTime()-new Date().getTimezoneOffset()*6e4).toISOString(),stepId:r,source:"BE",pageId:"unknown"}).catch(a=>{VA.warning("Error in evaluator service performing sendExecutionErrorToFELogger evaluate",a)})}catch(a){VA.warning("Error in evaluator service triggering sendExecutionErrorToFELogger",a)}}deserializeError(i){let r=typeof i=="string"?JSON.parse(i):i,a=new Error(r.message);a.name=r.name||"Error",a.stack=r.stack;for(let s of Object.keys(r))["name","message","stack"].includes(s)||(a[s]=r[s]);return a}get vtgContext(){return{page:this.page,vs:this.variableStoreService.variableStore,expect:Ttt.expect,checksumAI:e((i,r)=>r(),"checksumAI")}}async executeOnLive(i,r={}){let a={...this.vtgContext,...r},s=this.wrapCodeInContext(i,a);return await(0,eval)(s)(a)}wrapCodeInContext(i,r){return`(async ({${Object.keys(r).join(", ")}}) => { ${i} })`}async executeInPlaywrightTest(i,r={},a={},s){return new Promise((l,d)=>{if(eg.vtg.isSeparateProcess){if(!this.client){d(new Error("Client not connected"));return}let g=(0,x2n.randomUUID)();this.pendingPromises[g]={resolve:l,reject:d};let b={id:g,code:i,options:a};this.client.write(this.messageParser.makeMessage(JSON.stringify(b)))}else{let g=r?this.wrapCodeInContext(i,r)+"(context)":i;if(!this.listener)return;this.listener(g,r,(b,E)=>{b?(d(b),s==null||s(b)):l(E)})}})}async listenForExecution(i){return new Promise(r=>{this.resolveEvaluator=r,this.listener=i})}stopListening(){var i;(i=this.resolveEvaluator)==null||i.call(this)}};e(_VtgEvaluatorService,"VtgEvaluatorService");var N3r=_VtgEvaluatorService;var mRi={Playwright:[{type:"File",value:["node_modules/playwright-core/types/types.d.ts","node_modules/@playwright/test/node_modules/playwright-core/types/types.d.ts"],moduleName:"playwright-core"}],PlaywrightTest:[{type:"File",value:["node_modules/playwright/types/test.d.ts","node_modules/@playwright/test/node_modules/playwright/types/test.d.ts"],moduleName:"@playwright/test"}],Checksum:[{type:"File",value:"node_modules/@checksum-ai/runtime/index.d.ts",moduleName:"@checksum-ai/runtime"},{type:"Inline",value:"import type { IChecksumPage as CSPage, IChecksumExpect as CSExpect, ChecksumAI, IVariableStore, getLogin } from '@checksum-ai/runtime';declare global {interface IChecksumPage extends CSPage {};const page:IChecksumPage;const expect: CSExpect;const checksumAI: ChecksumAI;const login: ReturnType<typeof getLogin>}"}]};var wwe=class wwe{constructor(){this.cache=new Map}static getInstance(){return wwe.instance||(wwe.instance=new wwe),wwe.instance}get(r){return this.cache.get(r)}set(r,a){this.cache.set(r,a)}delete(r){this.cache.delete(r)}clear(){this.cache.clear()}};e(wwe,"InMemoryCache");var O3r=wwe;z5t();zvn();Xvn();o1e();var VDr=class VDr{constructor(r,a,s,l,d,g,b,E){this.newStoryId=r;this.editedFilePath=a;this.isLegacyMode=s;this.internalE2ETest=l;this.restoreFromAutoSave=d;this.checksumRoot=g;this.checksumConfig=b;this.isEditMode=!!this.editedFilePath,this.vtgInternalFilesDir=(0,hfe.join)(E,"vtg"),this.vtgSettingsService=new Brt(this.checksumRoot,new Ett(this.checksumConfig),E)}async initAndUpdateEnvAndPlaywrightArgs(r,a){if(r.CHECKSUM_VTG_INTERNAL_FILES_DIR=this.vtgInternalFilesDir,this.draftsFolderPath=(0,hfe.join)(this.vtgInternalFilesDir,this.internalE2ETest?"e2e":"drafts"),this.createFolderIfNotExists(this.draftsFolderPath),r.CHECKSUM_DRAFT_FOLDER_PATH=this.draftsFolderPath,this.isLegacyMode)return;a.unshift("--reporter=line"),r.CHECKSUM_VTG_TEST_FILE_MODE="true",this.isEditMode?r.CHECKSUM_VTG_TEST_FILE_EDIT_MODE="true":r.CHECKSUM_VTG_STORY_ID=this.newStoryId,r.PW_TEST_HTML_REPORT_OPEN="never";let s;this.isEditMode||((0,PK.writeFileSync)(this.getSavePathForNewChecksumSpec(),await vfn({body:"",testFunctionParams:["page","vs"],storyId:this.newStoryId})),this.editedFilePath=this.getSavePathForNewChecksumSpec()),this.copyCustomerEngUtils();let l=this.loadVtgTestFileMirror(this.editedFilePath);this.isEditMode&&!this.restoreFromAutoSave&&this.createActionJsonFileForExistingChecksumSpec(l,this.editedFilePath),await this.createEvalFileForExistingChecksumSpec(l,this.editedFilePath),s={mode:this.isEditMode?"edit":"start",actionsJsonFilePath:this.isEditMode&&!this.restoreFromAutoSave?this.getActionJsonFilePath(this.editedFilePath):void 0,title:l.testMirrors[0].title,internalTestId:l.testMirrors[0].internalTestId,storyId:l.testMirrors[0].storyId,evalFilePath:this.getEvalFilePath(this.editedFilePath),sourceFilePath:this.editedFilePath,restoreFromAutoSave:this.restoreFromAutoSave},r.CHECKSUM_VTG_TEST_FILE_RUN_CONFIG=JSON.stringify(s),a.push(this.getEvalFilePath(this.isEditMode?this.editedFilePath:void 0))}copyCustomerEngUtils(){let r=E6t(this.checksumRoot,10);if(!r){console.warn("Customer engineering repository was not found, using REPL will not be possible.");return}let a=(0,hfe.join)(r,eg.vtg.customerEngRepoInternalUtilsRelativePath);if(!(0,PK.existsSync)(a)){console.warn(`Internal utils file not found: ${a}, skipping copy.`);return}(0,PK.copyFileSync)(a,this.checksumAiInternalUtilsPath)}get checksumAiInternalUtilsPath(){return(0,hfe.join)(this.vtgInternalFilesDir,"checksum-ai-utils.ts")}async createEvalFileForExistingChecksumSpec(r,a){let s=new btt(r.sourceFile),l=y7r();s.transformSourceFile([new Ptt(a,l,{filterOutChecksumImports:!0}),new stt(a),new Ftt(a,l,{newRequireIdentifier:"checksumHotRequire",extraImportArguments:[$Dr.default.factory.createIdentifier("__filename")]}),new ott(r.sourceFile,r.testMirrors.map(b=>b.testBody),g7r(this.internalE2ETest?Gun:Hun),["page","vs","vtg"]),new B8t($Dr.default.NodeFlags.Let,!0)]);let d=this.getEvalFilePath(a);(0,PK.mkdirSync)((0,hfe.dirname)(d),{recursive:!0});let g=(0,PK.existsSync)(this.checksumAiInternalUtilsPath)?`globalThis.repl = require("${this.checksumAiInternalUtilsPath}").repl;`:"";(0,PK.writeFileSync)(d,`${this.internalE2ETest?'import { testingFunc } from "../../../../test.ts";':""}
1696
1696
  ${Yun}
1697
1697
  ${g}
1698
1698
  ${Xun}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksum-ai/runtime",
3
- "version": "2.0.4",
3
+ "version": "2.0.5-alpha",
4
4
  "description": "Checksum.ai test runtime",
5
5
  "main": "index.js",
6
6
  "dependencies": {