Files
paseo/packages/app/e2e/support/helpers/plugin-directory.ts
T
Mohamed Boudra ef146bc62d Browse, install and manage plugins from a built-in gallery (#9752)
* feat(app): browse, install and manage plugins from a built-in gallery

Settings → Host → Plugins becomes a gallery with two tabs. Installed lists
the host's plugins with on/off switches and pending updates. Browse lists the
plugin directory with featured cards, categories, sorting and search. Each
plugin has its own page with its screenshots, overview, details, install or
on/off controls, and its own settings screens inline.

Every install asks first, in a sheet naming the source and version, because
installing runs the plugin's code on the host. Uninstalling also asks first;
its confirm says what is deleted.

The daemon fetches the directory from its configured registry
(plugin.registry.list/get, gated by server_info.features.pluginRegistry). The
app never fetches from the registry itself, so a host with a private registry
shows that registry.

README overviews render with the registry's overview contract (the same one
the website uses): only https links and images work, and nothing is read as a
workspace file. Before this, a word like "Node.js" became a broken relative
link.

* fix(app): refresh plugin failures and leave Settings cleanly from a plugin page

The Installed row read the app-side evaluation error without subscribing to the
registry, so a plugin fixed by Reload kept its "failed" badge. Rows and the
plugin page now subscribe through usePluginEvaluationError.

Leaving Settings with no remembered workspace replaced only the top stack entry;
with a plugin page pushed on top, the Plugins list stayed mounted underneath and
reopening Settings stacked a second copy. Dismiss the Settings entries first.

* fix(app): keep Browse working as the registry grows, and test it end to end

Registry listings now reach apps through an open wire schema
(plugin.registry.list/get carry PluginListing*), and the daemon drops a listing
it cannot read instead of failing the whole index. A registry that adds an
artifact kind or bumps schemaVersion no longer breaks Browse on older apps.

The gallery picks its opening tab once, so installing the first plugin keeps
the user on Browse. README links open only https: the parser still autolinks
bare http, www and email text, so a press checks the URL again.

Adds a Browse e2e test against a local registry and Git repository: install
from a row through the confirm sheet, stay on Browse, open the listing page,
uninstall from it.

* test(server): give the oversized-sibling diff refresh the same time budget as its siblings

expect.poll defaults to one second, which a Windows git diff refresh can exceed.

* test(server): wait as long as the other observer tests for native watcher events

expect.poll defaults to one second; macOS FSEvents can deliver later than that on CI.

* fix(app): keep a listed plugin's page usable after uninstalling it, and fetch the directory less

An installed plugin's page finds its listing through the plugin, so uninstalling
a directory plugin from the Installed tab left "not installed or listed" with no
way back. The page now becomes the listing's page, offering Install again.

Updates are re-checked when the host's plugins change and after a failed update,
whose proposal named a revision that no longer exists. The directory, listing
and update queries refetch on mount only once stale, so opening a plugin's page
no longer refetches the whole directory and every update check.

* test(app): install the plugin before opening Plugins in the busy-queue reload test

Plugins opens on Browse when the host has no plugins and stays there after the first install, so a plugin installed through the daemon after the page opened never showed on Installed.

* test(website): wait for hydration before scrolling to the hero in a short window

The router resets the scroll position when the page hydrates. Scrolling to the mockup before that left it below the window, so its start line never came on screen and the opening scene never played. It failed 7 of 10 runs on webkit.

* fix(server): show the registry setup error on Browse instead of asking to retry

The registry's request headers were built inside the try around fetch, so a setup error such as credentials over plain HTTP came back as "Could not reach plugin registry. Retry later." Install already built them first.

* fix(app): show plugin errors without the request details meant for logs

A daemon RPC error's message ends with requestType=… code=…; the daemon's own text is in userMessage. Gallery alerts and toasts now show that text.

* fix(app): show why an update failed on the plugin's page

The update operation's failure was recorded under the plugin ID, but the page only read it to show the spinner, so a failed update looked as if nothing happened. The page now shows the error in its own alert, without the plugin's Failed badge, because the installed version keeps running. While an update is still available the button reads Retry.

* fix(app): show a plugin page's update error only while the update is offered

The failed update stayed in the operations store after the plugin was updated elsewhere or uninstalled, so the page kept saying the update failed. The page now shows it with the Update button it belongs to, as the Installed tab's Updates row does, and uninstalling forgets it.
2026-11-15 20:34:13 +07:00

206 lines
7.2 KiB
TypeScript

import { execFileSync } from "node:child_process";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { createServer } from "node:http";
import { tmpdir } from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { expect, test as base, type Page } from "../fixtures";
import appPackage from "../../../package.json";
import { gotoAppShell, openSettings } from "./app";
import { addConnectedHostAndReload } from "./hosts";
import { pluginRequirements } from "./plugin-fixture";
import {
expectToast,
openPluginPage,
pluginPageName,
selectInstalledTab,
selectPluginPageAction,
} from "./plugin-gallery";
import { openHostSection, selectSettingsHost } from "./settings";
import { startHostDaemon } from "./versioned-host-daemon";
/**
* Settings → Plugins → Browse against a host whose registry is a local server. The one listing
* installs from a local Git repository, so installing needs no network.
*/
export const LISTING = {
id: "acme/directory-example",
name: "Directory example",
description: "Adds a review checklist to every workspace",
overview: "Directory example keeps a checklist beside your agents.",
};
export const test = base.extend<{ directoryHost: { serverId: string; port: number } }>({
directoryHost: async ({ e2eWorker }, provide) => {
void e2eWorker;
const root = await mkdtemp(path.join(tmpdir(), "paseo-plugin-directory-"));
const registry = await startRegistry(await createListedPlugin(root));
try {
const host = await startHostDaemon({
version: appPackage.version,
pluginRegistryUrl: registry.url,
});
try {
await provide({ serverId: host.serverId, port: host.port });
} finally {
await host.dispose();
}
} finally {
await registry.close();
await rm(root, { recursive: true, force: true });
}
},
});
async function createListedPlugin(root: string) {
const repository = path.join(root, "repository");
execFileSync("git", ["init", "-b", "main", repository], { stdio: "ignore" });
await writeFile(
path.join(repository, "paseo-plugin.json"),
JSON.stringify({
id: "directory-example",
name: LISTING.name,
requirements: pluginRequirements,
}),
);
await writeFile(
path.join(repository, "index.client.ts"),
"export default function () { return () => {}; }",
);
const git = (...args: string[]) =>
execFileSync(
"git",
["-c", "user.name=Paseo Tests", "-c", "user.email=e2e@paseo.test", ...args],
{
cwd: repository,
encoding: "utf8",
},
).trim();
git("add", "-A");
git("commit", "-m", "initial");
const date = "2026-10-03T00:00:00.000Z";
return {
id: LISTING.id,
name: LISTING.name,
description: LISTING.description,
categories: ["tools"],
author: { github: "acme", name: "Acme" },
repository: { url: "https://github.com/acme/directory-example" },
artifact: {
kind: "git",
remote: pathToFileURL(repository).href,
commit: git("rev-parse", "HEAD"),
},
media: [],
submittedAt: date,
reviewedAt: date,
updatedAt: date,
publishedAt: date,
installs: 1200,
};
}
async function startRegistry(listing: Record<string, unknown>) {
const documents: Record<string, unknown> = {
"/index.json": {
schemaVersion: 1,
registry: { name: "Local", url: "http://127.0.0.1" },
categories: [{ slug: "tools", label: "Tools" }],
plugins: [listing],
featured: [],
generatedAt: "2026-10-03T00:00:00.000Z",
},
[`/plugins/${LISTING.id}.json`]: {
...listing,
readme: `# ${LISTING.name}\n\n${LISTING.overview}`,
},
};
const server = createServer((request, response) => {
const document = request.url ? documents[request.url] : undefined;
if (!document) {
response.writeHead(404).end();
return;
}
response.setHeader("Content-Type", "application/json");
response.end(JSON.stringify(document));
});
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const address = server.address();
if (!address || typeof address === "string") throw new Error("Missing registry address");
return {
url: `http://127.0.0.1:${address.port}`,
close: () => new Promise<void>((resolve) => server.close(() => resolve())),
};
}
function listingRow(page: Page) {
return page.getByTestId(`plugin-listing-${LISTING.id}`).filter({ visible: true });
}
function browseTab(page: Page) {
return page.getByRole("button", { name: "Browse", exact: true });
}
/** A host with no plugins opens Plugins on Browse. */
export async function openDirectory(page: Page, host: { serverId: string; port: number }) {
await gotoAppShell(page);
await addConnectedHostAndReload(page, { ...host, label: "Plugin directory" });
await openSettings(page);
await selectSettingsHost(page, host.serverId);
await openHostSection(page, host.serverId, "plugins");
await expect(browseTab(page)).toHaveAttribute("aria-selected", "true");
await expect(listingRow(page)).toContainText(LISTING.description);
}
/** Install asks first, naming the author and version, then the row offers Uninstall. */
export async function installListingFromRow(page: Page) {
await listingRow(page).getByTestId(`plugin-install-${LISTING.id}`).click();
const sheet = page.getByTestId("plugin-install-sheet");
await expect(sheet).toContainText("Acme");
await sheet.getByTestId("plugin-install-confirm").click();
await expect(listingRow(page).getByTestId(`plugin-uninstall-${LISTING.id}`)).toBeVisible({
timeout: 60_000,
});
}
/** Installing the first plugin keeps the user on Browse. */
export async function expectStillBrowsing(page: Page) {
await expect(browseTab(page)).toHaveAttribute("aria-selected", "true");
await expect(page.getByRole("button", { name: /^Installed · 1/ })).toBeVisible();
}
export async function openListingPage(page: Page) {
await listingRow(page).getByText(LISTING.name, { exact: true }).click();
await expect(pluginPageName(page)).toHaveText(LISTING.name);
await expect(page.getByText(LISTING.overview, { exact: true })).toBeVisible();
}
/**
* Uninstalling keeps the plugin's page open on its listing, back on Install, whether the page was
* opened from Browse or from the Installed tab.
*/
export async function uninstallFromPage(page: Page) {
page.once("dialog", (dialog) => dialog.accept());
await selectPluginPageAction(page, LISTING.name, "Uninstall");
await expectToast(page, `Uninstalled ${LISTING.name}`);
await expect(pluginPageName(page)).toHaveText(LISTING.name);
await expect(
page.getByTestId(`plugin-install-${LISTING.id}`).filter({ visible: true }),
).toBeVisible();
}
export async function installFromPage(page: Page) {
await page.getByTestId(`plugin-install-${LISTING.id}`).filter({ visible: true }).click();
await page.getByTestId("plugin-install-confirm").click();
await expect(
page.getByRole("button", { name: `Actions for ${LISTING.name}`, exact: true }),
).toBeVisible({ timeout: 60_000 });
}
export async function openFromInstalledTab(page: Page) {
await page.getByRole("button", { name: "Back to plugins", exact: true }).click();
await selectInstalledTab(page);
await openPluginPage(page, LISTING.name, "directory-example");
}