From 26a6ebc40d2d67ea27985e272f5e8ce193f2292c Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Mon, 19 Oct 2026 18:41:11 -0700 Subject: [PATCH] style: format the files #29042 merged unformatted, and keep the WSL connection under its line limit --- ...ad-managed-tunnel-identity-restart.test.ts | 47 ++++++++++++----- src/main/wsl/wsl-host-first-connect.ts | 3 +- src/main/wsl/wsl-host-service.test.ts | 3 +- src/main/wsl/wsl-orcad-connection-errors.ts | 18 +++++++ src/main/wsl/wsl-orcad-connection.test.ts | 6 ++- src/main/wsl/wsl-orcad-connection.ts | 52 ++++++++----------- src/main/wsl/wsl-orcad-pairing-identity.ts | 4 +- 7 files changed, 86 insertions(+), 47 deletions(-) create mode 100644 src/main/wsl/wsl-orcad-connection-errors.ts diff --git a/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts b/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts index c70bd4b08f6d..2bd56ad7a4c6 100644 --- a/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts +++ b/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts @@ -102,22 +102,38 @@ describe('reopening a managed tunnel after orcad restarted elsewhere', () => { return saved ? getPreferredPairingOffer(saved) : null }, deployAndLaunch: async () => ({ - outcome: 'ready', distro: 'Ubuntu', distroId: null, fullVersion: '1', pid: null, - holder: 'adopted', port: Number(new URL(server.getWebSocketEndpoint()!).port), - readiness: { runtimeId: server['runtime'].getRuntimeId(), + outcome: 'ready', + distro: 'Ubuntu', + distroId: null, + fullVersion: '1', + pid: null, + holder: 'adopted', + port: Number(new URL(server.getWebSocketEndpoint()!).port), + readiness: { + runtimeId: server['runtime'].getRuntimeId(), managedWslCliReconciliation: 'settled', - ...await buildServePairingReadiness({ pairingAddress: '127.0.0.1' }, server) } + ...(await buildServePairingReadiness({ pairingAddress: '127.0.0.1' }, server)) + } }), listen: async (_transport, { remotePort }) => ({ - entry: { id: 'bridge', connectionId: 'wsl:ubuntu', localPort: remotePort, - remoteHost: '127.0.0.1', remotePort }, - close: async () => {}, dispose: () => {} + entry: { + id: 'bridge', + connectionId: 'wsl:ubuntu', + localPort: remotePort, + remoteHost: '127.0.0.1', + remotePort + }, + close: async () => {}, + dispose: () => {} }) }) const dispatch = vi.spyOn(server['dispatcher'], 'dispatchStreaming') try { const connection = await manager.ensure('Ubuntu') - return { connection, caller: dispatch.mock.calls.at(-1)?.[2]?.authenticatedCallerFingerprint } + return { + connection, + caller: dispatch.mock.calls.at(-1)?.[2]?.authenticatedCallerFingerprint + } } finally { dispatch.mockRestore() await manager.dispose() @@ -126,9 +142,15 @@ describe('reopening a managed tunnel after orcad restarted elsewhere', () => { const first = await connect() expect(first.caller).toBeTruthy() addWslHostEnvironment(desktopProfile, { - id: 'wsl:ubuntu', name: 'Ubuntu', pairingCode: first.connection.pairingOffer, - record: { kind: 'wsl', distro: 'Ubuntu', - localPort: first.connection.localPort, remotePort: first.connection.remotePort } + id: 'wsl:ubuntu', + name: 'Ubuntu', + pairingCode: first.connection.pairingOffer, + record: { + kind: 'wsl', + distro: 'Ubuntu', + localPort: first.connection.localPort, + remotePort: first.connection.remotePort + } }) await server.stop() server = await startOrcad(hostProfile) @@ -139,7 +161,8 @@ describe('reopening a managed tunnel after orcad restarted elsewhere', () => { await expect(connect()).rejects.toThrow('orcad_identity_mismatch') refreshWslHostPairing(desktopProfile, 'wsl:ubuntu', { pairingCode: encodePairingOffer(pairingOffer(server)), - localPort: restarted.connection.localPort, remotePort: restarted.connection.remotePort + localPort: restarted.connection.localPort, + remotePort: restarted.connection.remotePort }) const rePaired = await connect() expect(rePaired.caller).toBeTruthy() diff --git a/src/main/wsl/wsl-host-first-connect.ts b/src/main/wsl/wsl-host-first-connect.ts index 9f24a23f29b9..074aa0a83857 100644 --- a/src/main/wsl/wsl-host-first-connect.ts +++ b/src/main/wsl/wsl-host-first-connect.ts @@ -7,7 +7,8 @@ import { errorMessage } from '../../shared/error-message' import type { WslHostAddResult } from '../../shared/wsl-host-types' import { OrcadHostUnsupportedError } from '../orcad/orcad-host-unavailable' import type { WslHostConnector } from './wsl-host-service' -import { WslOrcadLaunchDeferredError, type WslOrcadConnection } from './wsl-orcad-connection' +import type { WslOrcadConnection } from './wsl-orcad-connection' +import { WslOrcadLaunchDeferredError } from './wsl-orcad-connection-errors' type WslHostAddRefusal = Extract type AddConnector = Pick diff --git a/src/main/wsl/wsl-host-service.test.ts b/src/main/wsl/wsl-host-service.test.ts index c8ca64eb150a..35dbb82c37ea 100644 --- a/src/main/wsl/wsl-host-service.test.ts +++ b/src/main/wsl/wsl-host-service.test.ts @@ -12,7 +12,8 @@ import { getPreferredPairingOffer } from '../../shared/runtime-environments' import type { WslHostServerStop, WslHostStatus } from '../../shared/wsl-host-types' import type { WslHostDistroCandidate } from './wsl-host-distro-list' import { WslHostService, type WslHostConnector } from './wsl-host-service' -import { WslOrcadLaunchDeferredError, type WslOrcadConnection } from './wsl-orcad-connection' +import type { WslOrcadConnection } from './wsl-orcad-connection' +import { WslOrcadLaunchDeferredError } from './wsl-orcad-connection-errors' const KEY = Buffer.alloc(32, 3).toString('base64') const UBUNTU_ID = '0e3a7f2c-1b4d-4c5e-9f60-7a8b9c0d1e2f' diff --git a/src/main/wsl/wsl-orcad-connection-errors.ts b/src/main/wsl/wsl-orcad-connection-errors.ts new file mode 100644 index 000000000000..ecb96ba70d7c --- /dev/null +++ b/src/main/wsl/wsl-orcad-connection-errors.ts @@ -0,0 +1,18 @@ +import type { WslOrcadLaunch } from './wsl-orcad-deploy' + +export type WslOrcadDeferredLaunch = Extract + +/** orcad installed an update it may not activate yet (live terminals); nothing is listening. */ +export class WslOrcadLaunchDeferredError extends Error { + constructor(readonly launch: WslOrcadDeferredLaunch) { + super(launch.reason) + this.name = 'WslOrcadLaunchDeferredError' + } +} + +export class WslOrcadConnectionSupersededError extends Error { + constructor(distro: string) { + super(`The connection to the WSL distro ${distro} was closed while it was being opened.`) + this.name = 'WslOrcadConnectionSupersededError' + } +} diff --git a/src/main/wsl/wsl-orcad-connection.test.ts b/src/main/wsl/wsl-orcad-connection.test.ts index f4f9a1ea6b52..71cddad386d2 100644 --- a/src/main/wsl/wsl-orcad-connection.test.ts +++ b/src/main/wsl/wsl-orcad-connection.test.ts @@ -8,11 +8,13 @@ import { startEchoServer } from '../managed-server/lifecycle/orcad-stdio-bridge- import { fakeWslBridgeChildren, posixOrcadStdioBridge } from './wsl-orcad-bridge-test-child' import { WslOrcadConnectionManager, - WslOrcadConnectionSupersededError, - WslOrcadLaunchDeferredError, type WslOrcadConnection, type WslOrcadConnectionDependencies } from './wsl-orcad-connection' +import { + WslOrcadConnectionSupersededError, + WslOrcadLaunchDeferredError +} from './wsl-orcad-connection-errors' import type { WslOrcadLaunch } from './wsl-orcad-deploy' import { createWslOrcadHostTransport } from './wsl-orcad-host-transport' import { listenWslOrcadStdioBridge } from './wsl-orcad-stdio-bridge' diff --git a/src/main/wsl/wsl-orcad-connection.ts b/src/main/wsl/wsl-orcad-connection.ts index 6162edb1a1ea..aab14cb031a3 100644 --- a/src/main/wsl/wsl-orcad-connection.ts +++ b/src/main/wsl/wsl-orcad-connection.ts @@ -24,6 +24,10 @@ import type { WslOrcadHostTarget } from './wsl-orcad-host-target' import { createWslOrcadHostTransport } from './wsl-orcad-host-transport' import { resolveWslOrcadPairing } from './wsl-orcad-pairing-identity' import { trackWslOrcadHostEnvironment } from './wsl-orcad-host-environments' +import { + WslOrcadConnectionSupersededError, + WslOrcadLaunchDeferredError +} from './wsl-orcad-connection-errors' import { listenWslOrcadStdioBridge, type WslOrcadStdioBridgeOptions @@ -46,23 +50,6 @@ export type WslOrcadConnection = { close(): Promise } -type WslOrcadDeferredLaunch = Extract - -/** orcad installed an update it may not activate yet (live terminals); nothing is listening. */ -export class WslOrcadLaunchDeferredError extends Error { - constructor(readonly launch: WslOrcadDeferredLaunch) { - super(launch.reason) - this.name = 'WslOrcadLaunchDeferredError' - } -} - -export class WslOrcadConnectionSupersededError extends Error { - constructor(distro: string) { - super(`The connection to the WSL distro ${distro} was closed while it was being opened.`) - this.name = 'WslOrcadConnectionSupersededError' - } -} - export type WslOrcadConnectOptions = { environmentId?: string label?: string @@ -201,12 +188,9 @@ export class WslOrcadConnectionManager { const generation = this.generation(key) const environmentId = options.environmentId ?? defaultWslOrcadEnvironmentId(distro) const label = options.label ?? distro - const transport = (this.dependencies.createTransport ?? defaultTransport)({ - kind: 'wsl', - id: environmentId, - distro, - label - }) + const target: WslOrcadHostTarget = { kind: 'wsl', id: environmentId, distro, label } + const transport = + this.dependencies.createTransport?.(target) ?? createWslOrcadHostTransport({ target }) // Every call relaunches a stopped orcad, so a distro restart is recovered here. const launch = await (this.dependencies.deployAndLaunch ?? deployAndLaunchWslOrcad)(distro, { environmentId, @@ -234,12 +218,21 @@ export class WslOrcadConnectionManager { current.connection.environmentId === environmentId ) { const pairingOffer = await resolveWslOrcadPairing( - launch, current.connection.localPort, paired, this.dependencies.verifyIdentity + launch, + current.connection.localPort, + paired, + this.dependencies.verifyIdentity ) if (this.generation(key) !== generation) { throw new WslOrcadConnectionSupersededError(distro) } - return this.refreshOffer(key, current, launch, pairingOffer, options.status ? status.ready : null) + return this.refreshOffer( + key, + current, + launch, + pairingOffer, + options.status ? status.ready : null + ) } // orcad moved ports (or this is the first connect): the old bridge dials a dead port. const preferredLocalPort = current?.connection.localPort ?? options.localPort ?? 0 @@ -260,7 +253,10 @@ export class WslOrcadConnectionManager { throw new WslOrcadConnectionSupersededError(distro) } const pairingOffer = await resolveWslOrcadPairing( - launch, forward.entry.localPort, paired, this.dependencies.verifyIdentity + launch, + forward.entry.localPort, + paired, + this.dependencies.verifyIdentity ) if (this.generation(key) !== generation) { throw new WslOrcadConnectionSupersededError(distro) @@ -341,7 +337,3 @@ export class WslOrcadConnectionManager { } } } - -function defaultTransport(target: WslOrcadHostTarget): OrcadHostTransport { - return createWslOrcadHostTransport({ target }) -} diff --git a/src/main/wsl/wsl-orcad-pairing-identity.ts b/src/main/wsl/wsl-orcad-pairing-identity.ts index f29595f0cb05..b9aa67b8ac63 100644 --- a/src/main/wsl/wsl-orcad-pairing-identity.ts +++ b/src/main/wsl/wsl-orcad-pairing-identity.ts @@ -22,7 +22,9 @@ export async function resolveWslOrcadPairing( throw new OrcadManagedIdentityError(launch.port, identity.detail) } if (identity.verdict === 'unreachable') { - console.warn(`[wsl] Orca server in ${launch.distro} did not answer its bridge: ${identity.detail}`) + console.warn( + `[wsl] Orca server in ${launch.distro} did not answer its bridge: ${identity.detail}` + ) } return pairingOffer }