- Move the Terminal plugin into src/lib/features/terminal/ on the host Svelte runtime, with xterm 6.0.0 and addon-fit 0.11.0. - Buttons, shortcuts, Help rows, and the close guard follow the Terminal switch. The first use loads the module. - Add Settings → Terminal and the terminal settings section. The first start copies the old runestone.terminal key. - The 16 ANSI colors come from the --rs-ansi-* tokens. - Off asks first when a shell runs in any window (pty_running). - Rust: no pty-data or pty-exit events, an owner check for write, resize, and close, output joined up to 64 KiB or 8 ms, and the sessions of a reloaded page close. - Remove api.pty, the terminal contribution, TerminalSlot, and the plugin loader of the smoke harness. - Check only the tested switches in the Background smoke test. - Update the tests, the menu inventory, the docs, and UI-058.
72 lines
4.1 KiB
TypeScript
72 lines
4.1 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { migrateLegacyPreferences } from '../../../src/lib/settings/migration.ts';
|
|
import { LEGACY_KEYS } from '../../../src/lib/settings/store.ts';
|
|
|
|
const palette = { bg: '#123', text: '#abcdef', accent: '#AABBCC' };
|
|
const reader = (values: Record<string, string>) => (key: string) => Object.hasOwn(values, key) ? values[key] : null;
|
|
|
|
test('Migration reads the four old keys and the theme backup, and normalizes each value', () => {
|
|
const custom = { schema: 2, id: 'night', name: 'Night', colors: { ...palette, bg: '#000000' } };
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.settings': JSON.stringify({ autosaveEnabled: false, autosaveSeconds: 900, extra: true }),
|
|
'runestone.appearance': JSON.stringify({ theme: 'custom:night', mode: 'light', transparency: { amount: 140 } }),
|
|
'runestone.custom-themes': JSON.stringify([custom, { schema: 2, id: '../bad' }]),
|
|
'runestone.custom-themes.legacy': JSON.stringify([{ schema: 1, id: 'kept' }]),
|
|
'runestone.language': 'fr',
|
|
}));
|
|
assert.deepEqual(sections, {
|
|
general: { autosaveEnabled: false, autosaveSeconds: 5, showInternalFolder: false, tableFormulas: true, showFileTitle: true, keepLineBreaks: false },
|
|
language: 'fr',
|
|
customThemes: [{ ...custom, schema: 3, mode: 'dark' }],
|
|
customThemesLegacy: [{ schema: 1, id: 'kept' }],
|
|
// The mode comes from the migrated custom theme, not from a store that is still empty.
|
|
appearance: { theme: 'custom:night', mode: 'dark', transparency: { enabled: true, amount: 100 } },
|
|
});
|
|
});
|
|
|
|
test('Migration of version 1 themes keeps the saved palette and adds the originals to the backup once', () => {
|
|
const legacy = { schema: 1, id: 'old', name: 'Old', light: { ...palette, bg: '#fff' }, dark: palette };
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.appearance': JSON.stringify({ theme: 'custom:old', mode: 'light' }),
|
|
'runestone.custom-themes': JSON.stringify([legacy]),
|
|
'runestone.custom-themes.legacy': JSON.stringify([legacy]),
|
|
}));
|
|
assert.deepEqual(sections.customThemes, [{ schema: 3, id: 'old', name: 'Old', mode: 'light', colors: legacy.light }]);
|
|
assert.deepEqual(sections.customThemesLegacy, [legacy]);
|
|
assert.deepEqual(sections.appearance, { theme: 'custom:old', mode: 'light' });
|
|
});
|
|
|
|
test('Missing keys give no sections, so the defaults apply', () => {
|
|
assert.deepEqual(migrateLegacyPreferences(() => null), {});
|
|
assert.deepEqual(migrateLegacyPreferences(() => { throw new Error('Storage unavailable'); }), {});
|
|
});
|
|
|
|
test('Damaged old values become defaults and unknown languages become English', () => {
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.settings': '{broken',
|
|
'runestone.appearance': '[1, 2]',
|
|
'runestone.custom-themes': '{"not":"a list"}',
|
|
'runestone.language': 'de',
|
|
}));
|
|
assert.deepEqual(sections, {
|
|
general: { autosaveEnabled: true, autosaveSeconds: 5, showInternalFolder: false, tableFormulas: true, showFileTitle: true, keepLineBreaks: false },
|
|
language: 'en',
|
|
appearance: { theme: 'default', mode: 'dark' },
|
|
});
|
|
});
|
|
|
|
test('Migration keeps renamed theme IDs and a background image data URL', () => {
|
|
const image = 'data:image/png;base64,' + 'A'.repeat(40);
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.appearance': JSON.stringify({ theme: 'holo', mode: 'dark', newTabBackground: { image, overlay: 0.4 } }),
|
|
}));
|
|
assert.deepEqual(sections.appearance, { theme: 'harvest-moon', mode: 'dark', newTabBackground: { image, overlay: 0.4, position: 'center', size: 'cover' } });
|
|
});
|
|
|
|
test('Every section has one old key', () => {
|
|
// `runestone.features` and `runestone.background` came after the settings file. Only the browser preview uses them.
|
|
// `runestone.terminal` is the key of the Terminal plugin. The first start of the Terminal feature copies it into the file.
|
|
assert.deepEqual(Object.values(LEGACY_KEYS).sort(), ['runestone.appearance', 'runestone.background', 'runestone.custom-themes', 'runestone.custom-themes.legacy', 'runestone.features', 'runestone.language', 'runestone.settings', 'runestone.terminal']);
|
|
});
|