Align remote transport fixtures with host lifetime subscriptions

This commit is contained in:
Brennan Benson
2026-11-09 02:58:51 -08:00
parent 787cf337e0
commit fb1dbe280b
10 changed files with 48 additions and 26 deletions
@@ -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'
)
@@ -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'
)
@@ -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'
)
@@ -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'
)
@@ -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'
)
@@ -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()!
@@ -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()
@@ -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 = {
@@ -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'
)
@@ -51,6 +51,29 @@ export function readyHostSessionInventoryResponse(
}
}
export function stubRuntimeHostStatusSubscriptions(): (
snapshot: RuntimeHostStatusSnapshot
) => void {
const hostStatuses = createStore(() => ({
runtimeStatusByEnvironmentId: new Map<string, RuntimeEnvironmentStatus>()
}))
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<string, RuntimeEnvironmentStatus>()
}))
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<string, RuntimeEnvironmentStatus>()
}))
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,