mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
test: remove low-value output, PDF and download suites (#43459)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -3491,14 +3491,12 @@
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/notifications/pty-connection-hook-idle-arbitration.test.ts": 2228,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/spawn/pty-connection-main-pane-restore-start.test.ts": 2430,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/spawn/pty-connection-main-pane-start.test.ts": 2611,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/output-restore/pty-connection-post-dispose-restore-termination.test.ts": 1215,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/agent-identity/pty-connection-process-exit-row-retire.test.ts": 10626,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/host-ownership/pty-connection-owner-hydration-backend-retention.test.ts": 4181,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/input/pty-connection-remote-new-terminal-typeahead.test.ts": 1864,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/reattach/pty-connection-remote-snapshot-image-title.test.ts": 1754,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/tests/pty-connection-restore-and-resume.test.ts": 19401,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/output-restore/pty-connection-restored-baseline-shortfall.test.ts": 1902,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/output-restore/pty-connection-visible-pane-output-pause-latch.test.ts": 1639,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/reattach/deferred-session-reattach-startup-snapshot.test.ts": 1830,
|
||||
"src/shared/terminal/protocol/escape/terminal-synchronized-output-socket-splits.test.ts": 92,
|
||||
"src/renderer/src/components/terminal-pane/pty-connection/startup/main-pane-resume-banner.test.ts": 59,
|
||||
@@ -4483,7 +4481,6 @@
|
||||
"tests/e2e/orchestration-worker-workspace-resolution.unit.test.ts": 5936,
|
||||
"tests/e2e/paired-cli-agent-launch.unit.test.ts": 8918,
|
||||
"tests/e2e/paired-runtime-rejected-input-remount.unit.test.ts": 9954,
|
||||
"tests/e2e/pdf-detail-dimension-reads.unit.test.ts": 438,
|
||||
"tests/e2e/persistence-automation-target-dispatch.unit.test.ts": 8084,
|
||||
"tests/e2e/remote-agent-completion-authority.unit.test.ts": 1742,
|
||||
"tests/e2e/remote-terminal-input-delivery-model.unit.test.ts": 23690,
|
||||
|
||||
-143
@@ -1,143 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { toast } from 'sonner'
|
||||
import { getConnectionId } from '@/lib/workspace/ownership/connection-context'
|
||||
import { buildFileLinkActions } from './terminal-file-link-actions'
|
||||
import { downloadRemoteTerminalFile } from './terminal-remote-file-download-open'
|
||||
import { openDetectedFolder } from './terminal-folder-open'
|
||||
import type * as ArtifactGrantModule from '@/runtime/files/grants/runtime-terminal-artifact-grant'
|
||||
import { createTerminalLinkTestDoubles } from '../terminal-link-handlers-test-fixtures'
|
||||
import {
|
||||
flushAsyncWork,
|
||||
installTerminalLinkTestEnvironment,
|
||||
setPlatform
|
||||
} from '../terminal-link-handlers-test-harness'
|
||||
|
||||
const doubles = createTerminalLinkTestDoubles()
|
||||
const { storeState, openFileMock, openFilePathMock, statMock } = doubles
|
||||
const downloadFileMock = vi.fn()
|
||||
const downloadFolderMock = vi.fn()
|
||||
|
||||
vi.mock('sonner', () => ({
|
||||
toast: { error: vi.fn(), info: vi.fn(), success: vi.fn() }
|
||||
}))
|
||||
|
||||
vi.mock('@/store/index', () => ({
|
||||
useAppStore: {
|
||||
getState: () => storeState
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/workspace/activation/worktree-activation', () => ({
|
||||
activateAndRevealWorkspace: vi.fn(),
|
||||
activateAndRevealWorktree: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('./terminal-folder-open', () => ({ openDetectedFolder: vi.fn() }))
|
||||
|
||||
vi.mock('@/runtime/files/grants/runtime-terminal-artifact-grant', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof ArtifactGrantModule>()),
|
||||
hostStreamsGrantedFiles: vi.fn(async () => false)
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/workspace/ownership/connection-context', () => ({
|
||||
getConnectionId: vi.fn(() => null)
|
||||
}))
|
||||
|
||||
installTerminalLinkTestEnvironment(doubles)
|
||||
|
||||
beforeEach(() => {
|
||||
setPlatform('Windows')
|
||||
vi.mocked(getConnectionId).mockReturnValue('box')
|
||||
storeState.worktreesByRepo = {
|
||||
repo1: [{ id: 'wt-1', path: '/home/me/repo', repoId: 'repo1', hostId: 'ssh:box' }]
|
||||
}
|
||||
downloadFileMock.mockResolvedValue({ canceled: false, destinationPath: 'C:\\Users\\me\\run.sh' })
|
||||
downloadFolderMock.mockResolvedValue({ canceled: false, destinationPath: 'C:\\Users\\me\\out' })
|
||||
Object.assign(window.api.fs, {
|
||||
downloadFile: downloadFileMock,
|
||||
downloadFolder: downloadFolderMock
|
||||
})
|
||||
Object.assign(storeState, { sshConnectionStates: new Map() })
|
||||
Object.assign(window.api, { platform: { get: () => ({ platform: 'win32' }) } })
|
||||
})
|
||||
|
||||
describe('remote file link download action', () => {
|
||||
it('saves an SSH file without opening it', async () => {
|
||||
const actions = buildFileLinkActions(
|
||||
'/home/me/repo/run.sh',
|
||||
null,
|
||||
null,
|
||||
{ worktreeId: 'wt-1', worktreePath: '/home/me/repo', runtimeEnvironmentId: null },
|
||||
{ kind: 'ssh', connectionId: 'box' }
|
||||
)
|
||||
const download = actions.secondaryActions?.find((row) => row.label === 'Download…')
|
||||
|
||||
expect(download).toBeDefined()
|
||||
await download?.run()
|
||||
await flushAsyncWork()
|
||||
|
||||
expect(downloadFileMock).toHaveBeenCalledWith({
|
||||
filePath: '/home/me/repo/run.sh',
|
||||
connectionId: 'box'
|
||||
})
|
||||
expect(openFilePathMock).not.toHaveBeenCalled()
|
||||
expect(openFileMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each([
|
||||
[true, 1, 'success'],
|
||||
[false, 0, 'error']
|
||||
] as const)(
|
||||
'with folder transfer %s, saves or reports a folder link instead of revealing it',
|
||||
async (supportsFolderDownload, downloads, toastKind) => {
|
||||
statMock.mockResolvedValue({ isDirectory: true })
|
||||
Object.assign(storeState, {
|
||||
sshConnectionStates: new Map([['box', { supportsFolderDownload }]])
|
||||
})
|
||||
const actions = buildFileLinkActions(
|
||||
'/home/me/repo/out',
|
||||
null,
|
||||
null,
|
||||
{ worktreeId: 'wt-1', worktreePath: '/home/me/repo', runtimeEnvironmentId: null },
|
||||
{ kind: 'ssh', connectionId: 'box' }
|
||||
)
|
||||
const download = actions.secondaryActions?.find((row) => row.label === 'Download…')
|
||||
|
||||
expect(download).toBeDefined()
|
||||
await download?.run()
|
||||
await flushAsyncWork()
|
||||
|
||||
expect(downloadFolderMock).toHaveBeenCalledTimes(downloads)
|
||||
expect(toast[toastKind]).toHaveBeenCalledTimes(1)
|
||||
expect(openDetectedFolder).not.toHaveBeenCalled()
|
||||
expect(downloadFileMock).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
|
||||
it('reports a path the host disowned that is on this computer instead of opening it', async () => {
|
||||
await downloadRemoteTerminalFile(
|
||||
{ target: { kind: 'local' }, worktreeId: 'wt-1', worktreePath: '/home/me/repo' },
|
||||
'/home/me/repo/run.sh',
|
||||
null
|
||||
)
|
||||
|
||||
expect(toast.info).toHaveBeenCalledTimes(1)
|
||||
expect(downloadFileMock).not.toHaveBeenCalled()
|
||||
expect(openFilePathMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('tells the user to update a paired server that cannot stream a granted file', async () => {
|
||||
await downloadRemoteTerminalFile(
|
||||
{
|
||||
target: { kind: 'environment', environmentId: 'env-1' },
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/home/me/repo'
|
||||
},
|
||||
'/tmp/run.sh',
|
||||
{ terminalArtifactGrantId: 'g1' }
|
||||
)
|
||||
|
||||
expect(toast.error).toHaveBeenCalledWith(expect.stringContaining('newer Orca server'))
|
||||
expect(openFilePathMock).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
-167
@@ -1,167 +0,0 @@
|
||||
import type * as React from 'react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushAsyncTicks } from '../test-fixtures/pty-connection-test-async'
|
||||
import {
|
||||
createMockTransport,
|
||||
createPane,
|
||||
captureCallbackTerminalWrites,
|
||||
createManager
|
||||
} from '../test-fixtures/pty-connection-test-pane-fixtures'
|
||||
import type {
|
||||
ConnectCallbacks,
|
||||
MockTransport
|
||||
} from '../test-fixtures/pty-connection-test-pane-fixtures'
|
||||
import {
|
||||
buildPaneConnectionDeps,
|
||||
type PtyConnectionAgentTitleMocks,
|
||||
bindPaneAgentTitleMocks
|
||||
} from '../test-fixtures/pty-connection-test-deps'
|
||||
import { createInitialStoreState } from '../test-fixtures/pty-connection-test-store-fixtures'
|
||||
import type { StoreState } from '../test-fixtures/pty-connection-test-store-state'
|
||||
import {
|
||||
installTerminalTestGlobals,
|
||||
restoreTerminalTestGlobals
|
||||
} from '../test-fixtures/pty-connection-test-environment'
|
||||
|
||||
const { scheduleRuntimeGraphSync, shouldSeedCacheTimerOnInitialTitle, toastInfo } = vi.hoisted(
|
||||
() => ({
|
||||
scheduleRuntimeGraphSync: vi.fn(),
|
||||
shouldSeedCacheTimerOnInitialTitle: vi.fn(() => false),
|
||||
toastInfo: vi.fn()
|
||||
})
|
||||
)
|
||||
|
||||
let mockStoreState: StoreState
|
||||
let transportFactoryQueue: MockTransport[] = []
|
||||
let storeSubscribers: ((state: StoreState) => void)[] = []
|
||||
|
||||
vi.mock('@/runtime/sync-runtime-graph/graph-sync-scheduler', () => ({ scheduleRuntimeGraphSync }))
|
||||
|
||||
vi.mock('@/store/index', () => ({
|
||||
useAppStore: {
|
||||
getState: () => mockStoreState,
|
||||
subscribe: (listener: (state: StoreState) => void) => {
|
||||
storeSubscribers.push(listener)
|
||||
return () => {
|
||||
storeSubscribers = storeSubscribers.filter((candidate) => candidate !== listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/agent-status/aggregation/worktree-agent-status', async (importOriginal) => {
|
||||
const { buildAgentStatusModuleMock } =
|
||||
await import('../test-fixtures/pty-connection-test-environment')
|
||||
return buildAgentStatusModuleMock(await importOriginal<Record<string, unknown>>())
|
||||
})
|
||||
|
||||
vi.mock('../../titles/cache-timer-seeding', () => ({ shouldSeedCacheTimerOnInitialTitle }))
|
||||
|
||||
vi.mock('sonner', () => ({ toast: { info: toastInfo } }))
|
||||
|
||||
vi.mock('react', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof React>()
|
||||
return {
|
||||
...actual,
|
||||
useCallback: <T extends (...args: unknown[]) => unknown>(fn: T): T => fn
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('../../pty-transport/ipc/pty-transport', () => ({
|
||||
createIpcPtyTransport: vi.fn(() => {
|
||||
const nextTransport = transportFactoryQueue.shift()
|
||||
if (!nextTransport) {
|
||||
throw new Error('No mock transport queued')
|
||||
}
|
||||
return nextTransport
|
||||
})
|
||||
}))
|
||||
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules()
|
||||
vi.clearAllMocks()
|
||||
transportFactoryQueue = []
|
||||
storeSubscribers = []
|
||||
mockStoreState = createInitialStoreState(() => mockStoreState)
|
||||
await installTerminalTestGlobals()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
// Disposed restore tasks must not re-arm from finally: instant exits otherwise create an unbounded promise chain that exhausts the heap.
|
||||
it('stops re-arming the hidden output restore once the pane binding is disposed', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const getMainBufferSnapshot = window.api.pty.getMainBufferSnapshot as unknown as ReturnType<
|
||||
typeof vi.fn
|
||||
>
|
||||
const hidden = 'x'.repeat(2 * 1024 * 1024 + 1)
|
||||
const live = 'visible-after\r\n'
|
||||
getMainBufferSnapshot.mockResolvedValue({
|
||||
data: 'snapshot-state\r\n',
|
||||
cols: 100,
|
||||
rows: 30,
|
||||
seq: hidden.length + live.length
|
||||
})
|
||||
|
||||
const pane = createPane(1)
|
||||
const { writes } = captureCallbackTerminalWrites(pane)
|
||||
|
||||
// Count visibility getter reads to measure finally re-arms deterministically without timing or memory heuristics.
|
||||
let visibilityReads = 0
|
||||
let visible = false
|
||||
const isVisibleRef = {
|
||||
get current() {
|
||||
visibilityReads += 1
|
||||
return visible
|
||||
},
|
||||
set current(next: boolean) {
|
||||
visible = next
|
||||
}
|
||||
}
|
||||
const deps = buildPaneConnectionDeps(() => mockStoreState, { isVisibleRef })
|
||||
|
||||
const disposable = connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
// Arm the restore: hidden bytes land while the pane is hidden, then it is revealed.
|
||||
capturedDataCallback.current?.(hidden, { seq: hidden.length, rawLength: hidden.length })
|
||||
visible = true
|
||||
capturedDataCallback.current?.(live, {
|
||||
seq: hidden.length + live.length,
|
||||
rawLength: live.length
|
||||
})
|
||||
await flushAsyncTicks(20)
|
||||
|
||||
expect(getMainBufferSnapshot).toHaveBeenCalledTimes(1)
|
||||
expect(writes).toContain('snapshot-state\r\n')
|
||||
disposable.dispose()
|
||||
const readsAtDispose = visibilityReads
|
||||
try {
|
||||
await flushAsyncTicks(200)
|
||||
expect(visibilityReads - readsAtDispose).toBeLessThan(50)
|
||||
} finally {
|
||||
// Stop a regressed re-arm loop after measuring it so failures can finish.
|
||||
visible = false
|
||||
}
|
||||
})
|
||||
})
|
||||
-179
@@ -1,179 +0,0 @@
|
||||
// STA-4593: reveal during a null-ID rebind cannot unpause immediately; reconnect must rederive pause intent from live visibility or the host drops visible output indefinitely. Test both connect and stream-recovery callbacks.
|
||||
import type * as React from 'react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushAsyncTicks } from '../test-fixtures/pty-connection-test-async'
|
||||
import {
|
||||
createMockTransport,
|
||||
createPane,
|
||||
createManager,
|
||||
type ConnectCallbacks,
|
||||
type MockTransport
|
||||
} from '../test-fixtures/pty-connection-test-pane-fixtures'
|
||||
import {
|
||||
buildPaneConnectionDeps,
|
||||
type PtyConnectionAgentTitleMocks,
|
||||
bindPaneAgentTitleMocks
|
||||
} from '../test-fixtures/pty-connection-test-deps'
|
||||
import { createInitialStoreState } from '../test-fixtures/pty-connection-test-store-fixtures'
|
||||
import type { StoreState } from '../test-fixtures/pty-connection-test-store-state'
|
||||
import {
|
||||
installTerminalTestGlobals,
|
||||
restoreTerminalTestGlobals
|
||||
} from '../test-fixtures/pty-connection-test-environment'
|
||||
|
||||
const { scheduleRuntimeGraphSync, shouldSeedCacheTimerOnInitialTitle } = vi.hoisted(() => ({
|
||||
scheduleRuntimeGraphSync: vi.fn(),
|
||||
shouldSeedCacheTimerOnInitialTitle: vi.fn(() => false)
|
||||
}))
|
||||
|
||||
let mockStoreState: StoreState
|
||||
let transportFactoryQueue: MockTransport[] = []
|
||||
let storeSubscribers: ((state: StoreState) => void)[] = []
|
||||
|
||||
vi.mock('@/runtime/sync-runtime-graph/graph-sync-scheduler', () => ({
|
||||
scheduleRuntimeGraphSync
|
||||
}))
|
||||
|
||||
vi.mock('@/store/index', () => ({
|
||||
useAppStore: {
|
||||
getState: () => mockStoreState,
|
||||
subscribe: (listener: (state: StoreState) => void) => {
|
||||
storeSubscribers.push(listener)
|
||||
return () => {
|
||||
storeSubscribers = storeSubscribers.filter((candidate) => candidate !== listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/agent-status/aggregation/worktree-agent-status', async (importOriginal) => {
|
||||
const { buildAgentStatusModuleMock } =
|
||||
await import('../test-fixtures/pty-connection-test-environment')
|
||||
return buildAgentStatusModuleMock(await importOriginal<Record<string, unknown>>())
|
||||
})
|
||||
|
||||
vi.mock('../../titles/cache-timer-seeding', () => ({
|
||||
shouldSeedCacheTimerOnInitialTitle
|
||||
}))
|
||||
|
||||
vi.mock('react', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof React>()
|
||||
return {
|
||||
...actual,
|
||||
useCallback: <T extends (...args: unknown[]) => unknown>(fn: T): T => fn
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('../../pty-transport/ipc/pty-transport', () => ({
|
||||
createIpcPtyTransport: vi.fn(() => {
|
||||
const nextTransport = transportFactoryQueue.shift()
|
||||
if (!nextTransport) {
|
||||
throw new Error('No mock transport queued')
|
||||
}
|
||||
return nextTransport
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('../../pty-transport/remote-runtime/remote-runtime-pty-transport', () => ({
|
||||
createRemoteRuntimePtyTransport: vi.fn(() => {
|
||||
const nextTransport = transportFactoryQueue.shift()
|
||||
if (!nextTransport) {
|
||||
throw new Error('No mock transport queued')
|
||||
}
|
||||
return nextTransport
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('../../pty-transport/delivery/pty-dispatcher', async (importOriginal) => {
|
||||
const actual = await importOriginal<Record<string, unknown>>()
|
||||
return {
|
||||
...actual,
|
||||
getEagerPtyBufferHandle: vi.fn(() => undefined)
|
||||
}
|
||||
})
|
||||
|
||||
const REMOTE_PTY_ID = 'remote:env-1@@terminal-1'
|
||||
|
||||
function createDeps(overrides: Record<string, unknown> = {}) {
|
||||
return buildPaneConnectionDeps(() => mockStoreState, overrides)
|
||||
}
|
||||
|
||||
type Binding = { syncProcessTracking: () => void; dispose: () => void }
|
||||
|
||||
async function connectVisibleRemotePane(): Promise<{
|
||||
transport: MockTransport
|
||||
binding: Binding
|
||||
deps: ReturnType<typeof createDeps>
|
||||
callbacks: () => ConnectCallbacks
|
||||
pauseCalls: () => boolean[]
|
||||
}> {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport(REMOTE_PTY_ID)
|
||||
transport.setOutputPaused = vi.fn(() => true)
|
||||
transport.serializeBuffer = vi.fn()
|
||||
const captured: { callbacks: ConnectCallbacks | null } = { callbacks: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
captured.callbacks = callbacks
|
||||
return REMOTE_PTY_ID
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
const deps = createDeps({ isVisibleRef: { current: true } })
|
||||
const binding = connectPanePty(
|
||||
createPane(1) as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
expect(captured.callbacks).not.toBeNull()
|
||||
return {
|
||||
transport,
|
||||
binding,
|
||||
deps,
|
||||
callbacks: () => captured.callbacks!,
|
||||
pauseCalls: () =>
|
||||
(transport.setOutputPaused as ReturnType<typeof vi.fn>).mock.calls.map(
|
||||
([paused]) => paused as boolean
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
describe('remote pane output pause vs visibility', () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules()
|
||||
vi.clearAllMocks()
|
||||
transportFactoryQueue = []
|
||||
storeSubscribers = []
|
||||
mockStoreState = createInitialStoreState(() => mockStoreState)
|
||||
await installTerminalTestGlobals()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('red: a content-bearing recovery fires only onConnect, which must re-derive the pause bit alone', async () => {
|
||||
const { transport, binding, deps, callbacks, pauseCalls } = await connectVisibleRemotePane()
|
||||
|
||||
;(deps.isVisibleRef as { current: boolean }).current = false
|
||||
binding.syncProcessTracking()
|
||||
expect(pauseCalls().at(-1)).toBe(true)
|
||||
|
||||
transport.getPtyId.mockImplementation(() => null)
|
||||
;(deps.isVisibleRef as { current: boolean }).current = true
|
||||
binding.syncProcessTracking()
|
||||
|
||||
// Contentful recovery fires only onConnect; it must repair pause intent without onStreamRecovered.
|
||||
transport.getPtyId.mockImplementation(() => REMOTE_PTY_ID)
|
||||
callbacks().onConnect?.()
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(
|
||||
pauseCalls().at(-1),
|
||||
`onConnect alone did not unpause a visible pane (setOutputPaused calls: ${JSON.stringify(pauseCalls())})`
|
||||
).toBe(false)
|
||||
binding.dispose()
|
||||
})
|
||||
})
|
||||
@@ -1,132 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import type { PDFPageProxy } from 'pdfjs-dist'
|
||||
// The legacy entry supplies the same Node polyfills used by the PDF find tests.
|
||||
import { getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs'
|
||||
import { EventBus, PDFPageView, RenderingStates } from 'pdfjs-dist/web/pdf_viewer.mjs'
|
||||
import { afterAll, afterEach, beforeAll, expect, it, vi } from 'vitest'
|
||||
import { createPdfFindFixture } from './helpers/pdf-find-fixture'
|
||||
|
||||
let loadingTask: ReturnType<typeof getDocument> | undefined
|
||||
let pdfPage: PDFPageProxy
|
||||
const pageViews: PDFPageView[] = []
|
||||
|
||||
beforeAll(async () => {
|
||||
loadingTask = getDocument({ data: new Uint8Array(createPdfFindFixture()) })
|
||||
pdfPage = await (await loadingTask.promise).getPage(1)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
for (const pageView of pageViews) {
|
||||
pageView.destroy()
|
||||
}
|
||||
pageViews.length = 0
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await loadingTask?.destroy()
|
||||
})
|
||||
|
||||
it.each([1, 10])('bounds detail update dimension reads across %i eligible owners', (population) => {
|
||||
vi.stubGlobal('devicePixelRatio', 1)
|
||||
const initialArea = { minX: 400, minY: 400, maxX: 500, maxY: 500 }
|
||||
const owners = Array.from({ length: population }, (_, index) => {
|
||||
const pageView = new PDFPageView({
|
||||
id: index + 1,
|
||||
eventBus: new EventBus(),
|
||||
defaultViewport: pdfPage.getViewport({ scale: 1 }),
|
||||
maxCanvasPixels: 1_000_000,
|
||||
capCanvasAreaFactor: -1,
|
||||
enableSelectionRendering: false
|
||||
})
|
||||
pageViews.push(pageView)
|
||||
pageView.setPdfPage(pdfPage)
|
||||
pageView.update({ scale: 4 })
|
||||
pageView._ensureCanvasWrapper()
|
||||
const wrapper = pageView.div.querySelector('.canvasWrapper')
|
||||
if (!(wrapper instanceof HTMLElement)) {
|
||||
throw new Error('Missing PDF canvas wrapper')
|
||||
}
|
||||
const reads = { count: 0 }
|
||||
Object.defineProperties(wrapper, {
|
||||
clientWidth: {
|
||||
get() {
|
||||
reads.count += 1
|
||||
return 3264
|
||||
}
|
||||
},
|
||||
clientHeight: {
|
||||
get() {
|
||||
reads.count += 1
|
||||
return 4224
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.clientWidth).toBe(3264)
|
||||
expect(wrapper.clientHeight).toBe(4224)
|
||||
expect(reads.count).toBe(2)
|
||||
pageView.updateVisibleArea(initialArea)
|
||||
const detail = pageView.detailView
|
||||
expect(detail).not.toBeNull()
|
||||
// Only update admission is measured; raster completion is the workload's precondition.
|
||||
detail.renderingState = RenderingStates.FINISHED
|
||||
const reset = vi.spyOn(detail, 'reset')
|
||||
reads.count = 0
|
||||
return { pageView, detail, reset, reads, area: initialArea }
|
||||
})
|
||||
const countReads = (): number => owners.reduce((sum, owner) => sum + owner.reads.count, 0)
|
||||
const clearCounts = (): void => {
|
||||
for (const owner of owners) {
|
||||
owner.reads.count = 0
|
||||
owner.reset.mockClear()
|
||||
}
|
||||
}
|
||||
const updateAll = (): void => {
|
||||
for (const owner of owners) {
|
||||
owner.pageView.updateVisibleArea(owner.area)
|
||||
}
|
||||
}
|
||||
const expectUnchanged = (): void => {
|
||||
for (const owner of owners) {
|
||||
expect(owner.pageView.detailView).toBe(owner.detail)
|
||||
expect(owner.detail.renderingState).toBe(RenderingStates.FINISHED)
|
||||
expect(owner.reset).not.toHaveBeenCalled()
|
||||
}
|
||||
}
|
||||
|
||||
updateAll()
|
||||
expect(countReads()).toBeLessThanOrEqual(2 * population)
|
||||
expectUnchanged()
|
||||
|
||||
clearCounts()
|
||||
owners[0].area = { ...initialArea, minX: 480, maxX: 580 }
|
||||
updateAll()
|
||||
expect(countReads()).toBeLessThanOrEqual(2 * (population - 1) + 4)
|
||||
for (const [index, owner] of owners.entries()) {
|
||||
expect(owner.pageView.detailView).toBe(owner.detail)
|
||||
expect(owner.reset).toHaveBeenCalledTimes(index === 0 ? 1 : 0)
|
||||
expect(owner.detail.renderingState).toBe(
|
||||
index === 0 ? RenderingStates.INITIAL : RenderingStates.FINISHED
|
||||
)
|
||||
}
|
||||
|
||||
owners[0].detail.renderingState = RenderingStates.FINISHED
|
||||
clearCounts()
|
||||
for (let pass = 0; pass < 10; pass += 1) {
|
||||
updateAll()
|
||||
}
|
||||
expect(countReads()).toBeLessThanOrEqual(20 * population)
|
||||
expectUnchanged()
|
||||
|
||||
clearCounts()
|
||||
for (const owner of owners) {
|
||||
owner.pageView.updateVisibleArea(null)
|
||||
expect(owner.pageView.detailView).toBeNull()
|
||||
expect(owner.reset).toHaveBeenCalledTimes(1)
|
||||
owner.pageView.updateVisibleArea(null)
|
||||
expect(owner.reset).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
expect(countReads()).toBe(0)
|
||||
})
|
||||
Reference in New Issue
Block a user