ripplo 0.7.54 → 0.7.56

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.
@@ -0,0 +1,274 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __ripploCreateRequire } from "node:module";
3
+ const require = globalThis.require ?? __ripploCreateRequire(import.meta.url);
4
+ import{c as an}from"./chunk-ZPCVY23H.js";import{A as dn,E as cn,F as un,G as pn,H as fn,I as yn,a as A,b as F,c as He,d as Be,e as Ve,f as M,g as Ke,i as $,w as sn,x as ln}from"./chunk-QMQ77IFD.js";import{b as Le,e as u,f as p,i as _e,j as Ne}from"./chunk-PXYDLKAG.js";import{N as Ge,O as Xe,P as v,Q as Ye,S as Ze,U as en,a as T,b as I,c as qe,da as nn,ea as rn,ha as tn,ia as on,j as We,k as j,l as m,q as Je,r as se,s as h,t as P,u as Qe,v as ze,x as O}from"./chunk-OUOQU2Q2.js";import Rn from"fs";import N from"path";import{config as Pr}from"dotenv";import{z as L}from"zod";import{err as Cr,ok as hn}from"neverthrow";import U from"fs";import ce from"path";import{err as le,ok as mn}from"neverthrow";import{z as D}from"zod";var xr=ce.join(".ripplo","project.json"),de=[".env",".env.local"],br=D.object({envFiles:D.array(D.string().min(1)).optional(),projectId:D.string().min(1)});function gn(e){return ce.join(e,xr)}function ue(e){let n=gn(e);return U.existsSync(n)?Er(n).andThen(r=>{let t=br.safeParse(r);return t.success?mn({envFiles:t.data.envFiles??de,projectId:t.data.projectId}):le({issues:t.error.issues.map(o=>`${o.path.join(".")}: ${o.message}`),kind:"project-file-invalid",path:n})}):le({kind:"project-file-missing",path:n})}function pe(e){return ue(e).match(n=>n,()=>{})}function Er(e){try{return mn(JSON.parse(U.readFileSync(e,"utf8")))}catch(n){return le({issues:[n instanceof Error?n.message:String(n)],kind:"project-file-invalid",path:e})}}function Ii({cwd:e,envFiles:n,projectId:r}){let t=gn(e);U.mkdirSync(ce.dirname(t),{recursive:!0});let o={projectId:r};n!=null&&!Ir(n)&&(o.envFiles=[...n]),U.writeFileSync(t,JSON.stringify(o,null,2)+`
5
+ `)}function Ir(e){return e.length!==de.length?!1:e.every((n,r)=>n===de[r])}function $i(e){let r=pe(e)?.envFiles??[".env",".env.local"],t=N.join(e,".ripplo");r.forEach(o=>{let i=N.resolve(t,o);Rn.existsSync(i)&&Pr({override:!0,path:i,quiet:!0})}),_=void 0}var Ar=L.object({RIPPLO_APP_URL:L.url(),RIPPLO_ENGINE_URL:L.url(),RIPPLO_WEBHOOK_SECRET:L.string().min(1)}),_;function q(){return _!=null?hn(_):jr().map(e=>(_=e,e))}function Tr(e){let r=pe(e)?.envFiles??[],t=N.join(e,".ripplo");return r.map(o=>N.resolve(t,o)).filter(o=>!Rn.existsSync(o))}function jr(){let e=Ar.safeParse(process.env);if(!e.success)return Cr({issues:e.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`),kind:"env-invalid",missingEnvFiles:Tr(process.cwd())});let n=e.data;return hn({appUrl:n.RIPPLO_APP_URL,engineUrl:n.RIPPLO_ENGINE_URL,webhookSecret:n.RIPPLO_WEBHOOK_SECRET})}var W=class extends Error{failure;constructor(n){super(n.kind),this.name="CliError",this.failure=n}};function Ni(e){return e instanceof W?fe(e.failure):e instanceof Error?e.message:String(e)}function fe(e){switch(e.kind){case"project-file-missing":return[`Missing ${e.path} \u2014 this directory is not a Ripplo project.`,"Run `npx ripplo init` to create it (or cd into the project root).",Ke("setup")].join(`
6
+ `);case"project-file-invalid":return[`${e.path} is invalid:`,...e.issues.map(n=>` ${n}`),"Fix the file by hand or re-run `npx ripplo init`."].join(`
7
+ `);case"not-authenticated":return["Not signed in. Run `npx ripplo auth login`.","(Claude Code: run it yourself in the background \u2014 the user just approves in the browser.)"].join(`
8
+ `);case"env-invalid":return Fr(e);case"playwright-install-failed":return["Playwright browser install failed \u2014 Chromium is still missing.","Run `npx playwright install chromium` and check its output for network, proxy, or disk-space errors."].join(`
9
+ `);case"gitdir-unrecognized":return`Unrecognized .git file at ${e.marker} \u2014 expected a directory or a "gitdir:" pointer (worktree). Is the repo corrupted?`;case"gitdir-empty":return`Empty gitdir pointer at ${e.marker} \u2014 the worktree's .git file points nowhere. Re-create the worktree.`;case"oauth-device-code-failed":return[`Could not start sign-in (device-code request failed): ${e.description}`,"Is the Ripplo server reachable? Check RIPPLO_SERVER_URL and retry."].join(`
10
+ `);case"oauth-authorization-failed":return[`Sign-in failed (${e.code}): ${e.description}`,e.code==="expired_token"?"The approval window expired \u2014 run `npx ripplo auth login` again.":"Run `npx ripplo auth login` to retry."].join(`
11
+ `);case"compilation-failed":return $(e.error)}}function Fr(e){let n=e.missingEnvFiles.length===0?[]:["Declared env files not found:",...e.missingEnvFiles.map(r=>` ${r}`),"In a git worktree? Env files aren't copied from the main checkout \u2014 recreate them, or symlink to a shared file outside the working tree."];return["Env config invalid:",...e.issues.map(r=>` ${r}`),"Add the missing values to the env files declared in .ripplo/project.json.",...n].join(`
12
+ `)}import{err as Or,ok as Dr}from"neverthrow";import{z as ye}from"zod";var Mr="https://ripplo.ai";function Sn(){return wn().RIPPLO_SERVER_URL}function vn(){return wn().RIPPLO_PROJECT_ID}var $r=ye.object({RIPPLO_PROJECT_ID:ye.string().min(1).optional(),RIPPLO_SERVER_URL:ye.string().min(1).default(Mr)}),kn;function wn(){return kn??=$r.parse(process.env),kn}import xn from"fs";import me from"path";function bn(e){let n=xn.realpathSync(e),r=n,t=me.dirname(r);for(;t!==r;){if(xn.existsSync(me.join(r,".git")))return r;r=t,t=me.dirname(r)}return n}function H(e){return ue(e).andThen(n=>q().andThen(r=>{let t=Sn(),o=Ne(t);return o==null?Or({kind:"not-authenticated"}):Dr({appUrl:r.appUrl,cwd:bn(e),engineUrl:r.engineUrl,projectId:vn()??n.projectId,ripploServerUrl:t,token:o,webhookSecret:r.webhookSecret})}))}import Ur from"p-queue";var Lr=4,_r={"p0-ui":3,"p1-cli":2,"p2-cover":1,"p3-explore":0},B=new Ur({concurrency:Lr}),k={headedActive:0,interactiveActive:0,interactiveQueued:0},En={current:null};function na({headed:e,task:n,workClass:r}){let t=_r[r];return r==="p3-explore"?B.add(n,{priority:t}):(k.interactiveQueued+=1,V(),B.add(()=>Nr({headed:e,task:n}),{priority:t}))}function ra(e){!Number.isFinite(e)||e<1||(B.concurrency=Math.floor(e),V())}function ge(){return{active:k.interactiveActive,headedActive:k.headedActive,poolSize:B.concurrency,queued:k.interactiveQueued}}function ta(e){En.current=e}async function Nr({headed:e,task:n}){k.interactiveQueued-=1,k.interactiveActive+=1,k.headedActive+=e?1:0,V();try{return await n()}finally{k.interactiveActive-=1,k.headedActive-=e?1:0,V()}}function V(){En.current?.()}import Re from"fs";import he from"path";function In(e){try{let n=qr(e);if(n==null)return;let r=he.join(n,"HEAD"),t=Re.readFileSync(r,"utf8").trim(),o="ref: refs/heads/";return t.startsWith(o)?t.slice(o.length):t.length===0?void 0:t.slice(0,7)}catch{return}}function qr(e){let n=he.join(e,".git");if(Re.statSync(n).isDirectory())return n;let t=Re.readFileSync(n,"utf8").trim(),o="gitdir:";if(!t.startsWith(o))return;let i=t.slice(o.length).trim();if(i.length!==0)return he.resolve(e,i)}import Wr from"crypto";import{readFile as Pn}from"fs/promises";import Cn from"path";import{graphql as ke}from"gql.tada";import{err as Hr,ok as Br}from"neverthrow";var Vr=ke(`
13
+ mutation SyncDevSession(
14
+ $projectId: String!
15
+ $cwd: String!
16
+ $branch: String
17
+ $lockfileContent: String
18
+ $fixtures: [SyncDevFixtureInput!]
19
+ $preconditions: [SyncDevPreconditionInput!]!
20
+ $singletons: [SyncDevSingletonInput!]
21
+ $workflows: [SyncDevWorkflowInput!]!
22
+ ) {
23
+ syncDevSession(
24
+ projectId: $projectId
25
+ cwd: $cwd
26
+ branch: $branch
27
+ lockfileContent: $lockfileContent
28
+ fixtures: $fixtures
29
+ preconditions: $preconditions
30
+ singletons: $singletons
31
+ workflows: $workflows
32
+ ) {
33
+ id
34
+ hooksPaused
35
+ }
36
+ }
37
+ `);async function ha(e,n){let r=await M(e);if(r.isErr())return Hr({error:r.error,kind:"compilation-failed"});let t=await w({config:n,cwd:e,lockfile:r.value});return Br({devSessionId:t.devSessionId,lockfile:r.value})}async function w(e){let n=We(e.lockfile);return Qr({config:e.config,cwd:e.cwd,fixtures:e.lockfile.fixtures,payload:n})}var Kr=ke(`
38
+ query DevSessionSyncState($projectId: String!, $cwd: String!) {
39
+ project(id: $projectId) {
40
+ devSession(cwd: $cwd) {
41
+ id
42
+ hooksPaused
43
+ lockfileHash
44
+ }
45
+ }
46
+ }
47
+ `),Jr=ke(`
48
+ mutation AnnounceDevSessionActive($projectId: String!, $cwd: String!) {
49
+ announceDevSessionActive(projectId: $projectId, cwd: $cwd)
50
+ }
51
+ `);async function ka(e){let n=await Se(e.cwd);if(n!=null){let t=(await u({config:e.config,document:Kr,variables:{cwd:e.cwd,projectId:e.config.projectId}}).catch(()=>null))?.project?.devSession;if(t!=null&&t.lockfileHash===n)return await u({config:e.config,document:Jr,variables:{cwd:e.cwd,projectId:e.config.projectId}}).catch(()=>null),{devSessionId:t.id,hooksPaused:t.hooksPaused}}return w(e)}async function Se(e){let n=await An(e);return n==null?null:Wr.createHash("sha256").update(n).digest("hex")}async function Qr({config:e,cwd:n,fixtures:r,payload:t}){let o=In(n),i=await An(n),l=await zr(n,r),a=await u({config:e,document:Vr,variables:{branch:o??null,cwd:n,fixtures:l,lockfileContent:i,preconditions:t.preconditions.map(s=>({depends:[...s.depends],description:s.description,name:s.name,returns:[...s.returns]})),projectId:e.projectId,singletons:t.singletons.map(s=>({defaultValue:s.defaultValue,description:s.description,name:s.name,type:s.type})),workflows:t.workflows.map(s=>({expectedOutcome:s.expectedOutcome,name:s.name,preconditions:[...s.preconditions],requiresKeys:s.requiresKeys.map(c=>({namespace:c.namespace,preconditionName:c.preconditionName})),slug:s.slug,sourcePath:s.sourcePath,spec:JSON.stringify(s.spec)}))}});if(a.syncDevSession==null)throw new Error("syncDevSession returned null");return{devSessionId:a.syncDevSession.id,hooksPaused:a.syncDevSession.hooksPaused}}async function zr(e,n){let r=Object.entries(n);return Promise.all(r.map(async([t,o])=>({contentBase64:(await Pn(Cn.join(e,F,t))).toString("base64"),sha256:o.sha256})))}async function An(e){try{return await Pn(Cn.join(e,He),"utf8")}catch{return null}}import{randomUUID as bt}from"crypto";import{createId as Et}from"@paralleldrive/cuid2";import{CancellationTokenSource as It,ResponseError as Pt}from"vscode-jsonrpc/node";import{graphql as Gr}from"gql.tada";var Xr=Gr(`
52
+ mutation DaemonCreateRun(
53
+ $id: String
54
+ $workflowId: String!
55
+ $testId: String
56
+ $clientVersion: String
57
+ $executor: RunExecutor
58
+ $target: RunTarget
59
+ $lockfileHash: String
60
+ ) {
61
+ createRun(
62
+ id: $id
63
+ workflowId: $workflowId
64
+ testId: $testId
65
+ executor: $executor
66
+ target: $target
67
+ clientVersion: $clientVersion
68
+ lockfileHash: $lockfileHash
69
+ ) {
70
+ __typename
71
+ ... on MutationCreateRunSuccess {
72
+ data {
73
+ id
74
+ }
75
+ }
76
+ ... on LimitExceededError {
77
+ code
78
+ }
79
+ }
80
+ }
81
+ `);async function Tn(e){try{let r=(await u({config:e.config,document:Xr,variables:Yr(e)})).createRun;return r==null?K({detail:"create-run-null",type:"generic"}):r.__typename==="MutationCreateRunSuccess"?null:r.__typename==="LimitExceededError"?K({code:r.code,type:"limit"}):K({detail:r.__typename,type:"generic"})}catch(n){return Zr(n)}}function Yr({executor:e,lockfileHash:n,runId:r,target:t}){return{clientVersion:A(),executor:e,id:r,lockfileHash:n,target:e==="cloud"?"tunnel":void 0,testId:t.testId,workflowId:t.workflowId}}function K(e){return{kind:"dispatch-error",reason:e}}function Zr(e){return e instanceof Le?{detail:e.message,kind:"infra-error"}:K({detail:e instanceof Error?e.message:String(e),type:"generic"})}import{graphql as et}from"gql.tada";async function jn(e,n){let t=(await u({config:e,document:nt,variables:{cwd:n,projectId:e.projectId}})).project?.devSession?.workflows??[];return new Map(t.flatMap(o=>o.tests.map(i=>[`${o.slug}/${i.slug}`,{testId:i.id,workflowId:o.id}])))}var nt=et(`
82
+ query DaemonWorkflows($projectId: String!, $cwd: String!) {
83
+ project(id: $projectId) {
84
+ id
85
+ devSession(cwd: $cwd) {
86
+ id
87
+ workflows {
88
+ id
89
+ slug
90
+ tests {
91
+ id
92
+ slug
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ `);import{CancellationTokenSource as rt}from"vscode-jsonrpc/node";function ve(e){return`${e.workflowSlug}/${e.testSlug}`}function Fn(e){let{headed:n,inflight:r,jobId:t,lockfileHashValue:o,onExpire:i,runId:l,selection:a,timeoutMs:s}=e,c=ve(a),d=`${c}@${o}@${String(n)}`,f=r.get(d);if(f!=null)return f.jobIds.add(t),null;let y={cancellation:new rt,claimed:!1,claimKey:c,headed:n,inflightKey:d,jobIds:new Set([t]),runId:l,testName:a.testName,timer:null,workflowName:a.workflowName};return y.timer=setTimeout(()=>{J(r,y),i(y)},s),r.set(d,y),y}function J(e,n){n.timer!=null&&(clearTimeout(n.timer),n.timer=null),e.delete(n.inflightKey)}function we(e,n){let r=[...e.values()].find(t=>t.runId===n&&!t.claimed);return r==null?null:(r.claimed=!0,r.timer!=null&&(clearTimeout(r.timer),r.timer=null),r)}function Mn(e,n){[...e.values()].filter(r=>r.jobIds.has(n)).forEach(r=>{r.jobIds.delete(n),r.jobIds.size===0&&(J(e,r),r.cancellation.cancel())})}import{err as xe,ok as $n}from"neverthrow";function Dn({all:e,ids:n,lockfile:r}){if(e&&n.length>0)return xe({kind:"conflicting-flags"});if(e)return $n(r.workflows.filter(i=>!i.stub).flatMap(i=>i.tests.map(l=>h(l))));if(n.length===0)return xe({kind:"nothing-selected"});let t=n.map(i=>({id:i,refs:ot(r,i)})),o=t.filter(i=>i.refs.length===0).map(i=>i.id);return o.length>0?xe({kind:"unknown-ids",known:tt(r),unknown:o}):$n([...new Set(t.flatMap(i=>i.refs))])}function Un(e,n){let r=new Map(P(e).map(t=>[t.ref,{testName:t.test.name,testSlug:t.test.slug,workflowName:t.workflow.name,workflowSlug:m(t.workflow.name)}]));return n.map(t=>{let o=r.get(t);if(o==null)throw new Error(`selectionsFor: ref not in lockfile: ${t}`);return o})}function tt(e){return e.workflows.map(n=>m(n.name))}function ot(e,n){let r=e.workflows.find(t=>t.name===n||m(t.name)===m(n));return r!=null?r.tests.map(t=>h(t)):P(e).filter(t=>t.ref===n||On(t.ref)===On(n)).map(t=>t.ref)}function On(e){let n=e.lastIndexOf("/");return n===-1?m(e):`${m(e.slice(0,n))}/${m(e.slice(n+1))}`}import{err as Ie,ok as Wn}from"neverthrow";import{graphql as Hn}from"gql.tada";import{graphql as pt}from"gql.tada";import{execFileSync as it}from"child_process";var at=256*1024*1024;function Q(e,n){return it("git",[...e],{cwd:n,encoding:"utf8",maxBuffer:at,stdio:["ignore","pipe","pipe"]})}import ct from"fs";import st from"fs";import be from"path";var lt=["MERGE_HEAD","rebase-merge","rebase-apply","CHERRY_PICK_HEAD","REVERT_HEAD"];function Ln(e){let n=dt(e);return n==null?!1:lt.some(r=>st.existsSync(be.join(n,r)))}function dt(e){try{let n=Q(["rev-parse","--git-dir"],e).trim();return n.length===0?null:be.isAbsolute(n)?n:be.resolve(e,n)}catch{return null}}function ut(e){return _e(e,"hooks-paused")}function _n(e){return ct.existsSync(ut(e))||Ln(e)?!1:an(e)}var ft=pt(`
99
+ mutation AutoScopeAddDirty($projectId: String!, $cwd: String!, $workflowSlugs: [String!]!) {
100
+ addDirtyTestsToScope(projectId: $projectId, cwd: $cwd, workflowSlugs: $workflowSlugs) {
101
+ __typename
102
+ ... on MutationAddDirtyTestsToScopeSuccess {
103
+ data {
104
+ id
105
+ }
106
+ }
107
+ }
108
+ }
109
+ `);async function Ya({cwd:e,lockfile:n}){if(!_n(e))return{addedSlugs:[]};let r=Ee(e);if(r.length===0)return{addedSlugs:[]};let t=new Set(r),o=n.workflows.filter(s=>s.sourcePath!=null&&t.has(s.sourcePath)).map(s=>m(s.name));if(o.length===0)return{addedSlugs:[]};let i=H(e).unwrapOr(void 0);return i==null?{addedSlugs:[]}:await w({config:i,cwd:e,lockfile:n}).catch(s=>(p.warn("auto-sync failed: %s",s instanceof Error?s.message:String(s)),null))==null?{addedSlugs:[]}:{addedSlugs:await yt({cfg:i,slugs:o})?o:[]}}async function yt({cfg:e,slugs:n}){let t=(await u({config:e,document:ft,variables:{cwd:e.cwd,projectId:e.projectId,workflowSlugs:[...n]}}).catch(o=>(p.warn("auto-scope failed: %s",o instanceof Error?o.message:String(o)),null)))?.addDirtyTestsToScope;return t?.__typename!=="MutationAddDirtyTestsToScopeSuccess"?!1:t.data.length>0}var Nn=".ripplo/workflows/",qn=" -> ";function Ee(e){let n;try{n=Q(["status","--porcelain","-uall","--",".ripplo/workflows"],e)}catch{return[]}return n.split(`
110
+ `).map(r=>r.slice(3).trim()).map(r=>r.includes(qn)?r.split(qn)[1]:r).filter(r=>r!=null).filter(r=>r.startsWith(Nn)&&r.endsWith(".ts")).map(r=>r.slice(Nn.length)).filter(r=>r!=="index.ts"&&!r.endsWith("/index.ts"))}async function Bn({config:e,cwd:n,lockfile:r}){await gt({config:e,cwd:n,lockfile:r});let t=await ht(e);if(t.isErr())return Ie(t.error);let o=new Map(r.workflows.filter(l=>!l.stub).map(l=>[m(l.name),l])),i=[...new Set(t.value)].flatMap(l=>{let a=o.get(l);return a==null?[]:a.tests.map(s=>h(s))});return i.length===0?Ie({kind:"scope-empty"}):Wn(i)}var mt=Hn(`
111
+ mutation AddDirtyTestsToScope($projectId: String!, $cwd: String!, $workflowSlugs: [String!]!) {
112
+ addDirtyTestsToScope(projectId: $projectId, cwd: $cwd, workflowSlugs: $workflowSlugs) {
113
+ __typename
114
+ }
115
+ }
116
+ `);async function gt({config:e,cwd:n,lockfile:r}){let t=new Set(Ee(n)),o=r.workflows.filter(i=>i.sourcePath!=null&&t.has(i.sourcePath)).map(i=>m(i.name));o.length!==0&&await u({config:e,document:mt,variables:{cwd:e.cwd,projectId:e.projectId,workflowSlugs:o}}).catch(i=>{p.warn({err:i},"auto-scope of dirty tests failed")})}var Rt=Hn(`
117
+ query ScopeSelection($projectId: String!, $cwd: String!) {
118
+ project(id: $projectId) {
119
+ id
120
+ devSession(cwd: $cwd) {
121
+ id
122
+ scopeItems {
123
+ id
124
+ workflow {
125
+ id
126
+ slug
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ `);async function ht(e){try{let r=(await u({config:e,document:Rt,variables:{cwd:e.cwd,projectId:e.projectId}})).project?.devSession?.scopeItems??[];return Wn(r.flatMap(t=>t.workflow==null?[]:[t.workflow.slug]))}catch(n){return Ie({detail:n instanceof Error?n.message:String(n),kind:"scope-fetch-failed"})}}import{graphql as kt}from"gql.tada";var St=2e3,vt=kt(`
133
+ query DaemonCloudRunStatus($runId: String!) {
134
+ run(id: $runId) {
135
+ status
136
+ failureReason
137
+ }
138
+ }
139
+ `);function Kn({config:e,onComplete:n,onStarted:r,runId:t,signal:o}){let i=!1,l,a=!1,s=async()=>{if(i||o.aborted)return;let c=await wt(e,t).catch(()=>"unknown");if(!(i||o.aborted)){if(!a&&(c==="running"||Vn(c))&&(a=!0,r()),Vn(c)){i=!0,n(xt(c));return}l=setTimeout(()=>{s()},St)}};return s(),{stop:()=>{i=!0,l!=null&&clearTimeout(l)}}}async function wt(e,n){let t=(await u({config:e,document:vt,variables:{runId:n}})).run?.status;return t??"unknown"}function Vn(e){return e==="passed"||e==="failed"||e==="cancelled"||e==="unready"}function xt(e){return e==="passed"?{kind:"pass"}:e==="failed"?{detail:"failed",kind:"error"}:e==="cancelled"?{detail:"cancelled",kind:"error"}:e==="unready"?{detail:"unready",kind:"error"}:{detail:"unknown",kind:"error"}}var Ct=12e4,At=-32099,Pe=new Set,Jn=new Map;function Es(e){Pe.add(e)}function Tt(e){let n=new AbortController;return e.isCancellationRequested?(n.abort(),n.signal):(e.onCancellationRequested(()=>{n.abort()}),n.signal)}function Is(e){let n={...e,inflight:new Map,jobs:new Map};return{claim:r=>Ot(n,r),handleConnection:r=>{jt(n,r)},idle:()=>Gn(n)}}function jt(e,n){let r=sn(n);r.onRequest(cn,(t,o)=>Ft({connection:r,ctx:e,params:t,token:o})),r.onRequest(un,()=>{let t=ge();return{active:t.active,queued:t.queued,sseHealth:e.sseHealth(),version:A(),...e.explorationStatus()}}),r.onRequest(pn,()=>{let t=Gn(e);return t&&e.onShutdownRequest(),t}),r.onClose(()=>{Mt(e,r)}),r.onError(t=>{p.warn({err:t},"ipc connection error")}),n.on("error",t=>{p.warn({err:t},"ipc socket error")}),r.listen()}function Gn(e){let n=ge();return e.jobs.size===0&&n.active===0&&n.queued===0}async function Ft({connection:e,ctx:n,params:r,token:t}){let o=ln.safeParse(r);if(!o.success)throw Qn({code:"bad-message"});await n.ready;let i=await Ut({config:n.config,cwd:n.cwd,message:o.data});if(i.kind==="error")throw Qn(i.error);let l=bt(),a=new It;return t.onCancellationRequested(()=>{Xn(n,l)}),n.jobs.set(l,{cancellation:a,connection:e,failed:0,notRun:0,passed:0,total:i.selections.length}),Kt({ctx:n,headed:o.data.headed,jobId:l,lockfileHashValue:i.lockfileHashValue,selections:i.selections,targetsByClaimKey:i.targetsByClaimKey,token:a.token}).catch(s=>{p.error({err:s},"ipc dispatch failed")}),{jobId:l,total:i.selections.length}}function Qn(e){return new Pt(At,e.code,e)}function Xn(e,n){let r=e.jobs.get(n);r!=null&&(r.cancellation.cancel(),e.jobs.delete(n),Mn(e.inflight,n))}function Mt(e,n){[...e.jobs.entries()].filter(([,r])=>r.connection===n).forEach(([r])=>{Xn(e,r)})}function Yn(e,n,r){let t=e.jobs.get(n);t!=null&&(zn(()=>t.connection.sendNotification(fn,{event:r,jobId:n})),r.kind==="test-outcome"&&($t(t,r.outcome.kind),t.passed+t.failed+t.notRun>=t.total&&(zn(()=>t.connection.sendNotification(yn,{failed:t.failed,jobId:n,notRun:t.notRun,passed:t.passed})),e.jobs.delete(n))))}function zn(e){Promise.resolve().then(e).catch(n=>{p.warn({err:n},"ipc notification failed")})}function $t(e,n){if(n==="pass"){e.passed+=1;return}if(n==="dispatch-error"||n==="dispatch-timeout"||n==="infra-error"){e.notRun+=1;return}e.failed+=1}function x(e,n,r){n.jobIds.forEach(t=>{Yn(e,t,r)})}function Ot(e,n){let r=we(e.inflight,n);return r==null?null:{headed:r.headed,token:r.cancellation.token,finished:(t,o)=>{e.inflight.delete(r.inflightKey),x(e,r,{kind:"test-outcome",outcome:o,runId:r.runId,testName:r.testName,workflowName:r.workflowName})},started:()=>{x(e,r,{kind:"test-started",runId:r.runId,testName:r.testName,workflowName:r.workflowName})}}}function Dt(e){return e.kind==="typecheck-failed"?e.diagnostics.slice(0,5):e.kind==="invalid-lockfile"?e.issues.slice(0,5):e.kind==="load-threw"?[e.message]:[]}async function Ut({config:e,cwd:n,message:r}){return(await Be(n)).match(o=>Lt({config:e,cwd:n,lockfile:o,message:r}),o=>Promise.resolve({error:{code:"compile-failed",detail:o.kind,diagnostics:[...Dt(o)]},kind:"error"}))}async function Lt({config:e,cwd:n,lockfile:r,message:t}){let o=await qt(e.appUrl);if(o!=null)return{error:{code:"app-unreachable",detail:o,url:e.appUrl},kind:"error"};let i=await Se(n);if(i==null)return{error:{code:"sync-failed",detail:"lockfile-missing"},kind:"error"};if(!Pe.has(i)){let a=await Wt({config:e,cwd:n,lockfile:r});if(a!=null)return{error:{code:"sync-failed",detail:a},kind:"error"};Pe.add(i)}return(await Ht({config:e,cwd:n,lockfile:r,message:t})).match(async a=>({kind:"ready",lockfileHashValue:i,selections:Un(r,a),targetsByClaimKey:await _t({config:e,cwd:n,hash:i})}),a=>Promise.resolve({error:a,kind:"error"}))}async function _t({config:e,cwd:n,hash:r}){let t=Jn.get(r);if(t!=null)return t;let o=await jn(e,n);return Jn.set(r,o),o}var Nt=2e3;async function qt(e){try{return await fetch(e,{method:"HEAD",signal:AbortSignal.timeout(Nt)}),null}catch(n){return n instanceof Error?n.message:String(n)}}async function Wt(e){try{return await w(e),null}catch(n){return n instanceof Error?n.message:String(n)}}async function Ht({config:e,cwd:n,lockfile:r,message:t}){return!t.all&&t.tests.length===0?(await Bn({config:e,cwd:n,lockfile:r})).mapErr(Bt):Dn({all:t.all,ids:t.tests,lockfile:r}).mapErr(Vt)}function Bt(e){return e.kind==="scope-empty"?{code:"selection-nothing-selected"}:{code:"scope-failed",detail:e.detail}}function Vt(e){switch(e.kind){case"conflicting-flags":return{code:"selection-conflicting-flags"};case"nothing-selected":return{code:"selection-nothing-selected"};case"unknown-ids":return{code:"selection-unknown-ids",known:[...e.known],unknown:[...e.unknown]}}}async function Kt(e){await e.selections.reduce((n,r)=>n.then(()=>Jt(e,r)),Promise.resolve())}async function Jt(e,n){let{ctx:r,headed:t,jobId:o,lockfileHashValue:i,targetsByClaimKey:l,token:a}=e;if(a.isCancellationRequested)return;let s=ve(n),c=l.get(s);if(c==null){Yn(r,o,{kind:"test-outcome",outcome:{kind:"dispatch-error",reason:{detail:"test-not-found",type:"generic"}},runId:"",testName:n.testName,workflowName:n.workflowName});return}let d=Fn({headed:t,inflight:r.inflight,jobId:o,lockfileHashValue:i,runId:Et(),selection:n,timeoutMs:Ct,onExpire:g=>{x(r,g,{kind:"test-outcome",outcome:{detail:"dispatch-timeout",kind:"dispatch-timeout"},runId:"",testName:g.testName,workflowName:g.workflowName})}});if(d==null)return;let f=r.executor(),y=await Qt({ctx:r,executor:f,lockfileHashValue:i,run:d,target:c});if(y!=null){J(r.inflight,d),x(r,d,{kind:"test-outcome",outcome:y,runId:"",testName:n.testName,workflowName:n.workflowName});return}f==="cloud"&&zt(r,d)}function Qt({ctx:e,executor:n,lockfileHashValue:r,run:t,target:o}){return Tn({config:e.config,executor:n,lockfileHash:r,runId:t.runId,target:o})}function zt(e,n){let r=we(e.inflight,n.runId);r!=null&&Kn({config:e.config,runId:r.runId,signal:Tt(r.cancellation.token),onComplete:t=>{e.inflight.delete(r.inflightKey),x(e,r,{kind:"test-outcome",outcome:t,runId:r.runId,testName:r.testName,workflowName:r.workflowName})},onStarted:()=>{x(e,r,{kind:"test-started",runId:r.runId,testName:r.testName,workflowName:r.workflowName})}})}import Gt from"fs";import Xt from"path";async function $s(e){let n=Xt.join(e,".ripplo","index.ts");if(!Gt.existsSync(n))return{appUrl:void 0,engineUrl:void 0,errors:[{message:".ripplo/index.ts not found",path:""}],valid:!1,warnings:[]};let r=await M(e);return r.isErr()?{appUrl:void 0,engineUrl:void 0,errors:[{message:$(r.error),path:".ripplo/"}],valid:!1,warnings:[]}:q().match(t=>({appUrl:t.appUrl,engineUrl:t.engineUrl,errors:[],valid:!0,warnings:[]}),t=>({appUrl:void 0,engineUrl:void 0,errors:[{message:fe(t),path:""}],valid:!1,warnings:[]}))}async function Os(e){try{await fetch(e,{method:"HEAD",signal:AbortSignal.timeout(5e3)});return}catch{return`appUrl (${e}) is not responding. Make sure your dev server is running on that port.`}}async function Ds({appUrl:e,engineUrl:n}){let r=n.startsWith("http://")||n.startsWith("https://")?n:`${e}${n}`;try{return(await fetch(`${r}/setup`,{body:JSON.stringify({}),headers:{"Content-Type":"application/json"},method:"PUT",signal:AbortSignal.timeout(5e3)})).ok?"Engine endpoint accepted an unsigned request \u2014 webhook signature verification may be missing.":void 0}catch{return}}function Yt(e){let{backoffActive:n,exploreEnabled:r,headedActive:t,interactiveActive:o,interactiveQueued:i}=e,{explorationActive:l,exploreConcurrency:a,poolSize:s}=e;if(!r||t||i>0)return{abortCount:l,refillCount:0};if(n)return{abortCount:0,refillCount:0};let c=Math.min(a,s-1,s-o);return{abortCount:0,refillCount:Math.max(0,c-l)}}function Ls(e){let n={active:new Map,backoffUntil:0,cancelBackoffTimer:null,cancelHeartbeat:null,prevInteractiveActive:e.probe().interactiveActive,stopped:!1};return nr(n,e),{explorationActive:()=>n.active.size,notifyQueueChange:()=>{Zt(n,e)},stop:()=>{n.stopped=!0,n.cancelBackoffTimer?.(),n.cancelBackoffTimer=null,n.cancelHeartbeat?.(),n.cancelHeartbeat=null,rr(n,n.active.size)}}}function nr(e,n){e.stopped||(e.cancelHeartbeat=n.setTimer(()=>{z(e,n),nr(e,n)},15e3))}function z(e,n){if(e.stopped)return;let r=n.probe(),t=Yt({backoffActive:n.now()<e.backoffUntil,explorationActive:e.active.size,exploreConcurrency:n.exploreConcurrency(),exploreEnabled:n.exploreEnabled(),headedActive:r.headedActive>0,interactiveActive:r.interactiveActive,interactiveQueued:r.interactiveQueued,poolSize:r.poolSize});rr(e,t.abortCount),tr({count:t.refillCount,params:n,state:e})}function rr(e,n){[...e.active.values()].slice(0,n).forEach(({controller:r})=>{r.abort()})}function Zt(e,n){let r=n.probe();r.interactiveActive<e.prevInteractiveActive&&eo(e,n),e.prevInteractiveActive=r.interactiveActive,z(e,n)}function eo(e,n){e.backoffUntil=n.now()+3e4,e.cancelBackoffTimer?.(),e.cancelBackoffTimer=n.setTimer(()=>{e.cancelBackoffTimer=null,z(e,n)},3e4)}function tr({count:e,params:n,state:r}){if(e<=0)return;let t=no(n.sources);t!=null&&(ro({params:n,pulled:t,state:r}),tr({count:e-1,params:n,state:r}))}function no(e){return e.reduce((n,r)=>{if(n!=null)return n;let t=r.next();return t==null?null:{job:t,source:r}},null)}function ro({params:e,pulled:n,state:r}){let{job:t,source:o}=n,i=new AbortController;r.active.set(t.id,{controller:i,job:t,source:o}),e.execute({job:t,priority:o.priority,signal:i.signal}).then(()=>{er({job:t,outcome:Zn(i.signal,null),params:e,source:o,state:r})}).catch(l=>{er({job:t,outcome:Zn(i.signal,{error:l}),params:e,source:o,state:r})})}function Zn(e,n){return e.aborted?{kind:"aborted"}:n==null?{kind:"completed"}:{error:n.error,kind:"error"}}function er({job:e,outcome:n,params:r,source:t,state:o}){o.active.delete(e.id),t.onResult(e,n),z(o,r)}import{createMessageConnection as or,IPCMessageReader as ir,IPCMessageWriter as ar,NotificationType as to,NotificationType0 as sr,RequestType as lr,RequestType0 as oo}from"vscode-jsonrpc/node";import{z as R}from"zod";var Bs=R.object({headed:R.boolean(),runId:R.string().min(1),testRef:R.string().min(1)}),Vs=R.object({lockfileJson:R.string().optional(),unavailable:R.string().optional()}),Ks=R.object({runId:R.string().min(1),span:qe}),Js=R.object({outcome:dn,serverNotified:R.boolean()}),Qs=new sr("worker/ready"),zs=new lr("worker/run"),Gs=new oo("worker/lockfile"),Xs=new lr("worker/exploreTrail"),Ys=new to("worker/span"),Zs=new sr("worker/shutdown");function el(e){let n=or(new ir(e),new ar(e));return n.listen(),n}function nl(){let e=or(new ir(process),new ar(process));return e.listen(),e}import{gzipSync as yo}from"zlib";import{appendFileSync as mo,existsSync as X,readFileSync as fr,writeFileSync as pr}from"fs";import S from"path";import{graphql as Ae}from"gql.tada";function G(e){return[e.kind,e.target,e.value].filter(n=>n.length>0).join(" ")}function dr(e,n){return{kind:"finding",payload:lo(e),source:"verifier",step:n.step,stepIndex:n.stepIndex,timeNanos:n.timeNanos}}var io={"no-effect":"noEffect","required-state-unsatisfied":"requiredStateUnsatisfied",unresolvable:"unresolvable"},ao={"data-rule":"dataRule",fact:"fact",step:"step"},so={aborted:"aborted","action-failed":"actionFailed","app-not-ready":"appNotReady","check-failed":"checkFailed","client-mount-missing":"clientMountMissing","conflicting-sessions":"conflictingSessions","driver-launch":"driverLaunch","engine-decode":"engineDecode","engine-http":"engineHttp","engine-network":"engineNetwork","engine-unreachable":"engineUnreachable","setup-missing-row":"setupMissingRow","state-identity":"stateIdentity"};function lo(e){return e.kind==="consistency"?{kind:"mismatch",mismatch:fo(e.mismatch),pending:e.pending,wait:e.budget,waitMs:se[e.budget]}:e.kind==="pending-check"?{...co(e.source),kind:"pendingCheck",source:ao[e.source.kind],wait:e.budget,waitMs:se[e.budget]}:e.kind==="unrunnable"?{kind:"unrunnable",reason:io[e.reason]}:e.kind==="impossible-action"?{action:uo(e.step.action),kind:"impossibleAction",subject:ur(e.step.action)}:e.kind==="lift-visibility"?{declaredIndex:e.declaredIndex,kind:"liftVisibility",subject:I(e.locator),visibleIndex:e.visibleIndex}:{errorKind:so[e.error.kind],kind:"driverError",message:po(e.error)}}function co(e){return"check"in e?cr(e.check,!1):{checkKind:null,expected:null,negated:!1,subject:Xe(e.dataRule)}}function cr(e,n){return e.kind==="not"?cr(e.inner,!n):e.kind==="browser"?{checkKind:"browser",expected:e.value??null,negated:n,subject:Je(e.key)}:e.kind==="value"||e.kind==="text"?{checkKind:e.kind,expected:e.value,negated:n,subject:I(e.locator)}:{checkKind:e.kind,expected:null,negated:n,subject:I(e.locator)}}function uo(e){return`${e.kind} ${ur(e)}`.trim()}function ur(e){return e.locator==null?e.url??"":I(e.locator)}function po(e){return"message"in e?e.message:"detail"in e?e.detail:null}function fo(e){if(e.kind==="wrong-value")return{actual:v(e.sut),entity:e.entity,expected:v(e.snapshot),field:e.field,key:e.key,kind:"wrongValue"};if(e.kind==="expected-change"){let n=e.direction==null?"change":e.direction.replace(/d$/,"");return{actual:v(e.value),entity:e.entity,expected:`${n} from ${v(e.from)}`,field:e.field,key:e.key,kind:"expectedChange"}}return e.kind==="scalar-mismatch"?{actual:v(e.sut),expected:Ye(e.want),kind:"scalarMismatch",subject:Ge(e.subject)}:e.kind==="missing-row"?{entity:e.entity,key:e.key,kind:"missingRow"}:{entity:e.entity,key:e.key,kind:"unexpectedRow"}}function Z({config:e,fixturesDir:n,headed:r}){return{baseUrl:e.appUrl,engineUrl:e.engineUrl,fixturesDir:n,generate:T,headed:r,secret:e.webhookSecret}}async function Te(e){let n=ee(e);await je(e.config,e.runId,n)}function ee({debugDir:e,events:n,recordingOptional:r,runId:t,stepSources:o}){let i=Fe(n),l=xo(e,t);if(l==null&&!r)throw new Error("recording-missing");let a=i.map((c,d)=>$o({aliases:[...Io(n),...Po(i)],generated:Co(n),generatedSingletons:Ao(n),origin:l==null?wo(i):l.origin,record:c,rrwebEvents:l==null?[]:l.events,sourceTest:o?.[d]??null})),s=i.flatMap(c=>c.findings.map(d=>dr(d,{step:G(j(c.source,c.index)),stepIndex:c.index,timeNanos:yr(c)})));return go({debugDir:e,events:[...a,...s],runId:t}),i}function go({debugDir:e,events:n,runId:r}){if(n.length===0)return;let t=S.join(e,r,"behavior.jsonl");if(!X(t))return;let o=n.map(i=>JSON.stringify(i)).join(`
140
+ `);mo(t,`${o}
141
+ `)}function yr(e){return String(BigInt(Math.max(0,Math.round(e.endMs)))*1000000n)}async function je(e,n,r){let t=r.filter(l=>l.findings.length>0).length,o=r.length-t,i=r.reduce((l,a)=>l+Math.max(0,a.endMs-a.startMs),0);await u({config:e,document:Uo,variables:{items:[{duration:i,failCount:t,firstFailedStepTitle:Ro(r),passCount:o,runId:n,status:t>0?"failed":"passed"}]}})}function Ro(e){let n=e.filter(r=>r.findings.length>0).toSorted((r,t)=>r.index-t.index).at(0);return n==null?null:G(j(n.source,n.index))}function Fe(e){return e.flatMap(n=>n.kind==="step"?[{annotations:n.annotations,endMs:n.endMs,findings:n.findings,index:n.index,source:n.source,startMs:n.startMs,state:n.state,url:n.url}]:[])}async function mr(e,n){await u({config:e,document:Lo,variables:{runIds:[n]}})}var Y=".uploaded";async function ho({config:e,debugDir:n,runId:r}){let t=S.join(n,r),o=S.join(t,"behavior.jsonl");if(X(S.join(t,Y)))return;if(!X(o)){p.warn({runId:r},"behavior upload skipped: behavior.jsonl missing on disk");return}await[0,1e3,3e3].reduce((l,a)=>l.then(async s=>s?!0:(await new Promise(c=>setTimeout(c,a)),ko({behaviorPath:o,config:e,runDir:t,runId:r}))),Promise.resolve(!1))}async function ko({behaviorPath:e,config:n,runDir:r,runId:t}){try{let o=await u({config:n,document:Do,variables:{runId:t}}),i=await fetch(o.debugArtifactUploadUrl,{body:yo(fr(e)),headers:{"content-type":vo},method:"PUT"});return i.ok?(await mr(n,t),pr(S.join(r,Y),""),!0):(p.warn({runId:t,status:i.status},"behavior upload PUT failed"),!1)}catch(o){return So(o)?(p.warn({runId:t},"behavior upload refused by server; run unknown \u2014 not retrying"),pr(S.join(r,Y),""),!0):(p.warn({error:o,runId:t},"behavior upload failed"),!1)}}function So(e){if(typeof e!="object"||e==null||!("errors"in e))return!1;let{errors:n}=e;return Array.isArray(n)&&n.some(r=>{if(typeof r!="object"||r==null||!("extensions"in r))return!1;let{extensions:t}=r;return typeof t=="object"&&t!=null&&"code"in t&&t.code==="FORBIDDEN"})}var vo="application/x-ndjson";function wo(e){return e.reduce((n,r)=>Math.min(n,r.startMs),e[0]?.startMs??0)}function xo(e,n){let r=S.join(e,n,"behavior.jsonl");if(!X(r))return null;let t=fr(r,"utf8").split(`
142
+ `).filter(i=>i.length>0).map(i=>bo(i)).flatMap(i=>Eo(i)?[i.event]:[]),o=t[0];return o==null?null:{events:t,origin:o.timestamp}}function bo(e){return JSON.parse(e)}function Eo(e){return typeof e=="object"&&e!=null&&Reflect.get(e,"kind")==="rrweb"}function Io(e){return e.flatMap(n=>n.kind==="world"?n.aliases:[])}function Po(e){return e.flatMap(n=>{let r=To(n.source);return r.flatMap(t=>{let i=r.filter(a=>a.entity===t.entity).indexOf(t),l=n.state.rows.filter(a=>a.status==="created"&&a.entity===t.entity).at(i);return l==null?[]:[{alias:t.as,entity:t.entity,key:l.key}]})})}function Co(e){return new Set(e.flatMap(n=>n.kind==="world"?n.generated.map(r=>gr(r)):[]))}function gr({entity:e,field:n,key:r}){return`${e} ${r} ${n}`}function Ao(e){return new Set(e.flatMap(n=>n.kind==="world"?n.generatedSingletons:[]))}function To(e){return e==null?[]:e.expect.flatMap(n=>Ce(n))}function Ce(e){return e.kind==="state"&&e.assertion.kind==="created"?[{as:e.assertion.as,entity:e.entity}]:e.kind==="and"?e.predicates.flatMap(n=>Ce(n)):e.kind==="when"?e.branches.flatMap(n=>n.consequence.flatMap(r=>Ce(r))):[]}var jo=3,Fo=0;function Mo({endMs:e,rrwebEvents:n,startMs:r}){let t=n.find(o=>o.type===jo&&o.data?.source===Fo&&o.timestamp>=r&&o.timestamp<=e);return t==null?r:t.timestamp}function $o({aliases:e,generated:n,generatedSingletons:r,origin:t,record:o,rrwebEvents:i,sourceTest:l}){let a=j(o.source,o.index),s=Mo({endMs:o.endMs,rrwebEvents:i,startMs:o.startMs});return{annotations:[...o.annotations.map(d=>({ephemeral:d.ephemeral,kind:d.kind,label:d.label,outcome:d.outcome,recordingStartMs:Math.max(0,(d.kind==="action"?s:d.atMs)-t),rrwebIds:[...d.rrwebIds],url:d.url,value:d.value??null}))],duration:Math.max(0,o.endMs-o.startMs),kind:"step",nodeType:a.kind,pageUrl:o.url,recordingEndMs:Math.max(0,o.endMs-t),recordingStartMs:Math.max(0,s-t),source:"verifier",sourceTest:l,stateRows:o.state.rows.map(d=>Oo({aliases:e,generated:n,row:d})),stateSingletons:o.state.singletons.map(d=>({changed:d.changed,generated:r.has(d.name),name:d.name,value:d.value==null?null:String(d.value)})),stepIndex:o.index,timeNanos:yr(o),title:G(a)}}function Oo({aliases:e,generated:n,row:r}){let t=e.find(o=>o.entity===r.entity&&o.key===r.key);return{entity:r.entity,fields:r.fields.map(o=>({changed:o.changed,field:o.field,generated:n.has(gr({entity:r.entity,field:o.field,key:r.key})),value:o.value==null?null:String(o.value)})),key:r.key,label:t?.alias??r.key,status:r.status}}var Do=Ae(`
143
+ mutation DebugArtifactUploadUrl($runId: String!) {
144
+ debugArtifactUploadUrl(runId: $runId)
145
+ }
146
+ `),Uo=Ae(`
147
+ mutation CompleteRunsBatch($items: [CompleteRunItem!]!) {
148
+ completeRunsBatch(items: $items) {
149
+ id
150
+ status
151
+ }
152
+ }
153
+ `),Lo=Ae(`
154
+ mutation MarkRunArtifactsUploadedBatch($runIds: [String!]!) {
155
+ markRunArtifactsUploadedBatch(runIds: $runIds)
156
+ }
157
+ `);import{graphql as b}from"gql.tada";function _o(e){let n=e.trail;if(!(n==null||!No(e.kind)))return{baseLabel:n.baseLabel,baseState:n.baseState,durationMs:n.durationMs,outcome:e.kind,runId:e.runId,signature:n.signature,steps:n.steps}}function No(e){return e==="clean"||e==="flaky"||e==="finding"}async function Me({baseState:e,category:n,config:r,debugDir:t,devSessionId:o,events:i,lockfileHash:l,reproJson:a,runId:s,signature:c,spec:d,stepSources:f,summary:y,workflowSlug:g}){await u({config:r,document:Vo,variables:{devSessionId:o??null,lockfileHash:l??null,projectId:r.projectId,reproJson:a,runId:s,spec:d??null,workflowSlug:g??null}}),await Te({config:r,debugDir:t,events:i,recordingOptional:!0,runId:s,stepSources:f}),await u({config:r,document:Ko,variables:{baseState:e,category:n,projectId:r.projectId,reproRunId:s,signature:c,summary:y}})}async function ne(e,n,r){return(await u({config:e,document:Jo,variables:{lockfileHash:r,projectId:e.projectId,signature:n}})).exploreFindingExists}async function qo({attempts:e,config:n,devSessionId:r,findings:t,trail:o}){await u({config:n,document:Ho,variables:{attempts:e,devSessionId:r,findings:t,trail:o==null?null:{baseLabel:o.baseLabel,baseState:o.baseState,durationMs:o.durationMs,findingRunId:o.runId??null,findingSignature:o.signature??null,outcome:o.outcome,steps:o.steps.map(i=>({test:i.test,text:i.text}))}}})}async function Wo(e,n){return(await u({config:e,document:Bo,variables:{devSessionId:n}}).catch(t=>(p.warn({error:t},"reportExploreUnhealthy failed"),null)))?.reportExploreUnhealthy??!1}var Ho=b(`
158
+ mutation RecordExplorationProgress(
159
+ $devSessionId: String!
160
+ $attempts: Int!
161
+ $findings: Int!
162
+ $trail: ExploreTrailInput
163
+ ) {
164
+ recordExplorationProgress(
165
+ devSessionId: $devSessionId
166
+ attempts: $attempts
167
+ findings: $findings
168
+ trail: $trail
169
+ )
170
+ }
171
+ `),Bo=b(`
172
+ mutation ReportExploreUnhealthy($devSessionId: String!) {
173
+ reportExploreUnhealthy(devSessionId: $devSessionId)
174
+ }
175
+ `),Vo=b(`
176
+ mutation CreateExploreRun(
177
+ $projectId: String!
178
+ $runId: String!
179
+ $devSessionId: String
180
+ $lockfileHash: String
181
+ $spec: String
182
+ $reproJson: String
183
+ $workflowSlug: String
184
+ ) {
185
+ createExploreRun(
186
+ projectId: $projectId
187
+ runId: $runId
188
+ devSessionId: $devSessionId
189
+ lockfileHash: $lockfileHash
190
+ spec: $spec
191
+ reproJson: $reproJson
192
+ workflowSlug: $workflowSlug
193
+ ) {
194
+ id
195
+ }
196
+ }
197
+ `),Ko=b(`
198
+ mutation SubmitExploreFinding(
199
+ $projectId: String!
200
+ $signature: String!
201
+ $summary: String!
202
+ $baseState: String!
203
+ $category: ExploreFindingCategory!
204
+ $reproRunId: String!
205
+ ) {
206
+ submitExploreFinding(
207
+ projectId: $projectId
208
+ signature: $signature
209
+ summary: $summary
210
+ baseState: $baseState
211
+ category: $category
212
+ reproRunId: $reproRunId
213
+ ) {
214
+ id
215
+ }
216
+ }
217
+ `),Sl=b(`
218
+ mutation SetExploreFindingStatus(
219
+ $projectId: String!
220
+ $signature: String!
221
+ $status: ExploreFindingStatus!
222
+ ) {
223
+ setExploreFindingStatus(projectId: $projectId, signature: $signature, status: $status)
224
+ }
225
+ `),Jo=b(`
226
+ query ExploreFindingExists($projectId: String!, $signature: String!, $lockfileHash: String!) {
227
+ exploreFindingExists(projectId: $projectId, signature: $signature, lockfileHash: $lockfileHash)
228
+ }
229
+ `);import Go from"path";import{graphql as Xo}from"gql.tada";import{graphql as re}from"gql.tada";function $e(e){switch(e.kind){case"app-not-ready":return"appNotReady";case"client-mount-missing":return"appNotReady";case"engine-network":case"engine-http":return"backendUnreachable";case"engine-unreachable":return"engineUnreachable";case"engine-decode":case"state-identity":case"setup-missing-row":case"conflicting-sessions":case"driver-launch":case"action-failed":case"check-failed":case"aborted":return null}}async function Oe(e,n,r){await u({config:e,document:Qo,variables:{reason:r,runId:n}}).catch(t=>{p.error(t,"failRun submission failed")})}async function De(e,n,r){await u({config:e,document:zo,variables:{cause:r,runId:n}}).catch(t=>{p.error(t,"markRunUnready submission failed")})}var bl=re(`
230
+ mutation ReleaseRun($runId: String!) {
231
+ releaseRun(runId: $runId)
232
+ }
233
+ `),El=re(`
234
+ mutation HeartbeatRun($runId: String!) {
235
+ heartbeatRun(runId: $runId)
236
+ }
237
+ `),Qo=re(`
238
+ mutation FailRun($runId: String!, $reason: String!) {
239
+ failRun(runId: $runId, reason: $reason)
240
+ }
241
+ `),zo=re(`
242
+ mutation MarkRunUnready($runId: String!, $cause: RunUnreadyCause!) {
243
+ markRunUnready(runId: $runId, cause: $cause)
244
+ }
245
+ `);async function Yo({config:e,cwd:n,errorSettle:r,fixturesDir:t,headed:o,lockfile:i,onPhase:l,runId:a,session:s,signal:c,test:d}){if(!await ei(e,a))return{outcome:{kind:"dispatch-failed",reason:"already-claimed",runId:a},persisted:Promise.resolve()};let y=Go.join(n,".ripplo","debug"),g=[];return(await s.runOnce({capture:!0,lockfile:i,onPhase:l,options:Z({config:e,fixturesDir:t,headed:o}),params:void 0,runId:a,sequence:void 0,test:d,onEvent:E=>{g.push(E)}},c)).match(async E=>{let Ue=Fe(g),ie=Ue.flatMap(wr=>wr.findings),ae=Zo(ie);if(ae!=null)return ee({config:e,debugDir:y,events:g,recordingOptional:!0,runId:a,stepSources:void 0}),await Rr({config:e,error:ae,errorSettle:r,runId:a}),{outcome:{error:ae,kind:"error",runId:a},persisted:Promise.resolve()};await je(e,a,Ue),ee({config:e,debugDir:y,events:g,recordingOptional:!0,runId:a,stepSources:void 0});let vr=Promise.resolve();return{outcome:ie.length>0?{findings:ie,kind:"findings",runId:a}:{kind:"pass",runId:a},persisted:vr}},async E=>(await Rr({config:e,error:E,errorSettle:r,runId:a}),{outcome:{error:E,kind:"error",runId:a},persisted:Promise.resolve()}))}async function Rr({config:e,error:n,errorSettle:r,runId:t}){if(r==="defer")return;let o=$e(n);if(o!=null){await De(e,t,o);return}await Oe(e,t,O(n))}function Zo(e){let n=e.find(r=>r.kind==="driver-error"&&ze(r.error));return n!=null&&n.kind==="driver-error"?n.error:void 0}async function ei(e,n){return((await u({config:e,document:ni,variables:{runIds:[n]}})).startRunsBatch??[]).some(t=>t.id===n)}var ni=Xo(`
246
+ mutation StartRunsBatch($runIds: [String!]!) {
247
+ startRunsBatch(runIds: $runIds) {
248
+ id
249
+ }
250
+ }
251
+ `);import{randomUUID as ri}from"crypto";async function ti({assign:e,config:n,debugDir:r,devSessionId:t,fixturesDir:o,headed:i,lockfile:l,report:a,session:s,signal:c}){let d=Qe(l);if(e.stepRuns.length===0)return{kind:"error",reason:"empty-trail"};let f=fi(d,e.stepRuns),y=await tn({baseState:{name:h(e.baseStateTest),test:e.baseStateTest},corpus:d,lockfile:l,options:Z({config:n,fixturesDir:o,headed:i}),seenSignature:a?C=>ne(n,C,e.lockfileHash):void 0,session:s,stepRuns:e.stepRuns,runIdFor:C=>`explore-${ri()}-${String(C)}`},c),g=a?await di({baseStateTest:e.baseStateTest,config:n,debugDir:r,devSessionId:t,lockfileHash:e.lockfileHash,outcome:y,reproJson:si(d,e),stepSources:li(f)}):!1;return ai(y,f.length),yi(y,g,oi(f,e,y))}function oi(e,n,r){if(r.kind==="error"||r.kind==="aborted")return;let t=r.timing.confirm;return{baseLabel:n.baseStateTest.intent,baseState:h(n.baseStateTest),durationMs:Math.round(te(r.timing.detect)+(t==null?0:te(t))),signature:r.kind==="finding"||r.kind==="seen"?r.signature:void 0,steps:ii(e.slice(0,r.ranCount))}}function ii(e){return e.flatMap(n=>{let r=n.label.split("#")[0]??n.label;return n.actions.map(t=>({test:r,text:t}))})}function te(e){return e.engineMs+e.worldMs+e.browserMs+e.driveMs+e.teardownMs}function ai(e,n){if(e.kind==="error"){p.info({detail:O(e.error),kind:e.kind,reason:e.error.kind,steps:n},"explore trail");return}if(e.kind==="aborted"||e.kind==="seen"){p.info({kind:e.kind,steps:n},"explore trail");return}let r=e.timing.detect,t=e.timing.confirm;p.info({browserMs:r.browserMs,confirmMs:t==null?void 0:te(t),detectMs:te(r),driveMs:r.driveMs,engineMs:r.engineMs,kind:e.kind,steps:n,teardownMs:r.teardownMs,worldMs:r.worldMs},"explore trail")}function si(e,n){let r=n.stepRuns.flatMap(o=>{let i=e[o.idx];return i==null?[]:[{index:i.index,params:o.params,test:i.test}]}),t={baseStateRef:h(n.baseStateTest),steps:r};return JSON.stringify(t)}function li(e){return e.flatMap(n=>{let r=n.label.split("#")[0]??n.label;return n.actions.map(()=>r)})}async function di({baseStateTest:e,config:n,debugDir:r,devSessionId:t,lockfileHash:o,outcome:i,reproJson:l,stepSources:a}){return i.kind!=="finding"||i.captureEvents.length===0?!1:await ne(n,i.signature,o)?(p.info({devSessionId:t,signature:i.signature},"explore finding already reported, skipping duplicate"),!1):(await Me({baseState:i.baseState,category:ci(i.verifierLayer),config:n,debugDir:r,devSessionId:t,events:i.captureEvents,lockfileHash:o,reproJson:l,runId:i.runId,signature:i.signature,spec:pi(e,i.captureEvents),stepSources:a,summary:ui(i.captureEvents,i.title),workflowSlug:i.sourceTest?.split("/")[0]}).catch(s=>{p.warn({error:s},"explore finding report failed")}),!0)}function ci(e){return e==="data-rule"?"dataRule":e==="model-drift"?"modelDrift":e}function ui(e,n){let r=e.flatMap(t=>t.kind==="step"?[...t.findings]:[]).at(0);if(r!=null)return Ze(r);if(n!=null)return n;throw new Error("explore finding has no findings to summarize")}function pi(e,n){let r=n.flatMap(o=>o.kind==="step"?[o.source]:[]),t={absent:e.absent,actor:e.actor,exclusive:e.exclusive,intent:e.intent,maybe:[],name:e.name,params:e.params,singletons:e.singletons,steps:r,stub:!1,tests:[],world:e.world};return JSON.stringify(t)}function fi(e,n){return n.flatMap(r=>{let t=e[r.idx];return t==null?[]:[{actions:[...t.nav,...t.steps].map(o=>en(o.action)),label:`${t.test}#${String(t.index)}`}]})}function yi(e,n,r){return e.kind==="error"?{kind:e.kind,reason:`runtime:${e.error.kind}`}:e.kind==="finding"?{kind:e.kind,runId:n?e.runId:void 0,trail:r}:{kind:e.kind,trail:r}}import mi from"path";import{randomUUID as gi}from"crypto";async function nd({cwd:e,onReady:n,signal:r,step:t,target:o}){let i=H(e).match(f=>({config:f}),f=>({failure:f}));if("failure"in i)return{failure:i.failure,kind:"config-failed"};let l=i.config,a=await Ve(e);if(a.result.isErr())return{error:a.result.error,kind:"compile-failed"};let s=a.result.value,c=await Ri(s,o);return c.kind!=="ok"?c:(await nn({lockfile:s,onReady:n,options:hi(l),runId:`teleport-${gi()}`,sequence:c.sequence,stopAfterStep:t,test:c.test},r)).match(f=>({kind:"done",result:f}),f=>({error:f,kind:"run-failed"}))}async function Ri(e,n){if(n.kind==="explore"){let t=await on(e,n.repro);return t.kind==="unplannable"?{kind:"unplannable"}:{kind:"ok",sequence:t.sequence,test:t.baseTest}}let r=P(e).find(t=>t.ref===n.ref);return r==null?{kind:"no-test",ref:n.ref}:{kind:"ok",sequence:rn(e,r.test,void 0),test:r.test}}function hi(e){return{baseUrl:e.appUrl,engineUrl:e.engineUrl,fixturesDir:mi.join(e.cwd,F),generate:T,headed:!0,secret:e.webhookSecret}}import{graphql as hr}from"gql.tada";import{err as oe,ok as kr}from"neverthrow";var ki=hr(`
252
+ query ExecutorSession($projectId: String!, $cwd: String!) {
253
+ project(id: $projectId) {
254
+ id
255
+ devSession(cwd: $cwd) {
256
+ id
257
+ executor
258
+ }
259
+ }
260
+ }
261
+ `),Si=hr(`
262
+ mutation SetDevSessionExecutor($devSessionId: String!, $executor: RunExecutor!) {
263
+ setDevSessionExecutor(devSessionId: $devSessionId, executor: $executor) {
264
+ __typename
265
+ ... on DevSession {
266
+ id
267
+ executor
268
+ }
269
+ ... on DevSessionEndedError {
270
+ message
271
+ }
272
+ }
273
+ }
274
+ `);async function ad(e){return(await Sr(e)).map(r=>r.executor)}async function sd(e,n){let r=await Sr(e);if(r.isErr())return oe(r.error);let o=(await u({config:e,document:Si,variables:{devSessionId:r.value.id,executor:n}})).setDevSessionExecutor;return o==null?oe({kind:"empty-response"}):o.__typename!=="DevSession"?oe({kind:"session-ended"}):kr(o.executor)}async function Sr(e){let r=(await u({config:e,document:ki,variables:{cwd:e.cwd,projectId:e.projectId}})).project?.devSession;return r==null?oe({kind:"no-session"}):kr({executor:r.executor,id:r.id})}export{Ii as a,$i as b,q as c,Tr as d,Ni as e,fe as f,Sn as g,wn as h,H as i,Q as j,Ln as k,$s as l,Os as m,Ds as n,ut as o,_n as p,Ls as q,Bs as r,Ks as s,Js as t,Qs as u,zs as v,Gs as w,Xs as x,Ys as y,Zs as z,el as A,nl as B,na as C,ra as D,ge as E,ta as F,In as G,ha as H,w as I,ka as J,Se as K,Ya as L,Es as M,Tt as N,Is as O,Y as P,ho as Q,Oe as R,Yo as S,_o as T,qo as U,Wo as V,ti as W,nd as X,ad as Y,sd as Z};