Skip to content

Commit 417ce85

Browse files
committed
test: bind release assertions to explicit version contexts
1 parent ddf5b5a commit 417ce85

4 files changed

Lines changed: 213 additions & 185 deletions

File tree

‎src/auto-reply/reply/commands-plugins.install.test.ts‎

Lines changed: 73 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import { createCommandWorkspaceHarness } from "./commands-filesystem.test-suppor
1010
import { handlePluginsCommand } from "./commands-plugins.js";
1111
import { buildPluginsCommandParams } from "./commands.test-harness.js";
1212

13+
// Default-selector assertions describe a stable build; beta cases set their own identity.
14+
const coreVersion = vi.hoisted(() => ({ value: "2026.8.1" }));
15+
vi.mock("../../version.js", async (importOriginal) => ({
16+
...(await importOriginal<typeof import("../../version.js")>()),
17+
get VERSION() {
18+
return coreVersion.value;
19+
},
20+
}));
21+
1322
const {
1423
installPluginFromNpmPackArchiveMock,
1524
installPluginFromNpmSpecMock,
@@ -62,6 +71,18 @@ vi.mock("../../plugins/install-persistence.js", async (importOriginal) => ({
6271

6372
const workspaceHarness = createCommandWorkspaceHarness("openclaw-command-plugins-install-");
6473

74+
function mockNpmPluginInstall(pluginId: string, packageName: string, version = "1.0.0"): void {
75+
installPluginFromNpmSpecMock.mockResolvedValue({
76+
ok: true,
77+
pluginId,
78+
targetDir: `/tmp/${pluginId}`,
79+
version,
80+
extensions: ["index.js"],
81+
npmResolution: { name: packageName, version, resolvedSpec: `${packageName}@${version}` },
82+
});
83+
persistPluginInstallMock.mockResolvedValue({});
84+
}
85+
6586
function buildPluginsParams(
6687
commandBodyNormalized: string,
6788
workspaceDir: string,
@@ -126,6 +147,7 @@ function expectNonClawHubChatInstallRejected(
126147

127148
describe("handleCommands /plugins install", () => {
128149
afterEach(async () => {
150+
coreVersion.value = "2026.8.1";
129151
installPluginFromNpmPackArchiveMock.mockReset();
130152
installPluginFromNpmSpecMock.mockReset();
131153
installPluginFromPathMock.mockReset();
@@ -167,19 +189,7 @@ describe("handleCommands /plugins install", () => {
167189
},
168190
},
169191
};
170-
installPluginFromNpmSpecMock.mockResolvedValue({
171-
ok: true,
172-
pluginId: "policy-plugin",
173-
targetDir: "/tmp/policy-plugin",
174-
version: "1.0.0",
175-
extensions: ["index.js"],
176-
npmResolution: {
177-
name: "@acme/policy-plugin",
178-
version: "1.0.0",
179-
resolvedSpec: "@acme/[email protected]",
180-
},
181-
});
182-
persistPluginInstallMock.mockResolvedValue({});
192+
mockNpmPluginInstall("policy-plugin", "@acme/policy-plugin");
183193

184194
await withTempHome("openclaw-command-plugins-home-", async (home) => {
185195
await fs.writeFile(
@@ -222,7 +232,11 @@ describe("handleCommands /plugins install", () => {
222232
});
223233
});
224234

225-
it("allows npm packages matched by the official catalog", async () => {
235+
it.each([
236+
{ version: "2026.8.1", installSpec: "@openclaw/brave-plugin" },
237+
{ version: "2026.8.1-beta.4", installSpec: "@openclaw/brave-plugin@beta" },
238+
])("allows official catalog npm installs on core $version", async ({ version, installSpec }) => {
239+
coreVersion.value = version;
226240
const policyConfig: OpenClawConfig = {
227241
commands: { text: true, plugins: true },
228242
plugins: { enabled: true },
@@ -237,19 +251,7 @@ describe("handleCommands /plugins install", () => {
237251
},
238252
},
239253
};
240-
installPluginFromNpmSpecMock.mockResolvedValue({
241-
ok: true,
242-
pluginId: "brave",
243-
targetDir: "/tmp/brave",
244-
version: "1.0.0",
245-
extensions: ["index.js"],
246-
npmResolution: {
247-
name: "@openclaw/brave-plugin",
248-
version: "1.0.0",
249-
resolvedSpec: "@openclaw/[email protected]",
250-
},
251-
});
252-
persistPluginInstallMock.mockResolvedValue({});
254+
mockNpmPluginInstall("brave", "@openclaw/brave-plugin");
253255

254256
await withTempHome("openclaw-command-plugins-home-", async (home) => {
255257
await fs.writeFile(
@@ -267,7 +269,7 @@ describe("handleCommands /plugins install", () => {
267269

268270
expect(result?.reply?.text).toContain('Installed plugin "brave"');
269271
expectObjectFields(mockFirstObjectArg(installPluginFromNpmSpecMock), {
270-
spec: "@openclaw/brave-plugin",
272+
spec: installSpec,
271273
config: {
272274
...policyConfig,
273275
agents: { entries: { main: {} } },
@@ -284,20 +286,12 @@ describe("handleCommands /plugins install", () => {
284286
});
285287
});
286288

287-
it("allows npm packages matched by a bundled plugin manifest", async () => {
288-
installPluginFromNpmSpecMock.mockResolvedValue({
289-
ok: true,
290-
pluginId: "discord",
291-
targetDir: "/tmp/discord",
292-
version: "1.0.0",
293-
extensions: ["index.js"],
294-
npmResolution: {
295-
name: "@openclaw/discord",
296-
version: "1.0.0",
297-
resolvedSpec: "@openclaw/[email protected]",
298-
},
299-
});
300-
persistPluginInstallMock.mockResolvedValue({});
289+
it.each([
290+
{ version: "2026.8.1", installSpec: "@openclaw/discord" },
291+
{ version: "2026.8.1-beta.4", installSpec: "@openclaw/discord@beta" },
292+
])("allows bundled-manifest npm installs on core $version", async ({ version, installSpec }) => {
293+
coreVersion.value = version;
294+
mockNpmPluginInstall("discord", "@openclaw/discord");
301295

302296
await withTempHome("openclaw-command-plugins-home-", async () => {
303297
const workspaceDir = await workspaceHarness.createWorkspace();
@@ -310,7 +304,7 @@ describe("handleCommands /plugins install", () => {
310304

311305
expect(result?.reply?.text).toContain('Installed plugin "discord"');
312306
expectObjectFields(mockFirstObjectArg(installPluginFromNpmSpecMock), {
313-
spec: "@openclaw/discord",
307+
spec: installSpec,
314308
expectedPluginId: "discord",
315309
trustedSourceLinkedOfficialInstall: true,
316310
});
@@ -346,19 +340,7 @@ describe("handleCommands /plugins install", () => {
346340
});
347341

348342
it("allows plugin ids matched by the official catalog", async () => {
349-
installPluginFromNpmSpecMock.mockResolvedValue({
350-
ok: true,
351-
pluginId: "wecom-openclaw-plugin",
352-
targetDir: "/tmp/wecom-openclaw-plugin",
353-
version: "2026.7.2",
354-
extensions: ["index.js"],
355-
npmResolution: {
356-
name: "@wecom/wecom-openclaw-plugin",
357-
version: "2026.7.2",
358-
resolvedSpec: "@wecom/[email protected]",
359-
},
360-
});
361-
persistPluginInstallMock.mockResolvedValue({});
343+
mockNpmPluginInstall("wecom-openclaw-plugin", "@wecom/wecom-openclaw-plugin", "2026.7.2");
362344

363345
await withTempHome("openclaw-command-plugins-home-", async () => {
364346
const workspaceDir = await workspaceHarness.createWorkspace();
@@ -1043,46 +1025,41 @@ describe("handleCommands /plugins install", () => {
10431025
});
10441026
});
10451027

1046-
it("allows catalog npm package chat installs with alternate selectors", async () => {
1047-
installPluginFromNpmSpecMock.mockResolvedValue({
1048-
ok: true,
1049-
pluginId: "wecom-openclaw-plugin",
1050-
targetDir: "/tmp/wecom-openclaw-plugin",
1051-
version: "2026.7.2",
1052-
extensions: ["index.js"],
1053-
npmResolution: {
1054-
name: "@wecom/wecom-openclaw-plugin",
1055-
version: "2026.7.2",
1056-
resolvedSpec: "@wecom/[email protected]",
1057-
},
1058-
});
1059-
persistPluginInstallMock.mockResolvedValue({});
1028+
it.each([
1029+
{ version: "2026.8.1", installSpec: "@wecom/wecom-openclaw-plugin@latest" },
1030+
{ version: "2026.8.1-beta.4", installSpec: "@wecom/wecom-openclaw-plugin@beta" },
1031+
])(
1032+
"allows catalog npm @latest chat installs on core $version",
1033+
async ({ version, installSpec }) => {
1034+
coreVersion.value = version;
1035+
mockNpmPluginInstall("wecom-openclaw-plugin", "@wecom/wecom-openclaw-plugin", "2026.7.2");
10601036

1061-
await withTempHome("openclaw-command-plugins-home-", async () => {
1062-
const workspaceDir = await workspaceHarness.createWorkspace();
1063-
const params = buildPluginsParams(
1064-
"/plugins install @wecom/wecom-openclaw-plugin@latest --accept-capabilities",
1065-
workspaceDir,
1066-
);
1067-
const result = await handlePluginsCommand(params, true);
1068-
if (result === null) {
1069-
throw new Error("expected plugin install result");
1070-
}
1071-
expect(result.reply?.text).toContain('Installed plugin "wecom-openclaw-plugin"');
1072-
expectObjectFields(mockFirstObjectArg(installPluginFromNpmSpecMock), {
1073-
spec: "@wecom/wecom-openclaw-plugin@latest",
1074-
expectedPluginId: "wecom-openclaw-plugin",
1075-
expectedIntegrity: undefined,
1076-
trustedSourceLinkedOfficialInstall: true,
1077-
});
1078-
expectPersistedInstall("wecom-openclaw-plugin", {
1079-
source: "npm",
1080-
spec: "@wecom/wecom-openclaw-plugin@latest",
1081-
installPath: "/tmp/wecom-openclaw-plugin",
1082-
version: "2026.7.2",
1083-
resolvedName: "@wecom/wecom-openclaw-plugin",
1084-
resolvedVersion: "2026.7.2",
1037+
await withTempHome("openclaw-command-plugins-home-", async () => {
1038+
const workspaceDir = await workspaceHarness.createWorkspace();
1039+
const params = buildPluginsParams(
1040+
"/plugins install @wecom/wecom-openclaw-plugin@latest --accept-capabilities",
1041+
workspaceDir,
1042+
);
1043+
const result = await handlePluginsCommand(params, true);
1044+
if (result === null) {
1045+
throw new Error("expected plugin install result");
1046+
}
1047+
expect(result.reply?.text).toContain('Installed plugin "wecom-openclaw-plugin"');
1048+
expectObjectFields(mockFirstObjectArg(installPluginFromNpmSpecMock), {
1049+
spec: installSpec,
1050+
expectedPluginId: "wecom-openclaw-plugin",
1051+
expectedIntegrity: undefined,
1052+
trustedSourceLinkedOfficialInstall: true,
1053+
});
1054+
expectPersistedInstall("wecom-openclaw-plugin", {
1055+
source: "npm",
1056+
spec: "@wecom/wecom-openclaw-plugin@latest",
1057+
installPath: "/tmp/wecom-openclaw-plugin",
1058+
version: "2026.7.2",
1059+
resolvedName: "@wecom/wecom-openclaw-plugin",
1060+
resolvedVersion: "2026.7.2",
1061+
});
10851062
});
1086-
});
1087-
});
1063+
},
1064+
);
10881065
});

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

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ import {
4646
writePersistedInstalledPluginIndexInstallRecordsWithLeaseMock,
4747
} from "./plugins-cli-test-helpers.js";
4848

49+
// Default-selector assertions describe a stable build; beta cases set their own identity.
50+
const coreVersion = vi.hoisted(() => ({ value: "2026.8.1" }));
51+
vi.mock("../version.js", async (importOriginal) => ({
52+
...(await importOriginal<typeof import("../version.js")>()),
53+
get VERSION() {
54+
return coreVersion.value;
55+
},
56+
}));
57+
4958
const CLI_STATE_ROOT = "/tmp/openclaw-state";
5059
const ORIGINAL_OPENCLAW_STATE_DIR = process.env.OPENCLAW_STATE_DIR;
5160
const ORIGINAL_OPENCLAW_NIX_MODE = process.env.OPENCLAW_NIX_MODE;
@@ -624,6 +633,7 @@ describe("plugins cli install", () => {
624633
});
625634

626635
afterEach(() => {
636+
coreVersion.value = "2026.8.1";
627637
if (ORIGINAL_OPENCLAW_STATE_DIR === undefined) {
628638
delete process.env.OPENCLAW_STATE_DIR;
629639
} else {
@@ -1971,16 +1981,22 @@ describe("plugins cli install", () => {
19711981
expect(configWriteMock).toHaveBeenCalledWith(enabledCfg);
19721982
});
19731983

1974-
it.each([
1975-
{ label: "plugin id", arg: "brave" },
1976-
{ label: "npm package name", arg: "@openclaw/brave-plugin" },
1977-
])(
1978-
"installs the beta artifact for an official plugin on a beta gateway by $label",
1979-
async ({ arg }) => {
1984+
it.each(
1985+
[
1986+
{ version: "2026.8.1", channel: "beta" },
1987+
{ version: "2026.8.1-beta.4", channel: undefined },
1988+
{ version: "2026.8.1-beta.4", channel: "stable" },
1989+
].flatMap(({ version, channel }) =>
1990+
["brave", "@openclaw/brave-plugin"].map((arg) => ({ version, channel, arg })),
1991+
),
1992+
)(
1993+
"installs beta for $arg on core $version with channel $channel",
1994+
async ({ version, channel, arg }) => {
1995+
coreVersion.value = version;
19801996
primeSuccessfulPluginPersistence("brave");
19811997
pluginCliConfigMock.mockReturnValue({
19821998
...createEmptyPluginConfig(),
1983-
update: { channel: "beta" },
1999+
...(channel ? { update: { channel } } : {}),
19842000
} as OpenClawConfig);
19852001
findBundledPluginSourceMock.mockReturnValue(undefined);
19862002
installPluginFromNpmSpecMock.mockResolvedValue(createNpmPluginInstallResult("brave"));
@@ -2020,6 +2036,7 @@ describe("plugins cli install", () => {
20202036
});
20212037

20222038
it("passes third-party external catalog integrity with catalog install trust", async () => {
2039+
coreVersion.value = "2026.8.1-beta.4";
20232040
primeSuccessfulPluginPersistence("wecom-openclaw-plugin");
20242041
findBundledPluginSourceMock.mockReturnValue(undefined);
20252042
installPluginFromNpmSpecMock.mockResolvedValue(
@@ -2262,28 +2279,37 @@ describe("plugins cli install", () => {
22622279
expect(runtimeLogsContain("npm:@openclaw/[email protected]")).toBe(true);
22632280
});
22642281

2265-
it("marks catalog npm package installs with alternate selectors as trusted", async () => {
2266-
primeSuccessfulPluginPersistence("wecom-openclaw-plugin");
2267-
findBundledPluginSourceMock.mockReturnValue(undefined);
2268-
installPluginFromNpmSpecMock.mockResolvedValue(
2269-
createNpmPluginInstallResult("wecom-openclaw-plugin"),
2270-
);
2282+
it.each([
2283+
{ version: "2026.8.1", selector: "latest", installSelector: "latest" },
2284+
{ version: "2026.8.1-beta.4", selector: "latest", installSelector: "beta" },
2285+
{ version: "2026.8.1-beta.4", selector: "next", installSelector: "next" },
2286+
{ version: "2026.8.1-beta.4", selector: "2026.6.1", installSelector: "2026.6.1" },
2287+
])(
2288+
"trusts catalog npm @$selector on core $version",
2289+
async ({ version, selector, installSelector }) => {
2290+
coreVersion.value = version;
2291+
primeSuccessfulPluginPersistence("wecom-openclaw-plugin");
2292+
findBundledPluginSourceMock.mockReturnValue(undefined);
2293+
installPluginFromNpmSpecMock.mockResolvedValue(
2294+
createNpmPluginInstallResult("wecom-openclaw-plugin"),
2295+
);
22712296

2272-
await runCapabilityAcceptedPluginsInstallCommand([
2273-
"plugins",
2274-
"install",
2275-
"@wecom/wecom-openclaw-plugin@latest",
2276-
]);
2297+
await runCapabilityAcceptedPluginsInstallCommand([
2298+
"plugins",
2299+
"install",
2300+
`@wecom/wecom-openclaw-plugin@${selector}`,
2301+
]);
22772302

2278-
// Alternate selectors stay trusted by catalog package name, but must not
2279-
// inherit catalog integrity unless the install spec matches exactly.
2280-
expect(npmInstallCall().spec).toBe("@wecom/wecom-openclaw-plugin@latest");
2281-
expect(npmInstallCall().expectedPluginId).toBe("wecom-openclaw-plugin");
2282-
expect(npmInstallCall().trustedSourceLinkedOfficialInstall).toBe(true);
2283-
expect(npmInstallCall().expectedIntegrity).toBeUndefined();
2284-
expect(runtimeLogsContain("outside ClawHub review")).toBe(false);
2285-
expect(installPluginFromClawHubMock).not.toHaveBeenCalled();
2286-
});
2303+
// Alternate selectors stay trusted by catalog package name, but must not
2304+
// inherit catalog integrity unless the install spec matches exactly.
2305+
expect(npmInstallCall().spec).toBe(`@wecom/wecom-openclaw-plugin@${installSelector}`);
2306+
expect(npmInstallCall().expectedPluginId).toBe("wecom-openclaw-plugin");
2307+
expect(npmInstallCall().trustedSourceLinkedOfficialInstall).toBe(true);
2308+
expect(npmInstallCall().expectedIntegrity).toBeUndefined();
2309+
expect(runtimeLogsContain("outside ClawHub review")).toBe(false);
2310+
expect(installPluginFromClawHubMock).not.toHaveBeenCalled();
2311+
},
2312+
);
22872313

22882314
it("passes the active profile extensions dir to npm installs", async () => {
22892315
const extensionsDir = useProfileExtensionsDir();

0 commit comments

Comments
 (0)