@@ -6,13 +6,16 @@ import type { AddressInfo } from "node:net";
66import os from "node:os";
77import path from "node:path";
88import JSZip from "jszip";
9- import { describe, expect, it } from "vitest";
9+ import { afterEach, describe, expect, it } from "vitest";
10+ import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
1011import { loadInstalledPluginIndexInstallRecords } from "../plugins/installed-plugin-index-records.js";
1112
1213const PACKAGE_NAME = "@openclaw/telemetry-demo";
1314const PACKAGE_VERSION = "1.0.0";
1415const PLUGIN_ID = "telemetry-demo";
1516const ENCODED_PACKAGE_NAME = encodeURIComponent(PACKAGE_NAME);
17+ const PACKAGE_API_PATH = `/api/v1/packages/${ENCODED_PACKAGE_NAME}`;
18+ const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1619
1720async function readRequestBody(req: IncomingMessage): Promise<string> {
1821 const chunks: Buffer[] = [];
@@ -71,6 +74,8 @@ async function buildPluginZip(): Promise<Buffer> {
7174
7275type TestServerOptions = {
7376 artifactSha256?: string;
77+ artifactCompatibility?: Record<string, string> | null;
78+ packageCompatibility?: Record<string, string>;
7479 telemetryStatus?: number;
7580};
7681
@@ -84,7 +89,7 @@ async function startClawHubServer(options: TestServerOptions = {}) {
8489 async function handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
8590 const url = new URL(req.url ?? "/", "http://127.0.0.1");
8691 requestLog.push(`${req.method ?? "GET"} ${url.pathname}`);
87- const packagePath = `/api/v1/packages/${ENCODED_PACKAGE_NAME}` ;
92+ const packagePath = PACKAGE_API_PATH ;
8893
8994 if (req.method === "GET" && url.pathname === packagePath) {
9095 res.writeHead(200, { "Content-Type": "application/json" });
@@ -99,7 +104,7 @@ async function startClawHubServer(options: TestServerOptions = {}) {
99104 isOfficial: false,
100105 latestVersion: PACKAGE_VERSION,
101106 tags: { latest: PACKAGE_VERSION },
102- compatibility: {},
107+ compatibility: options.packageCompatibility ?? {},
103108 },
104109 owner: { handle: "openclaw" },
105110 }),
@@ -124,7 +129,9 @@ async function startClawHubServer(options: TestServerOptions = {}) {
124129 createdAt: 1,
125130 changelog: "Initial release",
126131 sha256hash: artifactSha256,
127- compatibility: {},
132+ ...(options.artifactCompatibility === null
133+ ? {}
134+ : { compatibility: options.artifactCompatibility ?? {} }),
128135 },
129136 }),
130137 );
@@ -257,6 +264,10 @@ describe("openclaw plugins install ClawHub E2E", () => {
257264 version: PACKAGE_VERSION,
258265 },
259266 ]);
267+ expect(testServer.requestLog).toContain(
268+ `GET ${PACKAGE_API_PATH}/versions/${PACKAGE_VERSION}/security`,
269+ );
270+ expect(testServer.requestLog).toContain(`GET ${PACKAGE_API_PATH}/download`);
260271
261272 const repeat = await spawnOpenClaw(
262273 ["plugins", "install", `clawhub:${PACKAGE_NAME}@${PACKAGE_VERSION}`, "--force"],
@@ -271,6 +282,46 @@ describe("openclaw plugins install ClawHub E2E", () => {
271282 }
272283 }, 60_000);
273284
285+ it.each([
286+ {
287+ label: "package plugin API",
288+ options: {
289+ packageCompatibility: { pluginApiRange: ">=9999.0.0" },
290+ artifactCompatibility: null,
291+ },
292+ error: "requires plugin API >=9999.0.0",
293+ },
294+ {
295+ label: "version gateway",
296+ options: { artifactCompatibility: { minGatewayVersion: "9999.0.0" } },
297+ error: "requires OpenClaw >=9999.0.0",
298+ },
299+ ])(
300+ "rejects incompatible $label metadata before trust and download",
301+ async ({ options, error }) => {
302+ const testServer = await startClawHubServer(options);
303+ const stateDir = tempDirs.make("openclaw-plugin-compatibility-e2e-");
304+ try {
305+ const result = await spawnOpenClaw(
306+ ["plugins", "install", `clawhub:${PACKAGE_NAME}@${PACKAGE_VERSION}`],
307+ { cwd: process.cwd(), env: buildEnv(stateDir, testServer.registry) },
308+ );
309+
310+ expect(result.status).not.toBe(0);
311+ expect(`${result.stdout}\n${result.stderr}`).toContain(error);
312+ expect(testServer.requestLog).not.toContain(
313+ `GET ${PACKAGE_API_PATH}/versions/${PACKAGE_VERSION}/security`,
314+ );
315+ expect(testServer.requestLog).not.toContain(`GET ${PACKAGE_API_PATH}/download`);
316+ expect(testServer.telemetryBodies).toEqual([]);
317+ await expect(readPersistedInstallRecord(stateDir)).resolves.toBeUndefined();
318+ } finally {
319+ await testServer.close();
320+ }
321+ },
322+ 30_000,
323+ );
324+
274325 it("does not report success when plugin installation fails", async () => {
275326 const testServer = await startClawHubServer({ artifactSha256: "0".repeat(64) });
276327 const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-plugin-telemetry-fail-"));
0 commit comments