fix(config): preserve large numeric schema keys

This commit is contained in:
Peter Steinberger
2026-05-29 04:20:42 -04:00
parent f6d293a1ee
commit 5ff0c75da7
4 changed files with 42 additions and 4 deletions

View File

@@ -91,6 +91,24 @@ describe("buildJsonChannelConfigSchema", () => {
issues: [{ path: ["enabled"], message: "must be boolean" }],
});
});
it("keeps numeric-looking object keys outside array-index range as strings", () => {
const result = buildJsonChannelConfigSchema(
{
type: "object",
required: ["100001"],
properties: {
"100001": { type: "boolean" },
},
},
{ cacheKey: "config-schema.test.large-numeric-key-channel" },
);
expect(result.runtime?.safeParse({})).toEqual({
success: false,
issues: [{ path: ["100001"], message: "must have required property '100001'" }],
});
});
});
describe("emptyChannelConfigSchema", () => {

View File

@@ -2,6 +2,7 @@ import { z, type ZodRawShape, type ZodTypeAny } from "zod";
import { DmPolicySchema } from "../../config/zod-schema.core.js";
import { validateJsonSchemaValue } from "../../plugins/schema-validator.js";
import type { JsonSchemaObject } from "../../shared/json-schema.types.js";
import { parseConfigPathArrayIndex } from "../../shared/path-array-index.js";
import type {
ChannelConfigRuntimeIssue,
ChannelConfigRuntimeParseResult,
@@ -84,8 +85,7 @@ function toIssuePath(path: string): Array<string | number> {
return [];
}
return path.split(".").map((segment) => {
const index = Number(segment);
return Number.isInteger(index) && String(index) === segment ? index : segment;
return parseConfigPathArrayIndex(segment) ?? segment;
});
}

View File

@@ -118,6 +118,26 @@ describe("buildJsonPluginConfigSchema", () => {
error: { issues: [{ path: ["enabled"], message: "must be boolean" }] },
});
});
it("keeps numeric-looking object keys outside array-index range as strings", () => {
const result = buildJsonPluginConfigSchema(
{
type: "object",
required: ["100001"],
properties: {
"100001": { type: "boolean" },
},
},
{ cacheKey: "config-schema.test.large-numeric-key" },
);
expect(result.safeParse?.({})).toEqual({
success: false,
error: {
issues: [{ path: ["100001"], message: "must have required property '100001'" }],
},
});
});
});
describe("emptyPluginConfigSchema", () => {

View File

@@ -1,5 +1,6 @@
import { z, type ZodTypeAny } from "zod";
import type { JsonSchemaObject } from "../shared/json-schema.types.js";
import { parseConfigPathArrayIndex } from "../shared/path-array-index.js";
import type { PluginConfigUiHint } from "./manifest-types.js";
import { validateJsonSchemaValue } from "./schema-validator.js";
import type { OpenClawPluginConfigSchema } from "./types.js";
@@ -89,8 +90,7 @@ function toIssuePath(path: string): Array<string | number> {
return [];
}
return path.split(".").map((segment) => {
const index = Number(segment);
return Number.isInteger(index) && String(index) === segment ? index : segment;
return parseConfigPathArrayIndex(segment) ?? segment;
});
}