diff --git a/packages/app/e2e/browser/host-confirmation.spec.ts b/packages/app/e2e/browser/host-confirmation.spec.ts index 6de8da14ce..10ca88392f 100644 --- a/packages/app/e2e/browser/host-confirmation.spec.ts +++ b/packages/app/e2e/browser/host-confirmation.spec.ts @@ -9,7 +9,7 @@ import { expectHostInHostPicker, hostConfirmation, openPairingLink, - saveLinkedHostBeforeLoad, + reopenPairingLinkWithSavedHosts, type LinkedHost, } from "../support/helpers/host-confirmation"; @@ -20,7 +20,9 @@ const linkedHost: LinkedHost = { daemonPublicKeyB64: "bGlua0NvbmZpcm1hdGlvbktleQ", }; -test("a pairing link for a new host asks before saving it", async ({ page }) => { +test("a pairing link asks before saving a host and reconnects without asking again", async ({ + page, +}) => { const link = buildPairingLink(linkedHost); await test.step("Cancel saves nothing and stays on the page", async () => { @@ -39,13 +41,10 @@ test("a pairing link for a new host asks before saving it", async ({ page }) => await openSettings(page); await expectHostInHostPicker(page, linkedHost.serverId, "listed"); }); -}); -test("a pairing link for a saved host connects without asking", async ({ page }) => { - await saveLinkedHostBeforeLoad(page, linkedHost); - - await openPairingLink(page, buildPairingLink(linkedHost)); - - await expectAppRoute(page, "/open-project", { timeout: 30_000 }); - await expect(hostConfirmation(page)).toHaveCount(0); + await test.step("reopening the saved host link connects without asking", async () => { + await reopenPairingLinkWithSavedHosts(page, link); + await expectAppRoute(page, "/open-project", { timeout: 30_000 }); + await expect(hostConfirmation(page)).toHaveCount(0); + }); }); diff --git a/packages/app/e2e/support/helpers/host-confirmation.ts b/packages/app/e2e/support/helpers/host-confirmation.ts index f6de576fc0..ea2e2f8a17 100644 --- a/packages/app/e2e/support/helpers/host-confirmation.ts +++ b/packages/app/e2e/support/helpers/host-confirmation.ts @@ -1,7 +1,5 @@ import { expect, type Locator, type Page } from "@playwright/test"; -const EXTRA_HOSTS_KEY = "@paseo:e2e-extra-hosts"; - export interface LinkedHost { serverId: string; relayEndpoint: string; @@ -31,31 +29,17 @@ export async function openPairingLink(page: Page, link: string): Promise { await page.goto(link); } -/** Saves a relay host before the app loads, as if it had been paired in an earlier session. */ -export async function saveLinkedHostBeforeLoad(page: Page, host: LinkedHost): Promise { - await page.goto("/"); - const nowIso = new Date().toISOString(); - const connectionId = `relay:${host.relayEndpoint}`; - const savedHost = { - serverId: host.serverId, - label: host.serverId, - connections: [ - { - id: connectionId, - type: "relay", - relayEndpoint: host.relayEndpoint, - useTls: false, - daemonPublicKeyB64: host.daemonPublicKeyB64, - }, - ], - preferredConnectionId: connectionId, - createdAt: nowIso, - updatedAt: nowIso, - }; - await page.evaluate(({ key, hosts }) => localStorage.setItem(key, JSON.stringify(hosts)), { - key: EXTRA_HOSTS_KEY, - hosts: [savedHost], - }); +/** Reopens a link from a fresh document while retaining hosts saved through the UI. */ +export async function reopenPairingLinkWithSavedHosts(page: Page, link: string): Promise { + for (const target of ["/", link]) { + // The fixture otherwise replaces the registry on every document load. + await page.evaluate(() => { + const nonce = localStorage.getItem("@paseo:e2e-seed-nonce"); + if (!nonce) throw new Error("Expected the e2e seed nonce before reopening a pairing link."); + localStorage.setItem("@paseo:e2e-disable-default-seed-once", nonce); + }); + await page.goto(target); + } } export function hostConfirmation(page: Page): Locator {