RuneStone 1.0.0

This commit is contained in:
Knotty Wyvern
2026-11-03 00:23:07 -07:00
commit 5557443ed1
818 changed files with 239368 additions and 0 deletions
@@ -0,0 +1,138 @@
// New-tab background images: large uploads, cross-window sync, reload, theme reuse, removal, picker menus, and narrow settings.
import assert from 'node:assert/strict';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
// The image is painted on .workarea-background, not on the empty tab (src/lib/theme/background.css).
// Background (src/lib/features/background/) loads after the first render, so each check waits for the image.
const waitForImage = page => page.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
await runSmoke('appearance/backgroundImages', async ({ browser }) => {
const output = await outputDir('appearance/backgroundImages');
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
await mockTauri(context, {
commands: test => {
const workspace = test.workspace({
root: 'C:\\host-todo-test',
files: {
'a.md': '# Note\n\nOriginal text.',
'.runestone/templates/Daily.md': '# Daily\n\n## Tasks',
'.runestone/marks.json': JSON.stringify({ pins: ['a.md'], bookmarks: ['a.md'], order: { '': ['a.md'] } }),
},
});
return {
...workspace,
workspace_list: args => workspace.workspace_list(args).filter(entry => entry.rel_path !== '.runestone'),
plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [] }),
'plugin:window|is_maximized': () => false,
};
},
});
const main = await openPage(context), settings = await openPage(context);
const imageInput = () => settings.getByLabel('Background image file', { exact: true });
const background = () => main.locator('.workarea-background').evaluate(node => /url\("(blob:[^"]+)"\)/.exec(getComputedStyle(node).backgroundImage)?.[1]);
const decoded = (page, url) => page.evaluate(async url => { const image = new Image(); image.src = url; await image.decode(); return image.naturalWidth; }, url);
const savedImageId = () => settings.evaluate(() => window.__TEST__.settings('appearance').newTabBackground.imageId);
const picker = name => settings.locator('.picker').and(settings.getByRole('button', { name, exact: true }));
await main.goto(smokeUrl); await main.locator('.empty').waitFor();
await settings.goto(smokeUrl + '/?settingsWindow=true');
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
const image = await main.evaluate(() => {
const canvas = document.createElement('canvas'); canvas.width = canvas.height = 700;
const ctx = canvas.getContext('2d'), pixels = ctx.createImageData(700, 700);
let seed = 23;
for (let i = 0; i < pixels.data.length; i++) { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; pixels.data[i] = i % 4 === 3 ? 255 : seed >>> 24; }
ctx.putImageData(pixels, 0, 0); return canvas.toDataURL();
});
const bytes = Buffer.from(image.split(',')[1], 'base64');
assert.ok(image.length > 2 ** 21 && bytes.length < 2_000_000, 'Fixture crosses the CSS limit but fits the upload limit');
await imageInput().setInputFiles({ name: 'large.png', mimeType: 'image/png', buffer: bytes });
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
let url = await background();
assert.equal(await decoded(main, url), 700, 'The actual new-tab image decodes');
await main.reload(); await main.locator('.empty').waitFor(); await waitForImage(main);
url = await background(); assert.equal(await decoded(main, url), 700, 'The saved image survives reload');
const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64');
const largeFile = path.join(output, '50MiB.png');
await writeFile(largeFile, Buffer.concat([pixel, Buffer.alloc(50 * 1024 * 1024 - pixel.length)]));
await imageInput().setInputFiles(largeFile);
await main.waitForFunction(old => /url\("(blob:[^"]+)"\)/.exec(getComputedStyle(document.querySelector('.workarea-background')).backgroundImage)?.[1] !== old, url);
url = await background(); assert.equal(await decoded(main, url), 1, '50 MiB image decodes');
assert.ok(await settings.evaluate(() => JSON.stringify(window.__TEST__.settings('appearance')).length < 500), 'Image bytes stay outside the settings file');
await main.reload(); await main.locator('.empty').waitFor(); await waitForImage(main);
url = await background(); assert.equal(await decoded(main, url), 1, '50 MiB image survives reload');
const acceptedId = await savedImageId();
const tooLargeFile = path.join(output, 'too-large.png');
await writeFile(tooLargeFile, Buffer.alloc(50 * 1024 * 1024 + 1));
await imageInput().setInputFiles(tooLargeFile);
await settings.getByRole('alert').filter({ hasText: '50 MiB' }).waitFor();
assert.equal(await savedImageId(), acceptedId);
assert.equal(await settings.locator('input[type=color]').count(), 0);
await settings.getByLabel('Image overlay', { exact: true }).fill('55');
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('0.55'));
await settings.getByLabel('Image overlay', { exact: true }).fill('-40');
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('255, 255, 255, 0.4'));
// A theme card chooses the theme and its light or dark mode together (src/lib/theme/ThemePicker.svelte).
for (const mode of ['dark', 'light']) {
await settings.getByRole('radio', { name: mode === 'dark' ? 'RuneStone Dark' : 'RuneStone Light', exact: true }).click();
await main.waitForFunction(mode => document.documentElement.dataset.theme === mode, mode);
assert.equal(await background(), url, 'Theme changes reuse the current image URL');
await main.screenshot({ path: `${output}/background-${mode}.png` });
// The image position menu is a shared menu of Appearance settings.
for (const name of ['Image position']) {
await picker(name).click();
const menu = settings.getByRole('menu', { name, exact: true });
assert.equal(await menu.evaluate(node => getComputedStyle(node).fontSize), '13px');
// Shared menu rows are 24px high (src/lib/theme/tokens.css:31, --rs-menu-row-height).
assert.equal(await menu.locator(':scope > button').first().evaluate(node => getComputedStyle(node).minHeight), '24px');
// The current choice shows a check mark in the icon column (src/lib/ui/actionMenu.ts).
assert.equal(await menu.locator('[aria-checked="true"] svg').count(), 1);
assert.equal(await menu.evaluate(node => { const reference = document.createElement('span'); reference.style.color = 'var(--rs-menu-border)'; node.append(reference); const matches = getComputedStyle(node).borderColor === getComputedStyle(reference).color; reference.remove(); return matches; }), true, 'Menu uses the shared border token');
assert.equal(await menu.evaluate(node => getComputedStyle(node).borderColor), 'rgba(0, 0, 0, 0)', 'Menus have no visible border');
await settings.screenshot({ path: `${output}/${name.replaceAll(' ', '-')}-${mode}.png` });
await settings.keyboard.press('Escape');
assert.equal(await picker(name).evaluate(node => node === document.activeElement), true);
}
}
await settings.setViewportSize({ width: 360, height: 480 });
await picker('Image position').scrollIntoViewIfNeeded();
await picker('Image position').click();
const box = await settings.getByRole('menu', { name: 'Image position', exact: true }).boundingBox();
assert.ok(box.x >= 0 && box.x + box.width <= 360 && box.y + box.height <= 480);
await settings.screenshot({ path: `${output}/menu-narrow.png` });
await settings.keyboard.press('Escape');
await settings.getByRole('button', { name: 'Remove image', exact: true }).click();
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage === 'none');
assert.equal(await main.evaluate(async url => { try { await fetch(url); return false; } catch { return true; } }, url), true, 'Removing an image releases its URL');
assert.equal(await settings.evaluate(async id => (await import('/src/lib/theme/backgroundImages.ts')).readBackgroundImage(id).then(Boolean), acceptedId), false, 'Removal deletes stored image bytes');
await settings.evaluate(async () => {
const external = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
external.pluginTools.update(items => [...items, ...Array.from({ length: 30 }, (_, index) => ({ owner: `test.plugin${index}`, id: 'settings', title: `Plugin settings ${index}`, kind: 'view', surface: 'settings' }))]);
});
for (const theme of ['light', 'dark']) {
await settings.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); window.dispatchEvent(new Event('focus')); }, theme);
await settings.setViewportSize({ width: 360, height: 600 });
assert.equal(await settings.getByRole('navigation', { name: 'Settings categories' }).getByRole('button').count() >= 34, true);
assert.equal(await settings.locator('.content').evaluate(node => node.clientHeight > 240 && node.clientWidth > 300), true, 'Long navigation leaves room for settings');
await settings.screenshot({ path: `${output}/long-plugin-list-${theme}-narrow.png` });
await main.setViewportSize({ width: 600, height: 700 });
await main.keyboard.press('F1');
await main.getByRole('dialog', { name: 'Help and about' }).waitFor();
// The shortcut list is open by default (src/lib/layout/SettingsDialog.svelte).
assert.equal(await main.locator('.help-card details[open]').count(), 1);
await main.locator('.help-card summary').first().focus(); await main.keyboard.press('Enter');
assert.equal(await main.locator('.help-card details[open]').count(), 2);
await main.keyboard.press('Enter');
await main.screenshot({ path: `${output}/help-${theme}-narrow.png` });
await main.getByRole('button', { name: 'Close help', exact: true }).click();
}
assert.deepEqual([...main.errors, ...settings.errors], []);
console.log('PASS: large image upload, decoding, cross-window sync, reload, theme reuse, removal, shared menu dimensions, keyboard dismissal, and narrow viewport.');
});