Skip to content

Commit 1e93fac

Browse files
committed
fix(update): cover persisted marketplace bundles
1 parent 3df8e5e commit 1e93fac

4 files changed

Lines changed: 90 additions & 12 deletions

File tree

‎src/cli/update-cli/plugin-payload-validation.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,25 @@ describe("runPluginPayloadSmokeCheck", () => {
183183
expect(result.failures).toEqual([]);
184184
});
185185

186+
it("accepts a persisted marketplace bundle record without transient format metadata", async () => {
187+
const dir = path.join(tmpRoot, "marketplace-bundle");
188+
await writeBundle({ dir, format: "cursor" });
189+
const result = await runPluginPayloadSmokeCheck({
190+
records: {
191+
"marketplace-bundle": {
192+
source: "marketplace",
193+
installPath: dir,
194+
marketplaceName: "Local",
195+
marketplaceSource: "local/repo",
196+
marketplacePlugin: "marketplace-bundle",
197+
},
198+
},
199+
env: {},
200+
});
201+
expect(result.checked).toEqual(["marketplace-bundle"]);
202+
expect(result.failures).toEqual([]);
203+
});
204+
186205
it("reports a bundle manifest failure instead of requiring package.json for bundle records", async () => {
187206
const dir = path.join(tmpRoot, "broken-bundle");
188207
await fs.mkdir(path.join(dir, ".codex-plugin"), { recursive: true });

‎src/cli/update-cli/plugin-payload-validation.ts‎

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
33
import path from "node:path";
44
import type { PluginInstallRecord } from "../../config/types.plugins.js";
55
import { detectBundleManifestFormat, loadBundleManifest } from "../../plugins/bundle-manifest.js";
6+
import type { PluginBundleFormat } from "../../plugins/manifest-types.js";
67
import { resolvePackageExtensionEntries, type PackageManifest } from "../../plugins/manifest.js";
78
import { validatePackageExtensionEntriesForInstall } from "../../plugins/package-entry-resolution.js";
89
import { auditOpenClawPeerDependencyLink } from "../../plugins/plugin-peer-link.js";
@@ -82,11 +83,11 @@ export async function runPluginPayloadSmokeCheck(params: {
8283
continue;
8384
}
8485

85-
const isBundleRecord = isBundleInstallRecord(record);
86+
const bundlePayload = resolveBundleInstallRecordPayload({ record, installPath });
8687
const packagePayload = await readPackagePayloadManifest(installPath);
8788
if (packagePayload.status === "present") {
8889
const usePackagePayload =
89-
!isBundleRecord || hasNativePackageMetadata(packagePayload.manifest);
90+
!bundlePayload.isBundlePayload || hasNativePackageMetadata(packagePayload.manifest);
9091
if (usePackagePayload) {
9192
failures.push(
9293
...(await validatePackagePayload({
@@ -97,12 +98,17 @@ export async function runPluginPayloadSmokeCheck(params: {
9798
);
9899
continue;
99100
}
100-
} else if (!isBundleRecord) {
101+
} else if (!bundlePayload.isBundlePayload) {
101102
failures.push(formatPackagePayloadReadFailure({ pluginId, installPath, packagePayload }));
102103
continue;
103104
}
104105

105-
const bundleFailure = validateBundleInstallRecordPayload({ pluginId, installPath, record });
106+
const bundleFailure = validateBundleInstallRecordPayload({
107+
pluginId,
108+
installPath,
109+
record,
110+
bundleFormat: bundlePayload.bundleFormat,
111+
});
106112
if (bundleFailure) {
107113
failures.push(bundleFailure);
108114
}
@@ -163,9 +169,7 @@ function hasNativePackageMetadata(manifest: PackageManifest): boolean {
163169

164170
export async function hasNativePackageInstallPayload(installPath: string): Promise<boolean> {
165171
const packagePayload = await readPackagePayloadManifest(installPath);
166-
return (
167-
packagePayload.status === "present" && hasNativePackageMetadata(packagePayload.manifest)
168-
);
172+
return packagePayload.status === "present" && hasNativePackageMetadata(packagePayload.manifest);
169173
}
170174

171175
async function validatePackagePayload(params: {
@@ -246,15 +250,35 @@ export function isBundleInstallRecord(record: PluginInstallRecord): boolean {
246250
);
247251
}
248252

253+
export function resolveBundleInstallRecordPayload(params: {
254+
record: PluginInstallRecord;
255+
installPath: string;
256+
}): { isBundlePayload: boolean; bundleFormat: PluginBundleFormat | null } {
257+
const hasBundleRecordMetadata = isBundleInstallRecord(params.record);
258+
if (!hasBundleRecordMetadata && params.record.source !== "marketplace") {
259+
return { isBundlePayload: false, bundleFormat: null };
260+
}
261+
const bundleFormat = detectBundleManifestFormat(params.installPath);
262+
return {
263+
isBundlePayload: hasBundleRecordMetadata || bundleFormat !== null,
264+
bundleFormat,
265+
};
266+
}
267+
249268
export function validateBundleInstallRecordPayload(params: {
250269
pluginId: string;
251270
installPath: string;
252271
record: PluginInstallRecord;
272+
bundleFormat?: PluginBundleFormat | null;
253273
}): PluginPayloadSmokeFailure | null {
254-
if (!isBundleInstallRecord(params.record)) {
274+
const hasBundleRecordMetadata = isBundleInstallRecord(params.record);
275+
const bundleFormat =
276+
params.bundleFormat === undefined
277+
? detectBundleManifestFormat(params.installPath)
278+
: params.bundleFormat;
279+
if (!hasBundleRecordMetadata && !bundleFormat) {
255280
return null;
256281
}
257-
const bundleFormat = detectBundleManifestFormat(params.installPath);
258282
if (!bundleFormat) {
259283
return {
260284
pluginId: params.pluginId,

‎src/cli/update-cli/update-command.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,35 @@ describe("collectMissingPluginInstallPayloads", () => {
324324
}
325325
});
326326

327+
it("accepts persisted marketplace bundle records without transient format metadata", async () => {
328+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-update-plugin-payload-"));
329+
const bundleDir = path.join(tmpDir, "state", "marketplace", "cursor-bundle");
330+
try {
331+
await fs.mkdir(path.join(bundleDir, ".cursor-plugin"), { recursive: true });
332+
await fs.writeFile(
333+
path.join(bundleDir, ".cursor-plugin", "plugin.json"),
334+
JSON.stringify({ name: "cursor-bundle" }),
335+
"utf8",
336+
);
337+
await expect(
338+
collectMissingPluginInstallPayloads({
339+
env: { HOME: tmpDir } as NodeJS.ProcessEnv,
340+
records: {
341+
"cursor-bundle": {
342+
source: "marketplace",
343+
installPath: bundleDir,
344+
marketplaceName: "Local",
345+
marketplaceSource: "local/repo",
346+
marketplacePlugin: "cursor-bundle",
347+
},
348+
},
349+
}),
350+
).resolves.toEqual([]);
351+
} finally {
352+
await fs.rm(tmpDir, { recursive: true, force: true });
353+
}
354+
});
355+
327356
it("keeps dual-format bundle records on the native package payload path", async () => {
328357
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-update-plugin-payload-"));
329358
const bundleDir = path.join(tmpDir, "state", "clawhub", "dual-format-bundle");

‎src/cli/update-cli/update-command.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ import { listPersistedBundledPluginLocationBridges } from "../plugins-location-b
142142
import { refreshPluginRegistryAfterConfigMutation } from "../plugins-registry-refresh.js";
143143
import {
144144
hasNativePackageInstallPayload,
145-
isBundleInstallRecord,
145+
resolveBundleInstallRecordPayload,
146146
validateBundleInstallRecordPayload,
147147
} from "./plugin-payload-validation.js";
148148
import {
@@ -579,11 +579,17 @@ export async function collectMissingPluginInstallPayloads(params: {
579579
missing.push({ pluginId, installPath, reason: "missing-package-dir" });
580580
continue;
581581
}
582-
if (isBundleInstallRecord(record)) {
582+
const bundlePayload = resolveBundleInstallRecordPayload({ record, installPath });
583+
if (bundlePayload.isBundlePayload) {
583584
if (await hasNativePackageInstallPayload(installPath)) {
584585
continue;
585586
}
586-
const bundleFailure = validateBundleInstallRecordPayload({ pluginId, installPath, record });
587+
const bundleFailure = validateBundleInstallRecordPayload({
588+
pluginId,
589+
installPath,
590+
record,
591+
bundleFormat: bundlePayload.bundleFormat,
592+
});
587593
if (bundleFailure) {
588594
missing.push({ pluginId, installPath, reason: "missing-package-json" });
589595
}

0 commit comments

Comments
 (0)