char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Stores split refactor (#27240)521a64cd0

char/aliceai-t5-moe
2.5 KiB64 linesraw
1// Guards the unfolding of `renderContentAsRawText` back onto the two
2// per-surface render keys. The single toggle carried user content and
3// thinking at once, so only the user key is restored from it and thinking
4// returns to its own default. The toggle is removed from the persisted
5// config so it does not stay orphaned in localStorage.
6
7import { CONFIG_LOCALSTORAGE_KEY } from '$lib/constants';
8import { MigrationService } from '$lib/services/migration.service';
9import { settingsStore } from '$lib/stores/settings/index.svelte';
10import { beforeEach, describe, expect, it } from 'vitest';
11
12const RENDER_KEYS_MIGRATION_ID = 'render-keys-unfold-v1';
13
14async function seedConfig(stored: Record<string, unknown>) {
15	localStorage.setItem(CONFIG_LOCALSTORAGE_KEY, JSON.stringify(stored));
16
17	const migration = MigrationService.getMigrations().find((m) => m.id === RENDER_KEYS_MIGRATION_ID);
18
19	await migration?.run();
20	settingsStore.initialize();
21}
22
23function persisted(): Record<string, unknown> {
24	return JSON.parse(localStorage.getItem(CONFIG_LOCALSTORAGE_KEY) ?? '{}');
25}
26
27describe('renderContentAsRawText unfolding', () => {
28	beforeEach(() => {
29		localStorage.removeItem(CONFIG_LOCALSTORAGE_KEY);
30		MigrationService.resetState();
31		settingsStore.initialize();
32	});
33
34	it('maps raw text to user content as plain text', async () => {
35		await seedConfig({ renderContentAsRawText: true });
36		expect(settingsStore.config.renderUserContentAsMarkdown).toBe(false);
37	});
38
39	it('maps markdown to user content as markdown', async () => {
40		await seedConfig({ renderContentAsRawText: false });
41		expect(settingsStore.config.renderUserContentAsMarkdown).toBe(true);
42	});
43
44	it('leaves thinking on its own default', async () => {
45		await seedConfig({ renderContentAsRawText: true });
46		expect(settingsStore.config.renderThinkingAsMarkdown).toBe(true);
47	});
48
49	it('keeps an explicit user preference over the toggle', async () => {
50		await seedConfig({ renderContentAsRawText: true, renderUserContentAsMarkdown: true });
51		expect(settingsStore.config.renderUserContentAsMarkdown).toBe(true);
52	});
53
54	it('drops the toggle from the persisted config', async () => {
55		await seedConfig({ renderContentAsRawText: true });
56		expect(persisted().renderContentAsRawText).toBeUndefined();
57	});
58
59	it('leaves both surfaces on markdown when nothing is stored', async () => {
60		await seedConfig({});
61		expect(settingsStore.config.renderUserContentAsMarkdown).toBe(true);
62		expect(settingsStore.config.renderThinkingAsMarkdown).toBe(true);
63	});
64});