e73304fe5463
delete dead ws:// LAN openSyncSession path, export openSyncSessionAtUrl, migrate tests (audit #8 part 2)
- time
- 2026-08-21 04:09 UTC · 2 months ago
- machine
- koh2
- agent
- glm-5.2
- session
- audit 2026-08-20 remediation
- parent
- 76cdd0f26f9d
↓ peach-browser-e73304fe.tar.gzatlas at this save
files changed4 files
src/background/sync-runner.ts+1 −1src/shared/sync-kk-transport.test.ts+7 −5src/shared/sync-transport.ts+3 −33src/shared/sync.disconnect.test.ts+22 −16src/background/sync-runner.ts+1 −1
@@ -36,7 +36,7 @@3636 import { getSyncSettings, relayInForce, type SyncSettings } from "./sync-settings";3737 3838 /**39- * Test/injection seam. Production wires in the real `openSyncSession`;39+ * Test/injection seam. Production wires in the real `openRelaySyncSession`;4040 * unit tests inject a fake to avoid real WebSocket + Noise KK.4141 */4242 export interface SyncRunnerDeps {src/shared/sync-kk-transport.test.ts+7 −5
@@ -5,7 +5,7 @@55 import {66 openRelaySyncResponderSession,77 openRelaySyncSession,8- openSyncSession,8+ openSyncSessionAtUrl,99 type SyncPeerIdentity,1010 } from "./sync-transport";1111 @@ -202,8 +202,9 @@202202 203203 it("selects paired state then completes KK with both keys pinned", async () => {204204 const peer = installPeer();205- const session = await openSyncSession(206- { ip: "127.0.0.1", port: 49142 },205+ const session = await openSyncSessionAtUrl(206+ "ws://127.0.0.1:49142/",207+ "LAN peer",207208 peer.identity,208209 hex(peer.responder.publicKey),209210 RENDEZVOUS_ID,@@ -220,8 +221,9 @@220221 it("rejects a post-KK identity that claims a different responder key", async () => {221222 const peer = installPeer("ff".repeat(32));222223 await expect(223- openSyncSession(224- { ip: "127.0.0.1", port: 49142 },224+ openSyncSessionAtUrl(225+ "ws://127.0.0.1:49142/",226+ "LAN peer",225227 peer.identity,226228 hex(peer.responder.publicKey),227229 RENDEZVOUS_ID,src/shared/sync-transport.ts+3 −33
@@ -8,7 +8,7 @@88 // are split across multiple Noise messages below).99 //1010 // On connect:11-// 1. Open ws://<ip>:<port>/11+// 1. Open wss://<relay>/<rendezvous-id>/1212 // 2. Send PEACH_RECONNECT with an opaque rotating rendezvous capability so1313 // the listener can select paired local state without exposing identities.1414 // 3. Run standard Noise KK using both locally-known static keys.@@ -69,11 +69,6 @@6969 remoteStaticPublicKey: Uint8Array;7070 }7171 72-export interface SyncEndpoint {73- ip: string;74- port: number;75-}76-7772 /** Our identity, repeated in the post-handshake PAIR_IDENTITY frame and bound7873 * to the local static key already authenticated by KK. */7974 export interface SyncPeerIdentity {@@ -111,31 +106,6 @@111106 }112107 113108 /**114- * Open a WebSocket to (ip, port), run Noise KK against both paired static115- * keys, exchange bound PAIR_IDENTITY frames, and return a ready-to-use116- * session.117- *118- * On a successful return, `setLastKnownIp` in the caller can persist119- * (ip, port) for the next session's fast path.120- */121-export async function openSyncSession(122- endpoint: SyncEndpoint,123- ourIdentity: SyncPeerIdentity,124- expectedRemotePubkeyHex: string,125- rendezvousId: string,126- options: SyncSessionOptions = {},127-): Promise<SyncSession> {128- return openSyncSessionAtUrl(129- `ws://${endpoint.ip}:${endpoint.port}/`,130- "LAN peer",131- ourIdentity,132- expectedRemotePubkeyHex,133- rendezvousId,134- options,135- );136-}137-138-/**139109 * Relay reconnect preserves the exact LAN wire protocol; only the WebSocket140110 * target changes. The URL builder enforces credential-free `wss://`.141111 */@@ -303,13 +273,13 @@303273 );304274 }305275 306-async function openSyncSessionAtUrl(276+export async function openSyncSessionAtUrl(307277 url: string,308278 targetLabel: string,309279 ourIdentity: SyncPeerIdentity,310280 expectedRemotePubkeyHex: string,311281 rendezvousId: string,312- options: SyncSessionOptions,282+ options: SyncSessionOptions = {},313283 ): Promise<SyncSession> {314284 if (!/^[A-Za-z0-9_-]{22,128}$/.test(rendezvousId)) {315285 throw new Error("reconnect requires a valid rotating rendezvous id");src/shared/sync.disconnect.test.ts+22 −16
@@ -1,6 +1,6 @@11 // T-020: WebSocket sync-disconnect handling (PCH-01-026 #9)22 //3-// Why this test exists: `openSyncSession` in sync-transport.ts3+// Why this test exists: `openSyncSessionAtUrl` in sync-transport.ts44 // wires three handlers onto the WebSocket:55 // - onerror: calls ws.close() to unblock parked receive() calls66 // - onclose: sets `closed = true`, drains the readers queue with empty bytes@@ -20,7 +20,7 @@2020 2121 import { describe, expect, it, vi } from "vitest";2222 import { generateKeyPair } from "@stablelib/x25519";23-import { openSyncSession, type SyncPeerIdentity } from "./sync-transport";23+import { openSyncSessionAtUrl, type SyncPeerIdentity } from "./sync-transport";2424 import { SYNC_LIMITS } from "./sync-limits";2525 2626 const TEST_KEYS = generateKeyPair();@@ -113,8 +113,9 @@113113 const peerKp = generateKeyPair();114114 const peerHex = Array.from(peerKp.publicKey).map(b => b.toString(16).padStart(2, "0")).join("");115115 116- const sessionPromise = openSyncSession(117- { ip: "127.0.0.1", port: 9999 },116+ const sessionPromise = openSyncSessionAtUrl(117+ "ws://127.0.0.1:9999/",118+ "LAN peer",118119 TEST_IDENTITY,119120 peerHex,120121 TEST_RENDEZVOUS_ID,@@ -154,8 +155,9 @@154155 const peerKp = generateKeyPair();155156 const peerHex = Array.from(peerKp.publicKey).map(b => b.toString(16).padStart(2, "0")).join("");156157 157- const sessionPromise = openSyncSession(158- { ip: "127.0.0.1", port: 9999 },158+ const sessionPromise = openSyncSessionAtUrl(159+ "ws://127.0.0.1:9999/",160+ "LAN peer",159161 TEST_IDENTITY,160162 peerHex,161163 TEST_RENDEZVOUS_ID,@@ -176,11 +178,11 @@176178 177179 // T-020c: WebSocket connect timeout — connection never opens.178180 // `connectWebSocket` wraps the connection in a timeout. If the timeout fires,179- // `openSyncSession` must reject with a timeout error.181+ // `openSyncSessionAtUrl` must reject with a timeout error.180182 //181183 // The default timeout is 5000ms (DEFAULT_CONNECT_TIMEOUT_MS). We pass a182184 // very short timeout (10ms) to make the test fast.183- it("T-020c: WebSocket connect timeout fires → openSyncSession rejects with timeout error", async () => {185+ it("T-020c: WebSocket connect timeout fires → openSyncSessionAtUrl rejects with timeout error", async () => {184186 let mockWs: MockWebSocketInstance;185187 const MockWebSocketCtor = vi.fn().mockImplementation(function(_url: string) {186188 mockWs = createMockWebSocket();@@ -193,8 +195,9 @@193195 const peerHex = Array.from(peerKp.publicKey).map(b => b.toString(16).padStart(2, "0")).join("");194196 195197 // Pass a very short connectTimeoutMs so the test doesn't take 5 seconds196- const sessionPromise = openSyncSession(197- { ip: "127.0.0.1", port: 9999 },198+ const sessionPromise = openSyncSessionAtUrl(199+ "ws://127.0.0.1:9999/",200+ "LAN peer",198201 TEST_IDENTITY,199202 peerHex,200203 TEST_RENDEZVOUS_ID,@@ -216,8 +219,9 @@216219 217220 const peerKp = generateKeyPair();218221 const peerHex = Array.from(peerKp.publicKey).map(b => b.toString(16).padStart(2, "0")).join("");219- const sessionPromise = openSyncSession(220- { ip: "127.0.0.1", port: 9999 },222+ const sessionPromise = openSyncSessionAtUrl(223+ "ws://127.0.0.1:9999/",224+ "LAN peer",221225 TEST_IDENTITY,222226 peerHex,223227 TEST_RENDEZVOUS_ID,@@ -247,8 +251,9 @@247251 const peerKp = generateKeyPair();248252 const peerHex = Array.from(peerKp.publicKey).map(b => b.toString(16).padStart(2, "0")).join("");249253 250- const sessionPromise = openSyncSession(251- { ip: "127.0.0.1", port: 9999 },254+ const sessionPromise = openSyncSessionAtUrl(255+ "ws://127.0.0.1:9999/",256+ "LAN peer",252257 TEST_IDENTITY,253258 peerHex,254259 TEST_RENDEZVOUS_ID,@@ -277,8 +282,9 @@277282 278283 const peerKp = generateKeyPair();279284 const peerHex = Array.from(peerKp.publicKey).map(b => b.toString(16).padStart(2, "0")).join("");280- const sessionPromise = openSyncSession(281- { ip: "127.0.0.1", port: 9999 },285+ const sessionPromise = openSyncSessionAtUrl(286+ "ws://127.0.0.1:9999/",287+ "LAN peer",282288 TEST_IDENTITY,283289 peerHex,284290 TEST_RENDEZVOUS_ID,