diff --git a/src/main/ephemeral-vm/runtime-resume-pairing.test.ts b/src/main/ephemeral-vm/runtime-resume-pairing.test.ts index 507fefcfa3a..ce5730820e7 100644 --- a/src/main/ephemeral-vm/runtime-resume-pairing.test.ts +++ b/src/main/ephemeral-vm/runtime-resume-pairing.test.ts @@ -236,6 +236,7 @@ describe('resuming a recipe VM server', () => { const firstGate = new Promise((resolve) => (releaseFirst = resolve)) const auth = serverAuth(serverDataPath) const repairedA = vi.fn() + const firstProbeSettled = Promise.withResolvers() // Resume A: its probe is held, so its re-pair would land late. await applyResumedRuntimePairing({ userDataPath: desktopDataPath, @@ -244,7 +245,11 @@ describe('resuming a recipe VM server', () => { invalidateTransport: vi.fn(), probeSavedPairing: async (connection) => { await firstGate - return auth(connection) + try { + return await auth(connection) + } finally { + firstProbeSettled.resolve() + } }, confirmInBackground: true, onRepairedInBackground: repairedA @@ -259,7 +264,11 @@ describe('resuming a recipe VM server', () => { }) const afterB = resolveEnvironmentPairingOffer(desktopDataPath, environmentId) releaseFirst() - await new Promise((resolve) => setTimeout(resolve, 20)) + await firstProbeSettled.promise + // Let A's confirmation chain (catch → guarded repair → then) run to the end. + for (let tick = 0; tick < 10; tick++) { + await Promise.resolve() + } expect(repairedA).not.toHaveBeenCalled() expect(resolveEnvironmentPairingOffer(desktopDataPath, environmentId)).toEqual(afterB) expect(outcomeB.environment.id).toBe(environmentId) diff --git a/src/main/ipc/runtime-environments/runtime-environment-shared-control-reconnect.test.ts b/src/main/ipc/runtime-environments/runtime-environment-shared-control-reconnect.test.ts index 4244cfa7aaf..6688d67e193 100644 --- a/src/main/ipc/runtime-environments/runtime-environment-shared-control-reconnect.test.ts +++ b/src/main/ipc/runtime-environments/runtime-environment-shared-control-reconnect.test.ts @@ -1,15 +1,18 @@ import { describe, expect, it, vi } from 'vitest' +import type { RemoteRuntimeSharedConnectionDiagnostics } from '../../../shared/remote-runtime/control/remote-runtime-shared-control-types' import { reconnectSharedControlIfIdle } from './runtime-environment-shared-control-reconnect' -function connection(state: string | null) { +type State = RemoteRuntimeSharedConnectionDiagnostics['state'] + +function connection(state: State | null) { return { - getDiagnostics: () => (state === null ? null : ({ state } as never)), + getDiagnostics: () => (state === null ? null : { state }), reconnectNow: vi.fn() } } describe('reconnectSharedControlIfIdle', () => { - it.each(['awaiting_ready', 'awaiting_authenticated', 'ready'])( + it.each(['awaiting_ready', 'awaiting_authenticated', 'ready'])( 'leaves a socket that is %s alone', (state) => { const socket = connection(state) @@ -18,11 +21,14 @@ describe('reconnectSharedControlIfIdle', () => { } ) - it.each(['closed', 'reconnecting', null])('reconnects when the socket is %s', (state) => { - const socket = connection(state) - reconnectSharedControlIfIdle(socket) - expect(socket.reconnectNow).toHaveBeenCalledTimes(1) - }) + it.each(['closed', 'reconnecting', null])( + 'reconnects when the socket is %s', + (state) => { + const socket = connection(state) + reconnectSharedControlIfIdle(socket) + expect(socket.reconnectNow).toHaveBeenCalledTimes(1) + } + ) it('does nothing without a connection', () => { expect(() => reconnectSharedControlIfIdle(undefined)).not.toThrow()