/** Opt-in, credential-free browser smoke: teardown retains its authenticated API client. */ import { spawn } from "node:child_process"; import { createServer } from "node:http"; import path from "node:path"; import { parseConnectionConfig } from "./connection-config.js"; import { openConnectionBrowser } from "./connection-launch.js"; import { runnerE2ETypeScriptProcessArgs } from "./web-server-command.js"; const repositoryRoot = path.resolve(import.meta.dirname, "../.."); if (process.argv[2] === "--worker") { const origin = process.argv[3]!; const browser = await openConnectionBrowser(parseConnectionConfig({ browser: { headed: false, channel: "chromium", freshness: "signed-out", } }), repositoryRoot, origin); await browser.context.pages()[0]!.goto(origin); let stopping = false; for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.once(signal, () => { if (stopping) return; stopping = true; void (async () => { let ok = false; try { ok = (await browser.context.request.get(`${origin}/cleanup`)).ok(); } finally { await browser.close(); } process.send?.({ kind: "cleanup", ok }); process.disconnect(); process.exitCode = ok ? 0 : 1; })().catch(() => { process.exitCode = 1; process.disconnect(); }); }); process.send?.({ kind: "ready" }); } else { let cleanupRequests = 0; const server = createServer((req, res) => { if (req.url === "/cleanup") { const authenticated = req.headers.cookie === "qa-cleanup=synthetic"; if (authenticated) cleanupRequests++; res.writeHead(authenticated ? 200 : 401).end(); } else res.writeHead(200, { "Content-Type": "text/html", "Set-Cookie": "qa-cleanup=synthetic; HttpOnly; Path=/" }).end("
Synthetic cleanup fixture
"); }); await new Promise