Files
orca/src/main/agent-launch/agent-launch-opencode-model.test.ts
T

74 lines
2.4 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import type { AgentLaunchIntent } from '../../shared/agent-launch/contracts/agent-launch-intent'
import { executeAgentLaunch } from './agent-launch-executor'
function harness() {
const readSettings = vi.fn(() => {
throw new Error('settings_unavailable')
})
const createSupport = vi.fn(async () => {
throw new Error('support_not_needed_for_refusal')
})
const createTerminal = vi.fn(async () => ({ handle: 'term_new' }))
const deliverPrompt = vi.fn(async () => true)
const createWorktree = vi.fn(async () => ({
worktreeId: 'wt_new',
connectionId: null,
startupTerminalHandle: 'term_new'
}))
return {
readSettings,
createTerminal,
deliverPrompt,
createWorktree,
run: (intent: AgentLaunchIntent) =>
executeAgentLaunch({
intent,
runtime: {
requireStore: () => ({ getSettings: readSettings }),
getStructuredAgentSessionCreateSupport: createSupport
},
surfaces: {
createTerminalAgent: createTerminal,
createStructuredSession: async () => {
throw new Error('structured_not_expected')
},
deliverTerminalPrompt: deliverPrompt
},
workspaces: {
createWorktree,
createFolderWorkspace: async () => {
throw new Error('folder_create_not_expected')
}
}
})
}
}
const reused: AgentLaunchIntent = {
agent: 'opencode',
target: { kind: 'existing', worktree: 'folder:private' },
reuseTerminal: { handle: 'term_existing' },
prompt: { text: 'Read only', delivery: 'submit' },
sessionOptions: { model: 'private-proof/model-b' }
}
const creating: AgentLaunchIntent = {
...reused,
reuseTerminal: undefined,
target: { kind: 'create-worktree', create: { repo: 'id:private', name: 'task' } }
}
describe('OpenCode model preferences on unsupported launch placements', () => {
it.each([reused, creating])(
'preserves definitive refusal without creating or delivering when the route settings read throws',
async (intent) => {
const h = harness()
await expect(h.run(intent)).rejects.toMatchObject({ code: 'capability_unsupported' })
expect(h.readSettings).toHaveBeenCalledOnce()
expect(h.createTerminal).not.toHaveBeenCalled()
expect(h.createWorktree).not.toHaveBeenCalled()
expect(h.deliverPrompt).not.toHaveBeenCalled()
}
)
})