Repository navigation
UI: Fix settings precedence, Factory < Admin (--ui-config-file) < Users (Settings panel) #26002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
allozaur
merged 5 commits into
ggml-org:master
from
ServeurpersoCom:ui/fix-settings-precedence
Jul 24, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
165ecc1
ui: settings sources, precedence, and application semantics
ServeurpersoCom f1893e2
ui: make Reset to Default a full return to instance state
ServeurpersoCom c9efc6b
ui: show the api key splash when the server requires a key
ServeurpersoCom ce0bd59
ui: add tests for api key validation splash behavior
ServeurpersoCom 718b10a
ui: use constants for the Content-Type header
ServeurpersoCom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
| import { validateApiKey } from '$lib/utils/api-key-validation'; | ||
| import { settingsStore } from '$lib/stores/settings.svelte'; | ||
| import { CONFIG_LOCALSTORAGE_KEY } from '$lib/constants/storage'; | ||
|
|
||
| function fakeFetch(status: number, capture: { auth?: string | null } = {}) { | ||
| return (async (_url: RequestInfo | URL, init?: RequestInit) => { | ||
| capture.auth = (init?.headers as Record<string, string>)?.['Authorization'] ?? null; | ||
| return new Response(status === 200 ? '{}' : 'Unauthorized', { status }); | ||
| }) as typeof globalThis.fetch; | ||
| } | ||
|
|
||
| const is401 = (err: unknown) => | ||
| typeof err === 'object' && err !== null && 'status' in err && err.status === 401; | ||
|
|
||
| describe('api key validation surfaces the splash', () => { | ||
| beforeEach(() => { | ||
| localStorage.removeItem(CONFIG_LOCALSTORAGE_KEY); | ||
| settingsStore.initialize(); | ||
| }); | ||
|
|
||
| it('keyed server, no stored key: throws 401 so the splash shows (onboarding)', async () => { | ||
| await expect(validateApiKey(fakeFetch(401))).rejects.toSatisfy(is401); | ||
| }); | ||
|
|
||
| it('keyed server, wrong stored key: throws 401 so the splash shows', async () => { | ||
| settingsStore.updateConfig('apiKey', 'wrong-key'); | ||
| await expect(validateApiKey(fakeFetch(401))).rejects.toSatisfy(is401); | ||
| }); | ||
|
|
||
| it('open server, no stored key: passes silently', async () => { | ||
| await expect(validateApiKey(fakeFetch(200))).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| it('valid stored key: passes and sends the bearer header', async () => { | ||
| settingsStore.updateConfig('apiKey', 'sk-good'); | ||
| const capture: { auth?: string | null } = {}; | ||
| await expect(validateApiKey(fakeFetch(200, capture))).resolves.toBeUndefined(); | ||
| expect(capture.auth).toBe('Bearer sk-good'); | ||
| }); | ||
| }); |
107 changes: 107 additions & 0 deletions
107
tools/ui/tests/client/settings-registry-invariants.svelte.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
| import { settingsStore, config } from '$lib/stores/settings.svelte'; | ||
| import { serverStore } from '$lib/stores/server.svelte'; | ||
| import { ParameterSyncService } from '$lib/services/parameter-sync.service'; | ||
| import { SETTING_CONFIG_DEFAULT } from '$lib/constants/settings-registry'; | ||
| import { CONFIG_LOCALSTORAGE_KEY } from '$lib/constants/storage'; | ||
| import type { SettingsConfigType } from '$lib/types'; | ||
|
|
||
| type Primitive = string | number | boolean; | ||
|
|
||
| const KEYS = Object.keys(SETTING_CONFIG_DEFAULT).filter( | ||
| (k) => ['string', 'number', 'boolean'].includes(typeof SETTING_CONFIG_DEFAULT[k]) && k !== 'theme' | ||
| ); | ||
|
|
||
| function divergent(key: string, base: Primitive): Primitive { | ||
| if (typeof base === 'boolean') return !base; | ||
| if (typeof base === 'number') return base + 7; | ||
| return `user-${key}`; | ||
| } | ||
|
|
||
| function baselineFor(key: string, base: Primitive): Primitive { | ||
| if (typeof base === 'boolean') return !base; | ||
| if (typeof base === 'number') return base + 42; | ||
| return `admin-${key}`; | ||
| } | ||
|
|
||
| function mockProps(uiSettings: Record<string, Primitive>) { | ||
| Object.defineProperty(serverStore, 'props', { | ||
| configurable: true, | ||
| get: () => | ||
| ({ | ||
| default_generation_settings: { params: { temperature: 0.8 } }, | ||
| ui_settings: uiSettings | ||
| }) as unknown as typeof serverStore.props | ||
| }); | ||
| } | ||
|
|
||
| const setUser = (key: string, value: Primitive) => | ||
| settingsStore.updateConfig(key as keyof SettingsConfigType, value as never); | ||
|
|
||
| const current = (key: string) => (config() as Record<string, unknown>)[key]; | ||
|
|
||
| describe('registry-wide invariants', () => { | ||
| beforeEach(() => { | ||
| localStorage.removeItem(CONFIG_LOCALSTORAGE_KEY); | ||
| }); | ||
|
|
||
| it('I1: no load ever modifies a stored user value, for any key of any type', () => { | ||
| settingsStore.initialize(); | ||
| const userValues: Record<string, Primitive> = {}; | ||
| for (const key of KEYS) { | ||
| userValues[key] = divergent(key, SETTING_CONFIG_DEFAULT[key] as Primitive); | ||
| setUser(key, userValues[key]); | ||
| } | ||
|
|
||
| // simulated F5 + adverse admin baseline on every key, synced twice | ||
| settingsStore.initialize(); | ||
| const adverse: Record<string, Primitive> = {}; | ||
| for (const key of KEYS) | ||
| adverse[key] = baselineFor(key, SETTING_CONFIG_DEFAULT[key] as Primitive); | ||
| mockProps(adverse); | ||
| settingsStore.syncWithServerDefaults(); | ||
| settingsStore.syncWithServerDefaults(); | ||
|
|
||
| for (const key of KEYS) { | ||
| expect(current(key), key).toBe(userValues[key]); | ||
| } | ||
| }); | ||
|
|
||
| it('first visit: the baseline applies for every key, false and 0 included', () => { | ||
| settingsStore.initialize(); | ||
| const baseline: Record<string, Primitive> = {}; | ||
| for (const key of KEYS) | ||
| baseline[key] = baselineFor(key, SETTING_CONFIG_DEFAULT[key] as Primitive); | ||
| mockProps(baseline); | ||
|
|
||
| settingsStore.syncWithServerDefaults(); | ||
|
|
||
| for (const key of KEYS) { | ||
| if (ParameterSyncService.canSyncParameter(key)) continue; | ||
| expect(current(key), key).toBe(baseline[key]); | ||
| } | ||
| }); | ||
|
|
||
| it('I3: Reset returns every key to baseline when defined, factory default otherwise', () => { | ||
| settingsStore.initialize(); | ||
| for (const key of KEYS) setUser(key, divergent(key, SETTING_CONFIG_DEFAULT[key] as Primitive)); | ||
|
|
||
| const baseline: Record<string, Primitive> = {}; | ||
| KEYS.filter((_, i) => i % 2 === 0).forEach((key) => { | ||
| baseline[key] = baselineFor(key, SETTING_CONFIG_DEFAULT[key] as Primitive); | ||
| }); | ||
| mockProps(baseline); | ||
|
|
||
| settingsStore.forceSyncWithServerDefaults(); | ||
|
|
||
| for (const key of KEYS) { | ||
| if (key in baseline) { | ||
| expect(current(key), key).toBe(baseline[key]); | ||
| } else if (ParameterSyncService.canSyncParameter(key)) { | ||
| expect(current(key), key).toBe(''); | ||
| } else { | ||
| expect(current(key), key).toBe(SETTING_CONFIG_DEFAULT[key]); | ||
| } | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.