@qadet/runner 0.7.13 → 0.7.14

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/qadet.mjs +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qadet/runner",
3
- "version": "0.7.13",
3
+ "version": "0.7.14",
4
4
  "description": "Runs Qadet tests in Chrome on this computer",
5
5
  "type": "module",
6
6
  "files": [
package/qadet.mjs CHANGED
@@ -100,7 +100,7 @@ ${n(" picture")} {
100
100
  window.location.assign(url)
101
101
  return window
102
102
  }
103
- })()`,$v=A(e=>e.addInitScript({content:bz}),"keepRunsToOneTab")});var Uv,cn,_v,Dc=y(()=>{"use strict";Uv=/^(?:[0-7][0-9A-HJKMNP-TV-Z]{25}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{24}|\d{5,})$/i,cn=A((e,t)=>{let[n="",i]=_v(e),[r="",o]=_v(t);if(i!==void 0){let E=i.replace(/^!/,""),I=(o??"").replace(/^!/,"");return(n.split("?")[0]??"").replace(/\/+$/,"")!==""&&!cn(n,r)?!1:E.startsWith("/")&&I.startsWith("/")?cn(E,I):E===I}let[s="",a]=n.split("?"),[c="",u]=r.split("?"),l=s.split("/").filter(Boolean),d=c.split("/").filter(Boolean);if(l.length===0?d.length!==0:l.length>d.length)return!1;let g=d.length-l.length;if(!l.every((E,I)=>E==="*"||E===d[g+I]||Uv.test(E)&&Uv.test(d[g+I]??"")))return!1;if(!a)return!0;let p=new URLSearchParams(a),m=new URLSearchParams(u||"");for(let[E,I]of p.entries())if(m.get(E)!==I)return!1;return!0},"pathMatches"),_v=A(e=>{let t=e.indexOf("#");return t===-1?[e,void 0]:[e.slice(0,t),e.slice(t+1)]},"splitHash")});var vz,Tv,zf,Lv,Mv,kz,Dz,Pv,Of,nA=y(()=>{"use strict";Zi();Dc();vz=300,Tv=new WeakMap,zf=new WeakMap,Lv=A(e=>{let t=[];Tv.set(e,t);let n=new Map;zf.set(e,n),e.on("request",i=>{["fetch","xhr"].includes(i.resourceType())&&n.set(i,Date.now())}),e.on("requestfinished",i=>n.delete(i)),e.on("requestfailed",i=>n.delete(i)),e.on("response",i=>{let r=i.request();if(!["fetch","xhr","document"].includes(r.resourceType()))return;let o=new URL(i.url());t.push({method:r.method(),path:`${o.pathname}${o.search}`,status:i.status(),at:Date.now()}),t.length>vz&&t.shift()})},"watchRequests"),Mv=A(async(e,t=5e3)=>{let n=zf.get(e);if(!n)return;let i=Uf(e),r=Date.now()+t;for(;[...n.values()].some(o=>o>=i)&&Date.now()<r;)await e.waitForTimeout(100).catch(()=>{})},"requestsSettled"),kz=A(e=>e>=200&&e<400,"succeeded"),Dz=A(({method:e,path:t,status:n})=>`${e} ${t} answered ${n}`,"describe"),Pv=A(async(e,t,n,i,r=1e4)=>{let o=t.toUpperCase(),s=Uf(e),a=A(()=>(Tv.get(e)??[]).filter(l=>l.at>=s&&l.method===o&&cn(n,l.path)),"sent"),c=Date.now()+r;do{if(a().find(d=>i===void 0?kz(d.status):d.status===i))return{passed:!0};await e.waitForTimeout(250).catch(()=>{})}while(Date.now()<c);let u=a().at(-1);return{passed:!1,reason:u?`${Dz(u)}, not ${i??"a success"}`:`No ${o} ${n} was sent since the last step`}},"requestAnswered"),Of=A(e=>{let t=zf.get(e);if(!t)return!1;let n=Date.now()-1e4;return[...t.values()].some(i=>i>=n)},"requestsPending")});import{mkdir as Sz,mkdtemp as xz}from"node:fs/promises";import{join as Nz,resolve as Rz}from"node:path";import{chromium as $z,devices as Fz}from"playwright-core";var Uz,_z,Sc,Tz,Lz,Or,Mz,Pz,Ov,Jv,zz,Xi,xc,Oz,Jz,eo,Gz,Gv,Vz,Yz,Nc,Vv,Hz,jz,qz,Yv,Wz,Zz,Ki,Rc,Kz,Xz,e2,zv,t2,iA,r2,Yn=y(()=>{"use strict";Zi();Ev();Lf();Mf();Pf();Fv();nA();Uz={channel:"chrome",hostMap:[],acceptInvalidCertificates:!1,allowedHosts:[],maskSelectors:[],videoRecording:{enabled:!1,mode:"disabled",width:1280,height:720,retentionDays:30},device:"desktop"},_z=A((e,t)=>t.startsWith("*.")?e.endsWith(t.slice(1)):e===t,"hostMatches"),Sc={width:960,height:540},Tz=A((e,t)=>{if(t||e.width*e.height<=Sc.width*Sc.height)return{width:e.width,height:e.height};let n=Math.min(Sc.width/e.width,Sc.height/e.height),i=A(r=>Math.max(2,Math.round(r*n/2)*2),"even");return{width:i(e.width),height:i(e.height)}},"laptopVideo"),Lz=A((e,t)=>{let n;try{n=new URL(e)}catch{return!1}return n.protocol==="about:"||n.protocol==="data:"?!0:n.protocol!=="http:"&&n.protocol!=="https:"?!1:t.some(i=>_z(n.hostname,i))},"siteAllowed"),Or=new Map,Mz=3e4,Pz=A(async e=>{let t=JSON.stringify(e),n=Or.get(t),i=n&&await n.browser.then(r=>r.isConnected()).catch(()=>!1);if(!n||!i){let r=$z.launch(e);n={browser:r,users:0},Or.set(t,n);let o=n;r.then(s=>s.on("disconnected",()=>{Or.get(t)===o&&Or.delete(t)})).catch(()=>Or.delete(t))}return clearTimeout(n.idle),n.users++,n.browser},"sharedBrowser"),Ov=A(async e=>{for(let[t,n]of Or)if(await n.browser.catch(()=>{})===e){n.users=Math.max(0,n.users-1),n.users===0&&(n.idle=setTimeout(()=>{Or.delete(t),e.close().catch(()=>{})},Mz),n.idle.unref());return}await e.close()},"releaseBrowser"),Jv=A(async()=>{let e=[...Or.values()];Or.clear(),await Promise.all(e.map(async t=>{clearTimeout(t.idle),await(await t.browser.catch(()=>{}))?.close().catch(()=>{})}))},"closeIdleBrowsers"),zz={mobile:"iPhone 15",tablet:"iPad Pro 11"},Xi=A(async({channel:e,hostMap:t,acceptInvalidCertificates:n,allowedHosts:i,maskSelectors:r=[],videoRecording:o,device:s="desktop"}=Uz,a,c)=>{let u=[...i,...a?[new URL(a).hostname]:[]],l=(Ke()?[]:t).map(({host:x,address:_})=>`MAP ${x} ${_}`).join(", "),d=await Pz({channel:Ke()?"chromium":e,headless:process.env.QADET_HEADLESS==="1",args:l?[`--host-resolver-rules=${l}`]:[]}),g=s==="desktop"?void 0:Fz[zz[s]],h=g?.viewport??Tz(o,Ke()),p,m,E,I=A(async x=>{let _=await d.newContext({...g,ignoreHTTPSErrors:n,storageState:c,...x&&p&&{recordVideo:{dir:p,size:h}}});return E=_,Ke()&&await Cv(_),await Nv(_,r),await gv(_),await $v(_),await Iv(_),await Vz(_),{context:_,page:await _.newPage()}},"prepared"),Q;if(o.enabled&&o.mode!=="disabled")try{let x=Rz(".qadet/video-recordings");await Sz(x,{recursive:!0}),p=await xz(Nz(x,"execution-")),Q=await I(!0)}catch(x){m=kv(x)?vv:x instanceof Error?x.message:String(x),await E?.close().catch(()=>{})}let{context:D,page:k}=Q??await I(!1).catch(async x=>{throw await Ov(d).catch(()=>{}),x});Lv(k);let U=k.video();return await k.route("**/*",x=>{let _=x.request();return _.isNavigationRequest()&&_.frame()===k.mainFrame()&&!Lz(_.url(),u)?x.abort("blockedbyclient"):x.fallback()}),k.on("filechooser",()=>{}),Jz(k),Oz(k),k.setDefaultTimeout(2e4),k.setDefaultNavigationTimeout(45e3),{browser:d,context:D,page:k,video:U,recordingDirectory:p,recordingError:m,videoSize:h}},"openBrowser"),xc=new WeakMap,Oz=A(e=>e.context().on("page",async t=>{if(await t.opener().catch(()=>null)!==e)return;await t.waitForLoadState("domcontentloaded").catch(()=>{});let n=t.url();await t.close().catch(()=>{}),n&&n!=="about:blank"&&await e.goto(n).catch(()=>{})}),"followNewTabsOn"),Jz=A(e=>e.on("dialog",async t=>{let n=`[${t.type()} dialog: "${t.message()}"]`,i=xc.get(e);xc.delete(e),i&&!i.accept?await t.dismiss().catch(()=>{}):await t.accept(t.type()==="prompt"?i?.text??t.defaultValue():void 0).catch(()=>{}),await e.evaluate(r=>{globalThis.__qadetAnnounced?.push({text:r,at:Date.now()})},n).catch(()=>{})}),"acceptDialogsOn"),eo=A(async({browser:e,context:t,video:n})=>{let i,r;try{await t.close(),i=await n?.path()}catch(o){r=o}try{await Ov(e)}catch(o){r??=o}return{videoPath:i,closeError:r}},"closeBrowser"),Gz=A(e=>e.locator(":user-invalid").evaluateAll(t=>t.map(n=>{let i=n;return{label:(i.labels?.[0]?.innerText||i.getAttribute("aria-label")||i.name).trim(),message:i.validationMessage}})).catch(()=>[]),"browserValidation"),Gv=`(() => {
103
+ })()`,$v=A(e=>e.addInitScript({content:bz}),"keepRunsToOneTab")});var Uv,cn,_v,Dc=y(()=>{"use strict";Uv=/^(?:[0-7][0-9A-HJKMNP-TV-Z]{25}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{24}|\d{5,})$/i,cn=A((e,t)=>{let[n="",i]=_v(e),[r="",o]=_v(t);if(i!==void 0){let E=i.replace(/^!/,""),I=(o??"").replace(/^!/,"");return(n.split("?")[0]??"").replace(/\/+$/,"")!==""&&!cn(n,r)?!1:E.startsWith("/")&&I.startsWith("/")?cn(E,I):E===I}let[s="",a]=n.split("?"),[c="",u]=r.split("?"),l=s.split("/").filter(Boolean),d=c.split("/").filter(Boolean);if(l.length===0?d.length!==0:l.length>d.length)return!1;let g=d.length-l.length;if(!l.every((E,I)=>E==="*"||E===d[g+I]||Uv.test(E)&&Uv.test(d[g+I]??"")))return!1;if(!a)return!0;let p=new URLSearchParams(a),m=new URLSearchParams(u||"");for(let[E,I]of p.entries())if(m.get(E)!==I)return!1;return!0},"pathMatches"),_v=A(e=>{let t=e.indexOf("#");return t===-1?[e,void 0]:[e.slice(0,t),e.slice(t+1)]},"splitHash")});var vz,Tv,zf,Lv,Mv,kz,Dz,Pv,Of,nA=y(()=>{"use strict";Zi();Dc();vz=300,Tv=new WeakMap,zf=new WeakMap,Lv=A(e=>{let t=[];Tv.set(e,t);let n=new Map;zf.set(e,n),e.on("request",i=>{["fetch","xhr"].includes(i.resourceType())&&n.set(i,Date.now())}),e.on("requestfinished",i=>n.delete(i)),e.on("requestfailed",i=>n.delete(i)),e.on("response",i=>{let r=i.request();if(!["fetch","xhr","document"].includes(r.resourceType()))return;let o=new URL(i.url());t.push({method:r.method(),path:`${o.pathname}${o.search}`,status:i.status(),at:Date.now()}),t.length>vz&&t.shift()})},"watchRequests"),Mv=A(async(e,t=5e3)=>{let n=zf.get(e);if(!n)return;let i=Uf(e),r=Date.now()+t;for(;[...n.values()].some(o=>o>=i)&&Date.now()<r;)await e.waitForTimeout(100).catch(()=>{})},"requestsSettled"),kz=A(e=>e>=200&&e<400,"succeeded"),Dz=A(({method:e,path:t,status:n})=>`${e} ${t} answered ${n}`,"describe"),Pv=A(async(e,t,n,i,r=1e4)=>{let o=t.toUpperCase(),s=Uf(e),a=A(()=>(Tv.get(e)??[]).filter(l=>l.at>=s&&l.method===o&&cn(n,l.path)),"sent"),c=Date.now()+r;do{if(a().find(d=>i===void 0?kz(d.status):d.status===i))return{passed:!0};await e.waitForTimeout(250).catch(()=>{})}while(Date.now()<c);let u=a().at(-1);return{passed:!1,reason:u?`${Dz(u)}, not ${i??"a success"}`:`No ${o} ${n} was sent since the last step`}},"requestAnswered"),Of=A(e=>{let t=zf.get(e);if(!t)return!1;let n=Date.now()-1e4;return[...t.values()].some(i=>i>=n)},"requestsPending")});import{mkdir as Sz,mkdtemp as xz}from"node:fs/promises";import{join as Nz,resolve as Rz}from"node:path";import{chromium as $z,devices as Fz}from"playwright-core";var Uz,_z,Sc,Tz,Lz,Or,Mz,Pz,Ov,Jv,zz,Xi,xc,Oz,Jz,eo,Gz,Gv,Vz,Yz,Nc,Vv,Hz,jz,qz,Yv,Wz,Zz,Ki,Rc,Kz,Xz,e2,zv,t2,iA,r2,Yn=y(()=>{"use strict";Zi();Ev();Lf();Mf();Pf();Fv();nA();Uz={channel:"chrome",hostMap:[],acceptInvalidCertificates:!1,allowedHosts:[],maskSelectors:[],videoRecording:{enabled:!1,mode:"disabled",width:1280,height:720,retentionDays:30},device:"desktop"},_z=A((e,t)=>t.startsWith("*.")?e.endsWith(t.slice(1)):e===t,"hostMatches"),Sc={width:960,height:540},Tz=A((e,t)=>{if(t||e.width*e.height<=Sc.width*Sc.height)return{width:e.width,height:e.height};let n=Math.min(Sc.width/e.width,Sc.height/e.height),i=A(r=>Math.max(2,Math.round(r*n/2)*2),"even");return{width:i(e.width),height:i(e.height)}},"laptopVideo"),Lz=A((e,t)=>{let n;try{n=new URL(e)}catch{return!1}return n.protocol==="about:"||n.protocol==="data:"?!0:n.protocol!=="http:"&&n.protocol!=="https:"?!1:t.some(i=>_z(n.hostname,i))},"siteAllowed"),Or=new Map,Mz=3e4,Pz=A(async e=>{let t=JSON.stringify(e),n=Or.get(t),i=n&&await n.browser.then(r=>r.isConnected()).catch(()=>!1);if(!n||!i){let r=$z.launch(e);n={browser:r,users:0},Or.set(t,n);let o=n;r.then(s=>s.on("disconnected",()=>{Or.get(t)===o&&Or.delete(t)})).catch(()=>Or.delete(t))}return clearTimeout(n.idle),n.users++,n.browser},"sharedBrowser"),Ov=A(async e=>{for(let[t,n]of Or)if(await n.browser.catch(()=>{})===e){n.users=Math.max(0,n.users-1),n.users===0&&(n.idle=setTimeout(()=>{Or.delete(t),e.close().catch(()=>{})},Mz),n.idle.unref());return}await e.close()},"releaseBrowser"),Jv=A(async()=>{let e=[...Or.values()];Or.clear(),await Promise.all(e.map(async t=>{clearTimeout(t.idle),await(await t.browser.catch(()=>{}))?.close().catch(()=>{})}))},"closeIdleBrowsers"),zz={mobile:"iPhone 15",tablet:"iPad Pro 11"},Xi=A(async({channel:e,hostMap:t,acceptInvalidCertificates:n,allowedHosts:i,maskSelectors:r=[],videoRecording:o,device:s="desktop"}=Uz,a,c)=>{let u=[...i,...a?[new URL(a).hostname]:[]],l=(Ke()?[]:t).map(({host:x,address:_})=>`MAP ${x} ${_}`).join(", "),d=await Pz({channel:Ke()?"chromium":e,headless:process.env.QADET_HEADLESS==="1",args:l?[`--host-resolver-rules=${l}`]:[]}),g=s==="desktop"?void 0:Fz[zz[s]],h=g?.viewport??Tz(o,Ke()),p,m,E,I=A(async x=>{let _=await d.newContext({...g,ignoreHTTPSErrors:n,storageState:c,...x&&p&&{recordVideo:{dir:p,size:h}}});return E=_,Ke()&&await Cv(_),await Nv(_,r),await gv(_),await $v(_),await Iv(_),await Vz(_),{context:_,page:await _.newPage()}},"prepared"),Q;if(o.enabled&&o.mode!=="disabled")try{let x=Rz(".qadet/video-recordings");await Sz(x,{recursive:!0}),p=await xz(Nz(x,"execution-")),Q=await I(!0)}catch(x){m=kv(x)?vv:x instanceof Error?x.message:String(x),await E?.close().catch(()=>{})}let{context:D,page:k}=Q??await I(!1).catch(async x=>{throw await Ov(d).catch(()=>{}),x});Lv(k);let U=k.video();return await k.route("**/*",x=>{let _=x.request();return _.isNavigationRequest()&&_.frame()===k.mainFrame()&&!Lz(_.url(),u)?x.abort("blockedbyclient"):x.fallback()}),k.on("filechooser",()=>{}),Jz(k),Oz(k),k.setDefaultTimeout(2e4),k.setDefaultNavigationTimeout(45e3),{browser:d,context:D,page:k,video:U,recordingDirectory:p,recordingError:m,videoSize:h}},"openBrowser"),xc=new WeakMap,Oz=A(e=>e.context().on("page",async t=>{if(await t.opener().catch(()=>null)!==e)return;await t.waitForLoadState("domcontentloaded").catch(()=>{}),t.url()==="about:blank"&&await t.waitForURL(r=>r.href!=="about:blank",{timeout:2e3}).catch(()=>{});let n=t.url(),i=n==="about:blank"?await t.evaluate(()=>{let r=globalThis.document;return r.body?.innerText.trim()?r.documentElement.outerHTML:""}).catch(()=>""):"";await t.close().catch(()=>{}),n&&n!=="about:blank"?await e.goto(n).catch(()=>{}):i&&await e.setContent(i).catch(()=>{})}),"followNewTabsOn"),Jz=A(e=>e.on("dialog",async t=>{let n=`[${t.type()} dialog: "${t.message()}"]`,i=xc.get(e);xc.delete(e),i&&!i.accept?await t.dismiss().catch(()=>{}):await t.accept(t.type()==="prompt"?i?.text??t.defaultValue():void 0).catch(()=>{}),await e.evaluate(r=>{globalThis.__qadetAnnounced?.push({text:r,at:Date.now()})},n).catch(()=>{})}),"acceptDialogsOn"),eo=A(async({browser:e,context:t,video:n})=>{let i,r;try{await t.close(),i=await n?.path()}catch(o){r=o}try{await Ov(e)}catch(o){r??=o}return{videoPath:i,closeError:r}},"closeBrowser"),Gz=A(e=>e.locator(":user-invalid").evaluateAll(t=>t.map(n=>{let i=n;return{label:(i.labels?.[0]?.innerText||i.getAttribute("aria-label")||i.name).trim(),message:i.validationMessage}})).catch(()=>[]),"browserValidation"),Gv=`(() => {
104
104
  const enhance = () => {
105
105
  // 1. Canvas elements
106
106
  document.querySelectorAll('canvas').forEach((c, i) => {
@@ -292,7 +292,7 @@ ${s}
292
292
  return Date.now() - window.__qadetLastChange
293
293
  })()`,HV=A(async e=>{if(Of(e))return!0;let t=await e.evaluate(YV).catch(()=>0);return typeof t!="number"||t<500},"busy"),Vx=A(async(e,t,n=Date.now)=>{let i=e.locator(t).first(),r=n(),o;for(;n()-r<VV;){if(await i.isVisible().catch(()=>!1))return!0;if(await HV(e)?o=void 0:o??=n(),o!==void 0&&n()-o>=GV)return!1;await e.waitForTimeout(150).catch(()=>{})}return!1},"targetReady")});var jV,qV,od,WV,GC,ZV,Hx,KV,fa,jx,sd,qx,Wx=y(()=>{"use strict";jV=[/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi,/\b[0-9a-f]{8}-(?:[0-9a-f]{4}-){1,3}(?:[0-9a-f]{1,12})?/gi,/ \(\d+\)/g,/\bSelect row \d+\b/gi,/\b[A-Z]{1,5}-\d{3,}\b/g,/\b(?=[A-Z0-9]*[A-Z])[A-Z0-9]{4,6}-[A-Z0-9]{4,6}\b/g,/#\d+\b/g,/\b\d{1,4}[/.-]\d{1,2}[/.-]\d{1,4}\b/g,/\b\d{1,2}\s+(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?(?:\s+\d{2,4})?\b/gi,/\b\d{1,2}:\d{2}:\d{2}\s*(?:am|pm)?\b/gi,/\b(?:just now|\d+\s+(?:seconds?|minutes?|hours?|days?) ago|yesterday|today)\b/gi,/\b(?=[a-z]*\d)(?=\d*[a-z])[a-z0-9]{6}\b/g],qV=/\b\d{1,2}:\d{2}\s*(?:am|pm)?\b/gi,od=/\[name="((?:[^"\\]|\\.)*)"i\]/,WV=/name: '((?:[^'\\]|\\.)*)'/,GC=/\{\{[A-Za-z_][A-Za-z0-9_]*\}\}/g,ZV=A(e=>String.fromCharCode(57344+e),"KEPT"),Hx=/[\ue000-\uf8ff]/,KV=A((e,t)=>{let n=[],i=A(c=>(n.push(c),ZV(n.length-1)),"hold"),r=e.replace(GC,i);t&&!GC.test(t)&&(r=r.replaceAll(t,()=>i(t))),GC.lastIndex=0;let o=r;for(let c of jV)o=o.replace(c,"\0");if(o.includes("\0")&&(o=o.replace(qV,"\0")),o===r)return;let s=o.split("\0").map(c=>c.replace(/^[\s\p{P}]+|[\s\p{P}]+$/gu,"")).filter(c=>c.replace(/[\ue000-\uf8ff]/g,"").length>=3||Hx.test(c));return(s.find(c=>Hx.test(c))??s[0])?.replace(/[\ue000-\uf8ff]/g,c=>n[c.charCodeAt(0)-57344]??"")},"stableName"),fa=/\.([A-Za-z][\w-]*?__)[A-Za-z0-9_-]{5}(?![\w-])/g,jx=A((e,t)=>{fa.test(e.selector)&&(fa.lastIndex=0,e={selector:e.selector.replace(fa,'[class*="$1"]'),code:e.code.replace(fa,'[class*="$1"]')}),fa.lastIndex=0;let n=e.selector.replace(/internal:label="Select row \d+"i/g,'internal:label="Select row"i'),i=e.code.replace(/\.getByLabel\('Select row \d+'\)/g,".getByLabel('Select row')"),r=n.match(od)?.[1],o=r&&KV(r.replace(/\\"/g,'"'),t);return o?{selector:n.replace(od,`[name=${JSON.stringify(o)}i]`),code:i.replace(WV,`name: '${o.replace(/'/g,"\\'")}'`)}:n===e.selector&&i===e.code?e:{selector:n,code:i}},"stableTarget"),sd=A(e=>od.test(e)?e.replace(od,'[name="$1"s]'):void 0,"exactName"),qx=A((e,t,n)=>t===0?{selector:`${e.selector} >> nth=0`,code:`${e.code}.first()`}:t===n-1?{selector:`${e.selector} >> nth=-1`,code:`${e.code}.last()`}:{selector:`${e.selector} >> nth=${t}`,code:`${e.code}.nth(${t})`},"nthTarget")});var XV,eY,tY,Zx,rY,Kx,jr,Xx,nY,VC,Ad,iY,oY,sY,AY,aY,cY,eN,uY,lY,YC=y(()=>{"use strict";$x();Yn();nd();_x();Lx();OC();Ox();Pf();Dc();Gx();nA();Yx();qn();bn();Wx();XV=10*1024*1024,eY={ctrl:"Control",control:"Control",cmd:"Meta",command:"Meta",meta:"Meta",win:"Meta",alt:"Alt",option:"Alt",shift:"Shift",esc:"Escape",escape:"Escape",return:"Enter",enter:"Enter",del:"Delete",space:"Space"},tY=A(e=>e.split("+").map(t=>t.trim()).map(t=>eY[t.toLowerCase()]??t).join("+"),"keyName"),Zx=A(async(e,t)=>{let n=await e.evaluate(i=>i.maxLength??-1).catch(()=>-1);if(n>0&&n<=2&&t.length>n){await e.click(),await e.page().keyboard.type(t,{delay:30});return}try{await e.fill(t)}catch(i){if(!/is not an <input>/.test(String(i)))throw i;let r=e.locator('input:not([type=hidden]), textarea, [contenteditable=""], [contenteditable="true"]').first();if(await r.count()===0)throw i;await r.fill(t)}},"fillField"),rY=A(async(e,t)=>{let n=A(o=>e.locator(o).count().catch(()=>0),"count");if(await n(t)<=1)return t;let i=t.replace(/(\[name="[^"]*")i\]/g,"$1s]");if(i!==t&&await n(i)===1)return i;let r=`${t} >> visible=true`;return await n(r)===1?r:t},"oneMatch"),Kx=new Set(["click","double_click","hover","fill","fillSecret","select"]),jr=A(async(e,t,{secrets:n,inbox:i,readDocument:r,fetchFixture:o})=>{let s=n.expandStep(t),a="target"in s&&s.target&&Kx.has(s.action)?{...s,target:{...s.target,selector:await rY(e,s.target.selector)}}:s;if("target"in a&&a.target&&iY.has(a.action)){await Ux(e,a.target.selector);let c=JC(a.target.selector);c&&await e.locator(a.target.selector).count().catch(()=>0)===0&&await e.locator(c).filter({visible:!0}).count().catch(()=>0)===1&&(a={...a,target:{...a.target,selector:`${c} >> visible=true`}})}if("target"in a&&a.target&&Kx.has(a.action)){let c=e.locator(a.target.selector);if(!await Vx(e,a.target.selector)&&await c.count().catch(()=>0)===0)throw new Error(`${a.target.code}: the page settled without it (nothing on the page matches it)`)}switch(a.action){case"click":return oY(e,a.target.selector);case"double_click":return sY(e,a.target.selector);case"hover":return AY(e,a.target.selector);case"drag":{let c=e.locator(a.from.selector),u=e.locator(a.to.selector),l=await c.boundingBox(),d=await u.boundingBox();if(l&&d){let g=l.x+l.width/2,h=l.y+l.height/2,p=d.x+d.width/2,m=d.y+d.height/2;return await e.mouse.move(g,h),await e.mouse.down(),await e.mouse.move(p,m,{steps:10}),e.mouse.up()}return c.dragTo(u)}case"draw":{let u=await e.locator(a.target.selector).boundingBox();if(!u)throw new Error(`${a.target.code} is not visible to draw on`);let l=a.points[0];if(!l)throw new Error("At least 2 points are required to draw.");await e.mouse.move(u.x+l.x,u.y+l.y),await e.mouse.down();for(let d=1;d<a.points.length;d++){let g=a.points[d];g&&await e.mouse.move(u.x+g.x,u.y+g.y,{steps:5})}return e.mouse.up()}case"remember":{let c=await Jx(e.locator(a.target.selector)).catch(u=>{let l=n.typedInto(a.target.selector);if(l!==void 0&&/password/i.test(u.message))return l;throw u});return n.remember(a.name,c)}case"rememberValue":return n.remember(a.name,n.expand(a.value));case"fill":{let c=n.expand(a.value);return n.noteTyped(a.target.selector,c),Zx(e.locator(a.target.selector),c)}case"fillSecret":{let c=e.locator(a.target.selector);return await Zx(c,n.value(a.secret)),Rv(c)}case"uploadCsv":{let c=Tx(a.fileName,n.expand(a.content)),u=e.locator(a.target.selector),d=await u.evaluate(g=>g.matches('input[type="file"]'))?u:u.locator('input[type="file"]');if(await d.count()!==1)throw new Error("The saved upload target no longer identifies one file input.");return d.setInputFiles({name:c.fileName,mimeType:"text/csv",buffer:Buffer.from(c.content,"utf8")})}case"uploadFile":{let c;if(a.fixtureId!==void 0){if(!o)throw new Error("Project fixtures cannot be loaded for this replay.");if(c=await o(a.fixtureId),c.content.byteLength>XV)throw new Error("Project fixtures cannot exceed 10 MB.")}else c={content:zx(a.fileName,n.expand(a.content??""),a.sizeBytes),fileName:a.fileName,mimeType:a.mimeType};let u=e.locator(a.target.selector),d=await u.evaluate(g=>g.matches('input[type="file"]'))?u:u.locator('input[type="file"]');if(await d.count()!==1)throw new Error("The saved upload target no longer identifies one file input.");return d.setInputFiles({name:c.fileName,mimeType:c.mimeType,buffer:c.content})}case"select":return eN(e,a.target.selector,n.expand(a.option));case"selectMany":return cY(e,a.target.selector,a.options.map(c=>n.expand(c)));case"answerDialog":xc.set(e,{accept:a.accept,text:a.text===void 0?void 0:n.expand(a.text)});return;case"press":return e.keyboard.press(tY(a.key));case"navigate":return e.goto(n.expand(a.url));case"expectText":if(!await ed(e,n.expand(a.text),a.within&&{...a.within,containing:n.expand(a.within.containing)},a.exact,a.wait?a.wait*1e3:void 0))throw new Error(`"${a.text}" is not${Xl(a.within)||" on the page"}`);return;case"expectNoText":{let c=n.expand(a.text);if(c!==c.trim()&&c.trim()){if(await e.evaluate(l=>(globalThis.document.body?.textContent??"").includes(l),c))throw new Error(`"${a.text}" is still on the page`);return}if(!await Cx(e,n.expand(a.text),a.within&&{...a.within,containing:n.expand(a.within.containing)},a.exact,a.wait?a.wait*1e3:void 0))throw new Error(`"${a.text}" is still${Xl(a.within)||" on the page"}`);return}case"expectPath":try{await e.waitForURL(c=>cn(a.path,zC(c)))}catch{throw new Error(`Expected to be on ${a.path} but was on ${rd(e)}`)}return;case"expectRequest":{let c=await Pv(e,a.method,n.expand(a.path),a.responseStatus);if(!c.passed)throw new Error(c.reason);return}case"followEmailLink":{if(!i)throw new Error("This project has no test inbox, so the email link can not be found");let c=await i.link(n.expand(a.to),a.subject&&n.expand(a.subject),a.linkText);return await e.context().clearCookies(),e.goto(c.url)}case"expectVisible":if(!await kx(e,a.target.selector))throw new Error(`${a.target.code} is not visible`);return;case"expectHidden":if(!await Dx(e,a.target.selector))throw new Error(`${a.target.code} is still shown`);return;case"expectEnabled":if(!await Sx(e,a.target.selector,a.enabled))throw new Error(`${a.target.code} is ${a.enabled?"disabled":"enabled"}`);return;case"expectCount":{let c=a.within&&{...a.within,containing:n.expand(a.within.containing)};if(!await yx(e,n.expand(a.text),a.count,c,a.exact))throw new Error(`"${n.expand(a.text)}" does not show ${a.count} times${Xl(c)}`);return}case"expectMedia":if(!await wx(e,a.target.selector,a.state))throw new Error(`${a.target.code} is not ${a.state}`);return;case"expectOrder":{let c=a.texts.map(u=>n.expand(u));if(!await Bx(e,c))throw new Error(`${c.map(u=>`"${u}"`).join(", ")} are not shown in this order`);return}case"expectValue":if(!await xx(e,a.target.selector,n.expand(a.value)))throw new Error(`${a.target.code} does not hold "${n.expand(a.value)}"`);return;case"expectChecked":if(!await Nx(e,a.target.selector,a.checked))throw new Error(`${a.target.code} is not ${a.checked?"on":"off"}`);return;case"expectInvalid":if(!await Rx(e,a.target.selector))throw new Error(`${a.target.code} was accepted, not refused`);return;case"expectDownload":{let{name:c,text:u}=await id(e,a.target.selector,r);if(!u.toLowerCase().includes(n.expand(a.text).toLowerCase()))throw new Error(`${c} does not contain "${a.text}"`)}}},"runStep"),Xx=A(async(e,t,n)=>{try{await jr(e,t,n),kr(t)||await td(e)}catch(i){if(kr(t))throw i;await e.waitForLoadState("load").catch(()=>{}),await e.waitForTimeout(1e3),"target"in t&&await VC(e,t.target.selector);let r="target"in t?await lY(e,t.target):void 0;await jr(e,r?{...t,target:r}:t,n).catch(()=>{throw i})}},"runStepSettled"),nY=120,VC=A(async(e,t)=>{let n=A(()=>e.locator(t).count().catch(()=>0),"found");if(await n()>0)return;let i=await e.locator("*").evaluateAll(r=>r.map((o,s)=>({element:o,index:s})).filter(({element:o})=>{let s=globalThis.getComputedStyle(o);return/(auto|scroll)/.test(s.overflowY)&&o.scrollHeight>o.clientHeight+20}).map(({index:o})=>o)).catch(()=>[]);for(let r of i.slice(0,5)){let o=e.locator("*").nth(r);await o.evaluate(s=>{s.scrollTop=0});for(let s=0;s<nY;s++){let a=await o.evaluate(c=>(c.scrollTop+=c.clientHeight*.8,c.dispatchEvent(new Event("scroll")),c.scrollTop+c.clientHeight>=c.scrollHeight-1));if(await e.waitForTimeout(30),await n()>0)return;if(a)break}}},"scrollUntilShown"),Ad=A(e=>{let t=jx(e,Pc);return t===e||t.selector.includes(" >> nth=")||/\{\{[A-Za-z_][A-Za-z0-9_]*\}\}/.test(t.selector)?t:qx(t,0,2)},"savedTarget"),iY=new Set(["click","double_click","hover"]),oY=A(async(e,t)=>{let n=e.locator(t);if(await n.count()<=1)return Dr(n,a=>a.click());let r=sd(t);if(r&&await e.locator(r).count()===1)return Dr(e.locator(r),a=>a.click());let o=await n.evaluateAll(a=>a.map(c=>c.href??null)),s=o.every(a=>a&&a===o[0]);return Dr(s?n.first():n,a=>a.click())},"clickTarget"),sY=A(async(e,t)=>{let n=e.locator(t);if(await n.count()<=1)return Dr(n,o=>o.dblclick());let r=sd(t);return r&&await e.locator(r).count()===1?Dr(e.locator(r),o=>o.dblclick()):Dr(n.first(),o=>o.dblclick())},"doubleClickTarget"),AY=A(async(e,t)=>{let n=e.locator(t);if(await n.count()<=1)return Dr(n,o=>o.hover());let r=sd(t);return r&&await e.locator(r).count()===1?Dr(e.locator(r),o=>o.hover()):Dr(n.first(),o=>o.hover())},"hoverTarget"),aY='[role="listbox"]:visible, .ant-select-dropdown:visible, .MuiPopover-root:visible, .MuiMenu-list:visible, [class*="dropdown" i]:visible, [class*="menu" i]:visible',cY=A(async(e,t,n)=>{let i=e.locator(t);if(await i.evaluate(o=>o.tagName==="SELECT").catch(()=>!1))return i.selectOption(n.map(o=>({label:o})));for(let o of n)await eN(e,t,o)},"selectOptions"),eN=A(async(e,t,n)=>{let i=e.locator(t);if(await i.evaluate(c=>c.tagName==="SELECT").catch(()=>!1))return i.selectOption(n);await i.click();let o=e.getByRole("option",{name:n,exact:!0}).filter({visible:!0}),s=e.locator(aY).getByText(n,{exact:!0}).filter({visible:!0}),a=o.or(s).first();await a.waitFor({state:"visible",timeout:5e3}).catch(()=>{throw new Error(`The dropdown opened, but no option "${n}" showed`)}),await a.click()},"selectOption"),uY=[["sign in","log in","login","signin"],["sign up","register","create account","signup"],["sign out","log out","logout","signout"]],lY=A(async(e,t)=>{let n=t.selector.match(/^internal:role=(button|link)\[name="([^"]+)"i\]$/);if(!n||await e.locator(t.selector).count().catch(()=>0)>0)return;let[,i,r=""]=n,o=uY.find(s=>s.includes(r.toLowerCase()));for(let s of o??[]){if(s===r.toLowerCase())continue;let a=`internal:role=${i}[name=${JSON.stringify(s)}i]`;if(await e.locator(a).count().catch(()=>0)===1)return{selector:a,code:`getByRole('${i}', { name: '${s}' })`}}},"sameWordsTarget")});var dY,gY,fY,Zo,HC=y(()=>{"use strict";Zi();Yn();nd();OC();_c();io();Dc();nA();_C();bn();Br();YC();dY=new Set(["click","double_click","hover","drag","draw","navigate"]),gY=A(e=>{switch(e.type){case"view":case"whole_page":case"locate":case"count":return!0;case"probe":return e.step.action!=="expectDownload";case"play":return!e.record&&(e.step.action==="click"||e.step.action==="press"&&e.step.key==="Escape");default:return!1}},"repairMay"),fY=/^qadet-target-\d+$/,Zo=class{constructor(t,n,i,r){this.page=t;this.context=n;this.findings=i;this.recorder=r;t.on("filechooser",()=>{this.filePickerOpened=!0})}page;context;findings;recorder;static{A(this,"PageHost")}steps=[];positions=[];recorded=0;toldFindings=0;cancelled=!1;filePickerOpened=!1;handles=new Map;real(t){return this.handles.size?JSON.parse(JSON.stringify(t),(n,i)=>i&&typeof i=="object"&&fY.test(i.selector??"")?{...i,...this.handles.get(i.selector)}:i):t}shown(t){let n=new Map([...this.handles].map(([i,r])=>[r.selector,i]));return this.secrets.redactAll(n.size?JSON.parse(JSON.stringify(t),(i,r)=>{let o=r&&typeof r=="object"&&n.get(r.selector);return o?{...r,selector:o,code:this.secrets.redact(r.code)}:r}):t)}selector(t){return this.secrets.expand(this.handles.get(t)?.selector??t)}get secrets(){return this.context.secrets}handle(t){if(!this.recorder&&!gY(t))return Promise.reject(new Error("A repair may only look at the page, click or press Escape"));switch(t.type){case"view":return this.view(!0);case"whole_page":return t.find?VC(this.page,`internal:text=${JSON.stringify(t.find)}i`).then(()=>this.view(!1)):this.view(!1);case"locate":return this.locate(t.ref);case"count":return this.count(t.selector,t.element);case"play":return this.play(this.real(t.step),t.record);case"probe":return this.probe(this.real(t.step));case"record":return this.recordStep(this.real(t.step),t.status,t.error);case"read":return this.read(t);case"drop":return this.drop(t.from,t.reason);default:return}}async view(t){let n=await Nc(this.page),i=this.findings.slice(this.toldFindings).map(({kind:r,message:o})=>({kind:r,message:o}));return t&&(this.toldFindings=this.findings.length),this.secrets.redactAll({...n,problems:t?i:[]})}async locate(t){let{target:n,locator:i}=await Yv(this.page,t),r=await i.evaluate(a=>({tag:a.tagName.toLowerCase(),fileInput:a.matches('input[type="file"]'),role:a.getAttribute("role")??void 0,name:a.getAttribute("aria-label")??void 0})),o=this.secrets.tokenizeStep(n),s=this.secrets.redactAll(o);if(JSON.stringify(s)!==JSON.stringify(o)){let a=`qadet-target-${this.handles.size+1}`;return this.handles.set(a,o),this.secrets.redactAll({target:{selector:a,code:s.code},...r})}return this.secrets.redactAll({target:o,...r})}async count(t,n){let i=this.page.locator(this.selector(t)),r=await i.count();if(!n)return{count:r};let o=await this.page.locator(this.selector(n)).elementHandle({timeout:2e3}).catch(()=>null),s=o?await i.evaluateAll((a,c)=>a.indexOf(c),o):-1;return{count:r,index:s}}async play(t,n=!1){try{if(kr(t)||kc(this.page),Tc(this.page,this.recorded+1),this.filePickerOpened=!1,await this.notePlace(t),await jr(this.page,t,this.context),dY.has(t.action)&&(await Mv(this.page),await bx(this.page)),t.action==="click"&&this.filePickerOpened)return{filePicker:!0,error:"The click opened the system file picker"};await td(this.page);let i=this.secrets.tokenizeStep(t);if(!n)return{saved:this.shown(i)};let r=await this.save(i,"passed");return{saved:this.shown(i),position:r,view:await this.view(!0)}}catch(i){return i instanceof Ve?{cancelled:!0}:{error:this.secrets.redact(ze(i))}}}async probe(t){let n=this.secrets.tokenizeStep(t),i=this.secrets.missing([t]);if(i.length)return{saved:this.shown(n),passed:!1,detail:`{{${i.join("}}, {{")}}} has no value: nothing remembered it. Read the value off the page with remember_value first, or check the text itself.`};let r="within"in t&&t.within?{...t.within,containing:this.secrets.expand(t.within.containing)}:void 0;if(r&&!await vx(this.page,r))return{saved:this.shown(n),passed:!1,scopeMissing:!0};if(t.action==="expectPath")return{saved:this.shown(n),passed:cn(t.path,rd(this.page))};try{return await this.notePlace(t),await jr(this.page,t,this.context),{saved:this.shown(n),passed:!0}}catch(o){if(o instanceof Ve)throw o;let s=r&&t.action==="expectText"?await ed(this.page,this.secrets.expand(t.text),void 0,t.exact,1e3):void 0;return{saved:this.shown(n),passed:!1,detail:this.secrets.redact(ze(o)),elsewhere:s}}}async recordStep(t,n,i){try{let r=this.secrets.tokenizeStep(t),o=await this.save(r,n,i);return{saved:this.shown(r),position:o,view:await this.view(!0)}}catch(r){if(r instanceof Ve)return{cancelled:!0};throw r}}place={};async notePlace(t){this.recorder&&(this.place={startedMs:Date.now()-this.recorder.startedAt,box:await Zl(this.page,t,n=>this.secrets.expand(n))})}async save(t,n,i){let{recorder:r}=this;if(!r)throw new Error("This run saves no steps");let o=++this.recorded;this.steps.push(t),this.positions.push(o);let s=await sA(this.page,r.runDir,o,t.action,!0);return await this.reported(r.reporter.step({position:o,elapsedMs:Date.now()-r.startedAt,step:t,status:n,error:i&&this.secrets.redact(i),screenshot:s,url:this.page.url(),...this.place})),this.place={},o}async read(t){if(t.kind==="download"){if(!t.selector)throw new Error("Name what gives the file");let{name:r,text:o}=await id(this.page,this.selector(t.selector),this.context.readDocument);return this.secrets.redactAll({name:r,text:o})}let{inbox:n}=this.context;if(!n)throw new Error("This project has no test inbox, so emails can not be read");if(!t.to)throw new Error("Name the address the email was sent to");let i=await n.latest(this.secrets.expand(t.to),t.subject&&this.secrets.expand(t.subject));return this.secrets.redactAll({subject:i.subject,text:i.text,links:i.links.map(({text:r,url:o})=>({text:r,url:o}))})}async resume(t,n){for(let[i,r]of t.entries()){let o=await this.play("target"in r?{...r,target:Ad(r.target)}:r,!0);if(o.cancelled)return this.cancelled=!0,{intents:[],error:"The run was cancelled"};if(o.error||o.filePicker){let s=`step ${i+1} (${this.secrets.redact(r.intent)}) no longer replays: ${o.error??"it opened the file picker"}`;return this.positions.length&&await this.drop(this.positions[0]??1,`The saved progress ${s}`),await this.page.goto(n),{intents:[],error:s}}}return{intents:t.map(i=>this.secrets.redact(i.intent))}}async drop(t,n){let i=this.positions.findIndex(r=>r>=t);return!this.recorder||i===-1||t<1?!1:(this.steps.splice(i),this.positions.splice(i),await this.reported(this.recorder.reporter.dropSteps(t,n)),!0)}async reported(t){try{await t}catch(n){throw n instanceof Ve&&(this.cancelled=!0),n}}}});var rN,hY,nN,yt,jC,pY,tN,mY,iN,xae,Nae,Rae,$ae,Fae,Uae,IY,EY,oN,sN,AN,aN,_ae,ad=y(()=>{"use strict";jo();bn();rN=3,hY=["explore","repair","checkUpdate"],nN=f.object({url:f.string(),token:f.string()}),yt=f.string().min(1).max(64),jC=f.object({selector:f.string(),code:f.string()}),pY=f.object({cost:f.number().optional(),total_tokens:f.number().optional()}),tN=f.object({passed:f.boolean(),reason:f.string(),verdict:f.enum(["passed","failed","blocked","inconclusive"]).optional()}),mY=f.object({intent:f.string(),passed:f.boolean(),position:f.number().int()}),iN=f.object({url:f.string(),tree:f.string(),dialog:f.boolean(),validation:f.array(f.object({label:f.string(),message:f.string()})),gone:f.array(f.string()),spoken:f.array(f.string()),problems:f.array(f.object({kind:f.string(),message:f.string()}))}),xae=f.object({target:jC,tag:f.string(),fileInput:f.boolean(),role:f.string().optional(),name:f.string().optional()}),Nae=f.object({saved:Ar.optional(),view:iN.optional(),position:f.number().int().optional(),error:f.string().optional(),filePicker:f.boolean().optional(),cancelled:f.boolean().optional()}),Rae=f.object({saved:Ar,passed:f.boolean(),detail:f.string().optional(),scopeMissing:f.boolean().optional(),elsewhere:f.boolean().optional()}),$ae=f.object({position:f.number().int().optional(),view:iN.optional(),saved:Ar.optional(),cancelled:f.boolean().optional()}),Fae=f.object({subject:f.string(),text:f.string(),links:f.array(f.object({text:f.string(),url:f.string()}))}),Uae=f.object({name:f.string(),text:f.string()}),IY=f.object({kind:f.enum(["step","check"]),step:Ar,error:f.string(),feedback:f.string().optional()}),EY=jC.extend({intent:f.string()}),oN=f.object({total_tokens:f.number(),cost:f.number().optional()}),sN=f.object({target:jC.nullable(),opening:EY.optional(),reason:f.string(),automatic:f.boolean(),usage:oN}),AN=f.object({update:Ar.nullable(),was:f.string(),now:f.string(),reason:f.string(),automatic:f.boolean(),usage:oN}),aN=f.discriminatedUnion("type",[f.object({type:f.literal("view"),id:yt}),f.object({type:f.literal("whole_page"),id:yt,find:f.string().optional()}),f.object({type:f.literal("locate"),id:yt,ref:f.string()}),f.object({type:f.literal("count"),id:yt,selector:f.string(),element:f.string().optional()}),f.object({type:f.literal("play"),id:yt,step:Ar,record:f.boolean().optional()}),f.object({type:f.literal("probe"),id:yt,step:Ar}),f.object({type:f.literal("record"),id:yt,step:Ar,status:f.enum(["passed","failed"]),error:f.string().optional()}),f.object({type:f.literal("read"),id:yt,kind:f.enum(["email","download"]),to:f.string().optional(),subject:f.string().optional(),selector:f.string().optional()}),f.object({type:f.literal("drop"),id:yt,from:f.number().int(),reason:f.string()}),f.object({type:f.literal("reply"),id:yt,value:f.unknown()}),f.object({type:f.literal("error"),id:yt,message:f.string()}),f.object({type:f.literal("finish"),verdict:tN.optional(),checks:f.array(mY),suggestedPrompt:f.string().optional(),ownSignIn:f.boolean().optional(),leftBehind:f.array(f.string()),usage:pY,error:f.string().optional(),aiError:f.string().optional(),limited:f.boolean(),knowledgeUsed:f.array(f.string())}),f.object({type:f.literal("failed"),message:f.string()}),f.object({type:f.literal("decided"),verdict:tN})]),_ae=f.discriminatedUnion("type",[f.object({type:f.literal("start"),protocol:f.number().int(),runId:f.number().int().positive(),token:f.string().min(1).max(2048),job:f.enum(hY),resumed:f.array(f.string().max(500)).max(200).optional(),early:f.boolean().optional()}),f.object({type:f.literal("reply"),id:yt,value:f.unknown()}),f.object({type:f.literal("error"),id:yt,message:f.string().max(2e3)}),f.object({type:f.literal("ask"),id:yt,question:IY})])});var cd,cN=y(()=>{"use strict";qn();Br();cd=class{constructor(t,n,i){this.socket=t;this.schema=n;this.handle=i}socket;schema;handle;static{A(this,"Channel")}pending=new Map;next=0;closed;request(t,n=6e4){if(this.closed)return Promise.reject(this.closed);let i=String(++this.next);return new Promise((r,o)=>{let s=setTimeout(()=>{this.pending.delete(i),o(new Error(`No answer within ${n/1e3} s`))},n);this.pending.set(i,{resolve:r,reject:o,timer:s}),this.send({...t,id:i})})}send(t){this.closed||this.socket.send(JSON.stringify(t))}async receive(t){let n=(()=>{try{return this.schema.safeParse(JSON.parse(t))}catch{return}})();if(!n?.success){this.close(new Error("The other side sent a message this one does not understand")),this.socket.close(4008,"Unreadable message");return}let i=n.data;if(i.type==="reply"||i.type==="error"){let r=i.id===void 0?void 0:this.pending.get(i.id);if(!r)return;this.pending.delete(i.id),clearTimeout(r.timer),i.type==="reply"?r.resolve(i.value):r.reject(new Error(i.message));return}try{let r=await this.handle(i);i.id!==void 0&&this.send({type:"reply",id:i.id,value:r})}catch(r){i.id!==void 0&&this.send({type:"error",id:i.id,message:ot(ze(r))})}}close(t){if(!this.closed){this.closed=t;for(let{reject:n,timer:i}of this.pending.values())clearTimeout(i),n(t);this.pending.clear()}}}});var QY,CY,qC,uN,lN,BY,dN,gN,WC=y(()=>{"use strict";cN();Br();ad();QY=A(e=>`Qadet's agent service isn't reachable at ${e}`,"unreachable"),CY=A((e,t,n,i,r,o)=>{let s=new URL("run",e.url.endsWith("/")?e.url:`${e.url}/`),a=new WebSocket(s),c={send:A(g=>a.send(g),"send"),close:A((g,h)=>{try{let p=g===void 0||g===1e3||g>=3e3&&g<=4999?g:4e3;a.close(p,h)}catch{try{a.close()}catch{}}},"close")},u=new cd(c,aN,g=>g.type==="finish"||g.type==="failed"||g.type==="decided"?r(g):i.handle(g)),l=new Promise((g,h)=>{a.addEventListener("open",()=>{u.send({type:"start",protocol:rN,runId:t,token:e.token,job:n,...o?.length?{resumed:o}:{},...n==="explore"?{early:!0}:{}}),g()}),a.addEventListener("error",()=>h(new Error(QY(e.url))))});a.addEventListener("message",g=>{u.receive(String(g.data))});let d=new Promise(g=>a.addEventListener("close",()=>{u.close(new Error("Qadet's agent service closed the connection")),g()}));return{channel:u,opened:l,closed:d,close:A(()=>a.close(1e3,"Done"),"close")}},"connect"),qC=A(e=>({usage:{cost:0,total_tokens:0},error:e,limited:!1,knowledgeUsed:[],checks:[],leftBehind:[]}),"failed"),uN=A(async(e,t,n,i=lN,r,o)=>{let s,a;try{({closed:a}=await dN(e,t,"explore",n,c=>{if(c.type==="failed")s=qC(c.message);else if(c.type==="decided")o?.(c.verdict);else if(c.type==="finish"){let{type:u,...l}=c;s=l}},i,r))}catch(c){return qC(ze(c))}return await a,s??qC("Qadet's agent service stopped before the test had a verdict")},"exploreWithAgent"),lN=9e4,BY=3e3,dN=A(async(e,t,n,i,r,o=lN,s)=>{let a=Date.now()+o;for(;;){let c=CY(e,t,n,i,r,s);try{return await c.opened,c}catch(u){if(Date.now()>=a)throw u;await new Promise(l=>setTimeout(l,BY))}}},"connectWhenUp"),gN=A(async(e,t,n,i)=>{let r,{channel:o,close:s}=await dN(e,t,n,i,a=>{a.type==="failed"&&(r=a.message)});return{ask:A(async a=>{if(r)throw new Error(r);return o.request({type:"ask",question:a},24e4).catch(c=>{throw new Error(r??c.message)})},"ask"),close:s}},"adviserFor")});var ud,ZC=y(()=>{"use strict";Br();ud=A(e=>{let t=Promise.resolve(),n,i=A(async()=>{if(await t,n instanceof Ve)throw n},"settled"),r=A(o=>async(...s)=>(await i(),o(...s)),"after");return{...e,step:A(async o=>{if(n!==void 0)throw n;t=t.then(()=>e.step(o).catch(s=>{n??=s}))},"step"),video:r(e.video),finish:r(e.finish),dropSteps:r(e.dropSteps),...e.decided&&{decided:r(e.decided)}}},"reportingInBackground")});var yY,wY,fN,hN=y(()=>{"use strict";yY=/\[data-(testid|test|qa|cy)="([a-z][\w-]*?[-_])(?:[0-7][0-9A-HJKMNP-TV-Z]{25}|[0-9a-f]{8}-[0-9a-f-]{27}|[0-9a-f]{24}|\d{5,})"\]/i,wY=new Set("open opens the a an to from in on of for and with click select choose view go page details detail product products item items card link button its this that first".split(" ")),fN=A(async(e,t,n)=>{let i=t.selector.match(yY);if(!i)return;let[,r,o]=i,s=n.replace(/["“”']/g," ").split(/\s+/).map(c=>c.replace(/[^\p{L}\p{N}-]/gu,"")).filter(c=>c.length>2&&!wY.has(c.toLowerCase())),a=`[data-${r}^="${o}"]`;if(s.length===0)return await e.locator(a).filter({visible:!0}).first().count().catch(()=>0)===0?void 0:{selector:`${a} >> visible=true >> nth=0`,code:`locator('${a}').first()`};for(let c=Math.min(s.length,4);c>=1;c--)for(let u=0;u+c<=s.length;u++){let l=s.slice(u,u+c).join(" ");if(await e.locator(a).filter({hasText:l,visible:!0}).count().catch(()=>0)===1)return{selector:`${a} >> visible=true >> internal:has-text=${JSON.stringify(l)}i`,code:`locator('${a}').filter({ hasText: ${JSON.stringify(l)} })`}}},"recordIdFallback")});var bY,pN,vY,IN,mN,EN,QN,KC,Ko,CN,BN=y(()=>{"use strict";bY=new Set(["navigate","fill","fillSecret","click","press"]),pN=/\b(log\s*-?\s*in|sign\s*-?\s*in|submit|continue|next|enter)\b/i,vY=A(e=>e.action==="press"||e.action==="click"&&(pN.test(e.intent)||pN.test(e.target.code)),"submits"),IN=A(e=>{let t=e.findIndex(u=>u.action==="fillSecret");if(t===-1||e.slice(0,t+1).some(u=>!bY.has(u.action)||u.cleanup))return 0;let i=e.slice(t+1),r=i.findIndex(u=>u.action!=="click"&&u.action!=="press"),o=r===-1?i:i.slice(0,r),s=o.findIndex(vY),a=s===-1?o.length?0:-1:s;if(a===-1)return 0;let c=t+1+a+1;return e.slice(c).some(u=>!u.action.startsWith("expect"))?c:0},"signInLength"),mN=/\b(sign|log)\s*-?\s*out\b/i,EN=A(e=>e.some(t=>t.action==="click"&&(mN.test(t.intent)||mN.test(t.target.code))),"signsOut"),QN=A((e,t)=>{let n=t.findLast(r=>r.action==="navigate"),i=t.flatMap(r=>r.action==="fill"?[r.value]:r.action==="fillSecret"?[`secret:${r.secret}`]:[]);return JSON.stringify([new URL(n?.url??e).origin,...i])},"sessionKey"),KC=class{constructor(t=()=>Date.now()){this.now=t}now;static{A(this,"Sessions")}saved=new Map;ending=new Map;get(t){if(this.ending.has(t))return;let n=this.saved.get(t);return n&&this.now()-n.savedAt>18e5&&this.saved.delete(t),this.saved.get(t)}save(t,n,i){this.ending.has(t)||this.saved.set(t,{state:n,url:i,savedAt:this.now()})}drop(t){this.saved.delete(t)}end(t){this.saved.delete(t),this.ending.set(t,(this.ending.get(t)??0)+1)}ended(t){let n=(this.ending.get(t)??1)-1;n>0?this.ending.set(t,n):this.ending.delete(t)}},Ko=new KC,CN=A(async(e,t,n)=>(await e.goto(n),await e.waitForLoadState("load").catch(()=>{}),new URL(e.url()).pathname===new URL(n).pathname&&!await e.locator('input[type="password"]:visible').count()?!0:(await t.clearCookies(),await e.evaluate(()=>{localStorage.clear(),sessionStorage.clear()}),!1)),"resume")});var qr,yN,kY,ha=y(()=>{"use strict";Zi();Yn();_c();io();_C();qn();bn();Wl();Br();HC();ad();WC();ZC();hN();YC();BN();qr=A(async(e,t,n,i)=>{let r=ud(n),{browser:o}=i.settings,{agent:s}=i,a=new oo(i.secrets,i.remembered),c=await $c(),u=a.missing(e.steps);if(u.length){let M=`Needs ${u.join(", ")}, which an earlier test remembers. Run the suite that orders them.`;return await r.finish({passed:!1,reason:M,verdict:"blocked",findings:[],durationMs:0,steps:[]}),{name:e.name,passed:!1,failure:{step:0,reason:M},findings:[],steps:[],repairedSteps:[],spend:{repairs:0,tokens:0,cost:0},durationMs:0,runDir:c,reportUrl:r.url}}let l=Date.now(),d=i.settings.inbox?new qo(i.settings.inbox,new Date(l),i.protectedAccounts):null,g=e.ownSignIn?0:IN(e.steps),h=g?QN(e.startUrl,e.steps.slice(0,g)):void 0,p=h&&EN(e.steps)?h:void 0,m=h&&!p?Ko.get(h):void 0;p&&Ko.end(p);let{browser:E,context:I,page:Q,video:D,recordingDirectory:k,recordingError:U,videoSize:x}=await Xi(o,void 0,m?.state),_=Date.now(),G=Lc(Q),me={secrets:a,inbox:d,readDocument:r.readDocument,fetchFixture:r.fetchFixture},ve=e.steps.map(M=>"target"in M?{...M,target:Ad(M.target)}:M),Be={repairs:0,tokens:0,cost:0},ce=[],ke,tr=!1,nt,Qr,Xs,Yi=0,Hi=new Map,Gn=A((M,je,$e)=>{let Fe=a.tokenizeStep({...M,target:je});if(!$e)return[Fe];let{intent:it,...Ce}=$e;return[a.tokenizeStep({action:"click",intent:it,target:Ce}),Fe]},"replacementFor"),Te=A(async(M,je,$e)=>{let Fe=a.tokenizeStep({...M,target:je});if(!$e)return await jr(Q,Fe,me),[Fe];let{intent:it,...Ce}=$e,te=a.tokenizeStep({action:"click",intent:it,target:Ce});return await Q.locator(je.selector).isVisible()||await jr(Q,te,me),await jr(Q,Fe,me),[te,Fe]},"runRepaired"),zr=A(()=>{let M=i.budget?.maxCost;return M!==void 0&&Be.cost>=M},"budgetSpent"),ji=A(M=>{Be.repairs++,Be.tokens+=M.total_tokens,Be.cost+=M.cost??0},"count"),Vn=new Zo(Q,me,G),wc=A(async(M,je,$e,Fe)=>{if(!s)throw $e;if(zr())throw new Error(`${ze($e)}. ${M==="check"?"Not updated":"No repair"}: this run's AI budget is spent`);let it=await gN(s,r.runId,M==="check"?"checkUpdate":"repair",Vn);try{return await it.ask(a.redactAll({kind:M,step:a.expandStep(je),error:ze($e),feedback:Fe}))}catch(Ce){throw new Error(`${ze($e)}. ${M==="check"?"Not updated":"No repair"}: the AI couldn't answer (${ek(Ce)})`)}finally{it.close()}},"ask"),eA=A(async(M,je,$e)=>{let Fe;for(let it=0;it<=3;it++){let Ce=AN.parse(await wc("check",M,$e,Fe));ji(Ce.usage);let te=Ce.update&&a.tokenizeStep(Vn.real(Ce.update));if(!te)throw new Error(`${ze($e)}. The check stands: Qadet found no sign the app changed on purpose`);if("target"in te&&!yN(te.target.selector)){Fe="That target uses an id the app makes for a record or a render, which changes between runs. Find the element by its label, role and name, or text instead.";continue}let De="target"in te?te.target.selector:`text=${JSON.stringify("text"in te&&te.text?a.expand(te.text):"")}`,xt=await t({number:je,intent:M.intent,was:{selector:"target"in M?M.target.selector:"",code:Ce.was},proposed:{selector:"target"in te?te.target.selector:"",code:Ce.now},reason:Ce.reason,screenshot:await Uc(Q,De),automatic:Ce.automatic||kY(M,te),check:!0,replacement:[te]});if(xt===!0)return te;if(xt===!1||it===3)throw $e;Fe=xt.revisionFeedback}throw $e},"updateCheck"),ae=A(async(M,je)=>{let $e="target"in M&&!kr(M)&&Hi.get(M.target.selector);if($e)return Te(M,$e.target,$e.opening);try{return await Xx(Q,M,me),[M]}catch(Fe){if("target"in M&&!kr(M)){let te=await fN(Q,M.target,a.expand(M.intent));if(te&&await t({number:je,intent:M.intent,was:M.target,proposed:te,reason:"Found the record the step names by its name, as its saved id no longer exists",screenshot:await Uc(Q,te.selector),automatic:!0,check:!1,replacement:Gn(M,te)})===!0)return Hi.set(M.target.selector,{target:te}),Te(M,te)}if(!s)throw Fe;if(kr(M))return[await eA(M,je,Fe)];if(!("target"in M))throw Fe;let it,Ce;for(let te=0;te<=3;te++){let De=sN.parse(await wc("step",M,Fe,it));ji(De.usage);let xt=De.target&&a.tokenizeStep(Vn.real(De.target));if(!xt)throw new Error(`${ze(Fe)}. No repair: ${De.reason}`);Ce=(De.opening&&a.tokenizeStep(Vn.real(De.opening)))??Ce;let Wi=await t({number:je,intent:M.intent,was:M.target,proposed:xt,opening:Ce,reason:De.reason,screenshot:await Uc(Q,a.expand(xt.selector)),automatic:De.automatic||!!M.cleanup,check:!1,replacement:Gn(M,xt,Ce)});if(Wi===!0)return Hi.set(M.target.selector,{target:xt,opening:Ce}),Te(M,xt,Ce);if(Wi===!1||te===3)throw Fe;it=Wi.revisionFeedback}throw Fe}},"runWithRepair");try{let M=m&&h?await CN(Q,I,m.url):!1;m&&h&&!M&&Ko.drop(h),M||await Q.goto(e.startUrl);let je=0,$e="",Fe=!!i.cleanup,it=!1;for(let Ce=0;Ce<ve.length;Ce++){let te=ve[Ce],De=Ce+1;if(M&&je<g){je++,await r.step({position:De,elapsedMs:Date.now()-_,step:te,status:"skipped",url:Q.url()});continue}if(ke&&!te.cleanup)continue;if(te.cleanup&&!Fe){await r.step({position:De,elapsedMs:Date.now()-_,step:te,status:"skipped",url:Q.url()});continue}h&&je===g-1&&($e=Q.url()),kr(te)||kc(Q),Tc(Q,De);let xt=Date.now()-_,Wi=await Zl(Q,te,Cr=>a.expand(Cr));try{let Cr=await ae(te,De);ve.splice(Ce,1,...Cr);for(let[rr,tA]of Cr.entries()){let lv=tA!==te;lv&&ce.push(De+rr);let cz=await sA(Q,c,De+rr,tA.action);await r.step({position:De+rr,elapsedMs:Date.now()-_,step:tA,status:"passed",repaired:lv,screenshot:cz,url:Q.url(),...rr===0?{startedMs:xt,box:Wi}:{}})}Ce+=Cr.length-1,je++,te.cleanup&&(it=!0),h&&!M&&je===g&&(await Q.waitForURL(rr=>rr.href!==$e,{timeout:1e4}).catch(()=>{}),Q.url()!==$e&&Ko.save(h,await I.storageState(),Q.url()))}catch(Cr){if(Cr instanceof Ve)throw Cr;let rr=ze(Cr),tA=await sA(Q,c,De,`${te.action}-failed`);if(await r.step({position:De,elapsedMs:Date.now()-_,step:te,status:"failed",error:rr,startedMs:xt,box:Wi,screenshot:tA,url:Q.url()}),te.cleanup){G.push({kind:"cleanup",message:ke&&!it?`Cleanup didn't start: the test failed at step ${ke.step}, possibly before it made anything to remove. Cleanup step ${De}: ${rr}`:`Test data may be left behind: cleanup step ${De} failed (${rr})`,page:Q.url()});break}ke={step:De,reason:rr},tr=no(Cr)}}}catch(M){nt=M}finally{p&&Ko.ended(p);let M=await eo({browser:E,context:I,video:D});Qr=M.videoPath,Xs=M.closeError,Yi=Date.now()-_}let qi=o.videoRecording,uv=!nt&&!ke;try{await r.video({path:Qr,directory:k,mode:qi.mode,passed:uv,durationMs:Yi,width:x.width,height:x.height,retentionDays:qi.retentionDays,error:U??(Xs?"Browser context did not close cleanly.":void 0)})}catch(M){process.stderr.write(`Could not report the video recording: ${M instanceof Error?M.message:String(M)}
294
294
  `)}if(nt)throw nt;let bc={name:e.name,passed:uv,failure:ke,findings:G,steps:ve,repairedSteps:ce,spend:Be,durationMs:Date.now()-l,runDir:c,reportUrl:r.url};return await Fc(c,bc),await r.finish({passed:bc.passed,reason:ke?`Failed at step ${ke.step}: ${ke.reason}`:"Every step passed",failureKind:tr?"environment":void 0,findings:G,durationMs:bc.durationMs,steps:ve,remembered:a.rememberedValues}),bc},"replay"),yN=A(e=>!Rc.test(e)&&[...e.matchAll(/data-(?:testid|test|qa|cy)=\\?"?([^"\]\\]+)/g)].every(t=>iA(t[1]??"")),"lastingTarget"),kY=A((e,t)=>{if(e.action!==t.action||!("target"in e)||!("target"in t))return!1;let{target:n,intent:i,...r}=e,{target:o,intent:s,...a}=t;return JSON.stringify(r)===JSON.stringify(a)&&yN(o.selector)&&JSON.stringify(n)!==JSON.stringify(o)},"sameCheckElsewhere")});var XC,eB,ld,dd,tB=y(()=>{"use strict";ha();XC=A(e=>({step:A(async()=>{},"step"),video:A(async()=>{},"video"),dropSteps:A(async()=>{},"dropSteps"),readDocument:A((t,n)=>e.readDocument(t,n),"readDocument"),fetchFixture:A(t=>e.fetchFixture(t),"fetchFixture"),finish:A(async()=>{},"finish"),runId:e.runId}),"quietReporter"),eB=A(e=>({...e,settings:{...e.settings,browser:{...e.settings.browser,videoRecording:{...e.settings.browser.videoRecording,enabled:!1,mode:"disabled"}}}}),"withoutVideo"),ld=A(async({test:e,rows:t,firstRow:n,context:i,reporter:r,budget:o})=>{let s=e.steps,a=0,c=[];for(let[u,l]of t.entries()){let d=o?o.maxCost-a:void 0,g=await qr({...e,steps:s,rows:void 0,checkpoint:void 0},async h=>!h.check,XC(r),eB({...i,remembered:{...i.remembered,...l},budget:d===void 0?i.budget:d>0?{maxCost:d}:null,agent:d!==void 0&&d<=0?null:i.agent}));a+=g.spend.cost,g.passed&&g.repairedSteps.length&&(s=g.steps),c.push({row:n+u,passed:g.passed,reason:g.failure?`Step ${g.failure.step}: ${g.failure.reason}`:"",aiCalls:g.spend.repairs})}return{results:c,steps:s,cost:a}},"replayRows"),dd=A(e=>{let t=e.filter(i=>!i.passed),n=t[0];return{passed:t.length===0,reason:n?`${t.length} of ${e.length} rows failed; row ${n.row} at ${n.reason}`:`All ${e.length} rows passed`}},"summarizeRows")});var wN,gd,rB=y(()=>{"use strict";Yn();_c();io();qn();Wl();Br();ha();WC();ZC();HC();tB();wN=A(async(e,t)=>{try{await e.video(t)}catch(n){process.stderr.write(`Could not report the video recording: ${n instanceof Error?n.message:String(n)}
295
- `)}},"reportVideo"),gd=A(async({url:e,prompt:t,context:n,reporter:i,checkpoint:r=[],rows:o=[]})=>{let s=ud(i),{settings:a}=n,c=o[0]??{},u=new oo(n.secrets,{...n.remembered,...c}),l=await $c(),d=Date.now(),{browser:g,context:h,page:p,video:m,recordingDirectory:E,recordingError:I,videoSize:Q}=await Xi(a.browser),D=Date.now(),k=0,U=a.inbox?new qo(a.inbox,new Date(d),n.protectedAccounts):null,x=Lc(p),_=new Zo(p,{secrets:u,inbox:U,readDocument:s.readDocument,fetchFixture:s.fetchFixture},x,{runDir:l,reporter:s,startedAt:d}),G,me=!1,ve=!1,Be,ce,ke,tr,nt,Qr=!1,Xs=A(ae=>{Qr||_.cancelled||!s.decided||(Qr=!0,s.decided({verdict:ae.verdict??(ae.passed?"passed":"failed"),reason:ae.reason}).catch(()=>{}))},"showDecision");try{if(await p.goto(e),!n.agent)throw new Error("Exploring needs an AI model. An admin can choose one in Settings.");let ae=r.length?await _.resume(r,e):{intents:[]};if(nt=ae.error,_.cancelled)throw new Ve;ce=await uN(n.agent,s.runId,_,void 0,ae.intents,Xs),{error:G,limited:me,verdict:Be}=ce,Be&&!G&&Xs(Be)}catch(ae){ae instanceof Ve||(G=ze(ae),ve=no(ae))}for(let ae of ce?.leftBehind??[])x.push({kind:"cleanup",message:ae,page:p.url()});let Yi=ce?.usage??{cost:0,total_tokens:0},Hi=await eo({browser:g,context:h,video:m});ke=Hi.videoPath,tr=Hi.closeError,k=Date.now()-D;let Gn=a.browser.videoRecording;if(_.cancelled)throw await wN(s,{path:ke,directory:E,mode:Gn.mode,passed:!1,durationMs:k,width:Q.width,height:Q.height,retentionDays:Gn.retentionDays,error:I??(tr?"Browser context did not close cleanly.":void 0)}),new Ve;let Te=G||!Be?{passed:!1,reason:G??"The agent stopped before reaching a verdict",verdict:ve?"blocked":me||!G?"inconclusive":void 0,failureKind:ve?"environment":void 0}:Be,zr=_.steps,ji,Vn=A(ae=>qr({name:"verification",prompt:t,startUrl:e,steps:zr},async()=>ae,XC(s),eB({...n,budget:n.budget&&{maxCost:n.budget.maxCost-(Yi.cost??0)},agent:ae?n.agent:null})),"repeatSteps"),wc=Object.keys(n.remembered??{}).some(ae=>JSON.stringify(zr).includes(`{{${ae}}}`));if(Te.passed&&wc)Te={...Te,reason:`${Te.reason??"Exploration passed all checks."} (Steps saved without repeating them now: they use values earlier tests in this ordered test run remembered, so they repeat when the whole run does.)`};else if(Te.passed&&o.length>1){let ae=await ld({test:{name:"row",prompt:t,startUrl:e,steps:zr},rows:o.slice(1),firstRow:2,context:n,reporter:s,budget:n.budget&&{maxCost:n.budget.maxCost-(Yi.cost??0)}});zr=ae.steps,ji=[{row:1,passed:!0,reason:"",aiCalls:0},...ae.results];let qi=dd(ji);Te=qi.passed?{...Te,reason:`${Te.reason} ${qi.reason}.`}:{passed:!1,reason:qi.reason,verdict:"failed"}}else if(Te.passed){let ae=await Vn(!0);ae.passed&&ae.repairedSteps.length&&(zr=ae.steps,ae=await Vn(!1)),ae.passed||(Te={passed:!0,reason:`${Te.reason??"Exploration passed all checks."} (Note: saved steps need review before automated headless replay: step ${ae.failure?.step}: ${ae.failure?.reason})`,verdict:"passed"},zr=[])}nt&&(Te={...Te,reason:`${Te.reason} (Saved progress discarded: ${nt})`}),await wN(s,{path:ke,directory:E,mode:Gn.mode,passed:Te.passed,durationMs:k,width:Q.width,height:Q.height,retentionDays:Gn.retentionDays,error:I??(tr?"Browser context did not close cleanly.":void 0)});let eA={url:e,prompt:t,...Te,steps:zr,checks:ce?.checks??[],findings:x,knowledgeUsed:ce?.knowledgeUsed??[],suggestedPrompt:ce?.suggestedPrompt,ownSignIn:ce?.ownSignIn,remembered:Object.fromEntries(Object.entries(u.rememberedValues).filter(([ae])=>!(ae in c))),limited:me&&!Te.passed,rowResults:ji,aiError:ce?.aiError,usage:Yi,durationMs:Date.now()-d,runDir:l,reportUrl:s.url};return await Fc(l,eA),await s.finish(eA),eA},"explore")});var ft,pa=y(()=>{"use strict";ft="0.7.13"});import{randomUUID as sB}from"node:crypto";import{chmod as DY,mkdir as SY,readFile as xY,rm as vN,writeFile as NY}from"node:fs/promises";import{homedir as kN}from"node:os";import{dirname as RY,posix as iB,win32 as $Y}from"node:path";var oB,AB,FY,Xo,fd,UY,bN,nB,Wr,_Y,es,hd,hi=y(()=>{"use strict";jo();oB=f.object({url:f.string().url(),token:f.string().min(1),runnerId:f.string().uuid().optional()}),AB=A(({platform:e=process.platform,home:t=kN(),appData:n=process.env.APPDATA,xdgConfigHome:i=process.env.XDG_CONFIG_HOME}={})=>{let r=e==="win32"?$Y:iB;return e==="win32"?r.join(n||r.join(t,"AppData","Roaming"),"Qadet","connection.json"):e==="darwin"?r.join(t,"Library","Application Support","Qadet","connection.json"):r.join(i||r.join(t,".config"),"qadet","connection.json")},"connectionPathFor"),FY=A(({platform:e=process.platform,home:t=kN(),xdgConfigHome:n=process.env.XDG_CONFIG_HOME}={})=>e==="darwin"?iB.join(n||iB.join(t,".config"),"qadet","connection.json"):void 0,"oldConnectionPathFor"),Xo=AB(),fd=FY(),UY=sB(),bN=A(e=>xY(e,"utf8").catch(()=>{}),"readSaved"),nB=A((e=process.env,t)=>{let n=e.QADET_URL?.trim()||t?.url,i=e.QADET_TOKEN?.trim()||t?.token;return!n||!i?t:oB.parse({url:new URL(n).origin,token:i,runnerId:t?.runnerId??UY})},"connectionFromEnv"),Wr=A(async(e=process.env)=>{let t=await bN(Xo);if(t)return nB(e,await _Y(oB.parse(JSON.parse(t))));let n=fd&&await bN(fd);if(n&&fd){let i={...oB.parse(JSON.parse(n)),runnerId:sB()};return await es(i),await vN(fd,{force:!0}),nB(e,i)}return nB(e)},"readConnection"),_Y=A(async e=>{if(e.runnerId)return e;let t={...e,runnerId:sB()};return await es(t),t},"withRunnerId"),es=A(async e=>(await SY(RY(Xo),{recursive:!0,mode:448}),await NY(Xo,`${JSON.stringify(e,null,2)}
295
+ `)}},"reportVideo"),gd=A(async({url:e,prompt:t,context:n,reporter:i,checkpoint:r=[],rows:o=[]})=>{let s=ud(i),{settings:a}=n,c=o[0]??{},u=new oo(n.secrets,{...n.remembered,...c}),l=await $c(),d=Date.now(),{browser:g,context:h,page:p,video:m,recordingDirectory:E,recordingError:I,videoSize:Q}=await Xi(a.browser),D=Date.now(),k=0,U=a.inbox?new qo(a.inbox,new Date(d),n.protectedAccounts):null,x=Lc(p),_=new Zo(p,{secrets:u,inbox:U,readDocument:s.readDocument,fetchFixture:s.fetchFixture},x,{runDir:l,reporter:s,startedAt:d}),G,me=!1,ve=!1,Be,ce,ke,tr,nt,Qr=!1,Xs=A(ae=>{Qr||_.cancelled||!s.decided||(Qr=!0,s.decided({verdict:ae.verdict??(ae.passed?"passed":"failed"),reason:ae.reason}).catch(()=>{}))},"showDecision");try{if(await p.goto(e),!n.agent)throw new Error("Exploring needs an AI model. An admin can choose one in Settings.");let ae=r.length?await _.resume(r,e):{intents:[]};if(nt=ae.error,_.cancelled)throw new Ve;ce=await uN(n.agent,s.runId,_,void 0,ae.intents,Xs),{error:G,limited:me,verdict:Be}=ce,Be&&!G&&Xs(Be)}catch(ae){ae instanceof Ve||(G=ze(ae),ve=no(ae))}for(let ae of ce?.leftBehind??[])x.push({kind:"cleanup",message:ae,page:p.url()});let Yi=ce?.usage??{cost:0,total_tokens:0},Hi=await eo({browser:g,context:h,video:m});ke=Hi.videoPath,tr=Hi.closeError,k=Date.now()-D;let Gn=a.browser.videoRecording;if(_.cancelled)throw await wN(s,{path:ke,directory:E,mode:Gn.mode,passed:!1,durationMs:k,width:Q.width,height:Q.height,retentionDays:Gn.retentionDays,error:I??(tr?"Browser context did not close cleanly.":void 0)}),new Ve;let Te=G||!Be?{passed:!1,reason:G??"The agent stopped before reaching a verdict",verdict:ve?"blocked":me||!G?"inconclusive":void 0,failureKind:ve?"environment":void 0}:Be,zr=_.steps,ji,Vn=A(ae=>qr({name:"verification",prompt:t,startUrl:e,steps:zr},async()=>ae,XC(s),eB({...n,budget:n.budget&&{maxCost:n.budget.maxCost-(Yi.cost??0)},agent:ae?n.agent:null})),"repeatSteps"),wc=Object.keys(n.remembered??{}).some(ae=>JSON.stringify(zr).includes(`{{${ae}}}`));if(Te.passed&&wc)Te={...Te,reason:`${Te.reason??"Exploration passed all checks."} (Steps saved without repeating them now: they use values earlier tests in this ordered test run remembered, so they repeat when the whole run does.)`};else if(Te.passed&&o.length>1){let ae=await ld({test:{name:"row",prompt:t,startUrl:e,steps:zr},rows:o.slice(1),firstRow:2,context:n,reporter:s,budget:n.budget&&{maxCost:n.budget.maxCost-(Yi.cost??0)}});zr=ae.steps,ji=[{row:1,passed:!0,reason:"",aiCalls:0},...ae.results];let qi=dd(ji);Te=qi.passed?{...Te,reason:`${Te.reason} ${qi.reason}.`}:{passed:!1,reason:qi.reason,verdict:"failed"}}else if(Te.passed){let ae=await Vn(!0);ae.passed&&ae.repairedSteps.length&&(zr=ae.steps,ae=await Vn(!1)),ae.passed||(Te={passed:!0,reason:`${Te.reason??"Exploration passed all checks."} (Note: saved steps need review before automated headless replay: step ${ae.failure?.step}: ${ae.failure?.reason})`,verdict:"passed"},zr=[])}nt&&(Te={...Te,reason:`${Te.reason} (Saved progress discarded: ${nt})`}),await wN(s,{path:ke,directory:E,mode:Gn.mode,passed:Te.passed,durationMs:k,width:Q.width,height:Q.height,retentionDays:Gn.retentionDays,error:I??(tr?"Browser context did not close cleanly.":void 0)});let eA={url:e,prompt:t,...Te,steps:zr,checks:ce?.checks??[],findings:x,knowledgeUsed:ce?.knowledgeUsed??[],suggestedPrompt:ce?.suggestedPrompt,ownSignIn:ce?.ownSignIn,remembered:Object.fromEntries(Object.entries(u.rememberedValues).filter(([ae])=>!(ae in c))),limited:me&&!Te.passed,rowResults:ji,aiError:ce?.aiError,usage:Yi,durationMs:Date.now()-d,runDir:l,reportUrl:s.url};return await Fc(l,eA),await s.finish(eA),eA},"explore")});var ft,pa=y(()=>{"use strict";ft="0.7.14"});import{randomUUID as sB}from"node:crypto";import{chmod as DY,mkdir as SY,readFile as xY,rm as vN,writeFile as NY}from"node:fs/promises";import{homedir as kN}from"node:os";import{dirname as RY,posix as iB,win32 as $Y}from"node:path";var oB,AB,FY,Xo,fd,UY,bN,nB,Wr,_Y,es,hd,hi=y(()=>{"use strict";jo();oB=f.object({url:f.string().url(),token:f.string().min(1),runnerId:f.string().uuid().optional()}),AB=A(({platform:e=process.platform,home:t=kN(),appData:n=process.env.APPDATA,xdgConfigHome:i=process.env.XDG_CONFIG_HOME}={})=>{let r=e==="win32"?$Y:iB;return e==="win32"?r.join(n||r.join(t,"AppData","Roaming"),"Qadet","connection.json"):e==="darwin"?r.join(t,"Library","Application Support","Qadet","connection.json"):r.join(i||r.join(t,".config"),"qadet","connection.json")},"connectionPathFor"),FY=A(({platform:e=process.platform,home:t=kN(),xdgConfigHome:n=process.env.XDG_CONFIG_HOME}={})=>e==="darwin"?iB.join(n||iB.join(t,".config"),"qadet","connection.json"):void 0,"oldConnectionPathFor"),Xo=AB(),fd=FY(),UY=sB(),bN=A(e=>xY(e,"utf8").catch(()=>{}),"readSaved"),nB=A((e=process.env,t)=>{let n=e.QADET_URL?.trim()||t?.url,i=e.QADET_TOKEN?.trim()||t?.token;return!n||!i?t:oB.parse({url:new URL(n).origin,token:i,runnerId:t?.runnerId??UY})},"connectionFromEnv"),Wr=A(async(e=process.env)=>{let t=await bN(Xo);if(t)return nB(e,await _Y(oB.parse(JSON.parse(t))));let n=fd&&await bN(fd);if(n&&fd){let i={...oB.parse(JSON.parse(n)),runnerId:sB()};return await es(i),await vN(fd,{force:!0}),nB(e,i)}return nB(e)},"readConnection"),_Y=A(async e=>{if(e.runnerId)return e;let t={...e,runnerId:sB()};return await es(t),t},"withRunnerId"),es=A(async e=>(await SY(RY(Xo),{recursive:!0,mode:448}),await NY(Xo,`${JSON.stringify(e,null,2)}
296
296
  `,{mode:384}),process.platform!=="win32"&&await DY(Xo,384),Xo),"saveConnection"),hd=A(()=>vN(Xo,{force:!0}),"forgetConnection")});import{createPrivateKey as TY,createPublicKey as LY,generateKeyPairSync as MY,sign as PY}from"node:crypto";import{chmod as zY,mkdir as OY,readFile as JY,writeFile as GY}from"node:fs/promises";import{dirname as DN,join as VY}from"node:path";var YY,SN,xN,NN,RN=y(()=>{"use strict";hi();YY=A((e=DN(AB()))=>VY(e,"device-key.pem"),"deviceKeyPath"),SN=A(async(e=YY())=>{let t=await JY(e,"utf8").catch(()=>{});if(t)return TY(t);let{privateKey:n}=MY("ed25519");return await OY(DN(e),{recursive:!0,mode:448}),await GY(e,n.export({type:"pkcs8",format:"pem"}),{mode:384}),process.platform!=="win32"&&await zY(e,384),n},"loadDeviceKey"),xN=A(e=>LY(e).export({type:"spki",format:"pem"}).toString(),"publicPem"),NN=A((e,t,n=Date.now())=>{let i=String(Math.floor(n/1e3)),r=`qadet-reconnect
297
297
  ${t}
298
298
  ${i}`;return{key:t,signed_at:i,signature:PY(null,Buffer.from(r),e).toString("base64")}},"signedReconnect")});var pd,aB=y(()=>{"use strict";jo();Wl();ad();pd=f.object({settings:f.object({browser:f.object({channel:f.string(),hostMap:f.array(f.object({host:f.string(),address:f.string()})).default([]),acceptInvalidCertificates:f.boolean().default(!1),allowedHosts:f.array(f.string()).default([]),maskSelectors:f.array(f.string()).default([]),device:f.enum(["desktop","mobile","tablet"]).default("desktop"),videoRecording:f.object({enabled:f.boolean().default(!1),mode:f.enum(["all","failures_only","disabled"]).default("disabled"),width:f.number().int().min(1).max(7680).default(1280),height:f.number().int().min(1).max(4320).default(720),retentionDays:f.number().int().min(1).max(365).default(30)}).default({enabled:!1,mode:"disabled",width:1280,height:720,retentionDays:30})}),inbox:px.nullable().default(null)}),secrets:f.record(f.string(),f.string()),remembered:f.record(f.string(),f.string()).default({}),agent:nN.nullable().default(null),budget:f.object({maxCost:f.number().positive()}).nullable().default(null),protectedAccounts:f.array(f.string()).default([]),cleanup:f.string().nullable().default(null),fixtures:f.array(f.object({id:f.number().int(),name:f.string(),domain:f.string().optional(),description:f.string().optional(),fileName:f.string(),mimeType:f.string(),byteSize:f.number().int().nonnegative()})).default([])})});import{hostname as jY}from"node:os";import{setTimeout as qY}from"node:timers/promises";var $N,FN,WY,lB,cB,_N,TN,md,uB,LN,MN,PN,zN,ON,ZY,KY,XY,dB,Id,JN,GN,UN,Ed,eH,tH,gB,fB,ma=y(()=>{"use strict";qn();bn();Br();pa();hi();aB();$N=!1,FN=!1,WY=10080*6e4,lB=A((e,t)=>{let n=A(o=>o.split(/[.-]/).map(s=>Number.parseInt(s,10)||0),"parts"),[i,r]=[n(e),n(t)];for(let o=0;o<Math.max(i.length,r.length);o++){let s=(i[o]??0)-(r[o]??0);if(s)return s>0}return!1},"isNewer"),_N=A(()=>cB,"tokenExpires"),TN=!1,md=A(()=>TN,"isPaused"),LN=A(()=>{let e=uB;return uB=void 0,e},"takeAsk"),PN=A(()=>MN,"askedToUpdateTo"),ON=A(()=>zN,"latestRunner"),ZY=A(e=>{e&&(zN=e),!($N||!e||ft==="dev"||!lB(e,ft))&&($N=!0,process.stdout.write(`A newer Qadet runner is available (${e}); this runner (${ft}) can keep running. Update it only if Qadet says an update is required.