fix(docs): validate plugin json examples

This commit is contained in:
Vincent Koc
2026-05-03 15:46:59 -07:00
parent e5ec14a06a
commit 9ba7183b63
3 changed files with 53 additions and 0 deletions

View File

@@ -441,6 +441,9 @@ knowledge layer:
{
memory: {
backend: "qmd",
},
plugins: {
entries: {
"memory-wiki": {
enabled: true,
config: {

View File

@@ -0,0 +1,49 @@
import fs from "node:fs";
import path from "node:path";
import JSON5 from "json5";
import { describe, expect, it } from "vitest";
const PLUGIN_DOCS_DIR = path.join(process.cwd(), "docs", "plugins");
function lineNumberAt(source: string, index: number): number {
return source.slice(0, index).split("\n").length;
}
function listMarkdownFiles(dir: string): string[] {
const files: string[] = [];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
files.push(...listMarkdownFiles(entryPath));
} else if (entry.isFile() && entry.name.endsWith(".md")) {
files.push(entryPath);
}
}
return files;
}
describe("plugin docs examples", () => {
it("keeps plugin docs JSON fences parseable", () => {
const failures: string[] = [];
for (const docPath of listMarkdownFiles(PLUGIN_DOCS_DIR)) {
const markdown = fs.readFileSync(docPath, "utf8");
const blocks = markdown.matchAll(/```(json5|json)\n([\s\S]*?)```/g);
for (const match of blocks) {
const lang = match[1] ?? "";
const code = match[2] ?? "";
const relativePath = path.relative(process.cwd(), docPath).split(path.sep).join("/");
const location = `${relativePath}:${lineNumberAt(markdown, match.index ?? 0)}`;
try {
if (lang === "json") {
JSON.parse(code);
} else {
JSON5.parse(code);
}
} catch (error) {
failures.push(`${location} ${lang.toUpperCase()} parse failed: ${String(error)}`);
}
}
}
expect(failures).toEqual([]);
});
});

View File

@@ -93,6 +93,7 @@ export const forcedUnitFastTestFiles = [
"src/canvas-host/server.state-dir.test.ts",
"src/docs/clawhub-plugin-docs.test.ts",
"src/docs/channel-config-examples.test.ts",
"src/docs/plugin-doc-examples.test.ts",
"src/docs/install-cloud-secrets.test.ts",
"src/docker-build-cache.test.ts",
"src/docker-image-digests.test.ts",