Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/shared/validation/schemas/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,20 @@ export const providerCooldownSettingsSchema = z
minRetryCooldownMs: z.number().int().min(0).max(300000).optional(),
maxRetryCooldownMs: z.number().int().min(0).max(3600000).optional(),
})
.strict();
.strict()
.superRefine((value, ctx) => {
if (
typeof value.minRetryCooldownMs === "number" &&
typeof value.maxRetryCooldownMs === "number" &&
value.maxRetryCooldownMs < value.minRetryCooldownMs
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "maxRetryCooldownMs must be greater than or equal to minRetryCooldownMs",
path: ["maxRetryCooldownMs"],
});
}
});

export const updateResilienceSchema = z
.object({
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/resilience-provider-cooldown-api-3556.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe("providerCooldown in updateResilienceSchema", () => {
});
assert.equal(result.success, false, "Schema should reject unknown keys");
});

it("rejects providerCooldown max below min", () => {
const result = updateResilienceSchema.safeParse({
providerCooldown: {
minRetryCooldownMs: 120000,
maxRetryCooldownMs: 30000,
},
});
assert.equal(result.success, false, "Schema should reject contradictory cooldown bounds");
});
});

describe("providerCooldown roundtrip through mergeResilienceSettings", () => {
Expand Down
Loading