(target: "selfhost" | "cloud", flags: ReadonlySet<string>)
| 190 | // The detached runner: boots the target, owns it (cloud's emulators live in |
| 191 | // this process), writes the state file, and tears down on SIGTERM. |
| 192 | const run = async (target: "selfhost" | "cloud", flags: ReadonlySet<string>) => { |
| 193 | const share = flags.has("--share"); |
| 194 | const logFile = process.env.E2E_CLI_LOG ?? join(devDir, `${target}.log`); |
| 195 | const base: Omit<InstanceState, "status"> = { |
| 196 | target, |
| 197 | runnerPid: process.pid, |
| 198 | logFile, |
| 199 | startedAt: new Date().toISOString(), |
| 200 | }; |
| 201 | writeState({ ...base, status: "starting" }); |
| 202 | |
| 203 | try { |
| 204 | let state: InstanceState; |
| 205 | let teardown: () => Promise<void>; |
| 206 | |
| 207 | // Claim ports atomically from this checkout's block (src/ports.ts) — the |
| 208 | // held block lock doubles as "this instance is deliberate, not a leak", |
| 209 | // and a concurrently running vitest suite walks to its own block. |
| 210 | const { claimPorts } = await import("../src/ports"); |
| 211 | |
| 212 | if (target === "selfhost") { |
| 213 | const { bootSelfhost } = await import("../setup/selfhost.boot"); |
| 214 | const claim = await claimPorts([ |
| 215 | { envVar: "E2E_SELFHOST_PORT", offset: 4, label: "selfhost vite dev (cli)" }, |
| 216 | ]); |
| 217 | const port = claim.ports.E2E_SELFHOST_PORT!; |
| 218 | const ip = share ? tailnetIp() : undefined; |
| 219 | const baseUrl = ip ? `http://${ip}:${port}` : `http://localhost:${port}`; |
| 220 | const admin = { email: "admin@e2e.test", password: "e2e-admin-password-123" }; |
| 221 | const booted = await bootSelfhost({ |
| 222 | port, |
| 223 | webBaseUrl: baseUrl, |
| 224 | admin, |
| 225 | host: share ? "0.0.0.0" : undefined, |
| 226 | fresh: !flags.has("--keep-data"), |
| 227 | logFile, |
| 228 | }); |
| 229 | teardown = async () => { |
| 230 | await booted.teardown(); |
| 231 | await claim.release(); |
| 232 | }; |
| 233 | state = { |
| 234 | ...base, |
| 235 | status: "ready", |
| 236 | childPids: booted.pids, |
| 237 | env: { |
| 238 | E2E_TARGET: "selfhost", |
| 239 | E2E_SELFHOST_URL: baseUrl, |
| 240 | E2E_SELFHOST_ADMIN_EMAIL: admin.email, |
| 241 | E2E_SELFHOST_ADMIN_PASSWORD: admin.password, |
| 242 | }, |
| 243 | urls: { app: baseUrl }, |
| 244 | admin, |
| 245 | }; |
| 246 | } else { |
| 247 | const { bootCloud } = await import("../setup/cloud.boot"); |
| 248 | const claim = await claimPorts([ |
| 249 | { envVar: "E2E_CLOUD_PORT", offset: 0, label: "cloud vite dev (cli)" }, |
no test coverage detected