char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
521a64cd0
char/aliceai-t5-moe
1import { CONFIG_LOCALSTORAGE_KEY } from '$lib/constants' ; 2import { serverStore } from '$lib/stores/server.svelte' ; 3import { settingsStore } from '$lib/stores/settings/index.svelte' ; 4import { beforeEach , describe , expect , it } from 'vitest' ; 5 6function mockProps ( uiSettings :Record < string , string | number | boolean >) { 7Object . defineProperty ( serverStore , 'props' , { 8configurable :true , 9get :() => 10({ 11default_generation_settings :{ params :{ temperature :0.8 } }, 12ui_settings :uiSettings 13}) as unknown as typeof serverStore . props 14}); 15} 16 17describe ( 'server ui_settings application semantics' , () => { 18beforeEach (() => { 19localStorage . removeItem ( CONFIG_LOCALSTORAGE_KEY ); 20}); 21 22it ( 'applies the admin defaults once for a new user' , () => { 23settingsStore . initialize (); 24mockProps ({ apiKey :'' , theme :'dark' }); 25 26settingsStore . syncWithServerDefaults (); 27 28expect ( settingsStore . config . theme ). toBe ( 'dark' ); 29}); 30 31it ( 'never reapplies on later loads: the user config diverges freely' , () => { 32settingsStore . initialize (); 33settingsStore . updateConfig ( 'theme' , 'light' ); 34settingsStore . updateConfig ( 'apiKey' , 'sk-user-key' ); 35 36// simulated F5: config now exists in localStorage 37settingsStore . initialize (); 38mockProps ({ apiKey :'' , theme :'dark' }); 39 40settingsStore . syncWithServerDefaults (); 41settingsStore . syncWithServerDefaults (); 42 43expect ( settingsStore . config . theme ). toBe ( 'light' ); 44expect ( settingsStore . config . apiKey ). toBe ( 'sk-user-key' ); 45const stored = JSON . parse ( localStorage . getItem ( CONFIG_LOCALSTORAGE_KEY ) ?? '{}' ); 46 47expect ( stored . apiKey ). toBe ( 'sk-user-key' ); 48}); 49 50it ( 'keeps a value the user sets before the baseline is reachable' , () => { 51settingsStore . initialize (); 52// the splash is the only way in when the server runs with --api-key, 53// so the first user write lands before the first successful /props 54settingsStore . updateConfig ( 'apiKey' , 'sk-user-key' ); 55mockProps ({ apiKey :'admin-placeholder' , theme :'dark' }); 56 57settingsStore . syncWithServerDefaults (); 58 59expect ( settingsStore . config . apiKey ). toBe ( 'sk-user-key' ); 60expect ( settingsStore . config . theme ). toBe ( 'dark' ); 61}); 62 63it ( 'Reset to Default reapplies the full baseline, api key included' , () => { 64settingsStore . initialize (); 65settingsStore . updateConfig ( 'theme' , 'light' ); 66settingsStore . updateConfig ( 'apiKey' , 'sk-user-key' ); 67mockProps ({ apiKey :'' , theme :'dark' }); 68 69settingsStore . forceSyncWithServerDefaults (); 70 71expect ( settingsStore . config . theme ). toBe ( 'dark' ); 72expect ( settingsStore . config . apiKey ). toBe ( '' ); 73}); 74}); 75 76describe ( 'syncable scope (spec section 4)' , () => { 77it ( 'sampling params keep their live server twin, ui settings carry none' , async () => { 78const { ParameterSyncService} = await import ( '$lib/services/parameter-sync.service' ); 79 80expect ( ParameterSyncService . canSyncParameter ( 'temperature' )). toBe ( true ); 81expect ( ParameterSyncService . canSyncParameter ( 'samplers' )). toBe ( true ); 82expect ( ParameterSyncService . canSyncParameter ( 'theme' )). toBe ( false ); 83expect ( ParameterSyncService . canSyncParameter ( 'systemMessage' )). toBe ( false ); 84expect ( ParameterSyncService . canSyncParameter ( 'apiKey' )). toBe ( false ); 85expect ( ParameterSyncService . canSyncParameter ( 'customCss' )). toBe ( false ); 86}); 87});