Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(web): match stored model IDs case-insensitively on the settings page (#7486)

Imaduddin Bhaisaheb65f91380e70f
diff --git a/changelog.d/7398.bugfix.md b/changelog.d/7398.bugfix.md
new file mode 100644
index 0000000000..72cfe7a5a5
--- /dev/null
+++ b/changelog.d/7398.bugfix.md
@@ -0,0 +1 @@
+The settings page no longer shows one model while saving another when a stored model ID differs from the model list only by letter case, and switching providers now keeps such a model (using the listed casing) instead of silently replacing it with the first listed model. The corrected casing is applied to the form only; the stored setting is updated the next time settings are saved.
diff --git a/src/local_deep_research/web/static/js/components/custom_dropdown.js b/src/local_deep_research/web/static/js/components/custom_dropdown.js
index e7770e467a..aa83234152 100644
--- a/src/local_deep_research/web/static/js/components/custom_dropdown.js
+++ b/src/local_deep_research/web/static/js/components/custom_dropdown.js
@@ -13,6 +13,32 @@
// Also export the updateDropdownOptions function
window.updateDropdownOptions = updateDropdownOptions;
+ /**
+ * Find the option whose value matches `value`: a full exact pass first,
+ * then a case-insensitive pass. The two passes must stay separate; OR-ing
+ * both comparisons per option makes the first case-variant win even when a
+ * later option matches exactly, so the displayed label and the submitted
+ * value disagree.
+ * @param {Array<{value: string}>} options - Dropdown options
+ * @param {string} value - Stored or requested value
+ * @returns {Object|undefined} The matching option, or undefined
+ */
+ function findOptionByValue(options, value) {
+ if (!Array.isArray(options) || value === null || value === undefined) {
+ return undefined;
+ }
+ const exact = options.find(opt => opt && opt.value === value);
+ if (exact) return exact;
+ if (!value || typeof value !== 'string') return undefined;
+ const lower = value.toLowerCase();
+ return options.find(
+ opt => opt && typeof opt.value === 'string' && opt.value.toLowerCase() === lower
+ );
+ }
+
+ // Shared with the settings page (components/settings.js)
+ window.findDropdownOption = findOptionByValue;
+
// Keep a registry of inputs and their associated options functions
const dropdownRegistry = {};
@@ -876,7 +902,10 @@
},
setValue: (value, triggerChange = true) => {
const options = getOptions();
- const matchedOption = options.find(opt => opt.value === value || (opt.value && value && opt.value.toLowerCase() === value.toLowerCase()));
+ const matchedOption = findOptionByValue(options, value);
+ // Submit the listed option's own casing, so the hidden
+ // field always names the model the visible label shows.
+ const resolvedValue = matchedOption ? matchedOption.value : value;
if (matchedOption) {
input.value = matchedOption.label;
@@ -892,14 +921,14 @@
// (dispatches change). See the matching note in
// handleItemClick above.
if (matchedOption) {
- onSelect(value, matchedOption);
+ onSelect(resolvedValue, matchedOption);
} else {
onSelect(value, { value, label: value });
}
- updateHiddenField(value);
+ updateHiddenField(resolvedValue);
} else if (hiddenInput) {
// Even if we don't trigger events, we should update the hidden field
- hiddenInput.value = value;
+ hiddenInput.value = resolvedValue;
}
}
};
diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.js
index bef384e593..bfc81fdb3b 100644
--- a/src/local_deep_research/web/static/js/components/settings.js
+++ b/src/local_deep_research/web/static/js/components/settings.js
@@ -4741,9 +4741,9 @@
// Set the current model without filtering first
if (currentModel) {
SafeLogger.log('Setting initial model:', currentModel);
+ // setValue also writes the hidden input (canonical casing
+ // when listed, the raw value otherwise)
modelDropdownControl.setValue(currentModel, false); // Don't fire event
- // Explicitly set hidden input value on init
- modelHiddenInput.value = currentModel;
}
// Now filter models for the current provider - AFTER setting the initial value
@@ -5380,6 +5380,30 @@
// --- MODIFICATION END ---
}
+ /**
+ * Find the option matching a stored model ID: exact match first, then
+ * case-insensitive. Uses the shared helper from custom_dropdown.js (loaded
+ * before this file). If it is missing, falls back to an inline
+ * exact-then-case-insensitive lookup and logs a console warning.
+ * @param {Array<{value: string, label: string}>} options - Candidate models
+ * @param {string} value - Stored model ID
+ * @returns {Object|undefined} The matching option, or undefined
+ */
+ function findModelOptionForValue(options, value) {
+ if (typeof window.findDropdownOption === 'function') {
+ return window.findDropdownOption(options, value);
+ }
+ // Shared helper missing (e.g. mixed-version asset serving after a
+ // deploy): keep the same exact-first, then case-insensitive lookup
+ // inline so the pre-fix silent model swap cannot come back, and
+ // leave a trace in the console.
+ SafeLogger.warn('window.findDropdownOption unavailable; using inline model lookup');
+ const exact = options.find(m => m.value === value);
+ if (exact) return exact;
+ const lowered = typeof value === 'string' ? value.toLowerCase() : value;
+ return options.find(m => typeof m.value === 'string' && m.value.toLowerCase() === lowered);
+ }
+
/**
* Filter model options based on the selected provider
* @param {string} provider - The provider to filter models by
@@ -5471,9 +5495,20 @@
// Try to maintain the current selection if applicable
const currentModel = modelHiddenInput ? modelHiddenInput.value : null;
if (currentModel) {
- // Check if current model is valid for this provider
- const isValid = filteredModels.some(m => m.value === currentModel);
- if (!isValid && filteredModels.length > 0) {
+ // Check if current model is valid for this provider. The
+ // stored casing may drift from the listing, so match exact
+ // first, then case-insensitively.
+ const matchedModel = findModelOptionForValue(filteredModels, currentModel);
+ if (matchedModel) {
+ if (matchedModel.value !== currentModel) {
+ // Casing drifted from the listing: canonicalize to
+ // the listed model instead of replacing it. Direct
+ // value-set bypasses the change listener, as below.
+ SafeLogger.log(`Canonicalizing model ${currentModel} to listed ${matchedModel.value}`);
+ modelHiddenInput.value = matchedModel.value;
+ modelInput.value = matchedModel.label || matchedModel.value;
+ }
+ } else if (filteredModels.length > 0) {
// Select first available model if current is not valid
const firstModel = filteredModels[0].value;
SafeLogger.log(`Current model ${currentModel} invalid for provider ${providerUpper}. Setting to first available: ${firstModel}`);
@@ -5535,11 +5570,14 @@
const currentModel = modelHiddenInput ? modelHiddenInput.value : null;
if (currentModel && modelDropdownControl && modelDropdownControl.setValue) {
- // Check if current model is valid for this provider
- const isValid = filteredModels.some(m => m.value === currentModel);
- if (isValid) {
- SafeLogger.log(`Setting model value to currently selected: ${currentModel}`);
- modelDropdownControl.setValue(currentModel, false);
+ // Check if current model is valid for this provider. The
+ // stored casing may drift from the listing, so match exact
+ // first, then case-insensitively.
+ const matchedModel = findModelOptionForValue(filteredModels, currentModel);
+ if (matchedModel) {
+ SafeLogger.log(`Setting model value to currently selected: ${matchedModel.value}`);
+ // setValue canonicalizes the hidden field to the listed casing
+ modelDropdownControl.setValue(matchedModel.value, false);
} else if (filteredModels.length > 0) {
// Select first available model
const firstModel = filteredModels[0].value;
diff --git a/src/local_deep_research/web/templates/pages/news-subscription-form.html b/src/local_deep_research/web/templates/pages/news-subscription-form.html
index 68e3055868..76776b6a52 100644
--- a/src/local_deep_research/web/templates/pages/news-subscription-form.html
+++ b/src/local_deep_research/web/templates/pages/news-subscription-form.html
@@ -281,21 +281,8 @@ function initializeDropdowns() {
// Set initial value if available
if (defaultSearchEngine && searchEngineDropdownInstance.setValue) {
console.log('Setting initial search engine value:', defaultSearchEngine);
- // Try exact match first
+ // setValue matches exact-first, then case-insensitively
searchEngineDropdownInstance.setValue(defaultSearchEngine, false);
-
- // Check if the value was set by looking at the input
- const input = document.getElementById('subscription-search-engine');
- if (!input.value && searchEngineOptions.length > 0) {
- // Try case-insensitive match
- const matchingOption = searchEngineOptions.find(opt =>
- opt.value.toLowerCase() === defaultSearchEngine.toLowerCase()
- );
- if (matchingOption) {
- console.log('Found case-insensitive match:', matchingOption);
- searchEngineDropdownInstance.setValue(matchingOption.value, false);
- }
- }
}
} else {
console.error('Search engine dropdown elements not found');
diff --git a/tests/js/components/custom-dropdown.test.js b/tests/js/components/custom-dropdown.test.js
index eb8c883ae8..4533f5259a 100644
--- a/tests/js/components/custom-dropdown.test.js
+++ b/tests/js/components/custom-dropdown.test.js
@@ -250,8 +250,107 @@ describe('setupCustomDropdown', () => {
const dd = setupCustomDropdown(input, dropdownList, () => options, onSelect, true);
dd.setValue('custom-model');
expect(input.value).toBe('custom-model');
+ expect(hiddenInput.value).toBe('custom-model');
+
+ // Same contract with triggerChange = false (the settings page's
+ // init path): the hidden field still gets the raw value, so
+ // callers need no separate hidden-input write.
+ hiddenInput.value = '';
+ dd.setValue('custom-model', false);
+ expect(input.value).toBe('custom-model');
+ expect(hiddenInput.value).toBe('custom-model');
dd.destroy();
});
+
+ describe('case-insensitive matching (#7398)', () => {
+ const caseVariants = [
+ { value: 'org/model-a', label: 'Wrong case' },
+ { value: 'Org/Model-A', label: 'Right case' },
+ ];
+
+ it('prefers an exact match over an earlier case-variant', () => {
+ const dd = setupCustomDropdown(input, dropdownList, () => caseVariants, onSelect);
+ dd.setValue('Org/Model-A');
+ // Displayed model must be the one actually submitted.
+ expect(input.value).toBe('Right case');
+ expect(hiddenInput.value).toBe('Org/Model-A');
+ expect(onSelect).toHaveBeenCalledWith('Org/Model-A', caseVariants[1]);
+ dd.destroy();
+ });
+
+ it('still prefers the exact match when it comes first', () => {
+ const reversed = [caseVariants[1], caseVariants[0]];
+ const dd = setupCustomDropdown(input, dropdownList, () => reversed, onSelect);
+ dd.setValue('org/model-a');
+ expect(input.value).toBe('Wrong case');
+ expect(hiddenInput.value).toBe('org/model-a');
+ dd.destroy();
+ });
+
+ it('canonicalizes a drifted stored value to the listed casing', () => {
+ const listed = [{ value: 'Org/Model-A', label: 'Model A' }];
+ const dd = setupCustomDropdown(input, dropdownList, () => listed, onSelect);
+ dd.setValue('org/model-a');
+ expect(input.value).toBe('Model A');
+ expect(hiddenInput.value).toBe('Org/Model-A');
+ expect(onSelect).toHaveBeenCalledWith('Org/Model-A', listed[0]);
+ dd.destroy();
+ });
+
+ it('canonicalizes the hidden field even when change events are suppressed', () => {
+ const listed = [{ value: 'Org/Model-A', label: 'Model A' }];
+ const dd = setupCustomDropdown(input, dropdownList, () => listed, onSelect);
+ dd.setValue('org/model-a', false);
+ expect(input.value).toBe('Model A');
+ expect(hiddenInput.value).toBe('Org/Model-A');
+ expect(onSelect).not.toHaveBeenCalled();
+ dd.destroy();
+ });
+
+ it('keeps an unmatched custom value as typed', () => {
+ const dd = setupCustomDropdown(input, dropdownList, () => caseVariants, onSelect, true);
+ dd.setValue('Some/Other-Model', false);
+ expect(input.value).toBe('Some/Other-Model');
+ expect(hiddenInput.value).toBe('Some/Other-Model');
+ dd.destroy();
+ });
+ });
+ });
+
+ describe('findDropdownOption helper (#7398)', () => {
+ const find = window.findDropdownOption;
+ const list = [
+ { value: 'org/model-a', label: 'lower' },
+ { value: 'Org/Model-A', label: 'canonical' },
+ { value: 'other', label: 'other' },
+ ];
+
+ it('is exposed for the settings page', () => {
+ expect(find).toBeTypeOf('function');
+ });
+
+ it('returns the exact match before a case-insensitive one', () => {
+ expect(find(list, 'Org/Model-A').label).toBe('canonical');
+ expect(find(list, 'org/model-a').label).toBe('lower');
+ });
+
+ it('falls back to a case-insensitive match', () => {
+ expect(find(list, 'OTHER').label).toBe('other');
+ expect(find([list[1]], 'org/model-a').label).toBe('canonical');
+ });
+
+ it('returns undefined for no match, empty or missing input', () => {
+ expect(find(list, 'missing')).toBeUndefined();
+ expect(find(list, '')).toBeUndefined();
+ expect(find(list, null)).toBeUndefined();
+ expect(find(list, undefined)).toBeUndefined();
+ expect(find(null, 'x')).toBeUndefined();
+ expect(find([], 'x')).toBeUndefined();
+ });
+
+ it('tolerates malformed options', () => {
+ expect(find([null, {}, { value: 5 }, { value: 'x', label: 'X' }], 'X').label).toBe('X');
+ });
});
describe('destroy', () => {
@@ -647,10 +746,10 @@ describe('setupCustomDropdown', () => {
});
it('setValue() with a case-variant stored value resolves on a bare Enter (duplicate labels)', () => {
- // Fails on the unedited head: setValue() itself matches
- // case-insensitively and writes the RAW value into the hidden
- // field, so the hidden input can legitimately hold a case
- // variant the user never typed. With two options sharing a
+ // The hidden input can hold a case variant the user never typed
+ // (before #7398, setValue() wrote the RAW value into it; it now
+ // canonicalizes, so the variant is planted directly below to keep
+ // guarding the Enter tie-break). With two options sharing a
// label, the pre-fix tie-break
// (`o.value === hiddenInput.value`) failed that case-variant
// comparison, the labelMatches.length===1 fallback did not
@@ -664,7 +763,10 @@ describe('setupCustomDropdown', () => {
const dd = setupCustomDropdown(input, dropdownList, () => options, onSelect, true);
dd.setValue('OpenAI/GPT-4O', false); // case-variant of options[0].value
expect(input.value).toBe('Shared display name');
- expect(hiddenInput.value).toBe('OpenAI/GPT-4O');
+ // setValue() canonicalizes to the listed casing (#7398)...
+ expect(hiddenInput.value).toBe('openai/gpt-4o');
+ // ...so plant the case variant directly to keep the tie-break covered.
+ hiddenInput.value = 'OpenAI/GPT-4O';
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
diff --git a/tests/js/components/settings-model-case-runtime.test.js b/tests/js/components/settings-model-case-runtime.test.js
new file mode 100644
index 0000000000..13db4481b5
--- /dev/null
+++ b/tests/js/components/settings-model-case-runtime.test.js
@@ -0,0 +1,295 @@
+/**
+ * Settings page model selection (#7398): when the stored model's casing
+ * drifts from the listing, the provider-filter pass must canonicalize to the
+ * case-insensitive match instead of silently replacing the user's model with
+ * the first listed one. A model that genuinely is not offered for the
+ * provider must still fall back to the first entry.
+ *
+ * `filterModelOptionsForProvider` has two code paths — the in-place
+ * `updateDropdownOptions` path and the `setupCustomDropdown` re-init
+ * fallback — and both are exercised here.
+ */
+
+import '@js/config/urls.js';
+import '@js/services/api.js';
+import '@js/utils/alert-helpers.js';
+import '@js/utils/provider-options.js';
+import '@js/utils/value-helpers.js';
+import '@js/components/custom_dropdown.js';
+
+// Captured at import time so each boot can restore the shared helper after a
+// test that removes it.
+const sharedFindDropdownOption = window.findDropdownOption;
+
+const flushPromises = async (turns = 12) => {
+ for (let turn = 0; turn < turns; turn += 1) await Promise.resolve();
+};
+
+function jsonResponse(payload, status = 200) {
+ return new Response(JSON.stringify(payload), {
+ status,
+ headers: { 'Content-Type': 'application/json' },
+ });
+}
+
+function setting(overrides) {
+ return {
+ category: 'general',
+ description: '',
+ editable: true,
+ max_value: null,
+ min_value: null,
+ options: null,
+ step: null,
+ visible: true,
+ ...overrides,
+ };
+}
+
+const LISTED_MODELS = [
+ { value: 'gpt-4o-mini', label: 'GPT-4o mini' },
+ { value: 'gpt-4o', label: 'GPT-4o' },
+];
+
+/**
+ * Boot the settings page with `llm.provider=openai` and a stored
+ * `llm.model`, then let the post-init provider filter run.
+ *
+ * @param {object} opts
+ * @param {string} opts.storedModel - value of the stored `llm.model` setting
+ * @param {Array<{value: string, label: string}>} [opts.models] - models the
+ * provider lists (defaults to LISTED_MODELS)
+ * @param {boolean} [opts.withoutSharedHelper] - true: drop `window.findDropdownOption`
+ * to exercise settings.js's inline fallback lookup
+ * @param {boolean} opts.inPlaceUpdate - true: `updateDropdownOptions` is
+ * available (in-place path); false: only `setupCustomDropdown` (re-init path)
+ */
+async function bootSettings({
+ storedModel,
+ inPlaceUpdate,
+ withoutSharedHelper = false,
+ models = LISTED_MODELS,
+}) {
+ vi.useFakeTimers();
+ vi.resetModules();
+ document.head.insertAdjacentHTML(
+ 'beforeend',
+ '<meta name="csrf-token" content="csrf-model-case">',
+ );
+ document.body.innerHTML = `
+ <form id="settings-form">
+ <input id="settings-search">
+ <button type="button" class="ldr-settings-tab active" data-tab="all">All</button>
+ <div id="settings-alert"></div>
+ <div id="settings-content"></div>
+ <button id="reset-to-defaults-button" type="button">Reset defaults</button>
+ <button id="toggle-raw-config" type="button"><span id="toggle-text"></span></button>
+ <section id="raw-config" style="display: none">
+ <textarea id="raw_config_editor"></textarea>
+ </section>
+ <div id="llm.model-empty-warning" style="display: none"></div>
+ </form>
+ `;
+
+ const settings = {
+ 'llm.provider': setting({
+ category: 'llm_general',
+ name: 'Provider',
+ type: 'LLM',
+ ui_element: 'select',
+ value: 'openai',
+ options: [
+ { value: 'openai', label: 'OpenAI API' },
+ { value: 'ollama', label: 'Ollama (Local)' },
+ ],
+ }),
+ 'llm.model': setting({
+ category: 'llm_general',
+ name: 'Model',
+ type: 'LLM',
+ ui_element: 'select',
+ value: storedModel,
+ }),
+ };
+
+ vi.stubGlobal('fetch', vi.fn((url) => {
+ if (url === URLS.SETTINGS_API.BASE) {
+ return Promise.resolve(jsonResponse({ status: 'success', settings }));
+ }
+ if (url === URLS.SETTINGS_API.AVAILABLE_MODELS) {
+ return Promise.resolve(jsonResponse({
+ providers: { openai_models: models },
+ provider_options: [{ value: 'openai', label: 'OpenAI' }],
+ }));
+ }
+ if (url === URLS.SETTINGS_API.AVAILABLE_SEARCH_ENGINES) {
+ return Promise.resolve(jsonResponse({
+ engine_options: [{ value: 'searxng', label: 'SearXNG' }],
+ }));
+ }
+ if (url === '/settings/api/data-location') {
+ return Promise.resolve(jsonResponse({
+ data_directory: '/tmp/ldr',
+ security_notice: { encrypted: false },
+ }));
+ }
+ if (url === URLS.SETTINGS_API.BACKUP_STATUS) {
+ return Promise.resolve(jsonResponse({ enabled: false, count: 0, backups: [] }));
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ }));
+ window.ui = { showMessage: vi.fn() };
+ window.matchMedia = vi.fn(() => ({ matches: false }));
+
+ // Stubs replace the real dropdown widget so only settings.js logic runs.
+ // `findDropdownOption` (from custom_dropdown.js) is intentionally kept.
+ const setValue = vi.fn();
+ window.setupCustomDropdown = vi.fn(() => ({ setValue }));
+ if (inPlaceUpdate) {
+ window.updateDropdownOptions = vi.fn();
+ } else {
+ delete window.updateDropdownOptions;
+ }
+
+ if (withoutSharedHelper) delete window.findDropdownOption;
+ else window.findDropdownOption = sharedFindDropdownOption;
+
+ await import('@js/components/settings.js');
+ if (document.readyState === 'loading') {
+ document.dispatchEvent(new Event('DOMContentLoaded'));
+ }
+ await flushPromises();
+ // Past the 100ms post-init provider filter.
+ await vi.advanceTimersByTimeAsync(400);
+
+ return {
+ setValue,
+ hidden: document.getElementById('llm.model_hidden'),
+ visible: document.getElementById('llm.model'),
+ };
+}
+
+afterEach(() => {
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+ vi.useRealTimers();
+ delete window.ui;
+ delete window.modelProvidersRequestInProgress;
+ delete window.searchEnginesRequestInProgress;
+ delete window.modelDropdownsInitialized;
+ delete window.searchEngineDropdownInitialized;
+ delete window.setupCustomDropdown;
+ delete window.updateDropdownOptions;
+ document.head.querySelector('meta[name="csrf-token"]')?.remove();
+ document.body.replaceChildren();
+});
+
+describe('in-place provider filter (updateDropdownOptions path)', () => {
+ it('canonicalizes a drifted stored model instead of swapping to the first one', async () => {
+ const { hidden, visible } = await bootSettings({
+ storedModel: 'GPT-4O',
+ inPlaceUpdate: true,
+ });
+
+ expect(hidden).not.toBeNull();
+ expect(hidden.value).toBe('gpt-4o');
+ expect(hidden.value).not.toBe('gpt-4o-mini');
+ expect(visible.value).toBe('GPT-4o');
+ });
+
+ it('keeps an exactly matching stored model untouched', async () => {
+ const { hidden } = await bootSettings({
+ storedModel: 'gpt-4o',
+ inPlaceUpdate: true,
+ });
+ expect(hidden.value).toBe('gpt-4o');
+ });
+
+ it('still falls back to the first model when the stored one is not offered', async () => {
+ const { hidden, visible } = await bootSettings({
+ storedModel: 'not-a-real-model',
+ inPlaceUpdate: true,
+ });
+ expect(hidden.value).toBe('gpt-4o-mini');
+ expect(visible.value).toBe('GPT-4o mini');
+ });
+});
+
+describe('re-init provider filter (setupCustomDropdown fallback path)', () => {
+ it('canonicalizes a drifted stored model instead of swapping to the first one', async () => {
+ const { setValue } = await bootSettings({
+ storedModel: 'GPT-4O',
+ inPlaceUpdate: false,
+ });
+
+ const values = setValue.mock.calls.map(([value]) => value);
+ expect(values).toContain('gpt-4o');
+ expect(values).not.toContain('gpt-4o-mini');
+ });
+
+ it('still falls back to the first model when the stored one is not offered', async () => {
+ const { setValue } = await bootSettings({
+ storedModel: 'not-a-real-model',
+ inPlaceUpdate: false,
+ });
+ expect(setValue).toHaveBeenCalledWith('gpt-4o-mini', false);
+ });
+});
+
+describe('inline lookup when window.findDropdownOption is unavailable', () => {
+ it('still canonicalizes a drifted model and warns that the helper is missing', async () => {
+ const warn = vi.spyOn(SafeLogger, 'warn');
+ const { hidden, visible } = await bootSettings({
+ storedModel: 'GPT-4O',
+ inPlaceUpdate: true,
+ withoutSharedHelper: true,
+ });
+
+ expect(hidden.value).toBe('gpt-4o');
+ expect(visible.value).toBe('GPT-4o');
+ expect(warn).toHaveBeenCalledWith(
+ expect.stringContaining('findDropdownOption unavailable'),
+ );
+ });
+
+ it('does not warn when the shared helper is present', async () => {
+ const warn = vi.spyOn(SafeLogger, 'warn');
+ await bootSettings({ storedModel: 'GPT-4O', inPlaceUpdate: true });
+ expect(warn).not.toHaveBeenCalledWith(
+ expect.stringContaining('findDropdownOption unavailable'),
+ );
+ });
+
+ it('still falls back to the first model when the stored one is not offered', async () => {
+ const { hidden } = await bootSettings({
+ storedModel: 'not-a-real-model',
+ inPlaceUpdate: true,
+ withoutSharedHelper: true,
+ });
+ expect(hidden.value).toBe('gpt-4o-mini');
+ });
+
+ // The shared helper's ordering is pinned in custom-dropdown.test.js; these
+ // pin the inline copy, which runs only when the helper is missing. A
+ // single pass accepting "exact OR case-variant" would pick whichever comes
+ // first, so both listing orders are covered.
+ it.each([
+ ['case-variant listed before the exact match', [
+ { value: 'GPT-4O', label: 'Variant first' },
+ { value: 'gpt-4o', label: 'Exact second' },
+ ]],
+ ['exact match listed before the case-variant', [
+ { value: 'gpt-4o', label: 'Exact first' },
+ { value: 'GPT-4O', label: 'Variant second' },
+ ]],
+ ])('prefers the exact match over a case-variant (%s)', async (_name, models) => {
+ const { hidden } = await bootSettings({
+ storedModel: 'gpt-4o',
+ inPlaceUpdate: true,
+ withoutSharedHelper: true,
+ models,
+ });
+
+ expect(hidden.value).toBe('gpt-4o');
+ });
+});