Skip to content

The agent that grows with you

test: trim salvage tests to invariants

teknium16fa17e872867
diff --git a/apps/desktop/src/app/model-picker-overlay.test.tsx b/apps/desktop/src/app/model-picker-overlay.test.tsx
deleted file mode 100644
index 347fa6b8c64..00000000000
--- a/apps/desktop/src/app/model-picker-overlay.test.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
-import type { WritableAtom } from 'nanostores'
-import { afterEach, expect, it, vi } from 'vitest'
-
-import { I18nProvider } from '@/i18n'
-import { requestModelOptions } from '@/lib/model-options'
-import { startManualOnboarding } from '@/store/onboarding'
-import { $gatewayState, $modelPickerOpen, $selectedStoredSessionId } from '@/store/session'
-import { $focusedTreePaneId as $focusedTreePaneIdMock } from '@/store/session-focus'
-import { $sessionTiles } from '@/store/session-states'
-import { stubMenuDomApis, stubResizeObserver } from '@/test/jsdom'
-
-import { ModelPickerOverlay } from './model-picker-overlay'
-
-// The mock below replaces the computed store with a writable atom.
-const $focusedTreePaneId = $focusedTreePaneIdMock as unknown as WritableAtom<null | string>
-
-vi.mock('@/store/session-focus', async () => {
- const { atom } = await import('nanostores')
-
- return { $focusedTreePaneId: atom<null | string>(null) }
-})
-vi.mock('@/hermes', async importOriginal => ({
- ...(await importOriginal<Record<string, unknown>>()),
- getLocalModelsStatus: vi.fn().mockResolvedValue({ loading: {} })
-}))
-vi.mock('@/lib/model-options', async importOriginal => ({
- ...(await importOriginal<Record<string, unknown>>()),
- requestModelOptions: vi.fn().mockResolvedValue({ model: '', provider: '', providers: [] })
-}))
-vi.mock('@/store/onboarding', async importOriginal => ({
- ...(await importOriginal<Record<string, unknown>>()),
- startManualOnboarding: vi.fn()
-}))
-
-stubResizeObserver()
-stubMenuDomApis()
-
-afterEach(() => {
- cleanup()
- vi.clearAllMocks()
- $sessionTiles.set([])
- $focusedTreePaneId.set(null)
- $selectedStoredSessionId.set(null)
- $modelPickerOpen.set(false)
- $gatewayState.set('idle')
-})
-
-it('reads the catalog from the backend profile but hands the Desktop alias to provider setup', async () => {
- $gatewayState.set('open')
- $modelPickerOpen.set(true)
- $selectedStoredSessionId.set('primary-a')
- $sessionTiles.set([
- {
- ownerRoute: { connectionId: 'connection-b', profile: 'desktop-b', targetProfile: 'backend-b' },
- storedSessionId: 'tile-b'
- }
- ])
- $focusedTreePaneId.set('session-tile:tile-b')
- const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
-
- render(
- <QueryClientProvider client={client}>
- <I18nProvider>
- <ModelPickerOverlay
- onSelect={() => undefined}
- ownerConnectionId="connection-a"
- profile="default"
- requestGateway={async () => undefined as never}
- />
- </I18nProvider>
- </QueryClientProvider>
- )
-
- await waitFor(() => expect(requestModelOptions).toHaveBeenCalled())
- expect(vi.mocked(requestModelOptions).mock.calls.every(([options]) => options.profile === 'backend-b')).toBe(true)
-
- fireEvent.click(await screen.findByRole('button', { name: 'Add provider' }))
- expect(startManualOnboarding).toHaveBeenCalledWith(undefined, { connectionId: 'connection-b', profile: 'desktop-b' })
- client.clear()
-})
diff --git a/apps/desktop/src/components/onboarding/connection-owner.test.tsx b/apps/desktop/src/components/onboarding/connection-owner.test.tsx
deleted file mode 100644
index 35bddedbd0d..00000000000
--- a/apps/desktop/src/components/onboarding/connection-owner.test.tsx
+++ /dev/null
@@ -1,243 +0,0 @@
-import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
-import { afterEach, expect, it, vi } from 'vitest'
-
-import { setApiRequestConnection, setApiRequestProfile } from '@/api/client'
-import { startOAuthLogin } from '@/api/config'
-import type { HermesApiRequest } from '@/global'
-import type * as HermesApi from '@/hermes'
-import {
- closeSecondaryGateways,
- configureGatewayRegistry,
- ensureGatewayForAgent,
- requestGatewayForAgent,
- setPrimaryGateway,
- setPrimaryGatewayConnection
-} from '@/store/gateway'
-import type * as OnboardingStore from '@/store/onboarding'
-import {
- $desktopOnboarding,
- closeManualOnboarding,
- type OnboardingContext,
- startManualProviderOAuth
-} from '@/store/onboarding'
-import { stubMenuDomApis, stubResizeObserver } from '@/test/jsdom'
-import { makeOAuthProvider } from '@/test/oauth-provider'
-
-import { FlowPanel } from './flow'
-
-import { DesktopOnboardingOverlay } from '.'
-
-stubResizeObserver()
-stubMenuDomApis()
-
-// Boundary test: real overlay/API helpers/gateway router; no OAuth
-// account or production backend. Intercept acquisition to inspect its context.
-const mocks = vi.hoisted(() => ({
- begin: vi.fn(),
- rpc: vi.fn(async () => ({ ok: true }))
-}))
-
-vi.mock('@/store/onboarding', async importOriginal => ({
- ...(await importOriginal<typeof OnboardingStore>()),
- startProviderOAuth: mocks.begin
-}))
-vi.mock('@/hermes', async importOriginal => ({
- ...(await importOriginal<typeof HermesApi>()),
- HermesGateway: class {
- connectionState = 'closed'
- connect = async () => {
- this.connectionState = 'open'
- }
- request = mocks.rpc
- close = () => {
- this.connectionState = 'closed'
- }
- onEvent = () => () => {}
- onState = () => () => {}
- }
-}))
-vi.mock('@/store/notify-baseline', () => ({ markNativeNotifyBaseline: vi.fn() }))
-
-const provider = { ...makeOAuthProvider('openai-codex'), flow: 'device_code' as const }
-
-afterEach(() => {
- cleanup()
- closeManualOnboarding()
- closeSecondaryGateways()
- setApiRequestConnection(null)
- setApiRequestProfile(null)
- vi.clearAllMocks()
- delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
-})
-
-it.each([
- { profile: 'leverage-ai', sharedRemote: true },
- { profile: 'custom', sharedRemote: true },
- { profile: 'mara', sharedRemote: false }
-])('keeps Settings readiness on its owner ($profile, shared=$sharedRemote)', async ({ profile, sharedRemote }) => {
- const localRequest = vi.fn(async () => ({ ok: true }))
-
- const localDial = vi.fn(async () => {
- throw new Error('Diagnostic local backend has no remote-only profile')
- })
-
- const remoteDial = vi.fn(async ({ connectionId, profile: routeProfile }) => ({
- connectionId,
- profile: routeProfile,
- sharedRemote,
- ...(sharedRemote ? {} : { remoteKind: 'ssh', remoteProfile: 'remote-research' }),
- mode: 'remote',
- authMode: 'token',
- baseUrl: 'https://athena.invalid',
- wsUrl: 'wss://athena.invalid/api/ws',
- token: 'fixture-only'
- }))
-
- const api = vi.fn(async () => ({ providers: [provider] }))
- Object.defineProperty(window, 'hermesDesktop', {
- configurable: true,
- value: {
- api,
- getConnection: localDial,
- getConnectionFor: remoteDial,
- touchBackend: vi.fn(async () => undefined)
- }
- })
- configureGatewayRegistry({ onEvent: vi.fn() })
- setPrimaryGateway({ connectionState: 'open', request: localRequest } as never, 'default')
- setPrimaryGatewayConnection({ connectionId: 'local' })
- await ensureGatewayForAgent('athena', profile)
- setApiRequestConnection('athena')
- setApiRequestProfile(profile)
- localDial.mockClear()
-
- await act(async () => {
- startManualProviderOAuth('openai-codex', profile)
- })
- render(
- <DesktopOnboardingOverlay
- enabled={false}
- profile={profile}
- requestGateway={(method, params) => requestGatewayForAgent('athena', profile, method, params)}
- />
- )
- await waitFor(() => expect(mocks.begin).toHaveBeenCalledOnce())
- const context = mocks.begin.mock.calls[0][1] as OnboardingContext
-
- // Switching the foreground device must not retarget a pending setup.
- setApiRequestConnection('local')
- setApiRequestProfile('default')
- await startOAuthLogin('openai-codex', context.scope)
- expect(api).toHaveBeenLastCalledWith(
- expect.objectContaining({
- connectionId: 'athena',
- profile,
- path: '/api/providers/oauth/openai-codex/start'
- })
- )
- await context.requestGateway('setup.status')
- await context.requestGateway('setup.runtime_check', { provider: 'openai-codex' })
- await context.requestGateway('model.options', { profile, explicit_only: true })
- const params = sharedRemote ? { profile } : {}
- expect(mocks.rpc).toHaveBeenCalledWith('setup.status', params)
- expect(localDial).not.toHaveBeenCalled()
- expect(mocks.rpc).toHaveBeenCalledWith('setup.runtime_check', { provider: 'openai-codex', ...params })
- expect(mocks.rpc).toHaveBeenCalledWith('model.options', { explicit_only: true, ...params })
- expect(localRequest).not.toHaveBeenCalled()
-})
-
-it('keeps an explicitly untagged owner through Change → Add provider', async () => {
- const owner = { connectionId: null, profile: 'legacy' }
- const api = vi.fn(async (_request: HermesApiRequest) => ({ providers: [] }))
- Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: { api } })
- startManualProviderOAuth('openai-codex', owner)
- setApiRequestConnection('athena')
- setApiRequestProfile('default')
- const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
-
- render(
- <QueryClientProvider client={client}>
- <FlowPanel
- ctx={{ scope: owner, profile: owner.profile, requestGateway: async () => ({ providers: [] }) as never }}
- flow={{
- status: 'confirming_model',
- currentModel: 'fixture-model',
- providerSlug: 'openai-codex',
- label: 'Codex',
- saving: false
- }}
- leaving={false}
- onBegin={() => undefined}
- />
- </QueryClientProvider>
- )
- fireEvent.click(screen.getByRole('button', { name: 'Change' }))
- fireEvent.click(await screen.findByRole('button', { name: 'Add provider' }))
- expect($desktopOnboarding.get().targetScope).toEqual(owner)
- await waitFor(() =>
- expect(api).toHaveBeenCalledWith(expect.objectContaining({ path: '/api/providers/oauth', profile: 'legacy' }))
- )
- expect(api.mock.calls.every(([request]) => !(request as { connectionId?: string }).connectionId)).toBe(true)
- client.clear()
-})
-
-it.each([null, undefined])('pins a registry owner when its profile is %s', async profile => {
- const localRequest = vi.fn(async (_method: string, _params?: Record<string, unknown>) => ({ ok: true }))
-
- const localDial = vi.fn(async () => {
- throw new Error('A registry-owned setup must not dial the legacy connection')
- })
-
- const remoteDial = vi.fn(async () => ({
- connectionId: 'athena',
- profile: 'default',
- sharedRemote: true,
- mode: 'remote',
- authMode: 'token',
- baseUrl: 'https://athena.invalid',
- wsUrl: 'wss://athena.invalid/api/ws',
- token: 'fixture-only'
- }))
-
- const api = vi.fn(async () => ({ providers: [provider] }))
- Object.defineProperty(window, 'hermesDesktop', {
- configurable: true,
- value: {
- api,
- getConnection: localDial,
- getConnectionFor: remoteDial,
- touchBackend: vi.fn(async () => undefined)
- }
- })
- configureGatewayRegistry({ onEvent: vi.fn() })
- setPrimaryGateway({ connectionState: 'open', request: localRequest } as never, 'default')
- setPrimaryGatewayConnection({ connectionId: 'local' })
- setApiRequestConnection('local')
- setApiRequestProfile('default')
-
- await act(async () => {
- startManualProviderOAuth('openai-codex', { connectionId: 'athena', profile })
- })
- render(
- <DesktopOnboardingOverlay
- enabled={false}
- profile="default"
- requestGateway={async (method, params) => (await localRequest(method, params)) as never}
- />
- )
- await waitFor(() => expect(mocks.begin).toHaveBeenCalledOnce())
- const context = mocks.begin.mock.calls[0][1] as OnboardingContext
-
- await startOAuthLogin('openai-codex', context.scope)
- expect(api).toHaveBeenLastCalledWith(
- expect.objectContaining({ connectionId: 'athena', path: '/api/providers/oauth/openai-codex/start' })
- )
- await context.requestGateway('setup.status')
- await context.requestGateway('setup.runtime_check', { provider: 'openai-codex' })
- expect(remoteDial).toHaveBeenCalledWith({ connectionId: 'athena', profile: 'default' })
- expect(mocks.rpc).toHaveBeenCalledWith('setup.status', { profile: 'default' })
- expect(mocks.rpc).toHaveBeenCalledWith('setup.runtime_check', { provider: 'openai-codex', profile: 'default' })
- expect(localDial).not.toHaveBeenCalled()
- expect(localRequest).not.toHaveBeenCalled()
-})
diff --git a/apps/desktop/src/store/onboarding-scope.test.ts b/apps/desktop/src/store/onboarding-scope.test.ts
deleted file mode 100644
index f7e9e662ef1..00000000000
--- a/apps/desktop/src/store/onboarding-scope.test.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { afterEach, expect, it, vi } from 'vitest'
-
-import { isTimeoutError, RECONNECT_ATTEMPT_TIMEOUT_MS } from '@/lib/with-timeout'
-
-import { requestOnboardingGateway } from './onboarding-scope'
-
-const mocks = vi.hoisted(() => ({ request: vi.fn(async () => ({ ok: true })) }))
-
-vi.mock('@/store/gateway', () => ({ requestGatewayForAgent: mocks.request }))
-
-const owner = { connectionId: 'athena', profile: 'leverage-ai' }
-
-function installDesktop(bridge: Record<string, unknown>) {
- const getConnection = vi.fn(async () => ({ sharedPrimary: true }))
- Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: { getConnection, ...bridge } })
-
- return getConnection
-}
-
-afterEach(() => {
- vi.useRealTimers()
- vi.clearAllMocks()
- delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
-})
-
-// Each failure must surface without sending the RPC anywhere, and without
-// falling back to the profile-only resolver that would pick another device.
-it('rejects a registry owner on a bridge that cannot dial registry connections', async () => {
- const getConnection = installDesktop({})
-
- await expect(requestOnboardingGateway(owner, 'setup.runtime_check')).rejects.toThrow(/Update Hermes Desktop/)
- expect(getConnection).not.toHaveBeenCalled()
- expect(mocks.request).not.toHaveBeenCalled()
-})
-
-it('surfaces a removed registry connection instead of retargeting setup', async () => {
- const getConnectionFor = vi.fn(async () => {
- throw new Error('No connection with id "athena"')
- })
-
- const getConnection = installDesktop({ getConnectionFor })
-
- await expect(requestOnboardingGateway(owner, 'setup.runtime_check')).rejects.toThrow('No connection with id "athena"')
- expect(getConnectionFor).toHaveBeenCalledWith({ connectionId: 'athena', profile: 'leverage-ai' })
- expect(getConnection).not.toHaveBeenCalled()
- expect(mocks.request).not.toHaveBeenCalled()
-})
-
-it('times out a wedged connection lookup', async () => {
- vi.useFakeTimers()
- const getConnectionFor = vi.fn(() => new Promise(() => undefined))
- const getConnection = installDesktop({ getConnectionFor })
- const pending = requestOnboardingGateway(owner, 'setup.runtime_check').catch((error: unknown) => error)
-
- await vi.advanceTimersByTimeAsync(RECONNECT_ATTEMPT_TIMEOUT_MS)
- const error = await pending
-
- expect(isTimeoutError(error)).toBe(true)
- expect((error as Error).message).toBe('Timed out resolving provider setup for "leverage-ai"')
- expect(getConnection).not.toHaveBeenCalled()
- expect(mocks.request).not.toHaveBeenCalled()
-})
-
-it('surfaces a failed legacy lookup for an untagged owner', async () => {
- const getConnection = vi.fn(async () => {
- throw new Error('Profile "legacy" is unavailable')
- })
-
- installDesktop({ getConnection, getConnectionFor: vi.fn() })
-
- await expect(requestOnboardingGateway({ connectionId: null, profile: 'legacy' }, 'setup.status')).rejects.toThrow(
- 'Profile "legacy" is unavailable'
- )
- expect(getConnection).toHaveBeenCalledWith('legacy')
- expect(mocks.request).not.toHaveBeenCalled()
-})