Files
paseo/packages/app/src/plugins/theme.test.ts
T
Mohamed Boudra 53d824a320 feat(plugins): split client and server plugin entries (#4206)
* feat(plugins): phase 1 split runtime entries after green gate

The compiler now builds explicit client and server entries, so runtime boundaries are source-owned instead of registration-name filtering. Compiler and runtime tests prove the entry split, directory and suffix boundaries, client Node import errors, migration failure, and client-only operation without a subprocess.

* feat(plugins): phase 2 run client entries after green gate

Explicit client and server contexts replace the mixed plugin context. The app runner owns every client registration and its idempotent removal, including late contributions and composer pills; focused contribution tests prove the removal contract, and all five migrated examples reached running on the isolated worktree daemon.

* feat(cli): phase 3 scaffold runtime split after green gate

The generated project demonstrates the required shared RPC contract, server handler, client surface, and sidebar wiring. The scaffold test and an isolated init, typecheck, install, and running check prove the phase acceptance path.

* docs(plugins): phase 4 publish migration after green gate

Gate: current docs and the paseo-plugin skill describe only explicit client/server entries. The standalone migration guide maps every former registration, and migration-doc.test.ts proves every client add* method remains represented.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Gate: compiler 13, runtime 24, typecheck, lint, and format passed. The dependency fixture proved node_modules/client was incorrectly treated as a plugin boundary.

* fixup! feat(plugins): phase 2 run client entries after green gate

Gate: client runtime and registry tests, typecheck, lint, format

* fixup! docs(plugins): phase 4 publish migration after green gate

Gate: migration docs test, paragraph audit, typecheck, lint, format

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Gate: compiler organization tests, typecheck, lint, targeted format

* fixup! feat(plugins): phase 2 run client entries after green gate

Gate: shared SDK tests, runtime tests, typecheck, lint, targeted format

* fixup! feat(cli): phase 3 scaffold runtime split after green gate

* fixup! docs(plugins): phase 4 publish migration after green gate

* fixup! feat(plugins): phase 1 split runtime entries after green gate

* docs(plugins): rewrite public plugin docs for runtime entries and mobile guardrails

* fixup! feat(cli): phase 3 scaffold runtime split after green gate

The scaffold now keeps DOM globals out of the program and declares only window.open inside client/web.ts. The scaffold test invokes tsc in a fresh process, proves the generated project passes, and proves a stray document access fails.

* fixup! docs(plugins): phase 4 publish migration after green gate

The internal guide and plugin skill now forbid both the DOM lib and triple-slash DOM references. They direct web adapters to declare only the globals used by client/web.ts.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Removing the obsolete Babel parser changes the locked npm dependency graph. The macOS Nix desktop gate reported the new fixed-output hash, which this commit records.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Reject relative imports that escape the plugin root while continuing to skip resolved node_modules internals. The compiler regression test proves the escaped import is rejected and the dependency-internal fixture remains accepted.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Classify absolute imports and reject plugin-authored paths that escape into node_modules. Dependency internals remain exempt based on their importer path. Red-first compiler regressions cover both bypasses, and the existing dependency fixture remains green.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Classify canonical esbuild resolution results so dependency-relative and symlink imports cannot escape client/server boundaries. The two compiler regressions failed before the fix and pass afterward.

* test(ci): synchronize flaky state transitions

Wait for repository watcher registration before emitting buffered ref events, let sidebar order polling retry unlaid-out rows, and wait for the inactive browser parking state before screenshot capture. These changes directly address the three observed CI failures; the affected server, Playwright, and desktop browser tests pass locally.

* test(ci): synchronize Mermaid completion layout assertion

The Playwright streaming acceptance test exposed a completion remount between visibility and layout sampling. Check the existing completion promise around the measurement so that transition is not reported as diagram loss.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Resolve bare package imports before boundary classification so symlinked dependency entries cannot expose server modules to the client bundle. The focused regression proves the bypass and the compiler file passes 20/20.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Allow canonical paths only within a matching linked package root while preserving runtime and containment checks for imports that leave it. The linked-dependency regression fails before the fix and compiler tests pass 21/21 afterward.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Reject matching package manifests that contain the plugin or live inside it, so linked-dependency roots cannot exempt plugin or workspace files. The ancestor-manifest regression fails before the fix and compiler tests pass 22/22 afterward.

* fixup! feat(plugins): phase 1 split runtime entries after green gate

Validate plugin-local lexical boundaries before canonical linked-root exemptions and require remembered-root imports to originate inside that root. The linked-root bypass regression fails before the fix and compiler tests pass 23/23 afterward.
2026-09-02 19:11:45 +02:00

211 lines
7.0 KiB
TypeScript

import { QueryClient } from "@tanstack/react-query";
import type { PluginThemeContribution } from "@getpaseo/plugin";
import { describe, expect, it } from "vitest";
import { darkTheme, lightTheme } from "@/styles/theme";
import { collectPluginThemes, rememberPluginThemeHost } from "./themes";
import { toPluginTheme } from "./theme";
import type { InstalledPlugin } from "./types";
const MOCHA: PluginThemeContribution = {
id: "mocha",
name: "Catppuccin Mocha",
appearance: "dark",
colors: {
background: "#1e1e2e",
foreground: "#cdd6f4",
raised: "#313244",
control: "#45475a",
border: "#45475a",
accent: "#cba6f7",
mutedForeground: "#a6adc8",
ring: "#6c7086",
},
};
const MOCHA_FORK: PluginThemeContribution = {
...MOCHA,
colors: { ...MOCHA.colors, background: "#11111b", accent: "#f5c2e7" },
};
const LATTE: PluginThemeContribution = {
id: "latte",
name: "Catppuccin Latte",
appearance: "light",
colors: {
background: "#eff1f5",
foreground: "#4c4f69",
raised: "#e6e9ef",
control: "#dce0e8",
border: "#ccd0da",
accent: "#8839ef",
mutedForeground: "#6c6f85",
ring: "#9ca0b0",
},
};
function installed(serverId: string, themes: PluginThemeContribution[]): InstalledPlugin {
return {
id: "catppuccin",
cleanup: () => undefined,
serverId,
clientBundle: serverId,
queryClient: new QueryClient(),
surfaces: [],
sidebarItems: [],
workspacePanels: [],
commandCenterItems: [],
clientSlashCommands: [],
attachmentSources: [],
themes,
timelineTransformers: [],
timelineRenderers: [],
};
}
describe("toPluginTheme", () => {
it("maps the app theme into the plugin color tokens", () => {
expect(toPluginTheme(lightTheme)).toEqual({
colors: {
surface0: lightTheme.colors.surface0,
surface1: lightTheme.colors.surface1,
surface2: lightTheme.colors.surface2,
border: lightTheme.colors.border,
foreground: lightTheme.colors.foreground,
foregroundMuted: lightTheme.colors.foregroundMuted,
accent: lightTheme.colors.accent,
accentForeground: lightTheme.colors.accentForeground,
statusSuccess: lightTheme.colors.statusSuccess,
statusWarning: lightTheme.colors.statusWarning,
statusDanger: lightTheme.colors.statusDanger,
},
});
});
});
describe("plugin theme palettes", () => {
it("expands a contributed palette onto the semantic and terminal tokens", () => {
const option = collectPluginThemes([installed("host-a", [MOCHA])], new Set(["host-a"]))[0];
const theme = option.theme;
expect(theme.colorScheme).toBe("dark");
expect(theme.colors).toMatchObject({
surface0: "#1e1e2e",
surface1: "#313244",
surface2: "#45475a",
surfaceSidebar: "#1e1e2e",
foreground: "#cdd6f4",
foregroundMuted: "#a6adc8",
border: "#45475a",
accent: "#cba6f7",
accentBright: "#cba6f7",
accentForeground: "#1e1e2e",
ring: "#6c7086",
terminal: {
background: "#1e1e2e",
foreground: "#cdd6f4",
cursor: "#cdd6f4",
cursorAccent: "#1e1e2e",
black: "#45475a",
brightBlack: "#6c7086",
},
});
});
it("carries the accent on the foreground when no accent is given", () => {
const { accent: _accent, ...colors } = MOCHA.colors;
const contribution = { ...MOCHA, colors };
const theme = collectPluginThemes([installed("host-a", [contribution])], new Set(["host-a"]))[0]
.theme;
expect(theme.colors.accent).toBe("#cdd6f4");
expect(theme.colors.accentBright).toBe("#cdd6f4");
});
it("keeps the status and syntax tokens the built-in dark themes use", () => {
const theme = collectPluginThemes([installed("host-a", [MOCHA])], new Set(["host-a"]))[0].theme;
expect(theme.colors.statusDanger).toBe(darkTheme.colors.statusDanger);
expect(theme.colors.syntax).toEqual(darkTheme.colors.syntax);
});
it("derives a complete light theme from the same palette contract", () => {
const theme = collectPluginThemes([installed("host-a", [LATTE])], new Set(["host-a"]))[0].theme;
expect(theme.colorScheme).toBe("light");
expect(theme.colors).toMatchObject({
surface0: "#eff1f5",
surface1: "#e6e9ef",
surface2: "#dce0e8",
surfaceSidebar: "#dce0e8",
foreground: "#4c4f69",
border: "#ccd0da",
accent: "#8839ef",
ring: "#9ca0b0",
terminal: {
background: "#eff1f5",
foreground: "#4c4f69",
black: "#4c4f69",
},
});
expect(theme.colors.statusDanger).toBe(lightTheme.colors.statusDanger);
expect(theme.colors.syntax).toEqual(lightTheme.colors.syntax);
});
});
const SUPPORTED = new Set(["host-a", "host-b", "host-z"]);
describe("collectPluginThemes", () => {
it("coalesces the same contribution across hosts", () => {
const options = collectPluginThemes(
[installed("host-a", [MOCHA]), installed("host-b", [MOCHA])],
new Set(["host-a", "host-b"]),
);
expect(options.map((option) => option.id)).toEqual(["catppuccin/theme/mocha"]);
});
// COMPAT(pluginThemes): a daemon without the capability keeps `addTheme` in the server bundle
// it compiles, so its themes are not offered at all.
it("drops themes from a host that predates the pluginThemes capability", () => {
expect(collectPluginThemes([installed("old-host", [MOCHA])], new Set())).toEqual([]);
});
it("keeps themes from the supported host when one peer is too old", () => {
const options = collectPluginThemes(
[installed("new-host", [MOCHA]), installed("old-host", [MOCHA])],
new Set(["new-host"]),
);
expect(options.map((option) => option.id)).toEqual(["catppuccin/theme/mocha"]);
});
// Two hosts, same plugin and theme id, different palettes. The picked host has to survive a peer
// connecting or dropping, or the app repaints with no settings change. The remembered host is
// module state, so this runs the whole sequence in one test rather than leaning on test order.
it("pins the palette to the picked host across peer connect and disconnect", () => {
const bothHosts = () =>
collectPluginThemes(
[installed("host-a", [MOCHA]), installed("host-z", [MOCHA_FORK])],
SUPPORTED,
);
const beforePick = bothHosts();
expect(beforePick).toHaveLength(1);
expect(beforePick[0]?.serverId).toBe("host-a");
expect(beforePick[0]?.theme.colors.surface0).toBe("#1e1e2e");
const onlyHostZ = collectPluginThemes([installed("host-z", [MOCHA_FORK])], SUPPORTED);
expect(onlyHostZ[0]).toBeDefined();
rememberPluginThemeHost(onlyHostZ[0]);
const afterPick = bothHosts();
expect(afterPick).toHaveLength(1);
expect(afterPick[0]?.serverId).toBe("host-z");
expect(afterPick[0]?.theme.colors.surface0).toBe("#11111b");
const withoutHostZ = collectPluginThemes([installed("host-a", [MOCHA])], SUPPORTED);
expect(withoutHostZ[0]?.serverId).toBe("host-a");
expect(withoutHostZ[0]?.theme.colors.surface0).toBe("#1e1e2e");
});
});