import assert from 'node:assert/strict'; import { mkdir } from 'node:fs/promises'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'playwright'); const origin = process.env.SMOKE_URL || 'http://127.0.0.1:1420'; const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) }); const errors = []; await mkdir('.audit/host-ui', { recursive: true }); try { const context = await browser.newContext({ viewport: { width: 1100, height: 800 } }); await context.addInitScript(() => { window.isTauri = true; const root = "C:\\appearance-smoke"; const files = new Map(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`])); const callbacks = new Map(); let sequence = 0; window.__TAURI_INTERNALS__ = { metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } }, transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; }, unregisterCallback: id => callbacks.delete(id), invoke: async (command, args = {}) => { if (command === "plugins_snapshot") return { root: "C:/appearance-smoke-plugins", plugins: [] }; if (command === "workspace_last_path") return root; if (command === "workspace_open") return { root, name: "appearance-smoke", watch_mode: "native" }; if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("File absent"); return files.get(args.rel); } if (command === "workspace_write") { files.set(args.rel, args.contents); return; } if (command === "workspace_list") return [...files.keys()].filter(path => !path.startsWith(".")).map(path => ({ name: path, rel_path: path, kind: "file" })); if (command === "workspace_search") return []; if (command === "plugin:event|listen") return args.handler; if (command === "plugin:window|is_maximized") return false; return null; }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} }; }); const page = await context.newPage(); page.on('pageerror', error => errors.push(error.message)); await page.goto(`${origin}/?settingsWindow=true`); await page.getByRole('button', { name: 'Appearance', exact: true }).click(); for (const [theme, mode] of [['default','dark'],['default','light'],['claude','dark'],['claude','light'],['sakura','light'],['harvest-moon','dark'],['crimson-pilot','dark'],['silver-serpent','dark']]) { await page.evaluate(async ({theme,mode}) => { (await import('/src/lib/theme/appearance.ts')).saveAppearance({theme,mode,transparency:{enabled:true,amount:18}}); window.dispatchEvent(new Event('focus')); },{theme,mode}); const slider = page.locator('#surface-transparency'); await slider.fill('100'); assert.equal(await page.evaluate(() => JSON.parse(localStorage.getItem('runestone.appearance')).transparency.amount),100); await slider.focus(); await page.keyboard.press('Home'); assert.equal(await slider.inputValue(),'0'); await page.keyboard.press('End'); assert.equal(await slider.inputValue(),'100'); await page.screenshot({path:`.audit/host-ui/${theme}-${mode}-slider-focus.png`}); await page.getByRole('switch',{name:'Transparent surfaces',exact:true}).uncheck(); assert(await slider.isDisabled()); await page.screenshot({path:`.audit/host-ui/${theme}-${mode}-slider-disabled.png`}); await page.getByRole('switch',{name:'Transparent surfaces',exact:true}).check(); await page.setViewportSize({width:360,height:740}); await slider.scrollIntoViewIfNeeded(); assert(await page.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth)); await page.screenshot({path:`.audit/host-ui/${theme}-${mode}-narrow.png`}); await page.setViewportSize({width:1100,height:800}); } await page.evaluate(async () => { const {installTheme} = await import('/src/lib/theme/customThemes.ts'); const {saveAppearance,exportAppearanceTheme} = await import('/src/lib/theme/appearance.ts'); const theme = exportAppearanceTheme('default'); theme.fonts = {ui:'Arial, sans-serif',prose:'Georgia, serif',heading:'Georgia, serif',mono:'Consolas, monospace'}; installTheme(theme); saveAppearance({theme:'custom:my-theme',mode:'dark'}); window.dispatchEvent(new Event('focus')); }); assert.match(await page.locator('.preview-prose').evaluate(node => getComputedStyle(node).fontFamily),/Georgia/); assert.match(await page.evaluate(async () => (await import('/src/lib/theme/appearance.ts')).exportAppearanceTheme('custom:my-theme').fonts.ui),/Arial/); await page.screenshot({path:'.audit/host-ui/custom-fonts.png'}); const main = await context.newPage(); await main.goto(origin); await main.bringToFront(); await main.getByRole('button',{name:'Files',exact:true}).waitFor(); await main.evaluate(async () => { const loaded = performance.getEntriesByType('resource').map(entry => entry.name).find(name => new URL(name).pathname === '/src/lib/plugins/external.ts'); const {pluginTools,refreshPlugins} = await import(loaded || '/src/lib/plugins/external.ts'); await refreshPlugins(); const invoke = window.__TAURI_INTERNALS__.invoke; window.__TAURI_INTERNALS__.invoke = (command,args) => command === 'plugins_snapshot' ? Promise.resolve(null) : invoke(command,args); const commands = [{owner:'runestone.background-slideshow',id:'next-image',title:'Next background image',kind:'command',surface:'commands',icon:'skip-forward'},{owner:'runestone.background-slideshow',id:'pause-resume',title:'Pause or resume background slideshow',kind:'command',surface:'commands',icon:'pause'}]; pluginTools.set(commands); }); for (const mode of ['dark','light']) { await main.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({theme:'default',mode}),mode); const button = main.getByRole('button',{name:'Commands',exact:true}); assert.equal(await button.getAttribute('title'),null); await button.hover(); await main.waitForTimeout(1100); assert.equal(await main.locator('[role=tooltip]:visible').count(),1); await main.screenshot({path:`.audit/host-ui/${mode}-single-tooltip.png`}); await main.keyboard.press('Escape'); assert.equal(await main.locator('[role=tooltip]:visible').count(),0); await main.mouse.move(400,400); await button.evaluate(node => node.blur()); await button.focus(); await main.waitForTimeout(600); assert.equal(await main.locator('[role=tooltip]:visible').count(),1); await button.click(); await main.getByRole('menu').waitFor(); const paths = await main.locator('.rs-menu svg').evaluateAll(nodes => nodes.map(node => node.innerHTML)); assert(paths.some(path => path.includes('M7 4v16'))); assert(paths.some(path => path.includes('m4 4 12 8'))); await main.screenshot({path:`.audit/host-ui/${mode}-slideshow-command-icons.png`}); await main.keyboard.press('Escape'); } assert.deepEqual(errors,[]); console.log('PASS: eight theme variants, slider endpoints, persistence, disabled states, narrow layout, font import/export, single tooltip, and command icons.'); } finally { await browser.close(); }