ui: read persisted settings before the API key probe (#27365)

The route loads run ahead of the root layout script, so validateApiKey
read the settings store while it still held factory defaults and probed
/props without the stored key. initStores() now hands the same startup
promise to every caller and the chat loads await it before probing.

The one-time admin baseline no longer overwrites a key the user has
already set: on a first visit the config carries factory values only, so
a diverging key comes from the user and wins.
This commit is contained in:
Pascal
2026-08-19 14:02:08 +02:00
committed by GitHub
parent 95c409c136
commit 77acca437f
5 changed files with 52 additions and 18 deletions
@@ -47,6 +47,19 @@ describe('server ui_settings application semantics', () => {
expect(stored.apiKey).toBe('sk-user-key');
});
it('keeps a value the user sets before the baseline is reachable', () => {
settingsStore.initialize();
// the splash is the only way in when the server runs with --api-key,
// so the first user write lands before the first successful /props
settingsStore.updateConfig('apiKey', 'sk-user-key');
mockProps({ apiKey: 'admin-placeholder', theme: 'dark' });
settingsStore.syncWithServerDefaults();
expect(settingsStore.config.apiKey).toBe('sk-user-key');
expect(settingsStore.config.theme).toBe('dark');
});
it('Reset to Default reapplies the full baseline, api key included', () => {
settingsStore.initialize();
settingsStore.updateConfig('theme', 'light');