fix(tags): clamp popular limit values#361
Conversation
Greptile SummaryThis PR fixes a subtle falsy-zero bug in the popular-tags route where
Confidence Score: 5/5Safe to merge — the change is a one-line swap to a well-tested utility with correct clamping semantics, and the new tests confirm all three boundary cases. The fix is minimal and focused: the parsePaginationParam utility already handles null, NaN, zero, and oversized values correctly, and the three new tests exercise exactly the edge cases the bug report described. No other logic in the route was changed, and the existing Supabase query path is untouched. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Route as GET /api/tags/popular
participant parsePaginationParam
participant Supabase
Client->>Route: "GET ?limit=<value>"
Route->>parsePaginationParam: parsePaginationParam(value, 50, 1, 200)
Note over parsePaginationParam: null/blank → 50 (default)<br/>NaN → 50 (default)<br/>0 → 1 (clamped to min)<br/>999 → 200 (clamped to max)
parsePaginationParam-->>Route: bounded limit
Route->>Supabase: from("gigs").select("skills_required").eq("status","active")
Supabase-->>Route: gigs[]
Route->>Supabase: from("tag_follows").select("tag")
Supabase-->>Route: follows[]
Note over Route: count tags, merge, sort by<br/>follower_count desc, gig_count desc
Route->>Route: tags.slice(0, limit)
Route-->>Client: "{ tags: limited[] }"
Reviews (1): Last reviewed commit: "fix(tags): clamp popular limit values" | Re-trigger Greptile |
Summary
limit=0to1instead of accidentally expanding it to the default50Fixes #360.
Paid task context: https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e
Verification
.\node_modules\.bin\vitest.CMD run src/app/api/tags/popular/route.test.ts.\node_modules\.bin\eslint.CMD src/app/api/tags/popular/route.ts src/app/api/tags/popular/route.test.tsgit diff --cached --checkExisting upstream check blockers
.\node_modules\.bin\tsc.CMD --noEmitreaches unrelated existing errors insrc/app/api/affiliates/offers/route.test.ts:53andsrc/app/api/applications/[id]/route.test.ts:21.corepack pnpm run buildcompiles successfully and progresses through static generation when given a process-local dummy OpenAI key, then stops because the local checkout has no Supabase service-role configuration.