diff --git a/packages/validation/api.test.ts b/packages/validation/api.test.ts index fa52ed890..dbd39983d 100644 --- a/packages/validation/api.test.ts +++ b/packages/validation/api.test.ts @@ -18,6 +18,41 @@ describe("search threshold schemas", () => { expect(searchSchemas).not.toContain(".transform(Number)") expect(searchSchemas).not.toContain("v === undefined || (v >= 0 && v <= 1)") + expect(searchSchemas).not.toContain( + "v === undefined || (v > 0 && v <= 100)", + ) + }) + + it.each([ + 1, 50, 100, + ])("accepts in-range limit value %p on search schemas", (limit) => { + expect(SearchRequestSchema.parse({ q: "memory", limit }).limit).toBe(limit) + expect(Searchv4RequestSchema.parse({ q: "memory", limit }).limit).toBe( + limit, + ) + }) + + it("preserves the limit default of 10 on search schemas", () => { + expect(SearchRequestSchema.parse({ q: "memory" }).limit).toBe(10) + expect(Searchv4RequestSchema.parse({ q: "memory" }).limit).toBe(10) + }) + + it("still rejects a limit above 100 on search schemas", () => { + expect( + SearchRequestSchema.safeParse({ q: "memory", limit: 101 }).success, + ).toBe(false) + expect( + Searchv4RequestSchema.safeParse({ q: "memory", limit: 101 }).success, + ).toBe(false) + }) + + it("still rejects a non-positive limit on search schemas", () => { + expect( + SearchRequestSchema.safeParse({ q: "memory", limit: 0 }).success, + ).toBe(false) + expect( + Searchv4RequestSchema.safeParse({ q: "memory", limit: -1 }).success, + ).toBe(false) }) it("preserves threshold defaults", () => { diff --git a/packages/validation/api.ts b/packages/validation/api.ts index ae6ac3191..43f6db943 100644 --- a/packages/validation/api.ts +++ b/packages/validation/api.ts @@ -432,7 +432,7 @@ export const SearchRequestSchema = z.object({ .positive() .optional() .default(10) - .refine((v) => v === undefined || (v > 0 && v <= 100), { + .refine((v) => v <= 100, { message: "limit must be between 1 and 100", params: { max: 100, @@ -527,7 +527,7 @@ export const Searchv4RequestSchema = z.object({ .positive() .optional() .default(10) - .refine((v) => v === undefined || (v > 0 && v <= 100), { + .refine((v) => v <= 100, { message: "limit must be between 1 and 100", params: { max: 100,