Files
openclaw/src/shared/json-schema-defaults.test.ts
qingminlong 5a3422ea8d fix(schema): resolve large local refs in schema arrays (#102195)
* fix(schema): resolve large local refs in schema arrays

* fix(schema): type large local ref fixture

* style(schema): format large local ref regression

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-09 09:51:30 +01:00

50 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { findJsonSchemaShapeError, normalizeJsonSchemaForTypeBox } from "./json-schema-defaults.js";
describe("normalizeJsonSchemaForTypeBox", () => {
it("combines pattern properties that collide after unicode repair", () => {
const normalized = normalizeJsonSchemaForTypeBox({
type: "object",
patternProperties: {
"^https:": { minLength: 1 },
"^https\\:": { maxLength: 10 },
},
});
expect(normalized).toMatchObject({
patternProperties: {
"^https:": {
allOf: [{ minLength: 1 }, { maxLength: 10 }],
},
},
});
});
it.each(["constructor", "toString", "__proto__"])(
"preserves pattern property key %s",
(pattern) => {
const normalized = normalizeJsonSchemaForTypeBox({
type: "object",
patternProperties: Object.fromEntries([[pattern, { type: "string" }]]),
});
expect(normalized).toMatchObject({
patternProperties: Object.fromEntries([[pattern, { type: "string" }]]),
});
},
);
it("resolves local refs to array entries beyond config path index limits", () => {
const prefixItems: (boolean | { type: string })[] = Array.from({ length: 100_002 }, () => true);
prefixItems[100_001] = { type: "string" };
expect(
findJsonSchemaShapeError({
type: "array",
prefixItems,
items: { $ref: "#/prefixItems/100001" },
}),
).toBeUndefined();
});
});