CLI: dedupe config validate errors and expose allowed values

This commit is contained in:
Gustavo Madeira Santana
2026-03-02 20:05:12 -05:00
parent a44843507f
commit f26853f14c
41 changed files with 1393 additions and 134 deletions

View File

@@ -35,6 +35,7 @@ describe("config plugin validation", () => {
let fixtureRoot = "";
let suiteHome = "";
let badPluginDir = "";
let enumPluginDir = "";
let bluebubblesPluginDir = "";
const envSnapshot = {
OPENCLAW_STATE_DIR: process.env.OPENCLAW_STATE_DIR,
@@ -48,6 +49,7 @@ describe("config plugin validation", () => {
suiteHome = path.join(fixtureRoot, "home");
await fs.mkdir(suiteHome, { recursive: true });
badPluginDir = path.join(suiteHome, "bad-plugin");
enumPluginDir = path.join(suiteHome, "enum-plugin");
bluebubblesPluginDir = path.join(suiteHome, "bluebubbles-plugin");
await writePluginFixture({
dir: badPluginDir,
@@ -61,6 +63,20 @@ describe("config plugin validation", () => {
required: ["value"],
},
});
await writePluginFixture({
dir: enumPluginDir,
id: "enum-plugin",
schema: {
type: "object",
properties: {
fileFormat: {
type: "string",
enum: ["markdown", "html"],
},
},
required: ["fileFormat"],
},
});
await writePluginFixture({
dir: bluebubblesPluginDir,
id: "bluebubbles-plugin",
@@ -185,13 +201,34 @@ describe("config plugin validation", () => {
if (!res.ok) {
const hasIssue = res.issues.some(
(issue) =>
issue.path === "plugins.entries.bad-plugin.config" &&
issue.path.startsWith("plugins.entries.bad-plugin.config") &&
issue.message.includes("invalid config"),
);
expect(hasIssue).toBe(true);
}
});
it("surfaces allowed enum values for plugin config diagnostics", async () => {
const res = validateInSuite({
agents: { list: [{ id: "pi" }] },
plugins: {
enabled: true,
load: { paths: [enumPluginDir] },
entries: { "enum-plugin": { config: { fileFormat: "txt" } } },
},
});
expect(res.ok).toBe(false);
if (!res.ok) {
const issue = res.issues.find(
(entry) => entry.path === "plugins.entries.enum-plugin.config.fileFormat",
);
expect(issue).toBeDefined();
expect(issue?.message).toContain('allowed: "markdown", "html"');
expect(issue?.allowedValues).toEqual(["markdown", "html"]);
expect(issue?.allowedValuesHiddenCount).toBe(0);
}
});
it("accepts known plugin ids and valid channel/heartbeat enums", async () => {
const res = validateInSuite({
agents: {