mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-24 10:12:44 +00:00
* fix(plugins): keep React out of the server plugin host * fix(plugins): align SDK guidance and tests with runtime boundaries * fix(plugin): loosen the react peer to ~19.1.0 The plugin SDK pins its react peer to exactly 19.1.0, and that pin is what a downstream `npm i -g @getpaseo/cli` resolves against. So every user ends up with react 19.1.0 in their global node_modules, where corporate dependency scanners flag it: the CVE-2025-55182 advisory range covers 19.1.0 even though the vulnerability itself lives in react-server-dom-webpack/-parcel/-turbopack, none of which the CLI installs. The user is then left hand-patching node_modules or uninstalling Paseo. Widening the peer to ~19.1.0 lets a downstream install pick the latest 19.1.x patch (19.1.9 today) while this repo stays on 19.1.0, which the root override still pins. Keeping the repo itself on 19.1.0 is deliberate. react-native 0.81.5 embeds a 19.1.0 Paper renderer that hard-throws "Incompatible React versions" on any exact mismatch, and it is reachable from Fabric builds too: RendererImplementation.js requires the Paper shim unconditionally in findNodeHandle, unstable_batchedUpdates, sendAccessibilityEvent and three other entry points, and react-native-gesture-handler re-exports findNodeHandle. Bumping the app's react is therefore not safe until react-native moves. The published CLI tree contains no react-native, so downstream installs are not subject to that constraint. Supersedes the earlier 19.1.5/19.1.9 version-bump approach on this branch, which would have broken the mobile app. * Enforce example import ownership including client types * Update Nix dependency hash for plugin peer metadata * Group plugin APIs under client and server entry trees * Resolve plugin type dependencies through declarations * Validate declarations for implicit plugin type imports * Preserve optional imports and validate declaration references * Refresh Nix hash for plugin declaration resolver * Canonicalize plugin paths consistently on Windows * Normalize plugin ownership paths across resolver boundaries --------- Co-authored-by: liujin0506 <liujin0506@qq.com> Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
110 lines
3.2 KiB
TypeScript
110 lines
3.2 KiB
TypeScript
import { describe, expect, expectTypeOf, it } from "vitest";
|
|
import { z } from "zod";
|
|
import { defineAttachmentSource, defineRpc, type RpcInput, type RpcOutput } from "../index.js";
|
|
import { callPluginRpc, searchPluginAttachments } from "./host.js";
|
|
|
|
const contract = defineRpc({
|
|
name: "increment",
|
|
input: z.unknown().pipe(z.object({ value: z.number() })),
|
|
output: z.object({ value: z.number() }),
|
|
});
|
|
|
|
describe("plugin RPC contracts", () => {
|
|
it("derives handler input and output types from a contract", () => {
|
|
expectTypeOf<RpcInput<typeof contract>>().toEqualTypeOf<{ value: number }>();
|
|
expectTypeOf<RpcOutput<typeof contract>>().toEqualTypeOf<{ value: number }>();
|
|
});
|
|
|
|
it("validates input before invoking the daemon", async () => {
|
|
let invocations = 0;
|
|
const invoke = async () => {
|
|
invocations += 1;
|
|
return { value: 2 };
|
|
};
|
|
|
|
await expect(callPluginRpc(contract, invoke, { value: "wrong" })).rejects.toBeInstanceOf(
|
|
z.ZodError,
|
|
);
|
|
expect(invocations).toBe(0);
|
|
});
|
|
|
|
it("validates output before resolving", async () => {
|
|
const invoke = async () => ({ value: "wrong" });
|
|
|
|
await expect(callPluginRpc(contract, invoke, { value: 1 })).rejects.toBeInstanceOf(z.ZodError);
|
|
});
|
|
|
|
it("returns parsed output for a valid invocation", async () => {
|
|
const invoke = async (method: string, input: unknown) => ({
|
|
value: method === "increment" && typeof input === "object" ? 2 : 0,
|
|
});
|
|
|
|
await expect(callPluginRpc(contract, invoke, { value: 1 })).resolves.toEqual({ value: 2 });
|
|
});
|
|
});
|
|
|
|
describe("plugin attachment sources", () => {
|
|
const search = defineRpc({
|
|
name: "issues.search",
|
|
input: z.object({ query: z.string() }),
|
|
output: z.object({
|
|
items: z.array(
|
|
z.object({
|
|
id: z.string(),
|
|
identifier: z.string(),
|
|
title: z.string(),
|
|
subtitle: z.string().optional(),
|
|
url: z.string(),
|
|
text: z.string(),
|
|
resourceType: z.string(),
|
|
}),
|
|
),
|
|
}),
|
|
});
|
|
|
|
it("searches through the declared RPC and validates the standard result", async () => {
|
|
const source = defineAttachmentSource({
|
|
id: "issues",
|
|
title: "Issue",
|
|
icon: "CircleDot",
|
|
pickerTitle: "Attach issue",
|
|
searchPlaceholder: "Search",
|
|
search,
|
|
});
|
|
|
|
const payload = await searchPluginAttachments(
|
|
source,
|
|
async (method, input) => ({
|
|
items: [
|
|
{
|
|
id: "issue-1",
|
|
identifier: `${method}:${String(Reflect.get(input as object, "query"))}`,
|
|
title: "Plugin attachments",
|
|
url: "https://example.com/issues/1",
|
|
text: "Issue snapshot",
|
|
resourceType: "issue",
|
|
},
|
|
],
|
|
}),
|
|
"ENG-123",
|
|
);
|
|
|
|
expect(payload.items[0]?.identifier).toBe("issues.search:ENG-123");
|
|
});
|
|
|
|
it("rejects a malformed standard search result", async () => {
|
|
const source = defineAttachmentSource({
|
|
id: "issues",
|
|
title: "Issue",
|
|
icon: "CircleDot",
|
|
pickerTitle: "Attach issue",
|
|
searchPlaceholder: "Search",
|
|
search,
|
|
});
|
|
|
|
await expect(
|
|
searchPluginAttachments(source, async () => ({ items: [{ id: "issue-1" }] }), "issue"),
|
|
).rejects.toBeInstanceOf(z.ZodError);
|
|
});
|
|
});
|