test(terminal): load the host runtime in setup so the alt-screen chain fits its test limit (#29661)

This commit is contained in:
Neil
2026-10-16 05:33:31 -07:00
committed by GitHub
parent a93fe5e955
commit 78f2e9b174
@@ -1,5 +1,5 @@
import type * as React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { Terminal } from '@xterm/headless'
import {
TerminalStreamOpcode,
@@ -159,24 +159,54 @@ async function render(events: PaneEvent[]): Promise<Terminal> {
return term
}
type HostModules = {
OrcaRuntimeService: new (store: null) => HostRuntime
sendSnapshotFrames: (send: HostSendFrame, options: Record<string, unknown>) => unknown
serializeBudgetedRequestedSnapshot: (
runtime: HostRuntime,
ptyId: string,
scrollbackRows: number
) => Promise<HostSnapshot | null>
installMultiplexFlowControl: (build: HostConnection) => void
}
let hostModules: HostModules | null = null
// Why a hook: the first load of the main runtime graph takes ~19s cold, and charged to the first
// test it crossed the 30s test limit whenever the directory ran in parallel.
async function loadHostModules(): Promise<HostModules> {
const [runtime, publication, flowControl] = await Promise.all([
vi.importActual<Pick<HostModules, 'OrcaRuntimeService'>>(
'../../../../main/runtime/orca-runtime'
),
vi.importActual<Pick<HostModules, 'sendSnapshotFrames' | 'serializeBudgetedRequestedSnapshot'>>(
'../../../../main/runtime/rpc/methods/terminal/terminal-snapshot-publication'
),
vi.importActual<Pick<HostModules, 'installMultiplexFlowControl'>>(
'../../../../main/runtime/rpc/methods/terminal/terminal-multiplex-flow-control'
)
])
return {
OrcaRuntimeService: runtime.OrcaRuntimeService,
sendSnapshotFrames: publication.sendSnapshotFrames,
serializeBudgetedRequestedSnapshot: publication.serializeBudgetedRequestedSnapshot,
installMultiplexFlowControl: flowControl.installMultiplexFlowControl
}
}
/** Real host + client chain: returns what the remote transport hands the pane for the push. */
async function publishHostRecovery(
missed: string
): Promise<{ data: string; meta: PtyReplayDataMeta; published: HostSnapshot }> {
const { OrcaRuntimeService } = await vi.importActual<{
OrcaRuntimeService: new (store: null) => HostRuntime
}>('../../../../main/runtime/orca-runtime')
const { sendSnapshotFrames, serializeBudgetedRequestedSnapshot } = await vi.importActual<{
sendSnapshotFrames: (send: HostSendFrame, options: Record<string, unknown>) => unknown
serializeBudgetedRequestedSnapshot: (
runtime: HostRuntime,
ptyId: string,
scrollbackRows: number
) => Promise<HostSnapshot | null>
}>('../../../../main/runtime/rpc/methods/terminal/terminal-snapshot-publication')
const { installMultiplexFlowControl } = await vi.importActual<{
installMultiplexFlowControl: (build: HostConnection) => void
}>('../../../../main/runtime/rpc/methods/terminal/terminal-multiplex-flow-control')
if (!hostModules) {
throw new Error('host modules are loaded in beforeAll')
}
const {
OrcaRuntimeService,
sendSnapshotFrames,
serializeBudgetedRequestedSnapshot,
installMultiplexFlowControl
} = hostModules
const host = new OrcaRuntimeService(null)
host.setPtyController({
@@ -301,6 +331,10 @@ async function publishHostRecovery(
}
describe('host-published recovery snapshot onto a live alt screen', () => {
beforeAll(async () => {
hostModules = await loadHostModules()
})
beforeEach(async () => {
vi.clearAllMocks()
transportFactoryQueue = []