mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Align the manager's model selection with the OpenCode TUI: one model.json-backed preference store, one provider catalog, one ordering and default-ownership rule, and one set of availability, ref-formatting and variant helpers shared across chat, schedules, agents and the goal auditor. - Add a shared TUI-compatible model-preference module and make the backend model.json store match its format. - Consolidate the frontend provider catalog, availability check, model ref formatter and variant persistence into single owners. - Drive chat, schedule, agent and goal-auditor model lists from a shared useModelSections hook and buildModelSections, following TUI ordering. - Extract a shared ModelCombobox with a taller list, and list models the TUI way in ModelQuickSelect. - Add a shared isRecord util and model-selection comparison helpers.
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { isModelAvailable } from './modelCatalog'
|
|
import type { ModelInfo } from '@opencode-manager/shared/opencode'
|
|
|
|
const models = [
|
|
{ providerID: 'openai', id: 'gpt-5' },
|
|
{ providerID: 'anthropic', id: 'claude-sonnet-4-20250514' },
|
|
] as unknown as ModelInfo[]
|
|
|
|
describe('isModelAvailable', () => {
|
|
it('accepts a selection that matches the OpenCode key', () => {
|
|
expect(isModelAvailable(models, { providerID: 'openai', modelID: 'gpt-5' })).toBe(true)
|
|
})
|
|
|
|
it('rejects a selection that matches only the backing model id', () => {
|
|
expect(isModelAvailable(models, { providerID: 'openai', modelID: 'gpt-5-2025-08-07' })).toBe(false)
|
|
})
|
|
|
|
it('accepts a string ref that matches the OpenCode key', () => {
|
|
expect(isModelAvailable(models, 'openai/gpt-5')).toBe(true)
|
|
})
|
|
|
|
it('accepts a string ref with a variant suffix', () => {
|
|
expect(isModelAvailable(models, 'openai/gpt-5#high')).toBe(true)
|
|
})
|
|
|
|
it('rejects a string ref that matches only the backing model id', () => {
|
|
expect(isModelAvailable(models, 'openai/gpt-5-2025-08-07')).toBe(false)
|
|
})
|
|
|
|
it('rejects an unknown provider', () => {
|
|
expect(isModelAvailable(models, { providerID: 'ghost', modelID: 'gpt-5' })).toBe(false)
|
|
})
|
|
|
|
it('rejects an unknown model', () => {
|
|
expect(isModelAvailable(models, { providerID: 'openai', modelID: 'missing' })).toBe(false)
|
|
})
|
|
|
|
it('rejects an unparsable string ref', () => {
|
|
expect(isModelAvailable(models, 'gpt-5')).toBe(false)
|
|
expect(isModelAvailable(models, '')).toBe(false)
|
|
})
|
|
|
|
it('rejects a null ref', () => {
|
|
expect(isModelAvailable(models, null)).toBe(false)
|
|
})
|
|
|
|
it('rejects every ref when the catalog is empty', () => {
|
|
expect(isModelAvailable([], { providerID: 'openai', modelID: 'gpt-5' })).toBe(false)
|
|
expect(isModelAvailable([], 'openai/gpt-5')).toBe(false)
|
|
})
|
|
})
|