Move the smoke tests onto the shared harness
Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri IPC mock, the in-memory workspace, and output folders, instead of its own copy. The tests keep their interactions and assertions. Mock handlers that the app never calls are gone. - Split the four mixed regression scripts into 18 feature tests. - Update tests that broke when the app changed on purpose. Each update cites the app source that shows the new behavior. - Mark two real app defects with @known-issue: the settings window controls are 1px shorter than the main window controls, and plugin tabs cannot be reordered by dragging without a workspace. - Merge three palette unit tests into one table-driven test. - The native tests load Playwright through the harness and read NATIVE_CDP_URL, with their old variable names as fallbacks. - A failed smoke test saves a screenshot and prints the console errors. - The runner runs failed tests once more, alone, and reports a test that then passes as flaky. Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78 passed.
This commit is contained in:
@@ -1,129 +1,115 @@
|
||||
import { createRequire } from "node:module";
|
||||
// Full-app plug-ins: compact header, navigation, dynamic and restored tabs, dialogs, settings forms across windows, and disable cleanup.
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const origin = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const callbacks = new Map(), listeners = new Map();
|
||||
let sequence = 0;
|
||||
const emit = (event, payload) => { for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload }); };
|
||||
const manifest = (id, name) => ({ schemaVersion: 1, id, name, author: "Test", description: "Access test", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" });
|
||||
const plugins = [manifest("runestone.local-autocomplete", "Local Autocomplete"), manifest("org.example.browser", "Browser"), manifest("org.example.tasks", "Tasks")];
|
||||
const modules = {
|
||||
"runestone.local-autocomplete": `export function activate(api) {
|
||||
window.accessTest = { mounts: 0, disposed: 0, settings: 0 };
|
||||
api.settings.subscribe?.(() => { window.accessTest.settings++; });
|
||||
api.registerView({ id: 'settings', title: 'Local Autocomplete', placement: 'editor', mount(container, context) {
|
||||
window.accessTest.mounts++;
|
||||
container.innerHTML = '<h2>Local Autocomplete</h2><label>Model<input aria-label="Model"></label><button>Save model</button><p class="mount-context"></p>';
|
||||
container.querySelector('p').textContent = context?.surface;
|
||||
container.querySelector('button').onclick = () => api.settings.write({ model: container.querySelector('input').value });
|
||||
return () => { window.accessTest.disposed++; };
|
||||
}});
|
||||
api.registerCommand({ id: 'configure', title: 'Configure Local Autocomplete', run: () => api.openView('settings') });
|
||||
api.registerCommand({ id: 'fail', title: 'Failed command', run: () => { throw Error('Command failed for test'); } });
|
||||
}`,
|
||||
"org.example.browser": `export function activate(api) {
|
||||
api.registerCommand({ id: 'new-tab', title: 'New browser tab', category: 'open', run() {
|
||||
const id = 'tab-' + Date.now(); api.registerView({ id, title: 'Browser instance', placement: 'editor', mount(container) { container.textContent = 'Browser content'; } }); api.openView(id);
|
||||
}});
|
||||
}`,
|
||||
"org.example.tasks": `export function activate(api) {
|
||||
api.registerView({ id: 'tasks', title: 'All tasks', icon: 'list', navigation: true, placement: 'editor', launch() { api.openView('default-board'); }, mount(container) { container.textContent = 'Task content'; } });
|
||||
api.registerView({ id: 'default-board', title: 'Default board', launcher: false, placement: 'editor', mount(container) { container.textContent = 'Default board content'; } });
|
||||
window.taskTestApi = api;
|
||||
api.registerView({ id: 'dialog', title: 'Task summary', mount(container) { container.textContent = 'Task summary content'; } });
|
||||
}`,
|
||||
};
|
||||
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 === 'plugin:event|listen') { const ids = listeners.get(args.event) || []; ids.push(args.handler); listeners.set(args.event, ids); return args.handler; }
|
||||
if (command === 'plugin:event|unlisten') { callbacks.delete(args.eventId); return; }
|
||||
if (command === 'browser_connect') return 'test-session';
|
||||
if (command === 'browser_stop') return;
|
||||
if (command === 'workspace_last_path') return null;
|
||||
if (command === 'plugins_snapshot') return { root: 'C:/test/plugins', plugins: plugins.map(manifest => ({ manifest, hash: 'test', enabled: !(manifest.id === 'runestone.local-autocomplete' && localStorage.getItem('disabled')), installedAt: 1, path: 'C:/test/plugins/' + manifest.id, error: null, removal: false })) };
|
||||
if (command === 'plugins_load') return modules[args.id];
|
||||
if (command === 'plugins_data') {
|
||||
if (args.value !== null) { localStorage.setItem('settings:' + args.id, args.value); emit('plugin-settings-changed', args.id); }
|
||||
return localStorage.getItem('settings:' + args.id) || 'null';
|
||||
}
|
||||
if (command === 'plugins_set_enabled') { if (!args.enabled) localStorage.setItem('disabled', 'true'); emit('plugins-changed', {}); return; }
|
||||
if (command === 'plugins_release' || command === 'settings_open_window') return;
|
||||
if (command.startsWith('plugin:window|')) return false;
|
||||
throw new Error('Unhandled IPC: ' + command);
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("plugins/access", async ({ browser }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
await mockTauri(context, {
|
||||
commands: test => {
|
||||
const manifest = (id, name) => ({ schemaVersion: 1, id, name, author: "Test", description: "Access test", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" });
|
||||
const plugins = [manifest("runestone.local-autocomplete", "Local Autocomplete"), manifest("org.example.browser", "Browser"), manifest("org.example.tasks", "Tasks")];
|
||||
const modules = {
|
||||
"runestone.local-autocomplete": `export function activate(api) {
|
||||
window.accessTest = { mounts: 0, disposed: 0, settings: 0 };
|
||||
api.settings.subscribe?.(() => { window.accessTest.settings++; });
|
||||
api.registerView({ id: 'settings', title: 'Local Autocomplete', placement: 'editor', mount(container, context) {
|
||||
window.accessTest.mounts++;
|
||||
container.innerHTML = '<h2>Local Autocomplete</h2><label>Model<input aria-label="Model"></label><button>Save model</button><p class="mount-context"></p>';
|
||||
container.querySelector('p').textContent = context?.surface;
|
||||
container.querySelector('button').onclick = () => api.settings.write({ model: container.querySelector('input').value });
|
||||
return () => { window.accessTest.disposed++; };
|
||||
}});
|
||||
api.registerCommand({ id: 'configure', title: 'Configure Local Autocomplete', run: () => api.openView('settings') });
|
||||
api.registerCommand({ id: 'fail', title: 'Failed command', run: () => { throw Error('Command failed for test'); } });
|
||||
}`,
|
||||
"org.example.browser": `export function activate(api) {
|
||||
api.registerCommand({ id: 'new-tab', title: 'New browser tab', category: 'open', run() {
|
||||
const id = 'tab-' + Date.now(); api.registerView({ id, title: 'Browser instance', placement: 'editor', mount(container) { container.textContent = 'Browser content'; } }); api.openView(id);
|
||||
}});
|
||||
}`,
|
||||
"org.example.tasks": `export function activate(api) {
|
||||
api.registerView({ id: 'tasks', title: 'All tasks', icon: 'list', navigation: true, placement: 'editor', launch() { api.openView('default-board'); }, mount(container) { container.textContent = 'Task content'; } });
|
||||
api.registerView({ id: 'default-board', title: 'Default board', launcher: false, placement: 'editor', mount(container) { container.textContent = 'Default board content'; } });
|
||||
window.taskTestApi = api;
|
||||
api.registerView({ id: 'dialog', title: 'Task summary', mount(container) { container.textContent = 'Task summary content'; } });
|
||||
}`,
|
||||
};
|
||||
// Settings and the enabled state live in localStorage, so both windows of the context share them.
|
||||
window.addEventListener("storage", event => {
|
||||
if (event.key?.startsWith("settings:")) test.emit("plugin-settings-changed", event.key.slice(9));
|
||||
if (event.key === "disabled") test.emit("plugins-changed", {});
|
||||
});
|
||||
return {
|
||||
browser_connect: () => "test-session",
|
||||
workspace_last_path: () => null,
|
||||
plugins_snapshot: () => ({ root: "C:/test/plugins", plugins: plugins.map(manifest => ({ manifest, hash: "test", enabled: !(manifest.id === "runestone.local-autocomplete" && localStorage.getItem("disabled")), installedAt: 1, path: "C:/test/plugins/" + manifest.id, error: null, removal: false })) }),
|
||||
plugins_load: ({ id }) => modules[id],
|
||||
plugins_data: ({ id, value }) => {
|
||||
if (value !== null) { localStorage.setItem("settings:" + id, value); test.emit("plugin-settings-changed", id); }
|
||||
return localStorage.getItem("settings:" + id) || "null";
|
||||
},
|
||||
plugins_set_enabled: ({ enabled }) => { if (!enabled) localStorage.setItem("disabled", "true"); test.emit("plugins-changed", {}); },
|
||||
plugins_release: () => null,
|
||||
"plugin:window|is_maximized": () => false,
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.addEventListener('storage', event => { if (event.key?.startsWith('settings:')) emit('plugin-settings-changed', event.key.slice(9)); if (event.key === 'disabled') emit('plugins-changed', {}); });
|
||||
});
|
||||
const main = await context.newPage(), settings = await context.newPage();
|
||||
for (const page of [main, settings]) { page.setDefaultTimeout(10000); page.on('pageerror', error => errors.push(error.message)); }
|
||||
try {
|
||||
await main.goto(origin);
|
||||
await main.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name: 'All tasks', exact: true }).waitFor();
|
||||
assert.equal(await main.getByRole('button', { name: 'Open tab or view', exact: true }).count(), 0);
|
||||
assert.equal(await main.getByRole('button', { name: 'Commands', exact: true }).count(), 1);
|
||||
await main.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name: 'All tasks', exact: true }).click();
|
||||
await main.getByText('Default board content', { exact: true }).waitFor();
|
||||
await main.evaluate(() => window.taskTestApi.openView('tasks'));
|
||||
await main.getByText('Task content', { exact: true }).waitFor();
|
||||
await main.evaluate(async () => {
|
||||
const { closePluginEditor, pluginTabState, pluginView, restorePluginTab } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
let view;
|
||||
const off = pluginView.subscribe(value => { view = value; }); off();
|
||||
const transfer = pluginTabState(view);
|
||||
closePluginEditor(view.key);
|
||||
if (!await restorePluginTab(transfer)) throw Error('Tab restore failed');
|
||||
});
|
||||
await main.getByText('Task content', { exact: true }).waitFor();
|
||||
await main.evaluate(async () => {
|
||||
const { runPluginCommand } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
await runPluginCommand('org.example.browser', 'new-tab');
|
||||
});
|
||||
await main.getByText('Browser content', { exact: true }).waitFor();
|
||||
await main.evaluate(async () => {
|
||||
const { openPluginView } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
openPluginView('org.example.tasks', 'dialog');
|
||||
});
|
||||
await main.getByRole('dialog', { name: 'Task summary' }).waitFor();
|
||||
await main.keyboard.press('Escape');
|
||||
for (const theme of ['dark', 'light']) {
|
||||
await main.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await main.screenshot({ path: `.audit/plugin-access-${theme}.png` });
|
||||
const output = await outputDir("plugins/access");
|
||||
const main = await openPage(context), settings = await openPage(context);
|
||||
const external = page => page.evaluate(() => performance.getEntriesByType("resource").find(entry => new URL(entry.name).pathname === "/src/lib/plugins/external.ts").name);
|
||||
try {
|
||||
await main.goto(smokeUrl);
|
||||
await main.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name: "All tasks", exact: true }).waitFor();
|
||||
assert.equal(await main.getByRole("button", { name: "Open tab or view", exact: true }).count(), 0);
|
||||
assert.equal(await main.getByRole("button", { name: "Commands", exact: true }).count(), 1);
|
||||
await main.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name: "All tasks", exact: true }).click();
|
||||
await main.getByText("Default board content", { exact: true }).waitFor();
|
||||
await main.evaluate(() => window.taskTestApi.openView("tasks"));
|
||||
await main.getByText("Task content", { exact: true }).waitFor();
|
||||
const module = await external(main);
|
||||
await main.evaluate(async module => {
|
||||
const { closePluginEditor, pluginTabState, pluginView, restorePluginTab } = await import(module);
|
||||
let view;
|
||||
const off = pluginView.subscribe(value => { view = value; }); off();
|
||||
const transfer = pluginTabState(view);
|
||||
closePluginEditor(view.key);
|
||||
if (!await restorePluginTab(transfer)) throw Error("Tab restore failed");
|
||||
}, module);
|
||||
await main.getByText("Task content", { exact: true }).waitFor();
|
||||
await main.evaluate(async module => { await (await import(module)).runPluginCommand("org.example.browser", "new-tab"); }, module);
|
||||
await main.getByText("Browser content", { exact: true }).waitFor();
|
||||
await main.evaluate(async module => { (await import(module)).openPluginView("org.example.tasks", "dialog"); }, module);
|
||||
await main.getByRole("dialog", { name: "Task summary" }).waitFor();
|
||||
await main.keyboard.press("Escape");
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await main.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await main.screenshot({ path: path.join(output, `plugin-access-${theme}.png`) });
|
||||
}
|
||||
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settings.getByRole("button", { name: "Local Autocomplete", exact: true }).click();
|
||||
await settings.getByRole("textbox", { name: "Model", exact: true }).fill("unsaved-model");
|
||||
assert.equal(await settings.locator(".mount-context").innerText(), "settings");
|
||||
await settings.waitForTimeout(5500);
|
||||
assert.equal(await settings.getByRole("textbox", { name: "Model", exact: true }).inputValue(), "unsaved-model");
|
||||
assert.equal(await settings.evaluate(() => window.accessTest.mounts), 1);
|
||||
await settings.getByRole("button", { name: "Save model", exact: true }).click();
|
||||
await main.waitForFunction(() => window.accessTest.settings === 1);
|
||||
await settings.screenshot({ path: path.join(output, "plugin-access-settings.png") });
|
||||
await settings.getByRole("button", { name: "General", exact: true }).click();
|
||||
await settings.waitForFunction(() => window.accessTest.disposed === 1);
|
||||
await settings.getByRole("textbox", { name: "Search settings" }).fill("Local");
|
||||
await settings.getByRole("textbox", { name: "Model", exact: true }).waitFor();
|
||||
await settings.getByRole("textbox", { name: "Search settings" }).fill("");
|
||||
await settings.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
||||
await settings.getByRole("switch", { name: "Local Autocomplete", exact: true }).uncheck();
|
||||
await settings.getByRole("button", { name: "Local Autocomplete", exact: true }).waitFor({ state: "detached" });
|
||||
await main.getByRole("button", { name: "Commands", exact: true }).waitFor({ state: "detached" });
|
||||
assert.deepEqual([...main.errors, ...settings.errors], []);
|
||||
} catch (error) {
|
||||
await settings.screenshot({ path: path.join(output, "plugin-access-failure.png") });
|
||||
console.log(await settings.locator("body").innerText(), await settings.evaluate(() => window.accessTest), [...main.errors, ...settings.errors]);
|
||||
throw error;
|
||||
}
|
||||
await settings.goto(origin + '/?settingsWindow=true');
|
||||
await settings.getByRole('button', { name: 'Local Autocomplete', exact: true }).click();
|
||||
await settings.getByRole('textbox', { name: 'Model', exact: true }).fill('unsaved-model');
|
||||
assert.equal(await settings.locator('.mount-context').innerText(), 'settings');
|
||||
await settings.waitForTimeout(5500);
|
||||
assert.equal(await settings.getByRole('textbox', { name: 'Model', exact: true }).inputValue(), 'unsaved-model');
|
||||
assert.equal(await settings.evaluate(() => window.accessTest.mounts), 1);
|
||||
await settings.getByRole('button', { name: 'Save model', exact: true }).click();
|
||||
await main.waitForFunction(() => window.accessTest.settings === 1);
|
||||
await settings.screenshot({ path: '.audit/plugin-access-settings.png' });
|
||||
await settings.getByRole('button', { name: 'General', exact: true }).click();
|
||||
await settings.waitForFunction(() => window.accessTest.disposed === 1);
|
||||
await settings.getByRole('textbox', { name: 'Search settings' }).fill('Local');
|
||||
await settings.getByRole('textbox', { name: 'Model', exact: true }).waitFor();
|
||||
await settings.getByRole('textbox', { name: 'Search settings' }).fill('');
|
||||
await settings.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
||||
await settings.getByRole('switch', { name: 'Local Autocomplete', exact: true }).uncheck();
|
||||
await settings.getByRole('button', { name: 'Local Autocomplete', exact: true }).waitFor({ state: 'detached' });
|
||||
await main.getByRole('button', { name: 'Commands', exact: true }).waitFor({ state: 'detached' });
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('Plugin access smoke passed: compact header, navigation, dynamic tabs, dialog, settings search, stable forms, cross-window settings, disable cleanup.');
|
||||
} catch (error) {
|
||||
await settings.screenshot({ path: '.audit/plugin-access-failure.png' });
|
||||
console.log(await settings.locator('body').innerText(), await settings.evaluate(() => window.accessTest), errors);
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
console.log("Plugin access smoke passed: compact header, navigation, dynamic tabs, dialog, settings search, stable forms, cross-window settings, disable cleanup.");
|
||||
});
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
// Local Autocomplete settings choices use the shared action menu in a modal: keyboard choice, saving, focus return, and cleanup.
|
||||
// @requires repo:RuneStone_Local_Autocomplete/src
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile, 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 browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage();
|
||||
const url = process.env.SMOKE_URL || 'http://127.0.0.1:1420';
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await mkdir('.audit/menu-audit', { recursive: true });
|
||||
await page.route('**/__choice-audit__', route => route.fulfill({ contentType: 'text/html', body: '<link rel="stylesheet" href="/src/lib/theme/tokens.css"><link rel="stylesheet" href="/src/lib/ui/menu.css"><style>dialog{inset:0;margin:0;max-width:none;max-height:none;width:100%;height:100%;box-sizing:border-box;background:var(--rs-bg);color:var(--rs-text);padding:0;border:0}</style><dialog><main></main></dialog>' }));
|
||||
await page.route('**/__autocomplete__/*.mjs', async route => {
|
||||
const name = new URL(route.request().url()).pathname.split('/').pop();
|
||||
assert.ok(['main.mjs', 'engine.mjs'].includes(name));
|
||||
await route.fulfill({ contentType: 'application/javascript', body: await readFile(new URL(`../../../../RuneStone_Local_Autocomplete/src/${name}`, import.meta.url), 'utf8') });
|
||||
});
|
||||
try {
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { outputDir, pluginRepo, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
const autocompleteSource = path.join(pluginRepo('RuneStone_Local_Autocomplete'), 'src');
|
||||
|
||||
await runSmoke('plugins/choiceMenus', async ({ page }) => {
|
||||
const output = await outputDir('plugins/choiceMenus');
|
||||
await page.route('**/__choice-audit__', route => route.fulfill({ contentType: 'text/html', body: '<link rel="stylesheet" href="/src/lib/theme/tokens.css"><link rel="stylesheet" href="/src/lib/ui/menu.css"><style>dialog{inset:0;margin:0;max-width:none;max-height:none;width:100%;height:100%;box-sizing:border-box;background:var(--rs-bg);color:var(--rs-text);padding:0;border:0}</style><dialog><main></main></dialog>' }));
|
||||
await page.route('**/__autocomplete__/*.mjs', async route => {
|
||||
const name = new URL(route.request().url()).pathname.split('/').pop();
|
||||
assert.ok(['main.mjs', 'engine.mjs'].includes(name));
|
||||
await route.fulfill({ contentType: 'application/javascript', body: await readFile(path.join(autocompleteSource, name), 'utf8') });
|
||||
});
|
||||
for (const theme of ['light', 'dark']) for (const width of [1100, 390]) {
|
||||
await page.setViewportSize({ width, height: 850 });
|
||||
await page.goto(url + '/__choice-audit__');
|
||||
await page.goto(smokeUrl + '/__choice-audit__');
|
||||
await page.evaluate(async theme => {
|
||||
document.documentElement.dataset.theme = theme;
|
||||
const { showActionMenu } = await import('/src/lib/ui/managedActionMenu.ts');
|
||||
@@ -38,7 +36,7 @@ try {
|
||||
assert.equal(await menu.evaluate(node => !!node.closest('dialog[open]')), true);
|
||||
await page.keyboard.press('End');
|
||||
assert.equal(await page.getByRole('menuitemradio', { name: 'Ollama', exact: true }).evaluate(node => node === document.activeElement), true);
|
||||
await page.screenshot({ path: `.audit/menu-audit/autocomplete-${theme}-${width}.png` });
|
||||
await page.screenshot({ path: path.join(output, `autocomplete-${theme}-${width}.png`) });
|
||||
await page.keyboard.press('Enter');
|
||||
assert.match(await trigger.innerText(), /Ollama/);
|
||||
await page.getByRole('button', { name: 'Save settings', exact: true }).click();
|
||||
@@ -48,6 +46,5 @@ try {
|
||||
await trigger.click(); await page.evaluate(() => window.choiceAudit.dispose());
|
||||
assert.equal(await page.locator('.rs-menu').count(), 0);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: Local Autocomplete shared choices, modal input, saved adapter, focus return, and cleanup in both themes at 1100/390px.');
|
||||
} finally { await browser.close(); }
|
||||
}, { timeout: 30000 });
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// Git plugin sidebar toolbar: the Graph control is icon-only, keeps its accessible name, shows hover and focus tooltips in both themes, and opens Graph.
|
||||
// @requires repo:RuneStone_Git/src
|
||||
// The source loads from the sibling RuneStone_Git checkout (RUNESTONE_PLUGIN_REPOS) without building a plugin ZIP.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, pluginRepo, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const name = "plugins/gitToolbar";
|
||||
await runSmoke(name, async ({ page }) => {
|
||||
const output = await outputDir(name);
|
||||
const source = pluginRepo("RuneStone_Git");
|
||||
const files = new Map(await Promise.all(["view.js", "model.js"].map(async file => [file, await readFile(path.join(source, "src", file), "utf8")])));
|
||||
const css = await readFile(path.join(source, "src", "style.css"), "utf8");
|
||||
await page.route("**/__git_source/*", route => route.fulfill({ contentType: "text/javascript", body: files.get(new URL(route.request().url()).pathname.split("/").pop()) || "" }));
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "C:\\git-toolbar", files: { "notes/draft.md": "Before.\n" } }),
|
||||
plugins_snapshot: () => ({ plugins: [], issues: [] }),
|
||||
spelling_menu_install: () => null,
|
||||
}),
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="notes"]').waitFor();
|
||||
await page.evaluate(async css => {
|
||||
const { mountSidebar } = await import("/__git_source/view.js");
|
||||
const container = document.createElement("div");
|
||||
container.id = "git-smoke";
|
||||
container.style.cssText = "position:fixed;inset:45px 0 0 0;z-index:1000;background:var(--rs-bg)";
|
||||
document.body.append(container);
|
||||
window.gitGraphOpens = 0;
|
||||
window.disposeGitSmoke = mountSidebar(container, {
|
||||
workspace: {},
|
||||
git: { status: async () => ({ available: true, repository: true, branch: "main", changes: [] }), pull: async () => {}, push: async () => {} },
|
||||
openView: () => window.gitGraphOpens++,
|
||||
}, css, () => {});
|
||||
}, css);
|
||||
const graph = page.locator("#git-smoke").getByRole("button", { name: "Graph", exact: true });
|
||||
// The plugin shows the shared host tooltip (a `.rs-tooltip` popover from `data-tooltip`) instead of a title and its own tooltip span.
|
||||
// RuneStone_Git/src/view.js: button() sets data-tooltip and aria-label; tooltipScope() shows the popover on hover and focus.
|
||||
const tooltip = page.locator(".rs-tooltip:popover-open");
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
|
||||
await graph.waitFor();
|
||||
assert.equal(await graph.locator("svg").count(), 1);
|
||||
assert.equal(await graph.getAttribute("title"), null);
|
||||
assert.equal(await graph.getAttribute("data-tooltip"), "Graph");
|
||||
assert.equal(await graph.evaluate(node => [...node.childNodes].filter(child => child.nodeType === Node.TEXT_NODE && child.textContent.trim()).length), 0);
|
||||
assert.equal(await graph.locator(":scope > :not(.rs-git-icon)").count(), 0, "Graph has no visible text label");
|
||||
await page.mouse.move(800, 800);
|
||||
await graph.evaluate(node => node.blur());
|
||||
assert.equal(await tooltip.count(), 0);
|
||||
await graph.hover();
|
||||
await tooltip.waitFor();
|
||||
assert.equal(await tooltip.innerText(), "Graph");
|
||||
await page.mouse.move(800, 800);
|
||||
await page.keyboard.press("Tab");
|
||||
await graph.focus();
|
||||
assert.equal(await graph.evaluate(node => node.matches(":focus-visible")), true);
|
||||
await tooltip.waitFor();
|
||||
assert.equal(await tooltip.innerText(), "Graph");
|
||||
await page.screenshot({ path: path.join(output, `git-toolbar-${theme}.png`) });
|
||||
}
|
||||
await graph.click();
|
||||
assert.equal(await page.evaluate(() => window.gitGraphOpens), 1);
|
||||
await page.evaluate(() => window.disposeGitSmoke());
|
||||
console.log("PASS: icon-only Graph control with accessible name, hover and focus tooltips in both themes, and Graph opens");
|
||||
}, { timeout: 15000 });
|
||||
@@ -1,238 +1,189 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
// Plug-in installation: ZIP and Git-link review, download errors, token clearing, updates, disabled installs, cleanup, and uninstall.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 }, locale: 'en-US', timezoneId: 'America/Vancouver' });
|
||||
const page = await context.newPage();
|
||||
const settingsPage = await context.newPage();
|
||||
settingsPage.setDefaultTimeout(10000);
|
||||
await context.exposeBinding("settingsHostInvoke", (_source, command, args) =>
|
||||
page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args }));
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
settingsPage.on("pageerror", error => errors.push(error.message));
|
||||
const manifest = JSON.parse(readFileSync('fixtures/plugins/workspace-overview/plugin.json', 'utf8'));
|
||||
const pluginCode = readFileSync('fixtures/plugins/workspace-overview/main.js', 'utf8') + '\n// Browser cleanup probe\n';
|
||||
await page.context().addInitScript(({ manifest, pluginCode }) => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
const files = new Map([
|
||||
["notes/welcome.md", "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n"],
|
||||
["notes/second.md", "# Second note\n"],
|
||||
["src/hello.py", "print('hello')\n"],
|
||||
]);
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
let sequence = 0;
|
||||
const calls = [];
|
||||
let installed = [];
|
||||
let removalPrepared = false;
|
||||
const data = { preserved: true };
|
||||
const path = "C:\\AppData\\RuneStone\\plugins\\" + manifest.id;
|
||||
const snapshot = () => ({ root: "C:\\AppData\\RuneStone\\plugins", plugins: installed });
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
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 (location.search.includes("settingsWindow") && !command.startsWith("plugin:event|") && !command.startsWith("plugin:window|"))
|
||||
return window.settingsHostInvoke(command, args);
|
||||
calls.push({ command, args });
|
||||
if (command === "settings_open_window") return;
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
if (command.startsWith("plugin:window|")) return null;
|
||||
if (command === "plugins_snapshot") return snapshot();
|
||||
if (command === "plugins_choose") return [{ token: 'candidate', source: 'C:/Downloads/overview.zip', manifest, error: null }];
|
||||
if (command === "plugins_from_git") {
|
||||
if (args.tag === 'missing') throw new Error('Release not found. Publish a release with one plugin ZIP.');
|
||||
return [{ token: 'git-candidate', source: args.url + ' @ ' + (args.tag || 'v1.0.0'), manifest, error: null }];
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const fixture = path.join(repoRoot, "fixtures", "plugins", "workspace-overview");
|
||||
const manifest = JSON.parse(readFileSync(path.join(fixture, "plugin.json"), "utf8"));
|
||||
const pluginCode = readFileSync(path.join(fixture, "main.js"), "utf8") + "\n// Browser cleanup probe\n";
|
||||
|
||||
await runSmoke("plugins/install", async ({ browser }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 }, locale: "en-US", timezoneId: "America/Vancouver" });
|
||||
const page = await openPage(context);
|
||||
const settingsPage = await openPage(context);
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
// The settings window forwards plug-in commands to the main window, which owns the installed state.
|
||||
await context.exposeBinding("settingsHostInvoke", (_source, command, args) =>
|
||||
page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args }));
|
||||
await mockTauri(context, {
|
||||
state: { manifest, pluginCode },
|
||||
commands: test => {
|
||||
const { manifest, pluginCode } = test.state;
|
||||
const isMaximized = () => false;
|
||||
if (location.search.includes("settingsWindow")) {
|
||||
return new Proxy({}, { get: (_table, command) => command === "plugin:window|is_maximized" ? isMaximized : args => window.settingsHostInvoke(command, args) });
|
||||
}
|
||||
if (command === "plugins_cancel") { removalPrepared = false; return; }
|
||||
if (command === "plugins_install") {
|
||||
const previous = installed[0];
|
||||
installed = [{ manifest, hash: 'reviewed-hash', enabled: previous ? previous.enabled : args.enabled, installedAt: Date.parse('2026-10-05T18:24:36Z'), path, error: null, removal: false }];
|
||||
emit('plugins-changed', null); return [{ name: manifest.name, error: null }];
|
||||
}
|
||||
if (command === "plugins_set_enabled") {
|
||||
installed[0].enabled = args.enabled;
|
||||
emit('plugins-changed', null); return;
|
||||
}
|
||||
if (command === "plugins_load") { window.__TEST__.cleaned = false; window.__TEST__.released = false; return pluginCode.replace('export function activate(api) {', 'export function activate(api) { api.onDispose(() => { window.__TEST__.cleaned = true; });'); }
|
||||
if (command === "plugins_release") { window.__TEST__.released = true; return; }
|
||||
if (command === "plugins_data") return JSON.stringify(data);
|
||||
if (command === "plugins_reveal") return;
|
||||
if (command === "plugins_prepare_remove") { removalPrepared = true; return { token: 'remove-plan', plugin: installed[0] }; }
|
||||
if (command === "plugins_remove") {
|
||||
if (!removalPrepared) throw Error('Missing removal plan');
|
||||
removalPrepared = false;
|
||||
installed[0].enabled = false; emit('plugins-changed', null);
|
||||
for (let i=0; i<100 && !window.__TEST__.released; i++) await new Promise(resolve => setTimeout(resolve, 50));
|
||||
if (!window.__TEST__.cleaned || !window.__TEST__.released) throw Error('Cleanup was not acknowledged');
|
||||
installed = []; emit('plugins-changed', null); return;
|
||||
}
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "pty_profiles") return [{ id: "powershell", title: "PowerShell", kind: "powershell" }];
|
||||
if (command === "pty_open") {
|
||||
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
|
||||
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
|
||||
emit("pty-data", { id: args.id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return;
|
||||
}
|
||||
if (command.startsWith("pty_")) return;
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
let installed = [];
|
||||
let removalPrepared = false;
|
||||
const data = { preserved: true };
|
||||
const pluginPath = "C:\\AppData\\RuneStone\\plugins\\" + manifest.id;
|
||||
const changed = () => test.emit("plugins-changed", null);
|
||||
Object.assign(test, { data, cleaned: false, released: false });
|
||||
const ws = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
return {
|
||||
...ws,
|
||||
"plugin:window|is_maximized": isMaximized,
|
||||
settings_open_window: () => null,
|
||||
plugins_snapshot: () => ({ root: "C:\\AppData\\RuneStone\\plugins", plugins: installed }),
|
||||
plugins_choose: () => [{ token: "candidate", source: "C:/Downloads/overview.zip", manifest, error: null }],
|
||||
plugins_from_git: ({ url, tag }) => {
|
||||
if (tag === "missing") throw new Error("Release not found. Publish a release with one plugin ZIP.");
|
||||
return [{ token: "git-candidate", source: url + " @ " + (tag || "v1.0.0"), manifest, error: null }];
|
||||
},
|
||||
plugins_cancel: () => { removalPrepared = false; },
|
||||
plugins_install: ({ enabled }) => {
|
||||
const previous = installed[0];
|
||||
installed = [{ manifest, hash: "reviewed-hash", enabled: previous ? previous.enabled : enabled, installedAt: Date.parse("2026-10-05T18:24:36Z"), path: pluginPath, error: null, removal: false }];
|
||||
changed();
|
||||
return [{ name: manifest.name, error: null }];
|
||||
},
|
||||
plugins_load: () => {
|
||||
test.cleaned = false; test.released = false;
|
||||
return pluginCode.replace("export function activate(api) {", "export function activate(api) { api.onDispose(() => { window.__TEST__.cleaned = true; });");
|
||||
},
|
||||
plugins_release: () => { test.released = true; },
|
||||
plugins_prepare_remove: () => { removalPrepared = true; return { token: "remove-plan", plugin: installed[0] }; },
|
||||
plugins_remove: async () => {
|
||||
if (!removalPrepared) throw Error("Missing removal plan");
|
||||
removalPrepared = false;
|
||||
installed[0].enabled = false; changed();
|
||||
for (let i = 0; i < 100 && !test.released; i++) await new Promise(resolve => setTimeout(resolve, 50));
|
||||
if (!test.cleaned || !test.released) throw Error("Cleanup was not acknowledged");
|
||||
installed = []; changed();
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root, data };
|
||||
}, { manifest, pluginCode });
|
||||
|
||||
async function quickOpen(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await page.locator('.live-writer').waitFor();
|
||||
}
|
||||
|
||||
|
||||
const settingsDialog = settingsPage.getByRole('dialog', { name: 'Settings', exact: true });
|
||||
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
|
||||
async function settings() {
|
||||
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
||||
await settingsPage.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '/?settingsWindow=true');
|
||||
await settingsDialog.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
||||
}
|
||||
async function uninstall() { await settingsDialog.locator('.card').filter({ hasText: 'Workspace overview' }).getByRole('button', { name: 'Uninstall', exact: true }).click(); }
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await settings();
|
||||
assert.equal(await settingsDialog.getByRole('button', { name: 'Install from folder', exact: true }).count(), 0);
|
||||
assert.equal(await settingsDialog.getByRole('button', { name: 'Install from file', exact: true }).count(), 0);
|
||||
await settingsDialog.getByRole('button', { name: 'Install plugin ZIP', exact: true }).click();
|
||||
let review = settingsPage.getByRole('dialog', { name: 'Review plugin installation', exact: true });
|
||||
await review.getByText('Source: C:/Downloads/overview.zip', { exact: true }).waitFor();
|
||||
await review.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
assert.equal(await count('plugins_install'), 0);
|
||||
const gitButton = settingsDialog.getByRole('button', { name: 'Install from Git link', exact: true });
|
||||
await gitButton.click();
|
||||
const gitDialog = settingsPage.getByRole('dialog', { name: 'Install from Git link', exact: true });
|
||||
await gitDialog.getByLabel('Repository link', { exact: true }).fill('https://git.example/owner/plugin.git');
|
||||
await gitDialog.getByLabel('Release tag (optional)', { exact: true }).fill('missing');
|
||||
await gitDialog.getByLabel('Access token (optional)', { exact: true }).fill('test-token');
|
||||
await gitDialog.getByRole('button', { name: 'Review release', exact: true }).click();
|
||||
await gitDialog.getByRole('alert').getByText(/Release not found/).waitFor();
|
||||
assert.equal(await gitDialog.getByLabel('Access token (optional)', { exact: true }).inputValue(), '');
|
||||
await gitDialog.getByLabel('Release tag (optional)', { exact: true }).fill('v1.0.0');
|
||||
await gitDialog.getByRole('button', { name: 'Review release', exact: true }).click();
|
||||
await review.getByText('Source: https://git.example/owner/plugin.git @ v1.0.0', { exact: true }).waitFor();
|
||||
await review.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
assert.equal(await count('plugins_install'), 0);
|
||||
assert(await gitButton.evaluate(element => element === document.activeElement));
|
||||
await settingsDialog.getByRole('button', { name: 'Install plugin ZIP', exact: true }).click();
|
||||
await review.getByRole('button', { name: 'Install and enable', exact: true }).click();
|
||||
await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).waitFor();
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
assert.equal(await settingsDialog.locator('time').getAttribute('datetime'), '2026-10-05T18:24:36.000Z');
|
||||
assert.match(await settingsDialog.locator('time').innerText(), /Oct 5, 2026.*11:24:36 AM PDT/);
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-manager-installed.png' });
|
||||
await settingsPage.keyboard.press('Escape');
|
||||
await page.getByRole('button', { name: 'Commands', exact: true }).click();
|
||||
await page.getByRole('menuitem', { name: /Show workspace overview/ }).click();
|
||||
const view = page.getByRole('dialog', { name: 'Workspace overview', exact: true });
|
||||
await view.getByText(/files and folders in this workspace/).waitFor();
|
||||
await view.getByRole('button', { name: 'Close plugin view', exact: true }).click();
|
||||
await settings();
|
||||
await settingsDialog.getByRole('button', { name: 'Install plugin ZIP', exact: true }).click();
|
||||
await review.getByText(/Update .* → .*Settings and enabled state stay the same/).waitFor();
|
||||
assert.equal(await review.getByRole('button', { name: 'Install and enable', exact: true }).count(), 0);
|
||||
for (const mode of ['dark', 'light']) {
|
||||
await settingsPage.evaluate(async mode => {
|
||||
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
saveAppearance({ theme: 'default', mode });
|
||||
}, mode);
|
||||
for (const width of [1440, 590]) {
|
||||
await settingsPage.setViewportSize({ width, height: width === 590 ? 820 : 1000 });
|
||||
await settingsPage.screenshot({ path: `.audit/plugin-update-review-${mode}-${width}.png` });
|
||||
assert.equal(await review.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
}
|
||||
});
|
||||
const output = await outputDir("plugins/install");
|
||||
const shot = name => settingsPage.screenshot({ path: path.join(output, name) });
|
||||
const settingsDialog = settingsPage.getByRole("dialog", { name: "Settings", exact: true });
|
||||
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
|
||||
async function settings() {
|
||||
await page.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).click();
|
||||
await settingsPage.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settingsDialog.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
||||
}
|
||||
await review.getByRole('button', { name: 'Apply packages', exact: true }).click();
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.data.preserved), true);
|
||||
assert.equal(await count('plugins_remove'), 0);
|
||||
await settingsPage.setViewportSize({ width: 1440, height: 1000 });
|
||||
await uninstall();
|
||||
const confirmation = settingsPage.getByRole('dialog', { name: 'Uninstall Workspace overview?', exact: true });
|
||||
assert(await confirmation.getByRole('button', { name: 'Cancel', exact: true }).evaluate(el => el === document.activeElement));
|
||||
assert.equal(await confirmation.getByRole('button', { name: 'Continue', exact: true }).count(), 0);
|
||||
await confirmation.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
assert.equal(await count('plugins_remove'), 0);
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
await uninstall();
|
||||
await confirmation.waitFor();
|
||||
await settingsPage.keyboard.press('Escape');
|
||||
assert(await settingsDialog.isVisible());
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
assert.equal(await count('plugins_remove'), 0);
|
||||
await uninstall();
|
||||
await confirmation.waitFor();
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-uninstall-confirmation.png' });
|
||||
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
||||
await settingsDialog.getByText('No plugins installed.', { exact: true }).waitFor();
|
||||
assert.equal(await count('plugins_remove'), 1);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.cleaned), true);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.data.preserved), true);
|
||||
await settingsPage.keyboard.press('Escape');
|
||||
assert.equal(await page.getByRole('button', { name: 'Plugin commands and views', exact: true }).count(), 0);
|
||||
await settingsPage.setViewportSize({ width: 590, height: 820 });
|
||||
await settings();
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-manager-narrow.png' });
|
||||
assert.equal(await settingsDialog.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
await gitButton.click();
|
||||
await gitDialog.getByLabel('Repository link', { exact: true }).fill('https://git.example/owner/plugin.git');
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-git-narrow.png' });
|
||||
assert.equal(await gitDialog.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
await gitDialog.getByRole('button', { name: 'Review release', exact: true }).click();
|
||||
await review.getByRole('button', { name: 'Install', exact: true }).click();
|
||||
await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).waitFor();
|
||||
assert.equal(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked(), false);
|
||||
assert.equal(await count('plugins_from_git'), 3);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('External plugin smoke passed: ZIP and Git-link review, download errors, token clearing, disabled installation, code loading, cancellation, focus, cleanup, and uninstall.');
|
||||
} catch (error) {
|
||||
console.log('Main page:', await page.locator('body').innerText());
|
||||
console.log('Page errors:', errors);
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
async function uninstall() { await settingsDialog.locator(".card").filter({ hasText: "Workspace overview" }).getByRole("button", { name: "Uninstall", exact: true }).click(); }
|
||||
|
||||
try {
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await settings();
|
||||
assert.equal(await settingsDialog.getByRole("button", { name: "Install from folder", exact: true }).count(), 0);
|
||||
assert.equal(await settingsDialog.getByRole("button", { name: "Install from file", exact: true }).count(), 0);
|
||||
await settingsDialog.getByRole("button", { name: "Install plugin ZIP", exact: true }).click();
|
||||
const review = settingsPage.getByRole("dialog", { name: "Review plugin installation", exact: true });
|
||||
await review.getByText("Source: C:/Downloads/overview.zip", { exact: true }).waitFor();
|
||||
await review.getByRole("button", { name: "Cancel", exact: true }).click();
|
||||
assert.equal(await count("plugins_install"), 0);
|
||||
const gitButton = settingsDialog.getByRole("button", { name: "Install from Git link", exact: true });
|
||||
await gitButton.click();
|
||||
const gitDialog = settingsPage.getByRole("dialog", { name: "Install from Git link", exact: true });
|
||||
await gitDialog.getByLabel("Repository link", { exact: true }).fill("https://git.example/owner/plugin.git");
|
||||
await gitDialog.getByLabel("Release tag (optional)", { exact: true }).fill("missing");
|
||||
await gitDialog.getByLabel("Access token (optional)", { exact: true }).fill("test-token");
|
||||
await gitDialog.getByRole("button", { name: "Review release", exact: true }).click();
|
||||
await gitDialog.getByRole("alert").getByText(/Release not found/).waitFor();
|
||||
assert.equal(await gitDialog.getByLabel("Access token (optional)", { exact: true }).inputValue(), "");
|
||||
await gitDialog.getByLabel("Release tag (optional)", { exact: true }).fill("v1.0.0");
|
||||
await gitDialog.getByRole("button", { name: "Review release", exact: true }).click();
|
||||
await review.getByText("Source: https://git.example/owner/plugin.git @ v1.0.0", { exact: true }).waitFor();
|
||||
await review.getByRole("button", { name: "Cancel", exact: true }).click();
|
||||
assert.equal(await count("plugins_install"), 0);
|
||||
assert(await gitButton.evaluate(element => element === document.activeElement));
|
||||
await settingsDialog.getByRole("button", { name: "Install plugin ZIP", exact: true }).click();
|
||||
await review.getByRole("button", { name: "Install and enable", exact: true }).click();
|
||||
await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).waitFor();
|
||||
assert(await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).isChecked());
|
||||
assert.equal(await settingsDialog.locator("time").getAttribute("datetime"), "2026-10-05T18:24:36.000Z");
|
||||
assert.match(await settingsDialog.locator("time").innerText(), /Oct 5, 2026.*11:24:36 AM PDT/);
|
||||
await shot("plugin-manager-installed.png");
|
||||
await settingsPage.keyboard.press("Escape");
|
||||
await page.getByRole("button", { name: "Commands", exact: true }).click();
|
||||
await page.getByRole("menuitem", { name: /Show workspace overview/ }).click();
|
||||
const view = page.getByRole("dialog", { name: "Workspace overview", exact: true });
|
||||
await view.getByText(/files and folders in this workspace/).waitFor();
|
||||
await view.getByRole("button", { name: "Close plugin view", exact: true }).click();
|
||||
await settings();
|
||||
await settingsDialog.getByRole("button", { name: "Install plugin ZIP", exact: true }).click();
|
||||
await review.getByText(/Update .* → .*Settings and enabled state stay the same/).waitFor();
|
||||
assert.equal(await review.getByRole("button", { name: "Install and enable", exact: true }).count(), 0);
|
||||
for (const mode of ["dark", "light"]) {
|
||||
await settingsPage.evaluate(async mode => {
|
||||
const { saveAppearance } = await import("/src/lib/theme/appearance.ts");
|
||||
saveAppearance({ theme: "default", mode });
|
||||
}, mode);
|
||||
for (const width of [1440, 590]) {
|
||||
await settingsPage.setViewportSize({ width, height: width === 590 ? 820 : 1000 });
|
||||
await shot(`plugin-update-review-${mode}-${width}.png`);
|
||||
assert.equal(await review.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
}
|
||||
}
|
||||
await review.getByRole("button", { name: "Apply packages", exact: true }).click();
|
||||
assert(await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).isChecked());
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.data.preserved), true);
|
||||
assert.equal(await count("plugins_remove"), 0);
|
||||
await settingsPage.setViewportSize({ width: 1440, height: 1000 });
|
||||
await uninstall();
|
||||
const confirmation = settingsPage.getByRole("dialog", { name: "Uninstall Workspace overview?", exact: true });
|
||||
assert(await confirmation.getByRole("button", { name: "Cancel", exact: true }).evaluate(el => el === document.activeElement));
|
||||
assert.equal(await confirmation.getByRole("button", { name: "Continue", exact: true }).count(), 0);
|
||||
await confirmation.getByRole("button", { name: "Cancel", exact: true }).click();
|
||||
assert.equal(await count("plugins_remove"), 0);
|
||||
assert(await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).isChecked());
|
||||
await uninstall();
|
||||
await confirmation.waitFor();
|
||||
await settingsPage.keyboard.press("Escape");
|
||||
assert(await settingsDialog.isVisible());
|
||||
assert(await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).isChecked());
|
||||
assert.equal(await count("plugins_remove"), 0);
|
||||
await uninstall();
|
||||
await confirmation.waitFor();
|
||||
await shot("plugin-uninstall-confirmation.png");
|
||||
await confirmation.getByRole("button", { name: "Uninstall and delete files", exact: true }).click();
|
||||
await settingsDialog.getByText("No plugins installed.", { exact: true }).waitFor();
|
||||
assert.equal(await count("plugins_remove"), 1);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.cleaned), true);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.data.preserved), true);
|
||||
await settingsPage.keyboard.press("Escape");
|
||||
assert.equal(await page.getByRole("button", { name: "Plugin commands and views", exact: true }).count(), 0);
|
||||
await settingsPage.setViewportSize({ width: 590, height: 820 });
|
||||
await settings();
|
||||
await shot("plugin-manager-narrow.png");
|
||||
assert.equal(await settingsDialog.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
await gitButton.click();
|
||||
await gitDialog.getByLabel("Repository link", { exact: true }).fill("https://git.example/owner/plugin.git");
|
||||
await shot("plugin-git-narrow.png");
|
||||
assert.equal(await gitDialog.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
await gitDialog.getByRole("button", { name: "Review release", exact: true }).click();
|
||||
await review.getByRole("button", { name: "Install", exact: true }).click();
|
||||
await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).waitFor();
|
||||
assert.equal(await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).isChecked(), false);
|
||||
assert.equal(await count("plugins_from_git"), 3);
|
||||
assert.deepEqual([...page.errors, ...settingsPage.errors], []);
|
||||
} catch (error) {
|
||||
console.log("Main page:", await page.locator("body").innerText());
|
||||
console.log("Page errors:", [...page.errors, ...settingsPage.errors]);
|
||||
throw error;
|
||||
}
|
||||
console.log("External plugin smoke passed: ZIP and Git-link review, download errors, token clearing, disabled installation, code loading, cancellation, focus, cleanup, and uninstall.");
|
||||
});
|
||||
|
||||
@@ -1,203 +1,172 @@
|
||||
// Feature plug-in lifecycle: Table formulas and Terminal turn off, persist, reopen across windows, and uninstall without restoration.
|
||||
// @requires plugin:terminal plugin:table-formulas
|
||||
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
await context.route('**/__settings-closed', route => route.fulfill({ contentType: 'text/html', body: '<!doctype html><title>Closed settings</title>' }));
|
||||
const page = await context.newPage();
|
||||
const settingsPage = await context.newPage();
|
||||
page.setDefaultTimeout(10000);
|
||||
settingsPage.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
settingsPage.on("pageerror", error => errors.push(error.message));
|
||||
await page.context().addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
const files = new Map([
|
||||
["notes/welcome.md", "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n"],
|
||||
["notes/second.md", "# Second note\n"],
|
||||
["src/hello.py", "print('hello')\n"],
|
||||
]);
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
let sequence = 0;
|
||||
const calls = [];
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
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 = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "settings_open_window") return;
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "pty_profiles") return [{ id: "powershell", title: "PowerShell", kind: "powershell" }];
|
||||
if (command === "pty_open") {
|
||||
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
|
||||
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
|
||||
emit("pty-data", { id: args.id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return;
|
||||
}
|
||||
if (command.startsWith("pty_")) return;
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
import { mockFeaturePlugins } from '../_harness/pluginMocks.mjs';
|
||||
|
||||
await runSmoke('plugins/lifecycle', async ({ browser }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
await context.route('**/__settings-closed', route => route.fulfill({ contentType: 'text/html', body: '<!doctype html><title>Closed settings</title>' }));
|
||||
const page = await openPage(context);
|
||||
const settingsPage = await openPage(context);
|
||||
page.on('console', message => { if (message.type() === 'error' || message.type() === 'warning') console.log(message.type(), message.text()); });
|
||||
await mockTauri(context, {
|
||||
commands: test => {
|
||||
const ws = test.workspace({
|
||||
root: 'C:\\smoke-workspace',
|
||||
files: {
|
||||
'notes/welcome.md': '---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n',
|
||||
'notes/second.md': '# Second note\n',
|
||||
'src/hello.py': "print('hello')\n",
|
||||
},
|
||||
});
|
||||
const files = ws.files;
|
||||
test.files = files;
|
||||
return {
|
||||
...ws,
|
||||
workspace_write: ({ rel, contents, expected }) => {
|
||||
if (expected !== undefined && files.get(rel) !== expected) throw new Error('Save blocked: file changed on disk');
|
||||
files.set(rel, contents);
|
||||
test.emit('workspace-event', { root: ws.root, kind: 'modify', paths: [rel] });
|
||||
},
|
||||
settings_open_window: () => null,
|
||||
pty_profiles: () => [{ id: 'powershell', title: 'PowerShell', kind: 'powershell' }],
|
||||
pty_open: async ({ id }) => {
|
||||
const data = [...new TextEncoder().encode('READY 🪨\r\n\x1b[6n')];
|
||||
test.emit('pty-data', { id, data: data.slice(0, 8) });
|
||||
test.emit('pty-data', { id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
},
|
||||
pty_write: () => null,
|
||||
pty_resize: () => null,
|
||||
pty_close: () => null,
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root };
|
||||
});
|
||||
await mockFeaturePlugins(page.context());
|
||||
|
||||
});
|
||||
await mockFeaturePlugins(context);
|
||||
const output = await outputDir('plugins/lifecycle');
|
||||
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
|
||||
const table = page.locator('.live-writer table');
|
||||
const dialog = settingsPage.getByRole('dialog', { name: 'Settings', exact: true });
|
||||
const switchFor = name => dialog.getByRole('switch', { name, exact: true });
|
||||
const ptyCalled = command => window.__TEST__.calls.some(call => call.command === command);
|
||||
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
|
||||
async function quickOpen(name) {
|
||||
await page.keyboard.press('Control+p');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).fill(name);
|
||||
await page.getByRole('dialog').getByRole('button').filter({ hasText: name }).first().click();
|
||||
await page.locator('.live-writer').waitFor();
|
||||
}
|
||||
async function settings() {
|
||||
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
||||
await settingsPage.goto(smokeUrl + '/?settingsWindow=true');
|
||||
await dialog.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
||||
}
|
||||
async function closeSettings() {
|
||||
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await settingsPage.goto(smokeUrl + '/__settings-closed');
|
||||
await page.bringToFront();
|
||||
}
|
||||
|
||||
async function quickOpen(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await page.locator('.live-writer').waitFor();
|
||||
}
|
||||
try {
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text), source);
|
||||
await quickOpen('formulas.md');
|
||||
await table.waitFor();
|
||||
assert.equal(await table.locator('.md-table-formula').innerText(), '6');
|
||||
await settings();
|
||||
await switchFor('Table formulas').uncheck();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-table-formula'));
|
||||
assert.match(await table.innerText(), /=A2\*3/);
|
||||
assert.equal(await page.locator('.table-formula-tools').count(), 0);
|
||||
await table.locator('td').last().click();
|
||||
await page.locator('.writer-cell-editor').fill('=A2*4');
|
||||
await page.keyboard.press('Enter');
|
||||
await settings();
|
||||
await switchFor('Table formulas').check();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => document.querySelector('.md-table-formula')?.textContent === '8');
|
||||
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { pressed: true }).press('ArrowRight');
|
||||
const preview = page.locator('.md-page table').first();
|
||||
await preview.locator('.md-table-formula').waitFor();
|
||||
await settings();
|
||||
await switchFor('Table formulas').uncheck();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-page .md-table-formula'));
|
||||
assert.match(await preview.innerText(), /=A2\*4/);
|
||||
await settings();
|
||||
await switchFor('Table formulas').check();
|
||||
await closeSettings();
|
||||
await preview.locator('.md-table-formula').waitFor();
|
||||
assert.equal(await preview.locator('.md-table-formula').innerText(), '8');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('formulas.md').includes('=A2*4'));
|
||||
assert(!await page.evaluate(() => window.__TEST__.files.get('formulas.md').includes('>8<')));
|
||||
|
||||
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
|
||||
const table = page.locator('.live-writer table');
|
||||
const dialog = settingsPage.getByRole('dialog', { name: 'Settings', exact: true });
|
||||
const switchFor = name => dialog.getByRole('switch', { name, exact: true });
|
||||
async function settings() {
|
||||
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
||||
await settingsPage.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '/?settingsWindow=true');
|
||||
await dialog.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
||||
}
|
||||
async function closeSettings() {
|
||||
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await settingsPage.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '/__settings-closed');
|
||||
await page.bringToFront();
|
||||
}
|
||||
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text), source);
|
||||
await quickOpen('formulas.md');
|
||||
await table.waitFor();
|
||||
assert.equal(await table.locator('.md-table-formula').innerText(), '6');
|
||||
await settings();
|
||||
await switchFor('Table formulas').uncheck();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-table-formula'));
|
||||
assert.match(await table.innerText(), /=A2\*3/);
|
||||
assert.equal(await page.locator('.table-formula-tools').count(), 0);
|
||||
await table.locator('td').last().click();
|
||||
await page.locator('.writer-cell-editor').fill('=A2*4');
|
||||
await page.keyboard.press('Enter');
|
||||
await settings();
|
||||
await switchFor('Table formulas').check();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => document.querySelector('.md-table-formula')?.textContent === '8');
|
||||
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { pressed: true }).press('ArrowRight');
|
||||
const preview = page.locator('.md-page table').first();
|
||||
await preview.locator('.md-table-formula').waitFor();
|
||||
await settings();
|
||||
await switchFor('Table formulas').uncheck();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-page .md-table-formula'));
|
||||
assert.match(await preview.innerText(), /=A2\*4/);
|
||||
await settings();
|
||||
await switchFor('Table formulas').check();
|
||||
await closeSettings();
|
||||
await preview.locator('.md-table-formula').waitFor();
|
||||
assert.equal(await preview.locator('.md-table-formula').innerText(), '8');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('formulas.md').includes('=A2*4'));
|
||||
assert(!await page.evaluate(() => window.__TEST__.files.get('formulas.md').includes('>8<')));
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
||||
await page.waitForFunction(ptyCalled, 'pty_open');
|
||||
await settings();
|
||||
await switchFor('Terminal').uncheck();
|
||||
await page.waitForFunction(ptyCalled, 'pty_close');
|
||||
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings.png') });
|
||||
await closeSettings();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
const opened = await count('pty_open');
|
||||
await page.keyboard.press('Control+j');
|
||||
assert.equal(await count('pty_open'), opened);
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
await settings();
|
||||
assert(!await switchFor('Terminal').isChecked());
|
||||
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_open'));
|
||||
await settings();
|
||||
await switchFor('Terminal').uncheck();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_close'));
|
||||
await settingsPage.screenshot({ path: '.audit/plugins-settings.png' });
|
||||
await closeSettings();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
const opened = await count('pty_open');
|
||||
await page.keyboard.press('Control+j');
|
||||
assert.equal(await count('pty_open'), opened);
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
await settings();
|
||||
assert(!await switchFor('Terminal').isChecked());
|
||||
|
||||
const standalone = await page.context().newPage();
|
||||
await standalone.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '?terminalWindow=C%3A%5Csmoke-workspace');
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await switchFor('Terminal').check();
|
||||
await standalone.locator('.xterm').waitFor();
|
||||
await standalone.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_open'));
|
||||
await switchFor('Terminal').uncheck();
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await standalone.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_close'));
|
||||
await standalone.close();
|
||||
await switchFor('Terminal').check();
|
||||
await closeSettings();
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
||||
await page.locator('.xterm').waitFor();
|
||||
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text.replace('=A2*3', '=A2*4')), source);
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).focus();
|
||||
await quickOpen('formulas.md');
|
||||
await settings();
|
||||
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
|
||||
for (const name of ['Terminal', 'Table formulas']) {
|
||||
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
|
||||
const confirmation = settingsPage.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
|
||||
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
||||
await confirmation.waitFor({ state: 'hidden' });
|
||||
await switchFor(name).waitFor({ state: 'detached' });
|
||||
const standalone = await openPage(context);
|
||||
await standalone.goto(smokeUrl + '?terminalWindow=C%3A%5Csmoke-workspace');
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await switchFor('Terminal').check();
|
||||
await standalone.locator('.xterm').waitFor();
|
||||
await standalone.waitForFunction(ptyCalled, 'pty_open');
|
||||
await switchFor('Terminal').uncheck();
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await standalone.waitForFunction(ptyCalled, 'pty_close');
|
||||
page.errors.push(...standalone.errors);
|
||||
await standalone.close();
|
||||
await switchFor('Terminal').check();
|
||||
await closeSettings();
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
||||
await page.locator('.xterm').waitFor();
|
||||
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text.replace('=A2*3', '=A2*4')), source);
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).focus();
|
||||
await quickOpen('formulas.md');
|
||||
await settings();
|
||||
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
|
||||
for (const name of ['Terminal', 'Table formulas']) {
|
||||
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
|
||||
const confirmation = settingsPage.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
|
||||
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
||||
await confirmation.waitFor({ state: 'hidden' });
|
||||
await switchFor(name).waitFor({ state: 'detached' });
|
||||
}
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-table-formula') && !document.querySelector('.xterm'));
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
assert.match(await table.innerText(), /=A2\*4/);
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await settings();
|
||||
await dialog.getByText('No plugins installed.', { exact: true }).waitFor();
|
||||
assert.deepEqual([...page.errors, ...settingsPage.errors], []);
|
||||
} catch (error) {
|
||||
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings-failure.png') });
|
||||
console.log('Settings page:', settingsPage.url(), await settingsPage.locator('body').innerText());
|
||||
await page.screenshot({ path: path.join(output, 'plugins-failure.png') });
|
||||
console.log(await page.locator('.md-page').allTextContents());
|
||||
console.log([...page.errors, ...settingsPage.errors]);
|
||||
throw error;
|
||||
}
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-table-formula') && !document.querySelector('.xterm'));
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
assert.match(await table.innerText(), /=A2\*4/);
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await settings();
|
||||
await dialog.getByText('No plugins installed.', { exact: true }).waitFor();
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('Plugin smoke passed: formulas, source preservation, terminal shutdown, persistence, shortcuts, cross-window enable controls, removal, and no automatic restoration.');
|
||||
} catch (error) {
|
||||
await settingsPage.screenshot({ path: ".audit/plugins-settings-failure.png" });
|
||||
console.log("Settings page:", settingsPage.url(), await settingsPage.locator('body').innerText());
|
||||
await page.screenshot({ path: ".audit/plugins-failure.png" });
|
||||
console.log(await page.locator('.md-page').allTextContents());
|
||||
console.log(errors);
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user