import test from 'brittle' import { readFileSync } from 'node:fs' import vm from 'node:vm' const SRC = readFileSync(new URL('../lib/agent/agent-models.js', import.meta.url), 'utf8') function load() { const sandbox = { console } vm.createContext(sandbox) vm.runInContext(SRC, sandbox, { filename: 'agent-models.js' }) return sandbox } test('QVAC catalog covers profiles and extra chat ids', async (t) => { const s = load() const ids = s.BARE_AGENT_QVAC_CHAT_MODELS.map((m) => m.id) t.ok(ids.includes('QWEN3_1_7B_INST_Q4')) t.ok(ids.includes('QWEN3_8B_INST_Q4_K_M')) t.ok(ids.includes('LLAMA_TOOL_CALLING_1B_INST_Q4_K')) t.ok(ids.includes('GEMMA4_2B_MULTIMODAL_Q4_K_M')) t.is(s.bareAgentQvacModelForProfile('recommended').id, 'QWEN3_1_7B_INST_Q4') t.is(s.bareAgentQvacModelForProfile('strong').id, 'QWEN3_4B_INST_Q4_K_M') }) test('parse OpenAI models skips embeddings and sorts', async (t) => { const s = load() const list = s.bareAgentParseOpenAiModels({ data: [ { id: 'llama-3.3-70b-versatile', owned_by: 'meta' }, { id: 'text-embedding-3-large', owned_by: 'openai' }, { id: 'whisper-large-v3', owned_by: 'openai' }, { id: 'gpt-4.1', owned_by: 'openai' } ] }) t.is(list.length, 2) t.is(list[0].id, 'gpt-4.1') t.is(list[1].id, 'llama-3.3-70b-versatile') }) test('fetch REST models uses /models and falls back on empty', async (t) => { const s = load() const live = await s.bareAgentFetchRestModels( async () => ({ ok: true, status: 200, json: async () => ({ data: [{ id: 'grok-4' }, { id: 'grok-3-mini' }] }) }), { baseUrl: 'https://api.x.ai/v1', apiKey: 'x' } ) t.is(live.length, 2) t.is(live[0].id, 'grok-3-mini') await t.exception(() => s.bareAgentFetchRestModels(async () => ({ ok: false, status: 401 }), { baseUrl: 'https://api.groq.com/openai/v1' }) ) t.ok(s.bareAgentRestModelsFallback('groq').some((m) => m.id === 'llama-3.3-70b-versatile')) })