RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
// 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";
|
||||
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) });
|
||||
}
|
||||
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();
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
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();
|
||||
}
|
||||
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, keep disabled", 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.");
|
||||
});
|
||||
Reference in New Issue
Block a user