Resolve model menu validation failures

This commit is contained in:
Brennan Benson
2026-11-09 06:52:08 -08:00
parent b393abd1aa
commit fb8eae54fa
17 changed files with 115 additions and 85 deletions
@@ -63,13 +63,13 @@ export function registerFilesystemGitModelDiscoveryHandlers(
return { success: false, error: localEnv.error }
}
return localDiscoveryOptions
? discoverCommitMessageModelsLocal(
? await discoverCommitMessageModelsLocal(
agentId as TuiAgent,
localEnv.env,
agentCommandOverride,
localDiscoveryOptions
)
: discoverCommitMessageModelsLocal(
: await discoverCommitMessageModelsLocal(
agentId as TuiAgent,
localEnv.env,
agentCommandOverride
@@ -1,20 +1,15 @@
import type { DiscoveryIO } from './terminal-model-discovery.test-fixture'
import { expect, it, vi } from 'vitest'
const io = vi.hoisted(() => ({
const io = vi.hoisted<DiscoveryIO>(() => ({
generateCommit: vi.fn(),
generatePr: vi.fn(),
handle: vi.fn(),
env: vi.fn(),
discover: vi.fn(),
materialize: vi.fn(),
distros: ['Ubuntu'] as string[],
distros: ['Ubuntu'],
distrosKnown: false,
rows: [] as {
path: string
head: string
branch: string
isBare: boolean
isMainWorktree: boolean
}[],
rows: [],
mutations: vi.fn(),
userAct: vi.fn()
}))
@@ -1,20 +1,16 @@
import { GitDiscoverCommitMessageModels } from '../../../shared/rpc-contract/git-params'
import type { DiscoveryIO } from './terminal-model-discovery.test-fixture'
import { expect, it, vi } from 'vitest'
const io = vi.hoisted(() => ({
const io = vi.hoisted<DiscoveryIO>(() => ({
generateCommit: vi.fn(),
generatePr: vi.fn(),
handle: vi.fn(),
env: vi.fn(),
discover: vi.fn(),
materialize: vi.fn(),
distros: ['Ubuntu'] as string[],
distros: ['Ubuntu'],
distrosKnown: false,
rows: [] as {
path: string
head: string
branch: string
isBare: boolean
isMainWorktree: boolean
}[],
rows: [],
mutations: vi.fn(),
userAct: vi.fn()
}))
@@ -90,12 +86,17 @@ it('keeps terminal Ubuntu inventory separate from native Git discovery and commi
})
expect(await rig.rpc()).toMatchObject({ models: [{ id: 'ubuntu-model' }] })
const git = GIT_COMMIT_MESSAGE_GENERATION_METHODS.find(
({ name }) => name === 'git.discoverCommitMessageModels'
(
method
): method is Extract<
(typeof GIT_COMMIT_MESSAGE_GENERATION_METHODS)[number],
{ params: typeof GitDiscoverCommitMessageModels }
> => method.params === GitDiscoverCommitMessageModels
)!
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: each method reads the real runtime; dispatcher context ports are not needed.
const context = { runtime: rig.runtime } as never
expect(
await git.handler({ worktree: rig.selector, agentId: 'antigravity' } as never, context)
await git.handler({ worktree: rig.selector, agentId: 'antigravity' }, context)
).toMatchObject({ success: true, models: [{ id: 'native-model' }] })
const override = {
sourceControlAiResolvedParams: {
@@ -135,10 +136,10 @@ it('settles a terminal repair refusal before preparing an environment or probing
io.distros = []
expect(await rig.ipc()).toMatchObject({ success: false })
const target = await rig.runtime.resolveTerminalWorkspaceReadTarget(rig.selector)
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture supplies the real launch resolver's store reads.
expect(() =>
resolveAgentLaunchRuntime(rig.store as never, target.scope, undefined, 'antigravity')
).toThrow('No agent was started.')
expect(() => {
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this read-port fixture supplies the launch resolver's store reads, as for the real runtime constructor.
return resolveAgentLaunchRuntime(rig.store as never, target.scope, undefined, 'antigravity')
}).toThrow('No agent was started.')
expect(io.env).not.toHaveBeenCalled()
expect(io.discover).not.toHaveBeenCalled()
})
@@ -1,20 +1,15 @@
import type { DiscoveryIO } from './terminal-model-discovery.test-fixture'
import { expect, it, vi } from 'vitest'
const io = vi.hoisted(() => ({
const io = vi.hoisted<DiscoveryIO>(() => ({
generateCommit: vi.fn(),
generatePr: vi.fn(),
handle: vi.fn(),
env: vi.fn(),
discover: vi.fn(),
materialize: vi.fn(),
distros: ['Ubuntu'] as string[],
distros: ['Ubuntu'],
distrosKnown: false,
rows: [] as {
path: string
head: string
branch: string
isBare: boolean
isMainWorktree: boolean
}[],
rows: [],
mutations: vi.fn(),
userAct: vi.fn()
}))
@@ -6,7 +6,7 @@ import { registerTerminalModelDiscoveryHandler } from '../terminal-model-discove
import { AGENT_MODEL_DISCOVERY_METHODS } from '../../runtime/rpc/methods/terminal/agent-model-discovery'
export const FOLDER_ID = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb'
type DiscoveryIO = {
export type DiscoveryIO = {
generateCommit: Mock
generatePr: Mock
handle: Mock
@@ -81,7 +81,7 @@ export async function discoverTerminalModels(
if (!env.ok) {
return { success: false, error: env.error }
}
return discoverCommitMessageModelsLocal(
return await discoverCommitMessageModelsLocal(
agentId,
env.env,
context.store.getSettings().agentCmdOverrides?.[agentId],
@@ -5,16 +5,13 @@ import { afterEach, expect, it, vi } from 'vitest'
import { sourceEntry } from './agent-launch-picker-sources.test-fixture'
import {
agentPickerDraft,
agentPickerFreshLaunchInputs
agentPickerFreshLaunchInputs,
agentPickerLaunchInputs
} from '../../../../shared/agent-launch/picker/agent-launch-picker'
import { AgentLaunchPicker } from './AgentLaunchPicker'
import { TooltipProvider } from '@/components/ui/tooltip'
import { useAppStore } from '@/store'
import { getDefaultSettings } from '../../../../shared/constants'
import {
agentPickerLaunchInputs,
type AgentPickerDraft
} from '../../../../shared/agent-launch/picker/agent-launch-picker'
const mocks = vi.hoisted(() => ({ call: vi.fn() }))
vi.mock('@/runtime/native-chat/requests/structured-agent-session-call', () => ({
callStructuredAgentSession: mocks.call
@@ -70,12 +67,17 @@ it.each(['codex', 'pi'] as const)(
refresh: async () => [agent]
}
}}
onPick={(_agent, draft) => picks.push(agentPickerLaunchInputs(draft as AgentPickerDraft))}
onPick={(_agent, draft) => {
if (!draft) {
throw new Error('Expected a model setup draft')
}
picks.push(agentPickerLaunchInputs(draft))
}}
/>
</TooltipProvider>
)
await userEvent.setup().click(screen.getByRole('button', { name: 'Select agent' }))
const search = await screen.findByPlaceholderText('Search agents and setups…')
const search = await screen.findByRole('textbox')
fireEvent.change(search, { target: { value: 'Account model' } })
await waitFor(() =>
expect(screen.getByRole('menuitem', { name: /Account model/ })).toBeTruthy()
@@ -123,7 +125,7 @@ it('searches a terminal dialog preset with a chat-default entry and launches its
</TooltipProvider>
)
await userEvent.setup().click(screen.getByRole('button', { name: 'Select agent' }))
fireEvent.change(await screen.findByPlaceholderText('Search agents and setups…'), {
fireEvent.change(await screen.findByRole('textbox'), {
target: { value: 'Flash Low' }
})
fireEvent.click(await screen.findByRole('menuitem', { name: /Gemini 3.8 Flash \(Low\)/ }))
@@ -3,7 +3,10 @@ import {
withAgentPickerCatalogAvailability,
agentPickerCatalogJobs
} from './agent-picker-catalog-jobs'
import { agentPickerModelMenu } from '../../../../shared/agent-launch/picker/agent-launch-picker-catalog'
import {
agentPickerModelMenu,
agentPickerModels
} from '../../../../shared/agent-launch/picker/agent-launch-picker-catalog'
import { beforeEach, expect, it, vi } from 'vitest'
const mocks = vi.hoisted(() => ({ discover: vi.fn(), structured: vi.fn() }))
vi.mock('@/runtime/native-chat/model-catalogs/terminal-model-discovery-client', () => ({
@@ -14,14 +17,13 @@ vi.mock('@/runtime/native-chat/requests/structured-agent-session-call', () => ({
}))
import { agentPickerModelCatalogReads } from './agent-launch-picker-host-reads'
import { cliModelCatalogAnswer } from '@/runtime/native-chat/model-catalogs/model-menu-cli-catalog'
import { resetHostModelCatalogSnapshotsForTests } from '@/runtime/native-chat/model-catalogs/host-model-catalog-snapshots'
import {
resetHostModelCatalogSnapshotsForTests,
forgetHostModelCatalogSnapshots,
recordHostModelCatalogSnapshot,
subscribeHostModelCatalogSnapshot
} from '@/runtime/native-chat/model-catalogs/host-model-catalog-snapshots'
import { projectAgentLaunchProfile } from '../../../../shared/agent-launch/choices/agent-launch-profile'
import { agentPickerModels } from '../../../../shared/agent-launch/picker/agent-launch-picker-catalog'
import { cliResult, sourceEntry } from './agent-launch-picker-sources.test-fixture'
beforeEach(() => {
@@ -1,3 +1,7 @@
import {
NewSessionResponseSchema,
SessionModelStateSchema
} from '../../../../main/acp/generated/acp-protocol.generated'
import recording from '../../../../main/acp/fixtures/antigravity-v1.4.3-options.json'
import { AcpStructuredOptions } from '../../../../main/acp/options/acp-structured-options'
import { parseAntigravityModels } from '../../../../shared/source-control/ai/generation/commit-message-model-parsers'
@@ -20,11 +24,10 @@ export function sourceEntry(
defaultSurface: AgentPickerEntry['defaultSurface'] = 'chat'
): AgentPickerEntry {
const options = new AcpStructuredOptions()
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: recorded ACP JSON has the protocol's select discriminator values.
options.adoptSession(
recording.session as Parameters<AcpStructuredOptions['adoptSession']>[0],
'new'
const session = NewSessionResponseSchema.extend({ models: SessionModelStateSchema }).parse(
recording.session
)
options.adoptSession(session, 'new')
return {
agent: 'antigravity',
label: 'Antigravity',
@@ -1,7 +1,14 @@
// @vitest-environment happy-dom
import { act, renderHook, render, fireEvent, screen, waitFor } from '@testing-library/react'
import {
act,
renderHook,
render,
fireEvent,
screen,
waitFor,
cleanup
} from '@testing-library/react'
import { afterEach, expect, it, vi } from 'vitest'
import { cleanup } from '@testing-library/react'
import { useState } from 'react'
import type { AgentDedicatedChoices } from '../../../../../shared/agent-launch/choices/agent-launch-choices'
const mocks = vi.hoisted(() => ({ call: vi.fn() }))
@@ -135,8 +142,7 @@ it('keeps options-only effort editable through pinning and clearing the model',
)
}
render(<Editor />)
const effort = () =>
screen.getByRole('combobox', { name: 'Reasoning effort' }) as HTMLSelectElement
const effort = () => screen.getByRole<HTMLSelectElement>('combobox', { name: 'Reasoning effort' })
expect(effort().value).toBe('high')
fireEvent.change(effort(), { target: { value: 'medium' } })
expect(changed).toHaveBeenLastCalledWith({ options: { effort: 'medium' } })
@@ -272,7 +278,7 @@ it.each(['live', 'empty', 'saved-empty'] as const)(
onChange={change}
/>
)
const model = screen.getByRole('combobox', { name: 'Model' }) as HTMLSelectElement
const model = screen.getByRole<HTMLSelectElement>('combobox', { name: 'Model' })
expect([...model.options].map(({ value }) => value)).toEqual([
'__agent_default__',
...(kind === 'live' ? ['gpt-6.1-sol'] : saved ? ['old-only'] : [])
@@ -280,7 +286,7 @@ it.each(['live', 'empty', 'saved-empty'] as const)(
expect(model.value).toBe(saved ? 'old-only' : '__agent_default__')
expect(screen.queryByRole('note')).toBeNull()
if (saved) {
const effort = screen.getByRole('combobox', { name: 'Reasoning effort' }) as HTMLSelectElement
const effort = screen.getByRole<HTMLSelectElement>('combobox', { name: 'Reasoning effort' })
expect(effort.value).toBe('ultra')
expect(effort.disabled).toBe(true)
expect(hook.result.current.descriptors.find(({ id }) => id === 'effort')).toMatchObject({
@@ -6,8 +6,8 @@ import { cliModelMenuScope } from '@/runtime/native-chat/model-catalogs/model-me
import { resetHostModelCatalogSnapshotsForTests } from '@/runtime/native-chat/model-catalogs/host-model-catalog-snapshots'
import { cliResult } from '../agent-launch-picker-sources.test-fixture'
const mocks = vi.hoisted(() => ({ discover: vi.fn() }))
vi.mock('@/runtime/source-control/git/runtime-git-generation-client', () => ({
discoverRuntimeCommitMessageModels: mocks.discover
vi.mock('@/runtime/native-chat/model-catalogs/terminal-model-discovery-client', () => ({
discoverRuntimeTerminalModels: mocks.discover
}))
vi.mock('./AgentChoiceMenu', () => ({
AgentChoiceMenu: (props: {
@@ -1,5 +1,5 @@
import type { ModelCatalogSource } from '../../../../../shared/agent-session/options/model-catalog-source'
import { useCallback, useEffect, useMemo } from 'react'
import { useCallback, useEffect } from 'react'
import {
useAppStateViewActive,
useAppViewExternalStore
@@ -13,7 +13,6 @@ import { modelMenuOptions } from '../../../../../shared/agent-session/options/mo
import { getAgentSessionOptionLaunchCatalog } from '../../../../../shared/agent-session/options/agent-session-option-catalog'
import type { TuiAgent } from '../../../../../shared/agent-launch/catalog/tui-agent'
import type { AgentDedicatedChoices } from '../../../../../shared/agent-launch/choices/agent-launch-choices'
import { structuredAgentSessionHostKey } from '@/runtime/native-chat/host-capabilities/structured-agent-session-host-capability'
export type AgentModelMenuSource = {
scope: HostModelMenuScope
@@ -30,27 +29,18 @@ export function useAgentModelMenu(
open: boolean
) {
const active = useAppStateViewActive()
const key = source ? structuredAgentSessionHostKey(source.scope.target) : null
const scope = useMemo(
() => source?.scope,
// oxlint-disable-next-line react-hooks/exhaustive-deps -- Scope identity is host/agent/worktree, not the caller's object.
[key, agent, source?.scope.worktree, source?.scope.sourceKey]
)
const catalog = source ? hostModelMenuCatalog(source.scope) : undefined
const subscribe = useCallback(
(listener: () => void) =>
scope ? hostModelMenuCatalog(scope).subscribe(listener) : subscribeAbsent(),
[scope]
)
const getSnapshot = useCallback(
() => (scope ? hostModelMenuCatalog(scope).snapshot : absent),
[scope]
(listener: () => void) => (catalog ? catalog.subscribe(listener) : subscribeAbsent()),
[catalog]
)
const getSnapshot = useCallback(() => catalog?.snapshot ?? absent, [catalog])
const snapshot = useAppViewExternalStore(subscribe, getSnapshot, () => absent)
useEffect(() => {
if (scope && open && active) {
void hostModelMenuCatalog(scope).read(source?.source === 'cli')
if (catalog && open && active) {
void catalog.read(source?.source === 'cli')
}
}, [scope, open, active, snapshot.generation, source?.source])
}, [catalog, open, active, snapshot.generation, source?.source])
const menu = modelMenuOptions(snapshot.answer, {
agent,
surface: 'terminal',
+7
View File
@@ -24526,5 +24526,12 @@
"stopped": "{{host}} stopped controlling browser tabs until Orca restarts.",
"disallowed": "{{host}} can no longer control browser tabs. Turn it back on in Settings > SSH.",
"failed": "Couldn’t stop {{host}}. Turn off its browser control in Settings > SSH."
},
"agents": {
"terminalModels": {
"connectionUnavailable": "Terminal model discovery is unavailable on this connection.",
"workspaceRequired": "Terminal model discovery requires a workspace on this host.",
"hostRequired": "Terminal model discovery requires a connected host."
}
}
}
@@ -10,7 +10,6 @@ import { resolveProjectExecutionRuntime } from '../../../../../../shared/executi
import { agentPickerUsesNativeRuntime } from '@/components/agent/agent-launch-picker-runtime'
import { modelMenuOptions } from '../../../../../../shared/agent-session/options/model-menu-options'
import { agentPickerModelCatalogReads } from '@/components/agent/agent-launch-picker-host-reads'
import type { AgentPickerEntry } from '../../../../../../shared/agent-launch/picker/agent-launch-picker'
import type * as ConnectionOwnerResolutionModule from '../../../workspace/ownership/connection-owner-resolution'
const mocks = vi.hoisted(() => ({
@@ -204,7 +203,17 @@ describe('buildAgentLaunchRouteInput', () => {
nativeRuntime: agentPickerUsesNativeRuntime(route, 'win32', 'C:\\repo'),
settings: {},
serverSettings: async () => ({})
}).catalog({ agent: 'codex', catalogRead: 'pending' } as AgentPickerEntry)
}).catalog({
agent: 'codex',
catalogRead: 'pending',
label: 'Codex',
rows: [],
surfaces: ['chat', 'terminal'],
defaultSurface: 'chat',
terminal: {},
structured: {},
catalog: { origin: 'unknown' }
})
expect(
modelMenuOptions(answer, {
agent: 'codex',
@@ -238,8 +238,15 @@ it('keeps native-only answers out of guest and differing paired-command routes',
await import('../../../../../shared/agent-session/options/model-menu-options')
const entry = {
agent: 'codex',
catalogRead: 'pending'
} as AgentPickerEntry
catalogRead: 'pending',
label: 'Codex',
rows: [],
surfaces: ['chat', 'terminal'],
defaultSurface: 'chat',
terminal: {},
structured: {},
catalog: { origin: 'unknown' }
} satisfies AgentPickerEntry
mocks.call.mockResolvedValue(catalog('native-only'))
for (const input of [
{ target, nativeRuntime: false, settings: {} },
@@ -1,3 +1,4 @@
import { translate } from '@/i18n/i18n'
import type {
RuntimeGitContext,
RuntimeDiscoverCommitMessageModelsResult
@@ -19,13 +20,22 @@ export async function discoverRuntimeTerminalModels(
if (context.connectionId) {
return {
success: false,
error: 'Terminal model discovery is unavailable on this connection.'
error: translate(
'agents.terminalModels.connectionUnavailable',
'Terminal model discovery is unavailable on this connection.'
)
}
}
return window.api.git.discoverTerminalModels({ agentId, ...(worktree ? { worktree } : {}) })
}
if (!context.worktreeId) {
return { success: false, error: 'Terminal model discovery requires a workspace on this host.' }
return {
success: false,
error: translate(
'agents.terminalModels.workspaceRequired',
'Terminal model discovery requires a workspace on this host.'
)
}
}
return callRuntimeRpc<RuntimeDiscoverCommitMessageModelsResult>(
context.target,
@@ -237,7 +237,10 @@ export function createGitApi(): NonNullable<Partial<PreloadApi>['git']> {
}),
discoverTerminalModels: async () => ({
success: false,
error: 'Terminal model discovery requires a connected host.'
error: translate(
'agents.terminalModels.hostRequired',
'Terminal model discovery requires a connected host.'
)
}),
discoverCommitMessageModels: async () => ({
success: false,