Files
opencode-manager/frontend/src/lib/primaryAgents.test.ts
T
Chris Scott 7e93eb4c34 feat(commands): align built-in slash commands with OpenCode v2
Replace the split built-in command name list and switch with one typed
registry, so a registered command without a handler is a compile error.
Remove the broken themes/share/unshare/editor entries and the hardcoded
init; server and custom commands now win on a name clash and built-ins
dispatch by registry identity.

Add /copy, /btw, /rename, /fork (message picker), /timeline, /model,
/agent, /variants, /mcp, /skills, /settings and /connect. Open the model
picker through state so /model and the select-model shortcut work while a
response is running, load full session history in the fork picker, and
keep attachments when a built-in command is submitted.

Extract shared clipboard and primary-agent helpers, reuse CopyButton in
the manager token settings, and update the Quick Start and chat docs.
2026-10-02 09:53:57 -04:00

57 lines
1.8 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { getPrimaryAgents, getNextPrimaryAgentId } from './primaryAgents'
interface TestAgent {
id: string
mode?: string
hidden?: boolean
}
describe('getPrimaryAgents', () => {
it('keeps primary and all agents that are not hidden', () => {
const agents: TestAgent[] = [
{ id: 'primary', mode: 'primary' },
{ id: 'all', mode: 'all' },
{ id: 'sub', mode: 'subagent' },
{ id: 'hidden', mode: 'primary', hidden: true },
]
expect(getPrimaryAgents(agents).map((agent) => agent.id)).toEqual(['primary', 'all'])
})
it('returns an empty array for undefined or empty input', () => {
expect(getPrimaryAgents(undefined)).toEqual([])
expect(getPrimaryAgents([])).toEqual([])
})
})
describe('getNextPrimaryAgentId', () => {
const agents: TestAgent[] = [
{ id: 'build', mode: 'primary' },
{ id: 'plan', mode: 'primary' },
{ id: 'sub', mode: 'subagent' },
{ id: 'hidden', mode: 'primary', hidden: true },
]
it('returns the next primary agent', () => {
expect(getNextPrimaryAgentId(agents, 'build')).toBe('plan')
})
it('wraps around after the last primary agent', () => {
expect(getNextPrimaryAgentId(agents, 'plan')).toBe('build')
})
it('matches the current agent id case-insensitively', () => {
expect(getNextPrimaryAgentId(agents, 'BUILD')).toBe('plan')
})
it('returns the first primary agent when the current agent is unknown', () => {
expect(getNextPrimaryAgentId(agents, 'missing')).toBe('build')
})
it('returns undefined when there are no primary agents', () => {
expect(getNextPrimaryAgentId(undefined, 'build')).toBeUndefined()
expect(getNextPrimaryAgentId([{ id: 'sub', mode: 'subagent' }], 'build')).toBeUndefined()
})
})