From 5ff0c75da75e5707d4dc52d5e250ebca5cec7e5c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 29 May 2026 04:20:42 -0400 Subject: [PATCH] fix(config): preserve large numeric schema keys --- src/channels/plugins/config-schema.test.ts | 18 ++++++++++++++++++ src/channels/plugins/config-schema.ts | 4 ++-- src/plugins/config-schema.test.ts | 20 ++++++++++++++++++++ src/plugins/config-schema.ts | 4 ++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/channels/plugins/config-schema.test.ts b/src/channels/plugins/config-schema.test.ts index 30d10a87f76..3aaae4f2963 100644 --- a/src/channels/plugins/config-schema.test.ts +++ b/src/channels/plugins/config-schema.test.ts @@ -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", () => { diff --git a/src/channels/plugins/config-schema.ts b/src/channels/plugins/config-schema.ts index e5c3065b927..5a51366328d 100644 --- a/src/channels/plugins/config-schema.ts +++ b/src/channels/plugins/config-schema.ts @@ -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 { return []; } return path.split(".").map((segment) => { - const index = Number(segment); - return Number.isInteger(index) && String(index) === segment ? index : segment; + return parseConfigPathArrayIndex(segment) ?? segment; }); } diff --git a/src/plugins/config-schema.test.ts b/src/plugins/config-schema.test.ts index 6b32515f4b9..1c55876dfac 100644 --- a/src/plugins/config-schema.test.ts +++ b/src/plugins/config-schema.test.ts @@ -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", () => { diff --git a/src/plugins/config-schema.ts b/src/plugins/config-schema.ts index b8e5b205986..6ace611d7d2 100644 --- a/src/plugins/config-schema.ts +++ b/src/plugins/config-schema.ts @@ -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 { return []; } return path.split(".").map((segment) => { - const index = Number(segment); - return Number.isInteger(index) && String(index) === segment ? index : segment; + return parseConfigPathArrayIndex(segment) ?? segment; }); }