Reduce anti-slop findings in Persistence (#2953)

* chore(ui): reduce persistence anti-slop findings

* test(ui): cover fallback settings response

* fix(ui): preserve usage model group contract
This commit is contained in:
Bohdan Triapitsyn
2026-08-16 19:21:35 +03:00
committed by GitHub
parent bfa0f9ee2a
commit 7ef6441bf3
2 changed files with 55 additions and 17 deletions
+41
View File
@@ -241,6 +241,47 @@ describe('updateDesktopSettings', () => {
}
});
test('sanitizes a successful fallback settings response before applying it', async () => {
const previousFetch = globalThis.fetch;
const fallbackFetch: typeof fetch = async () => new Response(JSON.stringify({ terminalShell: 'zsh' }), {
headers: { 'Content-Type': 'application/json' },
});
try {
globalThis.fetch = fallbackFetch;
useUIStore.getState().setTerminalShell('fish');
await updateDesktopSettings({ terminalShell: 'zsh' });
expect(useUIStore.getState().terminalShell).toBe('zsh');
expect(getSettingsSaveState()).toBe('idle');
} finally {
globalThis.fetch = previousFetch;
}
});
test('reports an error without applying a malformed fallback settings response', async () => {
const previousFetch = globalThis.fetch;
const fallbackFetch: typeof fetch = async () => new Response(JSON.stringify('ok'), {
headers: { 'Content-Type': 'application/json' },
});
const states: string[] = [];
const unsubscribe = subscribeToSettingsSaveState(() => {
states.push(getSettingsSaveState());
});
try {
globalThis.fetch = fallbackFetch;
useUIStore.getState().setTerminalShell('fish');
await updateDesktopSettings({ terminalShell: 'zsh' });
expect(useUIStore.getState().terminalShell).toBe('fish');
expect(states).toEqual(['saving', 'error']);
} finally {
unsubscribe();
globalThis.fetch = previousFetch;
}
});
test('drains a pending save to the previous runtime and ignores its stale response', async () => {
switchRuntimeEndpoint({ apiBaseUrl: 'https://settings-a.example', runtimeKey: 'settings-a' });
const saveResult = deferred<SettingsPayload>();