Skip to content

Commit 35217ad

Browse files
committed
test(qa): cover ClawHub package compatibility
1 parent 554a6f3 commit 35217ad

2 files changed

Lines changed: 80 additions & 4 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
title: ClawHub package compatibility validation
2+
3+
scenario:
4+
id: clawhub-package-compatibility
5+
surface: clawhub
6+
category: clawhub.compatibility-and-trust
7+
coverage:
8+
primary:
9+
- clawhub.clawhub-package-compatibility-validation
10+
objective: Verify ClawHub plugin compatibility metadata is enforced before trust checks or artifact download.
11+
successCriteria:
12+
- Incompatible package-level plugin API metadata fails visibly before trust checks or download.
13+
- Incompatible version-level minimum Gateway metadata fails visibly before trust checks or download.
14+
- Rejected installs leave no install record or telemetry.
15+
- Compatible metadata downloads and installs the plugin, persists its install record, and reports telemetry.
16+
docsRefs:
17+
- docs/cli/plugins.md
18+
- docs/plugins/manifest.md
19+
codeRefs:
20+
- src/cli/plugins-cli.clawhub-install.e2e.test.ts
21+
- src/plugins/clawhub.ts
22+
execution:
23+
kind: vitest
24+
path: src/cli/plugins-cli.clawhub-install.e2e.test.ts
25+
summary: Runs real CLI installs against a local ClawHub HTTP fixture and checks compatibility rejection ordering plus compatible install side effects.

‎src/cli/plugins-cli.clawhub-install.e2e.test.ts‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import type { AddressInfo } from "node:net";
66
import os from "node:os";
77
import path from "node:path";
88
import 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";
1011
import { loadInstalledPluginIndexInstallRecords } from "../plugins/installed-plugin-index-records.js";
1112

1213
const PACKAGE_NAME = "@openclaw/telemetry-demo";
1314
const PACKAGE_VERSION = "1.0.0";
1415
const PLUGIN_ID = "telemetry-demo";
1516
const ENCODED_PACKAGE_NAME = encodeURIComponent(PACKAGE_NAME);
17+
const PACKAGE_API_PATH = `/api/v1/packages/${ENCODED_PACKAGE_NAME}`;
18+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1619

1720
async function readRequestBody(req: IncomingMessage): Promise<string> {
1821
const chunks: Buffer[] = [];
@@ -71,6 +74,8 @@ async function buildPluginZip(): Promise<Buffer> {
7174

7275
type 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

Comments
 (0)