mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
test: remove four low-value renderer suites and redundant cases
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -6124,7 +6124,6 @@
|
||||
"src/renderer/src/hooks/useIpcEvents-browser-certificate-failure.test.ts": 2981,
|
||||
"src/renderer/src/hooks/useIpcEvents-browser-navigation.test.ts": 1511,
|
||||
"src/renderer/src/hooks/useIpcEvents-client-hosted-browser-rows.test.ts": 1894,
|
||||
"src/renderer/src/hooks/useIpcEvents-close-routing-active-browser-tab.test.ts": 4572,
|
||||
"src/renderer/src/hooks/useIpcEvents-close-routing-session-tabs.test.ts": 5812,
|
||||
"src/renderer/src/hooks/useIpcEvents-lifecycle.test.ts": 2326,
|
||||
"src/renderer/src/hooks/useIpcEvents-new-workspace-shortcut.test.ts": 72,
|
||||
@@ -6404,7 +6403,6 @@
|
||||
"src/renderer/src/lib/workspace/activation/worktree-activation-structured-chat-surface.test.ts": 2043,
|
||||
"src/renderer/src/lib/workspace/activation/worktree-activation-web-runtime.test.ts": 2768,
|
||||
"src/renderer/src/lib/workspace/activation/worktree-agent-activation-seam.test.ts": 3440,
|
||||
"src/renderer/src/lib/workspace/creation/worktree-creation-backend-startup-focus.test.ts": 2267,
|
||||
"src/renderer/src/lib/workspace/creation/worktree-creation-initial-surface.test.ts": 5258,
|
||||
"src/renderer/src/lib/workspace/creation/worktree-creation-structured-session-lifecycle.test.ts": 2633,
|
||||
"src/renderer/src/lib/workspace/creation/worktree-creation-structured-session-prompts.test.tsx": 4554,
|
||||
@@ -6578,7 +6576,6 @@
|
||||
"src/renderer/src/store/slices/browser/cleanup/browser-cleanup-close.test.ts": 1911,
|
||||
"src/renderer/src/store/slices/browser/cleanup/browser-mount-admission-removal.test.ts": 1982,
|
||||
"src/renderer/src/store/slices/browser/pages/browser-page-conversion.test.ts": 1777,
|
||||
"src/renderer/src/store/slices/browser/hosts/browser-remote-tab-creation.test.ts": 2119,
|
||||
"src/renderer/src/store/slices/browser/hosts/browser-session-host-selection.test.ts": 988,
|
||||
"src/renderer/src/store/slices/browser/profiles/browser-session-profiles.test.ts": 792,
|
||||
"src/renderer/src/store/slices/browser/tabs/browser-tab-creation-placement.test.ts": 1886,
|
||||
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { makeTerminalTab } from '@/store/terminals/terminal-row.test-fixture'
|
||||
import { status } from '@/components/native-chat/messages/agent-senders/native-chat-agent-sender.test-fixture'
|
||||
import { whenAgentTerminalAppears } from './agent-terminal-presence'
|
||||
|
||||
const initial = useAppStore.getState()
|
||||
|
||||
afterEach(() => {
|
||||
useAppStore.setState(initial, true)
|
||||
})
|
||||
|
||||
describe('whenAgentTerminalAppears', () => {
|
||||
it('ignores a Claude status entry from a native chat tab', () => {
|
||||
const onAppear = vi.fn()
|
||||
useAppStore.setState({
|
||||
tabsByWorktree: {},
|
||||
agentStatusByPaneKey: {},
|
||||
paneForegroundAgentByPaneKey: {}
|
||||
})
|
||||
const unsubscribe = whenAgentTerminalAppears('claude', onAppear)
|
||||
const entry = status(1)
|
||||
useAppStore.setState({ agentStatusByPaneKey: { [entry.paneKey]: entry } })
|
||||
expect(onAppear).not.toHaveBeenCalled()
|
||||
unsubscribe()
|
||||
})
|
||||
|
||||
it('fires for a Claude status entry from a terminal tab', () => {
|
||||
const onAppear = vi.fn()
|
||||
useAppStore.setState({
|
||||
tabsByWorktree: { workspace: [makeTerminalTab({ id: 'tab-1', worktreeId: 'workspace' })] },
|
||||
agentStatusByPaneKey: {},
|
||||
paneForegroundAgentByPaneKey: {}
|
||||
})
|
||||
whenAgentTerminalAppears('claude', onAppear)
|
||||
const entry = status(1)
|
||||
useAppStore.setState({ agentStatusByPaneKey: { [entry.paneKey]: entry } })
|
||||
expect(onAppear).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
+1
-172
@@ -1,83 +1,9 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { CLIPBOARD_TEXT_MEASURE_YIELD_CODE_UNITS } from '../../../../../../../shared/clipboard-text'
|
||||
import {
|
||||
createRemoteRuntimePtyTextBatcher,
|
||||
createRemoteRuntimeViewportBatcher
|
||||
} from './remote-runtime-pty-batching'
|
||||
import { createRemoteRuntimePtyTextBatcher } from './remote-runtime-pty-batching'
|
||||
|
||||
describe('createRemoteRuntimePtyTextBatcher', () => {
|
||||
it('sends idle input at once and coalesces input inside the window', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const flushes: string[] = []
|
||||
const batcher = createRemoteRuntimePtyTextBatcher(10, (text) => flushes.push(text), {
|
||||
maxPendingBytes: 8
|
||||
})
|
||||
|
||||
expect(batcher.push('a')).toBe(true)
|
||||
expect(flushes).toEqual(['a'])
|
||||
expect(batcher.push('b')).toBe(true)
|
||||
expect(batcher.push('c')).toBe(true)
|
||||
expect(flushes).toEqual(['a'])
|
||||
// Why: a remount during the window discards these, and the pane must know to say so.
|
||||
expect(batcher.hasPendingInput()).toBe(true)
|
||||
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
expect(flushes).toEqual(['a', 'bc'])
|
||||
expect(batcher.hasPendingInput()).toBe(false)
|
||||
|
||||
// The window stays open after a trailing flush; once it lapses idle, the next key goes at once.
|
||||
expect(batcher.push('d')).toBe(true)
|
||||
expect(flushes).toEqual(['a', 'bc'])
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
expect(flushes).toEqual(['a', 'bc', 'd'])
|
||||
await vi.advanceTimersByTimeAsync(10)
|
||||
expect(batcher.push('e')).toBe(true)
|
||||
expect(flushes).toEqual(['a', 'bc', 'd', 'e'])
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps idle input trailing while the leading edge is disabled', () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const flushes: string[] = []
|
||||
const batcher = createRemoteRuntimePtyTextBatcher(10, (text) => flushes.push(text), {
|
||||
sendLeadingEdge: () => false
|
||||
})
|
||||
|
||||
expect(batcher.push('a')).toBe(true)
|
||||
expect(batcher.push('b')).toBe(true)
|
||||
expect(flushes).toEqual([])
|
||||
vi.advanceTimersByTime(10)
|
||||
expect(flushes).toEqual(['ab'])
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('flushes before pending input exceeds the byte ceiling', () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const flushes: string[] = []
|
||||
const batcher = createRemoteRuntimePtyTextBatcher(10, (text) => flushes.push(text), {
|
||||
maxPendingBytes: 4
|
||||
})
|
||||
|
||||
expect(batcher.push('x')).toBe(true)
|
||||
expect(batcher.push('ab')).toBe(true)
|
||||
expect(batcher.push('cd')).toBe(true)
|
||||
expect(flushes).toEqual(['x'])
|
||||
|
||||
expect(batcher.push('e')).toBe(true)
|
||||
expect(flushes).toEqual(['x', 'abcd', 'e'])
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('splits one large UTF-8 input without splitting a code point', () => {
|
||||
const flushes: string[] = []
|
||||
const batcher = createRemoteRuntimePtyTextBatcher(10, (text) => flushes.push(text), {
|
||||
@@ -91,64 +17,6 @@ describe('createRemoteRuntimePtyTextBatcher', () => {
|
||||
expect(flushes).toEqual(['ab', '😀', 'cd'])
|
||||
})
|
||||
|
||||
it('rejects oversized input without flushing clipboard content', () => {
|
||||
const flushes: string[] = []
|
||||
const batcher = createRemoteRuntimePtyTextBatcher(10, (text) => flushes.push(text), {
|
||||
maxBytes: 4,
|
||||
maxPendingBytes: 4
|
||||
})
|
||||
|
||||
const secret = ['secret-token-', 'payload'].join('')
|
||||
|
||||
expect(batcher.push(secret)).toBe(false)
|
||||
expect(flushes).toEqual([])
|
||||
})
|
||||
|
||||
it('yields while validating large accepted input before sending it', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const flushes: string[] = []
|
||||
const text = 'x'.repeat(CLIPBOARD_TEXT_MEASURE_YIELD_CODE_UNITS + 1)
|
||||
const batcher = createRemoteRuntimePtyTextBatcher(10, (value) => flushes.push(value), {
|
||||
maxPendingBytes: text.length + 1
|
||||
})
|
||||
|
||||
expect(batcher.push(text)).toBe(true)
|
||||
expect(flushes).toEqual([])
|
||||
|
||||
const drained = batcher.drain()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
await drained
|
||||
|
||||
expect(flushes).toEqual([text])
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps input queued after deferred validation in byte order', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const flushes: string[] = []
|
||||
const text = 'x'.repeat(CLIPBOARD_TEXT_MEASURE_YIELD_CODE_UNITS + 1)
|
||||
const batcher = createRemoteRuntimePtyTextBatcher(1_000, (value) => flushes.push(value), {
|
||||
maxPendingBytes: text.length + 10
|
||||
})
|
||||
|
||||
expect(batcher.push(text)).toBe(true)
|
||||
expect(batcher.push('tail')).toBe(true)
|
||||
|
||||
const drained = batcher.drain()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
await drained
|
||||
|
||||
expect(flushes).toEqual([text])
|
||||
expect(batcher.takePending()).toBe('tail')
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('runs a validation barrier before input queued after it', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
@@ -202,42 +70,3 @@ describe('createRemoteRuntimePtyTextBatcher', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('createRemoteRuntimeViewportBatcher', () => {
|
||||
it('drops the queued viewport on clear so a later flush emits nothing', () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const resizes: { cols: number; rows: number }[] = []
|
||||
const batcher = createRemoteRuntimeViewportBatcher(33, (cols, rows) => {
|
||||
resizes.push({ cols, rows })
|
||||
})
|
||||
|
||||
batcher.queue(120, 40)
|
||||
batcher.clear()
|
||||
// A stale pending viewport left behind by clear() would leak out here.
|
||||
batcher.flush()
|
||||
|
||||
expect(resizes).toEqual([])
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('does not emit a cleared viewport when the debounce timer would have fired', () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const resizes: { cols: number; rows: number }[] = []
|
||||
const batcher = createRemoteRuntimeViewportBatcher(33, (cols, rows) => {
|
||||
resizes.push({ cols, rows })
|
||||
})
|
||||
|
||||
batcher.queue(90, 30)
|
||||
batcher.clear()
|
||||
vi.advanceTimersByTime(100)
|
||||
|
||||
expect(resizes).toEqual([])
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
-22
@@ -139,28 +139,6 @@ describe('paired client sleep/wake with several remote terminal tabs', () => {
|
||||
return panes
|
||||
}
|
||||
|
||||
it('rebinds every pane after the shared multiplex connection drops', async () => {
|
||||
const panes = await attachAllPanes()
|
||||
const before = subscribedHandles().length
|
||||
|
||||
// Laptop closed: the single multiplex socket dies, taking all six streams.
|
||||
subscriptionCallbacks?.onClose?.()
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(subscribedHandles().length).toBeGreaterThanOrEqual(before + PANE_COUNT)
|
||||
)
|
||||
const afterReconnect = subscribedHandles().slice(before)
|
||||
expect(new Set(afterReconnect).size, `resubscribes: ${JSON.stringify(afterReconnect)}`).toBe(
|
||||
PANE_COUNT
|
||||
)
|
||||
for (const pane of panes) {
|
||||
expect(pane.transport.getPtyId(), `pane ${pane.hostTabId} bound the wrong handle`).toBe(
|
||||
`remote:env-1@@${hostHandleByTabId.get(pane.hostTabId)}`
|
||||
)
|
||||
pane.transport.destroy?.()
|
||||
}
|
||||
})
|
||||
|
||||
it('re-materializes a pane whose host PTY was parked while the client slept', async () => {
|
||||
const panes = await attachAllPanes()
|
||||
const before = subscribedHandles().length
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
useIpcEventsForCloseRouting,
|
||||
type CloseActiveTabListener
|
||||
} from './ipc-events-close-routing-test-harness'
|
||||
|
||||
const { closeWebRuntimeSessionTab, destroyWorkspaceWebviews, isWebRuntimeSessionActive } =
|
||||
vi.hoisted(() => ({
|
||||
closeWebRuntimeSessionTab: vi.fn(),
|
||||
destroyWorkspaceWebviews: vi.fn(),
|
||||
isWebRuntimeSessionActive: vi.fn(() => true)
|
||||
}))
|
||||
|
||||
vi.mock('@/runtime/web-session-tabs-sync/actions/web-runtime-session-tab-lifecycle', () => ({
|
||||
closeWebRuntimeSessionTab
|
||||
}))
|
||||
vi.mock('@/runtime/hosted-terminals/creation/web-runtime-terminal-creation', () => ({
|
||||
createWebRuntimeSessionTerminal: vi.fn()
|
||||
}))
|
||||
vi.mock('@/runtime/web-session-tabs-sync/identity/web-runtime-session-environment', () => ({
|
||||
isWebRuntimeSessionActive
|
||||
}))
|
||||
vi.mock('@/store/slices/browser/cleanup/browser-webview-cleanup', () => ({
|
||||
destroyWorkspaceWebviews
|
||||
}))
|
||||
|
||||
const closeBrowserTab = vi.fn()
|
||||
const closeUnifiedTab = vi.fn()
|
||||
const recordClientHostedBrowserCloseIntents = vi.fn()
|
||||
|
||||
function activeBrowserWorkspace(handle: {
|
||||
environmentId?: string
|
||||
staged?: true
|
||||
}): Record<string, unknown> {
|
||||
return {
|
||||
activeTabType: 'browser',
|
||||
activeBrowserTabId: 'workspace-1',
|
||||
activeWorktreeId: 'wt-1',
|
||||
browserTabsByWorktree: { 'wt-1': [{ id: 'workspace-1' }] },
|
||||
browserPagesByWorkspace: { 'workspace-1': [{ id: 'page-1', workspaceId: 'workspace-1' }] },
|
||||
remoteBrowserPageHandlesByPageId: handle.environmentId
|
||||
? {
|
||||
'page-1': {
|
||||
environmentId: handle.environmentId,
|
||||
remotePageId: 'remote-1',
|
||||
...(handle.staged ? { staged: true } : {})
|
||||
}
|
||||
}
|
||||
: {},
|
||||
unifiedTabsByWorktree: {
|
||||
'wt-1': [{ id: 'unified-1', contentType: 'browser', entityId: 'workspace-1' }]
|
||||
},
|
||||
closeBrowserTab,
|
||||
closeUnifiedTab,
|
||||
recordClientHostedBrowserCloseIntents
|
||||
}
|
||||
}
|
||||
|
||||
/** Pageless host mirror ownership comes from its runtime-owned workspace row, not a local page. */
|
||||
function pagelessHostMirror(): Record<string, unknown> {
|
||||
return {
|
||||
...activeBrowserWorkspace({}),
|
||||
browserPagesByWorkspace: {},
|
||||
worktreesByRepo: {
|
||||
'repo-1': [{ id: 'wt-1', repoId: 'repo-1', runtimeOwnerEnvironmentId: 'env-a' }]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function requireListener(ref: { current: CloseActiveTabListener | null }): CloseActiveTabListener {
|
||||
if (!ref.current) {
|
||||
throw new Error('onCloseActiveTab was never registered')
|
||||
}
|
||||
return ref.current
|
||||
}
|
||||
|
||||
// Runtime connectivity alone does not prove host page ownership; inert host closes leave other tabs standing.
|
||||
describe('useIpcEvents Close Tab on the active browser tab', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
vi.unstubAllGlobals()
|
||||
vi.clearAllMocks()
|
||||
isWebRuntimeSessionActive.mockReturnValue(true)
|
||||
})
|
||||
|
||||
// Staged pages lack host identity yet; inert remote close lets the in-flight snapshot recreate them.
|
||||
it('unwinds a staged workspace as a cleanup close instead of closing it on the host', async () => {
|
||||
const listenerRef: { current: CloseActiveTabListener | null } = { current: null }
|
||||
await useIpcEventsForCloseRouting({
|
||||
closeActiveTabListenerRef: listenerRef,
|
||||
getState: () => activeBrowserWorkspace({ environmentId: 'env-a', staged: true })
|
||||
})
|
||||
|
||||
requireListener(listenerRef)()
|
||||
|
||||
expect(closeWebRuntimeSessionTab).not.toHaveBeenCalled()
|
||||
expect(closeBrowserTab).toHaveBeenCalledWith('workspace-1', { reason: 'cleanup' })
|
||||
})
|
||||
|
||||
// Pageless mirrors need local removal by unified tab ID; host sync has no local page to retract.
|
||||
it('removes the mirror tab itself when the host holds no page for it', async () => {
|
||||
const listenerRef: { current: CloseActiveTabListener | null } = { current: null }
|
||||
await useIpcEventsForCloseRouting({
|
||||
closeActiveTabListenerRef: listenerRef,
|
||||
getState: pagelessHostMirror
|
||||
})
|
||||
|
||||
requireListener(listenerRef)()
|
||||
|
||||
expect(closeWebRuntimeSessionTab).toHaveBeenCalledWith({
|
||||
worktreeId: 'wt-1',
|
||||
tabId: 'unified-1',
|
||||
environmentId: 'env-a',
|
||||
reason: 'user'
|
||||
})
|
||||
expect(closeUnifiedTab).toHaveBeenCalledWith('unified-1', undefined)
|
||||
expect(closeBrowserTab).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('tears a pageless mirror down here when its runtime is disconnected', async () => {
|
||||
isWebRuntimeSessionActive.mockReturnValue(false)
|
||||
const listenerRef: { current: CloseActiveTabListener | null } = { current: null }
|
||||
await useIpcEventsForCloseRouting({
|
||||
closeActiveTabListenerRef: listenerRef,
|
||||
getState: pagelessHostMirror
|
||||
})
|
||||
|
||||
requireListener(listenerRef)()
|
||||
|
||||
expect(closeWebRuntimeSessionTab).not.toHaveBeenCalled()
|
||||
expect(closeUnifiedTab).toHaveBeenCalledWith('unified-1', undefined)
|
||||
expect(closeBrowserTab).toHaveBeenCalledWith('workspace-1', undefined)
|
||||
})
|
||||
|
||||
// Guest focus can leave the group’s active-type mirror stale; forwarded source IDs must still close the guest’s workspace.
|
||||
it('closes the source workspace when the active-tab mirror points at a terminal', async () => {
|
||||
const listenerRef: { current: CloseActiveTabListener | null } = { current: null }
|
||||
await useIpcEventsForCloseRouting({
|
||||
closeActiveTabListenerRef: listenerRef,
|
||||
getState: () => ({
|
||||
...activeBrowserWorkspace({}),
|
||||
activeTabType: 'terminal',
|
||||
activeBrowserTabId: null,
|
||||
browserPagesByWorkspace: {
|
||||
'workspace-1': [{ id: 'page-1', workspaceId: 'stale-workspace', worktreeId: 'stale-wt' }]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
requireListener(listenerRef)({ sourceId: 'page-1' })
|
||||
|
||||
expect(closeBrowserTab).toHaveBeenCalledWith('workspace-1', undefined)
|
||||
expect(destroyWorkspaceWebviews).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('no-ops on a stale source id instead of closing the ambient active tab', async () => {
|
||||
const listenerRef: { current: CloseActiveTabListener | null } = { current: null }
|
||||
await useIpcEventsForCloseRouting({
|
||||
closeActiveTabListenerRef: listenerRef,
|
||||
getState: () => activeBrowserWorkspace({})
|
||||
})
|
||||
|
||||
requireListener(listenerRef)({ sourceId: 'page-that-no-longer-exists' })
|
||||
|
||||
expect(closeBrowserTab).not.toHaveBeenCalled()
|
||||
expect(closeUnifiedTab).not.toHaveBeenCalled()
|
||||
expect(closeWebRuntimeSessionTab).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('no-ops when a source page belongs to no live workspace', async () => {
|
||||
const listenerRef: { current: CloseActiveTabListener | null } = { current: null }
|
||||
await useIpcEventsForCloseRouting({
|
||||
closeActiveTabListenerRef: listenerRef,
|
||||
getState: () => ({
|
||||
...activeBrowserWorkspace({}),
|
||||
browserPagesByWorkspace: {
|
||||
orphan: [{ id: 'orphan-page', workspaceId: 'workspace-1', worktreeId: 'wt-1' }]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
requireListener(listenerRef)({ sourceId: 'orphan-page' })
|
||||
|
||||
expect(closeBrowserTab).not.toHaveBeenCalled()
|
||||
expect(closeUnifiedTab).not.toHaveBeenCalled()
|
||||
expect(closeWebRuntimeSessionTab).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
-189
@@ -1,189 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type * as MountedTerminalTabRegistryModule from '@/runtime/hosted-terminals/mounted-surfaces/mounted-terminal-tab-registry'
|
||||
import type { PreloadApi } from '../../../../../preload/api-types'
|
||||
|
||||
type CreateTerminalPayload = Parameters<Parameters<PreloadApi['ui']['onCreateTerminal']>[0]>[0]
|
||||
|
||||
const { focusRuntimeTerminalSurface } = vi.hoisted(() => ({
|
||||
focusRuntimeTerminalSurface: vi.fn(() => true)
|
||||
}))
|
||||
|
||||
vi.mock(
|
||||
'@/runtime/hosted-terminals/mounted-surfaces/mounted-terminal-tab-registry',
|
||||
async (importOriginal) => ({
|
||||
...(await importOriginal<typeof MountedTerminalTabRegistryModule>()),
|
||||
focusRuntimeTerminalSurface
|
||||
})
|
||||
)
|
||||
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { registerTerminalPresentationIpcBridge } from '@/hooks/ipc-events/terminal-presentation-ipc-bridge'
|
||||
import { activateAndRevealWorktree } from '../activation/worktree-activation'
|
||||
import { queueWorkspaceActivationTerminalFocus } from '../activation/workspace-activation-terminal-focus'
|
||||
import {
|
||||
makeCreatedAgentWorktree,
|
||||
seedEmptyActivatableWorktree
|
||||
} from '../activation/worktree-activation-created-agent.test-fixture'
|
||||
|
||||
const initialAppStoreState = useAppStore.getState()
|
||||
const AGENT_TAB_ID = 'b1a1c0de-0000-4000-8000-000000000001'
|
||||
const AGENT_LEAF_ID = 'b1a1c0de-0000-4000-8000-000000000002'
|
||||
const SETUP_TAB_ID = 'b1a1c0de-0000-4000-8000-000000000003'
|
||||
const SETUP_LEAF_ID = 'b1a1c0de-0000-4000-8000-000000000004'
|
||||
|
||||
let revealTerminal: (payload: CreateTerminalPayload) => void
|
||||
let frames: FrameRequestCallback[]
|
||||
|
||||
beforeEach(() => {
|
||||
frames = []
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
|
||||
frames.push(callback)
|
||||
return frames.length
|
||||
})
|
||||
vi.stubGlobal('cancelAnimationFrame', () => {})
|
||||
vi.stubGlobal(
|
||||
'MutationObserver',
|
||||
class {
|
||||
observe(): void {}
|
||||
disconnect(): void {}
|
||||
}
|
||||
)
|
||||
vi.stubGlobal('document', {
|
||||
activeElement: null,
|
||||
body: {},
|
||||
querySelector: () => null,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {}
|
||||
})
|
||||
vi.stubGlobal('window', {
|
||||
api: {
|
||||
ui: {
|
||||
onCreateTerminal: (listener: typeof revealTerminal) => {
|
||||
revealTerminal = listener
|
||||
return () => {}
|
||||
},
|
||||
onLaunchRecipe: () => () => {},
|
||||
onRequestTerminalTabMount: () => () => {},
|
||||
replyTerminalCreate: vi.fn()
|
||||
}
|
||||
}
|
||||
})
|
||||
registerTerminalPresentationIpcBridge([])
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
useAppStore.setState(initialAppStoreState, true)
|
||||
})
|
||||
|
||||
describe('a local agent create watched to completion', () => {
|
||||
it('opens on and focuses the agent tab the host adopted without activating', () => {
|
||||
const worktree = makeCreatedAgentWorktree()
|
||||
seedEmptyActivatableWorktree(worktree)
|
||||
useAppStore.setState({ activeWorktreeId: null, activeTabId: null })
|
||||
|
||||
// The host reveals its startup and setup terminals as main sends them for a local create.
|
||||
revealTerminal({
|
||||
requestId: 'reveal-agent',
|
||||
worktreeId: worktree.id,
|
||||
ptyId: 'pty-agent',
|
||||
launchAgent: 'codex',
|
||||
activate: false,
|
||||
surfaceOwner: false,
|
||||
tabId: AGENT_TAB_ID,
|
||||
leafId: AGENT_LEAF_ID
|
||||
})
|
||||
revealTerminal({
|
||||
requestId: 'reveal-setup',
|
||||
worktreeId: worktree.id,
|
||||
ptyId: 'pty-setup',
|
||||
title: 'Setup',
|
||||
activate: false,
|
||||
surfaceOwner: false,
|
||||
tabId: SETUP_TAB_ID,
|
||||
leafId: SETUP_LEAF_ID
|
||||
})
|
||||
expect(useAppStore.getState().activeWorktreeId).toBeNull()
|
||||
|
||||
// The completion rule's activation for a user still on the creation panel.
|
||||
const activation = activateAndRevealWorktree(worktree.id, {
|
||||
sidebarRevealBehavior: 'auto',
|
||||
agent: 'codex',
|
||||
backendStartupTerminalSpawned: true
|
||||
})
|
||||
expect(activation).toEqual({ primaryTabId: null })
|
||||
expect(useAppStore.getState().tabsByWorktree[worktree.id]?.map((tab) => tab.id)).toEqual([
|
||||
AGENT_TAB_ID,
|
||||
SETUP_TAB_ID
|
||||
])
|
||||
|
||||
expect(queueWorkspaceActivationTerminalFocus(worktree.id, activation)).toBe(true)
|
||||
frames.shift()?.(0)
|
||||
expect(focusRuntimeTerminalSurface).toHaveBeenCalledWith(AGENT_TAB_ID, null, worktree.id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('host reveal after early launch publication fails', () => {
|
||||
it.each([
|
||||
{ viewer: 'focus-in-workspace', moved: true, follows: false },
|
||||
{ viewer: 'focus-in-workspace', moved: false, follows: true },
|
||||
{ viewer: 'focus-window', moved: true, follows: true },
|
||||
{ viewer: 'none', moved: true, follows: false }
|
||||
] as const)(
|
||||
'honors $viewer after navigation=$moved for new and existing panes',
|
||||
({ viewer, moved, follows }) => {
|
||||
const worktree = makeCreatedAgentWorktree()
|
||||
const other = { ...worktree, id: `${worktree.id}-other` }
|
||||
const { revealWorktreeInSidebar } = seedEmptyActivatableWorktree(worktree, {
|
||||
extraWorktrees: [other]
|
||||
})
|
||||
const activeWorkspace = moved ? other.id : worktree.id
|
||||
useAppStore.setState({ activeWorktreeId: activeWorkspace, activeTabId: null })
|
||||
focusRuntimeTerminalSurface.mockClear()
|
||||
const payload: CreateTerminalPayload = {
|
||||
requestId: 'reveal-agent',
|
||||
worktreeId: worktree.id,
|
||||
ptyId: 'pty-agent',
|
||||
launchAgent: 'codex',
|
||||
activate: false,
|
||||
surfaceOwner: false,
|
||||
agentLaunchViewer: viewer,
|
||||
tabId: AGENT_TAB_ID,
|
||||
leafId: AGENT_LEAF_ID
|
||||
}
|
||||
revealTerminal(payload)
|
||||
expect(useAppStore.getState().activeWorktreeId).toBe(follows ? worktree.id : activeWorkspace)
|
||||
expect(useAppStore.getState().tabsByWorktree[worktree.id]?.map((tab) => tab.id)).toEqual([
|
||||
AGENT_TAB_ID
|
||||
])
|
||||
expect(useAppStore.getState().terminalLayoutsByTabId[AGENT_TAB_ID]?.ptyIdsByLeafId).toEqual({
|
||||
[AGENT_LEAF_ID]: 'pty-agent'
|
||||
})
|
||||
if (follows) {
|
||||
expect(useAppStore.getState().activeTabId).toBe(AGENT_TAB_ID)
|
||||
expect(focusRuntimeTerminalSurface).toHaveBeenCalledWith(
|
||||
AGENT_TAB_ID,
|
||||
AGENT_LEAF_ID,
|
||||
worktree.id
|
||||
)
|
||||
} else {
|
||||
expect(focusRuntimeTerminalSurface).not.toHaveBeenCalled()
|
||||
expect(useAppStore.getState().activeTabId).toBeNull()
|
||||
}
|
||||
if (viewer === 'focus-in-workspace') {
|
||||
expect(revealWorktreeInSidebar).not.toHaveBeenCalled()
|
||||
}
|
||||
// A reveal can find a tab restored while its earlier publication reply was lost.
|
||||
useAppStore.setState({ activeWorktreeId: activeWorkspace, activeTabId: null })
|
||||
focusRuntimeTerminalSurface.mockClear()
|
||||
revealTerminal(payload)
|
||||
expect(useAppStore.getState().activeWorktreeId).toBe(follows ? worktree.id : activeWorkspace)
|
||||
expect(useAppStore.getState().tabsByWorktree[worktree.id]).toHaveLength(1)
|
||||
if (follows) {
|
||||
expect(focusRuntimeTerminalSurface).toHaveBeenCalledOnce()
|
||||
} else {
|
||||
expect(focusRuntimeTerminalSurface).not.toHaveBeenCalled()
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -1,13 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { readRuntimeFileContent } from './runtime-file-read-client'
|
||||
import {
|
||||
fsReadFileChunk,
|
||||
fsStat,
|
||||
installRuntimeFileClientEnvironment,
|
||||
runtimeEnvironmentCall,
|
||||
type RuntimeRpcRequest
|
||||
} from '../runtime-file-client-test-harness'
|
||||
import { readRuntimeFileBytes } from './runtime-paged-file-read'
|
||||
|
||||
installRuntimeFileClientEnvironment()
|
||||
|
||||
@@ -136,16 +133,6 @@ describe('remote reads larger than one RPC reply', () => {
|
||||
expect(Buffer.from(result.content, 'utf8').equals(bytes)).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps a UTF-8 BOM so a save does not drop it', async () => {
|
||||
const bytes = Buffer.concat([Buffer.from([0xef, 0xbb, 0xbf]), htmlBytes(MB)])
|
||||
serveRemoteFile('table.csv', { bytes })
|
||||
|
||||
const result = await readRuntimeFileContent(remote('table.csv'))
|
||||
|
||||
expect(result.content.charCodeAt(0)).toBe(0xfeff)
|
||||
expect(Buffer.from(result.content, 'utf8').equals(bytes)).toBe(true)
|
||||
})
|
||||
|
||||
it.each([2, 5])('opens a %i MB PDF in the editor', async (sizeMb) => {
|
||||
const bytes = patternedBytes(sizeMb * MB)
|
||||
serveRemoteFile('paper.pdf', { bytes })
|
||||
@@ -159,17 +146,6 @@ describe('remote reads larger than one RPC reply', () => {
|
||||
expect(Buffer.from(result.content, 'base64').equals(bytes)).toBe(true)
|
||||
})
|
||||
|
||||
it('treats a large file with a NUL byte as binary, like a local read', async () => {
|
||||
const bytes = htmlBytes(2 * MB)
|
||||
bytes[10] = 0
|
||||
serveRemoteFile('data.txt', { bytes })
|
||||
|
||||
await expect(readRuntimeFileContent(remote('data.txt'))).resolves.toEqual({
|
||||
content: '',
|
||||
isBinary: true
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects a chunk whose payload does not match its byte count', async () => {
|
||||
serveRemoteFile('report.html', {
|
||||
bytes: htmlBytes(2 * MB),
|
||||
@@ -181,30 +157,3 @@ describe('remote reads larger than one RPC reply', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('whole-file bytes for a bytes custom editor', () => {
|
||||
it('returns the exact bytes of a paged remote workbook', async () => {
|
||||
const bytes = patternedBytes(MB + 17)
|
||||
serveRemoteFile('book.xlsx', { bytes })
|
||||
|
||||
const result = await readRuntimeFileBytes(remote('book.xlsx'), 16 * MB)
|
||||
|
||||
expect(result.kind).toBe('ok')
|
||||
expect(result.kind === 'ok' && Buffer.from(result.bytes).equals(bytes)).toBe(true)
|
||||
})
|
||||
|
||||
it('reads a local file through the local stat and chunk IPC', async () => {
|
||||
const bytes = patternedBytes(300 * 1024)
|
||||
fsStat.mockResolvedValue({ size: bytes.length, isDirectory: false, mtime: 5 })
|
||||
fsReadFileChunk.mockImplementation((args: ChunkParams) =>
|
||||
Promise.resolve(sliceChunk(args, bytes))
|
||||
)
|
||||
|
||||
const result = await readRuntimeFileBytes(
|
||||
{ target: { kind: 'local' }, filePath: '/repo/book.xlsx' },
|
||||
16 * MB
|
||||
)
|
||||
|
||||
expect(result.kind === 'ok' && Buffer.from(result.bytes).equals(bytes)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,22 +2,16 @@ import { describe, expect, it, vi } from 'vitest'
|
||||
import { getRepoExecutionHostId } from '../../../../shared/execution-host'
|
||||
import { createTestStore } from '../testing/app-store-test-fixture'
|
||||
import { makeWorktree } from '../slices/worktrees/worktree.test-fixture'
|
||||
import { workItemsCacheKey } from '../github/cache/cache-identity'
|
||||
|
||||
import type { Repo } from '../../../../shared/repo-types'
|
||||
import { toast } from 'sonner'
|
||||
import '../../../../shared/global-settings-test-fixture'
|
||||
import '../../web/preload-api/web-fallback-api'
|
||||
import {
|
||||
installReposRuntimeRoutingHarness,
|
||||
localRepo,
|
||||
projectsSetupExistingFolder,
|
||||
ptyKill,
|
||||
remoteRepo,
|
||||
reposRemoveForHost,
|
||||
runtimeEnvironmentCall,
|
||||
runtimeEnvironmentsList,
|
||||
sshRepo
|
||||
runtimeEnvironmentsList
|
||||
} from './repo-runtime-routing.test-fixture'
|
||||
|
||||
vi.mock('sonner', () => ({
|
||||
@@ -36,81 +30,6 @@ const ownerOf = (repo: Repo) => ({ hostId: getRepoExecutionHostId(repo) })
|
||||
const serverRepo: Repo = { ...remoteRepo, executionHostId: 'runtime:env-1' }
|
||||
|
||||
describe('repo slice runtime routing', () => {
|
||||
it('names an SSH host without a server and offers Connect, never its raw id (#37767)', async () => {
|
||||
const store = createTestStore()
|
||||
store.setState({ sshTargetLabels: new Map([['ssh-1', 'build box']]) })
|
||||
const connect = vi.fn().mockResolvedValue(null)
|
||||
Object.assign(window.api, { ssh: { connect } })
|
||||
|
||||
await expect(
|
||||
store.getState().setupProjectExistingFolder({
|
||||
projectId: 'github:acme/orca',
|
||||
hostId: 'ssh:ssh-1',
|
||||
path: '/srv/orca',
|
||||
kind: 'git'
|
||||
})
|
||||
).resolves.toBeNull()
|
||||
|
||||
expect(projectsSetupExistingFolder).not.toHaveBeenCalled()
|
||||
const [, options] = vi.mocked(toast.error).mock.calls[0] ?? []
|
||||
expect(options?.description).toContain('build box')
|
||||
expect(options?.description).not.toContain('ssh-1')
|
||||
const action = options?.action
|
||||
if (!action || typeof action !== 'object' || !('onClick' in action)) {
|
||||
throw new Error('expected a Connect action')
|
||||
}
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the action ignores its click event.
|
||||
action.onClick({} as never)
|
||||
expect(connect).toHaveBeenCalledWith({ targetId: 'ssh-1' })
|
||||
})
|
||||
|
||||
it('drops persisted visit timestamps for removed unhydrated SSH repos', async () => {
|
||||
const store = createTestStore()
|
||||
const sshWorktreeId = `${sshRepo.id}::/home/orca/wt`
|
||||
const localWorktreeId = `${localRepo.id}::/local/wt`
|
||||
store.setState({
|
||||
repos: [sshRepo, localRepo],
|
||||
activeRepoId: sshRepo.id,
|
||||
lastVisitedAtByWorktreeId: {
|
||||
[sshWorktreeId]: 100,
|
||||
[localWorktreeId]: 200
|
||||
}
|
||||
})
|
||||
|
||||
await store.getState().removeProject(sshRepo.id, ownerOf(sshRepo))
|
||||
|
||||
expect(store.getState().repos).toEqual([localRepo])
|
||||
expect(store.getState().lastVisitedAtByWorktreeId).toEqual({ [localWorktreeId]: 200 })
|
||||
expect(reposRemoveForHost).toHaveBeenCalledWith({ repoId: sshRepo.id, hostId: 'ssh:ssh-1' })
|
||||
})
|
||||
|
||||
it('evicts GitHub caches for removed repos using repo id and legacy path keys', async () => {
|
||||
const store = createTestStore()
|
||||
store.setState({
|
||||
repos: [localRepo],
|
||||
workItemsInvalidationNonce: 2,
|
||||
workItemsCache: {
|
||||
[workItemsCacheKey(localRepo.id, 20, '')]: { data: [], fetchedAt: 1 },
|
||||
[workItemsCacheKey(localRepo.path, 20, '')]: { data: [], fetchedAt: 1 },
|
||||
[workItemsCacheKey('other-repo', 20, '')]: { data: [], fetchedAt: 1 }
|
||||
},
|
||||
prCache: {
|
||||
[`${localRepo.id}::branch`]: { data: {} as never, fetchedAt: 1 },
|
||||
[`${localRepo.path}::branch`]: { data: {} as never, fetchedAt: 1 },
|
||||
'other-repo::branch': { data: {} as never, fetchedAt: 1 }
|
||||
}
|
||||
})
|
||||
|
||||
await store.getState().removeProject(localRepo.id, ownerOf(localRepo))
|
||||
|
||||
expect(Object.keys(store.getState().workItemsCache)).toEqual([
|
||||
workItemsCacheKey('other-repo', 20, '')
|
||||
])
|
||||
expect(Object.keys(store.getState().prCache)).toEqual(['other-repo::branch'])
|
||||
// A refetch signal only: eviction and the retired source owner may each bump it.
|
||||
expect(store.getState().workItemsInvalidationNonce).toBeGreaterThan(2)
|
||||
})
|
||||
|
||||
it('stops remote runtime terminals instead of killing remote ids through local pty IPC', async () => {
|
||||
runtimeEnvironmentsList.mockResolvedValue([{ id: 'env-1' }])
|
||||
runtimeEnvironmentCall.mockResolvedValue({
|
||||
@@ -148,46 +67,4 @@ describe('repo slice runtime routing', () => {
|
||||
expect(ptyKill).toHaveBeenCalledWith('pty-local-stale')
|
||||
expect(ptyKill).not.toHaveBeenCalledWith('remote:term-1')
|
||||
})
|
||||
|
||||
it('cleans up hidden detected worktree state when removing a repo', async () => {
|
||||
const store = createTestStore()
|
||||
const hiddenWorktree = makeWorktree({
|
||||
id: `${localRepo.id}::/local/hidden`,
|
||||
repoId: localRepo.id,
|
||||
path: '/local/hidden'
|
||||
})
|
||||
store.setState({
|
||||
repos: [localRepo],
|
||||
worktreesByRepo: { [localRepo.id]: [] },
|
||||
detectedWorktreesByRepo: {
|
||||
[localRepo.id]: {
|
||||
repoId: localRepo.id,
|
||||
authoritative: true,
|
||||
source: 'git',
|
||||
worktrees: [
|
||||
{
|
||||
...hiddenWorktree,
|
||||
ownership: 'external',
|
||||
selectedCheckout: false,
|
||||
visible: false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
tabsByWorktree: {
|
||||
[hiddenWorktree.id]: [{ id: 'tab-hidden', worktreeId: hiddenWorktree.id }] as never
|
||||
},
|
||||
ptyIdsByTabId: {
|
||||
'tab-hidden': ['pty-hidden']
|
||||
},
|
||||
activeWorktreeId: hiddenWorktree.id
|
||||
})
|
||||
|
||||
await store.getState().removeProject(localRepo.id, ownerOf(localRepo))
|
||||
|
||||
expect(store.getState().detectedWorktreesByRepo[localRepo.id]).toBeUndefined()
|
||||
expect(store.getState().tabsByWorktree[hiddenWorktree.id]).toBeUndefined()
|
||||
expect(store.getState().activeWorktreeId).toBeNull()
|
||||
expect(ptyKill).toHaveBeenCalledWith('pty-hidden')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { AppState } from '../../../types'
|
||||
import { layoutApplyTestTransport } from '@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture'
|
||||
import {
|
||||
createBrowserMockApi,
|
||||
resetBrowserRuntimeMocks,
|
||||
runtimeStatuses,
|
||||
settingsWithRuntime
|
||||
} from '../browser-slice-test-harness'
|
||||
import {
|
||||
createTestStoreDrawnFromMain,
|
||||
onePaneGroup
|
||||
} from '../browser-slice-drawn-from-main.test-fixture'
|
||||
|
||||
const createWebRuntimeSessionBrowserTabMock = vi.hoisted(() => vi.fn())
|
||||
const runtimeEnvironmentCall = vi.fn()
|
||||
const runtimeEnvironmentTransportCall = vi.fn()
|
||||
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-call', async (importOriginal) =>
|
||||
(
|
||||
await import('@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture')
|
||||
).runtimeRpcClientWithLayoutApply(await importOriginal())
|
||||
)
|
||||
vi.mock('@/runtime/workspace-layout/frames/runtime-layout-client', async (importOriginal) =>
|
||||
(
|
||||
await import('@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture')
|
||||
).runtimeLayoutClientWithTestFrames(await importOriginal())
|
||||
)
|
||||
vi.mock('@/store/slices/browser/tabs/paired-browser-tab-creator', () => ({
|
||||
getRegisteredPairedBrowserTabCreator: () => null,
|
||||
loadPairedBrowserTabCreator: async () => createWebRuntimeSessionBrowserTabMock
|
||||
}))
|
||||
|
||||
const mockApi = createBrowserMockApi(runtimeEnvironmentTransportCall)
|
||||
|
||||
// @ts-expect-error test window mock
|
||||
globalThis.window = { api: mockApi }
|
||||
|
||||
/** A server-owned workspace's desktop tab: the window draws it, as main never holds that layout. */
|
||||
function expectDrawnHere(state: AppState): void {
|
||||
expect(layoutApplyTestTransport.sent).toEqual([])
|
||||
expect(state.createUnifiedTab).toHaveBeenCalled()
|
||||
}
|
||||
|
||||
describe('createBrowserSlice runtime guard', () => {
|
||||
beforeEach(() => {
|
||||
resetBrowserRuntimeMocks({
|
||||
runtimeEnvironmentCall,
|
||||
runtimeEnvironmentTransportCall,
|
||||
createWebRuntimeSessionBrowserTabMock
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('rejects direct client-local materialization in the web client', async () => {
|
||||
vi.stubGlobal('__ORCA_WEB_CLIENT__', true)
|
||||
const { store } = await createTestStoreDrawnFromMain()
|
||||
|
||||
expect(() => store.getState().createBrowserTab('wt-1', 'about:blank')).toThrow(
|
||||
'must be created by a capable paired runtime'
|
||||
)
|
||||
expect(store.getState().browserTabsByWorktree['wt-1']).toBeUndefined()
|
||||
expect(store.getState().createUnifiedTab).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('uses the desktop client browser when a remote npm host cannot stream', async () => {
|
||||
const { store, main } = await createTestStoreDrawnFromMain({
|
||||
...onePaneGroup('wt-remote'),
|
||||
activeWorktreeId: 'wt-remote',
|
||||
settings: settingsWithRuntime('env-1'),
|
||||
runtimeStatusByEnvironmentId: runtimeStatuses([]),
|
||||
worktreesByRepo: {
|
||||
'repo-1': [
|
||||
{
|
||||
id: 'wt-remote',
|
||||
repoId: 'repo-1',
|
||||
hostId: 'local',
|
||||
runtimeOwnerEnvironmentId: 'env-1'
|
||||
} as never
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
await store.getState().openNewBrowserTabInActiveWorkspace('group-1')
|
||||
await main.settle()
|
||||
|
||||
expect(createWebRuntimeSessionBrowserTabMock).not.toHaveBeenCalled()
|
||||
const tab = store.getState().browserTabsByWorktree['wt-remote']?.[0]
|
||||
const page = tab ? store.getState().browserPagesByWorkspace[tab.id]?.[0] : undefined
|
||||
expect(page?.browserRuntimeEnvironmentId).toBeNull()
|
||||
expectDrawnHere(store.getState())
|
||||
})
|
||||
|
||||
it('does not create a local fallback tab when remote browser creation fails', async () => {
|
||||
// Failed remote creation must not fall back local and split workspace ownership (#5321).
|
||||
createWebRuntimeSessionBrowserTabMock.mockResolvedValueOnce(false)
|
||||
const { store, main } = await createTestStoreDrawnFromMain({
|
||||
...onePaneGroup('wt-remote'),
|
||||
activeWorktreeId: 'wt-remote',
|
||||
settings: { activeRuntimeEnvironmentId: 'env-1' } as AppState['settings'],
|
||||
runtimeStatusByEnvironmentId: runtimeStatuses(['browser.screencast.v1']),
|
||||
worktreesByRepo: {
|
||||
'repo-1': [
|
||||
{
|
||||
id: 'wt-remote',
|
||||
repoId: 'repo-1',
|
||||
hostId: 'local',
|
||||
runtimeOwnerEnvironmentId: 'env-1'
|
||||
} as never
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
await expect(store.getState().openNewBrowserTabInActiveWorkspace('group-1')).rejects.toThrow(
|
||||
'The paired runtime could not create a managed browser tab.'
|
||||
)
|
||||
|
||||
expect(createWebRuntimeSessionBrowserTabMock).toHaveBeenCalledWith({
|
||||
worktreeId: 'wt-remote',
|
||||
environmentId: 'env-1',
|
||||
url: 'about:blank',
|
||||
targetGroupId: 'group-1',
|
||||
clientTargetGroupId: 'group-1'
|
||||
})
|
||||
// No local tab created, no unified tab, no feature interaction recorded.
|
||||
await main.settle()
|
||||
expect(layoutApplyTestTransport.sent).toEqual([])
|
||||
expect(store.getState().browserTabsByWorktree['wt-remote']).toBeUndefined()
|
||||
expect(store.getState().createUnifiedTab).not.toHaveBeenCalled()
|
||||
expect(store.getState().recordFeatureInteraction).not.toHaveBeenCalledWith(
|
||||
'browser-tab-created'
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects a paired-web sign-in tab when the remote host cannot stream browsers', async () => {
|
||||
vi.stubGlobal('__ORCA_WEB_CLIENT__', true)
|
||||
const { store, main } = await createTestStoreDrawnFromMain({
|
||||
...onePaneGroup('wt-remote'),
|
||||
activeWorktreeId: 'wt-remote',
|
||||
settings: settingsWithRuntime('env-1'),
|
||||
runtimeStatusByEnvironmentId: runtimeStatuses([]),
|
||||
worktreesByRepo: {
|
||||
'repo-1': [
|
||||
{
|
||||
id: 'wt-remote',
|
||||
repoId: 'repo-1',
|
||||
hostId: 'local',
|
||||
runtimeOwnerEnvironmentId: 'env-1'
|
||||
} as never
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
await expect(
|
||||
store
|
||||
.getState()
|
||||
.openBrowserProfileTabInActiveWorkspace('https://accounts.google.com/', 'profile-1')
|
||||
).resolves.toBe(false)
|
||||
|
||||
expect(createWebRuntimeSessionBrowserTabMock).not.toHaveBeenCalled()
|
||||
expect(store.getState().browserTabsByWorktree['wt-remote']).toBeUndefined()
|
||||
await main.settle()
|
||||
expect(layoutApplyTestTransport.sent).toEqual([])
|
||||
})
|
||||
|
||||
it('does not create a local fallback tab when remote browser creation throws', async () => {
|
||||
createWebRuntimeSessionBrowserTabMock.mockRejectedValueOnce(new Error('remote down'))
|
||||
const { store, main } = await createTestStoreDrawnFromMain({
|
||||
...onePaneGroup('wt-remote'),
|
||||
activeWorktreeId: 'wt-remote',
|
||||
settings: { activeRuntimeEnvironmentId: 'env-1' } as AppState['settings'],
|
||||
runtimeStatusByEnvironmentId: runtimeStatuses(['browser.screencast.v1']),
|
||||
worktreesByRepo: {
|
||||
'repo-1': [
|
||||
{
|
||||
id: 'wt-remote',
|
||||
repoId: 'repo-1',
|
||||
hostId: 'local',
|
||||
runtimeOwnerEnvironmentId: 'env-1'
|
||||
} as never
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
await expect(store.getState().openNewBrowserTabInActiveWorkspace('group-1')).rejects.toThrow(
|
||||
'remote down'
|
||||
)
|
||||
await main.settle()
|
||||
expect(layoutApplyTestTransport.sent).toEqual([])
|
||||
|
||||
expect(store.getState().browserTabsByWorktree['wt-remote']).toBeUndefined()
|
||||
expect(store.getState().createUnifiedTab).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
+1
-23
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { installAttentionScreen } from '../../workspace-attention/workspace-unread-characterization-fixture'
|
||||
import '../../workspace-attention/workspace-unread-characterization-fixture'
|
||||
import type { AppState } from '../../../types'
|
||||
import type { FolderWorkspace } from '../../../../../../shared/folder-workspaces/folder-workspace-types'
|
||||
import type { ProjectGroup } from '../../../../../../shared/project-group-types'
|
||||
@@ -101,28 +101,6 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('folder workspace generic activation and activity', () => {
|
||||
it('publishes folder-scoped active state and reads the flag once on screen', async () => {
|
||||
const folderWorkspace = makeFolderWorkspace({ isUnread: true })
|
||||
const workspaceKey = folderWorkspaceKey(folderWorkspace.id)
|
||||
folderWorkspacesUpdate.mockImplementation(respondWithUpdates(folderWorkspace))
|
||||
const store = seedLocalFolderStore(folderWorkspace)
|
||||
|
||||
installAttentionScreen(store, true)
|
||||
store.getState().setActiveWorktree(workspaceKey)
|
||||
await Promise.resolve()
|
||||
|
||||
expect(store.getState()).toMatchObject({
|
||||
activeRepoId: null,
|
||||
activeWorktreeId: workspaceKey,
|
||||
activeWorkspaceKey: workspaceKey
|
||||
})
|
||||
expect(store.getState().folderWorkspaces[0]?.isUnread).toBe(false)
|
||||
expect(folderWorkspacesUpdate).toHaveBeenCalledWith({
|
||||
folderWorkspaceId: folderWorkspace.id,
|
||||
updates: { isUnread: false }
|
||||
})
|
||||
})
|
||||
|
||||
it('coalesces repeated activity persistence while keeping local activity current', async () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(1_000)
|
||||
|
||||
Reference in New Issue
Block a user