agent_patch
runs/2026-02-27__21-30-28__gpt-5-3-codex/flux-pr-5578/flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/agent-logs/agent.patch
7008 bytes
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/schemas.ts b/app/packages/zod/src/v4/classic/schemas.ts
index 5f41192..5491954 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/schemas.ts
+++ b/app/packages/zod/src/v4/classic/schemas.ts
@@ -174,7 +174,8 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
),
],
- })
+ }),
+ { parent: true }
);
};
inst.clone = (def, params) => core.clone(inst, def, params);
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/tests/to-json-schema.test.ts b/app/packages/zod/src/v4/classic/tests/to-json-schema.test.ts
index 45bf823..dee4d0b 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/tests/to-json-schema.test.ts
+++ b/app/packages/zod/src/v4/classic/tests/to-json-schema.test.ts
@@ -1741,6 +1741,27 @@ test("override with refs", () => {
`);
});
+test("override receives parent schema for wrapped/refined schemas", () => {
+ const schema = z.string().min(3).optional();
+ let sawParentOnOptional = false;
+ let sawParentOnRefinedString = false;
+
+ z.toJSONSchema(schema, {
+ override(ctx) {
+ const defType = ctx.zodSchema._zod.def.type;
+ if (defType === "optional" && ctx.parentZodSchema?._zod.def.type === "string") {
+ sawParentOnOptional = true;
+ }
+ if (defType === "string" && ctx.parentZodSchema?._zod.def.type === "string") {
+ sawParentOnRefinedString = true;
+ }
+ },
+ });
+
+ expect(sawParentOnOptional).toBe(true);
+ expect(sawParentOnRefinedString).toBe(true);
+});
+
test("override execution order", () => {
const schema = z.union([z.string(), z.number()]);
let unionSchema!: any;
@@ -1944,6 +1965,40 @@ test("extract schemas with id", () => {
`);
});
+test("metadata inheritance through refined clones", () => {
+ const base = z.string().meta({
+ title: "Base title",
+ description: "Base description",
+ });
+ const refined = base.min(5);
+ const result = z.toJSONSchema(refined);
+
+ expect(result).toMatchObject({
+ type: "string",
+ minLength: 5,
+ title: "Base title",
+ description: "Base description",
+ });
+});
+
+test("metadata overrides on refined clones preserve parent metadata", () => {
+ const base = z.string().meta({
+ title: "Base title",
+ description: "Base description",
+ });
+ const refined = base.min(5).meta({
+ description: "Refined description",
+ });
+ const result = z.toJSONSchema(refined);
+
+ expect(result).toMatchObject({
+ type: "string",
+ minLength: 5,
+ title: "Base title",
+ description: "Refined description",
+ });
+});
+
test("unrepresentable literal values are ignored", () => {
const a = z.toJSONSchema(z.literal(["hello", null, 5, BigInt(1324), undefined]), { unrepresentable: "any" });
expect(a).toMatchInlineSnapshot(`
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/core/to-json-schema.ts b/app/packages/zod/src/v4/core/to-json-schema.ts
index fd1333e..7b4c484 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/core/to-json-schema.ts
+++ b/app/packages/zod/src/v4/core/to-json-schema.ts
@@ -29,6 +29,7 @@ export interface JSONSchemaGeneratorParams {
/** Arbitrary custom logic that can be used to modify the generated JSON Schema. */
override?: (ctx: {
zodSchema: schemas.$ZodTypes;
+ parentZodSchema?: schemas.$ZodTypes | undefined;
jsonSchema: JSONSchema.BaseSchema;
path: (string | number)[];
}) => void;
@@ -88,6 +89,7 @@ export interface ToJSONSchemaContext {
override: (ctx: {
// must be schemas.$ZodType to prevent recursive type resolution error
zodSchema: schemas.$ZodType;
+ parentZodSchema?: schemas.$ZodType | undefined;
jsonSchema: JSONSchema.BaseSchema;
path: (string | number)[];
}) => void;
@@ -172,22 +174,27 @@ export function process<T extends schemas.$ZodType>(
path: _params.path,
};
- const parent = schema._zod.parent as T;
+ const parent = schema._zod.parent as T | undefined;
+ const isPureClone = !!parent && schema._zod.def === parent._zod.def;
if (parent) {
// schema was cloned from another schema
result.ref = parent;
process(parent, ctx, params);
ctx.seen.get(parent)!.isParent = true;
- } else if (schema._zod.processJSONSchema) {
- schema._zod.processJSONSchema(ctx, result.schema, params);
- } else {
- const _json = result.schema;
- const processor = ctx.processors[def.type];
- if (!processor) {
- throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
+ }
+
+ if (!isPureClone) {
+ if (schema._zod.processJSONSchema) {
+ schema._zod.processJSONSchema(ctx, result.schema, params);
+ } else {
+ const _json = result.schema;
+ const processor = ctx.processors[def.type];
+ if (!processor) {
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
+ }
+ processor(schema, ctx, _json, params);
}
- processor(schema, ctx, _json, params);
}
}
@@ -378,6 +385,7 @@ export function finalize<T extends schemas.$ZodType>(
// flatten ref if defined
const ref = seen.ref;
+ const parentZodSchema = (ref ?? (zodSchema._zod.parent as schemas.$ZodType | undefined)) ?? undefined;
seen.ref = null; // prevent recursion
if (ref) {
flattenRef(ref);
@@ -397,6 +405,7 @@ export function finalize<T extends schemas.$ZodType>(
if (!seen.isParent)
ctx.override({
zodSchema: zodSchema as schemas.$ZodTypes,
+ parentZodSchema: parentZodSchema as schemas.$ZodTypes | undefined,
jsonSchema: schema,
path: seen.path ?? [],
});
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/mini/schemas.ts b/app/packages/zod/src/v4/mini/schemas.ts
index e8002d2..5e97735 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/mini/schemas.ts
+++ b/app/packages/zod/src/v4/mini/schemas.ts
@@ -65,8 +65,8 @@ export const ZodMiniType: core.$constructor<ZodMiniType> = /*@__PURE__*/ core.$c
typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
),
],
- }
- // { parent: true }
+ },
+ { parent: true }
);
};
inst.refine = (check, params) => inst.check(refine(check, params)) as never;