agent_patch
runs/2026-02-27__21-30-28__gpt-5-4/flux-pr-5578/flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/agent-logs/agent.patch
7116 bytes
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/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..49ec980 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/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
@@ -2168,6 +2168,54 @@ test("overwrite descriptions", () => {
`);
});
+test("refinements inherit metadata from their source schema", () => {
+ const schema = z.string().meta({ title: "Name", description: "Base field" }).min(2);
+
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
+ {
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "description": "Base field",
+ "minLength": 2,
+ "title": "Name",
+ "type": "string",
+ }
+ `);
+});
+
+test("child metadata overrides inherited metadata without replaying parent structure", () => {
+ const schema = z
+ .object({
+ name: z.string(),
+ })
+ .meta({ title: "Base", description: "Parent description" })
+ .extend({
+ age: z.number(),
+ })
+ .meta({ description: "Child description" });
+
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
+ {
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "additionalProperties": false,
+ "description": "Child description",
+ "properties": {
+ "name": {
+ "type": "string",
+ },
+ "age": {
+ "type": "number",
+ },
+ },
+ "required": [
+ "name",
+ "age",
+ ],
+ "title": "Base",
+ "type": "object",
+ }
+ `);
+});
+
test("top-level readonly", () => {
const A = z
.object({
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/registries.ts b/app/packages/zod/src/v4/core/registries.ts
index 6d04ea1..56befdb 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/registries.ts
+++ b/app/packages/zod/src/v4/core/registries.ts
@@ -71,6 +71,10 @@ export class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema exten
return this._map.get(schema) as any;
}
+ getOwn<S extends Schema>(schema: S): $replace<Meta, S> | undefined {
+ return this._map.get(schema) as any;
+ }
+
has(schema: Schema): boolean {
return this._map.has(schema);
}
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/schemas.ts b/app/packages/zod/src/v4/core/schemas.ts
index 9102970..5761bae 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/schemas.ts
+++ b/app/packages/zod/src/v4/core/schemas.ts
@@ -158,6 +158,9 @@ export interface _$ZodTypeInternals {
/** @internal The parent of this schema. Only set during certain clone operations. */
parent?: $ZodType | undefined;
+
+ /** @internal The schema this instance was cloned from when its definition changed. */
+ source?: $ZodType | undefined;
}
/** @internal */
export interface $ZodTypeInternals<out O = unknown, out I = unknown> extends _$ZodTypeInternals {
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/to-json-schema.ts b/app/packages/zod/src/v4/core/to-json-schema.ts
index fd1333e..18eeb52 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/to-json-schema.ts
+++ b/app/packages/zod/src/v4/core/to-json-schema.ts
@@ -80,6 +80,27 @@ export interface Seen {
path?: (string | number)[] | undefined;
}
+function getMetadataForJSONSchema(
+ schema: schemas.$ZodType,
+ ctx: ToJSONSchemaContext,
+ seen: Set<schemas.$ZodType> = new Set()
+): Record<string, any> | undefined {
+ if (seen.has(schema)) {
+ return ctx.metadataRegistry.getOwn(schema);
+ }
+ seen.add(schema);
+
+ const inheritedFrom = (schema._zod.source ?? schema._zod.parent) as schemas.$ZodType | undefined;
+ const own = ctx.metadataRegistry.getOwn(schema);
+ if (!inheritedFrom) return own;
+
+ const inherited = { ...(getMetadataForJSONSchema(inheritedFrom, ctx, seen) ?? {}) };
+ delete inherited.id;
+
+ const merged = { ...inherited, ...own };
+ return Object.keys(merged).length ? merged : undefined;
+}
+
export interface ToJSONSchemaContext {
processors: Record<string, Processor>;
metadataRegistry: $ZodRegistry<Record<string, any>>;
@@ -141,6 +162,7 @@ export function process<T extends schemas.$ZodType>(
_params: ProcessParams = { path: [], schemaPath: [] }
): JSONSchema.BaseSchema {
const def = schema._zod.def as schemas.$ZodTypes["_zod"]["def"];
+ const parent = schema._zod.parent as T | undefined;
// check for schema in seens
const seen = ctx.seen.get(schema);
@@ -171,28 +193,27 @@ export function process<T extends schemas.$ZodType>(
schemaPath: [..._params.schemaPath, schema],
path: _params.path,
};
-
- const parent = schema._zod.parent as T;
-
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 (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);
}
}
// metadata
- const meta = ctx.metadataRegistry.get(schema);
+ const meta = parent ? ctx.metadataRegistry.getOwn(schema) : getMetadataForJSONSchema(schema, ctx);
if (meta) Object.assign(result.schema, meta);
if (ctx.io === "input" && isTransforming(schema)) {
diff --git a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/util.ts b/app/packages/zod/src/v4/core/util.ts
index 5b1e76b..7bc469d 100644
--- a/tmp/agent-patch-flux-pr-5578.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/util.ts
+++ b/app/packages/zod/src/v4/core/util.ts
@@ -485,6 +485,7 @@ export function escapeRegex(str: string): string {
export function clone<T extends schemas.$ZodType>(inst: T, def?: T["_zod"]["def"], params?: { parent: boolean }): T {
const cl = new inst._zod.constr(def ?? inst._zod.def);
if (!def || params?.parent) cl._zod.parent = inst;
+ else cl._zod.source = inst;
return cl as any;
}