Skip to content

Commit 6bf72ad

Browse files
committed
fix(plugins): ignore malformed build version metadata
1 parent c539192 commit 6bf72ad

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

‎src/plugins/loader-shared.test.ts‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, expect, it } from "vitest";
2-
import { validatePluginConfig } from "./loader-shared.js";
2+
import type { PluginCandidate } from "./discovery.js";
3+
import { createManifestPluginRecord, validatePluginConfig } from "./loader-shared.js";
4+
import type { PluginManifestRecord } from "./manifest-registry.js";
35

46
const emptyObjectSchema = {
57
type: "object",
@@ -11,6 +13,50 @@ function withSchemaKeyword(key: "if" | "then" | "else", value: unknown) {
1113
return { [key]: value };
1214
}
1315

16+
const manifestRecord = {
17+
id: "example",
18+
channels: [],
19+
providers: [],
20+
cliBackends: [],
21+
skills: [],
22+
hooks: [],
23+
origin: "global",
24+
rootDir: "/plugins/example",
25+
source: "/plugins/example/index.js",
26+
manifestPath: "/plugins/example/openclaw.plugin.json",
27+
} satisfies PluginManifestRecord;
28+
29+
function createRecordWithBuildVersion(openclawVersion: unknown) {
30+
const candidate = {
31+
idHint: "example",
32+
source: manifestRecord.source,
33+
rootDir: manifestRecord.rootDir,
34+
origin: manifestRecord.origin,
35+
packageManifest: {
36+
build: { openclawVersion },
37+
} as unknown as NonNullable<PluginCandidate["packageManifest"]>,
38+
} satisfies PluginCandidate;
39+
40+
return createManifestPluginRecord({
41+
candidate,
42+
manifestRecord,
43+
enabled: true,
44+
activationState: {
45+
enabled: true,
46+
activated: true,
47+
explicitlyEnabled: true,
48+
source: "explicit",
49+
},
50+
});
51+
}
52+
53+
describe("createManifestPluginRecord", () => {
54+
it("ignores malformed package build version metadata", () => {
55+
expect(createRecordWithBuildVersion(" 2026.7.2 ").builtWithOpenClawVersion).toBe("2026.7.2");
56+
expect(createRecordWithBuildVersion(42).builtWithOpenClawVersion).toBeUndefined();
57+
});
58+
});
59+
1460
describe("validatePluginConfig empty schema classification", () => {
1561
it("validates pattern properties instead of requiring empty config", () => {
1662
const schema = {

‎src/plugins/loader-shared.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import { err as resultError, ok, type Result } from "@openclaw/normalization-core/result";
4-
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
4+
import {
5+
normalizeLowercaseStringOrEmpty,
6+
normalizeOptionalString,
7+
} from "@openclaw/normalization-core/string-coerce";
58
import type { OpenClawConfig } from "../config/types.openclaw.js";
69
import { activateContextEngineRegistrations } from "../context-engine/registry.js";
710
import { createSubsystemLogger } from "../logging/subsystem.js";
@@ -285,7 +288,9 @@ export function createManifestPluginRecord(params: {
285288
description: manifestRecord.description,
286289
packageVersion: manifestRecord.packageVersion,
287290
version: manifestRecord.version,
288-
builtWithOpenClawVersion: candidate.packageManifest?.build?.openclawVersion?.trim(),
291+
builtWithOpenClawVersion: normalizeOptionalString(
292+
candidate.packageManifest?.build?.openclawVersion,
293+
),
289294
packageName: manifestRecord.packageName,
290295
format: manifestRecord.format,
291296
bundleFormat: manifestRecord.bundleFormat,

0 commit comments

Comments
 (0)