// A model that leaves the roster has to leave every list that names it. The // allowed lists are advisory copies of the roster; the roster is the fact. A // stale id there is invisible until someone asks a clinical question and the // request fails at the gateway. const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const route = fs.readFileSync(path.join(__dirname, '..', 'src/routes/adminConfig.js'), 'utf8'); test('one helper owns forgetting a model, and covers every list that names one', () => { assert.match(route, /async function forgetModelEverywhere\(ids\)/); for (const key of ['clinical_assistant.allowed_models', 'clinical_assistant.allowed_image_models', 'clinical_assistant.image_model_roster']) { assert.ok(route.includes("'" + key + "'"), key + ' is not pruned'); } // And a default pointing at a model that has gone. assert.match(route, /gone\.indexOf\(current\) !== -1\) await db\.setSetting\('models\.default', ''\)/); }); test('removing a custom model prunes it', () => { const handler = route.slice(route.indexOf("router.delete('/config/models/custom")); assert.match(handler.slice(0, 900), /await forgetModelEverywhere\(modelId\)/); }); test('disabling a model prunes it too — it stops being selectable either way', () => { const handler = route.slice(route.indexOf("router.put('/config/models/toggle")); assert.match(handler.slice(0, 1600), /if \(!enabled\) await forgetModelEverywhere\(modelId\)/); // Re-enabling must NOT silently re-allow it: that is a separate decision. assert.doesNotMatch(handler.slice(0, 1600), /if \(enabled\) await forgetModelEverywhere/); }); test('clearing every model clears every allowed list', () => { const handler = route.slice(route.indexOf("router.post('/config/models/clear-all")); assert.match(handler.slice(0, 900), /await db\.setSetting\(key, ''\)/); assert.match(handler.slice(0, 900), /Nothing is on the roster any more/); }); test('a list is only written when it actually changed', () => { // Avoids a settings write, an updated_at bump and a cache refresh per removal // when nothing referenced the model. const fn = route.slice(route.indexOf('async function forgetModelEverywhere')); assert.match(fn.slice(0, 1200), /if \(kept\.join\(','\) !== current\)/); });