|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { blobForProject, loadBootstrapPeerFrom } from "./peer"; |
| 3 | +import { |
| 4 | + addSyncSourceViaPaste, |
| 5 | + linkViaPaste, |
| 6 | + waitForScreenReady, |
| 7 | + watchUncaughtErrors, |
| 8 | +} from "./helpers"; |
| 9 | +import { octiServerConnectorId } from "../../src/protocol/connector-id"; |
| 10 | +import { serverBaseUrl } from "../../src/protocol/models"; |
| 11 | + |
| 12 | +/** |
| 13 | + * Real-browser multi-connector E2E. The vitest smoke suite |
| 14 | + * (`src/__smoke__/multi-connector.test.ts`) drives `ConnectorManager` directly; |
| 15 | + * this drives the actual UI: |
| 16 | + * |
| 17 | + * 1. Onboard against server A (paste-link peer A) → dashboard, peer A visible. |
| 18 | + * 2. Add server B from Settings → Sync sources → Add another (paste-link peer B). |
| 19 | + * 3. Both connectors are listed; both peers render on the merged dashboard. |
| 20 | + * |
| 21 | + * Two distinct peers (one per server) is the clearest "multiple connectors all |
| 22 | + * render in the real UI" signal — peer B's card only appears if connector B |
| 23 | + * refreshed AND decrypted, so it subsumes a per-connector health check. |
| 24 | + * Same-peer-on-both-servers dedupe is already covered by the vitest smoke. |
| 25 | + * |
| 26 | + * Needs two bootstrap files, one per server — see the `e2e-smoke` CI job. |
| 27 | + */ |
| 28 | + |
| 29 | +const PEER_A_FILE = process.env.BOOTSTRAP_PEER_A_FILE ?? "peer-a.json"; |
| 30 | +const PEER_B_FILE = process.env.BOOTSTRAP_PEER_B_FILE ?? "peer-b.json"; |
| 31 | + |
| 32 | +test("link two connectors via UI + merged dashboard", async ({ page }, testInfo) => { |
| 33 | + // Two real joins plus refresh cycles against two servers — comfortably above |
| 34 | + // the 60s config default. |
| 35 | + test.setTimeout(120_000); |
| 36 | + |
| 37 | + const peerA = loadBootstrapPeerFrom(PEER_A_FILE); |
| 38 | + const peerB = loadBootstrapPeerFrom(PEER_B_FILE); |
| 39 | + |
| 40 | + // Guard against a CI miswiring (both files pointing at the same server): the |
| 41 | + // connector-id encodes only domain + accountId, and both CI servers share |
| 42 | + // 127.0.0.1, so a same-server mistake wouldn't be obvious downstream. |
| 43 | + expect( |
| 44 | + serverBaseUrl(peerA.serverAddress), |
| 45 | + "peer A and peer B must live on different sync-servers", |
| 46 | + ).not.toBe(serverBaseUrl(peerB.serverAddress)); |
| 47 | + |
| 48 | + const blobA = blobForProject(peerA, testInfo.project.name); |
| 49 | + const blobB = blobForProject(peerB, testInfo.project.name); |
| 50 | + const assertNoUncaught = watchUncaughtErrors(page); |
| 51 | + |
| 52 | + // 1. Onboard against server A. |
| 53 | + await page.goto("/"); |
| 54 | + await waitForScreenReady(page, "onboarding"); |
| 55 | + await linkViaPaste(page, blobA); |
| 56 | + await expect( |
| 57 | + page.locator(`[data-testid="device-card"][data-device-id="${peerA.deviceId}"]`), |
| 58 | + "peer A visible after first link", |
| 59 | + ).toBeVisible(); |
| 60 | + |
| 61 | + // 2. Add server B through the in-dashboard add-source flow. |
| 62 | + await addSyncSourceViaPaste(page, blobB, 2); |
| 63 | + |
| 64 | + // Both connectors are listed, identified by their wire connector-id |
| 65 | + // (kserver-<domain>-<accountId>) — distinguishes the two servers by account |
| 66 | + // since both share 127.0.0.1 in CI. |
| 67 | + const expectedIds = [ |
| 68 | + octiServerConnectorId(peerA.serverAddress, peerA.accountId), |
| 69 | + octiServerConnectorId(peerB.serverAddress, peerB.accountId), |
| 70 | + ].sort(); |
| 71 | + const actualIds = await page |
| 72 | + .locator('[data-testid="connector-card"]') |
| 73 | + .evaluateAll((cards) => cards.map((c) => c.getAttribute("data-connector-id"))); |
| 74 | + expect(actualIds.filter((id): id is string => id !== null).sort()).toEqual(expectedIds); |
| 75 | + |
| 76 | + // 3. Reload to a clean dashboard (no stacked Settings/Sources sheets occluding |
| 77 | + // the grid; the persisted credentials re-bootstrap both connectors) and |
| 78 | + // assert both peers render on the merged dashboard. |
| 79 | + await page.goto("/"); |
| 80 | + await waitForScreenReady(page, "dashboard"); |
| 81 | + |
| 82 | + await expect( |
| 83 | + page.locator(`[data-testid="device-card"][data-device-id="${peerA.deviceId}"]`), |
| 84 | + "peer A visible on merged dashboard", |
| 85 | + ).toBeVisible(); |
| 86 | + await expect( |
| 87 | + page.locator(`[data-testid="device-card"][data-device-id="${peerB.deviceId}"]`), |
| 88 | + "peer B visible on merged dashboard", |
| 89 | + ).toBeVisible(); |
| 90 | + await expect(page.locator(".banner.err"), "no decode-error banner").toHaveCount(0); |
| 91 | + |
| 92 | + assertNoUncaught(); |
| 93 | +}); |
0 commit comments