diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/paired-reconnect-multi-pane-materialization.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/paired-reconnect-multi-pane-materialization.test.ts index c18b857a7f8..edcbe4d8a80 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/paired-reconnect-multi-pane-materialization.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/paired-reconnect-multi-pane-materialization.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' /** STA-3107: multiplex close races six pane recoveries; every pane must regain a host handle, including parked PTYs requiring session.tabs.activate (STA-3002). */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' // These transport fixtures never read abandoned-launch ownership from the app store. @@ -80,6 +81,7 @@ describe('paired client sleep/wake with several remote terminal tabs', () => { beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() vi.doUnmock( '../../../../runtime/hosted-terminals/streams/registry/remote-runtime-terminal-multiplexer-registry' ) diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-outage-toast-flood-and-stuck-reconnect.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-outage-toast-flood-and-stuck-reconnect.test.ts index b5cca5933ad..2301c028b43 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-outage-toast-flood-and-stuck-reconnect.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-outage-toast-flood-and-stuck-reconnect.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' /** Inject Electron-shaped RPC rejections with codes stripped to verify message classification, bounded outage surfaces and revivable reconnect, including host-side activation of pending panes (STA-3002). */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const appStore = vi.hoisted(() => ({ @@ -162,6 +163,7 @@ describe('remote runtime outage: toast flood and stuck reconnect (issue3)', () = beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() vi.doUnmock( '../../../../runtime/hosted-terminals/streams/registry/remote-runtime-terminal-multiplexer-registry' ) diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-deadline-reattach.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-deadline-reattach.test.ts index 8fa9e6c9d78..c610d557257 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-deadline-reattach.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-deadline-reattach.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const appStore = vi.hoisted(() => ({ getState: vi.fn(() => { @@ -162,6 +163,7 @@ describe('remote runtime pty reattach after the bounded recovery window', () => beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() vi.doUnmock( '../../../../runtime/hosted-terminals/streams/registry/remote-runtime-terminal-multiplexer-registry' ) diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-latched-pane-retention.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-latched-pane-retention.test.ts index fb3e0d66700..57f87bffd13 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-latched-pane-retention.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-latched-pane-retention.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const appStore = vi.hoisted(() => ({ getState: vi.fn(() => { @@ -140,6 +141,7 @@ describe('remote runtime pty latched-pane retention', () => { beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() vi.doUnmock( '../../../../runtime/hosted-terminals/streams/registry/remote-runtime-terminal-multiplexer-registry' ) diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-query-reply-immediate.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-query-reply-immediate.test.ts index 82ff1dbe380..77493658cce 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-query-reply-immediate.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-query-reply-immediate.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const appStore = vi.hoisted(() => ({ getState: vi.fn(() => { @@ -29,6 +30,7 @@ describe('remote transport sendInputImmediate (#7329)', () => { beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() vi.doUnmock( '../../../../runtime/hosted-terminals/streams/registry/remote-runtime-terminal-multiplexer-registry' ) diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-lifetime.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-lifetime.test.ts index 0e79b350601..a70c7faf43b 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-lifetime.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-lifetime.test.ts @@ -43,11 +43,11 @@ function publish(retired = false, pairingRevision = 1) { } fixture.publishHostSnapshot(snapshot) } -async function createTransport() { +async function createTransport(tabId = 'tab-1') { const { createRemoteRuntimePtyTransport } = await import('./remote-runtime-pty-transport') const transport = createRemoteRuntimePtyTransport('env-1', { worktreeId: 'wt-1', - tabId: 'tab-1', + tabId, leafId: 'pane:1' }) transports.push(transport) @@ -91,7 +91,7 @@ it.each(['success', 'refusal'] as const)( 'retires an awaited recovery iteration and fences its late %s before a verified legacy host revives it', async (settlement) => { publish() - const transport = await createTransport() + const transport = await createTransport('web-terminal-tab-1') const onExit = vi.fn() const onDisconnect = vi.fn() await transport.connect({ url: '', callbacks: { onExit, onDisconnect } }) @@ -102,6 +102,7 @@ it.each(['success', 'refusal'] as const)( fixture.runtimeCall.mockImplementation((args) => args.method === 'session.tabs.activate' ? request.promise : dispatch(args) ) + fixture.runtimeCall.mockClear() callbacks?.onClose?.() await vi.waitFor(() => expect( @@ -140,7 +141,7 @@ it.each(['success', 'refusal'] as const)( ) it('terminates a current manual-disconnect refusal inside the production activate/list poll', async () => { - const transport = await createTransport() + const transport = await createTransport('web-terminal-tab-1') await transport.connect({ url: '', callbacks: {} }) await vi.waitFor(() => expect(transport.isConnected()).toBe(true)) const dispatch = fixture.runtimeCall.getMockImplementation()! diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-session-launch.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-session-launch.test.ts index 4e7d4849e0b..e658708b81a 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-session-launch.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-host-session-launch.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' import { createHostSessionLaunchRuntimeFixture } from './remote-runtime-host-session-launch-test-fixture' import { ExplicitEnsure } from '../../../../../../shared/rpc-contract/agent-session-params' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -42,6 +43,7 @@ describe('createRemoteRuntimePtyTransport', () => { beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() delivery.mockReset().mockResolvedValue(true) promptFailure.error.mockClear() promptFailure.copy.mockClear() diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-spawn-intent.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-spawn-intent.test.ts index 486507e6c76..da92575659c 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-spawn-intent.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-transport-spawn-intent.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const appStore = vi.hoisted(() => ({ getState: vi.fn(() => { @@ -27,6 +28,7 @@ describe('createRemoteRuntimePtyTransport: restore spawn intent', () => { beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() runtimeCall.mockReset() capabilities = ['agent-session.host-authority.v1'] ensureResponse = { diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-resubscribe-failure-recovery-routing.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-resubscribe-failure-recovery-routing.test.ts index e0bc9465da6..7f3476312df 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-resubscribe-failure-recovery-routing.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-resubscribe-failure-recovery-routing.test.ts @@ -1,3 +1,4 @@ +import { stubRuntimeHostStatusSubscriptions } from '../remote/remote-runtime-pty-transport-test-harness' /** Nonrecoverable resubscribe errors still need central lifecycle routing: stale handles recover, gone/exit retire, SSH expiry delegates to the HUB, and oversized snapshots remain informational. Inject after a connected stream closes. */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const appStore = vi.hoisted(() => ({ @@ -165,6 +166,7 @@ describe('remote runtime resubscribe failure: recovery routing', () => { beforeEach(() => { vi.resetModules() + stubRuntimeHostStatusSubscriptions() vi.doUnmock( '../../../../runtime/hosted-terminals/streams/registry/remote-runtime-terminal-multiplexer-registry' ) diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote/remote-runtime-pty-transport-test-harness.ts b/src/renderer/src/components/terminal-pane/pty-transport/remote/remote-runtime-pty-transport-test-harness.ts index 93e494985f6..ea722277114 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote/remote-runtime-pty-transport-test-harness.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote/remote-runtime-pty-transport-test-harness.ts @@ -51,6 +51,29 @@ export function readyHostSessionInventoryResponse( } } +export function stubRuntimeHostStatusSubscriptions(): ( + snapshot: RuntimeHostStatusSnapshot +) => void { + const hostStatuses = createStore(() => ({ + runtimeStatusByEnvironmentId: new Map() + })) + const runtimeStatusSubscriptions = createRuntimeStatusSubscriptions(hostStatuses) + vi.doMock('@/store/slices/runtime-status/views/runtime-status-subscription-store', () => ({ + runtimeStatusSubscriptions + })) + return (snapshot) => { + hostStatuses.setState({ + runtimeStatusByEnvironmentId: new Map( + hostStatuses.getState().runtimeStatusByEnvironmentId + ).set(snapshot.environmentId, { + snapshot, + status: snapshot.retired ? null : snapshot.status, + checkedAt: snapshot.checkedAt + }) + }) + } +} + export type RemoteRuntimeTransportMocks = { publishHostSnapshot: (snapshot: RuntimeHostStatusSnapshot) => void // Why: specs re-implement these with their own request/callback shapes, so keep the loose spy type. @@ -67,20 +90,8 @@ export function createRemoteRuntimeTransportMocks( bindings: RemoteRuntimeTransportBindings ): RemoteRuntimeTransportMocks { const runtimeCall = vi.fn() - let hostStatuses = createStore(() => ({ - runtimeStatusByEnvironmentId: new Map() - })) - let runtimeStatusSubscriptions = createRuntimeStatusSubscriptions(hostStatuses) - const publishHostSnapshot = (snapshot: RuntimeHostStatusSnapshot): void => { - hostStatuses.setState({ - runtimeStatusByEnvironmentId: new Map( - hostStatuses.getState().runtimeStatusByEnvironmentId - ).set(snapshot.environmentId, { - snapshot, - status: snapshot.retired ? null : snapshot.status, - checkedAt: snapshot.checkedAt - }) - }) + let publishHostSnapshot: (snapshot: RuntimeHostStatusSnapshot) => void = () => { + throw new Error('Reset the runtime transport fixture before publishing host state') } const runtimeSubscribe = vi.fn() const refreshSessionTabsSnapshot = vi.fn(async () => {}) @@ -92,13 +103,7 @@ export function createRemoteRuntimeTransportMocks( function resetRemoteRuntimeTransport(): void { vi.resetModules() - hostStatuses = createStore(() => ({ - runtimeStatusByEnvironmentId: new Map() - })) - runtimeStatusSubscriptions = createRuntimeStatusSubscriptions(hostStatuses) - vi.doMock('@/store/slices/runtime-status/views/runtime-status-subscription-store', () => ({ - runtimeStatusSubscriptions - })) + publishHostSnapshot = stubRuntimeHostStatusSubscriptions() vi.doUnmock( '../../../../runtime/hosted-terminals/streams/registry/remote-runtime-terminal-multiplexer-registry' ) @@ -174,7 +179,7 @@ export function createRemoteRuntimeTransportMocks( } return { - publishHostSnapshot, + publishHostSnapshot: (snapshot) => publishHostSnapshot(snapshot), runtimeCall, runtimeSubscribe, refreshSessionTabsSnapshot,