import { expect, type Page } from "@playwright/test"; import { parseConnectionOfferFromUrl } from "@getpaseo/protocol/connection-offer"; import type { LocalElixirRelay } from "./local-elixir-relay"; import type { PackagedWebDaemon } from "./packaged-web-daemon"; import { expectRunningAgentChrome } from "./agent-stream"; import { buildCreateAgentPreferences } from "./daemon-registry"; export interface RelayDeploymentMeasurements { reconnectToastDelayMs: number; reconnectToastVisibleMs: number; totalReconnectMs: number; relayStartupMs: number; streamPausedWhileDisconnected: boolean; runningStatePreserved: boolean; streamResumedWithoutUserAction: boolean; } export async function connectDaemonWebAppOnlyThroughRelay( page: Page, daemon: PackagedWebDaemon, ): Promise { const offerUrl = await daemon.pairingOfferUrl(); const offer = parseConnectionOfferFromUrl(offerUrl); if (!offer) throw new Error("Daemon pairing command returned an invalid offer URL"); const relayConnection = { id: `relay:${offer.relay.endpoint}`, type: "relay" as const, relayEndpoint: offer.relay.endpoint, useTls: offer.relay.useTls ?? false, daemonPublicKeyB64: offer.daemonPublicKeyB64, }; const now = new Date().toISOString(); const host = { serverId: offer.serverId, label: "Relay deployment host", connections: [relayConnection], preferredConnectionId: relayConnection.id, createdAt: now, updatedAt: now, }; await page.route(/:(6767)\b/, (route) => route.abort()); await page.routeWebSocket(/:(6767)\b/, async (socket) => { await socket.close({ code: 1008, reason: "Blocked developer daemon during relay E2E" }); }); await page.route("**/*", async (route) => { if (route.request().resourceType() !== "document") { await route.continue(); return; } const response = await route.fetch(); const html = await response.text(); await route.fulfill({ response, body: html.replace(/