The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
test(window): Bug D recovery unit tests (reset data-safety + XSS escape)
purple5adb7a4a73fc
diff --git a/src/lib/__tests__/fatal-error.test.ts b/src/lib/__tests__/fatal-error.test.tsnew file mode 100644index 00000000..2fda0824--- /dev/null+++ b/src/lib/__tests__/fatal-error.test.ts@@ -0,0 +1,41 @@+/**+ * Bug D (surfingbird1010) — boot-failure recovery (fatal-error.ts).+ *+ * Critical safety properties (env: node — no DOM): a "Reset settings" recovery+ * must clear app settings but NEVER user DATA (chats, knowledge, curated+ * memory), and the error text shown in the recovery screen must be escaped (no+ * HTML injection). The DOM render itself is verified live (app launch) — here we+ * lock the data-safety + escaping logic.+ *+ * Run: npx vitest run src/lib/__tests__/fatal-error.test.ts+ */+import { describe, it, expect } from 'vitest'+import { SETTINGS_STORAGE_KEYS, escapeHtml } from '../fatal-error'++describe('SETTINGS_STORAGE_KEYS (Bug D reset safety)', () => {+ it('includes the settings/state stores', () => {+ for (const k of ['chat-settings', 'lu-providers', 'locally-uncensored-voice'])+ expect(SETTINGS_STORAGE_KEYS).toContain(k)+ })++ it('NEVER includes user-DATA stores (chats / knowledge / memory)', () => {+ for (const dataKey of ['chat-conversations', 'rag-store', 'locally-uncensored-memory']) {+ expect(SETTINGS_STORAGE_KEYS).not.toContain(dataKey)+ }+ })+})++describe('escapeHtml (Bug D recovery-screen XSS safety)', () => {+ it('escapes angle brackets, quotes and ampersands', () => {+ expect(escapeHtml('<img src=x onerror=alert(1)>')).toBe(+ '<img src=x onerror=alert(1)>',+ )+ expect(escapeHtml(`a & "b" 'c'`)).toBe('a & "b" 'c'')+ })++ it('leaves plain text unchanged', () => {+ expect(escapeHtml('hydration boom: cannot read x of undefined')).toBe(+ 'hydration boom: cannot read x of undefined',+ )+ })+})diff --git a/src/lib/fatal-error.ts b/src/lib/fatal-error.tsindex ba0f644b..5bacd89b 100644--- a/src/lib/fatal-error.ts+++ b/src/lib/fatal-error.ts@@ -58,7 +58,7 @@ export function resetSettingsAndReload(): void {}}-function escapeHtml(s: string): string {+export function escapeHtml(s: string): string {return s.replace(/[&<>"']/g, (c) =>({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c] as string),)