diff --git a/docs/development.md b/docs/development.md index 4b98b8a..8fc62b2 100644 --- a/docs/development.md +++ b/docs/development.md @@ -190,7 +190,7 @@ Some tests need files from outside this repository. Without those files, the tes The plugin SDK in `packages/plugin-sdk/` is the only source of the public plugin types. The host imports it with relative paths in `src/lib/plugins/sdk.ts`, `src/lib/ui/actionIcons.ts`, and `src/lib/ui/tooltip.ts`. Change a public type in the SDK, not in the host. Keep host-only types, such as the native transports, in `src/lib/plugins/sdk.ts`. -The menu types in `src/lib/ui/actionMenu.ts` and `src/lib/ui/managedActionMenu.ts` are the exception. The Terminal plugin keeps copies of these two files, and `pnpm check:menus` compares them. +The menu types in `src/lib/ui/actionMenu.ts` and `src/lib/ui/managedActionMenu.ts` are the exception: they keep their own declarations. `tests/unit/sdk/features.spec.ts` makes sure that their types and the SDK menu types are the same. The SDK source must not import host files. It must use only TypeScript syntax that Node.js can remove, because the unit tests load it directly. diff --git a/scripts/menuSurfaceAudit.mjs b/scripts/menuSurfaceAudit.mjs index 9d79761..368ee46 100644 --- a/scripts/menuSurfaceAudit.mjs +++ b/scripts/menuSurfaceAudit.mjs @@ -45,13 +45,6 @@ export async function checkInventory() { else if (!entry.design || !entry.check) failures.push(`Missing design or check: ${file}`); } for (const file of Object.keys(inventory.surfaces)) if (!(file in surfaces)) failures.push(`Stale inventory: ${file}`); - for (const name of ['actionMenu.ts', 'managedActionMenu.ts', 'IconButton.svelte']) { - try { - const host = await readFile(path.join(root, 'src/lib/ui', name), 'utf8'); - const terminal = await readFile(path.resolve(pluginRepos, 'RuneStone_Terminal/vendor/runestone/ui', name), 'utf8'); - if (host.replaceAll('\r\n', '\n') !== terminal.replaceAll('\r\n', '\n')) failures.push(`Terminal shared snapshot differs: ${name}`); - } catch (error) { failures.push(`Cannot check Terminal snapshot ${name}: ${error.code}`); } - } if (failures.length) { console.error(failures.join('\n')); return false; } console.log(`PASS: ${Object.keys(surfaces).length} source files across ${projects.length} projects match the reviewed menu inventory. Runtime checks remain separate.`); return true; diff --git a/scripts/smoke.mjs b/scripts/smoke.mjs index 7872ce8..bca4187 100644 --- a/scripts/smoke.mjs +++ b/scripts/smoke.mjs @@ -181,6 +181,13 @@ if (list) { } findChrome(); +// Tests that load plugin source resolve "@runestone/plugin-sdk" to this build. +if (!existsSync(path.join(root, "packages", "plugin-sdk", "dist", "index.js"))) { + console.log("Building the plugin SDK..."); + const build = spawn(process.execPath, [path.join(root, "scripts", "buildSdk.mjs")], { cwd: root, stdio: "inherit", windowsHide: true }); + const code = await new Promise(resolve => build.on("close", resolve)); + if (code !== 0) throw new Error("The plugin SDK build failed. Run pnpm sdk:build."); +} await mkdir(logRoot, { recursive: true }); let server; if (!(await reachable(env.SMOKE_URL))) { diff --git a/tests/smoke/layout/workbench.smoke.mjs b/tests/smoke/layout/workbench.smoke.mjs index b1736de..dbd0cc1 100644 --- a/tests/smoke/layout/workbench.smoke.mjs +++ b/tests/smoke/layout/workbench.smoke.mjs @@ -34,9 +34,13 @@ await runSmoke("layout/workbench", async ({ page }) => { workspace_search: () => [], pty_profiles: () => [{ id: "powershell", title: "PowerShell", kind: "powershell" }], pty_open: async args => { - const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")]; - test.emit("pty-data", { id: args.id, data: data.slice(0, 8) }); - test.emit("pty-data", { id: args.id, data: data.slice(8) }); + const data = new TextEncoder().encode("READY 🪨\r\n\x1b[6n"); + // A Terminal plugin that uses api.pty passes a channel and gets raw bytes. Released versions listen for events. + if (args.channel) setTimeout(() => { args.channel.onmessage(data.slice(0, 8).buffer); args.channel.onmessage(data.slice(8).buffer); }, 0); + else { + test.emit("pty-data", { id: args.id, data: [...data.slice(0, 8)] }); + test.emit("pty-data", { id: args.id, data: [...data.slice(8)] }); + } await new Promise(resolve => setTimeout(resolve, 50)); }, "plugin:dialog|message": () => "Cancel", diff --git a/tests/smoke/plugins/gitToolbar.smoke.mjs b/tests/smoke/plugins/gitToolbar.smoke.mjs index e25292b..861c89e 100644 --- a/tests/smoke/plugins/gitToolbar.smoke.mjs +++ b/tests/smoke/plugins/gitToolbar.smoke.mjs @@ -1,18 +1,26 @@ // 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. +// Its "@runestone/plugin-sdk" imports resolve to this repository's SDK build (packages/plugin-sdk/dist), which the runner builds. 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"; +import { mockTauri, outputDir, pluginRepo, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs"; + +const sdkImport = /(\bfrom\s*|\bimport\s*\(\s*)(["'])@runestone\/plugin-sdk(?:\/([a-z-]+))?\2/g; +const resolveSdk = source => source.replace(sdkImport, (_, keyword, quote, entry) => `${keyword}${quote}/__runestone_sdk/${entry || "index"}.js${quote}`); 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 files = new Map(await Promise.all(["view.js", "model.js"].map(async file => [file, resolveSdk(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 page.route("**/__runestone_sdk/*", async route => { + const file = path.join(repoRoot, "packages/plugin-sdk/dist", path.basename(new URL(route.request().url()).pathname)); + await route.fulfill({ contentType: "text/javascript", body: await readFile(file, "utf8") }); + }); await mockTauri(page, { commands: test => ({ ...test.workspace({ root: "C:\\git-toolbar", files: { "notes/draft.md": "Before.\n" } }), diff --git a/tests/smoke/plugins/lifecycle.smoke.mjs b/tests/smoke/plugins/lifecycle.smoke.mjs index a9ff42f..94a122c 100644 --- a/tests/smoke/plugins/lifecycle.smoke.mjs +++ b/tests/smoke/plugins/lifecycle.smoke.mjs @@ -33,10 +33,14 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => { }, 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) }); + pty_open: async ({ id, channel }) => { + const data = new TextEncoder().encode('READY 🪨\r\n\x1b[6n'); + // A Terminal plugin that uses api.pty passes a channel and gets raw bytes. Released versions listen for events. + if (channel) setTimeout(() => { channel.onmessage(data.slice(0, 8).buffer); channel.onmessage(data.slice(8).buffer); }, 0); + else { + 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,