mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
test: retire low-value renderer projections and unused HTTP fixture (#40915)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -6483,7 +6483,6 @@
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/closing/paired-terminal-tab-close-reload.test.ts": 1943,
|
||||
"src/renderer/src/runtime/workspace-layout/frames/pane-titles-drawn-from-frames.test.ts": 1988,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/agent-status/remote-agent-row-last-assistant-message.test.ts": 1776,
|
||||
"src/renderer/src/runtime/files/mutations/remote-host-file-delete-repro.test.ts": 1890,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/inventory/remote-runtime-session-tabs-inflight.test.ts": 55,
|
||||
"src/renderer/src/runtime/hosted-terminals/snapshots/remote-runtime-snapshot-outcome.test.ts": 233,
|
||||
"src/renderer/src/runtime/hosted-terminals/streams/remote-runtime-terminal-frame-drop-resync.test.ts": 266,
|
||||
@@ -6552,7 +6551,6 @@
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/agent-status/web-session-tabs-sync-remote-status-title-flap.test.ts": 1715,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/agent-status/web-session-tabs-sync-stale-spinner.test.ts": 921,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/tracking/web-session-tabs-sync-tracking-teardown.test.ts": 940,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/subscriptions/web-session-tabs-sync-unverifiable-host.test.tsx": 2424,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/subscriptions/web-session-tabs-sync-visibility-collision.test.tsx": 2699,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/subscriptions/web-session-tabs-sync-window-visibility.test.tsx": 2589,
|
||||
"src/renderer/src/runtime/web-session-tabs-sync/subscriptions/web-session-tabs-sync-worktree-switch.test.tsx": 2625,
|
||||
@@ -6569,7 +6567,6 @@
|
||||
"src/renderer/src/runtime/hosted-terminals/recovery/evidence/web-session-terminal-retirement-proof-ledger.test.ts": 685,
|
||||
"src/renderer/src/runtime/rpc/subscriptions/window-visibility-subscription-parking-stream-end.test.ts": 225,
|
||||
"src/renderer/src/runtime/workspace-layout/frames/workspace-layout-frame-binding.test.ts": 2155,
|
||||
"src/renderer/src/runtime/workspace-layout/frames/workspace-layout-frame-editor-views.test.ts": 2098,
|
||||
"src/renderer/src/runtime/workspace-layout/frames/workspace-layout-frame-held-tabs.test.ts": 2519,
|
||||
"src/renderer/src/runtime/workspace-layout/frames/workspace-layout-frame-sync.test.ts": 2282,
|
||||
"src/renderer/src/runtime/workspace-layout/frames/workspace-layout-frame-tab-props.test.ts": 2852,
|
||||
@@ -6646,7 +6643,6 @@
|
||||
"src/renderer/src/store/slices/editor/checks/editor-check-details-tabs.test.ts": 1814,
|
||||
"src/renderer/src/store/slices/editor/closing/editor-close-background-file.test.ts": 893,
|
||||
"src/renderer/src/store/slices/editor/closing/editor-close-document-siblings.test.ts": 1317,
|
||||
"src/renderer/src/store/slices/editor/closing/editor-close-file-cleanup.test.ts": 2000,
|
||||
"src/renderer/src/store/slices/editor/closing/editor-close-file-stale-active.test.ts": 1806,
|
||||
"src/renderer/src/store/slices/editor/closing/editor-close-pinned-sibling.test.ts": 924,
|
||||
"src/renderer/src/store/slices/editor/closing/editor-close-workspace-selection.test.ts": 1850,
|
||||
|
||||
@@ -1,27 +1,6 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { Session } from 'electron'
|
||||
import { setMainHttpClient } from '../../../network/http-client'
|
||||
|
||||
const { fetchMock, sessionFromPartitionMock } = vi.hoisted(() => {
|
||||
const fetchMock = vi.fn()
|
||||
const cookiesSetMock = vi.fn(() => Promise.resolve())
|
||||
const clearStorageDataMock = vi.fn(() => Promise.resolve())
|
||||
const sessionFromPartitionMock = vi.fn(() => ({
|
||||
clearStorageData: clearStorageDataMock,
|
||||
cookies: { set: cookiesSetMock },
|
||||
fetch: fetchMock
|
||||
}))
|
||||
return { clearStorageDataMock, cookiesSetMock, fetchMock, sessionFromPartitionMock }
|
||||
})
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { redactMiniMaxSecret } from './minimax-request-context'
|
||||
|
||||
setMainHttpClient({
|
||||
fetch: fetchMock,
|
||||
proxySession: () => null,
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the code under test only calls clearStorageData, cookies.set and fetch, which the fake provides.
|
||||
partitionSession: sessionFromPartitionMock as unknown as (partition: string) => Session
|
||||
})
|
||||
|
||||
describe('redactMiniMaxSecret', () => {
|
||||
it('redacts _token values in header and quoted syntax', () => {
|
||||
const redacted = redactMiniMaxSecret('cookie _token=eyJhABCDEF and _token:"x.y"')
|
||||
|
||||
-32
@@ -69,38 +69,6 @@ describe('recoverable connect failures on a remote runtime pane', () => {
|
||||
resetRemoteRuntimeTransport()
|
||||
})
|
||||
|
||||
it('keeps retrying a recoverable connect failure instead of latching immediately', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
installUnreachableRuntime()
|
||||
const { createRemoteRuntimePtyTransport } = await import('./remote-runtime-pty-transport')
|
||||
const onError = vi.fn()
|
||||
const transport = createRemoteRuntimePtyTransport('env-1', {
|
||||
worktreeId: 'wt-1',
|
||||
tabId: 'tab-1',
|
||||
leafId: 'pane:1'
|
||||
})
|
||||
|
||||
await transport.connect({
|
||||
url: '',
|
||||
sessionId: 'remote:env-1@@',
|
||||
callbacks: { onError }
|
||||
})
|
||||
|
||||
// Loss of contact is unverifiable, not a dead terminal: automatic recovery must still be running.
|
||||
expect(resolvePaneCalls).toBe(1)
|
||||
expect(transport.getRecoveryState?.().phase).toBe('backoff')
|
||||
expect(onError).not.toHaveBeenCalled()
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1_000)
|
||||
expect(resolvePaneCalls).toBeGreaterThan(1)
|
||||
|
||||
transport.destroy?.()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('leaves both revival paths armed once the recovery window is spent', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
|
||||
-28
@@ -97,34 +97,6 @@ describe('remote transport sendInputImmediate (#7329)', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('sends an immediate reply even with no pending typed input', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const { createRemoteRuntimePtyTransport } = await import('./remote-runtime-pty-transport')
|
||||
const transport = createRemoteRuntimePtyTransport('env-1', {
|
||||
worktreeId: 'wt-1',
|
||||
tabId: 'tab-1',
|
||||
leafId: 'pane:1'
|
||||
})
|
||||
transport.attach({
|
||||
existingPtyId: 'remote:env-1@@terminal-1',
|
||||
cols: 80,
|
||||
rows: 24,
|
||||
callbacks: {}
|
||||
})
|
||||
await vi.waitFor(() => expect(runtimeSubscribe).toHaveBeenCalled())
|
||||
|
||||
expect(transport.sendInputImmediate('\x1b[3;1R')).toBe(true)
|
||||
await Promise.resolve()
|
||||
|
||||
const sends = terminalSendCalls() as { params: { text: string } }[]
|
||||
expect(sends).toHaveLength(1)
|
||||
expect(sends[0]?.params.text).toBe('\x1b[3;1R')
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('does not reorder a query reply ahead of a large paste still in async validation', async () => {
|
||||
// Large pastes may still be in async validation, outside pending; replies cannot overtake that hidden prefix (#7736).
|
||||
const { createRemoteRuntimePtyTransport } = await import('./remote-runtime-pty-transport')
|
||||
|
||||
-21
@@ -34,27 +34,6 @@ it('does not remove handlers installed by a remount while sleep is pending', ()
|
||||
ptyReplayHandlers.delete(ptyId)
|
||||
})
|
||||
|
||||
it('replays rollback output in its original replay and live arrival order', () => {
|
||||
const ptyId = 'pty-shutdown-output-order'
|
||||
const delivered: string[] = []
|
||||
const meta = { seq: 9, rawLength: 3, transformed: true }
|
||||
const sidecar = vi.fn((data: string) => delivered.push(`sidecar:${data}`))
|
||||
ptyDataHandlers.set(ptyId, (data) => delivered.push(`data:${data}`))
|
||||
ptyReplayHandlers.set(ptyId, (data) => delivered.push(`replay:${data}`))
|
||||
ptyDataSidecars.set(ptyId, new Set([sidecar]))
|
||||
|
||||
const [snapshot] = unregisterPtyDataHandlers([ptyId])
|
||||
bufferPtyShutdownReplayData(ptyId, 'old')
|
||||
bufferPtyShutdownData(ptyId, 'new', meta)
|
||||
snapshot.rollback()
|
||||
|
||||
expect(delivered).toEqual(['replay:old', 'data:new', 'sidecar:new'])
|
||||
expect(sidecar).toHaveBeenCalledOnce()
|
||||
ptyDataHandlers.delete(ptyId)
|
||||
ptyDataSidecars.delete(ptyId)
|
||||
ptyReplayHandlers.delete(ptyId)
|
||||
})
|
||||
|
||||
it('drains pre-handler data before ordered shutdown output', () => {
|
||||
const ptyId = 'pty-shutdown-pre-handler-order'
|
||||
const delivered: string[] = []
|
||||
|
||||
@@ -76,38 +76,6 @@ describe('ensureWorktreeHasInitialTerminal', () => {
|
||||
command: 'gh issue view 42'
|
||||
})
|
||||
})
|
||||
|
||||
it('does not create a fallback while a backend startup terminal awaits mirroring', () => {
|
||||
useAppStore.setState({
|
||||
getKnownWorktreeById: ((id: string) =>
|
||||
id === 'wt-1'
|
||||
? { id: 'wt-1' }
|
||||
: undefined) as unknown as AppStoreState['getKnownWorktreeById']
|
||||
} as Partial<AppStoreState>)
|
||||
const store = createMockStore()
|
||||
|
||||
const result = ensureWorktreeHasInitialTerminal(
|
||||
store,
|
||||
'wt-1',
|
||||
undefined,
|
||||
undefined,
|
||||
{ command: 'gh issue view 42' },
|
||||
undefined,
|
||||
{ backendStartupTerminalSpawned: true }
|
||||
)
|
||||
|
||||
expect(result).toBeNull()
|
||||
expect(store.createTab).not.toHaveBeenCalled()
|
||||
expect(store.setActiveTab).not.toHaveBeenCalled()
|
||||
|
||||
useAppStore.setState({
|
||||
tabsByWorktree: { 'wt-1': [{ id: 'mirror-tab-1' }] }
|
||||
} as unknown as Partial<AppStoreState>)
|
||||
|
||||
expect(useAppStore.getState().pendingIssueCommandSplitByTabId['mirror-tab-1']).toEqual({
|
||||
command: 'gh issue view 42'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts live paired startup through after-wake when initial seeding returns no primary tab', async () => {
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { act, renderHook } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { FolderWorkspace } from '../../../../../shared/folder-workspaces/folder-workspace-types'
|
||||
import type { ProjectGroup } from '../../../../../shared/project-group-types'
|
||||
import type { Repo } from '../../../../../shared/repo-types'
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { folderWorkspaceKey } from '../../../../../shared/workspace-scope'
|
||||
import { useFileDeletion } from '@/components/right-sidebar/file-explorer/mutations/useFileDeletion'
|
||||
import { getFileExplorerOperationOwner } from '@/components/right-sidebar/file-explorer/navigation/file-explorer-operation-owner'
|
||||
import type { TreeNode } from '@/components/right-sidebar/file-explorer/tree/file-explorer-types'
|
||||
import { createCompatibleRuntimeStatusResponseIfNeeded } from '@/runtime/rpc/testing/runtime-compatibility-test-fixture'
|
||||
|
||||
const { confirm, toastError } = vi.hoisted(() => ({
|
||||
confirm: vi.fn(),
|
||||
toastError: vi.fn()
|
||||
}))
|
||||
const fsReadFile = vi.fn()
|
||||
const fsDeletePath = vi.fn()
|
||||
const runtimeEnvironmentCall = vi.fn()
|
||||
|
||||
vi.mock('@/components/confirmation-dialog-context', () => ({
|
||||
useConfirmationDialog: () => confirm
|
||||
}))
|
||||
vi.mock('@/hooks/useShortcutLabel', () => ({ useShortcutLabel: () => 'Delete' }))
|
||||
vi.mock('@/components/editor/autosave/editor-autosave', () => ({
|
||||
requestEditorFileSave: vi.fn().mockResolvedValue(undefined),
|
||||
requestEditorSaveQuiesce: vi.fn().mockResolvedValue(undefined)
|
||||
}))
|
||||
vi.mock('@/components/right-sidebar/file-explorer/mutations/fileExplorerUndoRedo', () => ({
|
||||
commitFileExplorerOp: vi.fn()
|
||||
}))
|
||||
vi.mock('@/i18n/i18n', () => ({ translate: (_key: string, fallback: string) => fallback }))
|
||||
vi.mock('sonner', () => ({ toast: { error: toastError } }))
|
||||
|
||||
const initialState = useAppStore.getInitialState()
|
||||
const SSH_CONNECTION_ID = 'ssh-target-1'
|
||||
const REMOTE_PATH = '/home/user/project/src/index.ts'
|
||||
const FOLDER_WORKSPACE_ID = 'folder-workspace-1'
|
||||
|
||||
function makeFolderWorkspace(overrides: Partial<FolderWorkspace> = {}): FolderWorkspace {
|
||||
return {
|
||||
id: FOLDER_WORKSPACE_ID,
|
||||
projectGroupId: 'group-1',
|
||||
name: 'Remote workspace',
|
||||
folderPath: '/home/user/project',
|
||||
connectionId: null,
|
||||
linkedTask: null,
|
||||
comment: '',
|
||||
isArchived: false,
|
||||
isUnread: false,
|
||||
isPinned: false,
|
||||
sortOrder: 1,
|
||||
lastActivityAt: 0,
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function makeProjectGroup(overrides: Partial<ProjectGroup> = {}): ProjectGroup {
|
||||
return {
|
||||
id: 'group-1',
|
||||
name: 'Remote workspace',
|
||||
parentPath: '/home/user/project',
|
||||
connectionId: null,
|
||||
parentGroupId: null,
|
||||
createdFrom: 'folder-scan',
|
||||
tabOrder: 0,
|
||||
isCollapsed: false,
|
||||
color: null,
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function makeRepo(overrides: Partial<Repo> & { id: string; path: string }): Repo {
|
||||
return {
|
||||
displayName: overrides.id,
|
||||
badgeColor: '#000',
|
||||
addedAt: 0,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
const remoteFile: TreeNode = {
|
||||
name: 'index.ts',
|
||||
path: REMOTE_PATH,
|
||||
relativePath: 'src/index.ts',
|
||||
isDirectory: false,
|
||||
depth: 0,
|
||||
operationOwner: { kind: 'ssh', connectionId: SSH_CONNECTION_ID }
|
||||
}
|
||||
|
||||
function renderDelete(activeWorktreeId: string) {
|
||||
return renderHook(() =>
|
||||
useFileDeletion({
|
||||
activeWorktreeId,
|
||||
openFiles: [],
|
||||
closeFile: vi.fn(),
|
||||
refreshDir: vi.fn().mockResolvedValue(undefined),
|
||||
setSelectedPaths: vi.fn(),
|
||||
isWindows: false
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
confirm.mockReset().mockResolvedValue(true)
|
||||
fsReadFile.mockReset().mockResolvedValue({ content: 'remote', isBinary: false })
|
||||
fsDeletePath.mockReset().mockResolvedValue(undefined)
|
||||
runtimeEnvironmentCall.mockReset()
|
||||
runtimeEnvironmentCall.mockImplementation((args: { method: string; selector?: string }) => {
|
||||
const runtimeId = args.selector ?? 'env-1'
|
||||
return (
|
||||
createCompatibleRuntimeStatusResponseIfNeeded(args, runtimeId) ?? {
|
||||
id: 'rpc-1',
|
||||
ok: true,
|
||||
result: null,
|
||||
_meta: { runtimeId }
|
||||
}
|
||||
)
|
||||
})
|
||||
toastError.mockReset()
|
||||
vi.stubGlobal('window', {
|
||||
...window,
|
||||
api: {
|
||||
fs: { readFile: fsReadFile, deletePath: fsDeletePath },
|
||||
runtime: { call: vi.fn() },
|
||||
runtimeEnvironments: { call: runtimeEnvironmentCall, subscribe: vi.fn() }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
useAppStore.setState(initialState, true)
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('issue #8135: deleting a remote SSH folder file', () => {
|
||||
it('fails closed for an ambiguous folder even when a runtime is focused', async () => {
|
||||
useAppStore.setState({
|
||||
settings: { activeRuntimeEnvironmentId: 'focused-env' } as never,
|
||||
folderWorkspaces: [makeFolderWorkspace()],
|
||||
projectGroups: [makeProjectGroup()],
|
||||
repos: [
|
||||
makeRepo({
|
||||
id: 'repo-local',
|
||||
path: '/home/user/project/local',
|
||||
projectGroupId: 'group-1'
|
||||
}),
|
||||
makeRepo({
|
||||
id: 'repo-ssh',
|
||||
path: '/home/user/project',
|
||||
connectionId: SSH_CONNECTION_ID,
|
||||
projectGroupId: 'group-1'
|
||||
})
|
||||
],
|
||||
worktreesByRepo: {}
|
||||
})
|
||||
const operationOwner = getFileExplorerOperationOwner(folderWorkspaceKey(FOLDER_WORKSPACE_ID))
|
||||
expect(operationOwner).toEqual({ kind: 'unresolved' })
|
||||
|
||||
const { result } = renderDelete(folderWorkspaceKey(FOLDER_WORKSPACE_ID))
|
||||
|
||||
await act(async () => {
|
||||
result.current.requestDelete({ ...remoteFile, operationOwner })
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(toastError).toHaveBeenCalledWith(
|
||||
"Couldn't determine which host owns this file. Check the workspace connection and try again."
|
||||
)
|
||||
})
|
||||
expect(fsReadFile).not.toHaveBeenCalled()
|
||||
expect(fsDeletePath).not.toHaveBeenCalled()
|
||||
expect(runtimeEnvironmentCall).not.toHaveBeenCalled()
|
||||
expect(confirm).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
-12
@@ -151,16 +151,4 @@ describe('a mirrored remote row decays on the replica clock, not the host clock'
|
||||
|
||||
expect(mirroredRowIsFreshAt(store, T0 + AGENT_STATUS_STALE_AFTER_MS + 1)).toBe(false)
|
||||
})
|
||||
|
||||
it('restarts the window when the host reports genuinely new evidence', () => {
|
||||
const store = seedPairedClientStore()
|
||||
applyChangedHostSnapshot(store, T0 + HOST_SKEW_MS, T0, 1)
|
||||
const laterClientNow = T0 + AGENT_STATUS_STALE_AFTER_MS - 1_000
|
||||
applyChangedHostSnapshot(store, T0 + HOST_SKEW_MS + 60_000, laterClientNow, 2)
|
||||
|
||||
expect(mirroredRowIsFreshAt(store, laterClientNow + AGENT_STATUS_STALE_AFTER_MS - 1)).toBe(true)
|
||||
expect(mirroredRowIsFreshAt(store, laterClientNow + AGENT_STATUS_STALE_AFTER_MS + 1)).toBe(
|
||||
false
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
-189
@@ -1,189 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { act, cleanup, renderHook } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type {
|
||||
RuntimeHostStatusSnapshot,
|
||||
RuntimeEnvironmentStatus
|
||||
} from '../../../../../shared/remote-runtime/host-status/runtime-host-status'
|
||||
import type { RuntimeStatus } from '../../../../../shared/runtime-session-contracts'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
ownerEnvironmentIdForWorkspace: vi.fn(),
|
||||
runtimeSessionMirrorEnvironmentKey: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('./use-runtime-session-mirror-environment-key', () => ({
|
||||
useRuntimeSessionMirrorEnvironmentKeys: () => ({
|
||||
environmentKey: mocks.runtimeSessionMirrorEnvironmentKey(),
|
||||
resubscribeSignal: ''
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('../mirrored-workspace-owner', () => ({
|
||||
mirroredRuntimeEnvironmentIdForWorkspace: (state: unknown, workspaceId: string | null) =>
|
||||
workspaceId ? (mocks.ownerEnvironmentIdForWorkspace(state, workspaceId) ?? null) : null
|
||||
}))
|
||||
|
||||
import { useAppStore } from '@/store/index'
|
||||
|
||||
import { replaceRuntimeEnvironmentRevisions } from '../../rpc/environment-revisions/runtime-environment-revision'
|
||||
import { clearHostLiveTerminalProbesForTests } from '../../hosted-terminals/inventory/host-live-terminal-probe'
|
||||
import { resetWebSessionTabsSnapshotFreshnessForTests } from '../tracking-lifecycle'
|
||||
import { useWebSessionTabsSync } from '../use-web-session-tabs-sync'
|
||||
import { clearRuntimeEnvironmentConnectionGenerations as clearRuntimeEnvironmentConnectionGenerationsForTests } from '@/store/slices/runtime-status/runtime-status-connection-generation'
|
||||
import { publicRuntimeEnvironment } from '../../rpc/testing/paired-runtime-environment-test-fixture'
|
||||
|
||||
const ENV_A = 'env-a'
|
||||
const WORKTREE = 'repo-a::worktree-a'
|
||||
const REVISION_A = 101
|
||||
const MIRROR_KEY = `${ENV_A}runtime-a0${REVISION_A}`
|
||||
const initialState = useAppStore.getInitialState()
|
||||
|
||||
type RuntimeSubscribe = typeof window.api.runtimeEnvironments.subscribe
|
||||
type RuntimeSubscription = {
|
||||
request: Parameters<RuntimeSubscribe>[0]
|
||||
unsubscribe: ReturnType<typeof vi.fn>
|
||||
}
|
||||
|
||||
const subscriptions: RuntimeSubscription[] = []
|
||||
const runtimeCall = vi.fn(async (_args: { method: string }) => ({
|
||||
id: 'list-all',
|
||||
ok: true as const,
|
||||
result: { snapshots: [] },
|
||||
_meta: { runtimeId: 'runtime-a' }
|
||||
}))
|
||||
const runtimeSubscribe = vi.fn<RuntimeSubscribe>(async (request) => {
|
||||
const unsubscribe = vi.fn()
|
||||
subscriptions.push({ request, unsubscribe })
|
||||
return { unsubscribe, sendBinary: vi.fn() }
|
||||
})
|
||||
|
||||
async function settle(): Promise<void> {
|
||||
await Promise.resolve()
|
||||
await Promise.resolve()
|
||||
await Promise.resolve()
|
||||
}
|
||||
|
||||
function makeStatus(runtimeId: string): RuntimeStatus {
|
||||
return {
|
||||
runtimeId,
|
||||
rendererGraphEpoch: 0,
|
||||
graphStatus: 'ready',
|
||||
authoritativeWindowId: null,
|
||||
liveTabCount: 0,
|
||||
liveLeafCount: 0
|
||||
}
|
||||
}
|
||||
|
||||
function verifiedSnapshot(): RuntimeHostStatusSnapshot {
|
||||
return {
|
||||
environmentId: ENV_A,
|
||||
pairingRevision: REVISION_A,
|
||||
sequence: 1,
|
||||
checkedAt: 1,
|
||||
status: makeStatus('runtime-a'),
|
||||
verification: 'verified',
|
||||
transport: 'ready'
|
||||
}
|
||||
}
|
||||
|
||||
function setRuntimeStatusEntry(entry: RuntimeEnvironmentStatus): void {
|
||||
useAppStore.setState({ runtimeStatusByEnvironmentId: new Map([[ENV_A, entry]]) })
|
||||
}
|
||||
|
||||
function activeTabsSubscriptions(): RuntimeSubscription[] {
|
||||
return subscriptions.filter(({ request }) => request.method === 'session.tabs.subscribe')
|
||||
}
|
||||
|
||||
describe('useWebSessionTabsSync under an unverifiable host probe', () => {
|
||||
beforeEach(() => {
|
||||
subscriptions.length = 0
|
||||
runtimeCall.mockClear()
|
||||
runtimeSubscribe.mockClear()
|
||||
mocks.ownerEnvironmentIdForWorkspace.mockReset().mockReturnValue(ENV_A)
|
||||
mocks.runtimeSessionMirrorEnvironmentKey.mockReset().mockReturnValue(MIRROR_KEY)
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: { runtimeEnvironments: { call: runtimeCall, subscribe: runtimeSubscribe } }
|
||||
})
|
||||
resetWebSessionTabsSnapshotFreshnessForTests()
|
||||
clearHostLiveTerminalProbesForTests()
|
||||
const runtimeEnvironments = [
|
||||
publicRuntimeEnvironment({ id: ENV_A, createdAt: 100, pairingRevision: REVISION_A })
|
||||
]
|
||||
replaceRuntimeEnvironmentRevisions(runtimeEnvironments)
|
||||
useAppStore.setState(
|
||||
{
|
||||
...initialState,
|
||||
activeWorktreeId: WORKTREE,
|
||||
workspaceSessionReady: true,
|
||||
runtimeEnvironments,
|
||||
runtimeStatusByEnvironmentId: new Map([
|
||||
[
|
||||
ENV_A,
|
||||
{
|
||||
status: makeStatus('runtime-a'),
|
||||
snapshot: verifiedSnapshot(),
|
||||
checkedAt: 1,
|
||||
connectionGeneration: 1
|
||||
}
|
||||
]
|
||||
])
|
||||
},
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
useAppStore.setState(initialState, true)
|
||||
replaceRuntimeEnvironmentRevisions([])
|
||||
resetWebSessionTabsSnapshotFreshnessForTests()
|
||||
clearRuntimeEnvironmentConnectionGenerationsForTests()
|
||||
})
|
||||
|
||||
it('holds the active session-tabs subscription when the probe goes unverifiable', async () => {
|
||||
renderHook(() => useWebSessionTabsSync())
|
||||
await act(settle)
|
||||
const held = activeTabsSubscriptions()
|
||||
expect(held).toHaveLength(1)
|
||||
|
||||
// The transport is still ready and the host is still delivering; only the probe failed.
|
||||
await act(async () => {
|
||||
setRuntimeStatusEntry({
|
||||
status: null,
|
||||
snapshot: { ...verifiedSnapshot(), sequence: 2, checkedAt: 2, verification: 'unavailable' },
|
||||
checkedAt: 2,
|
||||
connectionGeneration: 1
|
||||
})
|
||||
await settle()
|
||||
})
|
||||
|
||||
expect(held[0]!.unsubscribe).not.toHaveBeenCalled()
|
||||
expect(activeTabsSubscriptions()).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('still restarts the subscription when the host answers with a replacement runtime', async () => {
|
||||
renderHook(() => useWebSessionTabsSync())
|
||||
await act(settle)
|
||||
expect(activeTabsSubscriptions()).toHaveLength(1)
|
||||
|
||||
await act(async () => {
|
||||
setRuntimeStatusEntry({
|
||||
status: makeStatus('runtime-b'),
|
||||
snapshot: {
|
||||
...verifiedSnapshot(),
|
||||
sequence: 2,
|
||||
checkedAt: 2,
|
||||
status: makeStatus('runtime-b')
|
||||
},
|
||||
checkedAt: 2,
|
||||
connectionGeneration: 1
|
||||
})
|
||||
await settle()
|
||||
})
|
||||
|
||||
expect(activeTabsSubscriptions()).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
-138
@@ -1,138 +0,0 @@
|
||||
// Frame views reconstruct main-owned diff tabs after window reload, from both records frames and initial snapshots.
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type * as AgentStatusModule from '@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
import type { LayoutEditorView } from '../../../../../shared/workspace-layout/layout-editor-view'
|
||||
import { applyLayoutCommand } from '../../../../../shared/workspace-layout/workspace-layout-commands'
|
||||
import type { CommandOf } from '../../../../../shared/workspace-layout/workspace-layout-command-types'
|
||||
import { testContext } from '../../../../../shared/workspace-layout/workspace-layout-command.test-fixture'
|
||||
import type { WorkspaceLayoutModel } from '../../../../../shared/workspace-layout/workspace-layout-model'
|
||||
import { localDesktopSession } from '../../../../../shared/workspace-layout/workspace-layout-profile.test-fixture'
|
||||
import type { WorkspaceLayoutChangeFrame } from '../../../../../shared/workspace-layout/workspace-layout-stream-frames'
|
||||
import { GIT_KEY } from '../../../../../shared/workspace-layout/workspace-layout-session.test-fixture'
|
||||
import { bootWindowFromPartitions } from '../../../app-shell/startup-window-view.test-fixture'
|
||||
import { openFileOfLayoutEditorView } from '../../../store/slices/editor/tabs/open-file-layout-view'
|
||||
import { createStoreSessionMockApi } from '../../../store/testing/app-store-session-api.test-fixture'
|
||||
import { createTestStore } from '../../../store/testing/app-store-test-fixture'
|
||||
import { endLayoutFramePositions } from './layout-frame-position'
|
||||
import {
|
||||
loadMainLayoutModel,
|
||||
mainLayoutFrameSender,
|
||||
publishedLayoutsOf
|
||||
} from '../testing/main-loaded-layout-frames.test-fixture'
|
||||
import { installLayoutFrameApplyCheck } from '../testing/workspace-layout-frame-apply-check.test-fixture'
|
||||
import { openWorkspaceLayoutFrameSync } from './workspace-layout-frame-sync'
|
||||
|
||||
vi.mock('sonner', () => ({ toast: { info: vi.fn(), success: vi.fn(), error: vi.fn() } }))
|
||||
vi.mock('@/lib/agent-status/aggregation/worktree-agent-status', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof AgentStatusModule>()
|
||||
return { ...actual, detectAgentStatusFromTitle: vi.fn().mockReturnValue(null) }
|
||||
})
|
||||
|
||||
const stream = vi.hoisted(
|
||||
(): { onFrame: ((frame: WorkspaceLayoutChangeFrame) => void) | null } => ({ onFrame: null })
|
||||
)
|
||||
vi.mock('./runtime-layout-client', () => ({
|
||||
subscribeRuntimeLayout: (
|
||||
_target: unknown,
|
||||
_params: unknown,
|
||||
onFrame: (frame: WorkspaceLayoutChangeFrame) => void
|
||||
) => {
|
||||
stream.onFrame = onFrame
|
||||
return { close: () => {} }
|
||||
}
|
||||
}))
|
||||
|
||||
createStoreSessionMockApi()
|
||||
|
||||
const settle = () => new Promise<void>((resolve) => setTimeout(resolve, 0))
|
||||
|
||||
const DIFF_ID = `${GIT_KEY}::diff::unstaged::src/app.ts`
|
||||
const VIEW: LayoutEditorView = {
|
||||
view: { mode: 'diff', diffSource: 'unstaged' },
|
||||
file: {
|
||||
filePath: '/Users/dev/orca/src/app.ts',
|
||||
relativePath: 'src/app.ts',
|
||||
language: 'typescript'
|
||||
}
|
||||
}
|
||||
|
||||
const openDiff = (view?: LayoutEditorView): CommandOf<'openEditorTab'> => ({
|
||||
type: 'openEditorTab',
|
||||
workspace: GIT_KEY,
|
||||
tabId: DIFF_ID,
|
||||
fileId: DIFF_ID,
|
||||
contentType: 'diff',
|
||||
groupId: 'group-a',
|
||||
...(view ? { view } : {})
|
||||
})
|
||||
|
||||
function applied(model: WorkspaceLayoutModel, command: CommandOf<'openEditorTab'>) {
|
||||
const result = applyLayoutCommand(model, command, testContext())
|
||||
if (!result.ok) {
|
||||
throw new Error(`main refused ${command.type}: ${result.code}`)
|
||||
}
|
||||
return result.model
|
||||
}
|
||||
|
||||
/** A window restored from its own session, shown from main's snapshot of `model`. */
|
||||
async function boot(model = loadMainLayoutModel('local', localDesktopSession())) {
|
||||
const store = createTestStore()
|
||||
await bootWindowFromPartitions(store, [{ hostId: 'local', session: localDesktopSession() }])
|
||||
// Precondition: the window's restore holds no diff, as after a reload.
|
||||
expect(store.getState().openFiles.some((file) => file.id === DIFF_ID)).toBe(false)
|
||||
const sync = openWorkspaceLayoutFrameSync(store)
|
||||
const frames = mainLayoutFrameSender()
|
||||
let shown = model
|
||||
stream.onFrame!(frames.snapshot(publishedLayoutsOf(shown)))
|
||||
sync.start()
|
||||
await settle()
|
||||
const apply = async (command: CommandOf<'openEditorTab'>): Promise<void> => {
|
||||
shown = applied(shown, command)
|
||||
stream.onFrame!(frames.records(GIT_KEY, publishedLayoutsOf(shown)[GIT_KEY]!))
|
||||
await settle()
|
||||
}
|
||||
return { store, apply, close: () => sync.close() }
|
||||
}
|
||||
|
||||
const diffTabs = (store: Awaited<ReturnType<typeof boot>>['store']) =>
|
||||
(store.getState().unifiedTabsByWorktree[GIT_KEY] ?? []).filter((tab) => tab.entityId === DIFF_ID)
|
||||
|
||||
const REBUILT = openFileOfLayoutEditorView(VIEW, { entityId: DIFF_ID, worktreeId: GIT_KEY })
|
||||
|
||||
let check: ReturnType<typeof installLayoutFrameApplyCheck>
|
||||
beforeEach(() => {
|
||||
check = installLayoutFrameApplyCheck()
|
||||
})
|
||||
afterEach(() => {
|
||||
endLayoutFramePositions()
|
||||
check.uninstall()
|
||||
expect(check.failures).toEqual([])
|
||||
})
|
||||
|
||||
describe('a diff tab main publishes with its view', () => {
|
||||
it('draws from a records frame and rebuilds the open file the window lacks', async () => {
|
||||
const { store, apply, close } = await boot()
|
||||
check.forgetBuilds()
|
||||
|
||||
await apply(openDiff(VIEW))
|
||||
|
||||
expect(check.fullBuilt).toEqual([])
|
||||
expect(check.workspaceBuilt).toEqual([GIT_KEY])
|
||||
expect(diffTabs(store)).toHaveLength(1)
|
||||
expect(store.getState().openFiles.filter((file) => file.id === DIFF_ID)).toEqual([REBUILT])
|
||||
close()
|
||||
})
|
||||
|
||||
it('shows after a reload, from the snapshot alone', async () => {
|
||||
const main = applied(loadMainLayoutModel('local', localDesktopSession()), openDiff(VIEW))
|
||||
|
||||
const { store, close } = await boot(main)
|
||||
|
||||
expect(check.fullBuilt).toContain(GIT_KEY)
|
||||
expect(diffTabs(store)).toHaveLength(1)
|
||||
expect(store.getState().groupsByWorktree[GIT_KEY]![0]!.tabOrder).toContain(DIFF_ID)
|
||||
expect(store.getState().openFiles.filter((file) => file.id === DIFF_ID)).toEqual([REBUILT])
|
||||
close()
|
||||
})
|
||||
})
|
||||
@@ -95,12 +95,6 @@ describe('manual PR refresh whose outcome main also broadcasts', () => {
|
||||
expected: 'failure',
|
||||
check: { name: 'build', status: 'completed', conclusion: 'failure', url: null },
|
||||
order: 'reply-first'
|
||||
},
|
||||
{
|
||||
raw: 'success',
|
||||
expected: 'pending',
|
||||
check: { name: 'build', status: 'in_progress', conclusion: null, url: null },
|
||||
order: 'broadcast-first'
|
||||
}
|
||||
]
|
||||
it.each(checksDeliveryCases)(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Require exact host row on removal: unique-candidate/focused fallbacks can destroy the other host’s same-ID project (#13071).
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createTestStore } from '../testing/app-store-test-fixture'
|
||||
import { purgeOrphanedRuntimeSshProjects } from '../slices/worktrees/teardown/orphaned-runtime-ssh-project-purge'
|
||||
import type { ProjectGroup } from '../../../../shared/project-group-types'
|
||||
import type { Repo } from '../../../../shared/repo-types'
|
||||
import { clearRuntimeCompatibilityCache as clearRuntimeCompatibilityCacheForTests } from '../../runtime/rpc/compatibility/runtime-compatibility-cache'
|
||||
@@ -89,20 +88,6 @@ describe('project removal stays on its owner host (#13071)', () => {
|
||||
expect(runtimeCall).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('purges a destroyed SSH host row without touching the same id on the focused host', async () => {
|
||||
const store = createTestStore()
|
||||
store.setState({ repos: [localRow, sshRow] })
|
||||
|
||||
await purgeOrphanedRuntimeSshProjects(store.getState, ['target-1'])
|
||||
|
||||
expect(store.getState().repos).toEqual([localRow])
|
||||
expect(reposRemoveForHost).toHaveBeenCalledWith({
|
||||
repoId: 'same-repo',
|
||||
hostId: 'ssh:target-1'
|
||||
})
|
||||
expect(reposRemove).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('removes every row an owned group holds under the id, each on its own host', async () => {
|
||||
const store = createTestStore()
|
||||
store.setState({
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import { expect, it, vi } from 'vitest'
|
||||
import { toast } from 'sonner'
|
||||
import { getRepoExecutionHostId } from '../../../../shared/execution-host'
|
||||
import type { Repo } from '../../../../shared/repo-types'
|
||||
import type { PublicKnownRuntimeEnvironment } from '../../../../shared/remote-runtime/host-catalog/runtime-environments'
|
||||
import {
|
||||
ephemeralVmCleanup,
|
||||
ephemeralVmListRuntimes,
|
||||
installReposRuntimeRoutingHarness,
|
||||
reposRemoveForHost,
|
||||
runtimeEnvironmentCall,
|
||||
runtimeEnvironmentsList,
|
||||
sshRepo
|
||||
} from './repo-runtime-routing.test-fixture'
|
||||
@@ -25,36 +21,6 @@ vi.mock('sonner', () => ({
|
||||
|
||||
installReposRuntimeRoutingHarness()
|
||||
|
||||
it('retains a runtime-owned SSH project when VM cleanup fails', async () => {
|
||||
const runtimeRepo: Repo = { ...sshRepo, connectionId: 'runtime-ssh-runtime-1' }
|
||||
ephemeralVmListRuntimes.mockResolvedValue([
|
||||
{
|
||||
id: 'runtime-1',
|
||||
cleanupStatus: 'not_started',
|
||||
sshTargetId: runtimeRepo.connectionId
|
||||
}
|
||||
])
|
||||
ephemeralVmCleanup.mockResolvedValue({
|
||||
status: 'cleanup_failed',
|
||||
cleanupStatus: 'failed',
|
||||
sshTargetId: runtimeRepo.connectionId
|
||||
})
|
||||
const store = createTestStore()
|
||||
store.setState({ repos: [runtimeRepo], activeRepoId: runtimeRepo.id })
|
||||
|
||||
await store.getState().removeProject(runtimeRepo.id, {
|
||||
hostId: getRepoExecutionHostId(runtimeRepo),
|
||||
errorFeedback: 'toast'
|
||||
})
|
||||
|
||||
expect(store.getState().repos).toEqual([runtimeRepo])
|
||||
expect(reposRemoveForHost).not.toHaveBeenCalled()
|
||||
expect(toast.error).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.objectContaining({ description: expect.stringContaining('Retry cleanup') })
|
||||
)
|
||||
})
|
||||
|
||||
const vmServerRepo: Repo = {
|
||||
...sshRepo,
|
||||
id: 'vm-repo',
|
||||
@@ -80,49 +46,6 @@ const vmServer: PublicKnownRuntimeEnvironment = {
|
||||
}
|
||||
}
|
||||
|
||||
it('destroys a recipe VM whose managed server holds the project, without asking the gone server', async () => {
|
||||
ephemeralVmListRuntimes.mockResolvedValue([
|
||||
{ id: 'runtime-1', cleanupStatus: 'not_started', sshTargetId: 'runtime-ssh-runtime-1' }
|
||||
])
|
||||
ephemeralVmCleanup.mockResolvedValue({ status: 'cleaned', cleanupStatus: 'succeeded' })
|
||||
const store = createTestStore()
|
||||
store.setState({
|
||||
repos: [vmServerRepo],
|
||||
runtimeEnvironments: [vmServer]
|
||||
})
|
||||
|
||||
await store.getState().removeProject(vmServerRepo.id, {
|
||||
hostId: 'runtime:env-vm',
|
||||
errorFeedback: 'toast'
|
||||
})
|
||||
|
||||
expect(ephemeralVmCleanup).toHaveBeenCalledWith({ runtimeId: 'runtime-1' })
|
||||
expect(runtimeEnvironmentCall).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ method: 'repo.rm' })
|
||||
)
|
||||
expect(store.getState().repos).toEqual([])
|
||||
})
|
||||
|
||||
it("retains a recipe VM's managed-server project when VM cleanup fails", async () => {
|
||||
ephemeralVmListRuntimes.mockResolvedValue([
|
||||
{ id: 'runtime-1', cleanupStatus: 'not_started', sshTargetId: 'runtime-ssh-runtime-1' }
|
||||
])
|
||||
ephemeralVmCleanup.mockResolvedValue({
|
||||
status: 'cleanup_failed',
|
||||
cleanupStatus: 'failed',
|
||||
sshTargetId: 'runtime-ssh-runtime-1'
|
||||
})
|
||||
const store = createTestStore()
|
||||
store.setState({ repos: [vmServerRepo], runtimeEnvironments: [vmServer] })
|
||||
|
||||
await store.getState().removeProject(vmServerRepo.id, {
|
||||
hostId: 'runtime:env-vm',
|
||||
errorFeedback: 'toast'
|
||||
})
|
||||
|
||||
expect(store.getState().repos).toEqual([vmServerRepo])
|
||||
})
|
||||
|
||||
it('never destroys another VM whose server publishes the same workspace id', async () => {
|
||||
const sharedWorkspaceId = `${vmServerRepo.id}::/home/orca/project`
|
||||
ephemeralVmListRuntimes.mockResolvedValue([
|
||||
|
||||
@@ -85,26 +85,6 @@ async function storeWithOnlyBrowserTab(): Promise<{
|
||||
return { store, workspaceId: workspace.id, pageId }
|
||||
}
|
||||
|
||||
/** Three browser tabs in a known tab-bar order, so neighbor selection is deterministic. */
|
||||
async function storeWithThreeBrowserTabs(): Promise<{
|
||||
store: ReturnType<typeof createTestStore>
|
||||
ids: string[]
|
||||
}> {
|
||||
const store = createTestStore()
|
||||
seedStore(store, {
|
||||
worktreesByRepo: { repo1: [makeWorktree({ id: WT, repoId: 'repo1', path: '/path/wt1' })] },
|
||||
activeWorktreeId: WT,
|
||||
activeTabType: 'terminal'
|
||||
})
|
||||
main = await drawTabsFromMain(store)
|
||||
const ids = [0, 1, 2].map(
|
||||
(index) =>
|
||||
store.getState().createBrowserTab(WT, `https://example.test/${index}`, { activate: true }).id
|
||||
)
|
||||
await settled()
|
||||
return { store, ids }
|
||||
}
|
||||
|
||||
describe('closeBrowserTab with reason cleanup', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -125,27 +105,4 @@ describe('closeBrowserTab with reason cleanup', () => {
|
||||
expect(s.browserTabsByWorktree[WT] ?? []).toEqual([])
|
||||
expect(s.unifiedTabsByWorktree[WT] ?? []).toEqual([])
|
||||
})
|
||||
|
||||
// Require real closes still use Landing; cleanup carve-out must remain narrow.
|
||||
it('still returns to the landing state when the user closes the only tab', async () => {
|
||||
const { store, workspaceId } = await storeWithOnlyBrowserTab()
|
||||
|
||||
store.getState().closeBrowserTab(workspaceId)
|
||||
|
||||
await settled()
|
||||
|
||||
expect(store.getState().activeWorktreeId).toBeNull()
|
||||
})
|
||||
|
||||
// Background tab close must never move focus, including through pending address-bar bookkeeping.
|
||||
it('leaves the active browser tab alone when a background tab closes', async () => {
|
||||
const { store, ids } = await storeWithThreeBrowserTabs()
|
||||
store.getState().setActiveBrowserTab(ids[0]!)
|
||||
|
||||
store.getState().closeBrowserTab(ids[2]!)
|
||||
|
||||
await settled()
|
||||
|
||||
expect(store.getState().activeBrowserTabIdByWorktree[WT]).toBe(ids[0]!)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -140,27 +140,4 @@ describe('accepted details requests and reading cache', () => {
|
||||
expect(final?.error).not.toContain('SENTINEL_SECRET')
|
||||
}
|
||||
)
|
||||
|
||||
it('discards the superseded post-publication cache transaction under a nested context open', () => {
|
||||
const store = createEditorTabsStore()
|
||||
let nested = false
|
||||
const stop = store.subscribe(() => {
|
||||
if (nested) {
|
||||
return
|
||||
}
|
||||
nested = true
|
||||
store.getState().openCheckRunDetails('wt-1', 'new-context', readingCheck, {
|
||||
details: readingDetails(),
|
||||
loading: false,
|
||||
error: null
|
||||
})
|
||||
})
|
||||
store.getState().openCheckRunDetails('wt-1', 'old-context', readingCheck, {
|
||||
details: null,
|
||||
loading: true,
|
||||
error: null
|
||||
})
|
||||
expect(store.getState().openFiles[0].checkRunDetails?.contextKey).toBe('new-context')
|
||||
stop()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
||||
import { createEditorStore, createEditorTabsStore } from '../editor-slice-test-harness'
|
||||
|
||||
import type { Tab } from '../../../../../../shared/tab-types'
|
||||
import { makeWorktree } from '../../worktrees/worktree.test-fixture'
|
||||
|
||||
const { toastErrorMock } = vi.hoisted(() => ({
|
||||
toastErrorMock: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('sonner', () => ({
|
||||
toast: { error: toastErrorMock }
|
||||
}))
|
||||
|
||||
const { notifyHostOfMirroredEditorCloseMock } = vi.hoisted(() => ({
|
||||
notifyHostOfMirroredEditorCloseMock: vi.fn()
|
||||
}))
|
||||
vi.mock('@/runtime/web-session-tabs-sync/closing/close-mirrored-editor-tab', () => ({
|
||||
notifyHostOfMirroredEditorClose: (...args: unknown[]) =>
|
||||
notifyHostOfMirroredEditorCloseMock(...args)
|
||||
}))
|
||||
|
||||
// Why: tabs are mirrored only from a paired server's workspace, which keeps today's close path.
|
||||
const pairedServerWorktrees = {
|
||||
'repo-1': [
|
||||
makeWorktree({
|
||||
id: 'wt-1',
|
||||
repoId: 'repo-1',
|
||||
path: '/repo',
|
||||
runtimeOwnerEnvironmentId: 'env-1'
|
||||
}),
|
||||
makeWorktree({
|
||||
id: 'wt-2',
|
||||
repoId: 'repo-1',
|
||||
path: '/other',
|
||||
runtimeOwnerEnvironmentId: 'env-1'
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
function mirroredEditorUnifiedTab(id: string, entityId: string, worktreeId: string): Tab {
|
||||
return {
|
||||
id,
|
||||
entityId,
|
||||
worktreeId,
|
||||
groupId: `${worktreeId}:group`,
|
||||
contentType: 'editor',
|
||||
label: entityId,
|
||||
customLabel: null,
|
||||
color: null,
|
||||
sortOrder: 0,
|
||||
createdAt: 0
|
||||
}
|
||||
}
|
||||
|
||||
describe('createEditorSlice editor drafts', () => {
|
||||
it('preserves the foreground reveal when a background preview record was already replaced', () => {
|
||||
const store = createEditorTabsStore()
|
||||
store.getState().createUnifiedTab('wt-2', 'diff', {
|
||||
id: 'old-preview',
|
||||
entityId: 'removed-content',
|
||||
isPreview: true,
|
||||
activate: false,
|
||||
executionHostId: 'local'
|
||||
})
|
||||
const reveal = { filePath: '/repo/next.ts', line: 7, column: 3, matchLength: 4 }
|
||||
store.setState({ pendingEditorReveal: reveal })
|
||||
|
||||
store.getState().createUnifiedTab('wt-2', 'diff', {
|
||||
id: 'new-preview',
|
||||
entityId: 'new-content',
|
||||
isPreview: true,
|
||||
activate: false,
|
||||
executionHostId: 'local'
|
||||
})
|
||||
|
||||
expect(store.getState().pendingEditorReveal).toBe(reveal)
|
||||
expect(store.getState().activeWorktreeId).toBe('wt-1')
|
||||
expect(store.getState().unifiedTabsByWorktree['wt-2']?.map((tab) => tab.id)).toEqual([
|
||||
'new-preview'
|
||||
])
|
||||
})
|
||||
|
||||
it('drops replaced preview drafts so hidden preview state cannot linger', () => {
|
||||
const store = createEditorTabsStore()
|
||||
|
||||
store.getState().openFile(
|
||||
{
|
||||
filePath: '/repo/docs/README.md',
|
||||
relativePath: 'docs/README.md',
|
||||
worktreeId: 'wt-1',
|
||||
language: 'markdown',
|
||||
mode: 'edit'
|
||||
},
|
||||
{ preview: true }
|
||||
)
|
||||
store.getState().setEditorDraft('/repo/docs/README.md', 'draft')
|
||||
|
||||
store.getState().openFile(
|
||||
{
|
||||
filePath: '/repo/docs/guide.md',
|
||||
relativePath: 'docs/guide.md',
|
||||
worktreeId: 'wt-1',
|
||||
language: 'markdown',
|
||||
mode: 'edit'
|
||||
},
|
||||
{ preview: true }
|
||||
)
|
||||
|
||||
expect(store.getState().editorDrafts).toEqual({})
|
||||
})
|
||||
|
||||
it('falls back to a browser tab when closing the last editor in the active worktree', () => {
|
||||
const store = createEditorStore()
|
||||
|
||||
store.setState({
|
||||
browserTabsByWorktree: {
|
||||
'wt-1': [
|
||||
{
|
||||
id: 'browser-1',
|
||||
worktreeId: 'wt-1',
|
||||
url: 'https://example.com',
|
||||
title: 'Example',
|
||||
loading: false,
|
||||
faviconUrl: null,
|
||||
canGoBack: false,
|
||||
canGoForward: false,
|
||||
loadError: null,
|
||||
createdAt: 0
|
||||
}
|
||||
]
|
||||
},
|
||||
activeBrowserTabIdByWorktree: { 'wt-1': 'browser-1' }
|
||||
})
|
||||
|
||||
store.getState().openFile({
|
||||
filePath: '/repo/src/file.ts',
|
||||
relativePath: 'src/file.ts',
|
||||
worktreeId: 'wt-1',
|
||||
language: 'typescript',
|
||||
mode: 'edit'
|
||||
})
|
||||
|
||||
store.getState().closeFile('/repo/src/file.ts')
|
||||
|
||||
expect(store.getState().activeTabType).toBe('browser')
|
||||
expect(store.getState().activeBrowserTabId).toBe('browser-1')
|
||||
})
|
||||
|
||||
it('returns to the landing state when closing the last editor in a worktree with no other surfaces', () => {
|
||||
const store = createEditorStore()
|
||||
|
||||
store.getState().openFile({
|
||||
filePath: '/repo/notes.md',
|
||||
relativePath: 'notes.md',
|
||||
worktreeId: 'wt-1',
|
||||
language: 'markdown',
|
||||
mode: 'edit'
|
||||
})
|
||||
|
||||
store.getState().closeFile('/repo/notes.md')
|
||||
|
||||
expect(store.getState().activeWorktreeId).toBeNull()
|
||||
expect(store.getState().activeFileId).toBeNull()
|
||||
expect(store.getState().activeBrowserTabId).toBeNull()
|
||||
expect(store.getState().activeTabType).toBe('terminal')
|
||||
})
|
||||
})
|
||||
|
||||
describe('closeFile host mirroring', () => {
|
||||
beforeEach(() => {
|
||||
notifyHostOfMirroredEditorCloseMock.mockReset()
|
||||
})
|
||||
|
||||
it('notifies the host for mirrored editors removed by close all in the active worktree', () => {
|
||||
const store = createEditorTabsStore()
|
||||
store.setState({ worktreesByRepo: pairedServerWorktrees })
|
||||
const a = store.getState().openFile({
|
||||
filePath: '/repo/a.ts',
|
||||
relativePath: 'a.ts',
|
||||
worktreeId: 'wt-1',
|
||||
language: 'typescript',
|
||||
mode: 'edit',
|
||||
mirroredFromRuntimeSession: true
|
||||
})
|
||||
const b = store.getState().openFile({
|
||||
filePath: '/other/b.ts',
|
||||
relativePath: 'b.ts',
|
||||
worktreeId: 'wt-2',
|
||||
language: 'typescript',
|
||||
mode: 'edit',
|
||||
mirroredFromRuntimeSession: true
|
||||
})
|
||||
store.setState({
|
||||
unifiedTabsByWorktree: {
|
||||
'wt-1': [mirroredEditorUnifiedTab('host-tab-a', a, 'wt-1')],
|
||||
'wt-2': [mirroredEditorUnifiedTab('host-tab-b', b, 'wt-2')]
|
||||
},
|
||||
tabBarOrderByWorktree: {
|
||||
'wt-1': ['host-tab-a'],
|
||||
'wt-2': ['host-tab-b']
|
||||
}
|
||||
})
|
||||
|
||||
store.getState().closeAllFiles()
|
||||
|
||||
// closeAllFiles bypasses closeFile; require host close hooks for every directly removed mirror.
|
||||
expect(notifyHostOfMirroredEditorCloseMock).toHaveBeenCalledWith(expect.anything(), 'wt-1', a)
|
||||
expect(store.getState().openFiles).toHaveLength(1)
|
||||
expect(store.getState().openFiles[0]?.id).toBe(b)
|
||||
expect(store.getState().tabBarOrderByWorktree['wt-1']).toEqual([])
|
||||
expect(store.getState().tabBarOrderByWorktree['wt-2']).toEqual(['host-tab-b'])
|
||||
})
|
||||
})
|
||||
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { create } from 'zustand'
|
||||
import type { AppState } from '../../types'
|
||||
import { createHostedReviewSlice } from './hosted-review'
|
||||
import { getHostedReviewCacheKey } from './hosted-review-cache-identity'
|
||||
|
||||
import type { HostedReviewInfo } from '../../../../../shared/source-control/hosted-review/hosted-review-contracts'
|
||||
|
||||
@@ -46,17 +45,6 @@ function makeStore(settings: AppState['settings'] = null) {
|
||||
}))
|
||||
}
|
||||
|
||||
const review: HostedReviewInfo = {
|
||||
provider: 'gitlab',
|
||||
number: 5,
|
||||
title: 'Shared MR status',
|
||||
state: 'open',
|
||||
url: 'https://gitlab.com/g/p/-/merge_requests/5',
|
||||
status: 'success',
|
||||
updatedAt: '2026-05-10T00:00:00.000Z',
|
||||
mergeable: 'MERGEABLE'
|
||||
}
|
||||
|
||||
const githubReview: HostedReviewInfo = {
|
||||
provider: 'github',
|
||||
number: 12,
|
||||
@@ -81,48 +69,6 @@ describe('hosted review slice', () => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('clears stale GitHub PR cache when branch review lookup finds a non-GitHub review', async () => {
|
||||
mockApi.hostedReview.forBranch.mockResolvedValueOnce(review)
|
||||
const store = makeStore()
|
||||
store.setState({
|
||||
prCache: {
|
||||
'repo-1::feature/gitlab': {
|
||||
data: {
|
||||
number: 12,
|
||||
title: 'Old GitHub PR',
|
||||
state: 'open',
|
||||
url: 'https://github.com/acme/orca/pull/12',
|
||||
checksStatus: 'pending',
|
||||
updatedAt: '2026-03-28T00:00:00Z',
|
||||
mergeable: 'UNKNOWN',
|
||||
headSha: 'head-oid'
|
||||
},
|
||||
fetchedAt: 1
|
||||
},
|
||||
'/repo::feature/gitlab': {
|
||||
data: {
|
||||
number: 99,
|
||||
title: 'Old path-scoped GitHub PR',
|
||||
state: 'closed',
|
||||
url: 'https://github.com/acme/orca/pull/99',
|
||||
checksStatus: 'failure',
|
||||
updatedAt: '2026-03-28T00:00:00Z',
|
||||
mergeable: 'UNKNOWN',
|
||||
headSha: 'old-head-oid'
|
||||
},
|
||||
fetchedAt: 1
|
||||
}
|
||||
}
|
||||
} as unknown as Partial<AppState>)
|
||||
|
||||
await expect(
|
||||
store.getState().fetchHostedReviewForBranch('/repo', 'feature/gitlab')
|
||||
).resolves.toEqual(review)
|
||||
|
||||
expect(store.getState().prCache['repo-1::feature/gitlab']).toBeUndefined()
|
||||
expect(store.getState().prCache['/repo::feature/gitlab']).toBeUndefined()
|
||||
})
|
||||
|
||||
it('does not reuse an old-head request after the branch advances', async () => {
|
||||
const mergedAtHead: HostedReviewInfo = {
|
||||
...githubReview,
|
||||
@@ -161,50 +107,4 @@ describe('hosted review slice', () => {
|
||||
})
|
||||
).resolves.toBeNull()
|
||||
})
|
||||
|
||||
it('does not preserve a merged GitHub review after the worktree moves off its head', async () => {
|
||||
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
const cacheKey = getHostedReviewCacheKey(
|
||||
'/repo',
|
||||
'feature/merged',
|
||||
null,
|
||||
'repo-1',
|
||||
null,
|
||||
null,
|
||||
true
|
||||
)
|
||||
const store = makeStore()
|
||||
store.setState({
|
||||
hostedReviewCache: {
|
||||
[cacheKey]: {
|
||||
data: {
|
||||
provider: 'github',
|
||||
number: 7,
|
||||
title: 'Merged at head',
|
||||
state: 'merged',
|
||||
url: 'https://github.com/acme/orca/pull/7',
|
||||
status: 'success',
|
||||
updatedAt: '2026-05-10T00:00:00.000Z',
|
||||
mergeable: 'MERGEABLE',
|
||||
headSha: 'aaaaaaa'
|
||||
},
|
||||
fetchedAt: 1,
|
||||
linkedReviewHintKey: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
mockApi.hostedReview.forBranch.mockRejectedValueOnce(new Error('transient gh failure'))
|
||||
|
||||
try {
|
||||
// Failure after head advance must not preserve the prior merged review.
|
||||
await expect(
|
||||
store.getState().fetchHostedReviewForBranch('/repo', 'feature/merged', {
|
||||
force: true,
|
||||
currentHeadOid: 'bbbbbbb'
|
||||
})
|
||||
).resolves.toBeNull()
|
||||
} finally {
|
||||
consoleError.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -73,48 +73,6 @@ describe('TabsSlice', () => {
|
||||
|
||||
// Already-active group clicks skip activateTab; focusGroup must still expose its tab to the attention scan.
|
||||
describe('focusGroup', () => {
|
||||
it('does not broadcast active-surface writes when the focused group is already current', () => {
|
||||
const editorFileId = '/tmp/feature/src/main.ts'
|
||||
const tab = store.getState().createUnifiedTab(WT, 'editor', {
|
||||
id: 'editor-tab-1',
|
||||
entityId: editorFileId,
|
||||
label: 'main.ts'
|
||||
})
|
||||
const groupId = store.getState().groupsByWorktree[WT][0].id
|
||||
store.setState({
|
||||
activeWorktreeId: WT,
|
||||
openFiles: [makeOpenFile({ id: editorFileId, worktreeId: WT })],
|
||||
activeGroupIdByWorktree: { [WT]: groupId },
|
||||
activeFileId: editorFileId,
|
||||
activeFileIdByWorktree: { [WT]: editorFileId },
|
||||
activeBrowserTabId: null,
|
||||
activeBrowserTabIdByWorktree: { [WT]: null },
|
||||
activeTabId: null,
|
||||
activeTabIdByWorktree: { [WT]: null },
|
||||
activeTabType: 'editor',
|
||||
activeTabTypeByWorktree: { [WT]: 'editor' },
|
||||
groupsByWorktree: {
|
||||
[WT]: [
|
||||
{
|
||||
...store.getState().groupsByWorktree[WT][0],
|
||||
activeTabId: tab.id
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
const before = store.getState()
|
||||
const listener = vi.fn()
|
||||
const unsubscribe = store.subscribe(listener)
|
||||
|
||||
store.getState().focusGroup(WT, groupId)
|
||||
unsubscribe()
|
||||
|
||||
expect(listener).not.toHaveBeenCalled()
|
||||
expect(store.getState().activeGroupIdByWorktree).toBe(before.activeGroupIdByWorktree)
|
||||
expect(store.getState().activeFileIdByWorktree).toBe(before.activeFileIdByWorktree)
|
||||
expect(store.getState().activeTabTypeByWorktree).toBe(before.activeTabTypeByWorktree)
|
||||
})
|
||||
|
||||
// Why: focusGroup fires on every pointerdown in the group chrome; it moves what is on screen and the scan reads it.
|
||||
it("puts the focused group's active tab on screen", () => {
|
||||
const tabA = store.getState().createUnifiedTab(WT, 'terminal')
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
createTestStore,
|
||||
mockApi,
|
||||
resetRemoteRuntimeMocks,
|
||||
resetWorktreeSliceModuleMemory,
|
||||
runtimeEnvironmentCall
|
||||
resetWorktreeSliceModuleMemory
|
||||
} from '../worktrees/worktrees-slice-test-harness'
|
||||
|
||||
const requestWorktreeBaseFallbackNotice = vi.hoisted(() => vi.fn())
|
||||
@@ -36,120 +35,6 @@ describe('worktree unread (show-until-interact)', () => {
|
||||
resetRemoteRuntimeMocks()
|
||||
})
|
||||
|
||||
it('keeps unread state local instead of throwing for genuinely ambiguous owners (#10634)', () => {
|
||||
const store = createTestStore()
|
||||
const worktreeId = 'repo-shared::/same/path'
|
||||
store.setState({
|
||||
settings: { activeRuntimeEnvironmentId: 'hub-c' } as never,
|
||||
worktreesByRepo: {
|
||||
'repo-shared': [
|
||||
makeWorktree({
|
||||
id: worktreeId,
|
||||
repoId: 'repo-shared',
|
||||
hostId: 'ssh:ssh-a',
|
||||
runtimeOwnerEnvironmentId: 'hub-a'
|
||||
}),
|
||||
makeWorktree({
|
||||
id: worktreeId,
|
||||
repoId: 'repo-shared',
|
||||
hostId: 'ssh:ssh-b',
|
||||
runtimeOwnerEnvironmentId: 'hub-b'
|
||||
})
|
||||
]
|
||||
}
|
||||
} as Partial<AppState>)
|
||||
|
||||
expect(() =>
|
||||
store.getState().markAgentAttentionUnread({
|
||||
workspaceId: worktreeId,
|
||||
subjectKey: null,
|
||||
groupId: null,
|
||||
reason: 'agent-completion'
|
||||
})
|
||||
).not.toThrow()
|
||||
|
||||
expect(store.getState().worktreesByRepo['repo-shared'][0].isUnread).toBe(true)
|
||||
expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled()
|
||||
expect(runtimeEnvironmentCall).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('never throws from any passive path for a genuinely ambiguous owner (#10634)', () => {
|
||||
// Exercise every passive notification path; any unresolved-host throw recreates the uncaught renderer error.
|
||||
const worktreeId = 'repo-shared::/same/path'
|
||||
const ambiguousState = (): Partial<AppState> =>
|
||||
({
|
||||
settings: { activeRuntimeEnvironmentId: 'hub-c' } as never,
|
||||
worktreesByRepo: {
|
||||
'repo-shared': [
|
||||
makeWorktree({
|
||||
id: worktreeId,
|
||||
repoId: 'repo-shared',
|
||||
hostId: 'ssh:ssh-a',
|
||||
runtimeOwnerEnvironmentId: 'hub-a',
|
||||
isUnread: true
|
||||
}),
|
||||
makeWorktree({
|
||||
id: worktreeId,
|
||||
repoId: 'repo-shared',
|
||||
hostId: 'ssh:ssh-b',
|
||||
runtimeOwnerEnvironmentId: 'hub-b',
|
||||
isUnread: true
|
||||
})
|
||||
]
|
||||
}
|
||||
}) as Partial<AppState>
|
||||
|
||||
for (const [label, run] of [
|
||||
[
|
||||
'readOnScreenAttention',
|
||||
(s: AppState) =>
|
||||
s.readOnScreenAttention(
|
||||
{ workspaceIds: [worktreeId], targets: [{ worktreeId: worktreeId, tabId: 'no-tab' }] },
|
||||
{ screenArrived: true }
|
||||
)
|
||||
],
|
||||
['bumpWorktreeActivity', (s: AppState) => s.bumpWorktreeActivity(worktreeId)]
|
||||
] as const) {
|
||||
const store = createTestStore()
|
||||
store.setState(ambiguousState())
|
||||
mockApi.worktrees.updateMeta.mockClear()
|
||||
|
||||
expect(() => run(store.getState()), `${label} threw for an ambiguous owner`).not.toThrow()
|
||||
expect(
|
||||
mockApi.worktrees.updateMeta,
|
||||
`${label} persisted to a guessed host`
|
||||
).not.toHaveBeenCalled()
|
||||
}
|
||||
})
|
||||
|
||||
it('updates unread state for hidden detected worktrees', () => {
|
||||
const store = createTestStore()
|
||||
const hidden = makeWorktree({
|
||||
id: 'repo1::/path/hidden',
|
||||
repoId: 'repo1',
|
||||
path: '/path/hidden'
|
||||
})
|
||||
const detected = makeDetectedResult('repo1', [hidden])
|
||||
detected.worktrees[0] = { ...detected.worktrees[0], ownership: 'external', visible: false }
|
||||
store.setState({
|
||||
worktreesByRepo: { repo1: [] },
|
||||
detectedWorktreesByRepo: { repo1: detected }
|
||||
} as Partial<AppState>)
|
||||
|
||||
store.getState().markAgentAttentionUnread({
|
||||
workspaceId: hidden.id,
|
||||
subjectKey: null,
|
||||
groupId: null,
|
||||
reason: 'agent-completion'
|
||||
})
|
||||
expect(store.getState().detectedWorktreesByRepo.repo1.worktrees[0].isUnread).toBe(true)
|
||||
|
||||
store
|
||||
.getState()
|
||||
.readOnScreenAttention({ workspaceIds: [hidden.id], targets: [] }, { screenArrived: true })
|
||||
expect(store.getState().detectedWorktreesByRepo.repo1.worktrees[0].isUnread).toBe(false)
|
||||
})
|
||||
|
||||
it('reads a hidden detected worktree once it is activated and on screen', () => {
|
||||
const store = createTestStore()
|
||||
const hidden = makeWorktree({
|
||||
|
||||
-46
@@ -133,50 +133,4 @@ describe('workspace cleanup removal and protection', () => {
|
||||
})
|
||||
expect(removeWorktree).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fails a removal that reveals concrete git risk after an unverified force approval', async () => {
|
||||
const approvedCandidate = makeCandidate({
|
||||
executionHostId: 'local',
|
||||
tier: 'review',
|
||||
blockers: ['git-status-error'],
|
||||
git: {
|
||||
clean: null,
|
||||
upstreamAhead: null,
|
||||
upstreamBehind: null,
|
||||
checkedAt: null
|
||||
}
|
||||
})
|
||||
const nowRevealsUnpushed = makeCandidate({
|
||||
executionHostId: 'local',
|
||||
tier: 'review',
|
||||
blockers: ['unpushed-commits'],
|
||||
git: { clean: true, upstreamAhead: 3, upstreamBehind: 0, checkedAt: NOW }
|
||||
})
|
||||
const scan = vi.fn().mockResolvedValue({
|
||||
scannedAt: NOW,
|
||||
candidates: [nowRevealsUnpushed],
|
||||
errors: []
|
||||
} satisfies WorkspaceCleanupScanResult)
|
||||
installWorkspaceCleanupApi(scan)
|
||||
const removeWorktree = vi.fn().mockResolvedValue({ ok: true })
|
||||
const store = createCleanupTestStore(removeWorktree)
|
||||
|
||||
await expect(
|
||||
store.getState().removeWorkspaceCleanupCandidates([WORKTREE_ID], {
|
||||
approvedCandidates: [approvedCandidate]
|
||||
})
|
||||
).resolves.toEqual({
|
||||
removedIds: [],
|
||||
removedIdentities: [],
|
||||
failures: [
|
||||
{
|
||||
worktreeId: WORKTREE_ID,
|
||||
executionHostId: 'local',
|
||||
displayName: 'old-workspace',
|
||||
message: 'Workspace changed after confirmation. Refresh to review it before removing.'
|
||||
}
|
||||
]
|
||||
})
|
||||
expect(removeWorktree).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
-38
@@ -69,44 +69,6 @@ it('wakes slept folder on local after publishing restored explorer and terminal
|
||||
expect(store.getState().refreshGitHubForWorktreeIfStale).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('wakes slept git on local after publishing restored explorer and terminal state', () => {
|
||||
const { store, workspaceId, activate } = seedWorkspace('git', 'local')
|
||||
markWorktreeSleepIntent(workspaceId)
|
||||
const wake = vi.fn(() => {
|
||||
expect(store.getState().activeWorktreeId).toBe('worktree-activation')
|
||||
expect(store.getState().tabsByWorktree[workspaceId][0].generation).toBe(4)
|
||||
expect(store.getState().rightSidebarExplorerView).toBe('files')
|
||||
})
|
||||
onWorktreeSleepIntentCleared(workspaceId, wake)
|
||||
|
||||
activate()
|
||||
|
||||
expect(wake).toHaveBeenCalledOnce()
|
||||
expect(store.getState().activeWorkspaceExecutionHostId).toBe('local')
|
||||
expect(store.getState().tabsByWorktree[workspaceId][0].pendingActivationSpawn).toBe(true)
|
||||
expect(store.getState().activeTabId).toBe('terminal')
|
||||
expect(store.getState().refreshGitHubForWorktreeIfStale).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('wakes slept folder on ssh:remote after publishing restored explorer and terminal state', () => {
|
||||
const { store, workspaceId, activate } = seedWorkspace('folder', 'ssh:remote')
|
||||
markWorktreeSleepIntent(workspaceId)
|
||||
const wake = vi.fn(() => {
|
||||
expect(store.getState().activeWorktreeId).toBe('folder:folder-activation')
|
||||
expect(store.getState().tabsByWorktree[workspaceId][0].generation).toBe(4)
|
||||
expect(store.getState().rightSidebarExplorerView).toBe('files')
|
||||
})
|
||||
onWorktreeSleepIntentCleared(workspaceId, wake)
|
||||
|
||||
activate()
|
||||
|
||||
expect(wake).toHaveBeenCalledOnce()
|
||||
expect(store.getState().activeWorkspaceExecutionHostId).toBe('ssh:remote')
|
||||
expect(store.getState().tabsByWorktree[workspaceId][0].pendingActivationSpawn).toBe(true)
|
||||
expect(store.getState().activeTabId).toBe('terminal')
|
||||
expect(store.getState().refreshGitHubForWorktreeIfStale).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('wakes slept git on ssh:remote after publishing restored explorer and terminal state', () => {
|
||||
const { store, workspaceId, activate } = seedWorkspace('git', 'ssh:remote')
|
||||
markWorktreeSleepIntent(workspaceId)
|
||||
|
||||
-37
@@ -86,43 +86,6 @@ it('confirms a second PR by exact source and head when branch discovery would re
|
||||
)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ type: 'issue' as const },
|
||||
{ number: 99 },
|
||||
{ url: 'https://github.com/foreign/repo/pull/42' },
|
||||
{ branchName: 'unrelated' },
|
||||
{ headSha: 'other-head' }
|
||||
])(
|
||||
'rejects contradictory exact evidence without using an implicit fallback: %j',
|
||||
async (change) => {
|
||||
const { store, workspace, branchLookup } = setup()
|
||||
exactLookup.mockResolvedValue({ ...secondary, ...change })
|
||||
store.getState().observeTerminalGitHubPullRequestLink(workspace.id, link)
|
||||
await flush()
|
||||
expect(getWorkspaceAttachments(store.getState().worktreesByRepo.repo[0])).toEqual([])
|
||||
expect(branchLookup).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
|
||||
it('confirms a review against its saved push branch', async () => {
|
||||
const { store, workspace, branchLookup } = setup()
|
||||
const pending = Promise.withResolvers<GitHubWorkItem | null>()
|
||||
exactLookup.mockReturnValue(pending.promise)
|
||||
const saved = {
|
||||
...workspace,
|
||||
branch: 'refs/heads/local-copy',
|
||||
pushTarget: { remoteName: 'origin', branchName: 'feature' }
|
||||
}
|
||||
store.setState({ worktreesByRepo: { repo: [saved] } })
|
||||
store.getState().observeTerminalGitHubPullRequestLink(workspace.id, link)
|
||||
pending.resolve(secondary)
|
||||
await flush()
|
||||
expect(
|
||||
getWorkspaceAttachments(store.getState().worktreesByRepo.repo[0]).map((item) => item.number)
|
||||
).toEqual([42])
|
||||
expect(branchLookup).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('rejects delayed review after its saved push branch changes', async () => {
|
||||
const { store, workspace, branchLookup } = setup()
|
||||
const pending = Promise.withResolvers<GitHubWorkItem | null>()
|
||||
|
||||
-22
@@ -110,28 +110,6 @@ beforeEach(() => {
|
||||
resetWorktreeSliceModuleMemory()
|
||||
})
|
||||
|
||||
it('preserves distinct live confirmations on one branch without replacing the manual primary', async () => {
|
||||
const { store, pending, observeBurst, branchLookup } = setup()
|
||||
observeBurst()
|
||||
await flush()
|
||||
let completed = 0
|
||||
while (completed < 4) {
|
||||
const batch = [...pending]
|
||||
pending.clear()
|
||||
for (const [number, deferred] of batch) {
|
||||
deferred.resolve(review(number))
|
||||
}
|
||||
completed += batch.length
|
||||
await flush()
|
||||
}
|
||||
expect(branchLookup).not.toHaveBeenCalled()
|
||||
const items = getWorkspaceAttachments(store.getState().worktreesByRepo.repo[0])
|
||||
expect(items.map((item) => item.number).sort((a, b) => (a ?? 0) - (b ?? 0))).toEqual([
|
||||
7, 100, 101, 102, 103
|
||||
])
|
||||
expect(store.getState().worktreesByRepo.repo[0].linkedPR).toBe(7)
|
||||
})
|
||||
|
||||
it('drops stale queued starts and fallback reads after the pane closes', async () => {
|
||||
const { store, pending, observeBurst, closePane, branchLookup } = setup()
|
||||
observeBurst()
|
||||
|
||||
-54
@@ -1,6 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import type * as AgentStatusModule from '@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
import { getDefaultSettings } from '../../../../../../shared/constants'
|
||||
import { createCompatibleRuntimeStatusResponseIfNeeded } from '../../../../runtime/rpc/testing/runtime-compatibility-test-fixture'
|
||||
import { clearRuntimeCompatibilityCache as clearRuntimeCompatibilityCacheForTests } from '../../../../runtime/rpc/compatibility/runtime-compatibility-cache'
|
||||
import 'sonner'
|
||||
@@ -89,57 +88,4 @@ describe('removeWorktree cascade', () => {
|
||||
expect(mockApi.pty.kill).not.toHaveBeenCalled()
|
||||
expect(s.activeWorktreeId).toBe(worktreeId)
|
||||
})
|
||||
|
||||
it.each([
|
||||
'Could not connect to the remote Orca runtime.',
|
||||
'Remote Orca runtime closed the connection.',
|
||||
'Timed out waiting for the remote Orca runtime to respond.'
|
||||
])(
|
||||
'does not offer force delete for wrapped remote runtime failure: %s',
|
||||
async (runtimeFailure) => {
|
||||
const store = createTestStore()
|
||||
const worktreeId = 'repo1::/path/wt1'
|
||||
const error = `Error invoking remote method 'runtime-environments:call': Error: ${runtimeFailure}`
|
||||
const displayed = runtimeFailure
|
||||
|
||||
mockApi.runtimeEnvironments.call.mockImplementation((args: { method: string }) => {
|
||||
const compatibility = createCompatibleRuntimeStatusResponseIfNeeded(args)
|
||||
if (compatibility) {
|
||||
return Promise.resolve(compatibility)
|
||||
}
|
||||
if (args.method === 'repo.hooksCheck') {
|
||||
return Promise.resolve({
|
||||
id: 'rpc-hooks',
|
||||
ok: true,
|
||||
result: { hasHooks: false, hooks: null, mayNeedUpdate: false },
|
||||
_meta: { runtimeId: 'remote-runtime' }
|
||||
})
|
||||
}
|
||||
return Promise.reject(new Error(error))
|
||||
})
|
||||
|
||||
seedStore(store, {
|
||||
settings: { ...getDefaultSettings('/tmp'), activeRuntimeEnvironmentId: 'env-1' },
|
||||
worktreesByRepo: {
|
||||
repo1: [makeWorktree({ id: worktreeId, repoId: 'repo1', hostId: 'runtime:env-1' })]
|
||||
},
|
||||
tabsByWorktree: {},
|
||||
ptyIdsByTabId: {},
|
||||
terminalLayoutsByTabId: {}
|
||||
})
|
||||
|
||||
const result = await store
|
||||
.getState()
|
||||
.removeWorktree({ id: worktreeId, executionHostId: null })
|
||||
|
||||
expect(result).toEqual({ ok: false, error: displayed })
|
||||
expect(store.getState().deleteStateByWorktreeId[worktreeId]).toEqual({
|
||||
isDeleting: false,
|
||||
error: displayed,
|
||||
canForceDelete: false,
|
||||
forceDeleteReason: null
|
||||
})
|
||||
expect(mockApi.worktrees.remove).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
-57
@@ -60,31 +60,6 @@ it('refuses newly appeared unapproved live agent on local after preparation', as
|
||||
expect(mockApi.worktrees.remove).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('allows already-approved live agent on local after preparation', async () => {
|
||||
const store = createTestStore()
|
||||
const candidate = makeCandidate({ executionHostId: 'local' })
|
||||
candidate.blockers = ['live-agent']
|
||||
const wt = makeWorktree({ id: candidate.worktreeId, repoId: candidate.repoId, hostId: 'local' })
|
||||
store.setState({ worktreesByRepo: { [wt.repoId]: [wt] } })
|
||||
const gate = deferred<unknown>()
|
||||
const preparation = mockApi.hooks.check
|
||||
preparation.mockReturnValueOnce(gate.promise)
|
||||
const removal = store.getState().removeWorktree({ id: wt.id, executionHostId: 'local' }, false, {
|
||||
assertBeforeDispatch: () =>
|
||||
assertWorkspaceCleanupAgentStopApproved(store.getState(), candidate, candidate)
|
||||
})
|
||||
await vi.waitFor(() => expect(preparation).toHaveBeenCalled())
|
||||
const entry = makeAgentEntry('chat', 'working', Date.now(), {
|
||||
worktreeId: wt.id,
|
||||
connectionId: null,
|
||||
terminalHandle: undefined
|
||||
})
|
||||
store.setState({ agentStatusByPaneKey: { [entry.paneKey]: entry } })
|
||||
gate.resolve({ hasHooks: false })
|
||||
expect((await removal).ok).toBe(true)
|
||||
expect(mockApi.worktrees.remove).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuses newly appeared unapproved live agent on runtime:env-1 after preparation', async () => {
|
||||
const store = createTestStore()
|
||||
const candidate = makeCandidate({ executionHostId: 'runtime:env-1' })
|
||||
@@ -116,35 +91,3 @@ it('refuses newly appeared unapproved live agent on runtime:env-1 after preparat
|
||||
expect((await removal).ok).toBe(false)
|
||||
expect(runtimeEnvironmentCall).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('allows already-approved live agent on runtime:env-1 after preparation', async () => {
|
||||
const store = createTestStore()
|
||||
const candidate = makeCandidate({ executionHostId: 'runtime:env-1' })
|
||||
candidate.blockers = ['live-agent']
|
||||
const wt = makeWorktree({
|
||||
id: candidate.worktreeId,
|
||||
repoId: candidate.repoId,
|
||||
hostId: 'runtime:env-1'
|
||||
})
|
||||
store.setState({ worktreesByRepo: { [wt.repoId]: [wt] } })
|
||||
const gate = deferred<unknown>()
|
||||
store.setState({ trustedOrcaHooks: { repo1: { all: { approvedAt: 1 } } } })
|
||||
const preparation = runtimeEnvironmentTransportCall
|
||||
preparation.mockReturnValueOnce(gate.promise)
|
||||
const removal = store
|
||||
.getState()
|
||||
.removeWorktree({ id: wt.id, executionHostId: 'runtime:env-1' }, false, {
|
||||
assertBeforeDispatch: () =>
|
||||
assertWorkspaceCleanupAgentStopApproved(store.getState(), candidate, candidate)
|
||||
})
|
||||
await vi.waitFor(() => expect(preparation).toHaveBeenCalled())
|
||||
const entry = makeAgentEntry('chat', 'working', Date.now(), {
|
||||
worktreeId: wt.id,
|
||||
connectionId: null,
|
||||
terminalHandle: 'remote:env-1@@pty'
|
||||
})
|
||||
store.setState({ agentStatusByPaneKey: { [entry.paneKey]: entry } })
|
||||
gate.resolve(createCompatibleRuntimeStatusResponse())
|
||||
expect((await removal).ok).toBe(true)
|
||||
expect(runtimeEnvironmentCall).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
-81
@@ -10,7 +10,6 @@ import '../create-worktree-slice'
|
||||
import { makeWorktree } from '../worktree.test-fixture'
|
||||
import {
|
||||
createTestStore,
|
||||
mockApi,
|
||||
resetRemoteRuntimeMocks,
|
||||
resetWorktreeSliceModuleMemory
|
||||
} from '../worktrees-slice-test-harness'
|
||||
@@ -61,86 +60,6 @@ describe('removeWorktree state cleanup', () => {
|
||||
expect(hasDismissedHugeRepoWarning(replacementProbe)).toBe(false)
|
||||
})
|
||||
|
||||
it('purges the orphaned project that pointed at a destroyed runtime-owned SSH target', async () => {
|
||||
const store = createTestStore()
|
||||
const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' })
|
||||
const orphanedSetup: AppState['projectHostSetups'][number] = {
|
||||
id: 'setup-runtime-ssh',
|
||||
hostId: 'ssh:runtime-ssh-orca-1',
|
||||
projectId: 'project-runtime-ssh',
|
||||
repoId: 'repo-runtime-ssh',
|
||||
path: '/runtime/repo',
|
||||
displayName: 'Runtime repo',
|
||||
setupState: 'ready',
|
||||
setupMethod: 'legacy-repo',
|
||||
createdAt: 1,
|
||||
updatedAt: 1
|
||||
}
|
||||
const userSshSetup: AppState['projectHostSetups'][number] = {
|
||||
id: 'setup-user-ssh',
|
||||
hostId: 'ssh:my-server',
|
||||
projectId: 'project-user-ssh',
|
||||
repoId: 'repo-user-ssh',
|
||||
path: '/user/repo',
|
||||
displayName: 'User repo',
|
||||
setupState: 'ready',
|
||||
setupMethod: 'legacy-repo',
|
||||
createdAt: 1,
|
||||
updatedAt: 1
|
||||
}
|
||||
const deleteProjectHostSetup = vi.fn().mockResolvedValue(null)
|
||||
store.setState({
|
||||
worktreesByRepo: { repo1: [wt] },
|
||||
projectHostSetups: [orphanedSetup, userSshSetup],
|
||||
deleteProjectHostSetup
|
||||
})
|
||||
mockApi.ephemeralVm.listRuntimes.mockResolvedValueOnce([
|
||||
{
|
||||
id: 'runtime-1',
|
||||
workspaceId: 'repo1::/path/wt1',
|
||||
cleanupStatus: 'not_started',
|
||||
sshTargetId: 'runtime-ssh-orca-1'
|
||||
}
|
||||
])
|
||||
|
||||
await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null })
|
||||
|
||||
// Only the orphaned runtime-owned project setup is purged; the user's SSH project is untouched.
|
||||
expect(deleteProjectHostSetup).toHaveBeenCalledWith({
|
||||
setupId: 'setup-runtime-ssh',
|
||||
hostId: 'ssh:runtime-ssh-orca-1'
|
||||
})
|
||||
})
|
||||
|
||||
it('cleans up markdownFrontmatterVisible for preview-only source files in the removed worktree', async () => {
|
||||
const store = createTestStore()
|
||||
const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' })
|
||||
|
||||
store.setState({
|
||||
worktreesByRepo: { repo1: [wt] },
|
||||
openFiles: [
|
||||
{
|
||||
id: 'markdown-preview::file-1',
|
||||
worktreeId: 'repo1::/path/wt1',
|
||||
filePath: '/path/wt1/readme.md',
|
||||
relativePath: 'readme.md',
|
||||
language: 'markdown',
|
||||
isDirty: false,
|
||||
markdownPreviewSourceFileId: 'file-1',
|
||||
mode: 'markdown-preview' as const
|
||||
}
|
||||
],
|
||||
markdownFrontmatterVisible: {
|
||||
'file-1': true,
|
||||
'file-2': true
|
||||
}
|
||||
} as unknown as Partial<AppState>)
|
||||
|
||||
await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null })
|
||||
|
||||
expect(store.getState().markdownFrontmatterVisible).toEqual({ 'file-2': true })
|
||||
})
|
||||
|
||||
it('records the sidebar scroll anchor in the same tick it removes the worktree', async () => {
|
||||
const store = createTestStore()
|
||||
const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' })
|
||||
|
||||
@@ -130,22 +130,6 @@ describe("a new tab's first terminal, started by main in a layout-owner build",
|
||||
expect(store.getState().terminalPaneStartsByPaneKey[PANE_KEY]).toBeUndefined()
|
||||
})
|
||||
|
||||
it('starts its own terminal, with its startup, when main does not hold the tab', async () => {
|
||||
const store = storeWithWorktree()
|
||||
store.getState().createTab(WORKTREE, undefined, undefined, {
|
||||
id: TAB,
|
||||
initialLeafId: LEAF,
|
||||
pendingStartup: { command: 'make dev' }
|
||||
})
|
||||
await settle()
|
||||
|
||||
mocks.create!.reject(new Error('host_not_owned'))
|
||||
await settle()
|
||||
|
||||
expect(store.getState().terminalPaneStartsByPaneKey[PANE_KEY]).toBeUndefined()
|
||||
expect(store.getState().pendingStartupByTabId[TAB]).toMatchObject({ command: 'make dev' })
|
||||
})
|
||||
|
||||
it('gives no startup back to a tab the user closed before main answered', async () => {
|
||||
const store = storeWithWorktree()
|
||||
store.getState().createTab(WORKTREE, undefined, undefined, {
|
||||
|
||||
Reference in New Issue
Block a user