fix(plugins): fast-path strict manifest json

This commit is contained in:
Peter Steinberger
2026-04-27 21:26:56 +01:00
parent 11e6928b3e
commit 7d2d8af3ab
4 changed files with 26 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import JSON5 from "json5";
import { afterEach, describe, expect, it, vi } from "vitest";
import { loadPluginManifest, MAX_PLUGIN_MANIFEST_BYTES } from "./manifest.js";
import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js";
@@ -11,6 +12,7 @@ function makeTempDir() {
}
afterEach(() => {
vi.restoreAllMocks();
cleanupTrackedTempDirs(tempDirs);
});
@@ -33,6 +35,24 @@ describe("loadPluginManifest JSON5 tolerance", () => {
}
});
it("uses native JSON parsing for standard JSON manifests", () => {
const json5Parse = vi.spyOn(JSON5, "parse");
const dir = makeTempDir();
fs.writeFileSync(
path.join(dir, "openclaw.plugin.json"),
JSON.stringify({
id: "strict-json",
configSchema: { type: "object" },
}),
"utf-8",
);
const result = loadPluginManifest(dir, false);
expect(result.ok).toBe(true);
expect(json5Parse).not.toHaveBeenCalled();
});
it("parses a manifest with trailing commas", () => {
const dir = makeTempDir();
const json5Content = `{

View File

@@ -1,6 +1,5 @@
import fs from "node:fs";
import path from "node:path";
import JSON5 from "json5";
import type { ChannelConfigRuntimeSchema } from "../channels/plugins/types.config.js";
import { MANIFEST_KEY } from "../compat/legacy-names.js";
import { matchBoundaryFileOpenFailure, openBoundaryFileSync } from "../infra/boundary-file-read.js";
@@ -23,6 +22,7 @@ import type { JsonSchemaObject } from "../shared/json-schema.types.js";
import { normalizeOptionalString } from "../shared/string-coerce.js";
import { normalizeTrimmedStringList } from "../shared/string-normalization.js";
import { isRecord } from "../utils.js";
import { parseJsonWithJson5Fallback } from "../utils/parse-json-compat.js";
import {
normalizeManifestCommandAliases,
type PluginManifestCommandAlias,
@@ -1178,7 +1178,7 @@ export function loadPluginManifest(
}
let raw: unknown;
try {
raw = JSON5.parse(fs.readFileSync(opened.fd, "utf-8"));
raw = parseJsonWithJson5Fallback(fs.readFileSync(opened.fd, "utf-8"));
} catch (err) {
return {
ok: false,