feat(migration): add v4-to-v5 settings migration runner with backup

This commit is contained in:
2026-06-08 06:16:17 +05:30
parent 9f4bfbdfee
commit c62070304f
5 changed files with 143 additions and 1 deletions
@@ -0,0 +1,32 @@
import { describe, expect, test } from 'vitest';
import { migrateV4ToV5, v4SettingsSchema } from '@/lib/migrations/v4-to-v5';
describe('migrateV4ToV5', () => {
test('maps theme auto to system', () => {
const out = migrateV4ToV5({ theme: 'auto', editorFontSize: 14 });
expect(out.theme).toBe('system');
expect(out.editorFontSize).toBe(14);
});
test('drops unknown keys, applies defaults', () => {
const out = migrateV4ToV5({ theme: 'light', weirdKey: 1 });
expect(out.theme).toBe('light');
expect(out.weirdKey).toBeUndefined();
expect(out.tabSize).toBe(4); // default
});
test('throws on invalid v4 input', () => {
expect(() => migrateV4ToV5({ theme: 42 })).toThrow();
});
test('is idempotent — running twice yields the same v5 output', () => {
const v4 = { theme: 'dark', editorFontSize: 16, recentFiles: ['/a.md'] };
const a = migrateV4ToV5(v4);
const b = migrateV4ToV5(v4);
expect(a).toEqual(b);
});
test('exposes the v4 schema for use by main', () => {
expect(v4SettingsSchema).toBeDefined();
});
});