momentic 2.6.0 → 2.6.1
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/bin/cli.js
CHANGED
|
@@ -46,7 +46,7 @@ globstar while`,e,u,t,m,h),this.matchOne(e.slice(u),t.slice(m),r))return this.de
|
|
|
46
46
|
First test path: ${u}
|
|
47
47
|
|
|
48
48
|
Second test path: ${o}`)}t.tests[p.id]={type:Ie.TEST,name:p.name,id:p.id,description:p.description??void 0,labels:p.labels,...d};return}catch(p){r.warn(`Skipping file '${o}' because it is missing Momentic test metadata: ${p}`);return}case Ie.MODULE:try{let p=Lt.parse(a);t.modules[p.moduleId]={type:Ie.MODULE,name:p.name,id:p.moduleId,description:p.description??void 0,...d};let u=d.fileName.replace(".module.yaml","");!iy&&Ne(p.name)!==u&&r.warn(`The module with ID ${p.moduleId} has a name (${p.name}) that does not match its file name (${u}). We recommend renaming the module or the file to be consistent to avoid confusion and issues with module resolution.`);return}catch(p){r.warn(`Skipping file '${o}' because it is missing Momentic module metadata: ${p}`);return}default:r.warn(`Unsupported file type ${l}, skipping...`);return}}var oi="momentic.config.yaml",ay="momentic.workspace.yaml",TP=ue.object({projects:ue.string().array().describe("list of glob patterns to find project (momentic.config.yaml) files")}),EP=ue.union([ue.string(),ue.object({fromFile:ue.string(),json:ue.boolean().optional()})]),CP=ue.object({name:op,baseUrl:ue.string(),envFile:ue.string().optional().describe("path to a file on disk to read environment variables from. can be relative to project root or absolute."),envVariables:ue.record(ue.string(),EP).optional(),inheritFromShell:ue.boolean().optional().describe("inherit all environment variables from the shell - might be noisy"),browser:Nr.optional()}),RP=ue.object({postSave:ue.string().optional()}),AP=ue.object({name:op,include:ue.string().array().optional().describe("list of glob patterns that match momentic files (optional)"),exclude:ue.string().array().optional().describe("opposite of include, takes precedence over include"),goldenFileDir:ue.string().optional(),reporterDir:ue.string().optional(),outputDir:ue.string().optional(),retries:ue.number().optional().describe("number of retries per test"),parallel:ue.number().optional().describe("degree of parallelism"),environments:ue.array(CP).optional(),gitMainBranch:ue.string().optional(),gitProtectedBranches:ue.string().array().optional(),ai:xd.extend({aiPageFiltering:ue.boolean().optional().describe("rag v2 flag")}).optional(),browser:Nr.extend({autoExpandIframes:ue.boolean().optional(),disableSecondaryCacheResolution:ue.boolean().optional(),showZeroOpacityElements:ue.boolean().optional(),globalLocatorRedirect:ue.boolean().optional(),visualActions:ue.boolean().optional()}).optional(),advanced:gg.optional(),hooks:RP.optional()});function cy(n,e){let t;try{t=wP(n,"utf-8")}catch(o){b.warn(`Could not read possible Momentic ${e} file at ${n}: ${o}`);return}let r;try{if(r=ly.parse(t),typeof r!="object"||r===null)throw new Error(`The ${e} file should parse as a map with key-value pairs, but is type ${typeof r} instead`)}catch(o){b.warn(`Possible Momentic ${e} file at ${n} does not parse as valid YAML: ${o}`);return}return r}function sp(n){let e=cy(n,"project configuration");if(e!==void 0)try{return AP.parse(e)}catch(t){b.warn(`Possible Momentic project configuration file at ${n} does not adhere to the required schema: ${t}`);return}}function IP(n){let e=cy(n,"workspace configuration");if(e!==void 0)try{return TP.parse(e)}catch(t){b.warn(`Possible Momentic workspace configuration file at ${n} does not adhere to the required schema: ${t}`);return}}function PP(){let n=[],e=ap(),t=to.parse(e).root,r=15,o=0;for(;o<r;){o++;let i=to.basename(e);if(Us.includes(i))return b.warn(`Stopping search for Momentic projects since the current directory name (${i}) is likely a system artifact folder.`),n;for(let a of vP(e))if(a.endsWith(oi)){let s=to.join(e,a),l=sp(s);l&&n.push({configFilePath:s,config:l,rootDir:sy(s)})}if(n.length)return n;if(e=to.dirname(e),e===t)break}return n}function $t(n={}){let{configFilePath:e,nameFilter:t}=n,r=lp(e);if(t&&(r=r.filter(o=>o.config.name===t)),r.length>1)throw new Error(`Multiple valid projects were found in the same directory. Please use the '-c / --config' flag to disambiguate:
|
|
49
|
-
${r.map(o=>o.configFilePath)}`);if(r.length===0)throw new Error("No valid Momentic project file available.");return b.debug(`Found valid project configuration at ${r[0].configFilePath}`),r[0]}function LP(n){let e=IP(n);if(!e||!e.projects||!e.projects.length)return;let t=e.projects.map(i=>(i.endsWith("/")||(i+="/"),`${i}*${oi}`)),r=ri(t,{absolute:!1,cwd:ap(),dotRelative:!1,maxDepth:ip,nodir:!0}),o=[];for(let i of r){let a=to.join(ap(),i),s=sp(a);s&&o.push({configFilePath:a,config:s,rootDir:sy(a)})}return o}function lp(n){if(n){n=to.resolve(n);let t=sp(n);return t||(console.error(`No valid Momentic project file found at ${n}.`),process.exit(1)),[{config:t,configFilePath:n,rootDir:to.dirname(n)}]}if(bP(ay)){let t=LP(ay);if(t)return t}return PP()}function ii(n,e){let t=ly.stringify(n);xP(e,t)}import ai from"fs";import cp from"path";import{z as dp}from"zod";var dy="golden/visual-diff",py="reports",uy="test-results";var OP=dp.object({width:dp.number(),height:dp.number()}),si=class{defaultGoldenScreenshotDir;regenerateGoldenFiles;constructor(e,t){let r=cp.join(e.rootDir,e.config.goldenFileDir??dy);this.defaultGoldenScreenshotDir=r,this.regenerateGoldenFiles=t}async prepareGoldenScreenshotForComparison(e,t,r){if(t.screenshot?.data?.startsWith("https://")){let a=await fetch(t.screenshot.data);return{buffer:Buffer.from(await a.arrayBuffer()),width:t.screenshot.width,height:t.screenshot.height}}let o=t.screenshot?.data;o||(o=cp.join(this.defaultGoldenScreenshotDir,`${t.id}.jpg`));let i=`${o}.metadata.json`;if(this.regenerateGoldenFiles)return ai.mkdirSync(cp.dirname(o),{recursive:!0}),ai.writeFileSync(o,r.buffer),ai.writeFileSync(i,JSON.stringify({width:r.width,height:r.height})),{buffer:Buffer.from(r.buffer),width:r.width,height:r.height};if(ai.existsSync(o)){let a=ai.readFileSync(o),s=OP.parse(JSON.parse(ai.readFileSync(i,"utf-8")));return{buffer:a,width:s.width,height:s.height}}else throw new A("UserConfigurationError",`Cannot execute visual diff without a saved baseline screenshot at ${o}`)}};var li=class{flags;constructor(e){this.flags={auto_expand_iframes:e.browser?.autoExpandIframes??!1,rag_v2:e.ai?.aiPageFiltering??!1,faker_constant_seed:e.advanced?.fakerConstantSeed??!1,disable_secondary_cache_resolution:e.browser?.disableSecondaryCacheResolution??!1,show_zero_opacity_elements:e.browser?.showZeroOpacityElements??!1,global_locator_redirect:e.browser?.globalLocatorRedirect??!1,visual_actions:e.browser?.visualActions??!1,mini_model_initial_assertion:!1,mini_model_initial_locator:!1,show_test_plans:!1,icon_knowledge_base:!1,disable_clickhouse_caches:!1,disable_clickhouse_last_updated_endpoint:!1}}isBooleanFlagEnabled(e){return this.flags[e]}getAllFlags(){return{...this.flags}}getFlagPayload(e){}async refresh(){}};import MP from"simple-git";var Te=MP();function Sl(n){if(n.startsWith("git@")){let e=n.split(":");if(e.length===2){let t=e[1].replace(".git","").split("/");if(t.length===2){let r=t[0],o=t[1];return`${r}/${o}`}}}else if(n.startsWith("http")||n.startsWith("https")){let t=new URL(n).pathname.split("/").filter(Boolean);if(t.length>=2){let r=t[0],o=t[1].replace(".git","");return`${r}/${o}`}}}async function Ee(n,e){try{return(await e).trim()}catch(t){n.error({err:t},"Failed to run git command");return}}function NP(){if(process.env.GITHUB_ACTION)return"GithubActions";if(process.env.GITLAB_CI)return"GitlabCI";if(process.env.CIRCLECI)return"CircleCI";if(process.env.BUILDKITE)return"Buildkite";if(process.env["System.CollectionUri"]?.includes("azure"))return"AzureDevOps"}async function kP(n){let[e,t,r,o]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]);return{gitCommitSha:process.env.GITHUB_SHA,gitCommitShaShort:process.env.GITHUB_SHA?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env.GITHUB_HEAD_REF||process.env.GITHUB_REF_NAME,gitOriginUrl:t,gitCommitMessage:r,gitCommitAuthorName:o,githubRepository:process.env.GITHUB_REPOSITORY,pipelineId:`${process.env.GITHUB_RUN_ID}:${process.env.GITHUB_RUN_ATTEMPT}`}}async function _P(n){let[e,t,r]=await Promise.all([Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]);return{gitCommitSha:process.env.CI_COMMIT_SHA,gitCommitShaShort:process.env.CI_COMMIT_SHORT_SHA,gitCommitTimestamp:process.env.CI_COMMIT_TIMESTAMP?new Date(process.env.CI_COMMIT_TIMESTAMP):void 0,gitBranchName:process.env.CI_COMMIT_BRANCH||process.env.CI_COMMIT_REF_NAME,gitOriginUrl:e,gitCommitMessage:t,gitCommitAuthorName:r,gitlabProjectPath:process.env.CI_SERVER_HOST,pipelineId:`${process.env.CI_PIPELINE_ID}:${process.env.CI_JOB_ID}`}}async function DP(n){let[e,t,r,o]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]),i=t?.includes("github.com"),a=t?.includes("gitlab.com"),s=t?Sl(t):void 0;return{gitCommitSha:process.env.CIRCLE_SHA1,gitCommitShaShort:process.env.CIRCLE_SHA1?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env.CIRCLE_BRANCH,gitOriginUrl:process.env.CIRCLE_REPOSITORY_URL,gitCommitMessage:r,gitCommitAuthorName:o,githubRepository:i?s:void 0,gitlabProjectPath:a?s:void 0,pipelineId:`${process.env.CIRCLE_WORKFLOW_ID}:${process.env.CIRCLE_WORKFLOW_JOB_ID}`}}async function FP(n){let[e,t,r]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]),o=process.env.BUILDKITE_REPO,i=o?.includes("github.com"),a=o?.includes("gitlab.com"),s=o?Sl(o):void 0;return{gitCommitSha:process.env.BUILDKITE_COMMIT,gitCommitShaShort:process.env.BUILDKITE_COMMIT?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env.BUILDKITE_BRANCH,gitOriginUrl:o,gitCommitMessage:t,gitCommitAuthorName:r,githubRepository:i?s:void 0,gitlabProjectPath:a?s:void 0,pipelineId:`${process.env.BUILDKITE_PIPELINE_ID}:${process.env.BUILDKITE_BUILD_ID}:${process.env.BUILDKITE_JOB_ID}`}}async function UP(n){let[e,t,r]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]),o=process.env["Build.Repository.Uri"],i=o?.includes("github.com"),a=o?.includes("gitlab.com"),s=o?Sl(o):void 0;return{gitCommitSha:process.env["Build.SourceVersion"],gitCommitShaShort:process.env["Build.SourceVersion"]?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env["Build.SourceBranchName"],gitOriginUrl:o,gitCommitMessage:t,gitCommitAuthorName:r,githubRepository:i?s:void 0,gitlabProjectPath:a?s:void 0,pipelineId:`${process.env["System.JobId"]}:${process.env["System.JobAttempt"]}`}}async function BP(n,e){let[t,r,o,i,a,s,l,c]=await Promise.all([Ee(n,Te.revparse(["HEAD"])),Ee(n,Te.revparse(["--short","HEAD"])),Ee(n,Te.revparse(["--abbrev-ref","HEAD"])),Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"])),e?Ee(n,Te.raw(["merge-base","--fork-point",e])):Promise.resolve(void 0)]),d=c?await Ee(n,Te.show(["--no-patch","--format=%ci",c])):void 0,p=i?.includes("github.com"),u=i?.includes("gitlab.com"),m=i?Sl(i):void 0;return{gitCommitSha:t,gitCommitShaShort:r,gitBranchName:o,gitOriginUrl:i,gitCommitTimestamp:a?new Date(a):void 0,gitCommitMessage:s,gitCommitAuthorName:l,lastCommitOnMainSha:c,lastCommitOnMainTimestamp:d?new Date(d):void 0,githubRepository:p?m:void 0,gitlabProjectPath:u?m:void 0,pipelineId:void 0}}async function zP(n){let e=n.config.gitProtectedBranches??[];return n.config.gitMainBranch&&e.push(n.config.gitMainBranch),{gitMainBranch:n.config.gitMainBranch,gitProtectedBranches:e}}async function HP(n,e){let t=NP();if(!t)return BP(n,e);switch(t){case"GithubActions":return kP(n);case"GitlabCI":return _P(n);case"CircleCI":return DP(n);case"Buildkite":return FP(n);case"AzureDevOps":return UP(n)}}async function jP(n,e,t){if(t.lastCommitOnMainSha&&t.lastCommitOnMainTimestamp)return{};if(t.gitlabProjectPath){if(!t.gitMainBranch||!t.gitCommitSha)return{};try{let r=await e.getMergeBaseCommitFromGitlab(t.gitlabProjectPath,t.gitMainBranch,t.gitCommitSha);return{lastCommitOnMainSha:r.sha,lastCommitOnMainTimestamp:r.committer.date}}catch(r){return n.warn({err:r},"Failed to get remote metadata from Gitlab"),{}}}if(t.githubRepository){if(!t.gitMainBranch||!t.gitCommitSha)return{};try{let[r,o]=t.githubRepository.split("/"),i=await e.getMergeBaseCommitFromGithub(r,o,t.gitMainBranch,t.gitCommitSha);return{lastCommitOnMainSha:i.sha,lastCommitOnMainTimestamp:i.committer.date}}catch(r){return n.warn({err:r},"Failed to get remote metadata from Github"),{}}}return{}}async function ci(n,e,t){let r=await zP(t),o=await HP(n,r.gitMainBranch),i={...r,...o},a=await jP(n,e,i);return{...r,...o,...a}}import QN from"http";import{z as mp}from"zod";var $="v1",ka="2.6.0";var fr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}};var my=n=>{let e=n.reason===void 0?new DOMException("This operation was aborted.","AbortError"):n.reason;return e instanceof Error?e:new DOMException(e,"AbortError")};function U(n,e){let{milliseconds:t,fallback:r,message:o,customTimers:i={setTimeout,clearTimeout}}=e,a,s;if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);return new Promise((l,c)=>{if(e.signal){let{signal:p}=e;if(p.aborted)return c(my(p));s=()=>c(my(p)),p.addEventListener("abort",s)}let d=()=>{if(r)try{l(r())}catch(p){c(p)}else{typeof n.cancel=="function"&&Promise.resolve().then(()=>n.cancel()).catch(()=>{});let p=o instanceof Error?o:new fr(o??`Promise timed out after ${t}ms`);c(p)}};a=i.setTimeout(d,t),Promise.resolve(n).then(p=>l(p)).catch(p=>c(p))}).finally(()=>{i.clearTimeout(a),e.signal&&s&&e.signal.removeEventListener("abort",s)})}var yl=class{limit;windowMs;userActions;constructor(e,t){this.limit=e,this.windowMs=t,this.userActions=new Map}_cleanup(e,t="DEFAULT_USER"){let r=Date.now(),o=`${t}:${e}`;if(this.userActions.has(o)){let a=this.userActions.get(o)?.filter(s=>r-s<=this.windowMs)??[];a.length>0?this.userActions.set(o,a):this.userActions.delete(o)}}increment(e,t="DEFAULT_USER"){let r=Date.now(),o=`${t}:${e}`;this._cleanup(t,e),this.userActions.has(o)||this.userActions.set(o,[]);let i=this.userActions.get(o);return i.length>=this.limit?!0:(i.push(r),!1)}};var pp=["ability","able","aboard","about","above","accept","accident","according","account","accurate","acres","across","act","action","active","activity","actual","actually","add","addition","additional","adjective","adult","adventure","advice","affect","afraid","after","afternoon","again","against","age","ago","agree","ahead","aid","air","airplane","alike","alive","all","allow","almost","alone","along","aloud","alphabet","already","also","although","am","among","amount","ancient","angle","angry","animal","announced","another","answer","ants","any","anybody","anyone","anything","anyway","anywhere","apart","apartment","appearance","apple","applied","appropriate","are","area","arm","army","around","arrange","arrangement","arrive","arrow","art","article","as","aside","ask","asleep","at","ate","atmosphere","atom","atomic","attached","attack","attempt","attention","audience","author","automobile","available","average","avoid","aware","away","baby","back","bad","badly","bag","balance","ball","balloon","band","bank","bar","bare","bark","barn","base","baseball","basic","basis","basket","bat","battle","be","bean","bear","beat","beautiful","beauty","became","because","become","becoming","bee","been","before","began","beginning","begun","behavior","behind","being","believed","bell","belong","below","belt","bend","beneath","bent","beside","best","bet","better","between","beyond","bicycle","bigger","biggest","bill","birds","birth","birthday","bit","bite","black","blank","blanket","blew","blind","block","blood","blow","blue","board","boat","body","bone","book","border","born","both","bottle","bottom","bound","bow","bowl","box","boy","brain","branch","brass","brave","bread","break","breakfast","breath","breathe","breathing","breeze","brick","bridge","brief","bright","bring","broad","broke","broken","brother","brought","brown","brush","buffalo","build","building","built","buried","burn","burst","bus","bush","business","busy","but","butter","buy","by","cabin","cage","cake","call","calm","came","camera","camp","can","canal","cannot","cap","capital","captain","captured","car","carbon","card","care","careful","carefully","carried","carry","case","cast","castle","cat","catch","cattle","caught","cause","cave","cell","cent","center","central","century","certain","certainly","chain","chair","chamber","chance","change","changing","chapter","character","characteristic","charge","chart","check","cheese","chemical","chest","chicken","chief","child","children","choice","choose","chose","chosen","church","circle","circus","citizen","city","class","classroom","claws","clay","clean","clear","clearly","climate","climb","clock","close","closely","closer","cloth","clothes","clothing","cloud","club","coach","coal","coast","coat","coffee","cold","collect","college","colony","color","column","combination","combine","come","comfortable","coming","command","common","community","company","compare","compass","complete","completely","complex","composed","composition","compound","concerned","condition","congress","connected","consider","consist","consonant","constantly","construction","contain","continent","continued","contrast","control","conversation","cook","cookies","cool","copper","copy","corn","corner","correct","correctly","cost","cotton","could","count","country","couple","courage","course","court","cover","cow","cowboy","crack","cream","create","creature","crew","crop","cross","crowd","cry","cup","curious","current","curve","customs","cut","cutting","daily","damage","dance","danger","dangerous","dark","darkness","date","daughter","dawn","day","dead","deal","dear","death","decide","declared","deep","deeply","deer","definition","degree","depend","depth","describe","desert","design","desk","detail","determine","develop","development","diagram","diameter","did","die","differ","difference","different","difficult","difficulty","dig","dinner","direct","direction","directly","dirt","dirty","disappear","discover","discovery","discuss","discussion","disease","dish","distance","distant","divide","division","do","doctor","does","dog","doing","doll","dollar","done","donkey","door","dot","double","doubt","down","dozen","draw","drawn","dream","dress","drew","dried","drink","drive","driven","driver","driving","drop","dropped","drove","dry","duck","due","dug","dull","during","dust","duty","each","eager","ear","earlier","early","earn","earth","easier","easily","east","easy","eat","eaten","edge","education","effect","effort","egg","eight","either","electric","electricity","element","elephant","eleven","else","empty","end","enemy","energy","engine","engineer","enjoy","enough","enter","entire","entirely","environment","equal","equally","equator","equipment","escape","especially","essential","establish","even","evening","event","eventually","ever","every","everybody","everyone","everything","everywhere","evidence","exact","exactly","examine","example","excellent","except","exchange","excited","excitement","exciting","exclaimed","exercise","exist","expect","experience","experiment","explain","explanation","explore","express","expression","extra","eye","face","facing","fact","factor","factory","failed","fair","fairly","fall","fallen","familiar","family","famous","far","farm","farmer","farther","fast","fastened","faster","fat","father","favorite","fear","feathers","feature","fed","feed","feel","feet","fell","fellow","felt","fence","few","fewer","field","fierce","fifteen","fifth","fifty","fight","fighting","figure","fill","film","final","finally","find","fine","finest","finger","finish","fire","fireplace","firm","first","fish","five","fix","flag","flame","flat","flew","flies","flight","floating","floor","flow","flower","fly","fog","folks","follow","food","foot","football","for","force","foreign","forest","forget","forgot","forgotten","form","former","fort","forth","forty","forward","fought","found","four","fourth","fox","frame","free","freedom","frequently","fresh","friend","friendly","frighten","frog","from","front","frozen","fruit","fuel","full","fully","fun","function","funny","fur","furniture","further","future","gain","game","garage","garden","gas","gasoline","gate","gather","gave","general","generally","gentle","gently","get","getting","giant","gift","girl","give","given","giving","glad","glass","globe","go","goes","gold","golden","gone","good","goose","got","government","grabbed","grade","gradually","grain","grandfather","grandmother","graph","grass","gravity","gray","great","greater","greatest","greatly","green","grew","ground","group","grow","grown","growth","guard","guess","guide","gulf","gun","habit","had","hair","half","halfway","hall","hand","handle","handsome","hang","happen","happened","happily","happy","harbor","hard","harder","hardly","has","hat","have","having","hay","he","headed","heading","health","heard","hearing","heart","heat","heavy","height","held","hello","help","helpful","her","herd","here","herself","hidden","hide","high","higher","highest","highway","hill","him","himself","his","history","hit","hold","hole","hollow","home","honor","hope","horn","horse","hospital","hot","hour","house","how","however","huge","human","hundred","hung","hungry","hunt","hunter","hurried","hurry","hurt","husband","ice","idea","identity","if","ill","image","imagine","immediately","importance","important","impossible","improve","in","inch","include","including","income","increase","indeed","independent","indicate","individual","industrial","industry","influence","information","inside","instance","instant","instead","instrument","interest","interior","into","introduced","invented","involved","iron","is","island","it","its","itself","jack","jar","jet","job","join","joined","journey","joy","judge","jump","jungle","just","keep","kept","key","kids","kill","kind","kitchen","knew","knife","know","knowledge","known","label","labor","lack","lady","laid","lake","lamp","land","language","large","larger","largest","last","late","later","laugh","law","lay","layers","lead","leader","leaf","learn","least","leather","leave","leaving","led","left","leg","length","lesson","let","letter","level","library","lie","life","lift","light","like","likely","limited","line","lion","lips","liquid","list","listen","little","live","living","load","local","locate","location","log","lonely","long","longer","look","loose","lose","loss","lost","lot","loud","love","lovely","low","lower","luck","lucky","lunch","lungs","lying","machine","machinery","mad","made","magic","magnet","mail","main","mainly","major","make","making","man","managed","manner","manufacturing","many","map","mark","market","married","mass","massage","master","material","mathematics","matter","may","maybe","me","meal","mean","means","meant","measure","meat","medicine","meet","melted","member","memory","men","mental","merely","met","metal","method","mice","middle","might","mighty","mile","military","milk","mill","mind","mine","minerals","minute","mirror","missing","mission","mistake","mix","mixture","model","modern","molecular","moment","money","monkey","month","mood","moon","more","morning","most","mostly","mother","motion","motor","mountain","mouse","mouth","move","movement","movie","moving","mud","muscle","music","musical","must","my","myself","mysterious","nails","name","nation","national","native","natural","naturally","nature","near","nearby","nearer","nearest","nearly","necessary","neck","needed","needle","needs","negative","neighbor","neighborhood","nervous","nest","never","new","news","newspaper","next","nice","night","nine","no","nobody","nodded","noise","none","noon","nor","north","nose","not","note","noted","nothing","notice","noun","now","number","numeral","nuts","object","observe","obtain","occasionally","occur","ocean","of","off","offer","office","officer","official","oil","old","older","oldest","on","once","one","only","onto","open","operation","opinion","opportunity","opposite","or","orange","orbit","order","ordinary","organization","organized","origin","original","other","ought","our","ourselves","out","outer","outline","outside","over","own","owner","oxygen","pack","package","page","paid","pain","paint","pair","palace","pale","pan","paper","paragraph","parallel","parent","park","part","particles","particular","particularly","partly","parts","party","pass","passage","past","path","pattern","pay","peace","pen","pencil","people","per","percent","perfect","perfectly","perhaps","period","person","personal","pet","phrase","physical","piano","pick","picture","pictured","pie","piece","pig","pile","pilot","pine","pink","pipe","pitch","place","plain","plan","plane","planet","planned","planning","plant","plastic","plate","plates","play","pleasant","please","pleasure","plenty","plural","plus","pocket","poem","poet","poetry","point","pole","police","policeman","political","pond","pony","pool","poor","popular","population","porch","port","position","positive","possible","possibly","post","pot","potatoes","pound","pour","powder","power","powerful","practical","practice","prepare","present","president","press","pressure","pretty","prevent","previous","price","pride","primitive","principal","principle","printed","private","prize","probably","problem","process","produce","product","production","program","progress","promised","proper","properly","property","protection","proud","prove","provide","public","pull","pupil","pure","purple","purpose","push","put","putting","quarter","queen","question","quick","quickly","quiet","quietly","quite","rabbit","race","radio","railroad","rain","raise","ran","ranch","range","rapidly","rate","rather","raw","rays","reach","read","reader","ready","real","realize","rear","reason","recall","receive","recent","recently","recognize","record","red","refer","refused","region","regular","related","relationship","religious","remain","remarkable","remember","remove","repeat","replace","replied","report","represent","require","research","respect","rest","result","return","review","rhyme","rhythm","rice","rich","ride","riding","right","ring","rise","rising","river","road","roar","rock","rocket","rocky","rod","roll","roof","room","root","rope","rose","rough","round","route","row","rubbed","rubber","rule","ruler","run","running","rush","sad","saddle","safe","safety","said","sail","sale","salmon","salt","same","sand","sang","sat","satellites","satisfied","save","saved","saw","say","scale","scared","scene","school","science","scientific","scientist","score","screen","sea","search","season","seat","second","secret","section","see","seed","seeing","seems","seen","seldom","select","selection","sell","send","sense","sent","sentence","separate","series","serious","serve","service","sets","setting","settle","settlers","seven","several","shade","shadow","shake","shaking","shall","shallow","shape","share","sharp","she","sheep","sheet","shelf","shells","shelter","shine","shinning","ship","shirt","shoe","shoot","shop","shore","short","shorter","shot","should","shoulder","shout","show","shown","shut","sick","sides","sight","sign","signal","silence","silent","silk","silly","silver","similar","simple","simplest","simply","since","sing","single","sink","sister","sit","sitting","situation","six","size","skill","skin","sky","slabs","slave","sleep","slept","slide","slight","slightly","slip","slipped","slope","slow","slowly","small","smaller","smallest","smell","smile","smoke","smooth","snake","snow","so","soap","social","society","soft","softly","soil","solar","sold","soldier","solid","solution","solve","some","somebody","somehow","someone","something","sometime","somewhere","son","song","soon","sort","sound","source","south","southern","space","speak","special","species","specific","speech","speed","spell","spend","spent","spider","spin","spirit","spite","split","spoken","sport","spread","spring","square","stage","stairs","stand","standard","star","stared","start","state","statement","station","stay","steady","steam","steel","steep","stems","step","stepped","stick","stiff","still","stock","stomach","stone","stood","stop","stopped","store","storm","story","stove","straight","strange","stranger","straw","stream","street","strength","stretch","strike","string","strip","strong","stronger","struck","structure","struggle","stuck","student","studied","studying","subject","substance","success","successful","such","sudden","suddenly","sugar","suggest","suit","sum","summer","sun","sunlight","supper","supply","support","suppose","sure","surface","surprise","surrounded","swam","sweet","swept","swim","swimming","swing","swung","syllable","symbol","system","table","tail","take","taken","tales","talk","tall","tank","tape","task","taste","taught","tax","tea","teach","teacher","team","tears","teeth","telephone","television","tell","temperature","ten","tent","term","terrible","test","than","thank","that","thee","them","themselves","then","theory","there","therefore","these","they","thick","thin","thing","think","third","thirty","this","those","thou","though","thought","thousand","thread","three","threw","throat","through","throughout","throw","thrown","thumb","thus","thy","tide","tie","tight","tightly","till","time","tin","tiny","tip","tired","title","to","tobacco","today","together","told","tomorrow","tone","tongue","tonight","too","took","tool","top","topic","torn","total","touch","toward","tower","town","toy","trace","track","trade","traffic","trail","train","transportation","trap","travel","treated","tree","triangle","tribe","trick","tried","trip","troops","tropical","trouble","truck","trunk","truth","try","tube","tune","turn","twelve","twenty","twice","two","type","typical","uncle","under","underline","understanding","unhappy","union","unit","universe","unknown","unless","until","unusual","up","upon","upper","upward","us","use","useful","using","usual","usually","valley","valuable","value","vapor","variety","various","vast","vegetable","verb","vertical","very","vessels","victory","view","village","visit","visitor","voice","volume","vote","vowel","voyage","wagon","wait","walk","wall","want","war","warm","warn","was","wash","waste","watch","water","wave","way","we","weak","wealth","wear","weather","week","weigh","weight","welcome","well","went","were","west","western","wet","whale","what","whatever","wheat","wheel","when","whenever","where","wherever","whether","which","while","whispered","whistle","white","who","whole","whom","whose","why","wide","widely","wife","wild","will","willing","win","wind","window","wing","winter","wire","wise","wish","with","within","without","wolf","women","won","wonder","wonderful","wood","wooden","wool","word","wore","work","worker","world","worried","worry","worse","worth","would","wrapped","write","writer","writing","written","wrong","wrote","yard","year","yellow","yes","yesterday","yet","you","young","younger","your","yourself","youth","zero","zebra","zipper","zoo","zulu"];function hy(n){return new Array(n).fill(0).map(()=>pp[Math.floor(Math.random()*pp.length)]).join("-")}var $P=9e4,GP=15e3,bn=class extends Error{status;rawError;constructor(e,t,r,o={}){super(r,o),this.status=e,this.rawError=t}};async function WP(n){return n.text().then(e=>{try{return JSON.parse(e).error}catch{return e}})}var up=class{baseUrl;logger;constructor(e){this.baseUrl=e.baseUrl,this.logger=e.logger}getHeaders(){let e={"Content-Type":"application/json"};return ka&&(e[fg]=ka),e}async sendRequest(e,t,r=3,o=$P){let i=r,a,s={path:e,baseUrl:this.baseUrl,method:t.method};for(;r>0;)try{return r--,await this.sendSingleRequestHelper(e,t,o)}catch(l){if(a=l,l instanceof bn&&l.status>=400&&l.status<500)throw l;if(l instanceof Error&&l.name==="AbortError"&&(a=new fr),r===0)throw a;let c=1500,d=i-r,p=Math.min(c*Math.pow(2,d-1),GP);await new Promise(u=>setTimeout(u,p))}throw this.logger.warn({...s,err:a},"Got fatal error response from Momentic server"),a}async sendSingleRequestHelper(e,t,r){let o={path:e,baseUrl:this.baseUrl,method:t.method},i=new AbortController,a=setTimeout(()=>i.abort(),r),s=()=>i.abort();t.signal&&t.signal.addEventListener("abort",s);let l={...this.getHeaders(),...t.extraHeaders};try{let c=await fetch(`${this.baseUrl}${e}`,{method:t.method,body:t.body?JSON.stringify(t.body):void 0,headers:l,signal:i.signal});if(!c.ok){let p=await WP(c);throw new bn(c.status,p,`Request to ${e} failed with status ${c.status}: ${p}`)}let d;if(c.status===204)d={};else{let p=await c.text();try{d=JSON.parse(p)}catch{d=p}}return this.logger&&!t.noLog&&d&&this.logger.debug({result:d,status:c.status,...o},"Got response from Momentic server"),d}finally{clearTimeout(a),t.signal&&t.signal.removeEventListener("abort",s)}}},Ft=class extends up{apiKey;constructor(e){super(e),this.apiKey=e.apiKey}getHeaders(){return{...super.getHeaders(),Authorization:`Bearer ${this.apiKey}`}}};var ct=class extends Ft{constructor(e){super(e)}getAppUrl(){return this.baseUrl.replace(/\/\/api/,"//app")}async getAuthInfo(){let e=await this.sendRequest(`/${$}/auth/check`,{method:"GET",noLog:!0},10,5e3);return Dg.parse(e)}async bulkGetRunStatus(e){let t=await this.sendRequest(`/${$}/runs/status`,{method:"POST",body:e,noLog:!0},3,1e4);return Mg.parse(t)}async getTestYAMLExport(e){let t=await this.sendRequest(`/${$}/tests/export`,{method:"POST",body:e},3,3e4);return Ag.parse(t)}async updateStepCaches(e,t){await this.sendRequest(`/${$}/cache`,{method:"PATCH",body:e,extraHeaders:t},3,1e4)}async getStepCacheForTest(e,t){let r=await this.sendRequest(`/${$}/cache`,{method:"POST",body:e,extraHeaders:t},10,3e4);return Ig.parse(r)}async queueTests(e){let t=await this.sendRequest(`/${$}/tests/queue`,{method:"POST",body:e},3,1e4);return Rg.parse(t)}async uploadScreenshot(e){let t=await this.sendRequest(`/${$}/screenshots`,{method:"POST",body:e,noLog:!0},3,5e3);return _g.parse(t)}async getAllEnvironments(){let e=await this.sendRequest(`/${$}/environments`,{method:"GET"},3,5e3);return Fg.parse(e)}async acquireCacheLock(e,t){let r=await this.sendRequest(`/${$}/result-cache/lock`,{method:"POST",body:e,signal:t},3,3e4);return Gg.parse(r)}async releaseCacheLock(e){await this.sendRequest(`/${$}/result-cache/lock`,{method:"DELETE",body:{key:e}},3,5e3)}async deleteCacheResult(e){await this.sendRequest(`/${$}/result-cache/entry`,{method:"DELETE",body:e},3,5e3)}async setCacheResult(e){await this.sendRequest(`/${$}/result-cache/entry`,{method:"PATCH",body:e},3,5e3)}async getCacheResult(e){try{return await this.sendRequest(`/${$}/result-cache/entry`,{method:"POST",body:e},3,5e3)}catch(t){if(t instanceof Error&&t.message.includes("404"))return null;throw t}}async queueSuiteRuns(e){let t=await this.sendRequest(`/${$}/suites/queue`,{method:"POST",body:e},3,5e3);return Ug.parse(t)}async bulkGetRunGroupStatus(e){let t={runGroupIds:e},r=await this.sendRequest(`/${$}/run-groups/status`,{method:"POST",body:t,noLog:!0},3,5e3);return gh.array().parse(r)}async uploadProposedSteps(e,t){try{await this.sendRequest(`/${$}/test-fragments/`,{method:"POST",body:e},3,1e4)}catch(r){t.error({err:r},"Failed to upload proposed steps")}}async uploadSnapshotScreenshot(e,t,r){try{await this.sendRequest(`/${$}/snapshots/${t}/screenshot`,{method:"POST",body:r,noLog:!0},3,1e4)}catch(o){e.error({err:o},"Failed to upload screenshot")}}async generateConsoleLogsForRunAttemptUploadUrl(e,t,r){let o=await this.sendRequest(`/${$}/runs/${t}/attempts/${r}/console-logs`,{method:"POST",noLog:!0},3,5e3);return ca.parse(o)}async generateNetworkLogsForRunAttemptUploadUrl(e,t,r){let o=await this.sendRequest(`/${$}/runs/${t}/attempts/${r}/network-logs`,{method:"POST",noLog:!0},3,1e4);return ca.parse(o)}async generateHtmlSnapshotUploadUrl(e,t){let r=await this.sendRequest(`/${$}/snapshots/${t}/html`,{method:"POST",noLog:!0},3,1e4);return ca.parse(r)}async reportBillableEvents(e,t){try{await this.sendRequest(`/${$}/billing/events`,{method:"POST",body:t,noLog:!0},10,1e4)}catch(r){e.error({err:r},"Failed to report billable event")}}async fetchTestFragment(e){let t=await this.sendRequest(`/${$}/test-fragments/${e}`,{method:"GET",noLog:!0},3,1e4);return Bg.parse(t)}async patchTestFragment(e,t){await this.sendRequest(`/${$}/test-fragments/${e}`,{method:"PATCH",body:t},3,1e4)}async getPastTestResults(e,t){let r=await this.sendRequest(`/${$}/results/tests/${e}`,{method:"POST",body:t},3,1e4);return zg.parse(r)}async generateTestResultsUploadUrl(){let e=await this.sendRequest(`/${$}/results/uploads`,{method:"POST",noLog:!0},3,1e4);return Hg.parse(e)}async startProcessingResultsUpload(e,t){let r=await this.sendRequest(`/${$}/results/uploads/${e}/process`,{method:"POST",noLog:!0,body:t},3,1e4);return jg.parse(r)}async fetchIconKnowledgeBase(e){try{let t=await this.sendRequest(`/${$}/knowledge-base/icons`,{method:"GET",noLog:!0},3,5e3);return Jg.parse(t)}catch(t){return e.error({err:t},"Failed to fetch icon knowledge base"),null}}async saveNewIcons(e,t){try{await this.sendRequest(`/${$}/knowledge-base/icons`,{method:"POST",body:e,noLog:!0},3,5e3)}catch(r){t.error({err:r},"Failed to save new icons to icon knowledge base")}}async getMergeBaseCommitFromGithub(e,t,r,o){let i=new URLSearchParams;i.set("base",r),i.set("head",o);let a=await this.sendRequest(`/${$}/git/github/${e}/${t}/merge-base-commit?${i.toString()}`,{method:"GET",noLog:!0},3,1e4);return Cd.parse(a)}async getMergeBaseCommitFromGitlab(e,t,r){let o=new URLSearchParams;o.set("base",t),o.set("head",r);let i=await this.sendRequest(`/${$}/git/gitlab/${e}/merge-base-commit?${o.toString()}`,{method:"GET",noLog:!0},3,5e3);return Cd.parse(i)}async getAgentConfig(){let e=await this.sendRequest(`/${$}/web-agent/agent-config`,{method:"GET",noLog:!0},3,5e3);return mp.record(mp.string(),mp.string()).parse(e)}};import{randomUUID as gy}from"crypto";var bl=class{apiClient;constructor(e){this.apiClient=e}async reportBillableEvent(e,t,r){try{return await this.apiClient.reportBillableEvents(e,[{event:t,timestamp:new Date().toISOString(),transactionId:r?.eventId??gy(),properties:ud({},r)}])}catch(o){e.error({err:o},"Failed to report billable event")}}async reportCreditsUsed(e,t,r,o){if(r)try{return await this.apiClient.reportBillableEvents(e,[{event:"credits-used",timestamp:new Date().toISOString(),transactionId:o?.eventId??gy(),properties:ud({creditsUsed:r,usedBy:t},o)}])}catch(i){e.error({err:i},"Failed to report credits used")}}};function di(n,e,t){return fetch(n,{method:"PUT",body:t,headers:{"Content-Type":e}})}var wl=class{constructor(e){this.client=e}async storeConsoleLogsForRunAttempt(e,t,r,o){try{let i=JSON.stringify(o),{uploadUrl:a}=await this.client.generateConsoleLogsForRunAttemptUploadUrl(e,t,r),s=await di(a,"application/json",i);if(!s.ok)throw new Error(`Failed to upload network logs: ${s.statusText}`)}catch(i){e.error({err:i},"Failed to upload console logs")}}async storeNetworkLogsForRunAttempt(e,t,r,o){let i=JSON.stringify(o);try{let{uploadUrl:a}=await this.client.generateNetworkLogsForRunAttemptUploadUrl(e,t,r),s=await di(a,"application/json",i);if(!s.ok)throw new Error(`Failed to upload network logs: ${s.statusText}`)}catch(a){e.error({err:a},"Failed to upload network logs")}}async storeHtmlSnapshot(e,t,r){try{let{uploadUrl:o}=await this.client.generateHtmlSnapshotUploadUrl(e,t),i=await di(o,"text/html",r);if(!i.ok)throw new Error(`Failed to upload network logs: ${i.statusText}`)}catch(o){e.error({err:o},"Failed to upload html snapshot")}}async storeScreenshot(e,t,r){try{await this.client.uploadSnapshotScreenshot(e,t,{screenshot:r.toString("base64")})}catch(o){e.error({err:o},"Failed to upload screenshot")}}async storeA11yTreeSnapshot(e,t,r){return Promise.resolve()}async getConsoleLogsForRunAttempt(e,t,r){}async getNetworkLogsForRunAttempt(e,t,r){}async getHtmlSnapshot(e,t){}async getA11yTreeSnapshot(e,t){}async getScreenshot(e,t){}};var pi=class{constructor(e,t){this.client=e;this.orgId=t}async acquireCacheLock(e,t){return this.client.acquireCacheLock(e,t)}async uploadScreenshot(e){return(await this.client.uploadScreenshot({screenshot:e.toString("base64")})).key}async releaseCacheLock(e){return this.client.releaseCacheLock(e)}async deleteCacheResult(e){return this.client.deleteCacheResult(e)}async setCacheResult(e){return this.client.setCacheResult(e)}async getCacheResult(e){return this.client.getCacheResult(e)}fetchIconKnowledgeBase(e){return this.client.fetchIconKnowledgeBase(e)}saveNewIcons(e,t){return this.client.saveNewIcons(e,t)}};import{Faker as VP,en as qP}from"@faker-js/faker";var ui="v1",Sr=class{httpClient;fakerInstance;type="API_CLIENT";sms={send:this.sendSms.bind(this),fetchLatest:this.fetchLatestSms.bind(this)};email={send:this.sendEmail.bind(this),fetchLatest:this.fetchLatestEmail.bind(this),fetchAll:this.fetchAllEmails.bind(this)};ai={generate:this.sendAiGenerate.bind(this)};constructor(e){this.httpClient=e.httpClient,e.fakerSeed&&(this.fakerInstance=new VP({locale:qP}),this.fakerInstance.seed(e.fakerSeed))}async sendAiGenerate(e){let t=typeof e=="string"?{input:e}:e;return this.httpClient.sendRequest(`/${ui}/tools/ai/generate`,{method:"POST",body:t}).catch(r=>{throw r instanceof bn?new Error(r.rawError):new Error(`Failed to send AI generation: ${r.message}`)})}async sendSms(e){return this.httpClient.sendRequest(`/${ui}/tools/sms/send`,{method:"POST",body:e}).then(()=>{}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to send sms: ${t.message}`)})}async fetchLatestSms(e){return this.httpClient.sendRequest(`/${ui}/tools/sms/fetchLatest`,{method:"POST",body:e}).catch(t=>{throw t instanceof bn?new Error(t.rawError):t})}async sendEmail(e){return this.httpClient.sendRequest(`/${ui}/tools/email/send`,{method:"POST",body:e}).then(()=>{}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to send email: ${t.message}`)})}async fetchAllEmails(e){return this.httpClient.sendRequest(`/${ui}/tools/email/fetchAll`,{method:"POST",body:e}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to fetch all emails: ${t.message}`)})}async fetchLatestEmail(e){return this.httpClient.sendRequest(`/${ui}/tools/email/fetchLatest`,{method:"POST",body:e}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to fetch latest emails: ${t.message}`)})}};import{z as KP}from"zod";var mi=class extends Ft{agentConfig;constructor(e,t){super(t),this.agentConfig=e}async rankChunksWithAi(e,t){let r={...e,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/recommend-chunks-ai`,{method:"POST",body:r,signal:t.abortSignal});return vh.parse(o)}async rankChunksWithRag(e,t){let r=await this.sendRequest(`/${$}/web-agent/recommend-chunks`,{method:"POST",body:{cliVersion:ka,...e},signal:t.abortSignal});return wh.parse(r)}async getScreenshotFromS3(e){let t=await this.sendRequest(`/${$}/s3/visual-diff-screenshot`,{method:"POST",body:{url:e}});return KP.string().parse(t)}async getElementLocation(e,t){let r={...e,disableCache:t.disableCache,loggerTags:t.loggerTags,useMemory:t.useMemory,agentConfigVersion:this.agentConfig?.locator},o=await this.sendRequest(`/${$}/web-agent/locate-element`,{method:"POST",body:r,signal:t.abortSignal});return Eg.parse(o)}async getAssertionResult(e,t){let r={...e,disableCache:!!t.disableCache,useConsensus:!!t.useConsensus,attemptNumber:t.attemptNumber,loggerTags:t.loggerTags,useMemory:t.useMemory,agentConfigVersion:this.agentConfig?.locator},o=await this.sendRequest(`/${$}/web-agent/assertion`,{method:"POST",body:r,signal:t.abortSignal});return Td.parse(o)}async getLintStepResult(e,t){let r={...e,disableCache:!!t.disableCache,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/lint/step`,{method:"POST",body:r,signal:t.abortSignal});return Tg.parse(o)}async getVisualAssertionResult(e,t){let r={...e,disableCache:!!t.disableCache,useConsensus:!!t.useConsensus,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/visual-assertion`,{method:"POST",body:r,signal:t.abortSignal});return Td.parse(o)}async getAiActionCommand(e,t){let r=await this.sendRequest(`/${$}/web-agent/next-command-dynamic`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal});return xg.parse(r)}async getMultiturnAiActionCommand(e,t){return await this.sendRequest(`/${$}/web-agent/ai-action/next-command`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal})}async getMultiturnAiActionEvaluation(e,t){let r=await this.sendRequest(`/${$}/web-agent/ai-action/evaluate`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal});return zc.parse(r)}async getReverseMappedDescription(e,t){let r=await this.sendRequest(`/${$}/web-agent/reverse-mapped-description`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal});return Cg.parse(r)}async getTextExtraction(e,t){let r={...e,disableCache:t.disableCache,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/text-extraction`,{method:"POST",body:r,signal:t.abortSignal});return Bc.parse(o)}async getTestResultClassification(e,t){let r=await this.sendRequest(`/${$}/web-agent/result-classification`,{method:"POST",body:{...e,loggerTags:t.loggerTags},signal:t.abortSignal});return Zc.parse(r)}async getExtractedKeywords(e,t){let r=await this.sendRequest(`/${$}/web-agent/extract-keywords`,{method:"POST",body:{goal:e,disableCache:t.disableCache,context:e},signal:t.abortSignal});return Lh.parse(r)}async getAutohealingProposal(e,t){let r=await this.sendRequest(`/${$}/web-agent/autoheal-section`,{method:"POST",body:{...e,loggerTags:t.loggerTags},signal:t.abortSignal});return ym.parse(r)}async getFailureRecoveryProposal(e,t){let r=await this.sendRequest(`/${$}/web-agent/failure-recovery`,{method:"POST",body:{...e,loggerTags:t.loggerTags},signal:t.abortSignal});return bm.parse(r)}async getIframeRegex(e,t){let r=await this.sendRequest(`/${$}/web-agent/iframe-regex`,{method:"POST",body:e,signal:t.abortSignal});return Qu.parse(r)}};var hi=class extends Ft{generator;constructor(e,t){super(e),this.generator=t}async runTemplateMatching(e,t={}){let r=await this.sendRequest(`/${$}/web-agent/template-matching`,{method:"POST",body:e,signal:t?.signal});return em.parse(r)}async constructIframeRegex(e,t={}){return this.generator.getIframeRegex(e,{abortSignal:t.signal})}};var vl=class{constructor(e){this.client=e}async uploadResultsArchive(e,t){let{uploadUrl:r,id:o}=await this.client.generateTestResultsUploadUrl(),i=await di(r,"application/zip",t);if(!i.ok)throw new Error(`Failed to upload test results: ${await i.text()}`);let{runGroupId:a}=await this.client.startProcessingResultsUpload(o,{runGroupId:e});return a}};function gi({orgId:n,client:e,gitMetadata:t,alwaysSaveCache:r,noCache:o}){return o?new Ya:new hp(n,e,t,r)}var hp=class{constructor(e,t,{gitMainBranch:r,gitBranchName:o,gitProtectedBranches:i,gitCommitTimestamp:a,lastCommitOnMainSha:s,lastCommitOnMainTimestamp:l},c){this.orgId=e;this.client=t;this.cacheHeaders={},r&&(this.cacheHeaders[Sg]=r),o&&(this.cacheHeaders[yg]=o),a&&(this.cacheHeaders[bg]=a.toISOString()),s&&(this.cacheHeaders[wg]=s),l&&(this.cacheHeaders[vg]=l.toISOString()),c?this.writeCaches=!0:o?this.writeCaches=!i.includes(o):this.writeCaches=!0}cacheHeaders;writeCaches;async saveStepCacheEntries({entries:e,testId:t,logger:r}){if(!this.writeCaches){r.debug("Skipping cache storage because branch is protected");return}try{await this.client.updateStepCaches({entries:e,testId:t},this.cacheHeaders)}catch(o){r.error({err:o},"Failed to save step cache entries")}}async resolveStepCacheEntries(e){let{steps:t,beforeSteps:r,afterSteps:o}=e.stepLists,i=await this.client.getStepCacheForTest({testId:e.testId,steps:t,schemaVersion:e.schemaVersion},this.cacheHeaders);if(!this.writeCaches){e.logger.debug("Skipping cache last used at update because branch is protected");return}for(let s of[t,r,o])s&&$o({steps:s,stepCacheEntries:i,logger:e.logger});let{cachesToSave:a}=await Dt({stepLists:e.stepLists,cacheCreationParams:{testId:e.testId,orgId:this.orgId}});this.client.updateStepCaches({entries:a,testId:e.testId},this.cacheHeaders)}};import ek from"path";import{Server as CN}from"socket.io";import{cloneDeep as YP}from"lodash-es";var JP={showOverlay:!1},gp=class{sessions=new Map;sessionCountByIp=new Map;getCurrentConnectionsByIp(e){return this.sessionCountByIp.get(e)??0}getCurrentSessionsByIp(){return Object.fromEntries(this.sessionCountByIp)}reserveCapacityByIp(e){e&&this.sessionCountByIp.set(e,(this.sessionCountByIp.get(e)??0)+1)}releaseCapacityByIp(e){e&&this.sessionCountByIp.set(e,Math.max(this.getCurrentConnectionsByIp(e)-1,0))}registerSession({controller:e,context:t,cleanup:r,clientIp:o,sessionId:i,browserbaseSessionId:a}){return this.sessions.set(i,{controller:e,context:t,cleanup:r,clientIp:o,browserbaseSessionId:a,browserBehavior:YP(JP)}),i}removeSession(e,t){(async()=>{let o=this.sessions.get(e);if(!o)return;this.releaseCapacityByIp(o.clientIp);let{controller:i}=o;try{i.setClosed(),await i.browser.cleanup()}catch(a){t.error({err:a},"Error cleaning up browser in global state manager")}try{await o.cleanup?.()}catch(a){t.error({err:a},"Error running cleanup function in global state manager")}this.sessions.delete(e)})()}getSession(e){return this.sessions.get(e)}},Z=new gp;function fy(n,e,t){let r=Date.now(),o=Date.now(),i,a,s,l,c=!1,d=async(h,g)=>{if(!h.closed&&!h.isInPageLoad)try{let f=s;s=void 0;let S=h.url(),w=g.toEditorDisplayCopy();JSON.stringify(w)===JSON.stringify(i)&&S===l&&r>o||(n.emit("browserState",{logsPerPage:f?.logsPerPage,harPages:f?.harPages,harEntries:f?.harEntries,viewport:h.getViewport(),url:S,iframeSrcUrls:a??[],context:w,isInPageLoad:h.isInPageLoad}),r=Date.now()),l=S,i=w}catch(f){if(!n.connected)return;let S=f instanceof Error?f.message:`${f}`;if(S.includes("Frame was detached")||S.includes("Not attached to an active page")||S.includes("browser has been closed")||S.includes("UserInfrastructureError"))return;t.error({err:f,sessionId:e},"Error grabbing browser state")}},p=setInterval(()=>{let h=Z.getSession(e),g=h?.controller?.browser;if(!g||g.closed){t.debug("Clearing browser state socket cron due to the browser being closed"),clearInterval(p);return}d(g,h.context)},1e3),u=(h,g)=>!!(JSON.stringify(h)!==JSON.stringify(a)||g.logsPerPage.some(f=>f.length>0)||g.harPages&&Object.keys(g.harPages).length>0||g.harEntries&&Object.keys(g.harEntries).length>0),m=setInterval(async()=>{let g=Z.getSession(e)?.controller?.browser;if(!g||g.closed){clearInterval(m);return}else if(c)return;c=!0;try{let f=await g.getAllFrameUrls(),S=g.retrieveAndClearDebugData();u(f,S)&&(a=f,s=S,o=Date.now())}catch(f){t.warn({err:f},"Failed to fetch extended details")}finally{c=!1}},2500);return{timers:[p,m]}}var yr={};var XP=n=>()=>{let{sessionId:e}=n.metadata;yr[e]?.abort?.abort()},Sy={event:"cancelApiTest",createHandler:XP};import{CookieJar as fL}from"tough-cookie";import{randomUUID as iL}from"crypto";import{faker as ZP}from"@faker-js/faker";import QP from"assert";import eL from"axios";import tL from"moment";import*as nL from"otpauth";import rL from"pg";async function yy(n){let e;try{e=new URL(n.url).hostname}catch{}let t=[];return n.headers.getSetCookie()?.forEach(r=>{let o=Ms(r,e);t.push(...o)}),t}var oL=Object.getPrototypeOf(async function(){}).constructor;async function by(n,e,t){let r=e.code;e.options.fragment&&(r=`return ${e.code}`);let{env:o}=e.bindings,i=e.tools,a={},s=(f,S)=>{o[f]=S,a[f]=S},l={},c=(f,S)=>{o[f]=S,l[f]=S},d;r.includes("Octokit")&&(d=(await import("@octokit/rest")).Octokit);let p;r.includes("createAppAuth")&&(p=(await import("@octokit/auth-app")).createAppAuth);let u=async()=>await Promise.resolve(new oL("axios","moment","faker","assert","pg","Octokit","createAppAuth","OTPAuth","extractCookiesFromResponse","env","setVariable","setPersistentVariable","sendSms","waitForLatestSms","email","sms","ai",r)(eL,tL,i.fakerInstance??ZP,QP,rL,d,p,nL,yy,o,s,c,S=>i.sms.send(S),S=>i.sms.fetchLatest(S),i.email,i.sms,i.ai)),m=!0,h,g;try{h=await U(u(),{milliseconds:e.options.timeoutMs,message:`Timeout of ${e.options.timeoutMs}ms exceeded for code execution`,signal:e.signal})}catch(f){t.error({err:f,env:o,evalCode:r},`[${n}] Error executing code: ${f}`),m=!1,f instanceof fr?g=`Timeout of ${e.options.timeoutMs}ms exceeded for code execution`:g=f instanceof Error?f.message:`${f}`}return{result:h,variableUpdates:a,persistentVariableUpdates:l,success:m,error:g}}async function wy({code:n,fragment:e,context:t,localTools:r,logger:o,signal:i,timeoutMs:a=lr}){let s=iL(),l=await by(s,{code:n,options:{fragment:e,timeoutMs:a},bindings:t.toObjectCopy(),tools:r,signal:i},o);return b.debug(`[${s}] Got execution result: ${JSON.stringify(l)}`),l}import{createHmac as aL,randomUUID as sL}from"crypto";import lL from"fetch-retry";var cL=lL(global.fetch,{retries:3,retryOn:function(n,e,t){return!!(e!==null||t&&t.status>=500)},retryDelay:function(n){return Math.pow(2,n)*500}}),vy=process.env.GCP_JS_EVAL_FUNCTION_ENDPOINT,xy=process.env.MOMENTIC_LAMBDA_AUTH_SECRET;async function Ty({orgId:n,code:e,fragment:t,context:r,timeoutMs:o=lr,retries:i=2,signal:a,logger:s}){if(!vy)throw new Error("GCP_JS_EVAL_FUNCTION_ENDPOINT environment variable not set");let l,c,d=0;if(!xy)throw new Error("Missing lambda auth secret.");let p=aL("sha256",xy).update(n).digest("hex");for(;d<=i;){d++,a?.throwIfAborted();let m={id:sL(),orgId:n,momenticLambdaAuthHash:p,code:e,fragment:t,state:r.toObjectCopy(),timeoutMs:o};try{if(l=await U(cL(vy,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)}),{milliseconds:o,message:`Timeout of ${o}ms exceeded for code execution`,signal:a}),!l)throw new Error("Got empty response from code evaluation server");if(!l.ok)throw new Error(`Code evaluation server returned error code ${l.status}`);c=void 0;break}catch(h){c=h}}if(c)throw s.error({err:c},"Failed to evaluate code remotely"),c;if(!l)throw new Error(`An unexpected code evaluation error occurred${c?`: ${c}`:""}`);let u;try{u=Uh.parse(await l.json())}catch(m){throw new Error(`Code evaluation server returned invalid response: ${m}`)}if(u.error)throw new Error(`Code evaluation error: ${u.error}`);return u}async function Kn(n){let e;if(process.env.GCP_JS_EVAL_FUNCTION_ENDPOINT)e=await Ty(n);else if(n.localTools)e=await wy({...n,localTools:n.localTools});else throw new Error("No code evaluation environment available");if(e.error){let t=`Failed to evaluate code:
|
|
49
|
+
${r.map(o=>o.configFilePath)}`);if(r.length===0)throw new Error("No valid Momentic project file available.");return b.debug(`Found valid project configuration at ${r[0].configFilePath}`),r[0]}function LP(n){let e=IP(n);if(!e||!e.projects||!e.projects.length)return;let t=e.projects.map(i=>(i.endsWith("/")||(i+="/"),`${i}*${oi}`)),r=ri(t,{absolute:!1,cwd:ap(),dotRelative:!1,maxDepth:ip,nodir:!0}),o=[];for(let i of r){let a=to.join(ap(),i),s=sp(a);s&&o.push({configFilePath:a,config:s,rootDir:sy(a)})}return o}function lp(n){if(n){n=to.resolve(n);let t=sp(n);return t||(console.error(`No valid Momentic project file found at ${n}.`),process.exit(1)),[{config:t,configFilePath:n,rootDir:to.dirname(n)}]}if(bP(ay)){let t=LP(ay);if(t)return t}return PP()}function ii(n,e){let t=ly.stringify(n);xP(e,t)}import ai from"fs";import cp from"path";import{z as dp}from"zod";var dy="golden/visual-diff",py="reports",uy="test-results";var OP=dp.object({width:dp.number(),height:dp.number()}),si=class{defaultGoldenScreenshotDir;regenerateGoldenFiles;constructor(e,t){let r=cp.join(e.rootDir,e.config.goldenFileDir??dy);this.defaultGoldenScreenshotDir=r,this.regenerateGoldenFiles=t}async prepareGoldenScreenshotForComparison(e,t,r){if(t.screenshot?.data?.startsWith("https://")){let a=await fetch(t.screenshot.data);return{buffer:Buffer.from(await a.arrayBuffer()),width:t.screenshot.width,height:t.screenshot.height}}let o=t.screenshot?.data;o||(o=cp.join(this.defaultGoldenScreenshotDir,`${t.id}.jpg`));let i=`${o}.metadata.json`;if(this.regenerateGoldenFiles)return ai.mkdirSync(cp.dirname(o),{recursive:!0}),ai.writeFileSync(o,r.buffer),ai.writeFileSync(i,JSON.stringify({width:r.width,height:r.height})),{buffer:Buffer.from(r.buffer),width:r.width,height:r.height};if(ai.existsSync(o)){let a=ai.readFileSync(o),s=OP.parse(JSON.parse(ai.readFileSync(i,"utf-8")));return{buffer:a,width:s.width,height:s.height}}else throw new A("UserConfigurationError",`Cannot execute visual diff without a saved baseline screenshot at ${o}`)}};var li=class{flags;constructor(e){this.flags={auto_expand_iframes:e.browser?.autoExpandIframes??!1,rag_v2:e.ai?.aiPageFiltering??!1,faker_constant_seed:e.advanced?.fakerConstantSeed??!1,disable_secondary_cache_resolution:e.browser?.disableSecondaryCacheResolution??!1,show_zero_opacity_elements:e.browser?.showZeroOpacityElements??!1,global_locator_redirect:e.browser?.globalLocatorRedirect??!1,visual_actions:e.browser?.visualActions??!1,mini_model_initial_assertion:!1,mini_model_initial_locator:!1,show_test_plans:!1,icon_knowledge_base:!1,disable_clickhouse_caches:!1,disable_clickhouse_last_updated_endpoint:!1}}isBooleanFlagEnabled(e){return this.flags[e]}getAllFlags(){return{...this.flags}}getFlagPayload(e){}async refresh(){}};import MP from"simple-git";var Te=MP();function Sl(n){if(n.startsWith("git@")){let e=n.split(":");if(e.length===2){let t=e[1].replace(".git","").split("/");if(t.length===2){let r=t[0],o=t[1];return`${r}/${o}`}}}else if(n.startsWith("http")||n.startsWith("https")){let t=new URL(n).pathname.split("/").filter(Boolean);if(t.length>=2){let r=t[0],o=t[1].replace(".git","");return`${r}/${o}`}}}async function Ee(n,e){try{return(await e).trim()}catch(t){n.error({err:t},"Failed to run git command");return}}function NP(){if(process.env.GITHUB_ACTION)return"GithubActions";if(process.env.GITLAB_CI)return"GitlabCI";if(process.env.CIRCLECI)return"CircleCI";if(process.env.BUILDKITE)return"Buildkite";if(process.env["System.CollectionUri"]?.includes("azure"))return"AzureDevOps"}async function kP(n){let[e,t,r,o]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]);return{gitCommitSha:process.env.GITHUB_SHA,gitCommitShaShort:process.env.GITHUB_SHA?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env.GITHUB_HEAD_REF||process.env.GITHUB_REF_NAME,gitOriginUrl:t,gitCommitMessage:r,gitCommitAuthorName:o,githubRepository:process.env.GITHUB_REPOSITORY,pipelineId:`${process.env.GITHUB_RUN_ID}:${process.env.GITHUB_RUN_ATTEMPT}`}}async function _P(n){let[e,t,r]=await Promise.all([Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]);return{gitCommitSha:process.env.CI_COMMIT_SHA,gitCommitShaShort:process.env.CI_COMMIT_SHORT_SHA,gitCommitTimestamp:process.env.CI_COMMIT_TIMESTAMP?new Date(process.env.CI_COMMIT_TIMESTAMP):void 0,gitBranchName:process.env.CI_COMMIT_BRANCH||process.env.CI_COMMIT_REF_NAME,gitOriginUrl:e,gitCommitMessage:t,gitCommitAuthorName:r,gitlabProjectPath:process.env.CI_SERVER_HOST,pipelineId:`${process.env.CI_PIPELINE_ID}:${process.env.CI_JOB_ID}`}}async function DP(n){let[e,t,r,o]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]),i=t?.includes("github.com"),a=t?.includes("gitlab.com"),s=t?Sl(t):void 0;return{gitCommitSha:process.env.CIRCLE_SHA1,gitCommitShaShort:process.env.CIRCLE_SHA1?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env.CIRCLE_BRANCH,gitOriginUrl:process.env.CIRCLE_REPOSITORY_URL,gitCommitMessage:r,gitCommitAuthorName:o,githubRepository:i?s:void 0,gitlabProjectPath:a?s:void 0,pipelineId:`${process.env.CIRCLE_WORKFLOW_ID}:${process.env.CIRCLE_WORKFLOW_JOB_ID}`}}async function FP(n){let[e,t,r]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]),o=process.env.BUILDKITE_REPO,i=o?.includes("github.com"),a=o?.includes("gitlab.com"),s=o?Sl(o):void 0;return{gitCommitSha:process.env.BUILDKITE_COMMIT,gitCommitShaShort:process.env.BUILDKITE_COMMIT?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env.BUILDKITE_BRANCH,gitOriginUrl:o,gitCommitMessage:t,gitCommitAuthorName:r,githubRepository:i?s:void 0,gitlabProjectPath:a?s:void 0,pipelineId:`${process.env.BUILDKITE_PIPELINE_ID}:${process.env.BUILDKITE_BUILD_ID}:${process.env.BUILDKITE_JOB_ID}`}}async function UP(n){let[e,t,r]=await Promise.all([Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"]))]),o=process.env["Build.Repository.Uri"],i=o?.includes("github.com"),a=o?.includes("gitlab.com"),s=o?Sl(o):void 0;return{gitCommitSha:process.env["Build.SourceVersion"],gitCommitShaShort:process.env["Build.SourceVersion"]?.slice(0,6),gitCommitTimestamp:e?new Date(e):void 0,gitBranchName:process.env["Build.SourceBranchName"],gitOriginUrl:o,gitCommitMessage:t,gitCommitAuthorName:r,githubRepository:i?s:void 0,gitlabProjectPath:a?s:void 0,pipelineId:`${process.env["System.JobId"]}:${process.env["System.JobAttempt"]}`}}async function BP(n,e){let[t,r,o,i,a,s,l,c]=await Promise.all([Ee(n,Te.revparse(["HEAD"])),Ee(n,Te.revparse(["--short","HEAD"])),Ee(n,Te.revparse(["--abbrev-ref","HEAD"])),Ee(n,Te.listRemote(["--get-url","origin"])),Ee(n,Te.show(["--no-patch","--format=%ci"])),Ee(n,Te.show(["-s","--pretty=%B"])),Ee(n,Te.show(["-s","--pretty=%an"])),e?Ee(n,Te.raw(["merge-base","--fork-point",e])):Promise.resolve(void 0)]),d=c?await Ee(n,Te.show(["--no-patch","--format=%ci",c])):void 0,p=i?.includes("github.com"),u=i?.includes("gitlab.com"),m=i?Sl(i):void 0;return{gitCommitSha:t,gitCommitShaShort:r,gitBranchName:o,gitOriginUrl:i,gitCommitTimestamp:a?new Date(a):void 0,gitCommitMessage:s,gitCommitAuthorName:l,lastCommitOnMainSha:c,lastCommitOnMainTimestamp:d?new Date(d):void 0,githubRepository:p?m:void 0,gitlabProjectPath:u?m:void 0,pipelineId:void 0}}async function zP(n){let e=n.config.gitProtectedBranches??[];return n.config.gitMainBranch&&e.push(n.config.gitMainBranch),{gitMainBranch:n.config.gitMainBranch,gitProtectedBranches:e}}async function HP(n,e){let t=NP();if(!t)return BP(n,e);switch(t){case"GithubActions":return kP(n);case"GitlabCI":return _P(n);case"CircleCI":return DP(n);case"Buildkite":return FP(n);case"AzureDevOps":return UP(n)}}async function jP(n,e,t){if(t.lastCommitOnMainSha&&t.lastCommitOnMainTimestamp)return{};if(t.gitlabProjectPath){if(!t.gitMainBranch||!t.gitCommitSha)return{};try{let r=await e.getMergeBaseCommitFromGitlab(t.gitlabProjectPath,t.gitMainBranch,t.gitCommitSha);return{lastCommitOnMainSha:r.sha,lastCommitOnMainTimestamp:r.committer.date}}catch(r){return n.warn({err:r},"Failed to get remote metadata from Gitlab"),{}}}if(t.githubRepository){if(!t.gitMainBranch||!t.gitCommitSha)return{};try{let[r,o]=t.githubRepository.split("/"),i=await e.getMergeBaseCommitFromGithub(r,o,t.gitMainBranch,t.gitCommitSha);return{lastCommitOnMainSha:i.sha,lastCommitOnMainTimestamp:i.committer.date}}catch(r){return n.warn({err:r},"Failed to get remote metadata from Github"),{}}}return{}}async function ci(n,e,t){let r=await zP(t),o=await HP(n,r.gitMainBranch),i={...r,...o},a=await jP(n,e,i);return{...r,...o,...a}}import QN from"http";import{z as mp}from"zod";var $="v1",ka="2.6.1";var fr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}};var my=n=>{let e=n.reason===void 0?new DOMException("This operation was aborted.","AbortError"):n.reason;return e instanceof Error?e:new DOMException(e,"AbortError")};function U(n,e){let{milliseconds:t,fallback:r,message:o,customTimers:i={setTimeout,clearTimeout}}=e,a,s;if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);return new Promise((l,c)=>{if(e.signal){let{signal:p}=e;if(p.aborted)return c(my(p));s=()=>c(my(p)),p.addEventListener("abort",s)}let d=()=>{if(r)try{l(r())}catch(p){c(p)}else{typeof n.cancel=="function"&&Promise.resolve().then(()=>n.cancel()).catch(()=>{});let p=o instanceof Error?o:new fr(o??`Promise timed out after ${t}ms`);c(p)}};a=i.setTimeout(d,t),Promise.resolve(n).then(p=>l(p)).catch(p=>c(p))}).finally(()=>{i.clearTimeout(a),e.signal&&s&&e.signal.removeEventListener("abort",s)})}var yl=class{limit;windowMs;userActions;constructor(e,t){this.limit=e,this.windowMs=t,this.userActions=new Map}_cleanup(e,t="DEFAULT_USER"){let r=Date.now(),o=`${t}:${e}`;if(this.userActions.has(o)){let a=this.userActions.get(o)?.filter(s=>r-s<=this.windowMs)??[];a.length>0?this.userActions.set(o,a):this.userActions.delete(o)}}increment(e,t="DEFAULT_USER"){let r=Date.now(),o=`${t}:${e}`;this._cleanup(t,e),this.userActions.has(o)||this.userActions.set(o,[]);let i=this.userActions.get(o);return i.length>=this.limit?!0:(i.push(r),!1)}};var pp=["ability","able","aboard","about","above","accept","accident","according","account","accurate","acres","across","act","action","active","activity","actual","actually","add","addition","additional","adjective","adult","adventure","advice","affect","afraid","after","afternoon","again","against","age","ago","agree","ahead","aid","air","airplane","alike","alive","all","allow","almost","alone","along","aloud","alphabet","already","also","although","am","among","amount","ancient","angle","angry","animal","announced","another","answer","ants","any","anybody","anyone","anything","anyway","anywhere","apart","apartment","appearance","apple","applied","appropriate","are","area","arm","army","around","arrange","arrangement","arrive","arrow","art","article","as","aside","ask","asleep","at","ate","atmosphere","atom","atomic","attached","attack","attempt","attention","audience","author","automobile","available","average","avoid","aware","away","baby","back","bad","badly","bag","balance","ball","balloon","band","bank","bar","bare","bark","barn","base","baseball","basic","basis","basket","bat","battle","be","bean","bear","beat","beautiful","beauty","became","because","become","becoming","bee","been","before","began","beginning","begun","behavior","behind","being","believed","bell","belong","below","belt","bend","beneath","bent","beside","best","bet","better","between","beyond","bicycle","bigger","biggest","bill","birds","birth","birthday","bit","bite","black","blank","blanket","blew","blind","block","blood","blow","blue","board","boat","body","bone","book","border","born","both","bottle","bottom","bound","bow","bowl","box","boy","brain","branch","brass","brave","bread","break","breakfast","breath","breathe","breathing","breeze","brick","bridge","brief","bright","bring","broad","broke","broken","brother","brought","brown","brush","buffalo","build","building","built","buried","burn","burst","bus","bush","business","busy","but","butter","buy","by","cabin","cage","cake","call","calm","came","camera","camp","can","canal","cannot","cap","capital","captain","captured","car","carbon","card","care","careful","carefully","carried","carry","case","cast","castle","cat","catch","cattle","caught","cause","cave","cell","cent","center","central","century","certain","certainly","chain","chair","chamber","chance","change","changing","chapter","character","characteristic","charge","chart","check","cheese","chemical","chest","chicken","chief","child","children","choice","choose","chose","chosen","church","circle","circus","citizen","city","class","classroom","claws","clay","clean","clear","clearly","climate","climb","clock","close","closely","closer","cloth","clothes","clothing","cloud","club","coach","coal","coast","coat","coffee","cold","collect","college","colony","color","column","combination","combine","come","comfortable","coming","command","common","community","company","compare","compass","complete","completely","complex","composed","composition","compound","concerned","condition","congress","connected","consider","consist","consonant","constantly","construction","contain","continent","continued","contrast","control","conversation","cook","cookies","cool","copper","copy","corn","corner","correct","correctly","cost","cotton","could","count","country","couple","courage","course","court","cover","cow","cowboy","crack","cream","create","creature","crew","crop","cross","crowd","cry","cup","curious","current","curve","customs","cut","cutting","daily","damage","dance","danger","dangerous","dark","darkness","date","daughter","dawn","day","dead","deal","dear","death","decide","declared","deep","deeply","deer","definition","degree","depend","depth","describe","desert","design","desk","detail","determine","develop","development","diagram","diameter","did","die","differ","difference","different","difficult","difficulty","dig","dinner","direct","direction","directly","dirt","dirty","disappear","discover","discovery","discuss","discussion","disease","dish","distance","distant","divide","division","do","doctor","does","dog","doing","doll","dollar","done","donkey","door","dot","double","doubt","down","dozen","draw","drawn","dream","dress","drew","dried","drink","drive","driven","driver","driving","drop","dropped","drove","dry","duck","due","dug","dull","during","dust","duty","each","eager","ear","earlier","early","earn","earth","easier","easily","east","easy","eat","eaten","edge","education","effect","effort","egg","eight","either","electric","electricity","element","elephant","eleven","else","empty","end","enemy","energy","engine","engineer","enjoy","enough","enter","entire","entirely","environment","equal","equally","equator","equipment","escape","especially","essential","establish","even","evening","event","eventually","ever","every","everybody","everyone","everything","everywhere","evidence","exact","exactly","examine","example","excellent","except","exchange","excited","excitement","exciting","exclaimed","exercise","exist","expect","experience","experiment","explain","explanation","explore","express","expression","extra","eye","face","facing","fact","factor","factory","failed","fair","fairly","fall","fallen","familiar","family","famous","far","farm","farmer","farther","fast","fastened","faster","fat","father","favorite","fear","feathers","feature","fed","feed","feel","feet","fell","fellow","felt","fence","few","fewer","field","fierce","fifteen","fifth","fifty","fight","fighting","figure","fill","film","final","finally","find","fine","finest","finger","finish","fire","fireplace","firm","first","fish","five","fix","flag","flame","flat","flew","flies","flight","floating","floor","flow","flower","fly","fog","folks","follow","food","foot","football","for","force","foreign","forest","forget","forgot","forgotten","form","former","fort","forth","forty","forward","fought","found","four","fourth","fox","frame","free","freedom","frequently","fresh","friend","friendly","frighten","frog","from","front","frozen","fruit","fuel","full","fully","fun","function","funny","fur","furniture","further","future","gain","game","garage","garden","gas","gasoline","gate","gather","gave","general","generally","gentle","gently","get","getting","giant","gift","girl","give","given","giving","glad","glass","globe","go","goes","gold","golden","gone","good","goose","got","government","grabbed","grade","gradually","grain","grandfather","grandmother","graph","grass","gravity","gray","great","greater","greatest","greatly","green","grew","ground","group","grow","grown","growth","guard","guess","guide","gulf","gun","habit","had","hair","half","halfway","hall","hand","handle","handsome","hang","happen","happened","happily","happy","harbor","hard","harder","hardly","has","hat","have","having","hay","he","headed","heading","health","heard","hearing","heart","heat","heavy","height","held","hello","help","helpful","her","herd","here","herself","hidden","hide","high","higher","highest","highway","hill","him","himself","his","history","hit","hold","hole","hollow","home","honor","hope","horn","horse","hospital","hot","hour","house","how","however","huge","human","hundred","hung","hungry","hunt","hunter","hurried","hurry","hurt","husband","ice","idea","identity","if","ill","image","imagine","immediately","importance","important","impossible","improve","in","inch","include","including","income","increase","indeed","independent","indicate","individual","industrial","industry","influence","information","inside","instance","instant","instead","instrument","interest","interior","into","introduced","invented","involved","iron","is","island","it","its","itself","jack","jar","jet","job","join","joined","journey","joy","judge","jump","jungle","just","keep","kept","key","kids","kill","kind","kitchen","knew","knife","know","knowledge","known","label","labor","lack","lady","laid","lake","lamp","land","language","large","larger","largest","last","late","later","laugh","law","lay","layers","lead","leader","leaf","learn","least","leather","leave","leaving","led","left","leg","length","lesson","let","letter","level","library","lie","life","lift","light","like","likely","limited","line","lion","lips","liquid","list","listen","little","live","living","load","local","locate","location","log","lonely","long","longer","look","loose","lose","loss","lost","lot","loud","love","lovely","low","lower","luck","lucky","lunch","lungs","lying","machine","machinery","mad","made","magic","magnet","mail","main","mainly","major","make","making","man","managed","manner","manufacturing","many","map","mark","market","married","mass","massage","master","material","mathematics","matter","may","maybe","me","meal","mean","means","meant","measure","meat","medicine","meet","melted","member","memory","men","mental","merely","met","metal","method","mice","middle","might","mighty","mile","military","milk","mill","mind","mine","minerals","minute","mirror","missing","mission","mistake","mix","mixture","model","modern","molecular","moment","money","monkey","month","mood","moon","more","morning","most","mostly","mother","motion","motor","mountain","mouse","mouth","move","movement","movie","moving","mud","muscle","music","musical","must","my","myself","mysterious","nails","name","nation","national","native","natural","naturally","nature","near","nearby","nearer","nearest","nearly","necessary","neck","needed","needle","needs","negative","neighbor","neighborhood","nervous","nest","never","new","news","newspaper","next","nice","night","nine","no","nobody","nodded","noise","none","noon","nor","north","nose","not","note","noted","nothing","notice","noun","now","number","numeral","nuts","object","observe","obtain","occasionally","occur","ocean","of","off","offer","office","officer","official","oil","old","older","oldest","on","once","one","only","onto","open","operation","opinion","opportunity","opposite","or","orange","orbit","order","ordinary","organization","organized","origin","original","other","ought","our","ourselves","out","outer","outline","outside","over","own","owner","oxygen","pack","package","page","paid","pain","paint","pair","palace","pale","pan","paper","paragraph","parallel","parent","park","part","particles","particular","particularly","partly","parts","party","pass","passage","past","path","pattern","pay","peace","pen","pencil","people","per","percent","perfect","perfectly","perhaps","period","person","personal","pet","phrase","physical","piano","pick","picture","pictured","pie","piece","pig","pile","pilot","pine","pink","pipe","pitch","place","plain","plan","plane","planet","planned","planning","plant","plastic","plate","plates","play","pleasant","please","pleasure","plenty","plural","plus","pocket","poem","poet","poetry","point","pole","police","policeman","political","pond","pony","pool","poor","popular","population","porch","port","position","positive","possible","possibly","post","pot","potatoes","pound","pour","powder","power","powerful","practical","practice","prepare","present","president","press","pressure","pretty","prevent","previous","price","pride","primitive","principal","principle","printed","private","prize","probably","problem","process","produce","product","production","program","progress","promised","proper","properly","property","protection","proud","prove","provide","public","pull","pupil","pure","purple","purpose","push","put","putting","quarter","queen","question","quick","quickly","quiet","quietly","quite","rabbit","race","radio","railroad","rain","raise","ran","ranch","range","rapidly","rate","rather","raw","rays","reach","read","reader","ready","real","realize","rear","reason","recall","receive","recent","recently","recognize","record","red","refer","refused","region","regular","related","relationship","religious","remain","remarkable","remember","remove","repeat","replace","replied","report","represent","require","research","respect","rest","result","return","review","rhyme","rhythm","rice","rich","ride","riding","right","ring","rise","rising","river","road","roar","rock","rocket","rocky","rod","roll","roof","room","root","rope","rose","rough","round","route","row","rubbed","rubber","rule","ruler","run","running","rush","sad","saddle","safe","safety","said","sail","sale","salmon","salt","same","sand","sang","sat","satellites","satisfied","save","saved","saw","say","scale","scared","scene","school","science","scientific","scientist","score","screen","sea","search","season","seat","second","secret","section","see","seed","seeing","seems","seen","seldom","select","selection","sell","send","sense","sent","sentence","separate","series","serious","serve","service","sets","setting","settle","settlers","seven","several","shade","shadow","shake","shaking","shall","shallow","shape","share","sharp","she","sheep","sheet","shelf","shells","shelter","shine","shinning","ship","shirt","shoe","shoot","shop","shore","short","shorter","shot","should","shoulder","shout","show","shown","shut","sick","sides","sight","sign","signal","silence","silent","silk","silly","silver","similar","simple","simplest","simply","since","sing","single","sink","sister","sit","sitting","situation","six","size","skill","skin","sky","slabs","slave","sleep","slept","slide","slight","slightly","slip","slipped","slope","slow","slowly","small","smaller","smallest","smell","smile","smoke","smooth","snake","snow","so","soap","social","society","soft","softly","soil","solar","sold","soldier","solid","solution","solve","some","somebody","somehow","someone","something","sometime","somewhere","son","song","soon","sort","sound","source","south","southern","space","speak","special","species","specific","speech","speed","spell","spend","spent","spider","spin","spirit","spite","split","spoken","sport","spread","spring","square","stage","stairs","stand","standard","star","stared","start","state","statement","station","stay","steady","steam","steel","steep","stems","step","stepped","stick","stiff","still","stock","stomach","stone","stood","stop","stopped","store","storm","story","stove","straight","strange","stranger","straw","stream","street","strength","stretch","strike","string","strip","strong","stronger","struck","structure","struggle","stuck","student","studied","studying","subject","substance","success","successful","such","sudden","suddenly","sugar","suggest","suit","sum","summer","sun","sunlight","supper","supply","support","suppose","sure","surface","surprise","surrounded","swam","sweet","swept","swim","swimming","swing","swung","syllable","symbol","system","table","tail","take","taken","tales","talk","tall","tank","tape","task","taste","taught","tax","tea","teach","teacher","team","tears","teeth","telephone","television","tell","temperature","ten","tent","term","terrible","test","than","thank","that","thee","them","themselves","then","theory","there","therefore","these","they","thick","thin","thing","think","third","thirty","this","those","thou","though","thought","thousand","thread","three","threw","throat","through","throughout","throw","thrown","thumb","thus","thy","tide","tie","tight","tightly","till","time","tin","tiny","tip","tired","title","to","tobacco","today","together","told","tomorrow","tone","tongue","tonight","too","took","tool","top","topic","torn","total","touch","toward","tower","town","toy","trace","track","trade","traffic","trail","train","transportation","trap","travel","treated","tree","triangle","tribe","trick","tried","trip","troops","tropical","trouble","truck","trunk","truth","try","tube","tune","turn","twelve","twenty","twice","two","type","typical","uncle","under","underline","understanding","unhappy","union","unit","universe","unknown","unless","until","unusual","up","upon","upper","upward","us","use","useful","using","usual","usually","valley","valuable","value","vapor","variety","various","vast","vegetable","verb","vertical","very","vessels","victory","view","village","visit","visitor","voice","volume","vote","vowel","voyage","wagon","wait","walk","wall","want","war","warm","warn","was","wash","waste","watch","water","wave","way","we","weak","wealth","wear","weather","week","weigh","weight","welcome","well","went","were","west","western","wet","whale","what","whatever","wheat","wheel","when","whenever","where","wherever","whether","which","while","whispered","whistle","white","who","whole","whom","whose","why","wide","widely","wife","wild","will","willing","win","wind","window","wing","winter","wire","wise","wish","with","within","without","wolf","women","won","wonder","wonderful","wood","wooden","wool","word","wore","work","worker","world","worried","worry","worse","worth","would","wrapped","write","writer","writing","written","wrong","wrote","yard","year","yellow","yes","yesterday","yet","you","young","younger","your","yourself","youth","zero","zebra","zipper","zoo","zulu"];function hy(n){return new Array(n).fill(0).map(()=>pp[Math.floor(Math.random()*pp.length)]).join("-")}var $P=9e4,GP=15e3,bn=class extends Error{status;rawError;constructor(e,t,r,o={}){super(r,o),this.status=e,this.rawError=t}};async function WP(n){return n.text().then(e=>{try{return JSON.parse(e).error}catch{return e}})}var up=class{baseUrl;logger;constructor(e){this.baseUrl=e.baseUrl,this.logger=e.logger}getHeaders(){let e={"Content-Type":"application/json"};return ka&&(e[fg]=ka),e}async sendRequest(e,t,r=3,o=$P){let i=r,a,s={path:e,baseUrl:this.baseUrl,method:t.method};for(;r>0;)try{return r--,await this.sendSingleRequestHelper(e,t,o)}catch(l){if(a=l,l instanceof bn&&l.status>=400&&l.status<500)throw l;if(l instanceof Error&&l.name==="AbortError"&&(a=new fr),r===0)throw a;let c=1500,d=i-r,p=Math.min(c*Math.pow(2,d-1),GP);await new Promise(u=>setTimeout(u,p))}throw this.logger.warn({...s,err:a},"Got fatal error response from Momentic server"),a}async sendSingleRequestHelper(e,t,r){let o={path:e,baseUrl:this.baseUrl,method:t.method},i=new AbortController,a=setTimeout(()=>i.abort(),r),s=()=>i.abort();t.signal&&t.signal.addEventListener("abort",s);let l={...this.getHeaders(),...t.extraHeaders};try{let c=await fetch(`${this.baseUrl}${e}`,{method:t.method,body:t.body?JSON.stringify(t.body):void 0,headers:l,signal:i.signal});if(!c.ok){let p=await WP(c);throw new bn(c.status,p,`Request to ${e} failed with status ${c.status}: ${p}`)}let d;if(c.status===204)d={};else{let p=await c.text();try{d=JSON.parse(p)}catch{d=p}}return this.logger&&!t.noLog&&d&&this.logger.debug({result:d,status:c.status,...o},"Got response from Momentic server"),d}finally{clearTimeout(a),t.signal&&t.signal.removeEventListener("abort",s)}}},Ft=class extends up{apiKey;constructor(e){super(e),this.apiKey=e.apiKey}getHeaders(){return{...super.getHeaders(),Authorization:`Bearer ${this.apiKey}`}}};var ct=class extends Ft{constructor(e){super(e)}getAppUrl(){return this.baseUrl.replace(/\/\/api/,"//app")}async getAuthInfo(){let e=await this.sendRequest(`/${$}/auth/check`,{method:"GET",noLog:!0},10,5e3);return Dg.parse(e)}async bulkGetRunStatus(e){let t=await this.sendRequest(`/${$}/runs/status`,{method:"POST",body:e,noLog:!0},3,1e4);return Mg.parse(t)}async getTestYAMLExport(e){let t=await this.sendRequest(`/${$}/tests/export`,{method:"POST",body:e},3,3e4);return Ag.parse(t)}async updateStepCaches(e,t){await this.sendRequest(`/${$}/cache`,{method:"PATCH",body:e,extraHeaders:t},3,1e4)}async getStepCacheForTest(e,t){let r=await this.sendRequest(`/${$}/cache`,{method:"POST",body:e,extraHeaders:t},10,3e4);return Ig.parse(r)}async queueTests(e){let t=await this.sendRequest(`/${$}/tests/queue`,{method:"POST",body:e},3,1e4);return Rg.parse(t)}async uploadScreenshot(e){let t=await this.sendRequest(`/${$}/screenshots`,{method:"POST",body:e,noLog:!0},3,5e3);return _g.parse(t)}async getAllEnvironments(){let e=await this.sendRequest(`/${$}/environments`,{method:"GET"},3,5e3);return Fg.parse(e)}async acquireCacheLock(e,t){let r=await this.sendRequest(`/${$}/result-cache/lock`,{method:"POST",body:e,signal:t},3,3e4);return Gg.parse(r)}async releaseCacheLock(e){await this.sendRequest(`/${$}/result-cache/lock`,{method:"DELETE",body:{key:e}},3,5e3)}async deleteCacheResult(e){await this.sendRequest(`/${$}/result-cache/entry`,{method:"DELETE",body:e},3,5e3)}async setCacheResult(e){await this.sendRequest(`/${$}/result-cache/entry`,{method:"PATCH",body:e},3,5e3)}async getCacheResult(e){try{return await this.sendRequest(`/${$}/result-cache/entry`,{method:"POST",body:e},3,5e3)}catch(t){if(t instanceof Error&&t.message.includes("404"))return null;throw t}}async queueSuiteRuns(e){let t=await this.sendRequest(`/${$}/suites/queue`,{method:"POST",body:e},3,5e3);return Ug.parse(t)}async bulkGetRunGroupStatus(e){let t={runGroupIds:e},r=await this.sendRequest(`/${$}/run-groups/status`,{method:"POST",body:t,noLog:!0},3,5e3);return gh.array().parse(r)}async uploadProposedSteps(e,t){try{await this.sendRequest(`/${$}/test-fragments/`,{method:"POST",body:e},3,1e4)}catch(r){t.error({err:r},"Failed to upload proposed steps")}}async uploadSnapshotScreenshot(e,t,r){try{await this.sendRequest(`/${$}/snapshots/${t}/screenshot`,{method:"POST",body:r,noLog:!0},3,1e4)}catch(o){e.error({err:o},"Failed to upload screenshot")}}async generateConsoleLogsForRunAttemptUploadUrl(e,t,r){let o=await this.sendRequest(`/${$}/runs/${t}/attempts/${r}/console-logs`,{method:"POST",noLog:!0},3,5e3);return ca.parse(o)}async generateNetworkLogsForRunAttemptUploadUrl(e,t,r){let o=await this.sendRequest(`/${$}/runs/${t}/attempts/${r}/network-logs`,{method:"POST",noLog:!0},3,1e4);return ca.parse(o)}async generateHtmlSnapshotUploadUrl(e,t){let r=await this.sendRequest(`/${$}/snapshots/${t}/html`,{method:"POST",noLog:!0},3,1e4);return ca.parse(r)}async reportBillableEvents(e,t){try{await this.sendRequest(`/${$}/billing/events`,{method:"POST",body:t,noLog:!0},10,1e4)}catch(r){e.error({err:r},"Failed to report billable event")}}async fetchTestFragment(e){let t=await this.sendRequest(`/${$}/test-fragments/${e}`,{method:"GET",noLog:!0},3,1e4);return Bg.parse(t)}async patchTestFragment(e,t){await this.sendRequest(`/${$}/test-fragments/${e}`,{method:"PATCH",body:t},3,1e4)}async getPastTestResults(e,t){let r=await this.sendRequest(`/${$}/results/tests/${e}`,{method:"POST",body:t},3,1e4);return zg.parse(r)}async generateTestResultsUploadUrl(){let e=await this.sendRequest(`/${$}/results/uploads`,{method:"POST",noLog:!0},3,1e4);return Hg.parse(e)}async startProcessingResultsUpload(e,t){let r=await this.sendRequest(`/${$}/results/uploads/${e}/process`,{method:"POST",noLog:!0,body:t},3,1e4);return jg.parse(r)}async fetchIconKnowledgeBase(e){try{let t=await this.sendRequest(`/${$}/knowledge-base/icons`,{method:"GET",noLog:!0},3,5e3);return Jg.parse(t)}catch(t){return e.error({err:t},"Failed to fetch icon knowledge base"),null}}async saveNewIcons(e,t){try{await this.sendRequest(`/${$}/knowledge-base/icons`,{method:"POST",body:e,noLog:!0},3,5e3)}catch(r){t.error({err:r},"Failed to save new icons to icon knowledge base")}}async getMergeBaseCommitFromGithub(e,t,r,o){let i=new URLSearchParams;i.set("base",r),i.set("head",o);let a=await this.sendRequest(`/${$}/git/github/${e}/${t}/merge-base-commit?${i.toString()}`,{method:"GET",noLog:!0},3,1e4);return Cd.parse(a)}async getMergeBaseCommitFromGitlab(e,t,r){let o=new URLSearchParams;o.set("base",t),o.set("head",r);let i=await this.sendRequest(`/${$}/git/gitlab/${e}/merge-base-commit?${o.toString()}`,{method:"GET",noLog:!0},3,5e3);return Cd.parse(i)}async getAgentConfig(){let e=await this.sendRequest(`/${$}/web-agent/agent-config`,{method:"GET",noLog:!0},3,5e3);return mp.record(mp.string(),mp.string()).parse(e)}};import{randomUUID as gy}from"crypto";var bl=class{apiClient;constructor(e){this.apiClient=e}async reportBillableEvent(e,t,r){try{return await this.apiClient.reportBillableEvents(e,[{event:t,timestamp:new Date().toISOString(),transactionId:r?.eventId??gy(),properties:ud({},r)}])}catch(o){e.error({err:o},"Failed to report billable event")}}async reportCreditsUsed(e,t,r,o){if(r)try{return await this.apiClient.reportBillableEvents(e,[{event:"credits-used",timestamp:new Date().toISOString(),transactionId:o?.eventId??gy(),properties:ud({creditsUsed:r,usedBy:t},o)}])}catch(i){e.error({err:i},"Failed to report credits used")}}};function di(n,e,t){return fetch(n,{method:"PUT",body:t,headers:{"Content-Type":e}})}var wl=class{constructor(e){this.client=e}async storeConsoleLogsForRunAttempt(e,t,r,o){try{let i=JSON.stringify(o),{uploadUrl:a}=await this.client.generateConsoleLogsForRunAttemptUploadUrl(e,t,r),s=await di(a,"application/json",i);if(!s.ok)throw new Error(`Failed to upload network logs: ${s.statusText}`)}catch(i){e.error({err:i},"Failed to upload console logs")}}async storeNetworkLogsForRunAttempt(e,t,r,o){let i=JSON.stringify(o);try{let{uploadUrl:a}=await this.client.generateNetworkLogsForRunAttemptUploadUrl(e,t,r),s=await di(a,"application/json",i);if(!s.ok)throw new Error(`Failed to upload network logs: ${s.statusText}`)}catch(a){e.error({err:a},"Failed to upload network logs")}}async storeHtmlSnapshot(e,t,r){try{let{uploadUrl:o}=await this.client.generateHtmlSnapshotUploadUrl(e,t),i=await di(o,"text/html",r);if(!i.ok)throw new Error(`Failed to upload network logs: ${i.statusText}`)}catch(o){e.error({err:o},"Failed to upload html snapshot")}}async storeScreenshot(e,t,r){try{await this.client.uploadSnapshotScreenshot(e,t,{screenshot:r.toString("base64")})}catch(o){e.error({err:o},"Failed to upload screenshot")}}async storeA11yTreeSnapshot(e,t,r){return Promise.resolve()}async getConsoleLogsForRunAttempt(e,t,r){}async getNetworkLogsForRunAttempt(e,t,r){}async getHtmlSnapshot(e,t){}async getA11yTreeSnapshot(e,t){}async getScreenshot(e,t){}};var pi=class{constructor(e,t){this.client=e;this.orgId=t}async acquireCacheLock(e,t){return this.client.acquireCacheLock(e,t)}async uploadScreenshot(e){return(await this.client.uploadScreenshot({screenshot:e.toString("base64")})).key}async releaseCacheLock(e){return this.client.releaseCacheLock(e)}async deleteCacheResult(e){return this.client.deleteCacheResult(e)}async setCacheResult(e){return this.client.setCacheResult(e)}async getCacheResult(e){return this.client.getCacheResult(e)}fetchIconKnowledgeBase(e){return this.client.fetchIconKnowledgeBase(e)}saveNewIcons(e,t){return this.client.saveNewIcons(e,t)}};import{Faker as VP,en as qP}from"@faker-js/faker";var ui="v1",Sr=class{httpClient;fakerInstance;type="API_CLIENT";sms={send:this.sendSms.bind(this),fetchLatest:this.fetchLatestSms.bind(this)};email={send:this.sendEmail.bind(this),fetchLatest:this.fetchLatestEmail.bind(this),fetchAll:this.fetchAllEmails.bind(this)};ai={generate:this.sendAiGenerate.bind(this)};constructor(e){this.httpClient=e.httpClient,e.fakerSeed&&(this.fakerInstance=new VP({locale:qP}),this.fakerInstance.seed(e.fakerSeed))}async sendAiGenerate(e){let t=typeof e=="string"?{input:e}:e;return this.httpClient.sendRequest(`/${ui}/tools/ai/generate`,{method:"POST",body:t}).catch(r=>{throw r instanceof bn?new Error(r.rawError):new Error(`Failed to send AI generation: ${r.message}`)})}async sendSms(e){return this.httpClient.sendRequest(`/${ui}/tools/sms/send`,{method:"POST",body:e}).then(()=>{}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to send sms: ${t.message}`)})}async fetchLatestSms(e){return this.httpClient.sendRequest(`/${ui}/tools/sms/fetchLatest`,{method:"POST",body:e}).catch(t=>{throw t instanceof bn?new Error(t.rawError):t})}async sendEmail(e){return this.httpClient.sendRequest(`/${ui}/tools/email/send`,{method:"POST",body:e}).then(()=>{}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to send email: ${t.message}`)})}async fetchAllEmails(e){return this.httpClient.sendRequest(`/${ui}/tools/email/fetchAll`,{method:"POST",body:e}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to fetch all emails: ${t.message}`)})}async fetchLatestEmail(e){return this.httpClient.sendRequest(`/${ui}/tools/email/fetchLatest`,{method:"POST",body:e}).catch(t=>{throw t instanceof bn?new Error(t.rawError):new Error(`Failed to fetch latest emails: ${t.message}`)})}};import{z as KP}from"zod";var mi=class extends Ft{agentConfig;constructor(e,t){super(t),this.agentConfig=e}async rankChunksWithAi(e,t){let r={...e,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/recommend-chunks-ai`,{method:"POST",body:r,signal:t.abortSignal});return vh.parse(o)}async rankChunksWithRag(e,t){let r=await this.sendRequest(`/${$}/web-agent/recommend-chunks`,{method:"POST",body:{cliVersion:ka,...e},signal:t.abortSignal});return wh.parse(r)}async getScreenshotFromS3(e){let t=await this.sendRequest(`/${$}/s3/visual-diff-screenshot`,{method:"POST",body:{url:e}});return KP.string().parse(t)}async getElementLocation(e,t){let r={...e,disableCache:t.disableCache,loggerTags:t.loggerTags,useMemory:t.useMemory,agentConfigVersion:this.agentConfig?.locator},o=await this.sendRequest(`/${$}/web-agent/locate-element`,{method:"POST",body:r,signal:t.abortSignal});return Eg.parse(o)}async getAssertionResult(e,t){let r={...e,disableCache:!!t.disableCache,useConsensus:!!t.useConsensus,attemptNumber:t.attemptNumber,loggerTags:t.loggerTags,useMemory:t.useMemory,agentConfigVersion:this.agentConfig?.locator},o=await this.sendRequest(`/${$}/web-agent/assertion`,{method:"POST",body:r,signal:t.abortSignal});return Td.parse(o)}async getLintStepResult(e,t){let r={...e,disableCache:!!t.disableCache,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/lint/step`,{method:"POST",body:r,signal:t.abortSignal});return Tg.parse(o)}async getVisualAssertionResult(e,t){let r={...e,disableCache:!!t.disableCache,useConsensus:!!t.useConsensus,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/visual-assertion`,{method:"POST",body:r,signal:t.abortSignal});return Td.parse(o)}async getAiActionCommand(e,t){let r=await this.sendRequest(`/${$}/web-agent/next-command-dynamic`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal});return xg.parse(r)}async getMultiturnAiActionCommand(e,t){return await this.sendRequest(`/${$}/web-agent/ai-action/next-command`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal})}async getMultiturnAiActionEvaluation(e,t){let r=await this.sendRequest(`/${$}/web-agent/ai-action/evaluate`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal});return zc.parse(r)}async getReverseMappedDescription(e,t){let r=await this.sendRequest(`/${$}/web-agent/reverse-mapped-description`,{method:"POST",body:{...e,disableCache:t.disableCache,loggerTags:t.loggerTags},signal:t.abortSignal});return Cg.parse(r)}async getTextExtraction(e,t){let r={...e,disableCache:t.disableCache,loggerTags:t.loggerTags},o=await this.sendRequest(`/${$}/web-agent/text-extraction`,{method:"POST",body:r,signal:t.abortSignal});return Bc.parse(o)}async getTestResultClassification(e,t){let r=await this.sendRequest(`/${$}/web-agent/result-classification`,{method:"POST",body:{...e,loggerTags:t.loggerTags},signal:t.abortSignal});return Zc.parse(r)}async getExtractedKeywords(e,t){let r=await this.sendRequest(`/${$}/web-agent/extract-keywords`,{method:"POST",body:{goal:e,disableCache:t.disableCache,context:e},signal:t.abortSignal});return Lh.parse(r)}async getAutohealingProposal(e,t){let r=await this.sendRequest(`/${$}/web-agent/autoheal-section`,{method:"POST",body:{...e,loggerTags:t.loggerTags},signal:t.abortSignal});return ym.parse(r)}async getFailureRecoveryProposal(e,t){let r=await this.sendRequest(`/${$}/web-agent/failure-recovery`,{method:"POST",body:{...e,loggerTags:t.loggerTags},signal:t.abortSignal});return bm.parse(r)}async getIframeRegex(e,t){let r=await this.sendRequest(`/${$}/web-agent/iframe-regex`,{method:"POST",body:e,signal:t.abortSignal});return Qu.parse(r)}};var hi=class extends Ft{generator;constructor(e,t){super(e),this.generator=t}async runTemplateMatching(e,t={}){let r=await this.sendRequest(`/${$}/web-agent/template-matching`,{method:"POST",body:e,signal:t?.signal});return em.parse(r)}async constructIframeRegex(e,t={}){return this.generator.getIframeRegex(e,{abortSignal:t.signal})}};var vl=class{constructor(e){this.client=e}async uploadResultsArchive(e,t){let{uploadUrl:r,id:o}=await this.client.generateTestResultsUploadUrl(),i=await di(r,"application/zip",t);if(!i.ok)throw new Error(`Failed to upload test results: ${await i.text()}`);let{runGroupId:a}=await this.client.startProcessingResultsUpload(o,{runGroupId:e});return a}};function gi({orgId:n,client:e,gitMetadata:t,alwaysSaveCache:r,noCache:o}){return o?new Ya:new hp(n,e,t,r)}var hp=class{constructor(e,t,{gitMainBranch:r,gitBranchName:o,gitProtectedBranches:i,gitCommitTimestamp:a,lastCommitOnMainSha:s,lastCommitOnMainTimestamp:l},c){this.orgId=e;this.client=t;this.cacheHeaders={},r&&(this.cacheHeaders[Sg]=r),o&&(this.cacheHeaders[yg]=o),a&&(this.cacheHeaders[bg]=a.toISOString()),s&&(this.cacheHeaders[wg]=s),l&&(this.cacheHeaders[vg]=l.toISOString()),c?this.writeCaches=!0:o?this.writeCaches=!i.includes(o):this.writeCaches=!0}cacheHeaders;writeCaches;async saveStepCacheEntries({entries:e,testId:t,logger:r}){if(!this.writeCaches){r.debug("Skipping cache storage because branch is protected");return}try{await this.client.updateStepCaches({entries:e,testId:t},this.cacheHeaders)}catch(o){r.error({err:o},"Failed to save step cache entries")}}async resolveStepCacheEntries(e){let{steps:t,beforeSteps:r,afterSteps:o}=e.stepLists,i=await this.client.getStepCacheForTest({testId:e.testId,steps:t,schemaVersion:e.schemaVersion},this.cacheHeaders);if(!this.writeCaches){e.logger.debug("Skipping cache last used at update because branch is protected");return}for(let s of[t,r,o])s&&$o({steps:s,stepCacheEntries:i,logger:e.logger});let{cachesToSave:a}=await Dt({stepLists:e.stepLists,cacheCreationParams:{testId:e.testId,orgId:this.orgId}});this.client.updateStepCaches({entries:a,testId:e.testId},this.cacheHeaders)}};import ek from"path";import{Server as CN}from"socket.io";import{cloneDeep as YP}from"lodash-es";var JP={showOverlay:!1},gp=class{sessions=new Map;sessionCountByIp=new Map;getCurrentConnectionsByIp(e){return this.sessionCountByIp.get(e)??0}getCurrentSessionsByIp(){return Object.fromEntries(this.sessionCountByIp)}reserveCapacityByIp(e){e&&this.sessionCountByIp.set(e,(this.sessionCountByIp.get(e)??0)+1)}releaseCapacityByIp(e){e&&this.sessionCountByIp.set(e,Math.max(this.getCurrentConnectionsByIp(e)-1,0))}registerSession({controller:e,context:t,cleanup:r,clientIp:o,sessionId:i,browserbaseSessionId:a}){return this.sessions.set(i,{controller:e,context:t,cleanup:r,clientIp:o,browserbaseSessionId:a,browserBehavior:YP(JP)}),i}removeSession(e,t){(async()=>{let o=this.sessions.get(e);if(!o)return;this.releaseCapacityByIp(o.clientIp);let{controller:i}=o;try{i.setClosed(),await i.browser.cleanup()}catch(a){t.error({err:a},"Error cleaning up browser in global state manager")}try{await o.cleanup?.()}catch(a){t.error({err:a},"Error running cleanup function in global state manager")}this.sessions.delete(e)})()}getSession(e){return this.sessions.get(e)}},Z=new gp;function fy(n,e,t){let r=Date.now(),o=Date.now(),i,a,s,l,c=!1,d=async(h,g)=>{if(!h.closed&&!h.isInPageLoad)try{let f=s;s=void 0;let S=h.url(),w=g.toEditorDisplayCopy();JSON.stringify(w)===JSON.stringify(i)&&S===l&&r>o||(n.emit("browserState",{logsPerPage:f?.logsPerPage,harPages:f?.harPages,harEntries:f?.harEntries,viewport:h.getViewport(),url:S,iframeSrcUrls:a??[],context:w,isInPageLoad:h.isInPageLoad}),r=Date.now()),l=S,i=w}catch(f){if(!n.connected)return;let S=f instanceof Error?f.message:`${f}`;if(S.includes("Frame was detached")||S.includes("Not attached to an active page")||S.includes("browser has been closed")||S.includes("UserInfrastructureError"))return;t.error({err:f,sessionId:e},"Error grabbing browser state")}},p=setInterval(()=>{let h=Z.getSession(e),g=h?.controller?.browser;if(!g||g.closed){t.debug("Clearing browser state socket cron due to the browser being closed"),clearInterval(p);return}d(g,h.context)},1e3),u=(h,g)=>!!(JSON.stringify(h)!==JSON.stringify(a)||g.logsPerPage.some(f=>f.length>0)||g.harPages&&Object.keys(g.harPages).length>0||g.harEntries&&Object.keys(g.harEntries).length>0),m=setInterval(async()=>{let g=Z.getSession(e)?.controller?.browser;if(!g||g.closed){clearInterval(m);return}else if(c)return;c=!0;try{let f=await g.getAllFrameUrls(),S=g.retrieveAndClearDebugData();u(f,S)&&(a=f,s=S,o=Date.now())}catch(f){t.warn({err:f},"Failed to fetch extended details")}finally{c=!1}},2500);return{timers:[p,m]}}var yr={};var XP=n=>()=>{let{sessionId:e}=n.metadata;yr[e]?.abort?.abort()},Sy={event:"cancelApiTest",createHandler:XP};import{CookieJar as fL}from"tough-cookie";import{randomUUID as iL}from"crypto";import{faker as ZP}from"@faker-js/faker";import QP from"assert";import eL from"axios";import tL from"moment";import*as nL from"otpauth";import rL from"pg";async function yy(n){let e;try{e=new URL(n.url).hostname}catch{}let t=[];return n.headers.getSetCookie()?.forEach(r=>{let o=Ms(r,e);t.push(...o)}),t}var oL=Object.getPrototypeOf(async function(){}).constructor;async function by(n,e,t){let r=e.code;e.options.fragment&&(r=`return ${e.code}`);let{env:o}=e.bindings,i=e.tools,a={},s=(f,S)=>{o[f]=S,a[f]=S},l={},c=(f,S)=>{o[f]=S,l[f]=S},d;r.includes("Octokit")&&(d=(await import("@octokit/rest")).Octokit);let p;r.includes("createAppAuth")&&(p=(await import("@octokit/auth-app")).createAppAuth);let u=async()=>await Promise.resolve(new oL("axios","moment","faker","assert","pg","Octokit","createAppAuth","OTPAuth","extractCookiesFromResponse","env","setVariable","setPersistentVariable","sendSms","waitForLatestSms","email","sms","ai",r)(eL,tL,i.fakerInstance??ZP,QP,rL,d,p,nL,yy,o,s,c,S=>i.sms.send(S),S=>i.sms.fetchLatest(S),i.email,i.sms,i.ai)),m=!0,h,g;try{h=await U(u(),{milliseconds:e.options.timeoutMs,message:`Timeout of ${e.options.timeoutMs}ms exceeded for code execution`,signal:e.signal})}catch(f){t.error({err:f,env:o,evalCode:r},`[${n}] Error executing code: ${f}`),m=!1,f instanceof fr?g=`Timeout of ${e.options.timeoutMs}ms exceeded for code execution`:g=f instanceof Error?f.message:`${f}`}return{result:h,variableUpdates:a,persistentVariableUpdates:l,success:m,error:g}}async function wy({code:n,fragment:e,context:t,localTools:r,logger:o,signal:i,timeoutMs:a=lr}){let s=iL(),l=await by(s,{code:n,options:{fragment:e,timeoutMs:a},bindings:t.toObjectCopy(),tools:r,signal:i},o);return b.debug(`[${s}] Got execution result: ${JSON.stringify(l)}`),l}import{createHmac as aL,randomUUID as sL}from"crypto";import lL from"fetch-retry";var cL=lL(global.fetch,{retries:3,retryOn:function(n,e,t){return!!(e!==null||t&&t.status>=500)},retryDelay:function(n){return Math.pow(2,n)*500}}),vy=process.env.GCP_JS_EVAL_FUNCTION_ENDPOINT,xy=process.env.MOMENTIC_LAMBDA_AUTH_SECRET;async function Ty({orgId:n,code:e,fragment:t,context:r,timeoutMs:o=lr,retries:i=2,signal:a,logger:s}){if(!vy)throw new Error("GCP_JS_EVAL_FUNCTION_ENDPOINT environment variable not set");let l,c,d=0;if(!xy)throw new Error("Missing lambda auth secret.");let p=aL("sha256",xy).update(n).digest("hex");for(;d<=i;){d++,a?.throwIfAborted();let m={id:sL(),orgId:n,momenticLambdaAuthHash:p,code:e,fragment:t,state:r.toObjectCopy(),timeoutMs:o};try{if(l=await U(cL(vy,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)}),{milliseconds:o,message:`Timeout of ${o}ms exceeded for code execution`,signal:a}),!l)throw new Error("Got empty response from code evaluation server");if(!l.ok)throw new Error(`Code evaluation server returned error code ${l.status}`);c=void 0;break}catch(h){c=h}}if(c)throw s.error({err:c},"Failed to evaluate code remotely"),c;if(!l)throw new Error(`An unexpected code evaluation error occurred${c?`: ${c}`:""}`);let u;try{u=Uh.parse(await l.json())}catch(m){throw new Error(`Code evaluation server returned invalid response: ${m}`)}if(u.error)throw new Error(`Code evaluation error: ${u.error}`);return u}async function Kn(n){let e;if(process.env.GCP_JS_EVAL_FUNCTION_ENDPOINT)e=await Ty(n);else if(n.localTools)e=await wy({...n,localTools:n.localTools});else throw new Error("No code evaluation environment available");if(e.error){let t=`Failed to evaluate code:
|
|
50
50
|
${e.error}
|
|
51
51
|
Code received:
|
|
52
52
|
${n.code}`;throw n.logger.error({err:e.error,code:n.code,env:n.context.toObjectCopy()},t),new Error(t)}if(e.variableUpdates)for(let[t,r]of Object.entries(e.variableUpdates))n.context.setVariable(t,r);if(e.persistentVariableUpdates&&Object.keys(e.persistentVariableUpdates).length>0){await n.callbacks?.onPersistentVariableUpdates?.(e.persistentVariableUpdates);for(let[t,r]of Object.entries(e.persistentVariableUpdates))n.context.setVariable(t,r)}return e.result}import{set as dL}from"lodash-es";async function Gt(n){let{orgId:e,s:t,context:r,logger:o,signal:i,flagStore:a,retries:s=2,timeoutMs:l=lr,allowUndefined:c=!1}=n,d=/{{(.*?)}}/g,p=t.matchAll(d),u=t;for(let m of p){if(m.length<2)continue;let h=m[1].trim(),g;try{g=await Kn({orgId:e,code:h,fragment:!0,context:r,timeoutMs:l,logger:o,retries:s,localTools:n.localTools,signal:i,flagStore:a})}catch(S){throw o.error({err:S,value:t},"Error evaluating template string"),S}if(g===void 0&&!c)throw new A("UserConfigurationError",`Template fragment '${h}' evaluated to undefined. Please ensure that the variable name is spelled correctly and it is only referenced after being assigned a value.`);let f=typeof g=="string"?g:`${g}`;f=f.replaceAll(/\$/g,"$$$$"),u=u.replace(m[0],f)}return u}async function fi(n){return Ey(n)}async function Ey({obj:n,bannedKeys:e,allowList:t,context:r,prefixPath:o=[],replacements:i=[],...a}){for(let s in n){if(e.includes(s))continue;let l=!1;if(t)if(t.includes(s))l=!0;else continue;let c=n[s],d=[...o,s];if(typeof c=="string"&&c.includes("{{")){let p=await Gt({s:c,context:r,...a});if(c===p)continue;i.push({path:d,original:c}),n[s]=p}else typeof c=="object"&&c!==null&&!Array.isArray(c)&&await Ey({obj:c,bannedKeys:e,context:r,prefixPath:d,replacements:i,allowList:l?void 0:t,...a})}return i}function Cy(n,e){for(let{path:t,original:r}of e)dL(n,t,r)}import pL from"fetch-retry";var u6=process.env.MAILINATOR_API_KEY,m6=pL(global.fetch,{retryOn:function(n,e,t){return n>3?!1:!!(e!==null||t&&t.status>=400)},retryDelay:function(n){return 500}});import mL from"fetch-cookie";import{cloneDeep as hL}from"lodash-es";var uL=3e4;async function xl({command:n,logger:e,baseUrl:t,fetchImplementation:r=fetch}){let o=n.timeout??uL/1e3,i=Object.fromEntries(Object.entries(n.headers||{}).filter(([m,h])=>m&&h)),a=new URLSearchParams;Object.entries(n.params||{}).filter(([m,h])=>m&&h).forEach(([m,h])=>{a.append(m,h)});let s=a.toString(),l;if(Go(n.url)&&(l=n.url),t&&Wo(n.url,t)&&(l=new URL(n.url,t).toString()),!l)throw new A("ActionFailureError",`Invalid URL: ${n.url}`);e.debug({url:l,searchParams:s,headers:i,body:n.body,method:n.method},"Making HTTP request");let d=await U((async()=>{let m=s?`${l}?${s}`:l;try{return await r(m,{headers:i,method:n.method,body:n.body})}catch(h){throw e.error({err:h},"Failed to make HTTP request"),new Error(`Failed to make HTTP request: ${h}`)}})(),{milliseconds:o*1e3,fallback:()=>{throw new A("ActionFailureError",`Fetch request timed out after ${o} seconds`)}});if(!d.ok){let m;try{m=await d.text()}catch(h){m=`Failed to read response body: ${h}`}throw new A("ActionFailureError",`Fetch request failed with status ${d.status}: ${m}`)}let p={};d.headers.forEach((m,h)=>{p[h]=m});let u={status:d.status,headers:p};if(d.headers.get("content-type")?.includes("json"))try{u.json=await d.json()}catch{}else d.headers.get("content-type")?.includes("text")&&(u.text=await d.text());return u}async function Ry(n){let{fixtures:e,inputs:t}=n,{context:r}=e,{orgId:o,step:i}=t,a=hL(i);await fi({obj:a,orgId:o,bannedKeys:["code"],...e});let s=await gL(n);return a.envKey&&s.data&&r.setVariable(a.envKey,s.data),s}async function gL(n){let{fixtures:e,inputs:t}=n,{step:r,orgId:o,baseUrl:i}=t,{cookieJar:a}=e,s=new Date;switch(r.type){case"JAVASCRIPT":{let c=await Kn({code:r.code,orgId:o,fragment:!!r.fragment,timeoutMs:r.timeout?r.timeout*1e3:void 0,...e});try{JSON.stringify(c)}catch(d){return{...r,startedAt:s,finishedAt:new Date,status:"FAILED",message:`JavaScript return value is not serializable: ${d instanceof Error?d.message:`${d}`}`}}return{...r,startedAt:s,finishedAt:new Date,message:"JavaScript code executed successfully",status:"SUCCESS",data:c}}case"REQUEST":{let c=mL(fetch,a),d=await xl({command:r,logger:e.logger,baseUrl:i,fetchImplementation:c});return{...r,startedAt:s,finishedAt:new Date,status:"SUCCESS",message:"Request executed successfully",data:d}}default:return(c=>{throw"If Typescript complains about the line below, you missed a case or break in the switch above"})(r)}}async function Ay(n){let{inputs:e,fixtures:t,callbacks:r}=n,{signal:o}=t,{steps:i,orgId:a,baseUrl:s}=e,{test:l,step:c}=r,d={startedAt:new Date,status:"RUNNING",results:[]},p=d.results,u=new fL,m={cookieJar:u,...t};for(let h of i){let g=new Date;c.onStarted?.(h.id);let f;try{o?.throwIfAborted(),f=await Ry({inputs:{step:h,baseUrl:s,orgId:a},fixtures:m})}catch(S){o?.aborted?f={...h,startedAt:g,finishedAt:new Date,status:"CANCELLED",message:"Step cancelled by user."}:f={...h,startedAt:g,finishedAt:new Date,status:"FAILED",message:`Step failed: ${S instanceof Error?S.message:`${S}`}`}}if(p.push(f),c.onFinished?.({result:f,cookies:ks(u,new URL(s).hostname)}),l.updateAttemptProgress?.({results:p}),f.status!=="SUCCESS"){d.status=f.status==="CANCELLED"?"CANCELLED":"FAILED";break}}return d.status==="RUNNING"&&(d.status="PASSED"),d.finishedAt=new Date,l.onFinished?.(),d}async function Iy(n){let{socket:e,storageFactory:t}=n,r=n.socket.id,{testId:o}=e.handshake.query;if(typeof o!="string")throw new Error(`Received invalid test ID that does not parse as a string: ${o}`);let i=await n.getOrgId({type:"api-test",testId:o}),a=await t(i),{baseUrl:s,envName:l,testName:c,environmentVariables:d}=await fp({testId:o,orgId:i,logger:n.logger,storage:a,authorization:n.authorization}),p={type:"api-test",orgId:await n.getOrgId({type:"api-test",testId:o}),testId:o,sessionId:r,latestContext:new Ot({baseUrl:s||"",currentUrl:s||"",variablesFromEnvironment:d,envName:l,testName:c})};return yr[r]=p,p}async function fp({testId:n,logger:e,storage:t,authorization:r}){let o=await t.fetchApiTestMetadata(n,e);if(!o)throw new Error(`Failed to fetch API test metadata for test ID: ${n}`);let i;r?.type==="API_KEY"&&(i=new Sr({httpClient:new Ft({...r,logger:e}),fakerSeed:void 0}));let a=o.envs?.find(d=>d.default),s;a&&(s=await t.fetchEnvironment(a.name,e));let l=o.baseUrl||s?.variables?.[Ve];if(!l)throw new Error("Base URL is empty in both API test options and the configured environment");let c={...s?.variables};return{baseUrl:l,envName:s?.name,testName:o.name,environmentVariables:c,localCodeEvalTools:i}}var SL=n=>async(e,t)=>{let{steps:r}=e,{authorization:o,metadata:i,socket:a,logger:s,flagStoreFactory:l,storageFactory:c}=n,{orgId:d,testId:p,sessionId:u}=i,m=s.child({testId:p,orgId:d,sessionId:u}),h=yr[u];if(!h)throw new Error(`No api testing session with id ${u} could be found. Please reconnect and try again.`);let g=new AbortController;h.abort=g;let f=h.latestContext,S=await c(d),{localCodeEvalTools:w,baseUrl:x}=await fp({testId:p,orgId:d,logger:m,storage:S,authorization:o}),y={context:f,logger:m,localTools:w,signal:g.signal,flagStore:await l(d)},R=await Ay({inputs:{steps:r,orgId:d,baseUrl:x},fixtures:y,callbacks:{test:{onFinished:()=>{a.emit("apiTestFinished")}},step:{onStarted:L=>{a.emit("apiStepStarted",L)},onFinished:L=>{a.emit("apiStepFinished",L)}}}});t({result:R})},Py={event:"executeApiTest",createHandler:SL};var yL=({metadata:n,logger:e})=>{let{sessionId:t}=n;return async()=>{e.info({sessionId:t},"Cancel event received");let r=Z.getSession(t);if(!r)throw new Error("No active session found");try{r.controller.setClosed()}catch{}}},Ly={event:"cancel",createHandler:yL};var bL=({metadata:n,logger:e})=>{let{sessionId:t}=n;return async(r,o)=>{let i=Z.getSession(t);if(!i)throw new Error("No active session found");i.controller.setOpen();let a=i.controller.browser;try{let l=(await a.getBrowserState({skipWait:!0})).serialize();e.debug({a11yTree:l},"Fetched a11y tree from the browser"),o({a11yTree:l})}catch(s){e.error({err:s},"Error fetching a11y tree from the browser"),o({err:s.message})}}},Oy={event:"fetchA11yTree",createHandler:bL};var wL=({metadata:n,logger:e})=>{let{sessionId:t}=n;return async(r,o)=>{let i=Z.getSession(t);if(!i)throw new Error("No active session found");i.controller.setOpen();let a=i.controller.browser;try{let s=await a.html();o({html:s})}catch(s){e.error({err:s},"Error fetching DOM from the browser"),s.name==="TimeoutError"?o({err:"Timed out fetching DOM tree. This page may be too large for Momentic to process."}):o({err:s.message})}}},My={event:"fetchDom",createHandler:wL};var vL=({metadata:n,logger:e})=>{let{sessionId:t,type:r}=n;return o=>{e.info({sessionId:t,reason:o},`Disconnect event received (${o})`),r==="e2e"?Z.removeSession(t,e):r==="api-test"&&delete yr[t]}},Ny={event:"disconnect",createHandler:vL};function an(n){let{result:e,nestedResults:t}=n;if(!n.nestedResults.length)return;let{firstMetadata:r,lastMetadata:o}=xL(t);TL(e,r,o);let i=[...n.asyncTasks];n.asyncTasks.push((async()=>{try{await EL(i,e,r,o)}catch(a){n.logger.error({result:n.result,err:a},"Error hoisting scalar result metadata")}})())}function xL(n){let e=n[0],t;for(;;){switch(e.type){case"PRESET_ACTION":{t=e;break}case"CONDITIONAL":if(e.assertion){t=e;break}break;case"AI_ACTION_DYNAMIC":case"AI_ACTION":case"MODULE":case"SECTION":case"IFRAME":if(!e.results.length){t=e;break}e=e.results[e.results.length-1];break;default:return(a=>{throw"If Typescript complains about the line below, you missed a case or break in the switch above"})(e)}if(t)break}let r=n[n.length-1],o;for(;;){switch(r.type){case"PRESET_ACTION":{o=r;break}case"AI_ACTION_DYNAMIC":case"CONDITIONAL":case"AI_ACTION":case"MODULE":case"SECTION":case"IFRAME":if(!r.results.length){o=r;break}r=r.results[r.results.length-1];break;default:return(a=>{throw"If Typescript complains about the line below, you missed a case or break in the switch above"})(r)}if(o)break}return{firstMetadata:t,lastMetadata:o}}function TL(n,e,t){e&&(n.beforeUrl=e.beforeUrl),t&&(n.afterUrl=t.afterUrl,n.data=t.data,t.status!=="SUCCESS"&&(n.message=t.message))}async function EL(n,e,t,r){await Promise.allSettled(n),t&&(e.beforeSnapshot=t.beforeSnapshot),r&&(e.afterSnapshot=r.afterSnapshot)}import _a from"os";import CL from"v8";var ky,Mn,RL=_a.platform(),AL=_a.cpus().map(n=>({model:n.model,speed:n.speed}));function _y(n){let e=()=>{try{let t=!1,r=IL(),o=PL();r.freeMemory<1e6&&(t=!0);let i=CL.getHeapStatistics(),a=i.used_heap_size,s=i.heap_size_limit;a/s>.9&&(t=!0),t?n.warn({memory:r,cpu:o,heapStats:i},"Critical resource usage metrics detected"):n.debug({memory:r,cpu:o},"Got machine resource usage metrics")}catch{}};return e(),{interval:setInterval(e,1e4),cpuMetadata:AL,platform:RL}}function IL(){let n=_a.totalmem(),e=_a.freemem(),t=n-e;return{totalMemory:n,freeMemory:e,usedMemory:t}}function PL(){let n=_a.cpus(),e=Date.now(),t={measurementTime:e,user:0,nice:0,sys:0,idle:0,irq:0,total:0};for(let o of n)t.user+=o.times.user,t.nice+=o.times.nice,t.sys+=o.times.sys,t.idle+=o.times.idle,t.irq+=o.times.irq;if(t.total=t.user+t.nice+t.sys+t.idle+t.irq,!Mn)return Mn=t,null;let r={user:t.user-Mn.user,nice:t.nice-Mn.nice,sys:t.sys-Mn.sys,idle:t.idle-Mn.idle,irq:t.irq-Mn.irq,total:t.total-Mn.total};return ky={measurementTime:e,intervalMs:e-Mn.measurementTime,user:r.user/r.total*100,nice:r.nice/r.total*100,sys:r.sys/r.total*100,idle:r.idle/r.total*100,irq:r.irq/r.total*100,total:100-r.idle/r.total*100},Mn=t,ky}import{hostname as kL}from"os";async function Fy(n){let{command:e,tracer:t,timeoutMs:r,targetingWrapper:o,disableCache:i,fixtures:a}=n,{logger:s,abortSignal:l}=a;if(e.target&&!ir(e.target))throw new Error("Element assertion with x/y is not supported yet");let c=e.assertion.type==="ELEMENT_EXISTENCE"&&e.assertion.negated&&(e.assertion.condition==="EXISTS"||e.assertion.condition==="VISIBLE"),d=Date.now(),p=0,u,m=500;for(;p<2||Date.now()-d<r;){p++,p>1&&await te(m,l),l?.throwIfAborted();try{let{newTarget:h,elementInteractedDisplayString:g,result:f}=await o({ctx:a.ctx,tracer:t,command:e,target:e.target,cache:e.cache?.target,action:async S=>LL(S.locator,n),options:{...e,disableCache:i,disableGlobalLocatorRedirect:!0,source:Mr(e)}});if(u={success:f.success,data:f.data,err:f.err,newTarget:h,elementInteractedDisplayString:g},!f.success){u=f,m=Math.min(m*2,1e4);continue}return u}catch(h){if(l?.throwIfAborted(),c)return{success:!0,thoughts:`The element described does not exist on the page: ${h.message}`};if(s.warn({err:h},"Element assertion ended in error, retrying..."),!(h instanceof A)||h.reason!="ActionFailureError")throw h;u={success:!1,err:h}}}if(!u)throw new Error(`Failed to evaluate manual element assertion in ${r}ms.`);return u}async function LL(n,{command:e,fixtures:t}){let r=e.assertion;await t.browser.highlight(n);let o=!0,i,a;switch(r.type){case"ELEMENT_CONTENT":{let s=await n.textContent()??"";if(a={elementTextContent:je(s,500,!0)},!Dy(s,r.value,r.operation,!!r.negated)){let l=r.negated?dr[r.operation]:pr[r.operation];o=!1,i=new A("AssertionFailureError",`The content ${l} '${r.value}': ${s}`)}break}case"ELEMENT_ATTRIBUTE":{a={elementOuterHtml:je(await n.evaluate(l=>l.cloneNode(!1).outerHTML),500,!0)};let s;try{s=await n.getAttribute(r.attr,{timeout:3e3})??""}catch(l){i=new A("AssertionFailureError",`The element does not have an attribute named ${r.attr}: ${l}`),o=!1;break}if(!Dy(s,r.value,r.operation,!!r.negated)){let l=r.negated?dr[r.operation]:pr[r.operation];o=!1,r.operation==="EXISTS"?i=r.negated?new A("AssertionFailureError",`The attribute ${r.attr} ${l}: ${s}`):new A("AssertionFailureError",`The attribute ${r.attr} ${l}`):i=new A("AssertionFailureError",`The attribute ${r.attr} ${l} '${r.value}': ${s}`)}break}case"ELEMENT_EXISTENCE":{switch(r.condition){case"VISIBLE":{o=await n.evaluate(async(l,c)=>{let d=Date.now();for(;Date.now()-d<c;){let p=l.getBoundingClientRect();if(p.width>0&&p.height>0)return!0;await new Promise(u=>setTimeout(u,250))}return!1},Rn*1e3);break}case"EDITABLE":{o=await n.isEditable({timeout:Rn*1e3});break}case"EXISTS":{o=!0;break}case"ENABLED":{o=await n.isEnabled({timeout:Rn*1e3});break}default:return(l=>{throw"If Typescript complains about the line below, you missed a case or break in the switch above"})(r.condition)}if(o=r.negated?!o:o,!o){let s=r.negated?Pd[r.condition]:Ld[r.condition];i=new A("AssertionFailureError",`The element ${s}`)}break}}return{success:o,data:a,err:i}}function Dy(n,e,t,r){let o;switch(t){case"CONTAINS":{o=n.includes(e);break}case"EQUALS":{o=n.trim()===e.trim();break}case"STARTS_WITH":{o=n.trim().startsWith(e);break}case"EXISTS":{o=n.trim().length>0;break}default:return(a=>{throw"If Typescript complains about the line below, you missed a case or break in the switch above"})(t)}return r?!o:o}import{Jimp as OL}from"jimp";async function Da(n,e){let t=await n.screenshot(e),r=await OL.fromBuffer(t);return{buffer:t,width:Math.ceil(r.bitmap.width??0),height:Math.ceil(r.bitmap.height??0)}}import{Jimp as Uy}from"jimp";import Sp from"jpeg-js";import ML from"pixelmatch";async function By({ctx:n,tracer:e,command:t,disableCache:r,browser:o,targetingWrapper:i,logger:a,screenshotStorage:s}){if(t.target&&!ir(t.target))throw new Error("Visual Diff with x/y is not supported yet");await o.waitForDOMStability({logger:a});let l={clearHighlights:!0,hideCaret:!0},c;t.target?.elementDescriptor?c=(await i({ctx:n,tracer:e,command:t,target:t.target,cache:t.cache?.target??t.target?.a11yData,action:async z=>Da(o,{locator:z.locator,...l}),options:{...t,disableCache:r,disableGlobalLocatorRedirect:!0}})).result:c=await Da(o,l);let d=await s.prepareGoldenScreenshotForComparison(a,t,c);if((c.height!==d.height||c.width!==d.width)&&a.debug({currHeight:c.height,currWidth:c.width,savedHeight:d.height,savedWidth:d.width},"Mismatched before and after visual diff screenshot sizes"),Math.abs(c.height-d.height)>10||Math.abs(c.width-d.width)>10){let H=`${c.width}x${c.height}`,z=`${d.width}x${d.height}`;return{fail:!0,thoughts:`Current screenshot (${H}) does not match saved screenshot dimensions (${z}) - did you change the size of the target or the viewport?`,beforeScreenshotOverride:d.buffer,afterScreenshotOverride:c.buffer,succeedImmediately:!1,urlAfterCommand:o.url()}}let p=await Uy.fromBuffer(c.buffer),u={width:c.width,height:c.height},m=await Uy.fromBuffer(d.buffer),h={width:d.width,height:d.height},g,f=u.width*u.height,S=h.width*h.height,w=Math.abs(u.height-h.height),x=Math.abs(u.width-h.width);if(f>S){let H=p.cover({w:h.width,h:h.height});c.buffer=await H.getBuffer("image/jpeg"),g="current",c.width=h.width,c.height=h.height}else if(S>f){let H=m.cover({w:u.width,h:u.height});d.buffer=await H.getBuffer("image/jpeg"),g="saved"}let y={data:Buffer.alloc(c.width*c.height*4),width:c.width,height:c.height},E=t.threshold??.1,R=ML(Sp.decode(d.buffer).data,Sp.decode(c.buffer).data,y.data,c.width,c.height,{threshold:E,diffColorAlt:[0,255,0]})/(c.width*c.height)*100,L=R>E*100,M=`Visual diff of ${R.toFixed(2)}% detected, which is ${L?"over":"under"} the threshold of ${E*100}%.`;if(g&&(M+=` The ${g} screenshot was cropped since it was taller by ${w} pixels and wider by ${x} pixels.`),L)throw new A("ActionFailureError",M);return{fail:L,thoughts:M,beforeScreenshotOverride:c.buffer,afterScreenshotOverride:Sp.encode(y,75).data,succeedImmediately:!1,urlAfterCommand:o.url()}}var NL=5e3;async function Tl({timeout:n=Rn,...e}){let t=Date.now(),r=n*1e3,o=r+1e4,i,a=0,s=500;for(;a-t<r;){if(Date.now()-t>o){e.logger.warn("Exceeded max system timeout for page assertion, exiting...");break}e.signal.throwIfAborted();let l=Date.now();i=await zy(e),a=Date.now();let c=a-l;if(c>1e3&&e.logger.warn({pageAssertDuration:c},"Page assertion took longer than expected"),!i.success)await te(s,e.signal),s=Math.min(Math.floor(s*1.5),NL);else return i}return i=await zy(e),i}async function zy({assertion:n,browser:e,flagStore:t}){switch(n.type){case"CONTENT":{let o,i=!1,a;try{let s;if(t.isBooleanFlagEnabled("auto_expand_iframes")){let l=await e.evaluateFunctionInAllFrames(Hy,{value:n.value,negated:!!n.negated,returnHtml:!1});i=n.negated?l.every(c=>c.evaluation):l.some(c=>c.evaluation),s=l.find(c=>c.pageHtml)?.pageHtml}else({evaluation:i,pageHtml:s}=await e.evaluateFunctionInPage(Hy,{value:n.value,negated:!!n.negated,returnHtml:!0},"checking page content"));if(!i){let l=n.negated?dr.CONTAINS:pr.CONTAINS;a=new A("AssertionFailureError",`The page ${l} '${n.value}'.`),o=s}}catch(s){a=new A("AssertionFailureError",`Failed to evaluate page content assertion: ${s instanceof Error?s.message:`${s}`}`)}return{success:i,err:a,data:i||!o?void 0:{pageContent:o}}}default:return(o=>{throw"If Typescript complains about the line below, you missed a case or break in the switch above"})(n.type)}}function Hy({value:n,negated:e,returnHtml:t}){let r=document.documentElement.outerHTML,o=r.includes(n)===!e;return r.length>1e4&&(r=r.slice(0,1e4)+"...TRUNCATED"),{evaluation:o,pageHtml:!o&&t?r:void 0}}var yp=async n=>{let{step:e,resolvedInputs:t}=n.moduleParams,{logger:r,context:o,storage:i,codeEvalTools:a,controller:s}=n.fixtures,l=s.browser,{orgId:c,runId:d}=n.inputs,p=s.executeAbortController.signal;Object.keys(t).length>0&&(o.setInputs(t),r.debug({inputs:t,moduleId:e.moduleId},"Set module inputs"));let u,m=!1,h,g;if(e.cacheConfig||e.defaultCacheAllInvocations){let f=e.cacheConfig?.cacheKey||e.defaultCacheKey||"",S=await Gt({orgId:c,s:f,context:o,logger:r,localTools:a,signal:p,flagStore:s.flagStore});g={orgId:c,cacheKeys:[S,...Object.entries(t).map(([x,y])=>`${x}:${y}`)]},r.debug({original:f,keyParams:g},"Module cache key params");let w=Date.now();for(;Date.now()-w<hg;){p?.throwIfAborted();let x=await i.getCacheResult(g);if(x){r.debug({cacheResult:x},"Got result from module execution cache"),u=El(e,t,"SUCCESS"),u.message="Used cached module result.",u.data=JSON.parse(x),m=!0;break}else r.debug({cacheKey:f,keyParams:g},"No cache result found, continuing with lock acquisition");let y=await i.acquireCacheLock({keyParams:g,clientMetadata:`hostName:${kL()};runId:${d}`},p);if(y.acquired){h=y.keyPrefix,r.info({cacheKeyPrefixIfLockAcquired:h,cacheKey:f,keyParams:g},"Acquired cache lock and proceeding with module execution");break}else r.debug({cacheKeyPrefixIfLockAcquired:h,cacheKey:f,keyParams:g},"Failed to acquire cache lock, retrying...");await te(2500+Math.random()*1e4,p)}}try{if(!u)u=await _L(n);else if(e.autoAuth){let f=Ns.safeParse(u.data);if(!f.success)throw new A("UserConfigurationError",`Cached authentication module result is not a valid storage state: ${f.error.message}`);r.debug("Automatically loading auth state after cached module result"),await l.loadAuthState(f.data);let S=!1,w=e.advanced?.cacheInvalidation;if(w&&w.type==="PAGE_CHECK"){let x={type:"CONTENT",value:w.substring},y=await Tl({timeout:Rn,assertion:x,browser:l,flagStore:s.flagStore,logger:r,signal:p});y.success?r.debug({invalResult:y},"Cached result still valid after page check, continuing..."):(r.info({invalResult:y},"Invalidating cached result due to page check failure"),S=!0)}if(g&&S)return await i.deleteCacheResult(g),yp(n)}}finally{try{h!==void 0&&!m&&u?.status==="SUCCESS"&&await DL({step:e,result:u,browser:s.browser,cacheKeyPrefix:h,logger:r,storage:i})}finally{h!==void 0&&await i.releaseCacheLock(h)}}return u},_L=async n=>{let{step:e,tracer:t}=n.moduleParams,r=El(e,n.moduleParams.resolvedInputs,"SUCCESS"),o=await t.startSubSteps(),{status:i,results:a}=await br(n.work,()=>n.executeStepList({...n,listParams:{steps:e.steps,containerName:`module ('${e.name}')`,tracer:o}}));return r.results=a,r.status=i,r.finishedAt=new Date,an({asyncTasks:n.work.asyncTasks,nestedResults:a,result:r,logger:n.fixtures.logger}),r};function El(n,e,t){let r={};return Object.entries(e).forEach(([i,a])=>{r[i]=JSON.stringify(a)}),{type:"MODULE",id:n.id,moduleId:n.moduleId,moduleName:n.name,startedAt:new Date,cacheConfig:n.cacheConfig,inputs:r,results:[],finishedAt:new Date,status:t}}async function jy({orgId:n,step:e,context:t,logger:r,flagStore:o,codeEvalTools:i,signal:a}){let s={};try{for(let l of e.parameters??[]){let c=e.inputs?.[l]??e.defaultParameters?.[l];if(!c){r.warn(`No value or default found for parameter '${l}' that is required by module '${e.name}'`);continue}s[l]=await Kn({orgId:n,code:c,fragment:!0,context:t,logger:r,localTools:i,signal:a,flagStore:o})}return s}catch(l){throw a?.throwIfAborted(),new A("UserConfigurationError",`Failed to evaluate module inputs: ${l}`)}}async function DL({step:n,result:e,browser:t,cacheKeyPrefix:r,logger:o,storage:i}){let a=n.cacheConfig?.cacheExpiryMs;(!a||a===Wg)&&(a=n.defaultCacheTtl??Vg);let s;n.autoAuth?s=JSON.stringify(await t.saveAuthState()):e.data!==void 0?s=JSON.stringify(e.data):s='""',o.debug({cacheKeyPrefix:r,ttlMs:a,truncatedCacheResultJson:bf(s)},"Setting module cache result"),await i.setCacheResult({result:s,keyPrefix:r,ttlMs:a})}async function wr(n,e,t){let r=new Date;try{return t.throwIfAborted(),await e()}catch(o){let i=new Date,a="FAILED",s;if(t.aborted||o instanceof DOMException&&o.name==="AbortError"?(s="Step aborted by user.",a="CANCELLED"):o instanceof A?s=`${o}`:s=`An unexpected error occurred: ${o.message}`,n.type==="RESOLVED_MODULE"){let l=El(n,{},"FAILED");return l.message=s,l.startedAt=r,l.finishedAt=i,l}return{...Ys(n),startedAt:r,finishedAt:i,status:a,data:null,message:s,results:[]}}}async function br(n,e){let t=!1;try{return n&&!n.state.failureRecoveryDisabled&&(n.state.failureRecoveryDisabled=!0,t=!0),await e()}finally{n&&t&&(n.state.failureRecoveryDisabled=void 0)}}import{randomUUID as $y}from"crypto";import{cloneDeep as UL}from"lodash-es";function Cl(n,e){n.state.healingDetails?n.state.healingDetails.push(e):n.state.healingDetails=[e]}var Rl=async n=>{let{step:e,tracer:t}=n.presetParams,{logger:r,controller:o,context:i,billingReporter:a}=n.fixtures,{collectDebugData:s}=n.options,{testMetadata:l,suiteMetadata:c}=n.inputs,d=e.command.type,p=r.child({commandType:d,stepId:e.id,commandId:e.command.id}),u=aa(e.command);n.work.asyncTasks.push(a.reportCreditsUsed(p,d,u,{testId:l?.id,testName:l?.name,suiteId:c?.id,suiteName:c?.name}));let m=o.browser.url(),h=new Date,g,f=$y(),S=$y();if(s)try{g=await o.browser.screenshot({retries:1,clearHighlights:!0,quality:75});let C=await o.browser.getRawCondensedHtml();t.attachBeforeHtmlSnapshot({logger:p,snapshotId:f,html:C}),n.work.asyncTasks.push(n.fixtures.debugDataStorage.storeHtmlSnapshot(p,f,C))}catch(C){p.debug({err:C},"Failed to take screenshot before step, likely because the page is still loading. This is non-fatal and does not affect the test.")}let w,x,y,E=Ps();try{let C=await o.executePresetCommand(E,t,e.command,i,l?.advanced.disableAICaching??!1);C.beforeScreenshotOverride&&(g=C.beforeScreenshotOverride),y=C.afterScreenshotOverride;let{proposedStep:R}=BL({work:n.work,step:e,newTargets:C.newTargets,logger:p}),L=new Date,M=o.browser.url();x={beforeUrl:m,afterUrl:M,startedAt:h,finishedAt:L,viewport:o.browser.getViewport(),status:C.fail?"FAILED":"SUCCESS",elementInteracted:C.elementInteracted},w={...e,message:C.thoughts??zL(C.newTargets)??"Successfully executed preset action.",beforeUrl:m,afterUrl:M,finishedAt:L,startedAt:h,status:C.fail?"FAILED":"SUCCESS",data:C.data,results:[x],details:E.details,proposedStep:R},"assertion"in e.command&&(w.message=C.thoughts||"Assertion passed.")}catch(C){p.error({message:C.message,stack:C.stack},`Failed executing preset step ${$r(e.command)}`);let R=o.browser.url(),L=new Date,M=C instanceof Error?C.message:`${C}`;C instanceof A&&C.getLastScreenshotBuffer()&&(y=C.getLastScreenshotBuffer()),x={beforeUrl:m,afterUrl:R,startedAt:h,finishedAt:L,viewport:o.browser.getViewport(),status:C instanceof DOMException&&C.name==="AbortError"?"CANCELLED":"FAILED",message:M},w={...e,startedAt:h,finishedAt:L,beforeUrl:m,afterUrl:R,status:C instanceof DOMException&&C.name==="AbortError"?"CANCELLED":"FAILED",message:M,failureReason:C instanceof A?C.reason:void 0,results:[x],details:E.details}}if(s)try{y||(y=await o.browser.screenshot({retries:1,quality:75}));let C=await o.browser.getRawCondensedHtml();t.attachAfterHtmlSnapshot({logger:p,snapshotId:S,html:C}),n.work.asyncTasks.push(n.fixtures.debugDataStorage.storeHtmlSnapshot(p,S,C))}catch(C){p.debug({err:C},"Failed store debug data after step, likely because the page is still loading. This is non-fatal and does not affect the test.")}return x.beforeSnapshot=f,w.beforeSnapshot=f,x.afterSnapshot=S,w.afterSnapshot=S,g&&(t.attachBeforeScreenshot({logger:p,snapshotId:f,screenshot:g}),n.work.asyncTasks.push(n.fixtures.debugDataStorage.storeScreenshot(p,f,g))),y&&(t.attachAfterScreenshot({logger:p,snapshotId:S,screenshot:y}),n.work.asyncTasks.push(n.fixtures.debugDataStorage.storeScreenshot(p,S,y))),w};function BL({work:n,step:e,newTargets:t,logger:r}){if(!t?.length)return{proposedStep:void 0};let o=e.command;uf(o,t,r);let i=t[0]?.description;if(i&&"target"in o&&o.target&&o.target.type==="description"){let a={...o,target:{...o.target,elementDescriptor:i}},s={...UL(e),command:a};return Cl(n,{type:"DESCRIPTION_UPDATE",thoughts:`Updated element description after the original element could not be found on the page. New element location reasoning: ${t[0]?.thoughts}`}),{proposedStep:s}}return{proposedStep:void 0}}function zL(n){if(n?.length){if(n.length===1&&n[0]?.thoughts)return n[0].thoughts;if(n.length===2&&n.every(e=>e.thoughts))return`Located first element: ${n[0]?.thoughts}
|
|
@@ -3826,7 +3826,7 @@ ${a.stack}`),l.status(500).send("Internal Server Error")}),n){let a=xv.static(n,
|
|
|
3826
3826
|
for /f "tokens=5" %a in ('netstat -ano ^| findstr :58888') do taskkill /PID %a /F
|
|
3827
3827
|
`)}import f_ from"events";import Sc from"fs";import S_ from"open";import fc from"path";import{fileURLToPath as y_}from"url";import wk from"diff-lines";import{gt as vk}from"semver";import{execSync as nk}from"child_process";import{platform as rk}from"os";function mu(){return Rv()?(b.dimmed("Setting device pixel ratio to 2 automatically since a Mac OS Retina screen was detected."),b.dimmed(`If you are using a low pixel-density monitor, you should manually set --pixel-ratio to 1 to avoid incorrect viewport calculations. Confirm your device's pixel-ratio at https://www.mydevice.io.
|
|
3828
3828
|
`),2):(b.dimmed("Setting device pixel ratio to 1."),b.dimmed(`If you are using Momentic on a high-pixel density (HiDPI) monitor, relaunch with the --pixel-ratio option to avoid incorrect viewport calculations. Confirm your device's pixel-ratio at https://www.mydevice.io.
|
|
3829
|
-
l.`),1)}function Rv(){return rk()==="darwin"&&nk("system_profiler SPDisplaysDataType").toString().includes("Retina")}function hu(n){Rv()&&n===1&&(b.warn("If you are using Momentic on a Retina screen, relaunch with the --pixel-ratio option to avoid incorrect viewport calculations."),b.warn("Confirm your device's pixel-ratio at https://www.mydevice.io."))}import ok from"@actions/exec";import ik from"@actions/io";import ak from"quote";import sk from"string-argv";async function Av(n,e=!0){let t=sk(n),r=await ik.which(t[0],!0),o=t.slice(1),i=ok.exec(ak(r),o,{delay:100});if(e)return i}import{existsSync as lk,statSync as ck}from"fs";var Ai=!!process.env.CI||!!process.env.GITHUB_ACTIONS||!!process.env.GITHUB_RUN_ID||!!process.env.GITLAB_CI||!!process.env.CI_COMMIT_SHA||!!process.env.JENKINS_URL||!!process.env.BUILD_NUMBER||!!process.env.JENKINS_HOME||!!process.env.CIRCLECI||!!process.env.CIRCLE_BUILD_NUM||!!process.env.TRAVIS||!!process.env.TRAVIS_BUILD_NUMBER||!!process.env.BITBUCKET_BUILD_NUMBER||!!process.env.BITBUCKET_COMMIT||!!process.env.CODEBUILD_BUILD_ID||!!process.env.TF_BUILD||!!process.env.BUILD_BUILDID||!!process.env.AGENT_ID||!!process.env.BUILDER_SA_EMAIL||!!process.env.HEROKU_TEST_RUN_ID||!!process.env.CI_NODE_INDEX||!!process.env.TEAMCITY_VERSION||!!process.env.BUILD_VCS_NUMBER||!!process.env.BUILDKITE||!!process.env.BUILDKITE_BUILD_NUMBER||!!process.env.APPVEYOR||!!process.env.APPVEYOR_BUILD_NUMBER||!!process.env.DRONE||!!process.env.DRONE_BUILD_NUMBER||!!process.env.SHIPPABLE||!!process.env.BUILD_URL||!!process.env.SEMAPHORE||!!process.env.SEMAPHORE_EXECUTABLE_UUID||!!process.env.WOODPECKER||!!process.env.CI_BUILD_NUMBER||!!process.env.WERCKER_MAIN_PIPELINE_STARTED||!!process.env.BUDDY_EXECUTION_ID;function Iv(n){try{return lk(n)&&ck(n).isDirectory()}catch(e){return b.error({err:e},`Error reading path ${n} during directory existence check`),!1}}import dk from"csv-parser";import{createReadStream as pk}from"fs";function gu(n){return new Promise((e,t)=>{let r=[];pk(n).pipe(dk()).on("data",o=>r.push(o)).on("end",()=>e(r)).on("error",o=>t(o))})}import Xl from"semver";import{z as Zl}from"zod";var vn="2.6.0",uk="https://registry.npmjs.org/momentic",mk=Zl.object({versions:Zl.record(Zl.string(),Zl.unknown()).optional()});async function Pv(n){try{await hk(n)}catch(e){b.warn({err:e},"Failed to check CLI version against NPM servers")}}async function hk(n){if(!vn){n.warn("Unable to check CLI version because CLI_VERSION is not set");return}let e;for(let r=0;r<2;r++)try{let o=await U(fetch(uk),{milliseconds:5e3});if(!o.ok)throw new Error(`Got error status code ${o.statusText}`);let i=await o.json();e=mk.parse(i).versions;break}catch(o){n.warn({err:o},"Failed to fetch npm registry data")}if(!e){n.warn("Failed to fetch npm registry data. Skipping version check.");return}let t;for(let r of Object.keys(e))Xl.valid(r)&&(!t||Xl.gt(r,t))&&Xl.gt(r,vn)&&Xl.lt(r,"2.0.0")&&!r.includes("alpha")&&(t=r);t&&(b.warn(`Update available: v${vn} -> v${t}`),b.warn("This version may be missing critical fixes, features, and security updates."),b.warn(`Run "npx momentic@${t} -V" to update`))}import{existsSync as fk,mkdirSync as Sk,statSync as yk}from"fs";import{dirname as bk}from"path";import Ov from"readline/promises";import{hostname as gk}from"os";var Q=Vl({app:"cli",clientToken:"pub7eb923f18fb3f1d42ac5eba8c5ea13a5",hostname:gk(),disableConsoleLogs:!0}).child({version:"2.6.0"});var fu=!1,Mv=(()=>{try{return yk("/.dockerenv"),!0}catch{return!1}})();async function St(n,e){if(Ai||fu||Mv)return!0;Q.flush(),await new Promise(a=>setTimeout(a,500));let t=Ov.createInterface({input:process.stdin,output:process.stdout}),r=n.split("."),o;if(r.length===1)o=n;else{let a=`${r.slice(0,r.length-1).join(".").trim()}.`;e?b.warn(a):b.log(a),o=r[r.length-1].trim()}let i=await t.question(`${o} ('y' for yes / n for no / 'A' to accept all) `);return t.close(),i==="A"?(fu=!0,setTimeout(()=>{fu=!1},3e3),!0):i.toLowerCase()==="y"}async function Su(n){let e=bk(n);return Iv(e)?fk(n)?St(`File '${Lv(n)}' already exists. Overwrite existing content?`,!0):!0:await St(`Directory '${Lv(e)}' doesn't exist. Create it now?`,!0)?(Sk(e,{recursive:!0}),!0):!1}function Lv(n){return n.replace(/(\s+)/g,"\\$1")}async function Nv(n,e){if(Ai||Mv)return e;let t=Ov.createInterface({input:process.stdin,output:process.stdout}),r=await t.question(`${n} `);return t.close(),r.trim()||e}async function kv({test:n,fragment:e,entities:t,client:r,logger:o,yes:i}){vk(e.schemaVersion,De)&&(b.error(`This version of the CLI does not support the schema version of the fragment (${e.schemaVersion}). Please update to the latest version of the CLI and retry this command.`),process.exit(1)),pf(e.steps).forEach(g=>{t.modules[g]||(b.error(`The test patch contains a module with id ${g} that could not be found in the current project. This suggests that either this test patch or your local file system may be out of date.`),process.exit(1))}),e.createdAt.getTime()<Date.now()-7*24*60*60*1e3&&!i&&!await St("The test patch you are applying is more than 7 days old. Are you sure you want to continue?",!0)&&process.exit(1);let s=n.lastModified.getTime();e.createdAt.getTime()+60*60*1e3<s&&!i&&!await St("The test patch you are applying was created before the test was last updated. Are you sure you want to continue?",!0)&&process.exit(1);let l=Zr(n.fullFilePath,o,t),c=l.steps;if(!Array.isArray(c))throw new Error(`Test ${n.fullFilePath} is missing steps array`);let d,p;if(e.schemaVersion!==De){let{steps:g,newVersion:f}=await pa({metadata:{id:e.id,schemaVersion:e.schemaVersion},steps:e.steps,logger:b});d=f,p=Pe.array().parse(g)}else p=Pe.array().parse(e.steps);let{stepsToSave:u,moduleUpdates:m}=await Dt({stepLists:{steps:p}});u.beforeSteps=l.beforeSteps??void 0,u.afterSteps=l.afterSteps??void 0;let h=wk(JSON.stringify(c,void 0,2),JSON.stringify(u,void 0,2),{n_surrounding:5});b.dimmed("=".repeat(30)),b.dimmed(h),b.dimmed("=".repeat(30)),b.dimmed(""),d&&b.warn(`If this patch is applied, your test will also be automatically upgraded to the latest schema version (${d}). Schema upgrades have no impact on functionality, although you may notice minor differences in the test YAML.`),!i&&!await St("Do you want to apply this patch?")&&(b.dimmed("Cancelled."),process.exit(1)),Wn({relativeTestPath:n.relativePath,steps:u,schemaVersion:d??e.schemaVersion,project:t.project}),b.success("Patch applied successfully."),await r.patchTestFragment(e.id,{applied:!0,appliedAt:new Date})}import{randomUUID as uo}from"crypto";import{z as Zv}from"zod";var Wt=" ".repeat(6);import Xv from"chalk";import{Argument as co,Option as Me}from"@commander-js/extra-typings";import{validateHeaderValue as xk}from"http";import{cpus as _v}from"os";import{parse as Che}from"yaml";import{z as q}from"zod";var Ql=58888,yu=30*60*1e3,Zn=new Me("--api-key <key>","API key for authentication. If not supplied, attempts to read the MOMENTIC_API_KEY env var."),Qn=new Me("--server <server>","Momentic server to use. Leave unchanged unless using Momentic on-premise."),po=new Me("-y, --yes","Skip all confirmation prompts.").env("CI"),bu=new Me("-w, --wait","Wait for tests to finish running before exiting. Only applicable when running tests remotely").implies({remote:!0}),wu=new Me("--wait-timeout <waitTimeout>",`The maximum number of seconds to wait for tests to complete. Only applicable when the --wait option is specified. Defaults to ${yu/1e3} seconds.`),ec=new Me("--custom-headers <customHeaders...>","Specify custom headers in the form HEADER=VALUE to be sent with each request during the test. Multiple entries can be provided."),Fv=new Me("--reporter <reporter>","Output report files in a standardized format to a local directory. See the --reporter-dir flag for information on the output directory.").choices(Object.values(na)),Uv=new Me("--reporter-dir <reporterDir>","Output directory to store report files. Relative paths are resolved relative to the project root, which is defined by the detected momentic.config.yaml. Defaults to 'reports' if unset."),vu=new Me("--output-dir <outputDir>","[Alpha] Output directory to store run artifacts such as screenshots, results, and logs. Relative paths are resolved relative to the project root, which is defined by the detected momentic.config.yaml. This directory will be cleared at the start of execution."),Bv=new Me("--upload-results","Upload test results to Momentic Cloud. By default, this option is disabled."),xu=new Me("--include <includePatterns...>","Only include tests that match the provided regex patterns. Multiple patterns can be provided. The patterns will be matched against the test file paths and the pattern only needs to match a part of the path for the test to be included."),Tu=new Me("--exclude <excludePatterns...>","The inverted version of --include: a test that matches any of the provided exclusion patterns will be excluded from running."),Eu=new Me("--pixel-ratio <pixelRatio>","Device pixel ratio of your screen or monitor. Mac OS Retina displays and machines marketed as 'HiDPI' should set this to 2. Visit https://www.mydevice.io/ to find your device's pixel ratio."),zv=new Me("--port <port>",`Port to run the app on. Defaults to ${Ql}.`),Cu=new Me("--input-csv <inputCsv>","Path to a CSV file on disk where each row represents a set of inputs that will be made available to all tests that are ran. The first line of the CSV must be the input names."),tc=new Me("--env <env>","Name of the environment to use when running tests."),nc=new Me("--url-override <urlOverride>","Fully qualified url (e.g. https://www.google.com) to start all tests from. Overrides any default starting url set from the test or environment."),Hv=new Me("--shard-index <shardIndex>","The index of the shard to run tests for. Defaults to 1.").default(1).argParser(n=>parseInt(n,10)),xn=new Me("-c, --config <configPath>","Absolute or relative path to a Momentic configuration file (*.momentic.config.yaml)"),rc=new Me("-f, --filter <filter>","Run tests within the project that has a name equal to the filter provided. This option cannot be used together with file path or directory arguments, but substring matches are allowed."),jv=new Me("--shard-count <shardCount>","The number of shards that tests are being run on. Defaults to 1.").default(1).argParser(n=>parseInt(n,10)),$v=new Me("--fix","Attempt to fix any issues found. This option will write changes to your local file system."),Ru=new Me("--save-cache","Always save updated step caches after successful test runs. By default, caches are not saved when running on the protected branches configured in the momentic.config.yaml.").env("CI"),Au=new Me("--disable-cache","Disable caching of test results. This will cause all tests to be re-run every time."),Gv=new co("<tests...>",`One or more test paths to queue on Momentic Cloud.
|
|
3829
|
+
l.`),1)}function Rv(){return rk()==="darwin"&&nk("system_profiler SPDisplaysDataType").toString().includes("Retina")}function hu(n){Rv()&&n===1&&(b.warn("If you are using Momentic on a Retina screen, relaunch with the --pixel-ratio option to avoid incorrect viewport calculations."),b.warn("Confirm your device's pixel-ratio at https://www.mydevice.io."))}import ok from"@actions/exec";import ik from"@actions/io";import ak from"quote";import sk from"string-argv";async function Av(n,e=!0){let t=sk(n),r=await ik.which(t[0],!0),o=t.slice(1),i=ok.exec(ak(r),o,{delay:100});if(e)return i}import{existsSync as lk,statSync as ck}from"fs";var Ai=!!process.env.CI||!!process.env.GITHUB_ACTIONS||!!process.env.GITHUB_RUN_ID||!!process.env.GITLAB_CI||!!process.env.CI_COMMIT_SHA||!!process.env.JENKINS_URL||!!process.env.BUILD_NUMBER||!!process.env.JENKINS_HOME||!!process.env.CIRCLECI||!!process.env.CIRCLE_BUILD_NUM||!!process.env.TRAVIS||!!process.env.TRAVIS_BUILD_NUMBER||!!process.env.BITBUCKET_BUILD_NUMBER||!!process.env.BITBUCKET_COMMIT||!!process.env.CODEBUILD_BUILD_ID||!!process.env.TF_BUILD||!!process.env.BUILD_BUILDID||!!process.env.AGENT_ID||!!process.env.BUILDER_SA_EMAIL||!!process.env.HEROKU_TEST_RUN_ID||!!process.env.CI_NODE_INDEX||!!process.env.TEAMCITY_VERSION||!!process.env.BUILD_VCS_NUMBER||!!process.env.BUILDKITE||!!process.env.BUILDKITE_BUILD_NUMBER||!!process.env.APPVEYOR||!!process.env.APPVEYOR_BUILD_NUMBER||!!process.env.DRONE||!!process.env.DRONE_BUILD_NUMBER||!!process.env.SHIPPABLE||!!process.env.BUILD_URL||!!process.env.SEMAPHORE||!!process.env.SEMAPHORE_EXECUTABLE_UUID||!!process.env.WOODPECKER||!!process.env.CI_BUILD_NUMBER||!!process.env.WERCKER_MAIN_PIPELINE_STARTED||!!process.env.BUDDY_EXECUTION_ID;function Iv(n){try{return lk(n)&&ck(n).isDirectory()}catch(e){return b.error({err:e},`Error reading path ${n} during directory existence check`),!1}}import dk from"csv-parser";import{createReadStream as pk}from"fs";function gu(n){return new Promise((e,t)=>{let r=[];pk(n).pipe(dk()).on("data",o=>r.push(o)).on("end",()=>e(r)).on("error",o=>t(o))})}import Xl from"semver";import{z as Zl}from"zod";var vn="2.6.1",uk="https://registry.npmjs.org/momentic",mk=Zl.object({versions:Zl.record(Zl.string(),Zl.unknown()).optional()});async function Pv(n){try{await hk(n)}catch(e){b.warn({err:e},"Failed to check CLI version against NPM servers")}}async function hk(n){if(!vn){n.warn("Unable to check CLI version because CLI_VERSION is not set");return}let e;for(let r=0;r<2;r++)try{let o=await U(fetch(uk),{milliseconds:5e3});if(!o.ok)throw new Error(`Got error status code ${o.statusText}`);let i=await o.json();e=mk.parse(i).versions;break}catch(o){n.warn({err:o},"Failed to fetch npm registry data")}if(!e){n.warn("Failed to fetch npm registry data. Skipping version check.");return}let t;for(let r of Object.keys(e))Xl.valid(r)&&(!t||Xl.gt(r,t))&&Xl.gt(r,vn)&&Xl.lt(r,"2.0.0")&&!r.includes("alpha")&&(t=r);t&&(b.warn(`Update available: v${vn} -> v${t}`),b.warn("This version may be missing critical fixes, features, and security updates."),b.warn(`Run "npx momentic@${t} -V" to update`))}import{existsSync as fk,mkdirSync as Sk,statSync as yk}from"fs";import{dirname as bk}from"path";import Ov from"readline/promises";import{hostname as gk}from"os";var Q=Vl({app:"cli",clientToken:"pub7eb923f18fb3f1d42ac5eba8c5ea13a5",hostname:gk(),disableConsoleLogs:!0}).child({version:"2.6.1"});var fu=!1,Mv=(()=>{try{return yk("/.dockerenv"),!0}catch{return!1}})();async function St(n,e){if(Ai||fu||Mv)return!0;Q.flush(),await new Promise(a=>setTimeout(a,500));let t=Ov.createInterface({input:process.stdin,output:process.stdout}),r=n.split("."),o;if(r.length===1)o=n;else{let a=`${r.slice(0,r.length-1).join(".").trim()}.`;e?b.warn(a):b.log(a),o=r[r.length-1].trim()}let i=await t.question(`${o} ('y' for yes / n for no / 'A' to accept all) `);return t.close(),i==="A"?(fu=!0,setTimeout(()=>{fu=!1},3e3),!0):i.toLowerCase()==="y"}async function Su(n){let e=bk(n);return Iv(e)?fk(n)?St(`File '${Lv(n)}' already exists. Overwrite existing content?`,!0):!0:await St(`Directory '${Lv(e)}' doesn't exist. Create it now?`,!0)?(Sk(e,{recursive:!0}),!0):!1}function Lv(n){return n.replace(/(\s+)/g,"\\$1")}async function Nv(n,e){if(Ai||Mv)return e;let t=Ov.createInterface({input:process.stdin,output:process.stdout}),r=await t.question(`${n} `);return t.close(),r.trim()||e}async function kv({test:n,fragment:e,entities:t,client:r,logger:o,yes:i}){vk(e.schemaVersion,De)&&(b.error(`This version of the CLI does not support the schema version of the fragment (${e.schemaVersion}). Please update to the latest version of the CLI and retry this command.`),process.exit(1)),pf(e.steps).forEach(g=>{t.modules[g]||(b.error(`The test patch contains a module with id ${g} that could not be found in the current project. This suggests that either this test patch or your local file system may be out of date.`),process.exit(1))}),e.createdAt.getTime()<Date.now()-7*24*60*60*1e3&&!i&&!await St("The test patch you are applying is more than 7 days old. Are you sure you want to continue?",!0)&&process.exit(1);let s=n.lastModified.getTime();e.createdAt.getTime()+60*60*1e3<s&&!i&&!await St("The test patch you are applying was created before the test was last updated. Are you sure you want to continue?",!0)&&process.exit(1);let l=Zr(n.fullFilePath,o,t),c=l.steps;if(!Array.isArray(c))throw new Error(`Test ${n.fullFilePath} is missing steps array`);let d,p;if(e.schemaVersion!==De){let{steps:g,newVersion:f}=await pa({metadata:{id:e.id,schemaVersion:e.schemaVersion},steps:e.steps,logger:b});d=f,p=Pe.array().parse(g)}else p=Pe.array().parse(e.steps);let{stepsToSave:u,moduleUpdates:m}=await Dt({stepLists:{steps:p}});u.beforeSteps=l.beforeSteps??void 0,u.afterSteps=l.afterSteps??void 0;let h=wk(JSON.stringify(c,void 0,2),JSON.stringify(u,void 0,2),{n_surrounding:5});b.dimmed("=".repeat(30)),b.dimmed(h),b.dimmed("=".repeat(30)),b.dimmed(""),d&&b.warn(`If this patch is applied, your test will also be automatically upgraded to the latest schema version (${d}). Schema upgrades have no impact on functionality, although you may notice minor differences in the test YAML.`),!i&&!await St("Do you want to apply this patch?")&&(b.dimmed("Cancelled."),process.exit(1)),Wn({relativeTestPath:n.relativePath,steps:u,schemaVersion:d??e.schemaVersion,project:t.project}),b.success("Patch applied successfully."),await r.patchTestFragment(e.id,{applied:!0,appliedAt:new Date})}import{randomUUID as uo}from"crypto";import{z as Zv}from"zod";var Wt=" ".repeat(6);import Xv from"chalk";import{Argument as co,Option as Me}from"@commander-js/extra-typings";import{validateHeaderValue as xk}from"http";import{cpus as _v}from"os";import{parse as Che}from"yaml";import{z as q}from"zod";var Ql=58888,yu=30*60*1e3,Zn=new Me("--api-key <key>","API key for authentication. If not supplied, attempts to read the MOMENTIC_API_KEY env var."),Qn=new Me("--server <server>","Momentic server to use. Leave unchanged unless using Momentic on-premise."),po=new Me("-y, --yes","Skip all confirmation prompts.").env("CI"),bu=new Me("-w, --wait","Wait for tests to finish running before exiting. Only applicable when running tests remotely").implies({remote:!0}),wu=new Me("--wait-timeout <waitTimeout>",`The maximum number of seconds to wait for tests to complete. Only applicable when the --wait option is specified. Defaults to ${yu/1e3} seconds.`),ec=new Me("--custom-headers <customHeaders...>","Specify custom headers in the form HEADER=VALUE to be sent with each request during the test. Multiple entries can be provided."),Fv=new Me("--reporter <reporter>","Output report files in a standardized format to a local directory. See the --reporter-dir flag for information on the output directory.").choices(Object.values(na)),Uv=new Me("--reporter-dir <reporterDir>","Output directory to store report files. Relative paths are resolved relative to the project root, which is defined by the detected momentic.config.yaml. Defaults to 'reports' if unset."),vu=new Me("--output-dir <outputDir>","[Alpha] Output directory to store run artifacts such as screenshots, results, and logs. Relative paths are resolved relative to the project root, which is defined by the detected momentic.config.yaml. This directory will be cleared at the start of execution."),Bv=new Me("--upload-results","Upload test results to Momentic Cloud. By default, this option is disabled."),xu=new Me("--include <includePatterns...>","Only include tests that match the provided regex patterns. Multiple patterns can be provided. The patterns will be matched against the test file paths and the pattern only needs to match a part of the path for the test to be included."),Tu=new Me("--exclude <excludePatterns...>","The inverted version of --include: a test that matches any of the provided exclusion patterns will be excluded from running."),Eu=new Me("--pixel-ratio <pixelRatio>","Device pixel ratio of your screen or monitor. Mac OS Retina displays and machines marketed as 'HiDPI' should set this to 2. Visit https://www.mydevice.io/ to find your device's pixel ratio."),zv=new Me("--port <port>",`Port to run the app on. Defaults to ${Ql}.`),Cu=new Me("--input-csv <inputCsv>","Path to a CSV file on disk where each row represents a set of inputs that will be made available to all tests that are ran. The first line of the CSV must be the input names."),tc=new Me("--env <env>","Name of the environment to use when running tests."),nc=new Me("--url-override <urlOverride>","Fully qualified url (e.g. https://www.google.com) to start all tests from. Overrides any default starting url set from the test or environment."),Hv=new Me("--shard-index <shardIndex>","The index of the shard to run tests for. Defaults to 1.").default(1).argParser(n=>parseInt(n,10)),xn=new Me("-c, --config <configPath>","Absolute or relative path to a Momentic configuration file (*.momentic.config.yaml)"),rc=new Me("-f, --filter <filter>","Run tests within the project that has a name equal to the filter provided. This option cannot be used together with file path or directory arguments, but substring matches are allowed."),jv=new Me("--shard-count <shardCount>","The number of shards that tests are being run on. Defaults to 1.").default(1).argParser(n=>parseInt(n,10)),$v=new Me("--fix","Attempt to fix any issues found. This option will write changes to your local file system."),Ru=new Me("--save-cache","Always save updated step caches after successful test runs. By default, caches are not saved when running on the protected branches configured in the momentic.config.yaml.").env("CI"),Au=new Me("--disable-cache","Disable caching of test results. This will cause all tests to be re-run every time."),Gv=new co("<tests...>",`One or more test paths to queue on Momentic Cloud.
|
|
3830
3830
|
|
|
3831
3831
|
A test path is a lowercased version of your test name where spaces are replaced with dashes: 'npx momentic pull hello-world'.`),Wv=new co("<tests...>",`One or more test paths to import from Momentic Cloud.
|
|
3832
3832
|
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "momentic",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "momentic",
|
|
9
|
-
"version": "2.6.
|
|
9
|
+
"version": "2.6.1",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@actions/exec": "^1.1.1",
|
|
12
12
|
"@actions/io": "^1.1.3",
|