ripplo 0.7.44 → 0.7.45

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