"use strict";var g=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var n=(t,e)=>g(t,"name",{value:e,configurable:!0});var I=(t,e)=>{for(var r in e)g(t,r,{get:e[r],enumerable:!0})},C=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of M(e))!F.call(t,s)&&s!==r&&g(t,s,{get:()=>e[s],enumerable:!(o=P(e,s))||o.enumerable});return t};var w=t=>C(g({},"__esModule",{value:!0}),t);var z={};I(z,{default:()=>f});module.exports=w(z);var E=require("path");var T=n(t=>{if(t.error!=null)return"ERROR";let e=t.status_code;if(typeof e=="number"&&e>=500)return"ERROR";let r=t.exit_code;return typeof r=="number"&&r!==0?"ERROR":"INFO"},"severityFor");var y=require("fs");var b="\x1B[31m",v="\x1B[33m",D="\x1B[32m",_="\x1B[36m",O="\x1B[2m",W="\x1B[1m",d="\x1B[0m",L=n(()=>{let t=process.env.WIDE_EVENT_PRETTY;return t==="true"||t==="1"?!0:t==="false"||t==="0"?!1:process.stdout.isTTY?!0:process.env.APP_ENV==="local"},"shouldPretty"),B=new Set(["severity","message","kind","timestamp","_startedAtMs"]),H=n(t=>{let e=new WeakSet;return JSON.stringify(t,(r,o)=>{if(typeof o=="bigint")return o.toString();if(typeof o=="object"&&o!==null){if(e.has(o))return"[Circular]";e.add(o)}return o})},"safeStringify"),U=n(t=>t==="ERROR"||t==="CRITICAL"?b:t==="WARNING"?v:D,"colorForSeverity"),$=n(t=>{let e=String(t.severity??"INFO"),r=`${U(e)}${e.padEnd(5)}${d}`,o=t.kind?`${_}${t.kind}${d}`:"",s=String(t.message??""),a=t.error&&typeof t.error=="object"?(()=>{let i=t.error;return` ${b}${i.type??"Error"}: ${i.message??""}${d}`})():"",l=["outcome","test_suite_run_id","status"],u=Object.entries(t).filter(([i,p])=>!B.has(i)&&p!=null&&i!=="error"&&typeof p!="object"),c=n(i=>{let p=l.indexOf(i);return p===-1?l.length:p},"rank"),m=u.sort(([i],[p])=>c(i)-c(p)).slice(0,8).map(([i,p])=>`${O}${i}=${d}${p}`).join(" ");return[r,W+o+d,s,m,a].filter(i=>i&&i.trim()!=="").join("  ")},"formatPretty"),N=n(t=>{let e=t.trace_id;if(typeof e!="string"||e==="")return t;let r=process.env.GCP_PROJECT_ID||process.env.GOOGLE_CLOUD_PROJECT;return r?{...t,"logging.googleapis.com/trace":`projects/${r}/traces/${e}`}:t},"withGcpTraceField"),A=n(t=>{let e=L()?$(t):H(N(t));(0,y.writeSync)(1,e+`
`)},"emitEvent");var x=n(t=>{(0,y.writeSync)(2,t.endsWith(`
`)?t:`${t}
`)},"writeStderrLine");var j=n(t=>A(t),"defaultSink"),G=j;var S=n(t=>t==="true"||t==="1","truthy"),V=n(()=>S(process.env.CHECKSUM_WIDE_EVENTS)||S(process.env.WIDE_EVENT_PRETTY),"wideEventsEnabled"),Y=n(t=>{let e=t.kind??"event",r=t.outcome?` ${t.outcome}`:"",o=typeof t.duration_ms=="number"?` ${t.duration_ms}ms`:"";return`${e}${r}${o}`.trim()},"messageFor"),K=n(t=>{if(!V())return;let e={severity:T(t),message:t.message??Y(t),...t};try{G(e)}catch(r){try{x(`[wide-event] runtime emit failed: ${String(r)}`)}catch{}}},"dispatch");var k=n((t,e={})=>{K({timestamp:new Date().toISOString(),kind:t,...e})},"emitWideEvent");var R=2e3;function q(t){switch(t){case"passed":return"passed";case"timedOut":return"timedOut";case"skipped":return"skipped";case"interrupted":return"interrupted";case"failed":default:return"failed"}}n(q,"toProgressStatus");var h=class h{constructor(){this.monitorPort=process.env.CHECKSUM_UPLOAD_AGENT_PORT;this.startedAt=Date.now();this.rootDir=process.cwd();this.testsById=new Map;this.lastFlushAt=0;this.sendChain=Promise.resolve()}printsToStdio(){return!1}onBegin(e,r){this.guard(()=>{var o;e!=null&&e.rootDir&&(this.rootDir=e.rootDir);for(let s of((o=r==null?void 0:r.allTests)==null?void 0:o.call(r))??[])this.register(s);this.flush(!0)})}onTestBegin(e,r){this.guard(()=>{var s;let o=this.itemFor(e);o.status="running",o.startedAt=((s=r==null?void 0:r.startTime)==null?void 0:s.getTime())??Date.now(),o.endedAt=null,o.durationMs=null,o.retry=(r==null?void 0:r.retry)??0,this.flush()})}onTestEnd(e,r){this.guard(()=>{var a;let o=this.itemFor(e);o.status=q(r==null?void 0:r.status),o.endedAt=Date.now(),o.durationMs=(r==null?void 0:r.duration)??null,o.retry=(r==null?void 0:r.retry)??o.retry,o.startedAt==null&&(o.startedAt=((a=r==null?void 0:r.startTime)==null?void 0:a.getTime())??null),this.flush();let s=o.status==="passed"||o.status==="skipped";k("test_result",{test_suite_run_id:process.env.CHECKSUM_TEST_SUITE_ID,outcome:s?"success":"error",test_id:o.id,status:o.status,retry:o.retry,duration_ms:o.durationMs??void 0,title:o.title,file:o.file,project:o.project||void 0})})}async onEnd(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=void 0),await this.send()}itemFor(e){return this.testsById.get(e.id)??this.register(e)}register(e){var a,l,u,c,m;let r="";try{r=((u=(l=(a=e.parent)==null?void 0:a.project)==null?void 0:l.call(a))==null?void 0:u.name)??""}catch{}let o=((c=e.location)==null?void 0:c.file)??"";try{o&&(o=(0,E.relative)(this.rootDir,o))}catch{}let s={id:e.id,title:e.title??"",titlePath:this.titlePathOf(e),file:o,line:((m=e.location)==null?void 0:m.line)??0,project:r,status:"pending",startedAt:null,endedAt:null,durationMs:null,retry:0};return this.testsById.set(s.id,s),s}titlePathOf(e){var r;try{return(((r=e.titlePath)==null?void 0:r.call(e))??[]).filter(o=>!!o)}catch{return e.title?[e.title]:[]}}snapshot(){return{schemaVersion:1,source:"playwright",startedAt:this.startedAt,updatedAt:Date.now(),tests:[...this.testsById.values()]}}flush(e=!1){if(!this.monitorPort)return;let r=Date.now()-this.lastFlushAt;if(e||r>=R){this.lastFlushAt=Date.now(),this.send();return}this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=void 0,this.lastFlushAt=Date.now(),this.send()},R-r))}send(){return this.monitorPort?(this.sendChain=this.sendChain.then(()=>this.postSnapshot()),this.sendChain):Promise.resolve()}async postSnapshot(){try{await fetch(`http://127.0.0.1:${this.monitorPort}/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"runProgress",payload:this.snapshot()})})}catch{}}guard(e){try{e()}catch{}}};n(h,"ChecksumProgressReporter");var f=h;
