diff --git a/src/main/persistence/loading-store/github-cache-database.test.ts b/src/main/persistence/loading-store/github-cache-database.test.ts index 50d130bc061..008ac4e59a7 100644 --- a/src/main/persistence/loading-store/github-cache-database.test.ts +++ b/src/main/persistence/loading-store/github-cache-database.test.ts @@ -35,18 +35,6 @@ const save = (dataFile: string, cache: Parameters { - it('reads back saved entries, including removals', () => { - const dataFile = profileDataFile() - save(dataFile, { pr: { 'o/r#1': pr(1), 'o/r#2': pr(2) }, issue: {} }) - save(dataFile, { pr: { 'o/r#2': pr(3) }, issue: { 'o/r#9': pr(4) } }) - - expect(readGitHubCacheDatabase(dataFile)).toEqual({ - cache: { pr: { 'o/r#2': pr(3) }, issue: { 'o/r#9': pr(4) } }, - fromSidecar: false, - sidecarHash: null - }) - }) - it('keeps an older build sidecar until its imported rows commit', async () => { const dataFile = profileDataFile() save(dataFile, { pr: { 'o/r#1': pr(1) }, issue: {} }) diff --git a/src/main/ssh/host-server/ssh-host-server-on-connect-held-move.test.ts b/src/main/ssh/host-server/ssh-host-server-on-connect-held-move.test.ts deleted file mode 100644 index 5e8f7bd16ba..00000000000 --- a/src/main/ssh/host-server/ssh-host-server-on-connect-held-move.test.ts +++ /dev/null @@ -1,74 +0,0 @@ -/** #27267: stopped conversions must release their fence or report it retained and resume next connect. */ -import { describe, expect, it, vi } from 'vitest' -import type { SshTarget } from '../../../shared/ssh-types' -import { resolveHostServerOnConnect } from './ssh-host-server-on-connect' -import { hostServerDepsStub } from './testing/ssh-host-server-on-connect-test-deps' -import { unservedHostServerMessage, unservedServerStatus } from './ssh-host-unserved-status' - -const target: SshTarget = { id: 'ssh-1', label: 'Box', host: 'box', port: 22, username: 'me' } - -function fencedHost(phase: 'source-fenced' | 'destination-staged', registered: boolean) { - const host: { phase: string | null; registered: boolean } = { phase, registered } - return { - host, - deps: (overrides: Parameters[0] = {}) => - hostServerDepsStub({ - managedEnvironmentId: () => (host.phase && host.registered ? 'env-1' : null), - hasUnfinishedConversion: () => - host.phase === 'source-fenced' || host.phase === 'destination-staged', - isFencedBeforeStaging: () => host.phase === 'source-fenced', - ...overrides - }) - } -} - -describe('a move to the managed server that stops short', () => { - it('keeps the host locked and says the move is paused when the server cannot answer', async () => { - const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined) - const { deps } = fencedHost('source-fenced', true) - const d = deps({ - convert: vi.fn(async () => { - throw new Error('Could not connect to the remote Orca runtime.') - }), - abandonConversion: vi.fn(async () => { - throw new Error('Could not connect to the remote Orca runtime.') - }) - }) - const result = await resolveHostServerOnConnect(target, d) - expect(result).toMatchObject({ route: 'unserved', reason: 'failed', held: true }) - expect(d.abandonConversion).toHaveBeenCalledWith(target) - // Never an unavailability record: that would stop later connects from resuming. - expect(d.recordUnavailable).not.toHaveBeenCalled() - if (result.route !== 'unserved') { - throw new Error('expected unserved') - } - expect(unservedHostServerMessage(result)).toContain('Connect again to resume') - expect(unservedServerStatus(result)).toMatchObject({ kind: 'relay', held: true }) - warn.mockRestore() - }) - - it('gives the host back, with no lock to report, when the server proves it holds nothing', async () => { - const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined) - const { host, deps } = fencedHost('destination-staged', true) - const d = deps({ - convert: vi.fn(async () => { - throw new Error('orcad_migration_commit_not_committed:staged') - }), - abandonConversion: vi.fn(async () => { - host.phase = null - }) - }) - const result = await resolveHostServerOnConnect(target, d) - expect(result).toEqual({ - route: 'unserved', - reason: 'failed', - detail: 'orcad_migration_commit_not_committed:staged' - }) - if (result.route === 'unserved') { - expect(unservedHostServerMessage(result)).toBe( - 'Orca couldn’t start its server on this host. Try connecting again.' - ) - } - warn.mockRestore() - }) -}) diff --git a/src/main/ssh/host-server/ssh-host-server-on-connect-node-download.test.ts b/src/main/ssh/host-server/ssh-host-server-on-connect-node-download.test.ts index e7ddac1f80e..c93bcf0ceb6 100644 --- a/src/main/ssh/host-server/ssh-host-server-on-connect-node-download.test.ts +++ b/src/main/ssh/host-server/ssh-host-server-on-connect-node-download.test.ts @@ -4,7 +4,7 @@ import type { SshTarget } from '../../../shared/ssh-types' import { resolveHostServerOnConnect } from './ssh-host-server-on-connect' import { hostServerDepsStub } from './testing/ssh-host-server-on-connect-test-deps' import { unservedHostServerMessage } from './ssh-host-unserved-status' -import { sftpSessionClosedError } from '../file-transfer/ssh-file-transfer-abort' + import { NodeRuntimeUnreachableError } from '../../managed-server/install/remote-node-runtime-host-download' const target: SshTarget = { id: 'ssh-1', label: 'Box', host: 'box', port: 22, username: 'me' } @@ -54,11 +54,4 @@ describe('a managed-server setup that could not download Node', () => { expect(result).not.toHaveProperty('nodeDownloadBlocked') expect(unservedHostServerMessage(result)).toContain('Try connecting again') }) - - it('lets lost contact win, since nothing proves the host failed', async () => { - const lost = new Error('upload failed', { cause: sftpSessionClosedError() }) - const result = await deployFailingWith(lost) - expect(result).toMatchObject({ contactLost: true }) - expect(result).not.toHaveProperty('nodeDownloadBlocked') - }) }) diff --git a/src/renderer/src/components/native-chat/composer/controls/NativeChatComposerToolbar.test.tsx b/src/renderer/src/components/native-chat/composer/controls/NativeChatComposerToolbar.test.tsx deleted file mode 100644 index 2542a48748d..00000000000 --- a/src/renderer/src/components/native-chat/composer/controls/NativeChatComposerToolbar.test.tsx +++ /dev/null @@ -1,251 +0,0 @@ -// @vitest-environment happy-dom -import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react' -import { afterEach, expect, it, vi } from 'vitest' -import { Editor, EditorContent } from '@tiptap/react' -import StarterKit from '@tiptap/starter-kit' -import { focusMountedNativeChatEditor } from '../editor/native-chat-mounted-editor-view' -import { TooltipProvider } from '@/components/ui/tooltip' -import { NativeChatComposerActions } from './NativeChatComposerActions' -import type { - SessionOptionDescriptor, - SessionOptionsSurface -} from '../../../../../../shared/native-chat/input/native-chat-session-options' - -vi.mock('@/i18n/use-ui-language-revision', () => ({ useUiLanguageRevision: () => 0 })) -vi.mock('@/i18n/i18n', () => ({ - translate: (_key: string, fallback: string, values?: Record) => - Object.entries(values ?? {}).reduce( - (text, [key, value]) => text.replaceAll(`{{${key}}}`, value), - fallback - ) -})) -vi.mock('sonner', () => ({ toast: { error: vi.fn() } })) - -afterEach(() => { - cleanup() - vi.restoreAllMocks() - vi.unstubAllGlobals() -}) - -it('keeps current mode, permissions and Goal reachable through overflow, including pending writes, then restores direct controls', async () => { - let width = 140 - const observers = new Set<() => void>() - vi.stubGlobal( - 'ResizeObserver', - class { - constructor(callback: ResizeObserverCallback) { - observers.add(() => callback([], this)) - } - observe() {} - unobserve() {} - disconnect() {} - } - ) - vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function ( - this: HTMLElement - ) { - return this.hasAttribute('data-compact') ? width : 0 - }) - vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function ( - this: HTMLElement - ) { - const compact = this.closest('[data-compact]')?.getAttribute('data-compact') === 'true' - const sizes: Record = { - attach: [32, 32], - plan: [56, 26], - permissions: [112, 26], - goal: [54, 24], - model: [260, 26], - dictation: [32, 32], - cancel: [60, 60] - } - const id = this.dataset.composerControl - const measured = id - ? (sizes[id]?.[Number(compact)] ?? 0) - : this.querySelector('button[aria-label="More chat controls"]') - ? 24 - : 48 - return { - x: 0, - y: 0, - width: measured, - height: 24, - top: 0, - left: 0, - bottom: 24, - right: measured, - toJSON() {} - } - }) - let settle = () => {} - const setOption = vi.fn().mockImplementation( - () => - new Promise((resolve) => { - settle = () => resolve({ snapshot: [] }) - }) - ) - const surface: SessionOptionsSurface = { - getSnapshot: () => [], - setOption, - invokeAction: async () => ({ snapshot: [] }), - subscribe: () => () => {} - } - const snapshot: SessionOptionDescriptor[] = [ - { - id: 'model', - label: 'Model', - category: 'model', - transport: 'agent-session', - valueSource: 'applied', - settable: true, - kind: { - type: 'select', - currentValue: 'first', - choices: [ - { value: 'first', label: 'Long provider model' }, - { value: 'second', label: 'Second model' } - ] - } - }, - { - id: 'interactionMode', - label: 'Mode', - category: 'mode', - transport: 'agent-session', - valueSource: 'applied', - settable: true, - kind: { - type: 'select', - currentValue: 'plan', - choices: [ - { value: 'default', label: 'Build' }, - { value: 'plan', label: 'Plan' } - ] - } - }, - { - id: 'permissionMode', - label: 'Permissions', - transport: 'agent-session', - valueSource: 'applied', - settable: true, - kind: { - type: 'select', - currentValue: 'full-access', - choices: [ - { value: 'ask', label: 'Ask' }, - { value: 'full-access', label: 'Full access' } - ] - } - } - ] - const exitGoal = vi.fn() - const editor = new Editor({ - extensions: [StarterKit], - editorProps: { attributes: { role: 'textbox', 'aria-label': 'Chat message' } } - }) - const focus = () => focusMountedNativeChatEditor(editor) - const resize = (next: number) => { - width = next - act(() => observers.forEach((observer) => observer())) - } - const view = render( - - - - - - ) - fireEvent.click(screen.getByRole('button', { name: 'More chat controls' })) - const partial = screen.getByRole('dialog') - const menuMode = within(partial).getByRole('button', { name: 'Exit plan mode' }) - const menuPermission = within(partial).getByRole('button', { name: 'Permissions Full access' }) - menuPermission.focus() - resize(1000) - expect(within(partial).getByRole('button', { name: 'Exit plan mode' })).toBe(menuMode) - expect(within(partial).getByRole('button', { name: 'Permissions Full access' })).toBe( - menuPermission - ) - expect(document.activeElement).toBe(menuPermission) - fireEvent.click(screen.getByRole('button', { name: 'More chat controls' })) - await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()) - await waitFor(() => - expect(document.activeElement).toBe(screen.getByRole('textbox', { name: 'Chat message' })) - ) - resize(100) - fireEvent.click(screen.getByRole('button', { name: 'More chat controls' })) - resize(1000) - const outside = screen.getByRole('textbox', { name: 'Outside composer' }) - fireEvent.pointerDown(outside) - outside.focus() - await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()) - expect(document.activeElement).toBe(outside) - resize(100) - fireEvent.click(screen.getByRole('button', { name: 'More chat controls' })) - const popup = screen.getByRole('dialog') - await act(async () => - fireEvent.click(within(popup).getByRole('button', { name: 'Exit plan mode' })) - ) - expect(setOption).toHaveBeenLastCalledWith('interactionMode', 'default') - await waitFor(() => - expect(document.activeElement).toBe(screen.getByRole('textbox', { name: 'Chat message' })) - ) - fireEvent.click(screen.getByRole('button', { name: 'More chat controls' })) - expect( - within(screen.getByRole('dialog')).getByRole('button', { name: 'Exit plan mode' }) - ).toHaveProperty('disabled', true) - await act(async () => settle()) - const permission = within(screen.getByRole('dialog')).getByRole('button', { - name: 'Permissions Full access' - }) - fireEvent.pointerDown(permission, { button: 0, ctrlKey: false }) - await act(async () => fireEvent.click(screen.getByRole('menuitemradio', { name: /Ask/ }))) - expect(setOption).toHaveBeenLastCalledWith('permissionMode', 'ask') - await act(async () => settle()) - fireEvent.click( - within(screen.getByRole('dialog')).getByRole('button', { name: 'Exit goal mode' }) - ) - expect(exitGoal).toHaveBeenCalledOnce() - resize(1000) - const buttons = screen - .getAllByRole('button') - .map((button) => button.getAttribute('aria-label') ?? button.textContent) - expect(buttons.slice(0, 4)).toEqual([ - 'Attach file', - 'Permissions Full access', - 'Exit plan mode', - 'Exit goal mode' - ]) - expect(screen.queryByRole('button', { name: 'More chat controls' })).toBeNull() - const model = screen.getByRole('button', { name: 'Model Long provider model' }) - fireEvent.click(model) - const modelPopup = screen.getByRole('dialog') - resize(50) - expect(screen.getByRole('button', { name: 'Model Long provider model' })).toBe(model) - expect(screen.getByRole('dialog')).toBe(modelPopup) - fireEvent.click(within(modelPopup).getByRole('option', { name: /Second model/ })) - expect(setOption).toHaveBeenLastCalledWith('model', 'second') - resize(1000) - expect(screen.getByRole('dialog')).toBe(modelPopup) - expect(screen.getByRole('button', { name: 'Model Second model' })).toBe(model) - await act(async () => settle()) - view.unmount() - editor.destroy() -}) diff --git a/src/renderer/src/components/native-chat/tools/diffs/NativeChatTurnDiffRollup.test.tsx b/src/renderer/src/components/native-chat/tools/diffs/NativeChatTurnDiffRollup.test.tsx deleted file mode 100644 index f28cd80edf1..00000000000 --- a/src/renderer/src/components/native-chat/tools/diffs/NativeChatTurnDiffRollup.test.tsx +++ /dev/null @@ -1,186 +0,0 @@ -// @vitest-environment happy-dom -import '@testing-library/jest-dom/vitest' -import { act, cleanup, fireEvent, render, screen } from '@testing-library/react' -import { afterEach, beforeEach, expect, it, vi } from 'vitest' -import { toast } from 'sonner' -import type { NativeChatMessage } from '../../../../../../shared/native-chat/native-chat-types' -import type { GlobalSettings } from '../../../../../../shared/global-settings-types' -import { getDefaultSettings } from '../../../../../../shared/constants' -import { useAppStore } from '@/store' - -import { TooltipProvider } from '../../../ui/tooltip' - -import { NativeChatMessageList } from '../../NativeChatMessageList' -import { - session, - stubLayout, - stubResizeObserver -} from '../../viewport/virtualization/native-chat-windowing-test-harness' -import { NativeChatLinkClickContext } from '../../links/actions/native-chat-link-click-context' - -vi.mock('sonner', () => ({ - toast: { success: vi.fn(), error: vi.fn(), dismiss: vi.fn() } -})) - -const messages: NativeChatMessage[] = [ - { - id: 'u', - role: 'user', - source: 'transcript', - timestamp: 1, - blocks: [{ type: 'text', text: 'Fix the greeting' }] - }, - { - id: 'work', - role: 'assistant', - source: 'transcript', - timestamp: 2, - blocks: [ - { - type: 'tool-call', - name: 'Bash', - input: { command: 'inspect-private-diagnostic' }, - state: 'completed' - }, - { type: 'tool-result', output: 'diagnostic-output' }, - { - type: 'tool-call', - name: 'Edit', - input: { - file_path: '/repo/greeting.ts', - old_string: 'helloOld()', - new_string: 'helloNew()' - }, - state: 'completed' - }, - { type: 'tool-result', output: 'The file /repo/greeting.ts has been updated successfully.' }, - { type: 'tool-call', name: 'Diff', input: { path: 'status.ts' } }, - { type: 'tool-result', output: '@@ -1 +1 @@\n-statusOld()\n+statusNew()' } - ] - }, - { - id: 'answer', - role: 'assistant', - source: 'transcript', - timestamp: 3, - blocks: [{ type: 'text', text: 'Updated the greeting.' }] - } -] -let restoreLayout = (): void => {} -let restoreResizeObserver = (): void => {} -beforeEach(() => { - restoreLayout = stubLayout({ scrollGeometry: true, offsetChain: true }) - restoreResizeObserver = stubResizeObserver() -}) -afterEach(() => { - cleanup() - restoreResizeObserver() - restoreLayout() -}) - -it('keeps landed files visible after work folds, opens a patch in one click and survives history remount', () => { - const onLinkClick = vi.fn() - const view = (working: boolean) => ( - - - - - - ) - const { rerender, unmount } = render(view(true)) - expect(screen.getByRole('button', { name: /\/repo\/greeting.ts/ })).toBeVisible() - rerender(view(false)) - expect(screen.getByRole('button', { name: /\/repo\/greeting.ts/ })).toBeVisible() - expect(screen.queryByText('diagnostic-output')).toBeNull() - expect(screen.queryByText('helloNew()')).toBeNull() - fireEvent.click(screen.getByRole('button', { name: /\/repo\/greeting.ts/ })) - expect(screen.getByText('helloOld()')).toBeVisible() - expect(screen.getByText('helloNew()')).toBeVisible() - fireEvent.click(screen.getByRole('link', { name: '/repo/greeting.ts' })) - expect(onLinkClick).toHaveBeenCalledTimes(1) - expect(screen.getByText('helloNew()')).toBeVisible() - expect(screen.queryByText('statusNew()')).toBeNull() - unmount() - render(view(false)) - expect(screen.getByRole('button', { name: /status.ts/ })).toBeVisible() - expect(screen.queryByText('diagnostic-output')).toBeNull() -}) - -const hiddenList = ( - - - -) - -function withStore( - updateSettingsOrThrow: (updates: Partial) => Promise, - run: (actions: { openSettingsPage: () => void; openSettingsTarget: () => void }) => Promise -): Promise { - const original = useAppStore.getState() - const actions = { openSettingsPage: vi.fn(), openSettingsTarget: vi.fn() } - // Settings saved before this setting existed have no key; the card must still show for them. - const { nativeChatTurnDiffSummary: _absent, ...savedBeforeSetting } = getDefaultSettings('/tmp') - useAppStore.setState({ settings: savedBeforeSetting, updateSettingsOrThrow, ...actions }) - vi.mocked(toast.success).mockClear() - vi.mocked(toast.error).mockClear() - return run(actions).finally(() => useAppStore.setState(original, true)) -} - -it('Hide turns the changed-files card off in every chat and the toast links to its setting', () => - withStore( - async (updates) => { - useAppStore.setState((state) => ({ settings: { ...state.settings!, ...updates } })) - }, - async ({ openSettingsPage, openSettingsTarget }) => { - render(hiddenList) - await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Hide' }))) - expect(useAppStore.getState().settings?.nativeChatTurnDiffSummary).toBe(false) - expect(screen.queryByRole('button', { name: /\/repo\/greeting.ts/ })).toBeNull() - expect(screen.getByText('Updated the greeting.')).toBeVisible() - - expect(toast.success).toHaveBeenCalledTimes(1) - const description = vi.mocked(toast.success).mock.calls[0]?.[1]?.description - cleanup() - render(<>{typeof description === 'function' ? description() : description}) - fireEvent.click(screen.getByRole('button')) - expect(openSettingsPage).toHaveBeenCalledTimes(1) - expect(openSettingsTarget).toHaveBeenCalledWith({ - pane: 'chat', - repoId: null, - sectionId: 'chat-turn-diff-summary' - }) - - // A chat opened later stays without the card until the setting is turned back on. - cleanup() - render(hiddenList) - expect(screen.queryByRole('button', { name: 'Hide' })).toBeNull() - act(() => { - useAppStore.setState((state) => ({ - settings: { ...state.settings!, nativeChatTurnDiffSummary: true } - })) - }) - expect(screen.getByRole('button', { name: /\/repo\/greeting.ts/ })).toBeVisible() - } - )) - -it('a Hide whose save fails keeps the card and says so instead of confirming', () => - withStore( - () => Promise.reject(new Error('settings write failed')), - async () => { - render(hiddenList) - await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Hide' }))) - expect(screen.getByRole('button', { name: /\/repo\/greeting.ts/ })).toBeVisible() - expect(toast.success).not.toHaveBeenCalled() - expect(toast.error).toHaveBeenCalledTimes(1) - } - )) diff --git a/src/renderer/src/store/slices/agent-inventory/detected-agents.test.ts b/src/renderer/src/store/slices/agent-inventory/detected-agents.test.ts index e2e80bae143..143b266805d 100644 --- a/src/renderer/src/store/slices/agent-inventory/detected-agents.test.ts +++ b/src/renderer/src/store/slices/agent-inventory/detected-agents.test.ts @@ -10,7 +10,6 @@ import { RUNTIME_PROTOCOL_VERSION } from '../../../../../shared/protocol-version' import { clearRuntimeCompatibilityCache as clearRuntimeCompatibilityCacheForTests } from '@/runtime/rpc/compatibility/runtime-compatibility-cache' -import { FLOATING_TERMINAL_WORKTREE_ID } from '../../../../../shared/constants' const detectAgents = vi.fn() const refreshAgents = vi.fn() @@ -80,97 +79,6 @@ describe('createDetectedAgentsSlice WSL context', () => { }) }) - it('publishes a Floating-first host probe to a later ordinary local caller', async () => { - let resolveDetection: (agents: string[]) => void = () => {} - detectAgents.mockReturnValueOnce( - new Promise((resolve) => { - resolveDetection = resolve - }) - ) - const store = createTestStore() - - const floating = store.getState().ensureDetectedAgents(FLOATING_TERMINAL_WORKTREE_ID) - const ordinary = store.getState().ensureDetectedAgents() - - expect(detectAgents).toHaveBeenCalledTimes(1) - expect(store.getState().isDetectingAgents).toBe(true) - resolveDetection(['codex']) - await expect(Promise.all([floating, ordinary])).resolves.toEqual([['codex'], ['codex']]) - expect(store.getState().detectedAgentIds).toEqual(['codex']) - expect(store.getState().isDetectingAgents).toBe(false) - }) - - it('restores the legacy inventory when returning to a cached local context', async () => { - detectAgents.mockImplementation(async (context) => - context?.projectRuntime?.runtime.kind === 'wsl' ? ['claude'] : ['codex'] - ) - const store = createTestStore({ - repos: [makeRepo({ id: 'repo-1', path: '\\\\wsl.localhost\\Ubuntu\\home\\alice\\repo' })], - activeRepoId: 'repo-1', - activeWorktreeId: null - }) - - await store.getState().ensureDetectedAgents() - store.setState({ activeRepoId: null }) - await store.getState().ensureDetectedAgents() - store.setState({ activeRepoId: 'repo-1' }) - - await expect(store.getState().ensureDetectedAgents()).resolves.toEqual(['claude']) - expect(store.getState().detectedAgentIds).toEqual(['claude']) - }) - - it('retries a local context after a transient detection failure', async () => { - detectAgents - .mockRejectedValueOnce(new Error('cold-start timeout')) - .mockResolvedValueOnce(['codex']) - const store = createTestStore() - - await expect(store.getState().ensureDetectedAgents()).resolves.toEqual([]) - await expect(store.getState().ensureDetectedAgents()).resolves.toEqual(['codex']) - - expect(store.getState().detectedAgentIds).toEqual(['codex']) - }) - - it('clears local agents when the project runtime requires repair before detection', async () => { - detectAgents.mockImplementation(async (context) => { - if (context?.projectRuntime?.status === 'repair-required') { - throw new Error('Project runtime requires repair before agent detection') - } - return ['claude'] - }) - const store = createTestStore({ - repos: [makeRepo({ id: 'repo-1', path: 'C:\\repo' })], - activeRepoId: 'repo-1', - activeWorktreeId: null - }) - - await expect(store.getState().ensureDetectedAgents()).resolves.toEqual(['claude']) - expect(store.getState().detectedAgentIds).toEqual(['claude']) - - store.setState({ - settings: { - terminalWindowsShell: 'wsl.exe' - } as AppState['settings'] - } as Partial) - - await expect(store.getState().ensureDetectedAgents()).resolves.toEqual([]) - expect(store.getState().detectedAgentIds).toEqual([]) - - expect(detectAgents).toHaveBeenCalledWith({ - enabledOnly: true, - projectRuntime: { - status: 'repair-required', - repair: { - projectId: 'repo-1', - preferredRuntime: { kind: 'wsl', distro: null }, - reason: 'wsl-distro-required', - source: 'global-default', - cacheKey: 'repo-1:repair:wsl-distro-required:default' - } - } - }) - }) - it('does not keep previous context agents when detection fails after a context switch', async () => { detectAgents .mockReset() @@ -196,28 +104,6 @@ describe('createDetectedAgentsSlice WSL context', () => { await expect(detected).resolves.toEqual([]) expect(store.getState().detectedAgentIds).toEqual([]) }) - - it('ignores in-flight local detection results after a project runtime switch', async () => { - let resolveDetection: (agents: string[]) => void = () => {} - detectAgents.mockReturnValueOnce( - new Promise((resolve) => { - resolveDetection = resolve - }) - ) - const store = createTestStore({ - repos: [makeRepo({ id: 'repo-1', path: 'C:\\repo' })], - activeRepoId: 'repo-1', - activeWorktreeId: null - }) - - const pending = store.getState().ensureDetectedAgents() - store.getState().clearLocalDetectedAgents() - resolveDetection(['claude']) - - await expect(pending).resolves.toEqual(['claude']) - expect(store.getState().detectedAgentIds).toBeNull() - expect(store.getState().isDetectingAgents).toBe(false) - }) }) describe('createDetectedAgentsSlice remote detection', () => { @@ -255,50 +141,6 @@ describe('createDetectedAgentsSlice remote detection', () => { }) }) - it('shares an in-flight SSH detection and publishes its settled inventory', async () => { - const store = createTestStore() - let resolveRemote: (ids: string[]) => void = () => {} - detectRemoteAgents.mockReturnValueOnce( - new Promise((resolve) => { - resolveRemote = resolve - }) - ) - - const first = store.getState().ensureRemoteDetectedAgents('ssh-1') - const second = store.getState().ensureRemoteDetectedAgents('ssh-1') - - expect(second).toBe(first) - - resolveRemote(['claude']) - - await expect(first).resolves.toEqual(['claude']) - await expect(second).resolves.toEqual(['claude']) - expect(store.getState().remoteDetectedAgentIds['ssh-1']).toEqual(['claude']) - - await expect(store.getState().ensureRemoteDetectedAgents('ssh-1')).resolves.toEqual(['claude']) - }) - - it('deduplicates concurrent SSH refreshes', async () => { - const store = createTestStore() - store.setState({ remoteDetectedAgentIds: { 'ssh-1': ['claude'] } } as Partial) - let resolveRemote: (ids: string[]) => void = () => {} - detectRemoteAgents.mockReturnValueOnce( - new Promise((resolve) => { - resolveRemote = resolve - }) - ) - - const first = store.getState().refreshRemoteDetectedAgents('ssh-1') - const second = store.getState().refreshRemoteDetectedAgents('ssh-1') - - expect(second).toBe(first) - expect(store.getState().remoteDetectedAgentIds['ssh-1']).toEqual(['claude']) - - resolveRemote(['codex']) - await expect(first).resolves.toEqual(['codex']) - expect(store.getState().remoteDetectedAgentIds['ssh-1']).toEqual(['codex']) - }) - it('does not restore an SSH cache entry after it is cleared mid-detection', async () => { const store = createTestStore() let resolveRemote: (ids: string[]) => void = () => {} @@ -331,42 +173,6 @@ describe('createDetectedAgentsSlice remote detection', () => { expect(store.getState().remoteDetectedAgentIds['ssh-1']).toEqual(['kilo']) }) - it('re-runs runtime detection after an empty result instead of pinning it', async () => { - const store = createTestStore() - // Runtime Orca-serve path must retry empty detection after install/PATH fixes too, independently of SSH. - let detectCalls = 0 - runtimeEnvironmentCall.mockImplementation(({ method }: { method: string }) => { - let result: unknown - if (method === 'status.get') { - result = { - runtimeId: 'remote-runtime', - rendererGraphEpoch: 1, - graphStatus: 'ready', - authoritativeWindowId: null, - liveTabCount: 0, - liveLeafCount: 0, - runtimeProtocolVersion: RUNTIME_PROTOCOL_VERSION, - minCompatibleRuntimeClientVersion: MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION - } - } else { - detectCalls += 1 - result = detectCalls === 1 ? [] : ['kilo'] - } - return Promise.resolve({ - id: method, - ok: true, - result, - _meta: { runtimeId: 'remote-runtime' } - }) - }) - - await expect(store.getState().ensureRuntimeDetectedAgents('env-1')).resolves.toEqual([]) - expect(store.getState().runtimeDetectedAgentIds['env-1']).toEqual([]) - - await expect(store.getState().ensureRuntimeDetectedAgents('env-1')).resolves.toEqual(['kilo']) - expect(store.getState().runtimeDetectedAgentIds['env-1']).toEqual(['kilo']) - }) - it('keeps a late initial detect from overwriting a runtime refresh', async () => { const store = createTestStore() let resolveDetect: (value: unknown) => void = () => {} diff --git a/src/renderer/src/store/slices/agent-inventory/local-detected-agent-state.test.ts b/src/renderer/src/store/slices/agent-inventory/local-detected-agent-state.test.ts index 015e9f51ea9..9142e5a3370 100644 --- a/src/renderer/src/store/slices/agent-inventory/local-detected-agent-state.test.ts +++ b/src/renderer/src/store/slices/agent-inventory/local-detected-agent-state.test.ts @@ -192,45 +192,6 @@ describe('local detected agent context lifecycle', () => { expect(store.getState().isRefreshingAgents).toBe(false) }) - it('successful full refresh settles both modes with detects finishing first', async () => { - const store = createTestStore([]) - const enabledDetection = Promise.withResolvers() - const fullDetection = Promise.withResolvers() - const fullRefresh = Promise.withResolvers<{ agents: string[] }>() - detectAgents - .mockReturnValueOnce(enabledDetection.promise) - .mockReturnValueOnce(fullDetection.promise) - refreshAgents.mockReturnValueOnce(fullRefresh.promise) - const enabled = store.getState().ensureDetectedAgents() - const full = store.getState().ensureAllDetectedAgents() - const refreshed = store.getState().refreshAllDetectedAgents() - - expect(store.getState().isDetectingAgents).toBe(false) - expect(store.getState().isDetectingLocalAgentsByContext).toEqual({}) - expect(store.getState().isRefreshingLocalAgentsByContext).toEqual({ - host: true, - 'host\u0000all-agents': true - }) - const finishDetections = async () => { - enabledDetection.resolve(['claude']) - fullDetection.resolve(['claude', 'kiro']) - await Promise.all([enabled, full]) - } - await finishDetections() - expect(store.getState().isRefreshingAgents).toBe(true) - fullRefresh.resolve({ agents: ['codex', 'kiro'] }) - await refreshed - - expect(store.getState().localDetectedAgentIdsByContext).toEqual({ - host: ['codex', 'kiro'], - 'host\u0000all-agents': ['codex', 'kiro'] - }) - expect(store.getState().isDetectingLocalAgentsByContext).toEqual({}) - expect(store.getState().isRefreshingLocalAgentsByContext).toEqual({}) - expect(store.getState().isDetectingAgents).toBe(false) - expect(store.getState().isRefreshingAgents).toBe(false) - }) - it('failed full refresh settles both modes with detects finishing last', async () => { const store = createTestStore([]) const enabledDetection = Promise.withResolvers() @@ -269,45 +230,6 @@ describe('local detected agent context lifecycle', () => { expect(store.getState().isRefreshingAgents).toBe(false) }) - it('failed full refresh settles both modes with detects finishing first', async () => { - const store = createTestStore([]) - const enabledDetection = Promise.withResolvers() - const fullDetection = Promise.withResolvers() - const fullRefresh = Promise.withResolvers<{ agents: string[] }>() - detectAgents - .mockReturnValueOnce(enabledDetection.promise) - .mockReturnValueOnce(fullDetection.promise) - refreshAgents.mockReturnValueOnce(fullRefresh.promise) - const enabled = store.getState().ensureDetectedAgents() - const full = store.getState().ensureAllDetectedAgents() - const refreshed = store.getState().refreshAllDetectedAgents() - - expect(store.getState().isDetectingAgents).toBe(false) - expect(store.getState().isDetectingLocalAgentsByContext).toEqual({}) - expect(store.getState().isRefreshingLocalAgentsByContext).toEqual({ - host: true, - 'host\u0000all-agents': true - }) - const finishDetections = async () => { - enabledDetection.resolve(['claude']) - fullDetection.resolve(['claude', 'kiro']) - await Promise.all([enabled, full]) - } - await finishDetections() - expect(store.getState().isRefreshingAgents).toBe(true) - fullRefresh.reject(new Error('shell unavailable')) - await refreshed - - expect(store.getState().localDetectedAgentIdsByContext).toEqual({ - host: [], - 'host\u0000all-agents': [] - }) - expect(store.getState().isDetectingLocalAgentsByContext).toEqual({}) - expect(store.getState().isRefreshingLocalAgentsByContext).toEqual({}) - expect(store.getState().isDetectingAgents).toBe(false) - expect(store.getState().isRefreshingAgents).toBe(false) - }) - it('publishes a complete refresh to automatic readers without letting their late probe overwrite it', async () => { const store = createTestStore([]) store.setState({ settings: { ...store.getState().settings!, disabledTuiAgents: ['kiro'] } }) @@ -375,34 +297,6 @@ describe('local detected agent context lifecycle', () => { expect(store.getState().isRefreshingLocalAgentsByContext).toEqual({}) }) - it('deduplicates Floating-first callers without cached or settlement broadcast fanout', async () => { - let resolveDetection: (agents: string[]) => void = () => {} - detectAgents.mockReturnValueOnce( - new Promise((resolve) => { - resolveDetection = resolve - }) - ) - const store = createTestStore([]) - const listener = vi.fn() - const unsubscribe = store.subscribe(listener) - - const floating = store.getState().ensureDetectedAgents(FLOATING_TERMINAL_WORKTREE_ID) - const ordinary = store.getState().ensureDetectedAgents() - const joinedOrdinary = store.getState().ensureDetectedAgents() - - expect(ordinary).toBe(floating) - expect(joinedOrdinary).toBe(floating) - resolveDetection(['codex']) - await Promise.all([floating, ordinary, joinedOrdinary]) - expect(store.getState().detectedAgentIds).toEqual(['codex']) - - listener.mockClear() - await store.getState().ensureDetectedAgents() - await store.getState().ensureDetectedAgents() - expect(listener).not.toHaveBeenCalled() - unsubscribe() - }) - it('keeps native provider inventory across WSL selection and refresh', async () => { const store = createTestStore([makeRepo('repo-1')]) const projects = store.getState().projects