Files
RuneStone/tests/smoke/appearance/palettes.smoke.mjs
T
Knotty Wyvern 5bd616d7fd Give themes named color roles, theme data files, and file format 3
Phase 5a-1 and 5a-2.

- roles.ts names 51 color roles. One derivation rule fills the roles
  that a theme does not give, for all themes. tokens.css keeps only the
  root defaults, without theme blocks.
- Each built-in theme is one data file in src/lib/theme/themes/. No code
  outside the theme data names a theme ID. characterThemes.ts is gone.
- New roles: link, focus, on-accent, highlight, scrim, the syntax roles,
  and 16 terminal (ANSI) roles. Stray colors in components use the roles.
- contrast.ts checks each theme against the readability rules of
  docs/ui-color.md. The tests mark the known palette failures as todo,
  and a second test fails when a known failure starts to pass.
- Theme files use schema 3 with a mode and an optional built-in base.
  A short file gets the missing colors and fonts from the base. Schema 1
  and 2 files still import. Old syntax names convert on import.
- Docs: ui-color.md, plugin-development.md (theme tokens), ui-design.md,
  guides/themes.md, and UI-041 and UI-042 in design-decisions.md.

The applied colors stay the same for every built-in theme, except three
small changes: the conflict line uses the warn color, the Write
highlight uses the highlight role, and two dialog backdrops use the
scrim role.

pnpm check passes. pnpm test: 447 pass, 31 todo, 0 fail. Full smoke
suite: 93 passed, 2 known. appearance/palettes read the old syntax
names and passed 3 of 3 times after the fix. workspace/manageTemplates
failed one time and passed on retry.
2026-10-28 15:50:45 -07:00

166 lines
11 KiB
JavaScript

// Built-in palettes: modes, light-only Sakura, migration, persistence, typography, cross-window sync, source editor updates, and narrow settings.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("appearance/palettes", async ({ browser }) => {
const output = await outputDir("appearance/palettes");
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
await mockTauri(context, {
commands: test => ({
...test.workspace({
root: "C:\\appearance-smoke",
files: Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`])),
}),
plugins_snapshot: () => ({ root: "C:/appearance-smoke-plugins", plugins: [] }),
"plugin:window|is_maximized": () => false,
}),
});
const main = await openPage(context);
const settings = await openPage(context);
const secondSettings = await openPage(context);
const pages = [main, settings, secondSettings];
try {
await main.goto(smokeUrl);
await main.getByText("appearance-smoke", { exact: true }).waitFor();
async function openCode(index) {
await main.keyboard.press("Control+p");
await main.getByRole("textbox", { name: "Find a file" }).fill(`theme-${index}.py`);
await main.getByRole("dialog").getByRole("button").filter({ hasText: `theme-${index}.py` }).first().waitFor();
await main.getByRole("textbox", { name: "Find a file" }).press("Enter");
await main.locator(".source-editor .cm-content").waitFor();
await main.waitForFunction(file => document.querySelector(".editor .breadcrumb")?.textContent.endsWith(file)
&& document.querySelector(".source-editor .cm-content")?.dataset.language === "python", `theme-${index}.py`);
await main.locator(".source-editor .cm-line").filter({ hasText: `Theme sample ${index}` }).waitFor();
}
async function editorIds() {
// Mark each mounted editor once. A new editor has no mark, so it gets a new identifier.
return main.evaluate(() => [...document.querySelectorAll(".source-editor .cm-editor")]
.map(node => node.dataset.smokeId ||= String(window.__editorSerial = (window.__editorSerial || 0) + 1)));
}
// Wait until "RuneStone", "def", and "42" have three distinct syntax colors.
async function waitForSyntax() {
await main.waitForFunction(() => {
const spans = [...document.querySelectorAll(".source-editor .cm-line span")];
const colors = ["RuneStone", "def", "42"].map(text => {
const span = spans.find(node => !node.children.length && node.textContent.includes(text));
return span ? getComputedStyle(span).color : null;
});
return colors.every(Boolean) && new Set(colors).size === 3;
});
}
const themeName = (theme, mode) => theme === "sakura" ? "Sakura" : `${({ default: "RuneStone", claude: "Claude" })[theme]} ${mode === "light" ? "Light" : "Dark"}`;
const picker = (page, name) => page.locator(".picker").filter({ has: page.locator("svg") }).and(page.getByRole("button", { name, exact: true }));
async function choose(page, theme, mode) {
await picker(page, "Color theme").click();
await page.getByRole("menuitemradio", { name: themeName(theme, mode), exact: true }).click();
}
async function openAppearance(page) {
await page.goto(`${smokeUrl}/?settingsWindow=true`);
await page.getByRole("button", { name: "Appearance", exact: true }).click();
await picker(page, "Color theme").waitFor();
}
await openCode(0);
await openAppearance(settings);
await openAppearance(secondSettings);
async function expectAppearance(theme, mode) {
for (const page of [settings, secondSettings, main]) {
await page.waitForFunction(({ theme, mode }) => document.documentElement.dataset.palette === theme && document.documentElement.dataset.theme === mode, { theme, mode });
assert.equal(await page.evaluate(() => getComputedStyle(document.documentElement).colorScheme), mode);
}
assert.equal((await picker(secondSettings, "Color theme").textContent()).trim(), themeName(theme, mode));
await main.waitForFunction(() => {
const root = document.documentElement;
const probe = document.createElement("i");
probe.style.backgroundColor = getComputedStyle(root).getPropertyValue("--rs-workarea-editor-bg");
document.body.append(probe);
const expected = getComputedStyle(probe).backgroundColor;
probe.remove();
const surfaces = [...document.querySelectorAll(".source-editor .cm-editor")];
const workarea = document.querySelector(".editor > .body");
return surfaces.length > 0 && surfaces.every(element => getComputedStyle(element).backgroundColor === "rgba(0, 0, 0, 0)")
&& workarea && getComputedStyle(workarea).backgroundColor === expected;
});
return settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim());
}
let nextCode = 1;
const backgrounds = new Set();
for (const theme of ["default", "claude", "sakura"]) {
for (const mode of theme === "sakura" ? ["light"] : ["light", "dark"]) {
const before = await editorIds();
await choose(settings, theme, mode);
backgrounds.add(await expectAppearance(theme, mode));
assert.deepEqual(await editorIds(), before, "Existing source editors keep their identity when a theme changes");
await openCode(nextCode++);
assert.notDeepEqual(await editorIds(), before, "A new file creates a new source editor");
await expectAppearance(theme, mode);
await waitForSyntax();
assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme, mode });
await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}.png`) });
await main.screenshot({ path: path.join(output, `appearance-editor-${theme}-${mode}.png`) });
if (theme === "sakura") {
const keywordColor = await main.locator(".source-editor .cm-line span").evaluateAll(spans => {
const keyword = spans.find(span => !span.children.length && span.textContent.trim() === "def");
return keyword ? getComputedStyle(keyword).color : null;
});
assert.equal(keywordColor, "rgb(152, 85, 108)", "Sakura keywords use Plum Wine");
}
const typography = await settings.evaluate(() => ({
body: getComputedStyle(document.body).fontFamily,
heading: getComputedStyle(document.querySelector("h2")).fontFamily,
prose: getComputedStyle(document.documentElement).getPropertyValue("--rs-font-prose").trim(),
}));
if (theme === "claude") {
assert.match(typography.body, /Lora.*Georgia/);
assert.match(typography.prose, /Lora.*Georgia/);
assert.match(typography.heading, /Poppins.*Arial/);
assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim()), "#d97757");
} else assert.doesNotMatch(typography.body, /Lora|Georgia/);
console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new source editors`);
}
}
assert.equal(backgrounds.size, 5, "All supported combinations have distinct backgrounds");
await picker(settings, "Color theme").click();
assert.deepEqual(await settings.getByRole("menuitemradio").allTextContents(), ["RuneStone Light", "RuneStone Dark", "Claude Light", "Claude Dark", "Sakura", "Harvest Moon", "Crimson Pilot", "Silver Serpent"]);
await settings.keyboard.press("Escape");
assert.equal(await picker(settings, "Appearance").count(), 0);
assert.equal(await picker(secondSettings, "Appearance").count(), 0);
const sakura = await settings.evaluate(() => {
const css = getComputedStyle(document.documentElement);
return Object.fromEntries(["bg", "border", "selection", "bg-active", "syntax-keyword", "syntax-variable", "syntax-property", "syntax-constant", "syntax-punctuation"].map(key => [key, css.getPropertyValue(`--rs-${key}`).trim()]));
});
// The applied selection color caps its alpha at a6 so text backgrounds show through (appliedColors in src/lib/theme/contrast.ts).
assert.deepEqual(sakura, { bg: "#fefcfc", border: "#f8dbe6", selection: "#ffc9dca6", "bg-active": "#dbeacb", "syntax-keyword": "#98556c", "syntax-variable": "#618c71", "syntax-property": "#607fa9", "syntax-constant": "#687788", "syntax-punctuation": "#687788" });
for (const [theme, savedMode, expectedTheme, mode] of [
["gpt", "light", "default", "light"],
["terminal", "dark", "default", "dark"],
["sakura", "dark", "sakura", "light"],
]) {
await settings.evaluate(value => window.__TEST__.writeSettings("appearance", value), { theme, mode: savedMode });
await settings.reload();
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
await expectAppearance(expectedTheme, mode);
assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme: expectedTheme, mode });
console.log(`PASS: saved ${theme} ${savedMode} migrates to ${expectedTheme} ${mode}`);
}
for (const [theme, mode] of [["default", "dark"], ["claude", "light"], ["claude", "dark"], ["sakura", "light"]]) {
await settings.setViewportSize({ width: 1100, height: 780 });
await choose(settings, theme, mode);
await expectAppearance(theme, mode);
await settings.setViewportSize({ width: 360, height: 480 });
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "Narrow settings do not overflow the viewport");
assert(await settings.locator("dialog .content").evaluate(node => node.scrollWidth <= node.clientWidth), "Appearance controls do not overflow the content area");
const control = picker(settings, "Color theme");
await control.scrollIntoViewIfNeeded();
const bounds = await control.boundingBox();
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.height >= 28, "Color theme remains reachable at 360px");
await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}-360.png`) });
}
assert.deepEqual(pages.flatMap(page => page.errors), []);
} catch (error) {
for (const [index, page] of pages.entries()) await page.screenshot({ path: path.join(output, `appearance-failure-${index}.png`) }).catch(() => {});
throw error;
}
});