Skip to content

Commit f6a63db

Browse files
committed
test(clawhub): cover plugin release policy contracts
1 parent 361c07f commit f6a63db

2 files changed

Lines changed: 265 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
title: ClawHub release policy contracts
2+
3+
scenario:
4+
id: clawhub-release-policy-contracts
5+
surface: clawhub
6+
category: clawhub.publishing
7+
coverage:
8+
primary:
9+
- clawhub.package-release-validation
10+
- clawhub.version-bump-gates
11+
- clawhub.npm-trusted-publishing-provenance
12+
- clawhub.external-code-plugin-package-contract-required
13+
objective: Verify the real OpenClaw ClawHub and npm release checks enforce publishable plugin identity, provenance, compatibility metadata, and version bumps.
14+
successCriteria:
15+
- Valid publishable metadata passes both release checks with the expected package name, version, and extension id.
16+
- A noncanonical repository URL fails the npm trusted-publishing provenance gate.
17+
- Missing plugin API compatibility or build-version metadata fails the external code plugin package contract.
18+
- A committed source change without a version bump fails the ClawHub release check.
19+
- The same source change passes after the package version and compatibility metadata are bumped and committed.
20+
docsRefs:
21+
- docs/clawhub/publishing.md
22+
- docs/plugins/community.md
23+
- docs/help/testing-updates-plugins.md
24+
codeRefs:
25+
- scripts/plugin-clawhub-release-check.ts
26+
- scripts/plugin-npm-release-check.ts
27+
- scripts/lib/plugin-clawhub-release.ts
28+
- scripts/lib/plugin-npm-release.ts
29+
- packages/plugin-package-contract/src/index.ts
30+
- test/e2e/qa-lab/plugins/clawhub-release-policy-contracts.e2e.test.ts
31+
execution:
32+
kind: vitest
33+
path: test/e2e/qa-lab/plugins/clawhub-release-policy-contracts.e2e.test.ts
34+
summary: Execute the real ClawHub and npm release-check scripts against valid and invalid temporary git plugin packages.
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
// ClawHub release policy tests execute the real npm and ClawHub release checks.
2+
import { spawnSync } from "node:child_process";
3+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4+
import { join, resolve } from "node:path";
5+
import { afterEach, describe, expect, it } from "vitest";
6+
import { cleanupTempDirs, makeTempRepoRoot, writeJsonFile } from "../../../helpers/temp-repo.js";
7+
8+
const CLAWHUB_CHECK = resolve("scripts/plugin-clawhub-release-check.ts");
9+
const NPM_CHECK = resolve("scripts/plugin-npm-release-check.ts");
10+
const REPOSITORY_URL = "https://github.com/openclaw/openclaw";
11+
const PACKAGE_NAME = "@openclaw/demo-plugin";
12+
const INITIAL_VERSION = "2026.8.3";
13+
const tsxImport = import.meta.resolve("tsx");
14+
const tempDirs: string[] = [];
15+
16+
type FixtureOptions = {
17+
includeBuildVersion?: boolean;
18+
includePluginApi?: boolean;
19+
repositoryUrl?: string;
20+
version?: string;
21+
};
22+
23+
afterEach(() => cleanupTempDirs(tempDirs));
24+
25+
function git(cwd: string, args: string[]) {
26+
const result = spawnSync("git", ["-C", cwd, ...args], {
27+
encoding: "utf8",
28+
stdio: ["ignore", "pipe", "pipe"],
29+
});
30+
expect(result.status, result.stderr).toBe(0);
31+
return result.stdout.trim();
32+
}
33+
34+
function packageManifest(options: FixtureOptions = {}) {
35+
const version = options.version ?? INITIAL_VERSION;
36+
return {
37+
name: PACKAGE_NAME,
38+
version,
39+
type: "module",
40+
repository: {
41+
type: "git",
42+
url: options.repositoryUrl ?? REPOSITORY_URL,
43+
},
44+
openclaw: {
45+
extensions: ["./index.ts"],
46+
...(options.includePluginApi === false
47+
? {}
48+
: {
49+
compat: {
50+
pluginApi: `>=${version}`,
51+
},
52+
}),
53+
...(options.includeBuildVersion === false
54+
? {}
55+
: {
56+
build: {
57+
openclawVersion: version,
58+
},
59+
}),
60+
install: {
61+
npmSpec: PACKAGE_NAME,
62+
},
63+
release: {
64+
publishToClawHub: true,
65+
publishToNpm: true,
66+
},
67+
},
68+
};
69+
}
70+
71+
function createPluginRepo(options: FixtureOptions = {}) {
72+
const repoDir = makeTempRepoRoot(tempDirs, "openclaw-clawhub-policy-");
73+
const packageDir = join(repoDir, "extensions", "demo-plugin");
74+
mkdirSync(packageDir, { recursive: true });
75+
writeJsonFile(join(repoDir, "package.json"), {
76+
name: "openclaw-release-policy-fixture",
77+
private: true,
78+
});
79+
writeFileSync(join(repoDir, "pnpm-lock.yaml"), "lockfileVersion: '9.0'\n", "utf8");
80+
writeJsonFile(join(packageDir, "package.json"), packageManifest(options));
81+
writeFileSync(join(packageDir, "index.ts"), "export const demo = 1;\n", "utf8");
82+
writeFileSync(join(packageDir, "README.md"), "# Demo plugin\n", "utf8");
83+
84+
git(repoDir, ["init", "-b", "main"]);
85+
git(repoDir, ["add", "."]);
86+
git(repoDir, [
87+
"-c",
88+
"user.name=OpenClaw Test",
89+
"-c",
90+
91+
"commit",
92+
"-m",
93+
"initial plugin",
94+
]);
95+
return repoDir;
96+
}
97+
98+
function commitFixture(repoDir: string, message: string) {
99+
git(repoDir, ["add", "."]);
100+
git(repoDir, [
101+
"-c",
102+
"user.name=OpenClaw Test",
103+
"-c",
104+
105+
"commit",
106+
"-m",
107+
message,
108+
]);
109+
return git(repoDir, ["rev-parse", "HEAD"]);
110+
}
111+
112+
function runCheck(scriptPath: string, cwd: string, args: string[] = []) {
113+
return spawnSync(process.execPath, ["--import", tsxImport, scriptPath, ...args], {
114+
cwd,
115+
encoding: "utf8",
116+
env: {
117+
...process.env,
118+
NO_COLOR: "1",
119+
},
120+
});
121+
}
122+
123+
function expectValidPackage(result: ReturnType<typeof runCheck>, command: string, version: string) {
124+
expect(result.status, result.stderr).toBe(0);
125+
expect(result.stderr).toBe("");
126+
expect(result.stdout).toContain(`${command}: publishable plugin metadata looks OK.`);
127+
expect(result.stdout).toContain(`- ${PACKAGE_NAME}@${version} (stable, demo-plugin)`);
128+
}
129+
130+
describe("ClawHub release policy contracts", () => {
131+
it("validates package identity, version, and extension metadata through both release checks", () => {
132+
const repoDir = createPluginRepo();
133+
134+
expectValidPackage(
135+
runCheck(CLAWHUB_CHECK, repoDir),
136+
"plugin-clawhub-release-check",
137+
INITIAL_VERSION,
138+
);
139+
expectValidPackage(runCheck(NPM_CHECK, repoDir), "plugin-npm-release-check", INITIAL_VERSION);
140+
});
141+
142+
it("requires the canonical repository provenance for ClawHub and npm publishing", () => {
143+
const repoDir = createPluginRepo({
144+
repositoryUrl: "https://example.invalid/not-openclaw",
145+
});
146+
const expected = `package.json repository.url must be "${REPOSITORY_URL}" so npm provenance can validate GitHub trusted publishing`;
147+
148+
for (const scriptPath of [CLAWHUB_CHECK, NPM_CHECK]) {
149+
const result = runCheck(scriptPath, repoDir);
150+
expect(result.status).toBe(1);
151+
expect(result.stdout).toBe("");
152+
expect(result.stderr).toContain(expected);
153+
}
154+
});
155+
156+
it("requires the external code plugin compatibility and build contract", () => {
157+
const repoDir = createPluginRepo({
158+
includeBuildVersion: false,
159+
includePluginApi: false,
160+
});
161+
162+
for (const scriptPath of [CLAWHUB_CHECK, NPM_CHECK]) {
163+
const result = runCheck(scriptPath, repoDir);
164+
expect(result.status).toBe(1);
165+
expect(result.stdout).toBe("");
166+
expect(result.stderr).toContain(
167+
"openclaw.compat.pluginApi is required for external code plugin packages.",
168+
);
169+
expect(result.stderr).toContain(
170+
"openclaw.build.openclawVersion is required for external code plugin packages.",
171+
);
172+
}
173+
});
174+
175+
it("rejects a changed publishable plugin whose committed version did not change", () => {
176+
const repoDir = createPluginRepo();
177+
const baseRef = git(repoDir, ["rev-parse", "HEAD"]);
178+
writeFileSync(
179+
join(repoDir, "extensions", "demo-plugin", "index.ts"),
180+
"export const demo = 2;\n",
181+
"utf8",
182+
);
183+
const headRef = commitFixture(repoDir, "change plugin source");
184+
185+
const result = runCheck(CLAWHUB_CHECK, repoDir, ["--base-ref", baseRef, "--head-ref", headRef]);
186+
187+
expect(result.status).toBe(1);
188+
expect(result.stdout).toBe("");
189+
expect(result.stderr).toContain("version bumps required before ClawHub publish");
190+
expect(result.stderr).toContain(
191+
`${PACKAGE_NAME}@${INITIAL_VERSION}: changed publishable plugin still has the same version in package.json.`,
192+
);
193+
});
194+
195+
it("accepts a source change with a committed package version bump", () => {
196+
const repoDir = createPluginRepo();
197+
const baseRef = git(repoDir, ["rev-parse", "HEAD"]);
198+
const nextVersion = "2026.8.4";
199+
writeFileSync(
200+
join(repoDir, "extensions", "demo-plugin", "index.ts"),
201+
"export const demo = 2;\n",
202+
"utf8",
203+
);
204+
const manifestPath = join(repoDir, "extensions", "demo-plugin", "package.json");
205+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as ReturnType<
206+
typeof packageManifest
207+
>;
208+
writeJsonFile(manifestPath, {
209+
...manifest,
210+
version: nextVersion,
211+
openclaw: {
212+
...manifest.openclaw,
213+
compat: {
214+
pluginApi: `>=${nextVersion}`,
215+
},
216+
build: {
217+
openclawVersion: nextVersion,
218+
},
219+
},
220+
});
221+
const headRef = commitFixture(repoDir, "bump plugin version");
222+
const args = ["--base-ref", baseRef, "--head-ref", headRef];
223+
224+
expectValidPackage(
225+
runCheck(CLAWHUB_CHECK, repoDir, args),
226+
"plugin-clawhub-release-check",
227+
nextVersion,
228+
);
229+
expectValidPackage(runCheck(NPM_CHECK, repoDir, args), "plugin-npm-release-check", nextVersion);
230+
});
231+
});

0 commit comments

Comments
 (0)