diff --git a/package.json b/package.json index e28fa7c..6c14618 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:installer": "node scripts/buildInstaller.mjs", "preview": "vite preview", "prepare": "svelte-kit sync || echo ''", - "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json && svelte-check --tsconfig ./tsconfig.plugins.json", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "check:menus": "node scripts/menuSurfaceAudit.mjs", "tauri": "tauri", diff --git a/scripts/appearance.spec.ts b/scripts/appearance.spec.ts index b21bd49..4f72c97 100644 --- a/scripts/appearance.spec.ts +++ b/scripts/appearance.spec.ts @@ -85,3 +85,22 @@ test('Saved image layout restores valid choices and rejects CSS injection', () = assert.deepEqual(invalid.newTabBackground, { imageId, position: 'center', size: 'cover', overlay: 0 }); assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId } }).newTabBackground, { imageId, overlay: 0, position: 'center', size: 'cover' }); }); + +test('New tab backgrounds keep supported image data and reject active or remote content', () => { + const value = { theme: 'claude', mode: 'light', newTabBackground: { image: 'data:image/png;base64,YQ==', overlay: 0, position: 'center', size: 'cover' } }; + assert.deepEqual(parseAppearance(JSON.stringify(value)), value); + for (const image of ['https://example.com/photo.png', 'javascript:alert(1)', 'data:image/svg+xml;base64,YQ==', 'data:image/png;base64,' + 'A'.repeat(3_000_000)]) { + assert.equal(normalizeAppearance({ ...value, newTabBackground: { color: '#224466', image } }).newTabBackground, undefined); + } + assert.equal(normalizeAppearance({ ...value, newTabBackground: { color: 'red' } }).newTabBackground, undefined); + assert.equal(normalizeAppearance({ ...value, newTabBackground: undefined }).newTabBackground, undefined); +}); + +test('Background image references clamp the overlay and discard obsolete colors', () => { + const imageId = 'd10adda6-a2ec-4d73-a0a6-2cb1ed43bebc'; + const layout = { position: 'center', size: 'cover' }; + assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, color: '#224466', overlay: 3 } }).newTabBackground, { imageId, overlay: 1, ...layout }); + assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, overlay: -3 } }).newTabBackground, { imageId, overlay: -1, ...layout }); + assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, overlay: NaN } }).newTabBackground, { imageId, overlay: 0, ...layout }); + assert.equal(normalizeAppearance({ newTabBackground: { imageId: 'invalid' } }).newTabBackground, undefined); +}); diff --git a/scripts/hostTodo.spec.mjs b/scripts/hostTodo.spec.mjs deleted file mode 100644 index ad8f480..0000000 --- a/scripts/hostTodo.spec.mjs +++ /dev/null @@ -1,33 +0,0 @@ -import { test } from 'node:test'; -import assert from 'node:assert/strict'; -import { normalizeAppearance, parseAppearance, exportAppearanceTheme } from '../src/lib/theme/appearance.ts'; - -test('New tab backgrounds retain supported data while rejecting active and remote content', () => { - const value = { theme: 'claude', mode: 'light', newTabBackground: { image: 'data:image/png;base64,YQ==', overlay: 0 } }; - assert.deepEqual(parseAppearance(JSON.stringify(value)), value); - for (const image of ['https://example.com/photo.png', 'javascript:alert(1)', 'data:image/svg+xml;base64,YQ==', 'data:image/png;base64,' + 'A'.repeat(3_000_000)]) { - assert.equal(normalizeAppearance({ ...value, newTabBackground: { color: '#224466', image } }).newTabBackground, undefined); - } - assert.equal(normalizeAppearance({ ...value, newTabBackground: { color: 'red' } }).newTabBackground, undefined); - assert.equal(normalizeAppearance({ ...value, newTabBackground: undefined }).newTabBackground, undefined); -}); -test('Background storage references retain overlay limits and discard obsolete colors', () => { - const imageId = 'd10adda6-a2ec-4d73-a0a6-2cb1ed43bebc'; - assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, color: '#224466', overlay: 3 } }).newTabBackground, { imageId, overlay: 1 }); - assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, overlay: -3 } }).newTabBackground, { imageId, overlay: -1 }); - assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, overlay: NaN } }).newTabBackground, { imageId, overlay: 0 }); - assert.equal(normalizeAppearance({ newTabBackground: { imageId: 'invalid' } }).newTabBackground, undefined); -}); - -test('Export follows the selected built-in palette and can be imported as a custom theme', async () => { - const { parseCustomTheme } = await import('../src/lib/theme/customThemes.ts'); - globalThis.localStorage = { getItem: () => null }; - try { - const claude = exportAppearanceTheme('claude'); - assert.equal(claude.light.bg, '#faf9f5'); - assert.equal(claude.dark.accent, '#d97757'); - assert.deepEqual(parseCustomTheme(claude), claude); - const sakura = exportAppearanceTheme('sakura'); - assert.deepEqual(sakura.light, sakura.dark); - } finally { delete globalThis.localStorage; } -}); diff --git a/scripts/installerVersion.spec.ts b/scripts/installerVersion.spec.ts index add047d..5c4b638 100644 --- a/scripts/installerVersion.spec.ts +++ b/scripts/installerVersion.spec.ts @@ -4,6 +4,7 @@ import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { spawnSync } from 'node:child_process'; +import { existsSync } from 'node:fs'; import { releaseVersion, nextHotfix, compareReleases } from './releaseVersion.mjs'; const ordering = ['0.1.22z', '0.1.23', '0.1.23a', '0.1.23b', '0.1.23c', '0.1.23z', '0.1.23aa', '0.1.23ab', '0.1.23zz', '0.1.23aaa', '0.1.24']; @@ -15,7 +16,10 @@ test('hotfix versions retain their release identity and advance in letter order' for (let i = 0; i < ordering.length; i++) for (let j = 0; j < ordering.length; j++) assert.equal(compareReleases(ordering[i], ordering[j]), Math.sign(i - j)); }); -test('the native NSIS comparator blocks older hotfixes and permits reinstall', { skip: process.platform !== 'win32' }, async () => { +const makensis = path.join(process.env.LOCALAPPDATA ?? '', 'tauri/NSIS/makensis.exe'); +const nsisSkip = process.platform !== 'win32' ? 'Windows only' : existsSync(makensis) ? false : 'the NSIS compiler is missing; run pnpm build:installer once to download it'; + +test('the native NSIS comparator blocks older hotfixes and permits reinstall', { skip: nsisSkip }, async () => { const root = await mkdtemp(path.join(tmpdir(), 'runestone-installer-version-')); try { const checks: string[] = []; @@ -31,7 +35,7 @@ test('the native NSIS comparator blocks older hotfixes and permits reinstall', { const source = `Unicode true\nSilentInstall silent\nRequestExecutionLevel user\nName "RuneStone version check"\nOutFile "${executable}"\n!include LogicLib.nsh\n!include WordFunc.nsh\n!include "${path.resolve('src-tauri/windows/versionCompare.nsh')}"\nSection\n${checks.join('\n')}\nSetErrorLevel 0\nSectionEnd\n`; const script = path.join(root, 'compare.nsi'); await writeFile(script, source); - const compiler = path.join(process.env.LOCALAPPDATA!, 'tauri/NSIS/makensis.exe'); + const compiler = makensis; const built = spawnSync(compiler, ['/V2', script], { encoding: 'utf8', windowsHide: true }); assert.equal(built.status, 0, built.stdout + built.stderr); const checked = spawnSync(executable, ['/S'], { encoding: 'utf8', windowsHide: true, timeout: 30000 }); @@ -39,7 +43,8 @@ test('the native NSIS comparator blocks older hotfixes and permits reinstall', { const patched = spawnSync('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', path.resolve('scripts/setWindowsVersion.ps1'), '-Path', executable, '-Version', '0.1.23a', '-NumericVersion', '0.1.23.1'], { encoding: 'utf8', windowsHide: true }); assert.equal(patched.status, 0, patched.stdout + patched.stderr); assert.match(patched.stdout, /0\.1\.23a/); - const template = await readFile('src-tauri/windows/installer.nsi', 'utf8'); + // Git can check the template out with CRLF line endings on Windows. + const template = (await readFile('src-tauri/windows/installer.nsi', 'utf8')).replaceAll('\r\n', '\n'); assert.ok(template.includes('Call RuneStoneCompareVersions')); assert.ok(!template.includes('nsis_tauri_utils::SemverCompare')); assert.match(template, /SetErrorLevel 2\n\s+Quit/); diff --git a/scripts/plugins.spec.ts b/scripts/plugins.spec.ts index 55a31e6..745e7a9 100644 --- a/scripts/plugins.spec.ts +++ b/scripts/plugins.spec.ts @@ -2,8 +2,12 @@ import test from "node:test"; import assert from "node:assert/strict"; import { ContributionRegistry, pluginHost } from "../src/lib/plugins/registry.ts"; import { ExternalSession } from "../src/lib/plugins/externalSession.ts"; -// @ts-ignore The compiled package is generated by pnpm build:plugins. -import { activate } from "../plugin-packages/table-formulas/main.js"; +import { existsSync } from "node:fs"; +// The Table Formulas package comes from a sibling repository. Run `pnpm build:plugins` to build it. +const tableFormulasEntry = new URL("../plugin-packages/table-formulas/main.js", import.meta.url); +const tableFormulas = existsSync(tableFormulasEntry) ? await import(tableFormulasEntry.href) : undefined; +const activate = tableFormulas?.activate; +const needsTableFormulas = { skip: tableFormulas ? false : "the Table Formulas package is not built; run pnpm build:plugins" }; import { renderMarkdownHtml, renderMarkdownSections } from "../src/lib/workspace/noteHtml.ts"; import type { PluginApi } from "../src/lib/plugins/sdk.ts"; @@ -34,7 +38,7 @@ test("optional workspace creation and reads stop when the plugin is disabled", a assert.throws(() => api.workspace.readOptional!("board.json"), /disabled/); assert.equal(files.size, 1); }); -test("core starts without optional features and formula packages preserve source when stopped", async () => { +test("core starts without optional features and formula packages preserve source when stopped", needsTableFormulas, async () => { assert.equal(pluginHost.get("terminal"), undefined); assert.equal(pluginHost.get("tableFormulas"), undefined); const source = "| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n"; @@ -55,7 +59,7 @@ test("core starts without optional features and formula packages preserve source await next.stop(); }); -test("package contribution conflicts preserve the first owner and revoke access before cleanup", async () => { +test("package contribution conflicts preserve the first owner and revoke access before cleanup", needsTableFormulas, async () => { const registry = new ContributionRegistry(); const first = new ExternalSession("first", services, () => {}, () => {}, registry); const second = new ExternalSession("second", services, () => {}, () => {}, registry); @@ -72,7 +76,7 @@ test("package contribution conflicts preserve the first owner and revoke access await first.stop(); }); -test("partial activation and failed cleanup cannot retain feature contributions", async () => { +test("partial activation and failed cleanup cannot retain feature contributions", needsTableFormulas, async () => { const registry = new ContributionRegistry(); const session = new ExternalSession("failed", services, () => {}, () => {}, registry); await assert.rejects(session.start({ activate(api) { diff --git a/scripts/tableFormulas.spec.ts b/scripts/tableFormulas.spec.ts index c3f0eb5..c70c036 100644 --- a/scripts/tableFormulas.spec.ts +++ b/scripts/tableFormulas.spec.ts @@ -1,20 +1,24 @@ import assert from "node:assert/strict"; import test, { before, after } from "node:test"; import { ExternalSession } from "../src/lib/plugins/externalSession.ts"; -// @ts-ignore The compiled package is generated by pnpm build:plugins. -import { activate } from "../plugin-packages/table-formulas/main.js"; +import { existsSync } from "node:fs"; +// The Table Formulas package comes from a sibling repository. Run `pnpm build:plugins` to build it. +const tableFormulasEntry = new URL("../plugin-packages/table-formulas/main.js", import.meta.url); +const tableFormulas = existsSync(tableFormulasEntry) ? await import(tableFormulasEntry.href) : undefined; +const activate = tableFormulas?.activate; +const needsTableFormulas = { skip: tableFormulas ? false : "the Table Formulas package is not built; run pnpm build:plugins" }; const session = new ExternalSession("runestone.table-formulas", { workspace: { list: async () => [], read: async () => "", write: async () => {} }, settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() }, }, () => {}, () => {}); -before(() => session.start({ activate })); -after(() => session.stop()); +before(() => activate && session.start({ activate })); +after(() => activate && session.stop()); import { tableCellMarkdown } from "../src/lib/editor/tableCellMarkdown.ts"; import { renderMarkdownHtml, renderMarkdownSections } from "../src/lib/workspace/noteHtml.ts"; -test("Markdown rendering isolates tables and preserves literal, formatted, and non-table text", () => { +test("Markdown rendering isolates tables and preserves literal, formatted, and non-table text", needsTableFormulas, () => { const source = "| X | Y | Result |\r\n| --- | --- | --- |\r\n| 9 | 10 | =AVERAGE(A2:B2) |\r\n\r\n| X | Y | Result |\r\n| --- | --- | --- |\r\n| 1 | 3 | =A2*B2 |\r\n"; const html = renderMarkdownHtml(source, new Map()); assert.match(html, /aria-label="=AVERAGE\(A2:B2\) → 9.5">9.5<\/span>/); @@ -30,7 +34,7 @@ test("Markdown rendering isolates tables and preserves literal, formatted, and n assert.match(hostile, /#ERROR!/); }); -test("editing keeps formulas readable and code or explicit escapes literal", () => { +test("editing keeps formulas readable and code or explicit escapes literal", needsTableFormulas, () => { const doc = (text: string, marks?: { type: string }[]) => ({ type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text, marks }] }] }); assert.equal(tableCellMarkdown(doc("=SUM($B$2:C2)*50%")), "=SUM($B$2:C2)*50%"); assert.equal(tableCellMarkdown(doc("\\=1+2")), "\\=1+2"); diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 634d23d..ac55adb 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,4 +1,7 @@ fn main() { + // tauri-build requires every bundle resource to exist. `pnpm browser:stage` fills this + // folder for installers. An empty folder lets `cargo test` and `tauri dev` run without it. + std::fs::create_dir_all("browser-engine").expect("failed to create browser-engine"); tauri_build::try_build( tauri_build::Attributes::new().app_manifest( tauri_build::AppManifest::new().commands(&[ diff --git a/tsconfig.plugins.json b/tsconfig.plugins.json deleted file mode 100644 index 5dbac50..0000000 --- a/tsconfig.plugins.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { "types": ["svelte", "vite/client"] }, - "include": ["src/**/*.d.ts", "plugins/**/*.ts", "plugins/**/*.svelte"] -}