fix(config): allow root without zod preprocess wrapper

This commit is contained in:
Peter Steinberger
2026-02-14 02:53:41 +01:00
parent 87ed2632d3
commit 58456bc10d
6 changed files with 560 additions and 573 deletions

View File

@@ -7,15 +7,8 @@ describe("$schema key in config (#14998)", () => {
$schema: "https://openclaw.ai/config.json",
});
expect(result.success).toBe(true);
});
it("strips $schema from parsed output so it does not leak into UI", () => {
const result = OpenClawSchema.safeParse({
$schema: "https://openclaw.ai/config.json",
});
expect(result.success).toBe(true);
if (result.success) {
expect("$schema" in result.data).toBe(false);
expect(result.data.$schema).toBe("https://openclaw.ai/config.json");
}
});
@@ -24,8 +17,8 @@ describe("$schema key in config (#14998)", () => {
expect(result.success).toBe(true);
});
it("ignores non-string $schema (stripped before validation)", () => {
it("rejects non-string $schema", () => {
const result = OpenClawSchema.safeParse({ $schema: 123 });
expect(result.success).toBe(true);
expect(result.success).toBe(false);
});
});

View File

@@ -7,6 +7,7 @@ describe("config schema", () => {
const schema = res.schema as { properties?: Record<string, unknown> };
expect(schema.properties?.gateway).toBeTruthy();
expect(schema.properties?.agents).toBeTruthy();
expect(schema.properties?.$schema).toBeUndefined();
expect(res.uiHints.gateway?.label).toBe("Gateway");
expect(res.uiHints["gateway.auth.token"]?.sensitive).toBe(true);
expect(res.version).toBeTruthy();

View File

@@ -303,6 +303,12 @@ function stripChannelSchema(schema: ConfigSchema): ConfigSchema {
if (!root || !root.properties) {
return next;
}
// Allow `$schema` in config files for editor tooling, but hide it from the
// Control UI form schema so it does not show up as a configurable section.
delete root.properties.$schema;
if (Array.isArray(root.required)) {
root.required = root.required.filter((key) => key !== "$schema");
}
const channelsNode = asSchemaObject(root.properties.channels);
if (channelsNode) {
channelsNode.properties = {};

File diff suppressed because it is too large Load Diff