@testrelic/maestro-analytics 1.2.0 → 1.2.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/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
- 'use strict';var core=require('@testrelic/core'),fs=require('fs'),path=require('path'),fastXmlParser=require('fast-xml-parser'),yaml=require('yaml'),child_process=require('child_process'),os=require('os'),crypto=require('crypto'),url=require('url'),zlib=require('zlib'),stream=require('stream');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;var pt=".testrelic",Tr="testrelic-config.json",Ir=".testrelic",Mr=5,Er=new Set(["__proto__","constructor","prototype"]),ge=Object.freeze({apiKey:null,endpoint:"https://platform.testrelic.ai/api/v1",uploadStrategy:"batch",timeout:3e4,projectName:null,queueMaxAge:6048e5,queueDirectory:`${pt}/queue`,uploadArtifacts:true,artifactMaxSizeMb:50}),Fr={s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3};function he(e){let t=path.resolve(e);for(let r=0;r<=Mr;r++){let n=path.join(t,pt,Tr);if(fs.existsSync(n))try{if(fs.statSync(n).isFile())return n}catch{}let o=path.join(t,Ir);if(fs.existsSync(o))try{if(fs.statSync(o).isFile())return process.stderr.write(`[testrelic] Deprecation: config file ".testrelic" has moved to ".testrelic/testrelic-config.json". Please migrate your config file to the new location.
2
- `),o}catch{}let s=path.dirname(t);if(s===t)break;t=s;}return null}function be(e){try{let t=fs.readFileSync(e,"utf-8"),r=JSON.parse(t);return typeof r!="object"||r===null||Array.isArray(r)||!ft(r)?null:r}catch{return null}}function ft(e){for(let t of Object.keys(e)){if(Er.has(t))return false;let r=e[t];if(typeof r=="object"&&r!==null&&!Array.isArray(r)&&!ft(r))return false}return true}function K(e){let t=/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(e);if(t)return process.env[t[1]]??null;let r=/^\$([A-Za-z_][A-Za-z0-9_]*)$/.exec(e);return r?process.env[r[1]]??null:e}function X(e){let t=Object.create(null);for(let r of Object.keys(e)){let n=e[r];typeof n=="string"&&n.startsWith("$")?t[r]=K(n):typeof n=="object"&&n!==null&&!Array.isArray(n)?t[r]=X(n):t[r]=n;}return t}function me(e){let t=/^(\d+)\s*([smhd])$/.exec(e.trim());if(!t)return null;let r=parseInt(t[1],10),n=t[2],o=Fr[n];return !o||r<=0?null:r*o}function ye(e,t){let r=Object.create(null);if(Object.assign(r,ge),e){let l=e.cloud;l&&typeof l=="object"&&(typeof l.endpoint=="string"&&(r.endpoint=l.endpoint),typeof l.upload=="string"&&(r.uploadStrategy=l.upload),typeof l.timeout=="number"&&(r.timeout=l.timeout),typeof l.apiKey=="string"&&l.apiKey.length>0&&(r.apiKey=l.apiKey));let c=e["testrelic-repo"]??e.project;c&&typeof c=="object"&&typeof c.name=="string"&&(r.projectName=c.name);let d=e.queue;if(d&&typeof d=="object"){if(typeof d.maxAge=="string"){let u=me(d.maxAge);u!==null&&(r.queueMaxAge=u);}typeof d.directory=="string"&&(r.queueDirectory=d.directory);}}if(t){if(typeof t.apiKey=="string"&&t.apiKey.length>0){let l=t.apiKey.startsWith("$")?K(t.apiKey):t.apiKey;l&&(r.apiKey=l);}if(typeof t.endpoint=="string"){let l=t.endpoint.startsWith("$")?K(t.endpoint):t.endpoint;l&&(r.endpoint=l);}if(typeof t.upload=="string"&&(r.uploadStrategy=t.upload),typeof t.timeout=="number"&&(r.timeout=t.timeout),typeof t.projectName=="string"&&(r.projectName=t.projectName),typeof t.queueMaxAge=="string"){let l=me(t.queueMaxAge);l!==null&&(r.queueMaxAge=l);}typeof t.queueDirectory=="string"&&(r.queueDirectory=t.queueDirectory),typeof t.uploadArtifacts=="boolean"&&(r.uploadArtifacts=t.uploadArtifacts),typeof t.artifactMaxSizeMb=="number"&&(r.artifactMaxSizeMb=t.artifactMaxSizeMb);}let n=process.env.TESTRELIC_API_KEY;n&&n.length>0&&(r.apiKey=n);let o=process.env.TESTRELIC_CLOUD_ENDPOINT;o&&core.isValidEndpointUrl(o)&&(r.endpoint=o);let s=process.env.TESTRELIC_UPLOAD_STRATEGY;s&&["batch","realtime","both"].includes(s)&&(r.uploadStrategy=s);let i=process.env.TESTRELIC_CLOUD_TIMEOUT;if(i){let l=parseInt(i,10);!isNaN(l)&&l>=1e3&&l<=12e4&&(r.timeout=l);}let a=Object.freeze(r);return core.isValidCloudConfig(a)?a:ge}var Lr=["authorization","cookie","set-cookie","x-api-key"],Dr=["password","secret","token","apiKey","api_key"],Nr=1024*1024;function Or(e){let t=e??{},r=process.env.TESTRELIC_CAPTURE_NETWORK==="1"||process.env.TESTRELIC_CAPTURE_NETWORK?.toLowerCase()==="true";return Object.freeze({enabled:t.enabled??r??false,proxyPort:t.proxyPort??(process.env.TESTRELIC_PROXY_PORT?Number.parseInt(process.env.TESTRELIC_PROXY_PORT,10):8080),proxyHost:t.proxyHost??process.env.TESTRELIC_PROXY_HOST??"127.0.0.1",harPath:t.harPath??process.env.TESTRELIC_HAR_PATH??null,outputDir:t.outputDir??null,skipCertInstall:t.skipCertInstall??false,includeUrls:Object.freeze(t.includeUrls?[...t.includeUrls]:[]),excludeUrls:Object.freeze(t.excludeUrls?[...t.excludeUrls]:[]),redactHeaders:Object.freeze(t.redactHeaders?[...t.redactHeaders]:[...Lr]),redactBodyFields:Object.freeze(t.redactBodyFields?[...t.redactBodyFields]:[...Dr]),maxBodyBytes:t.maxBodyBytes??Nr})}var Ur=new Set(["__proto__","constructor","prototype"]);function gt(e){if(typeof e!="object"||e===null)return false;for(let t of Object.keys(e))if(Ur.has(t))return true;return false}function Hr(e){if(typeof e!="object"||e===null||gt(e))return false;let t=e;return !(t.outputPath!==void 0&&typeof t.outputPath!="string"||t.htmlReportPath!==void 0&&typeof t.htmlReportPath!="string"||t.openReport!==void 0&&typeof t.openReport!="boolean"||t.includeScreenshots!==void 0&&typeof t.includeScreenshots!="boolean"||t.includeVideo!==void 0&&typeof t.includeVideo!="boolean"||t.includeAiAnalysis!==void 0&&typeof t.includeAiAnalysis!="boolean"||t.includeLogs!==void 0&&typeof t.includeLogs!="boolean"||t.includeFlowMetadata!==void 0&&typeof t.includeFlowMetadata!="boolean"||t.quiet!==void 0&&typeof t.quiet!="boolean"||t.metadata!==void 0&&t.metadata!==null&&(typeof t.metadata!="object"||gt(t.metadata)))}function $r(e){if(e!==void 0&&!Hr(e))throw core.createError(core.ErrorCode.CONFIG_INVALID,"Invalid Maestro reporter configuration");let t=Object.create(null),r=e?.outputPath??"./test-results/testrelic-maestro.json";return t.outputPath=r,t.htmlReportPath=e?.htmlReportPath??r.replace(/\.json$/,".html"),t.openReport=e?.openReport??true,t.includeScreenshots=e?.includeScreenshots??true,t.includeVideo=e?.includeVideo??true,t.includeAiAnalysis=e?.includeAiAnalysis??true,t.includeLogs=e?.includeLogs??true,t.includeFlowMetadata=e?.includeFlowMetadata??true,t.flowsDir=e?.flowsDir??null,t.testRunId=e?.testRunId??null,t.metadata=e?.metadata??null,t.quiet=e?.quiet??false,t.reportMode=e?.reportMode??"batch",t.cloud=Br(e?.cloud??null),t.network=Or(e?.network),Object.freeze(t)}function Br(e){let t=he(process.cwd()),r=t?be(t):null,n=r?X(r):null,o=ye(n,e??void 0);return o.apiKey?o:null}var qr=new fastXmlParser.XMLParser({ignoreAttributes:false,attributeNamePrefix:"@_",allowBooleanAttributes:true,parseAttributeValue:true,trimValues:true});function Y(e){return e==null?[]:Array.isArray(e)?e:[e]}function ht(e){return !e||typeof e!="object"?[]:Y(e.property).map(n=>({name:String(n["@_name"]??""),value:String(n["@_value"]??"")}))}function Gr(e){let t=String(e["@_name"]??"unnamed"),r=String(e["@_classname"]??t),n=Number(e["@_time"]??0),o=e["@_id"]!=null?String(e["@_id"]):null,s=String(e["@_status"]??"").toUpperCase(),i=e.failure,a=e.error,l=e.skipped!==void 0,c="SUCCESS";return i?c="FAILURE":a?c="ERROR":l?c="SKIPPED":s==="FAILURE"||s==="FAILED"?c="FAILURE":s==="ERROR"?c="ERROR":s==="SKIPPED"&&(c="SKIPPED"),{id:o,name:t,classname:r,time:n,status:c,failureMessage:i?String(i["@_message"]??i["#text"]??""):null,failureType:i?String(i["@_type"]??""):null,errorMessage:a?String(a["@_message"]??a["#text"]??""):null,errorType:a?String(a["@_type"]??""):null,properties:ht(e.properties)}}function mt(e){let t=String(e["@_name"]??"Test Suite"),r=e["@_device"]!=null?String(e["@_device"]):null,n=Number(e["@_tests"]??0),o=Number(e["@_failures"]??0),s=Number(e["@_errors"]??0),i=Number(e["@_skipped"]??0),a=Number(e["@_time"]??0),c=Y(e.testcase).map(Gr);return {name:t,device:r,tests:n,failures:o,errors:s,skipped:i,time:a,testCases:c,properties:ht(e.properties)}}function bt(e){let t=qr.parse(e),r=[];if(t.testsuites){let l=t.testsuites;r=Y(l.testsuite).map(mt);}else t.testsuite&&(r=Y(t.testsuite).map(mt));let n=0,o=0,s=0,i=0,a=0;for(let l of r)n+=l.tests,o+=l.failures,s+=l.errors,i+=l.skipped,a+=l.time;return {testSuites:r,totalTests:n,totalFailures:o,totalErrors:s,totalSkipped:i,totalTime:a}}function xe(e){let t=fs.readFileSync(e,"utf-8");return bt(t)}var Yr=new Set(["tapOn","doubleTapOn","longPressOn","inputText","eraseText","pasteText","swipe","scroll","scrollUntilVisible","hideKeyboard","pressKey","setClipboard","copyTextFrom"]),Qr=new Set(["assertVisible","assertNotVisible","assertTrue","assertScreenshot","assertNoDefectsWithAI","assertWithAI","assertCondition"]),Zr=new Set(["launchApp","killApp","stopApp","clearState","openLink","back","clearKeychain"]),en=new Set(["setAirplaneMode","toggleAirplaneMode","setLocation","setOrientation","setPermissions","addMedia","travel"]),tn=new Set(["takeScreenshot","startRecording","stopRecording"]),rn=new Set(["runScript","evalScript"]),nn=new Set(["runFlow","repeat","retry","waitForAnimationToEnd","extendedWaitUntil"]),on=new Set(["assertWithAI","assertNoDefectsWithAI","extractTextWithAI"]),sn=new Set(["inputText","pasteText"]),an=200,ln=400;function vt(e){return on.has(e)?"ai":Qr.has(e)?"assertion":Yr.has(e)?"interaction":Zr.has(e)?"navigation":en.has(e)?"device":tn.has(e)?"media":rn.has(e)?"script":nn.has(e)?"flow_control":"other"}var cn={tapOnElement:"tapOn",assertCondition:"assertVisible",backPress:"back",applyConfiguration:"applyConfiguration",defineVariables:"defineVariables"};function dn(e){let t=e.replace(/Command$/,"");return cn[t]??t}function un(e){if(e.selector&&typeof e.selector=="object"){let t=e.selector;if(typeof t.textRegex=="string")return t.textRegex;if(typeof t.text=="string")return t.text;if(typeof t.id=="string")return `#${t.id}`}if(e.condition&&typeof e.condition=="object"){let t=e.condition,r=t.visible??t.notVisible;if(r){if(typeof r.textRegex=="string")return r.textRegex;if(typeof r.text=="string")return r.text}}if(typeof e.path=="string")return e.path}function yt(e,t){return e.length<=t?e:`${e.slice(0,t)}\u2026`}function pn(e){return e.length===0?"":`[REDACTED ${e.length} chars]`}function xt(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.x=="number"&&typeof t.y=="number")return `${t.x},${t.y}`}function fn(e,t){let r={};switch(e){case "inputText":case "pasteText":{let n=t.text??t.value;typeof n=="string"&&(r.text=sn.has(e)?pn(n):n);break}case "swipe":case "scroll":case "scrollUntilVisible":{typeof t.direction=="string"&&(r.direction=t.direction);let n=xt(t.start??t.startRelative),o=xt(t.end??t.endRelative);n&&(r.start=n),o&&(r.end=o),typeof t.duration=="number"&&(r.swipeDurationMs=t.duration),typeof t.timeout=="number"&&(r.timeoutMs=t.timeout);break}case "setLocation":{typeof t.latitude=="number"&&(r.latitude=t.latitude),typeof t.longitude=="number"&&(r.longitude=t.longitude);break}case "pressKey":case "back":{typeof t.key=="string"?r.key=t.key:typeof t.code=="string"&&(r.key=t.code);break}case "setOrientation":{typeof t.orientation=="string"&&(r.orientation=t.orientation);break}case "setAirplaneMode":case "toggleAirplaneMode":{(typeof t.value=="string"||typeof t.value=="boolean")&&(r.value=t.value);break}case "setPermissions":{t.permissions&&typeof t.permissions=="object"&&(r.permissions=t.permissions);break}case "addMedia":{Array.isArray(t.mediaPaths)?r.mediaPaths=t.mediaPaths:typeof t.path=="string"&&(r.mediaPaths=[t.path]);break}case "launchApp":case "killApp":case "stopApp":case "clearState":{let n=t.appId??t.packageName??t.bundleId;typeof n=="string"&&(r.appId=n),t.arguments&&(r.arguments=t.arguments);break}case "openLink":{typeof t.url=="string"?r.url=t.url:typeof t.link=="string"&&(r.url=t.link);break}case "runScript":case "evalScript":{typeof t.path=="string"&&(r.path=t.path),typeof t.script=="string"&&(r.script=yt(t.script,an)),typeof t.sourceDescription=="string"&&(r.sourceDescription=t.sourceDescription);break}case "assertWithAI":case "assertNoDefectsWithAI":case "extractTextWithAI":{let n=t.assertion??t.prompt??t.question;typeof n=="string"&&(r.prompt=yt(n,ln));break}case "extendedWaitUntil":case "waitForAnimationToEnd":{typeof t.timeout=="number"&&(r.timeoutMs=t.timeout);break}case "repeat":case "retry":{typeof t.times=="number"&&(r.times=t.times),typeof t.maxRetries=="number"&&(r.maxRetries=t.maxRetries),typeof t.condition=="object"&&t.condition&&(r.condition=t.condition);break}case "runFlow":{typeof t.file=="string"&&(r.file=t.file),typeof t.flowId=="string"&&(r.flowId=t.flowId);break}default:for(let n of ["text","value","url"]){let o=t[n];if(typeof o=="string"||typeof o=="number"||typeof o=="boolean"){r[n]=o;break}}}return Object.keys(r).length>0?r:void 0}function wt(e,t,r){let n=[e.commands,t.commands,t.subSteps,t.children];for(let o of n)if(Array.isArray(o)&&o.length>0)return o.map((s,i)=>we(s,i,r));return []}function we(e,t,r){let n,o,s,i=[];if(typeof e.command=="object"&&e.command!==null&&!Array.isArray(e.command)){let x=e.command,b=Object.keys(x)[0]??`step-${t}`;n=dn(b);let g=x[b]??{};o=un(g),s=fn(n,g),i=wt(g,e,r);}else n=e.command??e.commandName??e.name??`step-${t}`,o=e.selector??void 0,i=wt({},e,r);let a=e.metadata??{},l=gn(a.status??e.status),c=a.duration??e.duration??e.durationMs??0,d=typeof a.sequenceNumber=="number"?a.sequenceNumber:void 0,u;typeof a.timestamp=="number"?u=new Date(a.timestamp).toISOString():u=e.timestamp??e.time??r;let p=e.error??e.errorMessage??void 0;return {command:n,category:vt(n),status:l,duration:c,timestamp:u,...o?{selector:o}:{},...p?{error:p}:{},...s?{details:s}:{},...d!==void 0?{sequenceNumber:d}:{},...i.length>0?{children:i}:{}}}function gn(e){if(!e)return "completed";let t=e.toLowerCase();return t==="failed"||t==="error"?"failed":t==="skipped"?"skipped":"completed"}function kt(e,t){let r=t??new Date().toISOString();try{let n=JSON.parse(e);if(Array.isArray(n))return n.map((o,s)=>we(o,s,r));if(typeof n=="object"&&n!==null){let o=n,s=o.commands??o.steps??o.data;if(Array.isArray(s))return s.map((i,a)=>we(i,a,r))}return []}catch{return []}}function ve(e,t){try{let r=fs.readFileSync(e,"utf-8");return kt(r,t)}catch{return []}}function ke(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>path.basename(t).startsWith("commands")&&t.endsWith(".json")).map(t=>path.join(e,t))}catch{return []}}function wn(e){let t=[];for(let r of e)if(typeof r=="object"&&r!==null){let n=r;if(typeof n.runFlow=="string")t.push(n.runFlow);else if(typeof n.runFlow=="object"&&n.runFlow!==null){let o=n.runFlow;typeof o.file=="string"&&t.push(o.file);}}return t}function Rt(e){if(!e)return [];let t=[],r=Array.isArray(e)?e:[e];for(let n of r)if(typeof n=="string")t.push(n);else if(typeof n=="object"&&n!==null){let o=n;if(typeof o.runFlow=="string")t.push(o.runFlow);else if(typeof o.runFlow=="object"&&o.runFlow!==null){let s=o.runFlow;typeof s.file=="string"&&t.push(s.file);}typeof o.runScript=="string"&&t.push(o.runScript);}return t}function At(e,t){let r=e.split(/^---\s*$/m,2),n=r[0]??"",o=r[1]??"",s={};try{let h=yaml.parseDocument(n).toJS();typeof h=="object"&&h!==null&&!Array.isArray(h)&&(s=h);}catch{}let i=[];if(o.trim())try{let h=yaml.parseDocument(o).toJS();Array.isArray(h)&&(i=h);}catch{}let a=typeof s.appId=="string"?s.appId:null,l=typeof s.name=="string"?s.name:null,c=[];if(Array.isArray(s.tags))for(let g of s.tags)typeof g=="string"&&c.push(g);let d={};if(typeof s.env=="object"&&s.env!==null&&!Array.isArray(s.env))for(let[g,h]of Object.entries(s.env))d[g]=String(h);let u={};if(typeof s.properties=="object"&&s.properties!==null&&!Array.isArray(s.properties))for(let[g,h]of Object.entries(s.properties))u[g]=String(h);let p=Rt(s.onFlowStart),x=Rt(s.onFlowComplete),b=wn(i);return {appId:a,name:l,tags:c,env:d,properties:u,onFlowStart:p,onFlowComplete:x,subflowRefs:b,filePath:t}}function Ce(e){let t=fs.readFileSync(e,"utf-8");return At(t,e)}function Re(e){if(!fs.existsSync(e))return [];let t=[];function r(n){try{let o=fs.readdirSync(n,{withFileTypes:!0});for(let s of o){let i=path.join(n,s.name);if(s.isDirectory())r(i);else if(s.isFile()){let a=path.extname(s.name).toLowerCase();(a===".yaml"||a===".yml")&&t.push(i);}}}catch{}}return r(e),t}var Sn=/^(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)\s+(\w+)\s+(.+)$/,Tn=/^\[?(\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]?\s+(\w+)\s+(.+)$/;function St(e){let t=e.toUpperCase();return t==="DEBUG"||t==="TRACE"||t==="VERBOSE"?"DEBUG":t==="INFO"?"INFO":t==="WARN"||t==="WARNING"?"WARN":t==="ERROR"||t==="FATAL"||t==="SEVERE"?"ERROR":"INFO"}function Tt(e){let t=[],r=e.split(`
3
- `),n=new Date().toISOString().split("T")[0];for(let o of r){let s=o.trim();if(!s)continue;let i=Sn.exec(s);if(i){t.push({timestamp:i[1],level:St(i[2]),message:i[3],source:null});continue}if(i=Tn.exec(s),i){t.push({timestamp:`${n}T${i[1]}`,level:St(i[2]),message:i[3],source:null});continue}if(t.length>0){let a=t[t.length-1];t[t.length-1]={...a,message:a.message+`
4
- `+s};}}return t}function Ae(e){try{let t=fs.readFileSync(e,"utf-8");return Tt(t)}catch{return []}}function Se(e){for(let t of e){let r=t.message.toLowerCase();if(r.includes("android")||r.includes("adb")||r.includes("uiautomator")||r.includes("emulator"))return "android";if(r.includes("ios")||r.includes("xcuitest")||r.includes("simulator")||r.includes("xctest"))return "ios";if(r.includes("web driver")||r.includes("chrome")||r.includes("chromium"))return "web"}return "unknown"}function Te(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>path.basename(t)==="maestro.log"||t.endsWith(".log")).map(t=>path.join(e,t))}catch{return []}}var Ln=/(?:defect|issue|bug|error|warning|problem)/i,Dn=/(?:critical|severe|major|blocker)/i,Nn=/(?:warning|moderate|minor)/i,Ie=/(?:cut[\s-]?off|overlap|truncat|misalign|overflow|clip|obscur|hidden\s+text|broken\s+layout)/i,Q=/(?:spelling|typo|misspell|grammar)/i,Z=/(?:i18n|internationali[sz]ation|locali[sz]ation|untranslated|missing\s+translation)/i,Pe=/(?:layout|spacing|padding|margin|alignment|centering|position)/i,_e=/(?:accessib|a11y|contrast|screen\s*reader|alt\s*text|aria)/i;function Me(e){return Q.test(e)?"spelling":Z.test(e)?"i18n":_e.test(e)?"accessibility":Pe.test(e)?"layout":"ui"}function Ee(e){return Dn.test(e)?"critical":Nn.test(e)?"warning":"info"}function Fe(e){return e.replace(/<[^>]*>/g," ").replace(/\s+/g," ").trim()}function On(e){let t=[],r=Fe(e),n=/<li[^>]*>([\s\S]*?)<\/li>/gi,o;for(;(o=n.exec(e))!==null;){let s=o[1],i=Fe(s);!i||i.length<5||(Ln.test(i)||Ie.test(i)||Q.test(i)||Z.test(i))&&t.push({type:Me(i),severity:Ee(i),description:i,location:null,screenshot:null});}if(t.length===0){let s=/<p[^>]*>([\s\S]*?)<\/p>/gi;for(;(o=s.exec(e))!==null;){let i=Fe(o[1]);!i||i.length<10||(Ie.test(i)||Q.test(i)||Z.test(i)||Pe.test(i)||_e.test(i))&&t.push({type:Me(i),severity:Ee(i),description:i,location:null,screenshot:null});}}if(t.length===0&&r.length>20){let s=r.split(/[.!?]+/).filter(i=>i.trim().length>10);for(let i of s){let a=i.trim();(Ie.test(a)||Q.test(a)||Z.test(a)||Pe.test(a)||_e.test(a))&&t.push({type:Me(a),severity:Ee(a),description:a,location:null,screenshot:null});}}return t}function It(e){let t=On(e);return {defects:t,totalDefects:t.length,hasIssues:t.length>0,rawHtml:e}}function Le(e){try{let t=fs.readFileSync(e,"utf-8");return It(t)}catch{return {defects:[],totalDefects:0,hasIssues:false,rawHtml:null}}}function De(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>{let r=path.basename(t).toLowerCase();return path.extname(t).toLowerCase()===".html"&&(r.includes("insight")||r.includes("ai")||r.includes("analysis"))}).map(t=>path.join(e,t))}catch{return []}}var zn=new Set([".png",".jpg",".jpeg",".webp"]),qn=new Set([".mp4",".webm",".mov"]);function Mt(e){let t=[];if(!fs.existsSync(e))return t;function r(n){try{let o=fs.readdirSync(n,{withFileTypes:!0});for(let s of o){let i=path.join(n,s.name);s.isDirectory()?r(i):s.isFile()&&t.push(i);}}catch{}}return r(e),t}function Ne(e,t){let r=[],n=[],o=[],s=[],i=[],a=null,l=[];e&&l.push(...Mt(e)),t&&l.push(...Mt(t));let c=new Set;for(let d of l){if(c.has(d))continue;c.add(d);let u=path.basename(d).toLowerCase(),p=path.extname(d).toLowerCase();if(zn.has(p)){r.push(d);continue}if(qn.has(p)){n.push(d);continue}if(u==="maestro.log"||p===".log"&&u.includes("maestro")){o.push(d);continue}if(u.startsWith("commands")&&p===".json"){s.push(d);continue}if(p===".html"&&(u.includes("insight")||u.includes("ai")||u.includes("analysis"))){i.push(d);continue}if(p===".xml"&&(u.includes("report")||u.includes("junit"))){a||(a=d);continue}}return {screenshotPaths:r,videoPaths:n,logPaths:o,commandJsonPaths:s,aiReportPaths:i,junitReportPath:a}}function Gn(e){return {screenshots:e.screenshotPaths.length,videos:e.videoPaths.length,logs:e.logPaths.length,commandFiles:e.commandJsonPaths.length,aiReports:e.aiReportPaths.length,junitReport:e.junitReportPath?1:0}}function Vn(e){switch(e){case "interaction":return "ui_action";case "assertion":return "assertion";case "ai":return "assertion";case "navigation":return "navigation";case "device":return "custom_step";case "media":return "custom_step";case "script":return "custom_step";case "flow_control":return "custom_step";case "recording":return "custom_step";default:return "custom_step"}}function Jn(e){let t=e.details;if(t)switch(e.command){case "inputText":case "pasteText":if(typeof t.text=="string")return `${e.command} \u2192 ${t.text}`;break;case "swipe":case "scroll":case "scrollUntilVisible":if(typeof t.direction=="string")return `${e.command} ${t.direction}`;break;case "setLocation":if(typeof t.latitude=="number"&&typeof t.longitude=="number")return `setLocation ${t.latitude},${t.longitude}`;break;case "pressKey":if(typeof t.key=="string")return `pressKey ${t.key}`;break;case "setOrientation":if(typeof t.orientation=="string")return `setOrientation ${t.orientation}`;break;case "launchApp":case "killApp":case "stopApp":case "clearState":if(typeof t.appId=="string")return `${e.command} ${t.appId}`;break;case "openLink":if(typeof t.url=="string")return `openLink ${t.url}`;break;case "runScript":case "evalScript":if(typeof t.path=="string")return `${e.command} ${t.path}`;if(typeof t.sourceDescription=="string")return `${e.command} ${t.sourceDescription}`;break;case "assertWithAI":case "assertNoDefectsWithAI":case "extractTextWithAI":if(typeof t.prompt=="string")return `${e.command} \u2192 ${t.prompt}`;break;case "retry":if(typeof t.maxRetries=="number")return `retry \xD7 ${t.maxRetries}`;break;case "repeat":if(typeof t.times=="number")return `repeat \xD7 ${t.times}`;break;case "runFlow":if(typeof t.file=="string")return `runFlow ${t.file}`;break}return e.selector?`${e.command} \u2192 ${e.selector}`:e.command}function Oe(e,t){let r=Date.parse(e.timestamp),n=Number.isFinite(r)&&Number.isFinite(t)?Math.max(0,(r-t)/1e3):null,o=(e.children??[]).map(s=>Oe(s,t));return {title:Jn(e),category:Vn(e.category),status:e.status==="failed"?"failed":"passed",duration:e.duration,timestamp:e.timestamp,videoOffset:n,error:e.error??null,children:o}}function Wn(e,t){let r=Date.parse(e.timestamp),n=Date.parse(t.timestamp);return Number.isFinite(r)&&Number.isFinite(n)&&r!==n?r-n:0}function Kn(e,t){let r=Date.parse(e.startedAt),n=[...e.commands].sort((l,c)=>{let d=Date.parse(l.timestamp),u=Date.parse(c.timestamp);if(Number.isFinite(d)&&Number.isFinite(u)&&d!==u)return d-u;let p=l.sequenceNumber??0,x=c.sequenceNumber??0;return p-x}),o=[...e.assertions].sort((l,c)=>{let d=Date.parse(l.timestamp),u=Date.parse(c.timestamp);if(Number.isFinite(d)&&Number.isFinite(u)&&d!==u)return d-u;let p=l.sequenceNumber??0,x=c.sequenceNumber??0;return p-x}),s=[...n.map(l=>Oe(l,r)),...o.map(l=>Oe(l,r))];s.sort(Wn);let i=e.screenshotPaths.length>0||e.videoPath?{screenshot:e.screenshotPaths[0]??void 0,video:e.videoPath??void 0}:null,a=[...e.tags];return e.platform!=="unknown"&&!a.includes(e.platform)&&a.push(e.platform),{title:e.flowName,status:e.status,duration:e.duration,startedAt:e.startedAt,completedAt:e.completedAt,retryCount:0,tags:a,failure:e.failureMessage?{message:e.failureMessage,line:null,code:null,stack:null}:null,testId:`${e.flowFile}::${e.flowName}`,filePath:e.flowFile,suiteName:e.appId??"maestro-suite",testType:"mobile",isFlaky:false,retryStatus:null,expectedStatus:"passed",actualStatus:e.status,artifacts:i,networkRequests:null,apiCalls:t.length>0?[...t]:null,apiAssertions:null,actions:s.length>0?s:null,consoleLogs:null}}function Et(e,t){let r=`${e.flowFile}::${e.flowName}`,n=t?.get(r)??[],o=Kn(e,n);return {url:e.appId??"maestro-flow",navigationType:"page_load",visitedAt:e.startedAt,duration:e.duration,specFile:e.flowFile,domContentLoadedAt:null,networkIdleAt:null,networkStats:null,tests:[o]}}function Ue(e,t){return e.map(r=>Et(r,t))}var Ft={"2xx":0,"3xx":0,"4xx":0,"5xx":0,error:0};function Xn(e){return e===null?"error":e>=200&&e<300?"2xx":e>=300&&e<400?"3xx":e>=400&&e<500?"4xx":e>=500&&e<600?"5xx":"error"}function He(e,t){if(e.length===0)return null;let r=Math.min(e.length-1,Math.floor(t/100*e.length));return e[r]}function Yn(e){if(e.length===0)return {totalApiCalls:0,uniqueApiUrls:0,apiCallsByMethod:{},apiCallsByStatusRange:{...Ft},apiResponseTime:null};let t={},r={...Ft},n=new Set,o=[];for(let i of e)t[i.method]=(t[i.method]??0)+1,r[Xn(i.responseStatusCode)]+=1,n.add(i.url),Number.isFinite(i.responseTimeMs)&&i.responseTimeMs>0&&o.push(i.responseTimeMs);o.sort((i,a)=>i-a);let s=o.length>0?{p50:He(o,50)??0,p95:He(o,95)??0,p99:He(o,99)??0,avg:o.reduce((i,a)=>i+a,0)/o.length,min:o[0],max:o[o.length-1]}:null;return {totalApiCalls:e.length,uniqueApiUrls:n.size,apiCallsByMethod:t,apiCallsByStatusRange:r,apiResponseTime:s}}function V(e){let t=0,r=0,n=0,o=0,s=0,i=0,a=0,l=0,c=0,d=e.length,u=0,p={},x=new Set,b=[];for(let h of e){x.add(h.url);for(let y of h.tests){switch(t++,y.status){case "passed":r++;break;case "failed":n++;break;case "flaky":o++;break;case "skipped":s++;break;case "timedout":i++;break}if(y.actions)for(let T of y.actions)if(u++,T.category==="assertion")a++,T.status==="passed"?l++:c++;else {let C=T.category;p[C]=(p[C]??0)+1;}y.apiCalls&&y.apiCalls.length>0&&b.push(...y.apiCalls);}}let g=Yn(b);return {total:t,passed:r,failed:n,flaky:o,skipped:s,timedout:i,...g,totalAssertions:a,passedAssertions:l,failedAssertions:c,totalNavigations:d,uniqueNavigationUrls:x.size,totalTimelineSteps:e.length,totalActionSteps:u,actionStepsByCategory:p}}var Pt=`
1
+ 'use strict';var core=require('@testrelic/core'),fs=require('fs'),path=require('path'),fastXmlParser=require('fast-xml-parser'),yaml=require('yaml'),child_process=require('child_process'),os=require('os'),crypto=require('crypto'),url=require('url'),zlib=require('zlib'),stream=require('stream');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;var bt=".testrelic",Fr="testrelic-config.json",Pr=".testrelic",_r=5,Lr=new Set(["__proto__","constructor","prototype"]),me=Object.freeze({apiKey:null,endpoint:"https://platform.testrelic.ai/api/v1",uploadStrategy:"batch",timeout:3e4,projectName:null,queueMaxAge:6048e5,queueDirectory:`${bt}/queue`,uploadArtifacts:true,artifactMaxSizeMb:50}),Dr={s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3};function be(e){let t=path.resolve(e);for(let r=0;r<=_r;r++){let n=path.join(t,bt,Fr);if(fs.existsSync(n))try{if(fs.statSync(n).isFile())return n}catch{}let o=path.join(t,Pr);if(fs.existsSync(o))try{if(fs.statSync(o).isFile())return process.stderr.write(`[testrelic] Deprecation: config file ".testrelic" has moved to ".testrelic/testrelic-config.json". Please migrate your config file to the new location.
2
+ `),o}catch{}let s=path.dirname(t);if(s===t)break;t=s;}return null}function ye(e){try{let t=fs.readFileSync(e,"utf-8"),r=JSON.parse(t);return typeof r!="object"||r===null||Array.isArray(r)||!yt(r)?null:r}catch{return null}}function yt(e){for(let t of Object.keys(e)){if(Lr.has(t))return false;let r=e[t];if(typeof r=="object"&&r!==null&&!Array.isArray(r)&&!yt(r))return false}return true}function K(e){let t=/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(e);if(t)return process.env[t[1]]??null;let r=/^\$([A-Za-z_][A-Za-z0-9_]*)$/.exec(e);return r?process.env[r[1]]??null:e}function X(e){let t=Object.create(null);for(let r of Object.keys(e)){let n=e[r];typeof n=="string"&&n.startsWith("$")?t[r]=K(n):typeof n=="object"&&n!==null&&!Array.isArray(n)?t[r]=X(n):t[r]=n;}return t}function he(e){let t=/^(\d+)\s*([smhd])$/.exec(e.trim());if(!t)return null;let r=parseInt(t[1],10),n=t[2],o=Dr[n];return !o||r<=0?null:r*o}function xe(e,t){let r=Object.create(null);if(Object.assign(r,me),e){let l=e.cloud;l&&typeof l=="object"&&(typeof l.endpoint=="string"&&(r.endpoint=l.endpoint),typeof l.upload=="string"&&(r.uploadStrategy=l.upload),typeof l.timeout=="number"&&(r.timeout=l.timeout),typeof l.apiKey=="string"&&l.apiKey.length>0&&(r.apiKey=l.apiKey));let c=e["testrelic-repo"]??e.project;c&&typeof c=="object"&&typeof c.name=="string"&&(r.projectName=c.name);let d=e.queue;if(d&&typeof d=="object"){if(typeof d.maxAge=="string"){let u=he(d.maxAge);u!==null&&(r.queueMaxAge=u);}typeof d.directory=="string"&&(r.queueDirectory=d.directory);}}if(t){if(typeof t.apiKey=="string"&&t.apiKey.length>0){let l=t.apiKey.startsWith("$")?K(t.apiKey):t.apiKey;l&&(r.apiKey=l);}if(typeof t.endpoint=="string"){let l=t.endpoint.startsWith("$")?K(t.endpoint):t.endpoint;l&&(r.endpoint=l);}if(typeof t.upload=="string"&&(r.uploadStrategy=t.upload),typeof t.timeout=="number"&&(r.timeout=t.timeout),typeof t.projectName=="string"&&(r.projectName=t.projectName),typeof t.queueMaxAge=="string"){let l=he(t.queueMaxAge);l!==null&&(r.queueMaxAge=l);}typeof t.queueDirectory=="string"&&(r.queueDirectory=t.queueDirectory),typeof t.uploadArtifacts=="boolean"&&(r.uploadArtifacts=t.uploadArtifacts),typeof t.artifactMaxSizeMb=="number"&&(r.artifactMaxSizeMb=t.artifactMaxSizeMb);}let n=process.env.TESTRELIC_API_KEY;n&&n.length>0&&(r.apiKey=n);let o=process.env.TESTRELIC_CLOUD_ENDPOINT;o&&core.isValidEndpointUrl(o)&&(r.endpoint=o);let s=process.env.TESTRELIC_UPLOAD_STRATEGY;s&&["batch","realtime","both"].includes(s)&&(r.uploadStrategy=s);let i=process.env.TESTRELIC_CLOUD_TIMEOUT;if(i){let l=parseInt(i,10);!isNaN(l)&&l>=1e3&&l<=12e4&&(r.timeout=l);}let a=Object.freeze(r);return core.isValidCloudConfig(a)?a:me}var Ur=["authorization","cookie","set-cookie","x-api-key"],Hr=["password","secret","token","apiKey","api_key"],$r=1024*1024;function Br(e){let t=e??{},r=process.env.TESTRELIC_CAPTURE_NETWORK==="1"||process.env.TESTRELIC_CAPTURE_NETWORK?.toLowerCase()==="true";return Object.freeze({enabled:t.enabled??r??false,proxyPort:t.proxyPort??(process.env.TESTRELIC_PROXY_PORT?Number.parseInt(process.env.TESTRELIC_PROXY_PORT,10):8080),proxyHost:t.proxyHost??process.env.TESTRELIC_PROXY_HOST??"127.0.0.1",harPath:t.harPath??process.env.TESTRELIC_HAR_PATH??null,outputDir:t.outputDir??null,skipCertInstall:t.skipCertInstall??false,includeUrls:Object.freeze(t.includeUrls?[...t.includeUrls]:[]),excludeUrls:Object.freeze(t.excludeUrls?[...t.excludeUrls]:[]),redactHeaders:Object.freeze(t.redactHeaders?[...t.redactHeaders]:[...Ur]),redactBodyFields:Object.freeze(t.redactBodyFields?[...t.redactBodyFields]:[...Hr]),maxBodyBytes:t.maxBodyBytes??$r})}var jr=new Set(["__proto__","constructor","prototype"]);function xt(e){if(typeof e!="object"||e===null)return false;for(let t of Object.keys(e))if(jr.has(t))return true;return false}function zr(e){if(typeof e!="object"||e===null||xt(e))return false;let t=e;return !(t.outputPath!==void 0&&typeof t.outputPath!="string"||t.htmlReportPath!==void 0&&typeof t.htmlReportPath!="string"||t.openReport!==void 0&&typeof t.openReport!="boolean"||t.includeScreenshots!==void 0&&typeof t.includeScreenshots!="boolean"||t.includeVideo!==void 0&&typeof t.includeVideo!="boolean"||t.includeAiAnalysis!==void 0&&typeof t.includeAiAnalysis!="boolean"||t.includeLogs!==void 0&&typeof t.includeLogs!="boolean"||t.includeFlowMetadata!==void 0&&typeof t.includeFlowMetadata!="boolean"||t.quiet!==void 0&&typeof t.quiet!="boolean"||t.metadata!==void 0&&t.metadata!==null&&(typeof t.metadata!="object"||xt(t.metadata)))}function qr(e){if(e!==void 0&&!zr(e))throw core.createError(core.ErrorCode.CONFIG_INVALID,"Invalid Maestro reporter configuration");let t=Object.create(null),r=e?.outputPath??"./test-results/testrelic-maestro.json";return t.outputPath=r,t.htmlReportPath=e?.htmlReportPath??r.replace(/\.json$/,".html"),t.openReport=e?.openReport??true,t.includeScreenshots=e?.includeScreenshots??true,t.includeVideo=e?.includeVideo??true,t.includeAiAnalysis=e?.includeAiAnalysis??true,t.includeLogs=e?.includeLogs??true,t.includeFlowMetadata=e?.includeFlowMetadata??true,t.flowsDir=e?.flowsDir??null,t.testRunId=e?.testRunId??null,t.metadata=e?.metadata??null,t.quiet=e?.quiet??false,t.reportMode=e?.reportMode??"batch",t.cloud=Gr(e?.cloud??null),t.network=Br(e?.network),Object.freeze(t)}function Gr(e){let t=be(process.cwd()),r=t?ye(t):null,n=r?X(r):null,o=xe(n,e??void 0);return o.apiKey?o:null}var Wr=new fastXmlParser.XMLParser({ignoreAttributes:false,attributeNamePrefix:"@_",allowBooleanAttributes:true,parseAttributeValue:true,trimValues:true});function Y(e){return e==null?[]:Array.isArray(e)?e:[e]}function vt(e){return !e||typeof e!="object"?[]:Y(e.property).map(n=>({name:String(n["@_name"]??""),value:String(n["@_value"]??"")}))}function Kr(e){let t=String(e["@_name"]??"unnamed"),r=String(e["@_classname"]??t),n=Number(e["@_time"]??0),o=e["@_id"]!=null?String(e["@_id"]):null,s=String(e["@_status"]??"").toUpperCase(),i=e.failure,a=e.error,l=e.skipped!==void 0,c="SUCCESS";return i?c="FAILURE":a?c="ERROR":l?c="SKIPPED":s==="FAILURE"||s==="FAILED"?c="FAILURE":s==="ERROR"?c="ERROR":s==="SKIPPED"&&(c="SKIPPED"),{id:o,name:t,classname:r,time:n,status:c,failureMessage:i?String(i["@_message"]??i["#text"]??""):null,failureType:i?String(i["@_type"]??""):null,errorMessage:a?String(a["@_message"]??a["#text"]??""):null,errorType:a?String(a["@_type"]??""):null,properties:vt(e.properties)}}function wt(e){let t=String(e["@_name"]??"Test Suite"),r=e["@_device"]!=null?String(e["@_device"]):null,n=Number(e["@_tests"]??0),o=Number(e["@_failures"]??0),s=Number(e["@_errors"]??0),i=Number(e["@_skipped"]??0),a=Number(e["@_time"]??0),c=Y(e.testcase).map(Kr);return {name:t,device:r,tests:n,failures:o,errors:s,skipped:i,time:a,testCases:c,properties:vt(e.properties)}}function kt(e){let t=Wr.parse(e),r=[];if(t.testsuites){let l=t.testsuites;r=Y(l.testsuite).map(wt);}else t.testsuite&&(r=Y(t.testsuite).map(wt));let n=0,o=0,s=0,i=0,a=0;for(let l of r)n+=l.tests,o+=l.failures,s+=l.errors,i+=l.skipped,a+=l.time;return {testSuites:r,totalTests:n,totalFailures:o,totalErrors:s,totalSkipped:i,totalTime:a}}function we(e){let t=fs.readFileSync(e,"utf-8");return kt(t)}var tn=new Set(["tapOn","doubleTapOn","longPressOn","inputText","eraseText","pasteText","swipe","scroll","scrollUntilVisible","hideKeyboard","pressKey","setClipboard","copyTextFrom"]),rn=new Set(["assertVisible","assertNotVisible","assertTrue","assertScreenshot","assertNoDefectsWithAI","assertWithAI","assertCondition"]),nn=new Set(["launchApp","killApp","stopApp","clearState","openLink","back","clearKeychain"]),on=new Set(["setAirplaneMode","toggleAirplaneMode","setLocation","setOrientation","setPermissions","addMedia","travel"]),sn=new Set(["takeScreenshot","startRecording","stopRecording"]),an=new Set(["runScript","evalScript"]),ln=new Set(["runFlow","repeat","retry","waitForAnimationToEnd","extendedWaitUntil"]),cn=new Set(["assertWithAI","assertNoDefectsWithAI","extractTextWithAI"]),dn=new Set(["inputText","pasteText"]),un=200,pn=400;function At(e){return cn.has(e)?"ai":rn.has(e)?"assertion":tn.has(e)?"interaction":nn.has(e)?"navigation":on.has(e)?"device":sn.has(e)?"media":an.has(e)?"script":ln.has(e)?"flow_control":"other"}var fn={tapOnElement:"tapOn",assertCondition:"assertVisible",backPress:"back",applyConfiguration:"applyConfiguration",defineVariables:"defineVariables"};function gn(e){let t=e.replace(/Command$/,"");return fn[t]??t}function mn(e){if(e.selector&&typeof e.selector=="object"){let t=e.selector;if(typeof t.textRegex=="string")return t.textRegex;if(typeof t.text=="string")return t.text;if(typeof t.id=="string")return `#${t.id}`}if(e.condition&&typeof e.condition=="object"){let t=e.condition,r=t.visible??t.notVisible;if(r){if(typeof r.textRegex=="string")return r.textRegex;if(typeof r.text=="string")return r.text}}if(typeof e.path=="string")return e.path}function Ct(e,t){return e.length<=t?e:`${e.slice(0,t)}\u2026`}function hn(e){return e.length===0?"":`[REDACTED ${e.length} chars]`}function Rt(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.x=="number"&&typeof t.y=="number")return `${t.x},${t.y}`}function bn(e,t){let r={};switch(e){case "inputText":case "pasteText":{let n=t.text??t.value;typeof n=="string"&&(r.text=dn.has(e)?hn(n):n);break}case "swipe":case "scroll":case "scrollUntilVisible":{typeof t.direction=="string"&&(r.direction=t.direction);let n=Rt(t.start??t.startRelative),o=Rt(t.end??t.endRelative);n&&(r.start=n),o&&(r.end=o),typeof t.duration=="number"&&(r.swipeDurationMs=t.duration),typeof t.timeout=="number"&&(r.timeoutMs=t.timeout);break}case "setLocation":{typeof t.latitude=="number"&&(r.latitude=t.latitude),typeof t.longitude=="number"&&(r.longitude=t.longitude);break}case "pressKey":case "back":{typeof t.key=="string"?r.key=t.key:typeof t.code=="string"&&(r.key=t.code);break}case "setOrientation":{typeof t.orientation=="string"&&(r.orientation=t.orientation);break}case "setAirplaneMode":case "toggleAirplaneMode":{(typeof t.value=="string"||typeof t.value=="boolean")&&(r.value=t.value);break}case "setPermissions":{t.permissions&&typeof t.permissions=="object"&&(r.permissions=t.permissions);break}case "addMedia":{Array.isArray(t.mediaPaths)?r.mediaPaths=t.mediaPaths:typeof t.path=="string"&&(r.mediaPaths=[t.path]);break}case "launchApp":case "killApp":case "stopApp":case "clearState":{let n=t.appId??t.packageName??t.bundleId;typeof n=="string"&&(r.appId=n),t.arguments&&(r.arguments=t.arguments);break}case "openLink":{typeof t.url=="string"?r.url=t.url:typeof t.link=="string"&&(r.url=t.link);break}case "runScript":case "evalScript":{typeof t.path=="string"&&(r.path=t.path),typeof t.script=="string"&&(r.script=Ct(t.script,un)),typeof t.sourceDescription=="string"&&(r.sourceDescription=t.sourceDescription);break}case "assertWithAI":case "assertNoDefectsWithAI":case "extractTextWithAI":{let n=t.assertion??t.prompt??t.question;typeof n=="string"&&(r.prompt=Ct(n,pn));break}case "extendedWaitUntil":case "waitForAnimationToEnd":{typeof t.timeout=="number"&&(r.timeoutMs=t.timeout);break}case "repeat":case "retry":{typeof t.times=="number"&&(r.times=t.times),typeof t.maxRetries=="number"&&(r.maxRetries=t.maxRetries),typeof t.condition=="object"&&t.condition&&(r.condition=t.condition);break}case "runFlow":{typeof t.file=="string"&&(r.file=t.file),typeof t.flowId=="string"&&(r.flowId=t.flowId);break}default:for(let n of ["text","value","url"]){let o=t[n];if(typeof o=="string"||typeof o=="number"||typeof o=="boolean"){r[n]=o;break}}}return Object.keys(r).length>0?r:void 0}function St(e,t,r){let n=[e.commands,t.commands,t.subSteps,t.children];for(let o of n)if(Array.isArray(o)&&o.length>0)return o.map((s,i)=>ve(s,i,r));return []}function ve(e,t,r){let n,o,s,i=[];if(typeof e.command=="object"&&e.command!==null&&!Array.isArray(e.command)){let w=e.command,y=Object.keys(w)[0]??`step-${t}`;n=gn(y);let g=w[y]??{};o=mn(g),s=bn(n,g),i=St(g,e,r);}else n=e.command??e.commandName??e.name??`step-${t}`,o=e.selector??void 0,i=St({},e,r);let a=e.metadata??{},l=yn(a.status??e.status),c=a.duration??e.duration??e.durationMs??0,d=typeof a.sequenceNumber=="number"?a.sequenceNumber:void 0,u;typeof a.timestamp=="number"?u=new Date(a.timestamp).toISOString():u=e.timestamp??e.time??r;let p=e.error??e.errorMessage??void 0;return {command:n,category:At(n),status:l,duration:c,timestamp:u,...o?{selector:o}:{},...p?{error:p}:{},...s?{details:s}:{},...d!==void 0?{sequenceNumber:d}:{},...i.length>0?{children:i}:{}}}function yn(e){if(!e)return "completed";let t=e.toLowerCase();return t==="failed"||t==="error"?"failed":t==="skipped"?"skipped":"completed"}function Tt(e,t){let r=t??new Date().toISOString();try{let n=JSON.parse(e);if(Array.isArray(n))return n.map((o,s)=>ve(o,s,r));if(typeof n=="object"&&n!==null){let o=n,s=o.commands??o.steps??o.data;if(Array.isArray(s))return s.map((i,a)=>ve(i,a,r))}return []}catch{return []}}function ke(e,t){try{let r=fs.readFileSync(e,"utf-8");return Tt(r,t)}catch{return []}}function Ce(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>path.basename(t).startsWith("commands")&&t.endsWith(".json")).map(t=>path.join(e,t))}catch{return []}}function Rn(e){let t=[];for(let r of e)if(typeof r=="object"&&r!==null){let n=r;if(typeof n.runFlow=="string")t.push(n.runFlow);else if(typeof n.runFlow=="object"&&n.runFlow!==null){let o=n.runFlow;typeof o.file=="string"&&t.push(o.file);}}return t}function Mt(e){if(!e)return [];let t=[],r=Array.isArray(e)?e:[e];for(let n of r)if(typeof n=="string")t.push(n);else if(typeof n=="object"&&n!==null){let o=n;if(typeof o.runFlow=="string")t.push(o.runFlow);else if(typeof o.runFlow=="object"&&o.runFlow!==null){let s=o.runFlow;typeof s.file=="string"&&t.push(s.file);}typeof o.runScript=="string"&&t.push(o.runScript);}return t}function Et(e,t){let r=e.split(/^---\s*$/m,2),n=r[0]??"",o=r[1]??"",s={};try{let h=yaml.parseDocument(n).toJS();typeof h=="object"&&h!==null&&!Array.isArray(h)&&(s=h);}catch{}let i=[];if(o.trim())try{let h=yaml.parseDocument(o).toJS();Array.isArray(h)&&(i=h);}catch{}let a=typeof s.appId=="string"?s.appId:null,l=typeof s.name=="string"?s.name:null,c=[];if(Array.isArray(s.tags))for(let g of s.tags)typeof g=="string"&&c.push(g);let d={};if(typeof s.env=="object"&&s.env!==null&&!Array.isArray(s.env))for(let[g,h]of Object.entries(s.env))d[g]=String(h);let u={};if(typeof s.properties=="object"&&s.properties!==null&&!Array.isArray(s.properties))for(let[g,h]of Object.entries(s.properties))u[g]=String(h);let p=Mt(s.onFlowStart),w=Mt(s.onFlowComplete),y=Rn(i);return {appId:a,name:l,tags:c,env:d,properties:u,onFlowStart:p,onFlowComplete:w,subflowRefs:y,filePath:t}}function Re(e){let t=fs.readFileSync(e,"utf-8");return Et(t,e)}function Se(e){if(!fs.existsSync(e))return [];let t=[];function r(n){try{let o=fs.readdirSync(n,{withFileTypes:!0});for(let s of o){let i=path.join(n,s.name);if(s.isDirectory())r(i);else if(s.isFile()){let a=path.extname(s.name).toLowerCase();(a===".yaml"||a===".yml")&&t.push(i);}}}catch{}}return r(e),t}var En=/^(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)\s+\[?\s*(\w+)\s*\]?\s+(.+)$/,Fn=/^\[?(\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]?\s+\[?\s*(\w+)\s*\]?\s+(.+)$/;function Ft(e){let t=e.toUpperCase();return t==="DEBUG"||t==="TRACE"||t==="VERBOSE"?"DEBUG":t==="INFO"?"INFO":t==="WARN"||t==="WARNING"?"WARN":t==="ERROR"||t==="FATAL"||t==="SEVERE"?"ERROR":"INFO"}function Pn(e,t){let r=/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?$/.exec(t);if(!r)return new Date().toISOString();let n=Number(r[1]),o=Number(r[2]),s=Number(r[3]),i=r[4]?Number(r[4].padEnd(3,"0")):0;return new Date(e.getFullYear(),e.getMonth(),e.getDate(),n,o,s,i).toISOString()}function Pt(e,t){let r=[],n=e.split(`
3
+ `),o=t instanceof Date?t:null,s=typeof t=="string"?t:t instanceof Date?`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`:new Date().toISOString().split("T")[0];for(let i of n){let a=i.trim();if(!a)continue;let l=En.exec(a);if(l){r.push({timestamp:l[1],level:Ft(l[2]),message:l[3],source:null});continue}if(l=Fn.exec(a),l){let c=o?Pn(o,l[1]):`${s}T${l[1]}`;r.push({timestamp:c,level:Ft(l[2]),message:l[3],source:null});continue}if(r.length>0){let c=r[r.length-1];r[r.length-1]={...c,message:c.message+`
4
+ `+a};}}return r}function Ae(e,t){try{let r=fs.readFileSync(e,"utf-8");return Pt(r,t)}catch{return []}}function Te(e){for(let t of e){let r=t.message.toLowerCase();if(r.includes("android")||r.includes("adb")||r.includes("uiautomator")||r.includes("emulator"))return "android";if(r.includes("ios")||r.includes("xcuitest")||r.includes("simulator")||r.includes("xctest"))return "ios";if(r.includes("web driver")||r.includes("chrome")||r.includes("chromium"))return "web"}return "unknown"}function Ie(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>path.basename(t)==="maestro.log"||t.endsWith(".log")).map(t=>path.join(e,t))}catch{return []}}var Hn=/(?:defect|issue|bug|error|warning|problem)/i,$n=/(?:critical|severe|major|blocker)/i,Bn=/(?:warning|moderate|minor)/i,Me=/(?:cut[\s-]?off|overlap|truncat|misalign|overflow|clip|obscur|hidden\s+text|broken\s+layout)/i,Q=/(?:spelling|typo|misspell|grammar)/i,Z=/(?:i18n|internationali[sz]ation|locali[sz]ation|untranslated|missing\s+translation)/i,_e=/(?:layout|spacing|padding|margin|alignment|centering|position)/i,Le=/(?:accessib|a11y|contrast|screen\s*reader|alt\s*text|aria)/i;function Ee(e){return Q.test(e)?"spelling":Z.test(e)?"i18n":Le.test(e)?"accessibility":_e.test(e)?"layout":"ui"}function Fe(e){return $n.test(e)?"critical":Bn.test(e)?"warning":"info"}function Pe(e){return e.replace(/<[^>]*>/g," ").replace(/\s+/g," ").trim()}function jn(e){let t=[],r=Pe(e),n=/<li[^>]*>([\s\S]*?)<\/li>/gi,o;for(;(o=n.exec(e))!==null;){let s=o[1],i=Pe(s);!i||i.length<5||(Hn.test(i)||Me.test(i)||Q.test(i)||Z.test(i))&&t.push({type:Ee(i),severity:Fe(i),description:i,location:null,screenshot:null});}if(t.length===0){let s=/<p[^>]*>([\s\S]*?)<\/p>/gi;for(;(o=s.exec(e))!==null;){let i=Pe(o[1]);!i||i.length<10||(Me.test(i)||Q.test(i)||Z.test(i)||_e.test(i)||Le.test(i))&&t.push({type:Ee(i),severity:Fe(i),description:i,location:null,screenshot:null});}}if(t.length===0&&r.length>20){let s=r.split(/[.!?]+/).filter(i=>i.trim().length>10);for(let i of s){let a=i.trim();(Me.test(a)||Q.test(a)||Z.test(a)||_e.test(a)||Le.test(a))&&t.push({type:Ee(a),severity:Fe(a),description:a,location:null,screenshot:null});}}return t}function _t(e){let t=jn(e);return {defects:t,totalDefects:t.length,hasIssues:t.length>0,rawHtml:e}}function De(e){try{let t=fs.readFileSync(e,"utf-8");return _t(t)}catch{return {defects:[],totalDefects:0,hasIssues:false,rawHtml:null}}}function Ne(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>{let r=path.basename(t).toLowerCase();return path.extname(t).toLowerCase()===".html"&&(r.includes("insight")||r.includes("ai")||r.includes("analysis"))}).map(t=>path.join(e,t))}catch{return []}}var Wn=new Set([".png",".jpg",".jpeg",".webp"]),Kn=new Set([".mp4",".webm",".mov"]);function Lt(e){let t=[];if(!fs.existsSync(e))return t;function r(n){try{let o=fs.readdirSync(n,{withFileTypes:!0});for(let s of o){let i=path.join(n,s.name);s.isDirectory()?r(i):s.isFile()&&t.push(i);}}catch{}}return r(e),t}function Oe(e,t){let r=[],n=[],o=[],s=[],i=[],a=null,l=[];e&&l.push(...Lt(e)),t&&l.push(...Lt(t));let c=new Set;for(let d of l){if(c.has(d))continue;c.add(d);let u=path.basename(d).toLowerCase(),p=path.extname(d).toLowerCase();if(Wn.has(p)){r.push(d);continue}if(Kn.has(p)){n.push(d);continue}if(u==="maestro.log"||p===".log"&&u.includes("maestro")){o.push(d);continue}if(u.startsWith("commands")&&p===".json"){s.push(d);continue}if(p===".html"&&(u.includes("insight")||u.includes("ai")||u.includes("analysis"))){i.push(d);continue}if(p===".xml"&&(u.includes("report")||u.includes("junit"))){a||(a=d);continue}}return {screenshotPaths:r,videoPaths:n,logPaths:o,commandJsonPaths:s,aiReportPaths:i,junitReportPath:a}}function Xn(e){return {screenshots:e.screenshotPaths.length,videos:e.videoPaths.length,logs:e.logPaths.length,commandFiles:e.commandJsonPaths.length,aiReports:e.aiReportPaths.length,junitReport:e.junitReportPath?1:0}}function Yn(e){switch(e){case "interaction":return "ui_action";case "assertion":return "assertion";case "ai":return "assertion";case "navigation":return "navigation";case "device":return "custom_step";case "media":return "custom_step";case "script":return "custom_step";case "flow_control":return "custom_step";case "recording":return "custom_step";default:return "custom_step"}}function Qn(e){let t=e.details;if(t)switch(e.command){case "inputText":case "pasteText":if(typeof t.text=="string")return `${e.command} \u2192 ${t.text}`;break;case "swipe":case "scroll":case "scrollUntilVisible":if(typeof t.direction=="string")return `${e.command} ${t.direction}`;break;case "setLocation":if(typeof t.latitude=="number"&&typeof t.longitude=="number")return `setLocation ${t.latitude},${t.longitude}`;break;case "pressKey":if(typeof t.key=="string")return `pressKey ${t.key}`;break;case "setOrientation":if(typeof t.orientation=="string")return `setOrientation ${t.orientation}`;break;case "launchApp":case "killApp":case "stopApp":case "clearState":if(typeof t.appId=="string")return `${e.command} ${t.appId}`;break;case "openLink":if(typeof t.url=="string")return `openLink ${t.url}`;break;case "runScript":case "evalScript":if(typeof t.path=="string")return `${e.command} ${t.path}`;if(typeof t.sourceDescription=="string")return `${e.command} ${t.sourceDescription}`;break;case "assertWithAI":case "assertNoDefectsWithAI":case "extractTextWithAI":if(typeof t.prompt=="string")return `${e.command} \u2192 ${t.prompt}`;break;case "retry":if(typeof t.maxRetries=="number")return `retry \xD7 ${t.maxRetries}`;break;case "repeat":if(typeof t.times=="number")return `repeat \xD7 ${t.times}`;break;case "runFlow":if(typeof t.file=="string")return `runFlow ${t.file}`;break}return e.selector?`${e.command} \u2192 ${e.selector}`:e.command}function Ue(e,t){let r=Date.parse(e.timestamp),n=Number.isFinite(r)&&Number.isFinite(t)?Math.max(0,(r-t)/1e3):null,o=(e.children??[]).map(s=>Ue(s,t));return {title:Qn(e),category:Yn(e.category),status:e.status==="failed"?"failed":"passed",duration:e.duration,timestamp:e.timestamp,videoOffset:n,error:e.error??null,children:o}}function Zn(e,t){let r=Date.parse(e.timestamp),n=Date.parse(t.timestamp);return Number.isFinite(r)&&Number.isFinite(n)&&r!==n?r-n:0}function eo(e,t){let r=Date.parse(e.startedAt),n=[...e.commands].sort((l,c)=>{let d=Date.parse(l.timestamp),u=Date.parse(c.timestamp);if(Number.isFinite(d)&&Number.isFinite(u)&&d!==u)return d-u;let p=l.sequenceNumber??0,w=c.sequenceNumber??0;return p-w}),o=[...e.assertions].sort((l,c)=>{let d=Date.parse(l.timestamp),u=Date.parse(c.timestamp);if(Number.isFinite(d)&&Number.isFinite(u)&&d!==u)return d-u;let p=l.sequenceNumber??0,w=c.sequenceNumber??0;return p-w}),s=[...n.map(l=>Ue(l,r)),...o.map(l=>Ue(l,r))];s.sort(Zn);let i=e.screenshotPaths.length>0||e.videoPath?{screenshot:e.screenshotPaths[0]??void 0,video:e.videoPath??void 0}:null,a=[...e.tags];return e.platform!=="unknown"&&!a.includes(e.platform)&&a.push(e.platform),{title:e.flowName,status:e.status,duration:e.duration,startedAt:e.startedAt,completedAt:e.completedAt,retryCount:0,tags:a,failure:e.failureMessage?{message:e.failureMessage,line:null,code:null,stack:null}:null,testId:`${e.flowFile}::${e.flowName}`,filePath:e.flowFile,suiteName:e.appId??"maestro-suite",testType:"mobile",isFlaky:false,retryStatus:null,expectedStatus:"passed",actualStatus:e.status,artifacts:i,networkRequests:null,apiCalls:t.length>0?[...t]:null,apiAssertions:null,actions:s.length>0?s:null,consoleLogs:null}}function Dt(e,t){let r=`${e.flowFile}::${e.flowName}`,n=t?.get(r)??[],o=eo(e,n);return {url:e.appId??"maestro-flow",navigationType:"page_load",visitedAt:e.startedAt,duration:e.duration,specFile:e.flowFile,domContentLoadedAt:null,networkIdleAt:null,networkStats:null,tests:[o]}}function He(e,t){return e.map(r=>Dt(r,t))}var Nt={"2xx":0,"3xx":0,"4xx":0,"5xx":0,error:0};function to(e){return e===null?"error":e>=200&&e<300?"2xx":e>=300&&e<400?"3xx":e>=400&&e<500?"4xx":e>=500&&e<600?"5xx":"error"}function $e(e,t){if(e.length===0)return null;let r=Math.min(e.length-1,Math.floor(t/100*e.length));return e[r]}function ro(e){if(e.length===0)return {totalApiCalls:0,uniqueApiUrls:0,apiCallsByMethod:{},apiCallsByStatusRange:{...Nt},apiResponseTime:null};let t={},r={...Nt},n=new Set,o=[];for(let i of e)t[i.method]=(t[i.method]??0)+1,r[to(i.responseStatusCode)]+=1,n.add(i.url),Number.isFinite(i.responseTimeMs)&&i.responseTimeMs>0&&o.push(i.responseTimeMs);o.sort((i,a)=>i-a);let s=o.length>0?{p50:$e(o,50)??0,p95:$e(o,95)??0,p99:$e(o,99)??0,avg:o.reduce((i,a)=>i+a,0)/o.length,min:o[0],max:o[o.length-1]}:null;return {totalApiCalls:e.length,uniqueApiUrls:n.size,apiCallsByMethod:t,apiCallsByStatusRange:r,apiResponseTime:s}}function G(e){let t=0,r=0,n=0,o=0,s=0,i=0,a=0,l=0,c=0,d=e.length,u=0,p={},w=new Set,y=[];for(let h of e){w.add(h.url);for(let b of h.tests){switch(t++,b.status){case "passed":r++;break;case "failed":n++;break;case "flaky":o++;break;case "skipped":s++;break;case "timedout":i++;break}if(b.actions)for(let A of b.actions)if(u++,A.category==="assertion")a++,A.status==="passed"?l++:c++;else {let R=A.category;p[R]=(p[R]??0)+1;}b.apiCalls&&b.apiCalls.length>0&&y.push(...b.apiCalls);}}let g=ro(y);return {total:t,passed:r,failed:n,flaky:o,skipped:s,timedout:i,...g,totalAssertions:a,passedAssertions:l,failedAssertions:c,totalNavigations:d,uniqueNavigationUrls:w.size,totalTimelineSteps:e.length,totalActionSteps:u,actionStepsByCategory:p}}var Ot=`
5
5
  /* \u2500\u2500 Theme Variables (verbatim from Appium) \u2500\u2500 */
6
6
  :root,[data-theme="dark"]{
7
7
  --bg:#0f1117;--bg-1:#161b22;--bg-2:#1c2128;--bg-3:#21262d;--bg-code:#13111c;
@@ -365,15 +365,15 @@ body{font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Rob
365
365
  .test-row-arrow{display:none}
366
366
  .summary-chip,.filter-chip,.status-indicator,.detail-status-badge,.dm-badge,.trb,.cmd-badge,.ai-severity{print-color-adjust:exact;-webkit-print-color-adjust:exact}
367
367
  }
368
- `;var _t=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 196 247" fill="none">
368
+ `;var Ut=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 196 247" fill="none">
369
369
  <path fill-rule="evenodd" clip-rule="evenodd" d="M4.75 1.08009C2.034 2.66209 -0.130999 7.63009 0.610001 10.5821C0.969001 12.0121 3.021 15.2131 5.17 17.6971C14.375 28.3321 18 39.7791 18 58.2101V71.0001H12.434C1.16501 71.0001 0 73.4641 0 97.3051C0 106.858 0.298003 128.922 0.662003 146.337L1.323 178H33.606C65.786 178 65.897 178.007 68.544 180.284C72.228 183.453 72.244 189.21 68.579 192.877L65.957 195.5L33.479 195.801L1 196.103V204.551V213H24.577H48.154L51.077 215.923C55.007 219.853 55.007 224.147 51.077 228.077L48.154 231H26.469H4.783L5.41901 233.534C5.76901 234.927 7.143 238.527 8.472 241.534L10.89 247H40.945H71L71.006 241.75C71.017 230.748 76.027 221.606 84.697 216.767C97.854 209.424 114.086 213.895 121.323 226.857C123.659 231.041 124.418 233.833 124.789 239.607L125.263 247H155.187H185.11L187.528 241.534C188.857 238.527 190.231 234.927 190.581 233.534L191.217 231H169.531H147.846L144.923 228.077C142.928 226.082 142 224.152 142 222C142 219.848 142.928 217.918 144.923 215.923L147.846 213H171.423H195V204.551V196.103L162.521 195.801L130.043 195.5L127.421 192.877C123.991 189.445 123.835 183.869 127.074 180.421L129.349 178H162.013H194.677L195.338 146.337C195.702 128.922 196 106.858 196 97.3051C196 73.4641 194.835 71.0001 183.566 71.0001H178V58.2101C178 39.6501 181.397 28.7731 190.538 18.0651C195.631 12.0971 196.572 9.00809 194.511 5.02109C192.672 1.46509 190.197 9.12233e-05 186.028 9.12233e-05C179.761 9.12233e-05 168.713 14.8831 163.388 30.5001C160.975 37.5771 160.608 40.3751 160.213 54.7501L159.765 71.0001H150.732H141.7L142.286 53.2501C142.904 34.5511 144.727 24.3761 148.938 16.1211C151.823 10.4671 151.628 5.90109 148.364 2.63609C145 -0.726907 140.105 -0.887909 136.596 2.25009C133.481 5.03609 128.686 17.0811 126.507 27.5921C125.569 32.1191 124.617 43.0901 124.28 53.2501L123.69 71.0001H115.345H107V38.4231V5.84609L104.077 2.92309C102.082 0.928088 100.152 9.12233e-05 98 9.12233e-05C95.848 9.12233e-05 93.918 0.928088 91.923 2.92309L89 5.84609V38.4231V71.0001H80.655H72.31L71.72 53.2501C71.383 43.0901 70.431 32.1191 69.493 27.5921C67.314 17.0811 62.519 5.03609 59.404 2.25009C55.998 -0.795909 51.059 -0.710905 47.646 2.45209C44.221 5.62609 44.191 9.92109 47.539 17.4911C51.71 26.9241 53.007 34.4791 53.676 53.2501L54.31 71.0001H45.272H36.235L35.787 54.7501C35.392 40.3751 35.025 37.5771 32.612 30.5001C27.194 14.6091 16.228 -0.02891 9.787 0.03009C7.979 0.04709 5.712 0.519093 4.75 1.08009ZM42.687 108.974C33.431 112.591 20.036 125.024 18.408 131.512C17.476 135.223 20.677 140.453 28.253 147.599C37.495 156.319 44.191 159.471 53.5 159.485C59.317 159.494 61.645 158.953 67.274 156.289C77.634 151.385 88.987 139.161 88.996 132.9C89.004 127.304 76.787 114.707 66.745 109.956C59.16 106.368 50.285 106.006 42.687 108.974ZM129.255 109.904C119.151 114.768 106.996 127.33 107.004 132.9C107.013 139.108 118.562 151.475 128.939 156.389C134.338 158.945 136.744 159.496 142.521 159.498C152.526 159.501 160.369 155.502 169.771 145.605C180.444 134.368 180.278 130.975 168.486 119.388C160.043 111.094 152.727 107.595 143 107.201C136.364 106.933 134.78 107.244 129.255 109.904ZM48.5 125.922C46.3 126.969 43.152 128.945 41.505 130.314L38.511 132.802L40.504 135.005C41.601 136.216 44.434 138.342 46.8 139.728C52.577 143.114 57.36 142.466 64.009 137.395L68.978 133.606L66.756 131.24C60.944 125.054 54.357 123.135 48.5 125.922ZM138.386 125.063C136.674 125.571 133.375 127.677 131.057 129.743L126.841 133.5L131.901 137.343C138.65 142.468 143.407 143.124 149.2 139.728C151.566 138.342 154.351 136.269 155.389 135.122C157.684 132.587 156.742 131.097 150.58 127.511C145.438 124.519 142.329 123.895 138.386 125.063ZM91.923 162.923C89.043 165.804 89 166.008 89 176.973C89 184.805 89.435 188.941 90.47 190.941C92.356 194.589 96.918 196.273 101.03 194.84C105.82 193.17 107 189.638 107 176.973C107 166.008 106.957 165.804 104.077 162.923C102.082 160.928 100.152 160 98 160C95.848 160 93.918 160.928 91.923 162.923ZM94.5 232.155C91.026 234.055 90 236.229 90 241.691V247H98H106V242.082C106 235.732 105.37 234.242 101.928 232.463C98.591 230.737 97.197 230.679 94.5 232.155Z" fill="url(#paint0_linear_55_11)"/>
370
370
  <defs><linearGradient id="paint0_linear_55_11" x1="98" y1="0.000244141" x2="98" y2="247" gradientUnits="userSpaceOnUse">
371
371
  <stop stop-color="#03B79C"/><stop offset="0.504808" stop-color="#4EDAA4"/><stop offset="0.865285" stop-color="#84F3AA"/>
372
- </linearGradient></defs></svg>`,Lt=`<svg width="32" height="40" viewBox="0 0 196 247" fill="none" xmlns="http://www.w3.org/2000/svg">
372
+ </linearGradient></defs></svg>`,Ht=`<svg width="32" height="40" viewBox="0 0 196 247" fill="none" xmlns="http://www.w3.org/2000/svg">
373
373
  <path fill-rule="evenodd" clip-rule="evenodd" d="M4.75 1.08009C2.034 2.66209 -0.130999 7.63009 0.610001 10.5821C0.969001 12.0121 3.021 15.2131 5.17 17.6971C14.375 28.3321 18 39.7791 18 58.2101V71.0001H12.434C1.16501 71.0001 0 73.4641 0 97.3051C0 106.858 0.298003 128.922 0.662003 146.337L1.323 178H33.606C65.786 178 65.897 178.007 68.544 180.284C72.228 183.453 72.244 189.21 68.579 192.877L65.957 195.5L33.479 195.801L1 196.103V204.551V213H24.577H48.154L51.077 215.923C55.007 219.853 55.007 224.147 51.077 228.077L48.154 231H26.469H4.783L5.41901 233.534C5.76901 234.927 7.143 238.527 8.472 241.534L10.89 247H40.945H71L71.006 241.75C71.017 230.748 76.027 221.606 84.697 216.767C97.854 209.424 114.086 213.895 121.323 226.857C123.659 231.041 124.418 233.833 124.789 239.607L125.263 247H155.187H185.11L187.528 241.534C188.857 238.527 190.231 234.927 190.581 233.534L191.217 231H169.531H147.846L144.923 228.077C142.928 226.082 142 224.152 142 222C142 219.848 142.928 217.918 144.923 215.923L147.846 213H171.423H195V204.551V196.103L162.521 195.801L130.043 195.5L127.421 192.877C123.991 189.445 123.835 183.869 127.074 180.421L129.349 178H162.013H194.677L195.338 146.337C195.702 128.922 196 106.858 196 97.3051C196 73.4641 194.835 71.0001 183.566 71.0001H178V58.2101C178 39.6501 181.397 28.7731 190.538 18.0651C195.631 12.0971 196.572 9.00809 194.511 5.02109C192.672 1.46509 190.197 9.12233e-05 186.028 9.12233e-05C179.761 9.12233e-05 168.713 14.8831 163.388 30.5001C160.975 37.5771 160.608 40.3751 160.213 54.7501L159.765 71.0001H150.732H141.7L142.286 53.2501C142.904 34.5511 144.727 24.3761 148.938 16.1211C151.823 10.4671 151.628 5.90109 148.364 2.63609C145 -0.726907 140.105 -0.887909 136.596 2.25009C133.481 5.03609 128.686 17.0811 126.507 27.5921C125.569 32.1191 124.617 43.0901 124.28 53.2501L123.69 71.0001H115.345H107V38.4231V5.84609L104.077 2.92309C102.082 0.928088 100.152 9.12233e-05 98 9.12233e-05C95.848 9.12233e-05 93.918 0.928088 91.923 2.92309L89 5.84609V38.4231V71.0001H80.655H72.31L71.72 53.2501C71.383 43.0901 70.431 32.1191 69.493 27.5921C67.314 17.0811 62.519 5.03609 59.404 2.25009C55.998 -0.795909 51.059 -0.710905 47.646 2.45209C44.221 5.62609 44.191 9.92109 47.539 17.4911C51.71 26.9241 53.007 34.4791 53.676 53.2501L54.31 71.0001H45.272H36.235L35.787 54.7501C35.392 40.3751 35.025 37.5771 32.612 30.5001C27.194 14.6091 16.228 -0.02891 9.787 0.03009C7.979 0.04709 5.712 0.519093 4.75 1.08009ZM42.687 108.974C33.431 112.591 20.036 125.024 18.408 131.512C17.476 135.223 20.677 140.453 28.253 147.599C37.495 156.319 44.191 159.471 53.5 159.485C59.317 159.494 61.645 158.953 67.274 156.289C77.634 151.385 88.987 139.161 88.996 132.9C89.004 127.304 76.787 114.707 66.745 109.956C59.16 106.368 50.285 106.006 42.687 108.974ZM129.255 109.904C119.151 114.768 106.996 127.33 107.004 132.9C107.013 139.108 118.562 151.475 128.939 156.389C134.338 158.945 136.744 159.496 142.521 159.498C152.526 159.501 160.369 155.502 169.771 145.605C180.444 134.368 180.278 130.975 168.486 119.388C160.043 111.094 152.727 107.595 143 107.201C136.364 106.933 134.78 107.244 129.255 109.904ZM48.5 125.922C46.3 126.969 43.152 128.945 41.505 130.314L38.511 132.802L40.504 135.005C41.601 136.216 44.434 138.342 46.8 139.728C52.577 143.114 57.36 142.466 64.009 137.395L68.978 133.606L66.756 131.24C60.944 125.054 54.357 123.135 48.5 125.922ZM138.386 125.063C136.674 125.571 133.375 127.677 131.057 129.743L126.841 133.5L131.901 137.343C138.65 142.468 143.407 143.124 149.2 139.728C151.566 138.342 154.351 136.269 155.389 135.122C157.684 132.587 156.742 131.097 150.58 127.511C145.438 124.519 142.329 123.895 138.386 125.063ZM91.923 162.923C89.043 165.804 89 166.008 89 176.973C89 184.805 89.435 188.941 90.47 190.941C92.356 194.589 96.918 196.273 101.03 194.84C105.82 193.17 107 189.638 107 176.973C107 166.008 106.957 165.804 104.077 162.923C102.082 160.928 100.152 160 98 160C95.848 160 93.918 160.928 91.923 162.923ZM94.5 232.155C91.026 234.055 90 236.229 90 241.691V247H98H106V242.082C106 235.732 105.37 234.242 101.928 232.463C98.591 230.737 97.197 230.679 94.5 232.155Z" fill="url(#paint0_linear_55_11)"/>
374
374
  <defs><linearGradient id="paint0_linear_55_11" x1="98" y1="0.000244141" x2="98" y2="247" gradientUnits="userSpaceOnUse">
375
375
  <stop stop-color="#03B79C"/><stop offset="0.504808" stop-color="#4EDAA4"/><stop offset="0.865285" stop-color="#84F3AA"/>
376
- </linearGradient></defs></svg>`;var Dt=`
376
+ </linearGradient></defs></svg>`;var $t=`
377
377
  /* \u2500\u2500 Utilities \u2500\u2500 */
378
378
  function esc(s){if(!s)return '';return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;')}
379
379
  function fmtDur(ms){if(!ms||ms<=0)return '\\u2014';if(ms<1000)return Math.round(ms)+'ms';if(ms<60000)return (ms/1000).toFixed(1)+'s';var m=Math.floor(ms/60000),s=Math.round((ms%60000)/1000);return s>0?m+'m '+s+'s':m+'m'}
@@ -658,7 +658,7 @@ function renderFlowList(){
658
658
  }
659
659
  el.innerHTML=h;
660
660
  }
661
- `;var Nt=`
661
+ `;var Bt=`
662
662
  /* \u2500\u2500 Drawer Open/Close \u2500\u2500 */
663
663
  function openDrawer(flowIdx){
664
664
  openFlowIdx=flowIdx;
@@ -796,7 +796,7 @@ function renderRootCauseAnalysis(t,flow){
796
796
  h+='</div></div>';
797
797
  return h;
798
798
  }
799
- `;var Ot=`
799
+ `;var jt=`
800
800
  function renderStepsTab(flow){
801
801
  var actions=flow.test.actions||[];
802
802
  if(actions.length===0)return '<div class="no-tests">No step data available for this flow.</div>';
@@ -867,7 +867,7 @@ function getCmdBadge(cat){
867
867
  var pair=m[cat]||['CMD','cmd-badge-cmd'];
868
868
  return '<span class="cmd-badge '+pair[1]+'">'+pair[0]+'</span>';
869
869
  }
870
- `;var Ut=`
870
+ `;var zt=`
871
871
  function renderAssertionsTab(flow){
872
872
  var actions=flow.test.actions||[];
873
873
  var asserts=actions.filter(function(a){return a.category==='assertion'});
@@ -898,7 +898,7 @@ function renderAssertionsTab(flow){
898
898
  h+='</tbody></table>';
899
899
  return h;
900
900
  }
901
- `;var Ht=`
901
+ `;var qt=`
902
902
  function renderAiDefectsTab(){
903
903
  if(aiDefects.length===0)return '<div class="ai-empty">\\u2714 No AI defects detected.</div>';
904
904
  var h='<div style="font-size:12px;color:var(--fg-1);margin-bottom:16px">'+aiDefects.length+' defect'+(aiDefects.length>1?'s':'')+' found by Maestro AI analysis</div>';
@@ -978,7 +978,7 @@ function genericFixPlaybook(d){
978
978
  +'<li>Reproduce on a physical device</li>'
979
979
  +'<li>Add <code>assertNoDefectsWithAI</code> for regression detection</li></ul>';
980
980
  }
981
- `;var $t=`
981
+ `;var Gt=`
982
982
  /* \u2500\u2500 Theme \u2500\u2500 */
983
983
  function applyTheme(){
984
984
  var pref=localStorage.getItem('tr-theme')||'system';
@@ -1142,19 +1142,19 @@ document.addEventListener('input',function(e){
1142
1142
  document.addEventListener('keydown',function(e){
1143
1143
  if(e.key==='Escape'&&$('drawer').classList.contains('open'))closeDrawer();
1144
1144
  });
1145
- `;var Qn=`
1145
+ `;var no=`
1146
1146
  (function(){
1147
1147
  var payload=JSON.parse(document.getElementById('report-data').textContent);
1148
1148
  var report=payload.report;
1149
1149
  var aiDefects=payload.aiDefects||[];
1150
1150
  var screenshotPaths=payload.screenshotPaths||[];
1151
1151
 
1152
- ${Dt}
1153
- ${Nt}
1154
- ${Ot}
1155
- ${Ut}
1156
- ${Ht}
1157
1152
  ${$t}
1153
+ ${Bt}
1154
+ ${jt}
1155
+ ${zt}
1156
+ ${qt}
1157
+ ${Gt}
1158
1158
 
1159
1159
  applyTheme();
1160
1160
  renderRunMeta();
@@ -1164,7 +1164,7 @@ document.addEventListener('keydown',function(e){
1164
1164
  renderFlowList();
1165
1165
 
1166
1166
  var _lo=document.getElementById('loading-overlay');if(_lo)_lo.remove();
1167
- })();`;function $e(e){let t=e.replace(/<\//g,"<\\/");return `<!-- TestRelic Maestro Report \u2014 self-contained, no external dependencies -->
1167
+ })();`;function Be(e){let t=e.replace(/<\//g,"<\\/");return `<!-- TestRelic Maestro Report \u2014 self-contained, no external dependencies -->
1168
1168
  <!DOCTYPE html>
1169
1169
  <html lang="en" data-theme="">
1170
1170
  <head>
@@ -1172,15 +1172,15 @@ document.addEventListener('keydown',function(e){
1172
1172
  <meta name="viewport" content="width=device-width,initial-scale=1">
1173
1173
  <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data: blob: file: 'self'; media-src blob: 'self'; connect-src 'self';">
1174
1174
  <title>TestRelic Maestro Test Report</title>
1175
- <link rel="icon" type="image/svg+xml" href="data:image/svg+xml;base64,${Buffer.from(_t).toString("base64")}">
1176
- <style>${Pt}</style>
1175
+ <link rel="icon" type="image/svg+xml" href="data:image/svg+xml;base64,${Buffer.from(Ut).toString("base64")}">
1176
+ <style>${Ot}</style>
1177
1177
  <script>(function(){var p=localStorage.getItem('tr-theme')||'system';var t=p==='system'?(window.matchMedia('(prefers-color-scheme:light)').matches?'light':'dark'):p;document.documentElement.setAttribute('data-theme',t);})()</script>
1178
1178
  </head>
1179
1179
  <body>
1180
1180
  <div class="wrap">
1181
1181
  <div class="top-bar">
1182
1182
  <div class="brand">
1183
- ${Lt}
1183
+ ${Ht}
1184
1184
  <div class="brand-text">
1185
1185
  <span class="brand-title">TestRelic AI</span>
1186
1186
  <span class="brand-sub">Maestro Test Report</span>
@@ -1225,16 +1225,16 @@ document.addEventListener('keydown',function(e){
1225
1225
  <div class="drawer-body" id="drawer-body"></div>
1226
1226
  </aside>
1227
1227
  <script id="report-data" type="application/json">${t}</script>
1228
- <script>${Qn}</script>
1228
+ <script>${no}</script>
1229
1229
  </body>
1230
- </html>`}function Be(e,t,r,n){let o=path.resolve(n),s=path.dirname(o);fs.existsSync(s)||fs.mkdirSync(s,{recursive:true});let a=JSON.stringify({report:e,aiDefects:t,screenshotPaths:r}),l=$e(a);fs.writeFileSync(o,l,"utf-8");}function oo(e){let t=60-e.length;return t>0?e+" ".repeat(t):e}function D(e){return `\u2502 ${oo(e)} \u2502
1231
- `}function je(e,t,r,n,o){if(n||e.total===0)return;let s=`\u250C${"\u2500".repeat(62)}\u2510
1230
+ </html>`}function je(e,t,r,n){let o=path.resolve(n),s=path.dirname(o);fs.existsSync(s)||fs.mkdirSync(s,{recursive:true});let a=JSON.stringify({report:e,aiDefects:t,screenshotPaths:r}),l=Be(a);fs.writeFileSync(o,l,"utf-8");}function co(e){let t=60-e.length;return t>0?e+" ".repeat(t):e}function O(e){return `\u2502 ${co(e)} \u2502
1231
+ `}function ze(e,t,r,n,o){if(n||e.total===0)return;let s=`\u250C${"\u2500".repeat(62)}\u2510
1232
1232
  `,i=`\u2514${"\u2500".repeat(62)}\u2518
1233
- `,a=D(""),l=s;l+=D("TestRelic AI - Maestro Test Report"),l+=a;let c=[];if(e.passed>0&&c.push(`${e.passed} \u2713`),e.failed>0&&c.push(`${e.failed} \u2717`),e.flaky>0&&c.push(`${e.flaky} \u26A0`),e.skipped>0&&c.push(`${e.skipped} skipped`),e.timedout>0&&c.push(`${e.timedout} timedout`),l+=D(`Flows: ${e.total} total (${c.join(" ")})`),e.totalAssertions>0&&(l+=D(`Assertions: ${e.totalAssertions} total (${e.passedAssertions} \u2713 ${e.failedAssertions} \u2717)`)),e.totalActionSteps>0){let d=[],u=e.actionStepsByCategory;u.ui_action&&d.push(`${u.ui_action} UI`),u.navigation&&d.push(`${u.navigation} nav`),u.custom_step&&d.push(`${u.custom_step} custom`);let p=d.length>0?` (${d.join(" ")})`:"";l+=D(`Steps: ${e.totalActionSteps} total${p}`);}if(o&&o.length>0){let d=o.filter(b=>b.severity==="critical").length,u=o.filter(b=>b.severity==="warning").length,p=o.filter(b=>b.severity==="info").length,x=[];d>0&&x.push(`${d} critical`),u>0&&x.push(`${u} warning`),p>0&&x.push(`${p} info`),l+=D(`AI Defects: ${o.length} found (${x.join(" ")})`);}l+=D(`Report: ${r}`),l+=D(`Data: ${t}`),l+=i,l+=`For more information visit us at https://docs.testrelic.ai
1234
- `,process.stderr.write(l);}function ze(e){let t=process.platform,r;t==="darwin"?r=`open "${e}"`:t==="win32"?r=`start "" "${e}"`:r=`xdg-open "${e}"`,child_process.exec(r,()=>{});}function fo(){let e=[];try{let r=path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));e.push(path.join(r,"proxy-addon","testrelic_capture.py")),e.push(path.join(r,"..","src","proxy-addon","testrelic_capture.py"));}catch{}let t=globalThis.__dirname;t&&e.push(path.join(t,"proxy-addon","testrelic_capture.py"));for(let r of e)if(fs.existsSync(r))return path.resolve(r);return null}function go(e){if(e)return fs.mkdirSync(e,{recursive:true}),e;let t=crypto.randomBytes(6).toString("hex"),r=path.join(os.tmpdir(),`testrelic-maestro-network-${t}`);return fs.mkdirSync(r,{recursive:true}),r}async function mo(){return new Promise(e=>{let t=child_process.spawn("mitmdump",["--version"],{shell:true}),r=false,n=o=>{r||(r=true,e(o));};t.on("error",()=>n(false)),t.on("close",o=>n(o===0)),setTimeout(()=>{try{t.kill();}catch{}n(false);},5e3);})}async function zt(e){let{config:t,verbose:r=true}=e;if(!t.enabled)return null;if(!await mo())return r&&process.stderr.write("\u26A0 TestRelic: --capture-network requested but `mitmdump` is not on PATH.\n Install mitmproxy (`brew install mitmproxy` / `pipx install mitmproxy`)\n or supply --har-path to import a HAR file instead.\n"),null;let n=fo();if(!n)return r&&process.stderr.write(`\u26A0 TestRelic: network-capture addon not found in package; skipping capture.
1235
- `),null;let o=go(e.outputDir??t.outputDir??void 0),s=path.join(o,"network.jsonl"),i=["--listen-host",t.proxyHost,"--listen-port",String(t.proxyPort),"-s",n,"--set",`testrelic_output=${s}`,"--set",`testrelic_redact_headers=${t.redactHeaders.join(",")}`,"--set",`testrelic_redact_body_fields=${t.redactBodyFields.join(",")}`,"--set",`testrelic_max_body_bytes=${t.maxBodyBytes}`,"--set","console_eventlog_verbosity=warn","--set","termlog_verbosity=warn"],a;try{a=child_process.spawn("mitmdump",i,{stdio:["ignore","pipe","pipe"],shell:!0});}catch(c){return r&&process.stderr.write(`\u26A0 TestRelic: failed to spawn mitmdump: ${c.message}
1236
- `),null}a.stdout?.on("data",c=>{r&&process.stderr.write(`[mitmdump] ${c.toString("utf-8")}`);}),a.stderr?.on("data",c=>{r&&process.stderr.write(`[mitmdump] ${c.toString("utf-8")}`);}),await new Promise(c=>setTimeout(c,750));let l=()=>new Promise(c=>{if(a.killed||a.exitCode!==null){c();return}let d=false,u=()=>{d||(d=true,c());};a.once("close",u),a.once("exit",u);try{a.kill("SIGINT");}catch{try{a.kill();}catch{}}setTimeout(()=>{if(!d){try{a.kill("SIGKILL");}catch{}u();}},4e3);});return {outputPath:s,outputDir:o,host:t.proxyHost,port:t.proxyPort,stop:l}}var U={teardown:async()=>{}};function Vt(e){let t=child_process.spawnSync(e,["--version"],{shell:true,stdio:"ignore"});return t.error===void 0||t.error.code!=="ENOENT"}function E(e,t){e||process.stderr.write(`${t}
1237
- `);}function N(e,t,r,n){e||(t==="android"?process.stderr.write(`\u2139 TestRelic: real-device Android capture \u2014 set the device proxy manually:
1233
+ `,a=O(""),l=s;l+=O("TestRelic AI - Maestro Test Report"),l+=a;let c=[];if(e.passed>0&&c.push(`${e.passed} \u2713`),e.failed>0&&c.push(`${e.failed} \u2717`),e.flaky>0&&c.push(`${e.flaky} \u26A0`),e.skipped>0&&c.push(`${e.skipped} skipped`),e.timedout>0&&c.push(`${e.timedout} timedout`),l+=O(`Flows: ${e.total} total (${c.join(" ")})`),e.totalAssertions>0&&(l+=O(`Assertions: ${e.totalAssertions} total (${e.passedAssertions} \u2713 ${e.failedAssertions} \u2717)`)),e.totalActionSteps>0){let d=[],u=e.actionStepsByCategory;u.ui_action&&d.push(`${u.ui_action} UI`),u.navigation&&d.push(`${u.navigation} nav`),u.custom_step&&d.push(`${u.custom_step} custom`);let p=d.length>0?` (${d.join(" ")})`:"";l+=O(`Steps: ${e.totalActionSteps} total${p}`);}if(o&&o.length>0){let d=o.filter(y=>y.severity==="critical").length,u=o.filter(y=>y.severity==="warning").length,p=o.filter(y=>y.severity==="info").length,w=[];d>0&&w.push(`${d} critical`),u>0&&w.push(`${u} warning`),p>0&&w.push(`${p} info`),l+=O(`AI Defects: ${o.length} found (${w.join(" ")})`);}l+=O(`Report: ${r}`),l+=O(`Data: ${t}`),l+=i,l+=`For more information visit us at https://docs.testrelic.ai
1234
+ `,process.stderr.write(l);}function qe(e){let t=process.platform,r;t==="darwin"?r=`open "${e}"`:t==="win32"?r=`start "" "${e}"`:r=`xdg-open "${e}"`,child_process.exec(r,()=>{});}function yo(){let e=[];try{let r=path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));e.push(path.join(r,"proxy-addon","testrelic_capture.py")),e.push(path.join(r,"..","src","proxy-addon","testrelic_capture.py"));}catch{}let t=globalThis.__dirname;t&&e.push(path.join(t,"proxy-addon","testrelic_capture.py"));for(let r of e)if(fs.existsSync(r))return path.resolve(r);return null}function xo(e){if(e)return fs.mkdirSync(e,{recursive:true}),e;let t=crypto.randomBytes(6).toString("hex"),r=path.join(os.tmpdir(),`testrelic-maestro-network-${t}`);return fs.mkdirSync(r,{recursive:true}),r}async function wo(){return new Promise(e=>{let t=child_process.spawn("mitmdump",["--version"],{shell:true}),r=false,n=o=>{r||(r=true,e(o));};t.on("error",()=>n(false)),t.on("close",o=>n(o===0)),setTimeout(()=>{try{t.kill();}catch{}n(false);},5e3);})}async function Wt(e){let{config:t,verbose:r=true}=e;if(!t.enabled)return null;if(!await wo())return r&&process.stderr.write("\u26A0 TestRelic: --capture-network requested but `mitmdump` is not on PATH.\n Install mitmproxy (`brew install mitmproxy` / `pipx install mitmproxy`)\n or supply --har-path to import a HAR file instead.\n"),null;let n=yo();if(!n)return r&&process.stderr.write(`\u26A0 TestRelic: network-capture addon not found in package; skipping capture.
1235
+ `),null;let o=xo(e.outputDir??t.outputDir??void 0),s=path.join(o,"network.jsonl"),i=["--listen-host",t.proxyHost,"--listen-port",String(t.proxyPort),"-s",n,"--set",`testrelic_output=${s}`,"--set",`testrelic_redact_headers=${t.redactHeaders.join(",")}`,"--set",`testrelic_redact_body_fields=${t.redactBodyFields.join(",")}`,"--set",`testrelic_max_body_bytes=${t.maxBodyBytes}`,"--set","console_eventlog_verbosity=warn","--set","termlog_verbosity=warn"],a;try{a=child_process.spawn("mitmdump",i,{stdio:["ignore","pipe","pipe"],shell:!0});}catch(c){return r&&process.stderr.write(`\u26A0 TestRelic: failed to spawn mitmdump: ${c.message}
1236
+ `),null}a.stdout?.on("data",c=>{r&&process.stderr.write(`[mitmdump] ${c.toString("utf-8")}`);}),a.stderr?.on("data",c=>{r&&process.stderr.write(`[mitmdump] ${c.toString("utf-8")}`);}),await new Promise(c=>setTimeout(c,750));let l=()=>new Promise(c=>{if(a.killed||a.exitCode!==null){c();return}let d=false,u=()=>{d||(d=true,c());};a.once("close",u),a.once("exit",u);try{a.kill("SIGINT");}catch{try{a.kill();}catch{}}setTimeout(()=>{if(!d){try{a.kill("SIGKILL");}catch{}u();}},4e3);});return {outputPath:s,outputDir:o,host:t.proxyHost,port:t.proxyPort,stop:l}}var $={teardown:async()=>{}};function Yt(e){let t=child_process.spawnSync(e,["--version"],{shell:true,stdio:"ignore"});return t.error===void 0||t.error.code!=="ENOENT"}function E(e,t){e||process.stderr.write(`${t}
1237
+ `);}function U(e,t,r,n){e||(t==="android"?process.stderr.write(`\u2139 TestRelic: real-device Android capture \u2014 set the device proxy manually:
1238
1238
  Settings \u2192 Wi-Fi \u2192 (long-press your network) \u2192 Modify \u2192 Proxy: Manual
1239
1239
  Host: ${r} Port: ${n}
1240
1240
  Then install mitmproxy CA: open http://mitm.it from the device after the proxy is reachable.
@@ -1244,33 +1244,33 @@ document.addEventListener('keydown',function(e){
1244
1244
  Then install + TRUST the mitmproxy CA:
1245
1245
  1. Open http://mitm.it from Safari on the device \u2192 install profile.
1246
1246
  2. Settings \u2192 General \u2192 About \u2192 Certificate Trust Settings \u2192 enable mitmproxy.
1247
- `));}async function qt(e,t){return new Promise(r=>{let n=t?["-s",t,...e]:e,o=child_process.spawn("adb",n,{shell:true,stdio:["ignore","pipe","pipe"]}),s="",i="";o.stdout?.on("data",a=>{s+=a.toString();}),o.stderr?.on("data",a=>{i+=a.toString();}),o.on("error",()=>r({code:127,stdout:s,stderr:i||"adb not on PATH"})),o.on("close",a=>r({code:a??1,stdout:s,stderr:i}));})}async function xo(e){let{deviceId:t,proxyHost:r,proxyPort:n,quiet:o,skipCertInstall:s}=e;if(!Vt("adb"))return E(o,"\u26A0 TestRelic: `adb` not on PATH; skipping automatic Android proxy setup. See manual instructions:"),N(o,"android",r,n),U;let i=await qt(["shell","settings","put","global","http_proxy",`${r}:${n}`],t);return i.code!==0?(E(o,`\u26A0 TestRelic: adb set proxy failed: ${i.stderr.trim()||"unknown error"}`),N(o,"android",r,n),U):(E(o,`\u2139 TestRelic: Android proxy set to ${r}:${n} on ${t??"default device"}.`),s||E(o,`\u2139 TestRelic: if HTTPS calls fail, install the mitmproxy CA on the emulator:
1247
+ `));}async function Kt(e,t){return new Promise(r=>{let n=t?["-s",t,...e]:e,o=child_process.spawn("adb",n,{shell:true,stdio:["ignore","pipe","pipe"]}),s="",i="";o.stdout?.on("data",a=>{s+=a.toString();}),o.stderr?.on("data",a=>{i+=a.toString();}),o.on("error",()=>r({code:127,stdout:s,stderr:i||"adb not on PATH"})),o.on("close",a=>r({code:a??1,stdout:s,stderr:i}));})}async function Ro(e){let{deviceId:t,proxyHost:r,proxyPort:n,quiet:o,skipCertInstall:s}=e;if(!Yt("adb"))return E(o,"\u26A0 TestRelic: `adb` not on PATH; skipping automatic Android proxy setup. See manual instructions:"),U(o,"android",r,n),$;let i=await Kt(["shell","settings","put","global","http_proxy",`${r}:${n}`],t);return i.code!==0?(E(o,`\u26A0 TestRelic: adb set proxy failed: ${i.stderr.trim()||"unknown error"}`),U(o,"android",r,n),$):(E(o,`\u2139 TestRelic: Android proxy set to ${r}:${n} on ${t??"default device"}.`),s||E(o,`\u2139 TestRelic: if HTTPS calls fail, install the mitmproxy CA on the emulator:
1248
1248
  open http://mitm.it from Chrome on the emulator and follow prompts,
1249
1249
  OR for a system-level install:
1250
1250
  adb root && adb remount && adb push <mitm-ca>.0 /system/etc/security/cacerts/ && adb reboot
1251
- Set --skip-cert-install to silence this hint.`),{teardown:async()=>{await qt(["shell","settings","put","global","http_proxy",":0"],t);}})}async function wo(e){return new Promise(t=>{let r=child_process.spawn("xcrun",e,{shell:true,stdio:["ignore","pipe","pipe"]}),n="",o="";r.stdout?.on("data",s=>{n+=s.toString();}),r.stderr?.on("data",s=>{o+=s.toString();}),r.on("error",()=>t({code:127,stdout:n,stderr:o||"xcrun not on PATH"})),r.on("close",s=>t({code:s??1,stdout:n,stderr:o}));})}async function vo(e){let{proxyHost:t,proxyPort:r,quiet:n,skipCertInstall:o}=e;if(process.platform!=="darwin")return E(n,"\u26A0 TestRelic: iOS simulator capture requires macOS; the host is not Darwin. Skipping setup."),N(n,"ios",t,r),U;if(!Vt("xcrun"))return E(n,"\u26A0 TestRelic: `xcrun` not on PATH; skipping automatic iOS simulator setup."),N(n,"ios",t,r),U;if(!o){let s=path.join(process.env.HOME??"",".mitmproxy","mitmproxy-ca-cert.pem");if(fs.existsSync(s)){let i=e.deviceId??"booted",a=await wo(["simctl","keychain",i,"add-root-cert",s]);a.code===0?E(n,`\u2139 TestRelic: installed mitmproxy CA on iOS simulator (${i}).`):(E(n,`\u26A0 TestRelic: failed to add-root-cert via simctl: ${a.stderr.trim()}`),N(n,"ios",t,r));}else E(n,`\u26A0 TestRelic: mitmproxy CA not found at ${s}. Run mitmdump once to generate it,
1252
- then re-run with --capture-network. Falling back to manual instructions:`),N(n,"ios",t,r);}return E(n,`\u2139 TestRelic: in the iOS simulator, configure Wi-Fi \u2192 (i) \u2192 Manual proxy:
1251
+ Set --skip-cert-install to silence this hint.`),{teardown:async()=>{await Kt(["shell","settings","put","global","http_proxy",":0"],t);}})}async function So(e){return new Promise(t=>{let r=child_process.spawn("xcrun",e,{shell:true,stdio:["ignore","pipe","pipe"]}),n="",o="";r.stdout?.on("data",s=>{n+=s.toString();}),r.stderr?.on("data",s=>{o+=s.toString();}),r.on("error",()=>t({code:127,stdout:n,stderr:o||"xcrun not on PATH"})),r.on("close",s=>t({code:s??1,stdout:n,stderr:o}));})}async function Ao(e){let{proxyHost:t,proxyPort:r,quiet:n,skipCertInstall:o}=e;if(process.platform!=="darwin")return E(n,"\u26A0 TestRelic: iOS simulator capture requires macOS; the host is not Darwin. Skipping setup."),U(n,"ios",t,r),$;if(!Yt("xcrun"))return E(n,"\u26A0 TestRelic: `xcrun` not on PATH; skipping automatic iOS simulator setup."),U(n,"ios",t,r),$;if(!o){let s=path.join(process.env.HOME??"",".mitmproxy","mitmproxy-ca-cert.pem");if(fs.existsSync(s)){let i=e.deviceId??"booted",a=await So(["simctl","keychain",i,"add-root-cert",s]);a.code===0?E(n,`\u2139 TestRelic: installed mitmproxy CA on iOS simulator (${i}).`):(E(n,`\u26A0 TestRelic: failed to add-root-cert via simctl: ${a.stderr.trim()}`),U(n,"ios",t,r));}else E(n,`\u26A0 TestRelic: mitmproxy CA not found at ${s}. Run mitmdump once to generate it,
1252
+ then re-run with --capture-network. Falling back to manual instructions:`),U(n,"ios",t,r);}return E(n,`\u2139 TestRelic: in the iOS simulator, configure Wi-Fi \u2192 (i) \u2192 Manual proxy:
1253
1253
  Server: ${t} Port: ${r}
1254
- (We do not set host-wide \`networksetup\` proxy automatically; see docs.)`),U}async function Jt(e){switch(e.platform){case "android":return xo(e);case "ios":return vo(e);case "web":return E(e.quiet,"\u2139 TestRelic: --capture-network ignored for Maestro web flows (browser already handles HTTP)."),U;default:return E(e.quiet,"\u26A0 TestRelic: target platform unknown; printing manual proxy setup instructions:"),N(e.quiet,"android",e.proxyHost,e.proxyPort),N(e.quiet,"ios",e.proxyHost,e.proxyPort),U}}function So(){let e=crypto.randomBytes(8).toString("hex");return path.join(os.tmpdir(),`testrelic-maestro-${e}`)}function Kt(e,t){let r=[];e.platform&&r.push("--platform",e.platform),e.device&&r.push("--device",e.device),r.push("test");let n=path.join(t,"report.xml"),o=path.join(t,"artifacts"),s=path.join(t,"debug");if(r.push("--format","junit"),r.push("--output",n),r.push("--test-output-dir",o),r.push("--debug-output",s),e.analyze&&r.push("--analyze"),e.includeTags&&r.push("--include-tags",e.includeTags),e.excludeTags&&r.push("--exclude-tags",e.excludeTags),e.shards&&e.shards>1&&r.push("--shards",String(e.shards)),e.config&&r.push("--config",e.config),e.env)for(let[i,a]of Object.entries(e.env))r.push("-e",`${i}=${a}`);return e.maestroArgs&&r.push(...e.maestroArgs),r.push(...e.flowPaths),r}function To(e){switch((e??"").toLowerCase()){case "android":return "android";case "ios":return "ios";case "web":return "web";default:return "unknown"}}function Io(e,t,r,n,o,s,i){return new Promise(a=>{let l=[],c=[],d=child_process.spawn("maestro",e,{stdio:["inherit","pipe","pipe"],shell:true});d.stdout.on("data",u=>{l.push(u),s||process.stdout.write(u);}),d.stderr.on("data",u=>{c.push(u),s||process.stderr.write(u);}),d.on("close",async u=>{try{await i();}catch{}a({exitCode:u??1,junitPath:t,testOutputDir:r,debugOutputDir:n,stdout:Buffer.concat(l).toString("utf-8"),stderr:Buffer.concat(c).toString("utf-8"),networkJsonlDir:o});}),d.on("error",async u=>{try{await i();}catch{}a({exitCode:127,junitPath:t,testOutputDir:r,debugOutputDir:n,stdout:"",stderr:`Failed to start maestro CLI: ${u.message}`,networkJsonlDir:o});});})}async function Mo(e,t={}){let r=e.outputDir?path.resolve(e.outputDir):So();fs.mkdirSync(path.join(r,"artifacts"),{recursive:true}),fs.mkdirSync(path.join(r,"debug"),{recursive:true});let n=Kt(e,r),o=path.join(r,"report.xml"),s=path.join(r,"artifacts"),i=path.join(r,"debug"),a=null,l=null,c=t.network;if(c?.enabled){let p=path.join(r,"network");a=await zt({config:c,outputDir:p,verbose:!e.quiet}),a&&(l=await Jt({platform:To(e.platform),deviceId:e.device,proxyHost:a.host,proxyPort:a.port,skipCertInstall:c.skipCertInstall,quiet:e.quiet}));}let d=a?.outputDir??null,u=async()=>{if(a&&await new Promise(p=>setTimeout(p,500)),l)try{await l.teardown();}catch{}if(a)try{await a.stop();}catch{}};return Io(n,o,s,i,d,e.quiet,u)}var Qt="[REDACTED]";function Xt(e,t){if(!e)return null;let r=new Set(t.map(o=>o.toLowerCase())),n={};for(let[o,s]of Object.entries(e))n[o]=r.has(o.toLowerCase())?Qt:s;return n}function qe(e,t){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>qe(n,t));let r={};for(let[n,o]of Object.entries(e))r[n]=t.has(n)?Qt:qe(o,t);return r}function Yt(e,t){if(!e||t.length===0)return e;try{let r=JSON.parse(e),n=qe(r,new Set(t));return JSON.stringify(n)}catch{return e}}function Ge(e,t,r){return {...e,requestHeaders:Xt(e.requestHeaders,t),responseHeaders:Xt(e.responseHeaders,t),requestBody:Yt(e.requestBody,r),responseBody:e.isBinary?e.responseBody:Yt(e.responseBody,r)}}function Ve(e,t,r){let n=o=>typeof o=="string"?e.includes(o):o.test(e);return r.some(n)?false:t.length===0?true:t.some(n)}function Po(e){let t=e.trim();if(!t)return null;try{let r=JSON.parse(t);return typeof r.url!="string"||typeof r.method!="string"?null:{id:r.id??`api-call-${Date.now()}`,timestamp:r.timestamp??new Date().toISOString(),method:r.method,url:r.url,requestHeaders:r.requestHeaders??null,requestBody:r.requestBody??null,responseStatusCode:r.responseStatusCode??null,responseStatusText:r.responseStatusText??null,responseHeaders:r.responseHeaders??null,responseBody:r.responseBody??null,responseTimeMs:typeof r.responseTimeMs=="number"?r.responseTimeMs:0,isBinary:r.isBinary??!1,error:r.error??null}}catch{return null}}function _o(e,t){let r=[];for(let n of e.split(/\r?\n/)){let o=Po(n);o&&Ve(o.url,t.includeUrls,t.excludeUrls)&&r.push(Ge(o,t.redactHeaders,t.redactBodyFields));}return r}function Lo(e,t){try{return _o(fs.readFileSync(e,"utf-8"),t)}catch{return []}}function Do(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>t.endsWith(".jsonl")).map(t=>path.join(e,t))}catch{return []}}function Zt(e){if(!e||e.length===0)return null;let t={};for(let r of e)typeof r.name=="string"&&typeof r.value=="string"&&(t[r.name]=r.value);return Object.keys(t).length>0?t:null}function No(e){return e?typeof e.text=="string"?e.text:Array.isArray(e.params)?e.params.map(t=>`${encodeURIComponent(t.name)}=${encodeURIComponent(t.value??"")}`).join("&"):null:null}function Oo(e){return e?/^(image|audio|video|application\/(octet-stream|pdf|zip|protobuf))/.test(e):false}function Uo(e,t){let r=e.request,n=e.response;if(!r?.method||!r.url)return null;let o=n?.content,s=Oo(o?.mimeType);return {id:`har-call-${t}`,timestamp:e.startedDateTime??new Date().toISOString(),method:r.method,url:r.url,requestHeaders:Zt(r.headers),requestBody:No(r.postData),responseStatusCode:typeof n?.status=="number"&&n.status>0?n.status:null,responseStatusText:n?.statusText??null,responseHeaders:Zt(n?.headers),responseBody:o?.text??null,responseTimeMs:typeof e.time=="number"?e.time:0,isBinary:s,error:null}}function Ho(e,t){let r;try{r=JSON.parse(e);}catch{return []}let n=r.log?.entries??[],o=[];return n.forEach((s,i)=>{let a=Uo(s,i);a&&Ve(a.url,t.includeUrls,t.excludeUrls)&&o.push(Ge(a,t.redactHeaders,t.redactBodyFields));}),o}function $o(e,t){try{return Ho(fs.readFileSync(e,"utf-8"),t)}catch{return []}}function Bo(e,t){let r=new Map;for(let o of t)r.set(o.testId,[]);if(e.length===0||t.length===0)return r;let n=t.map(o=>({testId:o.testId,startMs:Date.parse(o.startedAt),endMs:Date.parse(o.completedAt)}));for(let o of e){let s=Date.parse(o.timestamp);if(!Number.isFinite(s))continue;let i=n.find(l=>Number.isFinite(l.startMs)&&Number.isFinite(l.endMs)&&s>=l.startMs&&s<=l.endMs);if(i){r.get(i.testId).push(o);continue}let a=null;for(let l of n){if(!Number.isFinite(l.startMs)||!Number.isFinite(l.endMs))continue;let c=s<l.startMs?l.startMs-s:s-l.endMs;(!a||c<a.dist)&&(a={testId:l.testId,dist:c});}a&&r.get(a.testId).push(o);}return r}function rr(e,t,r){if(!t.enabled&&!t.harPath)return new Map;let n=[];if(e)for(let o of Do(e))n.push(...Lo(o,t));return t.harPath&&fs.existsSync(t.harPath)&&n.push(...$o(t.harPath,t)),n.length===0?new Map:Bo(n,r)}function nr(e){return e.map((t,r)=>({...t,id:`api-call-${r}`}))}var qo=new Set(["localhost","127.0.0.1","0.0.0.0"]);function Je(e){let t=new URL(e);if(t.protocol!=="https:"&&!(t.protocol==="http:"&&qo.has(t.hostname)))throw core.createError(core.ErrorCode.CLOUD_CONFIG_INVALID,`HTTPS is required for cloud communication. Got: ${t.protocol}//${t.hostname}`)}var Go=3e3;async function ee(e){let t=new AbortController,r=setTimeout(()=>t.abort(),Go);try{return (await fetch(`${e}/health`,{method:"GET",signal:t.signal})).ok}catch{return false}finally{clearTimeout(r);}}async function sr(e){return new Promise(t=>setTimeout(t,e))}async function or(e){try{let r=(await e.json()).error;if(r&&typeof r.message=="string")return r.message}catch{}return `HTTP ${e.status}`}async function te(e,t,r){let n=new AbortController,o=setTimeout(()=>n.abort(),r);try{let s=await fetch(`${e}/sdk/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:t}),signal:n.signal});if(s.ok){let a=await s.json();return {accessToken:a.accessToken,refreshToken:a.refreshToken,expiresIn:a.expiresIn,orgId:a.orgId,orgName:a.orgName,userId:a.userId,userName:a.userName}}if(s.status===429){let a=s.headers.get("Retry-After"),l=a?parseInt(a,10)*1e3:5e3;if(!isNaN(l)&&l>0){await sr(l);let c=await fetch(`${e}/sdk/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:t}),signal:n.signal});if(c.ok){let d=await c.json();return {accessToken:d.accessToken,refreshToken:d.refreshToken,expiresIn:d.expiresIn,orgId:d.orgId,orgName:d.orgName,userId:d.userId,userName:d.userName}}}return {code:"rate_limited",message:"Rate limited during token exchange.",statusCode:429}}return s.status===400?{code:"validation_error",message:await or(s),statusCode:400}:s.status===401?{code:"invalid_key",message:"API key is invalid or has been revoked.",statusCode:401}:s.status===403?{code:"expired_key",message:"API key has expired.",statusCode:403}:{code:"server_error",message:await or(s),statusCode:s.status}}catch(s){return s instanceof DOMException&&s.name==="AbortError"?{code:"timeout",message:"Token exchange timed out.",statusCode:null}:{code:"network_error",message:"Failed to reach cloud for token exchange.",statusCode:null}}finally{clearTimeout(o);}}function re(e){return "code"in e&&typeof e.code=="string"&&["invalid_key","expired_key","validation_error","rate_limited","server_error","network_error","timeout"].includes(e.code)}async function We(e,t,r){let n=new AbortController,o=setTimeout(()=>n.abort(),r);try{let s=await fetch(`${e}/sdk/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t}),signal:n.signal});if(s.status===429){let a=s.headers.get("Retry-After"),l=a?parseInt(a,10)*1e3:5e3;!isNaN(l)&&l>0&&(await sr(l),s=await fetch(`${e}/sdk/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t}),signal:n.signal}));}if(!s.ok)return null;let i=await s.json();return {accessToken:i.accessToken,refreshToken:i.refreshToken,expiresIn:i.expiresIn}}catch{return null}finally{clearTimeout(o);}}async function Ke(e,t,r,n,o,s){let i=new AbortController,a=setTimeout(()=>i.abort(),o);try{let l={gitId:r,displayName:n};s&&(l.branch=s);let c=await fetch(`${e}/repos/resolve`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(l),signal:i.signal});if(!c.ok)return null;let d=await c.json();return {repoId:d.repoId,displayName:d.displayName}}catch{return null}finally{clearTimeout(a);}}var Xo=5e3;function O(e,t){try{return child_process.execSync(e,{cwd:t,timeout:Xo,encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim()||null}catch{return null}}function Xe(e){let t=O("git rev-parse --abbrev-ref HEAD",e),r=O("git rev-parse --short HEAD",e),n=O("git log -1 --pretty=%s",e),o=O("git log -1 --format=%an",e)??O("git config user.name",e),s=Yo(e),i=s?j(s):null;return {branch:t,commitSha:r,commitMessage:n,commitAuthor:o,remoteUrl:i}}function Yo(e){let t=O("git remote get-url origin",e);if(t)return t;let r=O("git remote",e);if(!r)return null;let n=r.split(`
1255
- `)[0]?.trim();return n?O(`git remote get-url ${n}`,e):null}function j(e){let t=e.trim();return t=t.replace(/^[a-z+]+:\/\//,""),t=t.replace(/^[^@]+@/,""),t=t.replace(/:(?!\d)/,"/"),t=t.replace(/\.git$/,""),t=t.replace(/\/+$/,""),t=t.replace(/^[^@/]+@/,""),t.toLowerCase()}function Ye(e){let t=e.split("/").filter(Boolean);return t[t.length-1]??e}function ir(e){try{let t=fs.readFileSync(path.join(e,"package.json"),"utf-8"),r=JSON.parse(t);return typeof r.name=="string"&&r.name.length>0?r.name:null}catch{return null}}function z(e){let t=ir(e);return t||`local/${path.basename(e)}`}var ns="1.0.0",ar=10;function oe(e,t,r,n,o,s,i,a){try{fs.mkdirSync(e,{recursive:!0});let l=Date.now(),c=`${l}-${t}-${r}.json`,d=path.join(e,c),u={version:ns,queuedAt:new Date(l).toISOString(),reason:n,retryCount:0,targetEndpoint:o,method:s,payload:i,headers:a},p=d+".tmp";fs.writeFileSync(p,JSON.stringify(u,null,2),"utf-8"),fs.renameSync(p,d);}catch(l){l.code==="ENOSPC"?process.stderr.write(`\u26A0 TestRelic: Disk full \u2014 unable to queue upload data.
1254
+ (We do not set host-wide \`networksetup\` proxy automatically; see docs.)`),$}async function Qt(e){switch(e.platform){case "android":return Ro(e);case "ios":return Ao(e);case "web":return E(e.quiet,"\u2139 TestRelic: --capture-network ignored for Maestro web flows (browser already handles HTTP)."),$;default:return E(e.quiet,"\u26A0 TestRelic: target platform unknown; printing manual proxy setup instructions:"),U(e.quiet,"android",e.proxyHost,e.proxyPort),U(e.quiet,"ios",e.proxyHost,e.proxyPort),$}}function Fo(){let e=crypto.randomBytes(8).toString("hex");return path.join(os.tmpdir(),`testrelic-maestro-${e}`)}function er(e,t){let r=[];e.platform&&r.push("--platform",e.platform),e.device&&r.push("--device",e.device),r.push("test");let n=path.join(t,"report.xml"),o=path.join(t,"artifacts"),s=path.join(t,"debug");if(r.push("--format","junit"),r.push("--output",n),r.push("--test-output-dir",o),r.push("--debug-output",s),e.analyze&&r.push("--analyze"),e.includeTags&&r.push("--include-tags",e.includeTags),e.excludeTags&&r.push("--exclude-tags",e.excludeTags),e.shards&&e.shards>1&&r.push("--shards",String(e.shards)),e.config&&r.push("--config",e.config),e.env)for(let[i,a]of Object.entries(e.env))r.push("-e",`${i}=${a}`);return e.maestroArgs&&r.push(...e.maestroArgs),r.push(...e.flowPaths),r}function Po(e){switch((e??"").toLowerCase()){case "android":return "android";case "ios":return "ios";case "web":return "web";default:return "unknown"}}function _o(e,t,r,n,o,s,i){return new Promise(a=>{let l=[],c=[],d=child_process.spawn("maestro",e,{stdio:["inherit","pipe","pipe"],shell:true});d.stdout.on("data",u=>{l.push(u),s||process.stdout.write(u);}),d.stderr.on("data",u=>{c.push(u),s||process.stderr.write(u);}),d.on("close",async u=>{try{await i();}catch{}a({exitCode:u??1,junitPath:t,testOutputDir:r,debugOutputDir:n,stdout:Buffer.concat(l).toString("utf-8"),stderr:Buffer.concat(c).toString("utf-8"),networkJsonlDir:o});}),d.on("error",async u=>{try{await i();}catch{}a({exitCode:127,junitPath:t,testOutputDir:r,debugOutputDir:n,stdout:"",stderr:`Failed to start maestro CLI: ${u.message}`,networkJsonlDir:o});});})}async function Lo(e,t={}){let r=e.outputDir?path.resolve(e.outputDir):Fo();fs.mkdirSync(path.join(r,"artifacts"),{recursive:true}),fs.mkdirSync(path.join(r,"debug"),{recursive:true});let n=er(e,r),o=path.join(r,"report.xml"),s=path.join(r,"artifacts"),i=path.join(r,"debug"),a=null,l=null,c=t.network;if(c?.enabled){let p=path.join(r,"network");a=await Wt({config:c,outputDir:p,verbose:!e.quiet}),a&&(l=await Qt({platform:Po(e.platform),deviceId:e.device,proxyHost:a.host,proxyPort:a.port,skipCertInstall:c.skipCertInstall,quiet:e.quiet}));}let d=a?.outputDir??null,u=async()=>{if(a&&await new Promise(p=>setTimeout(p,500)),l)try{await l.teardown();}catch{}if(a)try{await a.stop();}catch{}};return _o(n,o,s,i,d,e.quiet,u)}var nr="[REDACTED]";function tr(e,t){if(!e)return null;let r=new Set(t.map(o=>o.toLowerCase())),n={};for(let[o,s]of Object.entries(e))n[o]=r.has(o.toLowerCase())?nr:s;return n}function Ge(e,t){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>Ge(n,t));let r={};for(let[n,o]of Object.entries(e))r[n]=t.has(n)?nr:Ge(o,t);return r}function rr(e,t){if(!e||t.length===0)return e;try{let r=JSON.parse(e),n=Ge(r,new Set(t));return JSON.stringify(n)}catch{return e}}function Ve(e,t,r){return {...e,requestHeaders:tr(e.requestHeaders,t),responseHeaders:tr(e.responseHeaders,t),requestBody:rr(e.requestBody,r),responseBody:e.isBinary?e.responseBody:rr(e.responseBody,r)}}function Je(e,t,r){let n=o=>typeof o=="string"?e.includes(o):o.test(e);return r.some(n)?false:t.length===0?true:t.some(n)}function Oo(e){let t=e.trim();if(!t)return null;try{let r=JSON.parse(t);return typeof r.url!="string"||typeof r.method!="string"?null:{id:r.id??`api-call-${Date.now()}`,timestamp:r.timestamp??new Date().toISOString(),method:r.method,url:r.url,requestHeaders:r.requestHeaders??null,requestBody:r.requestBody??null,responseStatusCode:r.responseStatusCode??null,responseStatusText:r.responseStatusText??null,responseHeaders:r.responseHeaders??null,responseBody:r.responseBody??null,responseTimeMs:typeof r.responseTimeMs=="number"?r.responseTimeMs:0,isBinary:r.isBinary??!1,error:r.error??null}}catch{return null}}function Uo(e,t){let r=[];for(let n of e.split(/\r?\n/)){let o=Oo(n);o&&Je(o.url,t.includeUrls,t.excludeUrls)&&r.push(Ve(o,t.redactHeaders,t.redactBodyFields));}return r}function Ho(e,t){try{return Uo(fs.readFileSync(e,"utf-8"),t)}catch{return []}}function $o(e){if(!fs.existsSync(e))return [];try{return fs.readdirSync(e,{recursive:!0}).map(String).filter(t=>t.endsWith(".jsonl")).map(t=>path.join(e,t))}catch{return []}}function or(e){if(!e||e.length===0)return null;let t={};for(let r of e)typeof r.name=="string"&&typeof r.value=="string"&&(t[r.name]=r.value);return Object.keys(t).length>0?t:null}function Bo(e){return e?typeof e.text=="string"?e.text:Array.isArray(e.params)?e.params.map(t=>`${encodeURIComponent(t.name)}=${encodeURIComponent(t.value??"")}`).join("&"):null:null}function jo(e){return e?/^(image|audio|video|application\/(octet-stream|pdf|zip|protobuf))/.test(e):false}function zo(e,t){let r=e.request,n=e.response;if(!r?.method||!r.url)return null;let o=n?.content,s=jo(o?.mimeType);return {id:`har-call-${t}`,timestamp:e.startedDateTime??new Date().toISOString(),method:r.method,url:r.url,requestHeaders:or(r.headers),requestBody:Bo(r.postData),responseStatusCode:typeof n?.status=="number"&&n.status>0?n.status:null,responseStatusText:n?.statusText??null,responseHeaders:or(n?.headers),responseBody:o?.text??null,responseTimeMs:typeof e.time=="number"?e.time:0,isBinary:s,error:null}}function qo(e,t){let r;try{r=JSON.parse(e);}catch{return []}let n=r.log?.entries??[],o=[];return n.forEach((s,i)=>{let a=zo(s,i);a&&Je(a.url,t.includeUrls,t.excludeUrls)&&o.push(Ve(a,t.redactHeaders,t.redactBodyFields));}),o}function Go(e,t){try{return qo(fs.readFileSync(e,"utf-8"),t)}catch{return []}}function Vo(e,t){let r=new Map;for(let o of t)r.set(o.testId,[]);if(e.length===0||t.length===0)return r;let n=t.map(o=>({testId:o.testId,startMs:Date.parse(o.startedAt),endMs:Date.parse(o.completedAt)}));for(let o of e){let s=Date.parse(o.timestamp);if(!Number.isFinite(s))continue;let i=n.find(l=>Number.isFinite(l.startMs)&&Number.isFinite(l.endMs)&&s>=l.startMs&&s<=l.endMs);if(i){r.get(i.testId).push(o);continue}let a=null;for(let l of n){if(!Number.isFinite(l.startMs)||!Number.isFinite(l.endMs))continue;let c=s<l.startMs?l.startMs-s:s-l.endMs;(!a||c<a.dist)&&(a={testId:l.testId,dist:c});}a&&r.get(a.testId).push(o);}return r}function ar(e,t,r){if(!t.enabled&&!t.harPath)return new Map;let n=[];if(e)for(let o of $o(e))n.push(...Ho(o,t));return t.harPath&&fs.existsSync(t.harPath)&&n.push(...Go(t.harPath,t)),n.length===0?new Map:Vo(n,r)}function lr(e){return e.map((t,r)=>({...t,id:`api-call-${r}`}))}var Ko=new Set(["localhost","127.0.0.1","0.0.0.0"]);function We(e){let t=new URL(e);if(t.protocol!=="https:"&&!(t.protocol==="http:"&&Ko.has(t.hostname)))throw core.createError(core.ErrorCode.CLOUD_CONFIG_INVALID,`HTTPS is required for cloud communication. Got: ${t.protocol}//${t.hostname}`)}var Xo=3e3;async function ee(e){let t=new AbortController,r=setTimeout(()=>t.abort(),Xo);try{return (await fetch(`${e}/health`,{method:"GET",signal:t.signal})).ok}catch{return false}finally{clearTimeout(r);}}async function dr(e){return new Promise(t=>setTimeout(t,e))}async function cr(e){try{let r=(await e.json()).error;if(r&&typeof r.message=="string")return r.message}catch{}return `HTTP ${e.status}`}async function te(e,t,r){let n=new AbortController,o=setTimeout(()=>n.abort(),r);try{let s=await fetch(`${e}/sdk/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:t}),signal:n.signal});if(s.ok){let a=await s.json();return {accessToken:a.accessToken,refreshToken:a.refreshToken,expiresIn:a.expiresIn,orgId:a.orgId,orgName:a.orgName,userId:a.userId,userName:a.userName}}if(s.status===429){let a=s.headers.get("Retry-After"),l=a?parseInt(a,10)*1e3:5e3;if(!isNaN(l)&&l>0){await dr(l);let c=await fetch(`${e}/sdk/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:t}),signal:n.signal});if(c.ok){let d=await c.json();return {accessToken:d.accessToken,refreshToken:d.refreshToken,expiresIn:d.expiresIn,orgId:d.orgId,orgName:d.orgName,userId:d.userId,userName:d.userName}}}return {code:"rate_limited",message:"Rate limited during token exchange.",statusCode:429}}return s.status===400?{code:"validation_error",message:await cr(s),statusCode:400}:s.status===401?{code:"invalid_key",message:"API key is invalid or has been revoked.",statusCode:401}:s.status===403?{code:"expired_key",message:"API key has expired.",statusCode:403}:{code:"server_error",message:await cr(s),statusCode:s.status}}catch(s){return s instanceof DOMException&&s.name==="AbortError"?{code:"timeout",message:"Token exchange timed out.",statusCode:null}:{code:"network_error",message:"Failed to reach cloud for token exchange.",statusCode:null}}finally{clearTimeout(o);}}function re(e){return "code"in e&&typeof e.code=="string"&&["invalid_key","expired_key","validation_error","rate_limited","server_error","network_error","timeout"].includes(e.code)}async function Ke(e,t,r){let n=new AbortController,o=setTimeout(()=>n.abort(),r);try{let s=await fetch(`${e}/sdk/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t}),signal:n.signal});if(s.status===429){let a=s.headers.get("Retry-After"),l=a?parseInt(a,10)*1e3:5e3;!isNaN(l)&&l>0&&(await dr(l),s=await fetch(`${e}/sdk/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t}),signal:n.signal}));}if(!s.ok)return null;let i=await s.json();return {accessToken:i.accessToken,refreshToken:i.refreshToken,expiresIn:i.expiresIn}}catch{return null}finally{clearTimeout(o);}}async function Xe(e,t,r,n,o,s){let i=new AbortController,a=setTimeout(()=>i.abort(),o);try{let l={gitId:r,displayName:n};s&&(l.branch=s);let c=await fetch(`${e}/repos/resolve`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(l),signal:i.signal});if(!c.ok)return null;let d=await c.json();return {repoId:d.repoId,displayName:d.displayName}}catch{return null}finally{clearTimeout(a);}}var ts=5e3;function H(e,t){try{return child_process.execSync(e,{cwd:t,timeout:ts,encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim()||null}catch{return null}}function Ye(e){let t=H("git rev-parse --abbrev-ref HEAD",e),r=H("git rev-parse --short HEAD",e),n=H("git log -1 --pretty=%s",e),o=H("git log -1 --format=%an",e)??H("git config user.name",e),s=rs(e),i=s?j(s):null;return {branch:t,commitSha:r,commitMessage:n,commitAuthor:o,remoteUrl:i}}function rs(e){let t=H("git remote get-url origin",e);if(t)return t;let r=H("git remote",e);if(!r)return null;let n=r.split(`
1255
+ `)[0]?.trim();return n?H(`git remote get-url ${n}`,e):null}function j(e){let t=e.trim();return t=t.replace(/^[a-z+]+:\/\//,""),t=t.replace(/^[^@]+@/,""),t=t.replace(/:(?!\d)/,"/"),t=t.replace(/\.git$/,""),t=t.replace(/\/+$/,""),t=t.replace(/^[^@/]+@/,""),t.toLowerCase()}function Qe(e){let t=e.split("/").filter(Boolean);return t[t.length-1]??e}function ur(e){try{let t=fs.readFileSync(path.join(e,"package.json"),"utf-8"),r=JSON.parse(t);return typeof r.name=="string"&&r.name.length>0?r.name:null}catch{return null}}function z(e){let t=ur(e);return t||`local/${path.basename(e)}`}var ls="1.0.0",pr=10;function oe(e,t,r,n,o,s,i,a){try{fs.mkdirSync(e,{recursive:!0});let l=Date.now(),c=`${l}-${t}-${r}.json`,d=path.join(e,c),u={version:ls,queuedAt:new Date(l).toISOString(),reason:n,retryCount:0,targetEndpoint:o,method:s,payload:i,headers:a},p=d+".tmp";fs.writeFileSync(p,JSON.stringify(u,null,2),"utf-8"),fs.renameSync(p,d);}catch(l){l.code==="ENOSPC"?process.stderr.write(`\u26A0 TestRelic: Disk full \u2014 unable to queue upload data.
1256
1256
  `):process.stderr.write(`\u26A0 TestRelic: Unable to queue upload data.
1257
- `);}}async function Ze(e,t,r){let n;try{n=fs.readdirSync(e).filter(s=>s.endsWith(".json")&&!s.endsWith(".tmp")).sort();}catch{return}if(n.length===0)return;let o=[];for(let s=0;s<n.length;s+=ar)o.push(n.slice(s,s+ar));for(let s of o)for(let i of s){let a=path.join(e,i);try{if(!fs.statSync(a).isFile())continue;let c=fs.readFileSync(a,"utf-8"),d=JSON.parse(c);if(!core.isValidQueueEntry(d)){fs.unlinkSync(a);continue}let u=d;if((await fetch(u.targetEndpoint,{method:u.method,headers:{...u.headers,Authorization:`Bearer ${r}`},body:JSON.stringify(u.payload)})).ok)fs.unlinkSync(a);else return}catch{return}}}function et(e,t){try{let r=fs.readdirSync(e).filter(o=>o.endsWith(".json")&&!o.endsWith(".tmp")),n=Date.now();for(let o of r){let s=path.join(e,o);try{let i=fs.readFileSync(s,"utf-8"),l=JSON.parse(i).queuedAt;if(typeof l=="string"){let c=new Date(l).getTime();n-c>t&&fs.unlinkSync(s);}}catch{try{fs.unlinkSync(s);}catch{}}}}catch{}}var ds=3e5,us=864e5,ps=6e4,dr=3e4,ur="https://platform.testrelic.ai/settings/api-keys",W=class{constructor(t){this.gitMetadata=null;this.repoId=null;this.failureReason=null;this.flushPromise=null;this.healthCheckTimer=null;this.config=t,this.authState={mode:"pending",accessToken:null,refreshToken:null,expiresAt:null,orgId:null,orgName:null,userId:null,userName:null};}async initialize(){if(!this.config||!this.config.apiKey){this.setLocalMode("no_api_key"),process.stderr.write(`\u2139 TestRelic: No API key configured. Running in local mode.
1258
- `);return}try{if(Je(this.config.endpoint),this.gitMetadata=Xe(),!await ee(this.config.endpoint)){this.setLocalMode("cloud_unreachable"),process.stderr.write(`\u26A0 TestRelic: Cloud unreachable. Switching to local mode.
1257
+ `);}}async function et(e,t,r){let n;try{n=fs.readdirSync(e).filter(s=>s.endsWith(".json")&&!s.endsWith(".tmp")).sort();}catch{return}if(n.length===0)return;let o=[];for(let s=0;s<n.length;s+=pr)o.push(n.slice(s,s+pr));for(let s of o)for(let i of s){let a=path.join(e,i);try{if(!fs.statSync(a).isFile())continue;let c=fs.readFileSync(a,"utf-8"),d=JSON.parse(c);if(!core.isValidQueueEntry(d)){fs.unlinkSync(a);continue}let u=d;if((await fetch(u.targetEndpoint,{method:u.method,headers:{...u.headers,Authorization:`Bearer ${r}`},body:JSON.stringify(u.payload)})).ok)fs.unlinkSync(a);else return}catch{return}}}function tt(e,t){try{let r=fs.readdirSync(e).filter(o=>o.endsWith(".json")&&!o.endsWith(".tmp")),n=Date.now();for(let o of r){let s=path.join(e,o);try{let i=fs.readFileSync(s,"utf-8"),l=JSON.parse(i).queuedAt;if(typeof l=="string"){let c=new Date(l).getTime();n-c>t&&fs.unlinkSync(s);}}catch{try{fs.unlinkSync(s);}catch{}}}}catch{}}var ms=3e5,hs=864e5,bs=6e4,mr=3e4,hr="https://platform.testrelic.ai/settings/api-keys",J=class{constructor(t){this.gitMetadata=null;this.repoId=null;this.failureReason=null;this.flushPromise=null;this.healthCheckTimer=null;this.config=t,this.authState={mode:"pending",accessToken:null,refreshToken:null,expiresAt:null,orgId:null,orgName:null,userId:null,userName:null};}async initialize(){if(!this.config||!this.config.apiKey){this.setLocalMode("no_api_key"),process.stderr.write(`\u2139 TestRelic: No API key configured. Running in local mode.
1258
+ `);return}try{if(We(this.config.endpoint),this.gitMetadata=Ye(),!await ee(this.config.endpoint)){this.setLocalMode("cloud_unreachable"),process.stderr.write(`\u26A0 TestRelic: Cloud unreachable. Switching to local mode.
1259
1259
  `);return}let r=await te(this.config.endpoint,this.config.apiKey,this.config.timeout);if(re(r)){this.handleAuthError(r.code,r.statusCode);return}let n=r;this.authState={mode:"cloud",accessToken:n.accessToken,refreshToken:n.refreshToken,expiresAt:Date.now()+n.expiresIn*1e3,orgId:n.orgId,orgName:n.orgName,userId:n.userId,userName:n.userName},process.stderr.write(`\u2713 TestRelic: Connected to cloud (${n.orgName} / ${n.userName})
1260
- `),await this.resolveRepoId(),this.config.queueDirectory&&(et(this.config.queueDirectory,this.config.queueMaxAge),this.startBackgroundFlush()),this.startHealthCheck();}catch(t){this.setLocalMode("unexpected_error"),process.stderr.write(`\u26A0 TestRelic: Unexpected error during cloud initialization. ${t instanceof Error?t.message:String(t)}
1261
- `);}}getMode(){return this.authState.mode}isCloudMode(){return this.authState.mode==="cloud"}isLocalMode(){return this.authState.mode==="local"}getAccessToken(){return this.authState.accessToken}getRepoId(){return this.repoId}getGitMetadata(){return this.gitMetadata}getConfig(){return this.config}getFailureReason(){return this.failureReason}getEndpoint(){return this.config?.endpoint??"https://platform.testrelic.ai/api/v1"}async ensureValidToken(){if(!this.isCloudMode()||!this.authState.accessToken)return false;let t=this.authState.expiresAt??0;if(Date.now()+ds<t)return true;if(!this.config||!this.authState.refreshToken)return this.switchToLocalMode("token_expired_no_refresh"),false;try{let r=await We(this.config.endpoint,this.authState.refreshToken,this.config.timeout);return r?(this.authState.accessToken=r.accessToken,this.authState.refreshToken=r.refreshToken,this.authState.expiresAt=Date.now()+r.expiresIn*1e3,!0):(this.switchToLocalMode("token_refresh_failed"),!1)}catch{return this.switchToLocalMode("token_refresh_error"),false}}switchToLocalMode(t){this.authState.mode!=="local"&&(this.authState.mode="local",this.failureReason=t,process.stderr.write(`\u26A0 TestRelic: Switched to local mode (${t}).
1262
- `));}async dispose(){if(this.healthCheckTimer&&(clearInterval(this.healthCheckTimer),this.healthCheckTimer=null),this.flushPromise){try{await Promise.race([this.flushPromise,new Promise(t=>setTimeout(t,dr))]);}catch{}this.flushPromise=null;}this.authState={mode:"local",accessToken:null,refreshToken:null,expiresAt:null,orgId:null,orgName:null,userId:null,userName:null},this.repoId=null,this.gitMetadata=null;}setLocalMode(t){this.authState.mode="local",this.failureReason=t;}handleAuthError(t,r){switch(t){case "invalid_key":this.setLocalMode("invalid_api_key"),process.stderr.write(`\u26A0 TestRelic: API key is invalid or revoked. Running in local mode.
1263
- \u2192 Manage keys: ${ur}
1260
+ `),await this.resolveRepoId(),this.config.queueDirectory&&(tt(this.config.queueDirectory,this.config.queueMaxAge),this.startBackgroundFlush()),this.startHealthCheck();}catch(t){this.setLocalMode("unexpected_error"),process.stderr.write(`\u26A0 TestRelic: Unexpected error during cloud initialization. ${t instanceof Error?t.message:String(t)}
1261
+ `);}}getMode(){return this.authState.mode}isCloudMode(){return this.authState.mode==="cloud"}isLocalMode(){return this.authState.mode==="local"}getAccessToken(){return this.authState.accessToken}getRepoId(){return this.repoId}getGitMetadata(){return this.gitMetadata}getConfig(){return this.config}getFailureReason(){return this.failureReason}getEndpoint(){return this.config?.endpoint??"https://platform.testrelic.ai/api/v1"}async ensureValidToken(){if(!this.isCloudMode()||!this.authState.accessToken)return false;let t=this.authState.expiresAt??0;if(Date.now()+ms<t)return true;if(!this.config||!this.authState.refreshToken)return this.switchToLocalMode("token_expired_no_refresh"),false;try{let r=await Ke(this.config.endpoint,this.authState.refreshToken,this.config.timeout);return r?(this.authState.accessToken=r.accessToken,this.authState.refreshToken=r.refreshToken,this.authState.expiresAt=Date.now()+r.expiresIn*1e3,!0):(this.switchToLocalMode("token_refresh_failed"),!1)}catch{return this.switchToLocalMode("token_refresh_error"),false}}switchToLocalMode(t){this.authState.mode!=="local"&&(this.authState.mode="local",this.failureReason=t,process.stderr.write(`\u26A0 TestRelic: Switched to local mode (${t}).
1262
+ `));}async dispose(){if(this.healthCheckTimer&&(clearInterval(this.healthCheckTimer),this.healthCheckTimer=null),this.flushPromise){try{await Promise.race([this.flushPromise,new Promise(t=>setTimeout(t,mr))]);}catch{}this.flushPromise=null;}this.authState={mode:"local",accessToken:null,refreshToken:null,expiresAt:null,orgId:null,orgName:null,userId:null,userName:null},this.repoId=null,this.gitMetadata=null;}setLocalMode(t){this.authState.mode="local",this.failureReason=t;}handleAuthError(t,r){switch(t){case "invalid_key":this.setLocalMode("invalid_api_key"),process.stderr.write(`\u26A0 TestRelic: API key is invalid or revoked. Running in local mode.
1263
+ \u2192 Manage keys: ${hr}
1264
1264
  `);break;case "expired_key":this.setLocalMode("expired_api_key"),process.stderr.write(`\u26A0 TestRelic: API key has expired. Running in local mode.
1265
- \u2192 Generate a new key: ${ur}
1265
+ \u2192 Generate a new key: ${hr}
1266
1266
  `);break;case "rate_limited":this.setLocalMode("rate_limited"),process.stderr.write(`\u26A0 TestRelic: Rate limited during authentication. Running in local mode.
1267
1267
  `);break;default:this.setLocalMode(`auth_error_${r??"unknown"}`),process.stderr.write(`\u26A0 TestRelic: Cloud authentication failed. Running in local mode.
1268
- `);break}}async resolveRepoId(){if(!this.config||!this.authState.accessToken)return;let t=this.gitMetadata?.remoteUrl?j(this.gitMetadata.remoteUrl):null,r=t?Ye(t):this.config.projectName??z(process.cwd()),n=t??this.config.projectName??z(process.cwd()),o=this.readRepoCache(n);if(o){this.repoId=o.repoId;return}try{let s=await Ke(this.config.endpoint,this.authState.accessToken,n,r,this.config.timeout,this.gitMetadata?.branch);s&&(this.repoId=s.repoId,this.writeRepoCache(n,s.repoId,s.displayName));}catch{}}readRepoCache(t){if(!this.config)return null;let r=path.join(this.config.queueDirectory,"..","cache","repo.json");try{if(!fs.existsSync(r))return null;let n=fs.readFileSync(r,"utf-8"),o=JSON.parse(n);if(o.gitId!==t||Date.now()-o.resolvedAt>us)return null;let s=this.hashApiKey();return s&&o.apiKeyHash!==s?null:o}catch{return null}}writeRepoCache(t,r,n){if(!this.config)return;let o=path.join(this.config.queueDirectory,"..","cache"),s=path.join(o,"repo.json");try{fs.mkdirSync(o,{recursive:!0});let i={repoId:r,gitId:t,displayName:n,resolvedAt:Date.now(),apiKeyHash:this.hashApiKey()??""},a=s+".tmp";fs.writeFileSync(a,JSON.stringify(i,null,2),"utf-8"),fs.renameSync(a,s);}catch{}}hashApiKey(){return this.config?.apiKey?crypto.createHash("sha256").update(this.config.apiKey).digest("hex").substring(0,16):null}startBackgroundFlush(){if(!this.config||!this.authState.accessToken)return;let t=this.authState.accessToken,r=this.config.queueDirectory,n=this.config.endpoint;this.flushPromise=Promise.race([Ze(r,n,t),new Promise(o=>setTimeout(o,dr))]).catch(()=>{});}startHealthCheck(){if(!this.config)return;let t=this.config.endpoint;this.healthCheckTimer=setInterval(async()=>{if(!this.isCloudMode()&&!(!this.failureReason||!["cloud_unreachable","auth_timeout","network_error"].includes(this.failureReason)))try{if(!await ee(t))return;if(this.config?.apiKey){let n=await te(this.config.endpoint,this.config.apiKey,this.config.timeout);if(!re(n)){let o=n;this.authState={mode:"cloud",accessToken:o.accessToken,refreshToken:o.refreshToken,expiresAt:Date.now()+o.expiresIn*1e3,orgId:o.orgId,orgName:o.orgName,userId:o.userId,userName:o.userName},this.failureReason=null,process.stderr.write(`\u2713 TestRelic: Cloud connectivity restored.
1269
- `),this.startBackgroundFlush();}}}catch{}},ps);}};var gs=1048576,se=[1e3,3e3,9e3],ie=3;function le(e,t,r,n,o){let s=n?.provider&&n.provider!=="unknown"?n.provider:"local";return {runId:e.testRunId,repoGitId:t,startedAt:e.startedAt,summary:e.summary,timeline:e.timeline,environment:s,testFramework:"maestro",...o&&o.length>0?{tests:o}:{},...r?.branch?{branch:r.branch}:{},...r?.commitSha?{commit:r.commitSha}:{},...r?.commitMessage?{commitMessage:r.commitMessage}:{},...r?.commitAuthor?{commitAuthor:r.commitAuthor}:{},...e.completedAt?{finishedAt:e.completedAt}:{},...e.totalDuration?{duration:e.totalDuration}:{},...n?.provider?{ciProvider:n.provider}:{},...n?.runUrl?{ciRunUrl:n.runUrl}:{}}}async function ae(e){return new Promise(t=>setTimeout(t,e))}async function pr(e,t,r){for(let n=0;n<ie;n++)try{let o=await fetch(e,t);if(o.ok)return o;if(o.status===401&&r&&n===0){let s=await r();if(s){let i={...t,headers:{...t.headers,Authorization:`Bearer ${s}`}},a=await fetch(e,i);if(a.ok)return a}return null}if(o.status===429&&n<ie-1){let s=o.headers.get("Retry-After"),i=s?parseInt(s,10)*1e3:se[n];!isNaN(i)&&i>0?await ae(i):await ae(se[n]);continue}if(o.status>=500&&n<ie-1){await ae(se[n]);continue}return o}catch{if(n<ie-1){await ae(se[n]);continue}return null}return null}function ms(e){let t=JSON.stringify(e),r={"Content-Type":"application/json"};if(Buffer.byteLength(t,"utf-8")>gs){let n=zlib.gzipSync(Buffer.from(t,"utf-8"));return r["Content-Encoding"]="gzip",{body:n,headers:r}}return {body:t,headers:r}}async function rt(e,t,r,n){let o=`${e}/runs`,{body:s,headers:i}=ms(r);i.Authorization=`Bearer ${t}`;let a=await pr(o,{method:"POST",headers:i,body:s},n);return a?.ok?{success:true,statusCode:a.status,error:null}:a?.status===409?{success:true,statusCode:409,error:null}:{success:false,reason:a?`Upload failed with status ${a.status}`:"Upload failed after retries",statusCode:a?.status??null,payload:r,targetEndpoint:o,method:"POST"}}function hs(e){let t={};for(let[r,n]of Object.entries(e))n!=null&&(t[r]=n);return t}async function bs(e,t,r){let n=`${e}/runs/init`;try{let o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(hs(r))});return o.ok?{runId:(await o.json()).runId}:null}catch{return null}}async function ys(e,t,r,n){let o=`${e}/runs/${r}/finalize`;return (await pr(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(n)}))?.ok??false}var Cs=5,ce=[1e3,3e3,9e3],q=3,Rs={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".webm":"video/webm",".mp4":"video/mp4",".mov":"video/quicktime",".zip":"application/zip"},nt=0,ot=[];async function As(){nt>=Cs&&await new Promise(e=>ot.push(e)),nt++;}function Ss(){nt--,ot.length>0&&ot.shift()();}async function de(e){return new Promise(t=>setTimeout(t,e))}function Ts(e){let t=e.substring(e.lastIndexOf(".")).toLowerCase();return Rs[t]??"application/octet-stream"}function Is(e){try{return fs.statSync(e).size}catch{return 0}}async function Ms(e,t,r,n,o){let s=`${e}/artifacts/upload-url`,i=JSON.stringify({runId:r.runId,testId:r.testId,fileName:path.basename(r.filePath),contentType:o,type:r.type,sizeBytes:n});for(let a=0;a<q;a++)try{let l=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:i});if(l.ok)return await l.json();if(l.status>=500&&a<q-1){await de(ce[a]);continue}return null}catch{if(a<q-1){await de(ce[a]);continue}return null}return null}async function Es(e,t,r,n){for(let o=0;o<q;o++)try{let s=fs.createReadStream(t),i=stream.Readable.toWeb(s),a=await fetch(e,{method:"PUT",headers:{"Content-Type":r,"Content-Length":String(n)},body:i,duplex:"half"});if(a.ok)return !0;if(a.status>=500&&o<q-1){await de(ce[o]);continue}return !1}catch{if(o<q-1){await de(ce[o]);continue}return false}return false}async function Fs(e,t,r){try{return (await fetch(`${e}/artifacts/confirm`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({artifactId:r})})).ok}catch{return false}}async function fr(e,t,r,n){let o=Is(r.filePath);if(o===0)return {success:false,storageKey:null,artifactId:null,error:"file_not_found_or_empty"};if(o>n*1024*1024)return {success:false,storageKey:null,artifactId:null,error:"file_too_large"};let s=Ts(r.filePath);await As();try{let i=await Ms(e,t,r,o,s);if(!i)return {success:!1,storageKey:null,artifactId:null,error:"upload_url_request_failed"};if(!await Es(i.uploadUrl,r.filePath,s,o))return {success:!1,storageKey:i.storageKey,artifactId:i.artifactId,error:"presigned_put_failed"};let l=await Fs(e,t,i.artifactId);return {success:l,storageKey:i.storageKey,artifactId:i.artifactId,error:l?null:"confirm_failed"}}finally{Ss();}}async function st(e,t,r,n){let o=new Map,s=r.map(async i=>{let a=await fr(e,t,i,n);o.set(i.filePath,a);});return await Promise.allSettled(s),o}function Ps(e){return e.GITHUB_ACTIONS!=="true"?null:{provider:"github-actions",buildId:e.GITHUB_RUN_ID??null,commitSha:e.GITHUB_SHA??null,branch:e.GITHUB_REF_NAME??null,runUrl:e.GITHUB_SERVER_URL&&e.GITHUB_REPOSITORY&&e.GITHUB_RUN_ID?`${e.GITHUB_SERVER_URL}/${e.GITHUB_REPOSITORY}/actions/runs/${e.GITHUB_RUN_ID}`:null}}function _s(e){return e.GITLAB_CI!=="true"?null:{provider:"gitlab-ci",buildId:e.CI_PIPELINE_ID??null,commitSha:e.CI_COMMIT_SHA??null,branch:e.CI_COMMIT_BRANCH??e.CI_COMMIT_REF_NAME??null,runUrl:e.CI_PIPELINE_URL??null}}function Ls(e){if(!e.JENKINS_URL)return null;let t=e.GIT_BRANCH??null;return t?.startsWith("origin/")&&(t=t.slice(7)),{provider:"jenkins",buildId:e.BUILD_ID??null,commitSha:e.GIT_COMMIT??null,branch:t,runUrl:e.BUILD_URL??null}}function Ds(e){return e.CIRCLECI!=="true"?null:{provider:"circleci",buildId:e.CIRCLE_BUILD_NUM??null,commitSha:e.CIRCLE_SHA1??null,branch:e.CIRCLE_BRANCH??null,runUrl:e.CIRCLE_BUILD_URL??null}}function Ns(e){if(!e.BITBUCKET_PIPELINE_UUID)return null;let t=e.BITBUCKET_WORKSPACE&&e.BITBUCKET_REPO_SLUG&&e.BITBUCKET_PIPELINE_UUID?`https://bitbucket.org/${e.BITBUCKET_WORKSPACE}/${e.BITBUCKET_REPO_SLUG}/pipelines/results/${e.BITBUCKET_PIPELINE_UUID}`:null;return {provider:"bitbucket-pipelines",buildId:e.BITBUCKET_BUILD_NUMBER??null,commitSha:e.BITBUCKET_COMMIT??null,branch:e.BITBUCKET_BRANCH??null,runUrl:t}}var Os=[Ps,_s,Ls,Ds,Ns];function ue(e){let t=e??process.env;for(let r of Os){let n=r(t);if(n)return n}return null}function Us(e){let t=[];for(let r of e){let n=r,o=n.tests;if(!Array.isArray(o)||o.length===0){t.push(r);continue}for(let s of o){t.push({timestamp:s.startedAt,title:s.title,category:"test",navigationType:n.navigationType,url:n.url,visitedAt:n.visitedAt,duration:s.duration,status:s.status,test_status:s.status,test_id:s.testId,test_title:s.title,specfile:s.filePath,suiteName:s.suiteName,type:"test",...s.failure?{error:s.failure.message,errorMessage:s.failure.message}:{}});for(let i of s.actions??[])t.push({timestamp:i.timestamp,title:i.title,category:i.category,status:i.status,test_status:s.status,duration:i.duration,error:i.error,test_id:s.testId,test_title:s.title,specfile:s.filePath,url:n.url,type:i.category==="assertion"?"assert":"action"});}}return t}function gr(e){let r=e.getGitMetadata()?.remoteUrl;return r?j(r):e.getConfig()?.projectName??z(process.cwd())}async function it(e,t,r,n,o,s,i,a,l,c,d){try{let u=d?.length??0,p=(a?.length??0)+(l?.length??0)+u>0;if(e.isCloudMode()&&p&&await e.ensureValidToken()){let b=e.getEndpoint(),g=e.getAccessToken(),h=t?.artifactMaxSizeMb??50,y=[];for(let C of a??[])y.push({filePath:C,runId:r,testId:"maestro-suite",type:"screenshot"});let T=new Set;for(let C of d??[])y.push({filePath:C.path,runId:r,testId:C.testId,type:"video"}),T.add(C.path);for(let C of l??[])T.has(C)||y.push({filePath:C,runId:r,testId:"maestro-suite",type:"video"});if(y.length>0){let C=await st(b,g,y,h),_=Array.from(C.entries()),I=_.filter(([,m])=>m.success).length,f=_.filter(([,m])=>!m.success);if(I>0){let m=y.filter(v=>v.type==="video").length,w=d?.length??0,R=y.filter(v=>v.type==="screenshot").length,A=[];if(R>0&&A.push(`${R} screenshot(s)`),m>0){let v=w>0?` (${w} per-flow)`:"";A.push(`${m} video(s)${v}`);}process.stderr.write(`\u2713 TestRelic: Uploaded ${I} artifact(s) [${A.join(", ")}] to cloud storage.
1268
+ `);break}}async resolveRepoId(){if(!this.config||!this.authState.accessToken)return;let t=this.gitMetadata?.remoteUrl?j(this.gitMetadata.remoteUrl):null,r=t?Qe(t):this.config.projectName??z(process.cwd()),n=t??this.config.projectName??z(process.cwd()),o=this.readRepoCache(n);if(o){this.repoId=o.repoId;return}try{let s=await Xe(this.config.endpoint,this.authState.accessToken,n,r,this.config.timeout,this.gitMetadata?.branch);s&&(this.repoId=s.repoId,this.writeRepoCache(n,s.repoId,s.displayName));}catch{}}readRepoCache(t){if(!this.config)return null;let r=path.join(this.config.queueDirectory,"..","cache","repo.json");try{if(!fs.existsSync(r))return null;let n=fs.readFileSync(r,"utf-8"),o=JSON.parse(n);if(o.gitId!==t||Date.now()-o.resolvedAt>hs)return null;let s=this.hashApiKey();return s&&o.apiKeyHash!==s?null:o}catch{return null}}writeRepoCache(t,r,n){if(!this.config)return;let o=path.join(this.config.queueDirectory,"..","cache"),s=path.join(o,"repo.json");try{fs.mkdirSync(o,{recursive:!0});let i={repoId:r,gitId:t,displayName:n,resolvedAt:Date.now(),apiKeyHash:this.hashApiKey()??""},a=s+".tmp";fs.writeFileSync(a,JSON.stringify(i,null,2),"utf-8"),fs.renameSync(a,s);}catch{}}hashApiKey(){return this.config?.apiKey?crypto.createHash("sha256").update(this.config.apiKey).digest("hex").substring(0,16):null}startBackgroundFlush(){if(!this.config||!this.authState.accessToken)return;let t=this.authState.accessToken,r=this.config.queueDirectory,n=this.config.endpoint;this.flushPromise=Promise.race([et(r,n,t),new Promise(o=>setTimeout(o,mr))]).catch(()=>{});}startHealthCheck(){if(!this.config)return;let t=this.config.endpoint;this.healthCheckTimer=setInterval(async()=>{if(!this.isCloudMode()&&!(!this.failureReason||!["cloud_unreachable","auth_timeout","network_error"].includes(this.failureReason)))try{if(!await ee(t))return;if(this.config?.apiKey){let n=await te(this.config.endpoint,this.config.apiKey,this.config.timeout);if(!re(n)){let o=n;this.authState={mode:"cloud",accessToken:o.accessToken,refreshToken:o.refreshToken,expiresAt:Date.now()+o.expiresIn*1e3,orgId:o.orgId,orgName:o.orgName,userId:o.userId,userName:o.userName},this.failureReason=null,process.stderr.write(`\u2713 TestRelic: Cloud connectivity restored.
1269
+ `),this.startBackgroundFlush();}}}catch{}},bs);}};var xs=1048576,se=[1e3,3e3,9e3],ie=3;function le(e,t,r,n,o){let s=n?.provider&&n.provider!=="unknown"?n.provider:"local";return {runId:e.testRunId,repoGitId:t,startedAt:e.startedAt,summary:e.summary,timeline:e.timeline,environment:s,testFramework:"maestro",...o&&o.length>0?{tests:o}:{},...r?.branch?{branch:r.branch}:{},...r?.commitSha?{commit:r.commitSha}:{},...r?.commitMessage?{commitMessage:r.commitMessage}:{},...r?.commitAuthor?{commitAuthor:r.commitAuthor}:{},...e.completedAt?{finishedAt:e.completedAt}:{},...e.totalDuration?{duration:e.totalDuration}:{},...n?.provider?{ciProvider:n.provider}:{},...n?.runUrl?{ciRunUrl:n.runUrl}:{}}}async function ae(e){return new Promise(t=>setTimeout(t,e))}async function br(e,t,r){for(let n=0;n<ie;n++)try{let o=await fetch(e,t);if(o.ok)return o;if(o.status===401&&r&&n===0){let s=await r();if(s){let i={...t,headers:{...t.headers,Authorization:`Bearer ${s}`}},a=await fetch(e,i);if(a.ok)return a}return null}if(o.status===429&&n<ie-1){let s=o.headers.get("Retry-After"),i=s?parseInt(s,10)*1e3:se[n];!isNaN(i)&&i>0?await ae(i):await ae(se[n]);continue}if(o.status>=500&&n<ie-1){await ae(se[n]);continue}return o}catch{if(n<ie-1){await ae(se[n]);continue}return null}return null}function ws(e){let t=JSON.stringify(e),r={"Content-Type":"application/json"};if(Buffer.byteLength(t,"utf-8")>xs){let n=zlib.gzipSync(Buffer.from(t,"utf-8"));return r["Content-Encoding"]="gzip",{body:n,headers:r}}return {body:t,headers:r}}async function nt(e,t,r,n){let o=`${e}/runs`,{body:s,headers:i}=ws(r);i.Authorization=`Bearer ${t}`;let a=await br(o,{method:"POST",headers:i,body:s},n);return a?.ok?{success:true,statusCode:a.status,error:null}:a?.status===409?{success:true,statusCode:409,error:null}:{success:false,reason:a?`Upload failed with status ${a.status}`:"Upload failed after retries",statusCode:a?.status??null,payload:r,targetEndpoint:o,method:"POST"}}function vs(e){let t={};for(let[r,n]of Object.entries(e))n!=null&&(t[r]=n);return t}async function ks(e,t,r){let n=`${e}/runs/init`;try{let o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(vs(r))});return o.ok?{runId:(await o.json()).runId}:null}catch{return null}}async function Cs(e,t,r,n){let o=`${e}/runs/${r}/finalize`;return (await br(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(n)}))?.ok??false}var Is=5,ce=[1e3,3e3,9e3],q=3,Ms={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".webm":"video/webm",".mp4":"video/mp4",".mov":"video/quicktime",".zip":"application/zip"},ot=0,st=[];async function Es(){ot>=Is&&await new Promise(e=>st.push(e)),ot++;}function Fs(){ot--,st.length>0&&st.shift()();}async function de(e){return new Promise(t=>setTimeout(t,e))}function Ps(e){let t=e.substring(e.lastIndexOf(".")).toLowerCase();return Ms[t]??"application/octet-stream"}function _s(e){try{return fs.statSync(e).size}catch{return 0}}async function Ls(e,t,r,n,o){let s=`${e}/artifacts/upload-url`,i=JSON.stringify({runId:r.runId,testId:r.testId,fileName:path.basename(r.filePath),contentType:o,type:r.type,sizeBytes:n});for(let a=0;a<q;a++)try{let l=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:i});if(l.ok)return await l.json();if(l.status>=500&&a<q-1){await de(ce[a]);continue}return null}catch{if(a<q-1){await de(ce[a]);continue}return null}return null}async function Ds(e,t,r,n){for(let o=0;o<q;o++)try{let s=fs.createReadStream(t),i=stream.Readable.toWeb(s),a=await fetch(e,{method:"PUT",headers:{"Content-Type":r,"Content-Length":String(n)},body:i,duplex:"half"});if(a.ok)return !0;if(a.status>=500&&o<q-1){await de(ce[o]);continue}return !1}catch{if(o<q-1){await de(ce[o]);continue}return false}return false}async function Ns(e,t,r){try{return (await fetch(`${e}/artifacts/confirm`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({artifactId:r})})).ok}catch{return false}}async function yr(e,t,r,n){let o=_s(r.filePath);if(o===0)return {success:false,storageKey:null,artifactId:null,error:"file_not_found_or_empty"};if(o>n*1024*1024)return {success:false,storageKey:null,artifactId:null,error:"file_too_large"};let s=Ps(r.filePath);await Es();try{let i=await Ls(e,t,r,o,s);if(!i)return {success:!1,storageKey:null,artifactId:null,error:"upload_url_request_failed"};if(!await Ds(i.uploadUrl,r.filePath,s,o))return {success:!1,storageKey:i.storageKey,artifactId:i.artifactId,error:"presigned_put_failed"};let l=await Ns(e,t,i.artifactId);return {success:l,storageKey:i.storageKey,artifactId:i.artifactId,error:l?null:"confirm_failed"}}finally{Fs();}}async function it(e,t,r,n){let o=new Map,s=r.map(async i=>{let a=await yr(e,t,i,n);o.set(i.filePath,a);});return await Promise.allSettled(s),o}function Os(e){return e.GITHUB_ACTIONS!=="true"?null:{provider:"github-actions",buildId:e.GITHUB_RUN_ID??null,commitSha:e.GITHUB_SHA??null,branch:e.GITHUB_REF_NAME??null,runUrl:e.GITHUB_SERVER_URL&&e.GITHUB_REPOSITORY&&e.GITHUB_RUN_ID?`${e.GITHUB_SERVER_URL}/${e.GITHUB_REPOSITORY}/actions/runs/${e.GITHUB_RUN_ID}`:null}}function Us(e){return e.GITLAB_CI!=="true"?null:{provider:"gitlab-ci",buildId:e.CI_PIPELINE_ID??null,commitSha:e.CI_COMMIT_SHA??null,branch:e.CI_COMMIT_BRANCH??e.CI_COMMIT_REF_NAME??null,runUrl:e.CI_PIPELINE_URL??null}}function Hs(e){if(!e.JENKINS_URL)return null;let t=e.GIT_BRANCH??null;return t?.startsWith("origin/")&&(t=t.slice(7)),{provider:"jenkins",buildId:e.BUILD_ID??null,commitSha:e.GIT_COMMIT??null,branch:t,runUrl:e.BUILD_URL??null}}function $s(e){return e.CIRCLECI!=="true"?null:{provider:"circleci",buildId:e.CIRCLE_BUILD_NUM??null,commitSha:e.CIRCLE_SHA1??null,branch:e.CIRCLE_BRANCH??null,runUrl:e.CIRCLE_BUILD_URL??null}}function Bs(e){if(!e.BITBUCKET_PIPELINE_UUID)return null;let t=e.BITBUCKET_WORKSPACE&&e.BITBUCKET_REPO_SLUG&&e.BITBUCKET_PIPELINE_UUID?`https://bitbucket.org/${e.BITBUCKET_WORKSPACE}/${e.BITBUCKET_REPO_SLUG}/pipelines/results/${e.BITBUCKET_PIPELINE_UUID}`:null;return {provider:"bitbucket-pipelines",buildId:e.BITBUCKET_BUILD_NUMBER??null,commitSha:e.BITBUCKET_COMMIT??null,branch:e.BITBUCKET_BRANCH??null,runUrl:t}}var js=[Os,Us,Hs,$s,Bs];function ue(e){let t=e??process.env;for(let r of js){let n=r(t);if(n)return n}return null}function zs(e){let t=[];for(let r of e){let n=r,o=n.tests;if(!Array.isArray(o)||o.length===0){t.push(r);continue}for(let s of o){t.push({timestamp:s.startedAt,title:s.title,category:"test",navigationType:n.navigationType,url:n.url,visitedAt:n.visitedAt,duration:s.duration,status:s.status,test_status:s.status,test_id:s.testId,test_title:s.title,specfile:s.filePath,suiteName:s.suiteName,type:"test",...s.failure?{error:s.failure.message,errorMessage:s.failure.message}:{}});for(let i of s.actions??[])t.push({timestamp:i.timestamp,title:i.title,category:i.category,status:i.status,test_status:s.status,duration:i.duration,error:i.error,test_id:s.testId,test_title:s.title,specfile:s.filePath,url:n.url,type:i.category==="assertion"?"assert":"action"});}}return t}function xr(e){let r=e.getGitMetadata()?.remoteUrl;return r?j(r):e.getConfig()?.projectName??z(process.cwd())}async function at(e,t,r,n,o,s,i,a,l,c,d){try{let u=d?.length??0,p=(a?.length??0)+(l?.length??0)+u>0;if(e.isCloudMode()&&p&&await e.ensureValidToken()){let y=e.getEndpoint(),g=e.getAccessToken(),h=t?.artifactMaxSizeMb??50,b=[];for(let R of a??[])b.push({filePath:R,runId:r,testId:"maestro-suite",type:"screenshot"});let A=new Set;for(let R of d??[])b.push({filePath:R.path,runId:r,testId:R.testId,type:"video"}),A.add(R.path);for(let R of l??[])A.has(R)||b.push({filePath:R,runId:r,testId:"maestro-suite",type:"video"});if(b.length>0){let R=await it(y,g,b,h),D=Array.from(R.entries()),I=D.filter(([,m])=>m.success).length,f=D.filter(([,m])=>!m.success);if(I>0){let m=b.filter(k=>k.type==="video").length,x=d?.length??0,v=b.filter(k=>k.type==="screenshot").length,S=[];if(v>0&&S.push(`${v} screenshot(s)`),m>0){let k=x>0?` (${x} per-flow)`:"";S.push(`${m} video(s)${k}`);}process.stderr.write(`\u2713 TestRelic: Uploaded ${I} artifact(s) [${S.join(", ")}] to cloud storage.
1270
1270
  `);}if(f.length>0){process.stderr.write(`\u26A0 TestRelic: ${f.length} artifact(s) failed to upload:
1271
- `);for(let[m,w]of f){let R=y.find(v=>v.filePath===m),A=R?`[${R.type}] ${m}`:m;process.stderr.write(` \u2717 ${A} \u2014 reason: ${w.error??"unknown"}
1272
- `);}}}}if(e.isCloudMode())if(await e.ensureValidToken()){let b=e.getGitMetadata(),g=ue(),h=gr(e),y=Us(n.timeline),T={...n,timeline:y},C=le(T,h,b,g,c),_=await rt(e.getEndpoint(),e.getAccessToken(),C,async()=>await e.ensureValidToken()?e.getAccessToken():null);if(_.success)process.stderr.write(`\u2713 TestRelic: Cloud upload succeeded \u2192 ${e.getEndpoint()}/runs/${r}
1273
- `);else {let I=_,f=t?.queueDirectory??".testrelic/queue";oe(f,r,"batch",I.reason,I.targetEndpoint,I.method,I.payload,{"Content-Type":"application/json"}),process.stderr.write(`\u26A0 TestRelic: Cloud upload failed, queued for retry.
1274
- `);}}else {let b=t?.queueDirectory??".testrelic/queue",g=e.getGitMetadata(),h=ue(),y=gr(e),T=le(n,y,g,h);oe(b,r,"batch",e.getFailureReason()??"token_invalid",`${e.getEndpoint()}/runs`,"POST",T,{"Content-Type":"application/json"});}await e.dispose();}catch{try{await e.dispose();}catch{}}}function hr(e,t,r){if(t.length===0)return null;let n=path.basename(e,path.extname(e)).toLowerCase(),o=t.find(a=>path.basename(a,path.extname(a)).toLowerCase()===n);if(o)return o;let s=t.find(a=>path.basename(a).toLowerCase().includes(n));if(s)return s;let i=t.find(a=>{let l=path.basename(a,path.extname(a)).toLowerCase();return l.length>=3&&(n.startsWith(l)||n.includes(l))});if(i)return i;if(r){let a=path.basename(r,path.extname(r)).toLowerCase(),l=t.find(d=>path.basename(d,path.extname(d)).toLowerCase()===a);if(l)return l;let c=t.find(d=>path.basename(d).toLowerCase().includes(a));if(c)return c}return null}function zs(e,t){if(t.length===0)return [];let r=path.basename(e,path.extname(e)).toLowerCase(),n=t.filter(o=>{let s=path.basename(o).toLowerCase(),i=path.basename(o,path.extname(o)).toLowerCase();return s.startsWith(r)||s.includes(r)?true:i.length>=3&&(r.startsWith(i)||r.includes(i))});return n.length>0?n:t.slice()}function qs(e){for(let t of e)if(t.command==="startRecording"){let r=t.metadata,n=r?.path??r?.recording??r?.fileName;if(typeof n=="string")return n;if(typeof t.selector=="string")return t.selector}return null}function Gs(e){let t=new Map;for(let[r,n]of e){let o=path.basename(r).replace(/^commands[-_]?/i,"").replace(/\.json$/i,"").toLowerCase(),s=qs(n);s&&o&&t.set(o,s);}return t}function Vs(e,t){let r=path.basename(t,path.extname(t)).toLowerCase();if(!r||e.size===0)return {commands:[],matchedAnyFile:false};let n=o=>path.basename(o,path.extname(o)).replace(/^commands[-_]?/i,"").toLowerCase();for(let[o,s]of e)if(n(o)===r)return {commands:s,matchedAnyFile:true};for(let[o,s]of e){let i=n(o);if(i.length>=3&&i.includes(r))return {commands:s,matchedAnyFile:true}}for(let[o,s]of e){let i=n(o);if(i.length>=3&&r.includes(i))return {commands:s,matchedAnyFile:true}}return {commands:[],matchedAnyFile:false}}function Js(e){switch(e){case "android":return "Android";case "ios":return "iOS";case "web":return "Web";default:return}}function Ws(e,t){let r=e.logEntries.length>0?e.logEntries.map(n=>({level:n.level.toLowerCase(),message:n.message,timestamp:n.timestamp,source:n.source})):void 0;return {testId:`${e.flowFile}::${e.flowName}`,title:e.flowName,status:e.status,duration:e.duration,suiteName:e.appId??"maestro-suite",filePath:e.flowFile,testType:"mobile",isFlaky:false,startedAt:e.startedAt,completedAt:e.completedAt,tags:e.tags,failure:e.failureMessage?{message:e.failureMessage}:null,retry:0,retryCount:0,retryStatus:null,source:"maestro",platform:e.platform!=="unknown"?e.platform:void 0,os:Js(e.platform),deviceName:e.deviceId,...r?{consoleLogs:r}:{},...t&&t.length>0?{apiCalls:t}:{}}}function Ks(e,t,r){if(e.length===0)return [];let n=Date.parse(t),o=Date.parse(r);return Number.isNaN(n)||Number.isNaN(o)?e.slice():e.filter(s=>{let i=Date.parse(s.timestamp);return Number.isNaN(i)?true:i>=n&&i<=o})}async function Xs(e){let{config:t}=e,r=new Date().toISOString(),n=t.testRunId??crypto.randomUUID(),o=Ne(e.testOutputDir,e.debugOutputDir),s=e.junitPath??o.junitReportPath,i=e.debugOutputDir?Te(e.debugOutputDir):o.logPaths,a=[];for(let f of i){let m=Ae(f);m.length>0&&a.push(...m);}let l=e.platform??"unknown";if(l==="unknown"&&a.length>0){let f=Se(a);f!=="unknown"&&(l=f);}let c=new Map;if(e.flowsDir&&fs.existsSync(e.flowsDir)){let f=Re(e.flowsDir);for(let m of f){let w=Ce(m),R=w.name??m;c.set(R,w);}}let d=new Map,u=e.testOutputDir?ke(e.testOutputDir):o.commandJsonPaths;for(let f of u)d.set(f,ve(f));let p=[],x=e.testOutputDir?De(e.testOutputDir):o.aiReportPaths;for(let f of x){let m=Le(f);p.push(...m.defects);}let b=Gs(d),g=[];if(s&&fs.existsSync(s)){let f=xe(s),m=Array.from(d.values()).flat(),w=m.filter(A=>A.category==="assertion"),R=m.filter(A=>A.category!=="assertion");for(let A of f.testSuites)for(let v of A.testCases){let k=v.name,M=c.get(k),H=v.status==="SUCCESS"?"passed":v.status==="SKIPPED"?"skipped":"failed",L=v.time*1e3,$=r,G=new Date(new Date($).getTime()+L).toISOString(),B=v.classname||k,yr=path.basename(B,path.extname(B)).toLowerCase(),xr=b.get(yr)??null,{commands:at,matchedAnyFile:lt}=Vs(d,B),wr=lt?at.filter(fe=>fe.category!=="assertion"):R,vr=lt?at.filter(fe=>fe.category==="assertion"):w;g.push({flowName:k,flowFile:B,appId:M?.appId??null,platform:l,deviceId:e.device,status:H,duration:L,startedAt:$,completedAt:G,tags:M?.tags??[],properties:M?.properties??{},commands:wr,assertions:vr,screenshotPaths:zs(B,o.screenshotPaths),videoPath:hr(B,o.videoPaths,xr),aiDefects:p,logEntries:Ks(a,$,G),failureMessage:v.failureMessage??v.errorMessage??null,failureType:v.failureType??v.errorType??null,subflowRefs:M?.subflowRefs??[],metadata:M??null});}}if(g.length===0&&c.size>0)for(let[,f]of c)g.push({flowName:f.name??f.filePath,flowFile:f.filePath,appId:f.appId,platform:l,deviceId:e.device,status:"passed",duration:0,startedAt:r,completedAt:r,tags:f.tags,properties:f.properties,commands:[],assertions:[],screenshotPaths:[],videoPath:null,aiDefects:[],logEntries:a.slice(),failureMessage:null,failureType:null,subflowRefs:f.subflowRefs,metadata:f});let h=(()=>{if(!t.network?.enabled&&!t.network?.harPath)return;let f=g.map(R=>({testId:`${R.flowFile}::${R.flowName}`,startedAt:R.startedAt,completedAt:R.completedAt})),m=rr(e.networkJsonlDir??null,t.network,f);if(m.size===0)return;let w=new Map;for(let[R,A]of m)w.set(R,nr(A));return w})(),y=Ue(g,h),T=V(y),C=new Date().toISOString(),_=Date.now()-new Date(r).getTime(),I={schemaVersion:"1.0.0",testRunId:n,startedAt:r,completedAt:C,totalDuration:_,summary:T,ci:null,metadata:t.metadata??null,timeline:y,shardRunIds:null};if(fs.mkdirSync(path.dirname(path.resolve(t.outputPath)),{recursive:true}),fs.writeFileSync(path.resolve(t.outputPath),JSON.stringify(I,null,2),"utf-8"),Be(I,p,o.screenshotPaths,path.resolve(t.htmlReportPath)),je(T,t.outputPath,t.htmlReportPath,t.quiet,p),t.openReport&&ze(path.resolve(t.htmlReportPath)),t.cloud){let f=new W(t.cloud);await f.initialize();let m=t.includeVideo?o.videoPaths:[],w=[];if(m.length>0){for(let k of g){let M=path.basename(k.flowFile,path.extname(k.flowFile)).toLowerCase(),H=b.get(M)??null,L=hr(k.flowFile,m,H);if(L){let $=`${k.flowFile}::${k.flowName}`;w.some(G=>G.path===L&&G.testId===$)||w.push({path:L,testId:$});}}if(m.length===1){let k=m[0];for(let M of g){let H=`${M.flowFile}::${M.flowName}`;w.some(L=>L.testId===H)||w.push({path:k,testId:H});}}}let R=new Set(w.map(k=>k.path)),A=m.filter(k=>!R.has(k)),v=g.map(k=>{let M=`${k.flowFile}::${k.flowName}`;return Ws(k,h?.get(M))});await it(f,t.cloud,n,I,C,_,T,t.includeScreenshots?o.screenshotPaths:[],A,v,w);}return {report:I,flowResults:g,aiDefects:p,artifacts:o}}function ni(e){return "tests"in e&&"visitedAt"in e}function br(e){let t=[],r=[],n="",o="",s="";for(let c of e)try{let d=fs.readFileSync(c,"utf-8"),u=JSON.parse(d);s||(s=u.testRunId),(!n||u.startedAt<n)&&(n=u.startedAt),(!o||u.completedAt&&u.completedAt>o)&&(o=u.completedAt);for(let p of u.timeline)t.push(p),ni(p)&&r.push(p);}catch{process.stderr.write(`\u26A0 TestRelic: Unable to read report file: ${c}
1275
- `);}let i=V(r),a=n?new Date(n).getTime():Date.now(),l=o?new Date(o).getTime():Date.now();return {schemaVersion:"1.0.0",testRunId:s||`maestro-merged-${Date.now()}`,startedAt:n||new Date().toISOString(),completedAt:o||new Date().toISOString(),totalDuration:l-a,summary:i,ci:null,metadata:null,timeline:t,shardRunIds:null}}function oi(e,t){if(!fs.existsSync(e))throw new Error(`Directory does not exist: ${e}`);let r=fs.readdirSync(e).filter(o=>path.extname(o)===".json"&&o.includes("testrelic")).map(o=>path.join(e,o)),n=br(r);return fs.writeFileSync(t,JSON.stringify(n,null,2),"utf-8"),n}exports.CloudClient=W;exports.DEFAULT_CLOUD_CONFIG=ge;exports.buildMaestroArgs=Kt;exports.buildSummary=V;exports.buildTimeline=Ue;exports.buildTimelineEntry=Et;exports.buildUploadPayload=le;exports.categorizeCommand=vt;exports.cleanupExpiredQueue=et;exports.collectArtifacts=Ne;exports.collectGitMetadata=Xe;exports.deriveNonGitProjectId=z;exports.deriveRepoDisplayName=Ye;exports.detectCI=ue;exports.detectPlatformFromLogs=Se;exports.discoverAiReports=De;exports.discoverCommandFiles=ke;exports.discoverConfigFile=he;exports.discoverFlowFiles=Re;exports.discoverLogFiles=Te;exports.enforceHttps=Je;exports.exchangeToken=te;exports.finalizeAndUpload=it;exports.finalizeRun=ys;exports.flushQueue=Ze;exports.generateHtmlReport=Be;exports.getArtifactStats=Gn;exports.healthCheck=ee;exports.initRealtimeRun=bs;exports.isAuthError=re;exports.mergeCloudConfig=ye;exports.mergeReports=br;exports.mergeReportsFromDirectory=oi;exports.normalizeGitRemoteUrl=j;exports.openInBrowser=ze;exports.orchestrateReport=Xs;exports.parseAiReportFile=Le;exports.parseAiReportHtml=It;exports.parseCommandsFile=ve;exports.parseCommandsJson=kt;exports.parseConfigFile=be;exports.parseDuration=me;exports.parseFlowFile=Ce;exports.parseFlowYaml=At;exports.parseJUnitFile=xe;exports.parseJUnitXml=bt;exports.parseLogContent=Tt;exports.parseLogFile=Ae;exports.printConsoleSummary=je;exports.readPackageJsonName=ir;exports.refreshAccessToken=We;exports.renderHtmlDocument=$e;exports.resolveConfig=$r;exports.resolveEnvVar=K;exports.resolveEnvVars=X;exports.resolveRepo=Ke;exports.runMaestro=Mo;exports.uploadArtifact=fr;exports.uploadArtifacts=st;exports.uploadBatchRun=rt;exports.writeToQueue=oe;//# sourceMappingURL=index.cjs.map
1271
+ `);for(let[m,x]of f){let v=b.find(k=>k.filePath===m),S=v?`[${v.type}] ${m}`:m;process.stderr.write(` \u2717 ${S} \u2014 reason: ${x.error??"unknown"}
1272
+ `);}}}}if(e.isCloudMode())if(await e.ensureValidToken()){let y=e.getGitMetadata(),g=ue(),h=xr(e),b=zs(n.timeline),A={...n,timeline:b},R=le(A,h,y,g,c),D=await nt(e.getEndpoint(),e.getAccessToken(),R,async()=>await e.ensureValidToken()?e.getAccessToken():null);if(D.success)process.stderr.write(`\u2713 TestRelic: Cloud upload succeeded \u2192 ${e.getEndpoint()}/runs/${r}
1273
+ `);else {let I=D,f=t?.queueDirectory??".testrelic/queue";oe(f,r,"batch",I.reason,I.targetEndpoint,I.method,I.payload,{"Content-Type":"application/json"}),process.stderr.write(`\u26A0 TestRelic: Cloud upload failed, queued for retry.
1274
+ `);}}else {let y=t?.queueDirectory??".testrelic/queue",g=e.getGitMetadata(),h=ue(),b=xr(e),A=le(n,b,g,h);oe(y,r,"batch",e.getFailureReason()??"token_invalid",`${e.getEndpoint()}/runs`,"POST",A,{"Content-Type":"application/json"});}await e.dispose();}catch{try{await e.dispose();}catch{}}}function vr(e,t,r){if(t.length===0)return null;let n=path.basename(e,path.extname(e)).toLowerCase(),o=t.find(a=>path.basename(a,path.extname(a)).toLowerCase()===n);if(o)return o;let s=t.find(a=>path.basename(a).toLowerCase().includes(n));if(s)return s;let i=t.find(a=>{let l=path.basename(a,path.extname(a)).toLowerCase();return l.length>=3&&(n.startsWith(l)||n.includes(l))});if(i)return i;if(r){let a=path.basename(r,path.extname(r)).toLowerCase(),l=t.find(d=>path.basename(d,path.extname(d)).toLowerCase()===a);if(l)return l;let c=t.find(d=>path.basename(d).toLowerCase().includes(a));if(c)return c}return null}function Ws(e,t){if(t.length===0)return [];let r=path.basename(e,path.extname(e)).toLowerCase(),n=t.filter(o=>{let s=path.basename(o).toLowerCase(),i=path.basename(o,path.extname(o)).toLowerCase();return s.startsWith(r)||s.includes(r)?true:i.length>=3&&(r.startsWith(i)||r.includes(i))});return n.length>0?n:t.slice()}function Ks(e){for(let t of e)if(t.command==="startRecording"){let r=t.metadata,n=r?.path??r?.recording??r?.fileName;if(typeof n=="string")return n;if(typeof t.selector=="string")return t.selector}return null}function kr(e){return path.basename(e).replace(/^commands[-_]?/i,"").replace(/\.json$/i,"").replace(/^\(/,"").replace(/\)$/,"").toLowerCase()}function Xs(e){let t=new Map;for(let[r,n]of e){let o=kr(r),s=Ks(n);s&&o&&t.set(o,s);}return t}function Ys(e,t){let r=path.basename(t,path.extname(t)).toLowerCase();if(!r||e.size===0)return {commands:[],matchedAnyFile:false};let n=o=>kr(o);for(let[o,s]of e)if(n(o)===r)return {commands:s,matchedAnyFile:true};for(let[o,s]of e){let i=n(o);if(i.length>=3&&i.includes(r))return {commands:s,matchedAnyFile:true}}for(let[o,s]of e){let i=n(o);if(i.length>=3&&r.includes(i))return {commands:s,matchedAnyFile:true}}return {commands:[],matchedAnyFile:false}}function Qs(e){switch(e){case "android":return "Android";case "ios":return "iOS";case "web":return "Web";default:return}}function Zs(e,t,r){let n=e.logEntries.length>0?e.logEntries.map(o=>({level:o.level.toLowerCase(),message:o.message,timestamp:o.timestamp,source:o.source})):void 0;return {testId:`${e.flowFile}::${e.flowName}`,title:e.flowName,status:e.status,duration:e.duration,suiteName:e.appId??"maestro-suite",filePath:e.flowFile,testType:"mobile",isFlaky:false,startedAt:e.startedAt,completedAt:e.completedAt,tags:e.tags,failure:e.failureMessage?{message:e.failureMessage}:null,retry:0,retryCount:0,retryStatus:null,source:"maestro",platform:e.platform!=="unknown"?e.platform:void 0,os:Qs(e.platform),deviceName:e.deviceId,...n?{consoleLogs:n}:{},...t&&t.length>0?{apiCalls:t}:{},...r&&r.length>0?{actions:r}:{}}}function ei(e,t,r){if(e.length===0)return [];let n=Date.parse(t),o=Date.parse(r);return Number.isNaN(n)||Number.isNaN(o)?e.slice():e.filter(s=>{let i=Date.parse(s.timestamp);return Number.isNaN(i)?true:i>=n&&i<=o})}async function ti(e){let{config:t}=e,r=new Date().toISOString(),n=t.testRunId??crypto.randomUUID(),o=Oe(e.testOutputDir,e.debugOutputDir),s=e.junitPath??o.junitReportPath,i=e.debugOutputDir?Ie(e.debugOutputDir):o.logPaths,a=[];for(let f of i){let m;try{let{statSync:v}=await import('fs');m=v(f).mtime;}catch{}let x=Ae(f,m);x.length>0&&a.push(...x);}let l=e.platform??"unknown";if(l==="unknown"&&a.length>0){let f=Te(a);f!=="unknown"&&(l=f);}let c=new Map;if(e.flowsDir&&fs.existsSync(e.flowsDir)){let f=Se(e.flowsDir);for(let m of f){let x=Re(m),v=x.name??m;c.set(v,x);}}let d=new Map,u=e.testOutputDir?Ce(e.testOutputDir):o.commandJsonPaths;for(let f of u)d.set(f,ke(f));let p=[],w=e.testOutputDir?Ne(e.testOutputDir):o.aiReportPaths;for(let f of w){let m=De(f);p.push(...m.defects);}let y=Xs(d),g=[];if(s&&fs.existsSync(s)){let f=we(s),m=Array.from(d.values()).flat(),x=m.filter(S=>S.category==="assertion"),v=m.filter(S=>S.category!=="assertion");for(let S of f.testSuites)for(let k of S.testCases){let C=k.name,M=c.get(C),N=k.status==="SUCCESS"?"passed":k.status==="SKIPPED"?"skipped":"failed",F=k.time*1e3,L=k.classname||C,W=path.basename(L,path.extname(L)).toLowerCase(),Rr=y.get(W)??null,{commands:lt,matchedAnyFile:ct}=Ys(d,L),dt=ct?lt.filter(B=>B.category!=="assertion"):v,ut=ct?lt.filter(B=>B.category==="assertion"):x,pt=[...dt,...ut].reduce((B,Sr)=>{let ge=Date.parse(Sr.timestamp);return Number.isFinite(ge)&&ge<B?ge:B},Number.POSITIVE_INFINITY),fe=Number.isFinite(pt)?new Date(pt).toISOString():r,ft=new Date(new Date(fe).getTime()+F).toISOString();g.push({flowName:C,flowFile:L,appId:M?.appId??null,platform:l,deviceId:e.device,status:N,duration:F,startedAt:fe,completedAt:ft,tags:M?.tags??[],properties:M?.properties??{},commands:dt,assertions:ut,screenshotPaths:Ws(L,o.screenshotPaths),videoPath:vr(L,o.videoPaths,Rr),aiDefects:p,logEntries:ei(a,fe,ft),failureMessage:k.failureMessage??k.errorMessage??null,failureType:k.failureType??k.errorType??null,subflowRefs:M?.subflowRefs??[],metadata:M??null});}}if(g.length===0&&c.size>0)for(let[,f]of c)g.push({flowName:f.name??f.filePath,flowFile:f.filePath,appId:f.appId,platform:l,deviceId:e.device,status:"passed",duration:0,startedAt:r,completedAt:r,tags:f.tags,properties:f.properties,commands:[],assertions:[],screenshotPaths:[],videoPath:null,aiDefects:[],logEntries:a.slice(),failureMessage:null,failureType:null,subflowRefs:f.subflowRefs,metadata:f});let h=(()=>{if(!t.network?.enabled&&!t.network?.harPath)return;let f=g.map(v=>({testId:`${v.flowFile}::${v.flowName}`,startedAt:v.startedAt,completedAt:v.completedAt})),m=ar(e.networkJsonlDir??null,t.network,f);if(m.size===0)return;let x=new Map;for(let[v,S]of m)x.set(v,lr(S));return x})(),b=He(g,h),A=G(b),R=new Date().toISOString(),D=Date.now()-new Date(r).getTime(),I={schemaVersion:"1.0.0",testRunId:n,startedAt:r,completedAt:R,totalDuration:D,summary:A,ci:null,metadata:t.metadata??null,timeline:b,shardRunIds:null};if(fs.mkdirSync(path.dirname(path.resolve(t.outputPath)),{recursive:true}),fs.writeFileSync(path.resolve(t.outputPath),JSON.stringify(I,null,2),"utf-8"),je(I,p,o.screenshotPaths,path.resolve(t.htmlReportPath)),ze(A,t.outputPath,t.htmlReportPath,t.quiet,p),t.openReport&&qe(path.resolve(t.htmlReportPath)),t.cloud){let f=new J(t.cloud);await f.initialize();let m=t.includeVideo?o.videoPaths:[],x=[];if(m.length>0){for(let C of g){let M=path.basename(C.flowFile,path.extname(C.flowFile)).toLowerCase(),N=y.get(M)??null,F=vr(C.flowFile,m,N);if(F){let L=`${C.flowFile}::${C.flowName}`;x.some(W=>W.path===F&&W.testId===L)||x.push({path:F,testId:L});}}if(m.length===1){let C=m[0];for(let M of g){let N=`${M.flowFile}::${M.flowName}`;x.some(F=>F.testId===N)||x.push({path:C,testId:N});}}}let v=new Set(x.map(C=>C.path)),S=m.filter(C=>!v.has(C)),k=g.map((C,M)=>{let N=`${C.flowFile}::${C.flowName}`,F=b[M]?.tests?.[0];return Zs(C,h?.get(N),F?.actions??null)});await at(f,t.cloud,n,I,R,D,A,t.includeScreenshots?o.screenshotPaths:[],S,k,x);}return {report:I,flowResults:g,aiDefects:p,artifacts:o}}function li(e){return "tests"in e&&"visitedAt"in e}function Cr(e){let t=[],r=[],n="",o="",s="";for(let c of e)try{let d=fs.readFileSync(c,"utf-8"),u=JSON.parse(d);s||(s=u.testRunId),(!n||u.startedAt<n)&&(n=u.startedAt),(!o||u.completedAt&&u.completedAt>o)&&(o=u.completedAt);for(let p of u.timeline)t.push(p),li(p)&&r.push(p);}catch{process.stderr.write(`\u26A0 TestRelic: Unable to read report file: ${c}
1275
+ `);}let i=G(r),a=n?new Date(n).getTime():Date.now(),l=o?new Date(o).getTime():Date.now();return {schemaVersion:"1.0.0",testRunId:s||`maestro-merged-${Date.now()}`,startedAt:n||new Date().toISOString(),completedAt:o||new Date().toISOString(),totalDuration:l-a,summary:i,ci:null,metadata:null,timeline:t,shardRunIds:null}}function ci(e,t){if(!fs.existsSync(e))throw new Error(`Directory does not exist: ${e}`);let r=fs.readdirSync(e).filter(o=>path.extname(o)===".json"&&o.includes("testrelic")).map(o=>path.join(e,o)),n=Cr(r);return fs.writeFileSync(t,JSON.stringify(n,null,2),"utf-8"),n}exports.CloudClient=J;exports.DEFAULT_CLOUD_CONFIG=me;exports.buildMaestroArgs=er;exports.buildSummary=G;exports.buildTimeline=He;exports.buildTimelineEntry=Dt;exports.buildUploadPayload=le;exports.categorizeCommand=At;exports.cleanupExpiredQueue=tt;exports.collectArtifacts=Oe;exports.collectGitMetadata=Ye;exports.deriveNonGitProjectId=z;exports.deriveRepoDisplayName=Qe;exports.detectCI=ue;exports.detectPlatformFromLogs=Te;exports.discoverAiReports=Ne;exports.discoverCommandFiles=Ce;exports.discoverConfigFile=be;exports.discoverFlowFiles=Se;exports.discoverLogFiles=Ie;exports.enforceHttps=We;exports.exchangeToken=te;exports.finalizeAndUpload=at;exports.finalizeRun=Cs;exports.flushQueue=et;exports.generateHtmlReport=je;exports.getArtifactStats=Xn;exports.healthCheck=ee;exports.initRealtimeRun=ks;exports.isAuthError=re;exports.mergeCloudConfig=xe;exports.mergeReports=Cr;exports.mergeReportsFromDirectory=ci;exports.normalizeGitRemoteUrl=j;exports.openInBrowser=qe;exports.orchestrateReport=ti;exports.parseAiReportFile=De;exports.parseAiReportHtml=_t;exports.parseCommandsFile=ke;exports.parseCommandsJson=Tt;exports.parseConfigFile=ye;exports.parseDuration=he;exports.parseFlowFile=Re;exports.parseFlowYaml=Et;exports.parseJUnitFile=we;exports.parseJUnitXml=kt;exports.parseLogContent=Pt;exports.parseLogFile=Ae;exports.printConsoleSummary=ze;exports.readPackageJsonName=ur;exports.refreshAccessToken=Ke;exports.renderHtmlDocument=Be;exports.resolveConfig=qr;exports.resolveEnvVar=K;exports.resolveEnvVars=X;exports.resolveRepo=Xe;exports.runMaestro=Lo;exports.uploadArtifact=yr;exports.uploadArtifacts=it;exports.uploadBatchRun=nt;exports.writeToQueue=oe;//# sourceMappingURL=index.cjs.map
1276
1276
  //# sourceMappingURL=index.cjs.map