import test from 'brittle' import { readFileSync } from 'node:fs' import vm from 'node:vm' const QVAC_SRC = readFileSync(new URL('../lib/agent/agent-qvac.js', import.meta.url), 'utf8') const MODELS_SRC = readFileSync( new URL('../lib/agent/agent-models.js', import.meta.url), 'utf8' ) const TUI_SRC = readFileSync(new URL('../lib/agent/agent-tui.js', import.meta.url), 'utf8') function load() { const sandbox = { console } vm.createContext(sandbox) vm.runInContext( QVAC_SRC + '\n' + MODELS_SRC + '\n' + TUI_SRC + '\n;this.__exports = { bareAgentHonorExplicitQvacModel, bareAgentApplyLiveModel, bareAgentApplyProviderProfile, bareAgentQvacGetProfile, bareAgentQvacFindChatModel, bareAgentQvacResolveCtxSize, bareAgentQvacSyncSettingsForModel }', sandbox ) return sandbox.__exports } test('explicit QVAC model survives profile apply (live Discord/CLI switch)', async (t) => { const { bareAgentApplyProviderProfile } = load() const next = bareAgentApplyProviderProfile({ backend: 'qvac', qvac_profile: 'recommended', qvac_model: 'QWEN3_8B_INST_Q4_K_M', model: 'QWEN3_8B_INST_Q4_K_M' }) t.is(next.qvac_model, 'QWEN3_8B_INST_Q4_K_M') t.is(next.model, 'QWEN3_8B_INST_Q4_K_M') }) test('empty QVAC model fills from profile', async (t) => { const { bareAgentApplyProviderProfile, bareAgentQvacGetProfile } = load() const next = bareAgentApplyProviderProfile({ backend: 'qvac', qvac_profile: 'strong' }) t.is(next.qvac_model, bareAgentQvacGetProfile('strong').chatModel) }) test('apply live model on QVAC sets both keys and profile when catalog-known', async (t) => { const { bareAgentApplyLiveModel } = load() const next = bareAgentApplyLiveModel( { backend: 'qvac', qvac_profile: 'recommended', qvac_model: 'QWEN3_1_7B_INST_Q4' }, 'QWEN3_600M_INST_Q4' ) t.is(next.qvac_model, 'QWEN3_600M_INST_Q4') t.is(next.model, 'QWEN3_600M_INST_Q4') t.is(next.qvac_profile, 'lite') }) test('live QVAC model switch resets ctx to the new model card', async (t) => { const { bareAgentApplyLiveModel, bareAgentQvacResolveCtxSize, bareAgentQvacGetProfile } = load() const next = bareAgentApplyLiveModel( { backend: 'qvac', qvac_profile: 'recommended', qvac_model: 'QWEN3_1_7B_INST_Q4', qvac_ctx_size: 32768 }, 'QWEN3_5_4B_MULTIMODAL_Q4_K_M' ) t.is(next.qvac_model, 'QWEN3_5_4B_MULTIMODAL_Q4_K_M') t.is(next.qvac_ctx_size, 0) t.is( bareAgentQvacResolveCtxSize(next, bareAgentQvacGetProfile(next.qvac_profile)), 262144 ) }) test('apply live model on REST only changes model', async (t) => { const { bareAgentApplyLiveModel } = load() const next = bareAgentApplyLiveModel( { backend: 'rest', provider: 'groq', rest_api_key: 'gsk', rest_base_url: 'https://api.groq.com/openai/v1', model: 'old' }, 'llama-3.1-8b-instant' ) t.is(next.backend, 'rest') t.is(next.model, 'llama-3.1-8b-instant') t.absent(next.qvac_model) })