fix: reject invalid provider cooldown bounds (#4589)

Integrated into release/v3.8.34 (rebuilt — bundled commits stripped)
This commit is contained in:
KooshaPari
2026-06-22 13:13:45 -07:00
committed by GitHub
parent e9be562bf1
commit ce1a53e5f8
2 changed files with 24 additions and 1 deletions

View File

@@ -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({

View File

@@ -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", () => {