fix: normalize regional API base URL and prevent invalid multi-region…#2942
fix: normalize regional API base URL and prevent invalid multi-region…#2942HarshMN2345 merged 3 commits intomainfrom
Conversation
WalkthroughA new utility module Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/helpers/apiEndpoint.ts (1)
71-85: Add focused tests for endpoint normalization edge cases.Please add helper-level tests for: repeated prefixes, hostnames with ports, unknown region values, and
isMultiRegion=falsepassthrough behavior to lock this logic down.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/helpers/apiEndpoint.ts` around lines 71 - 85, Add focused unit tests that exercise buildRegionalV1Endpoint and its helpers (stripLeadingRegionSubdomain, getRegionSubdomain): 1) verify repeated region prefixes are normalized (e.g., "us-us.example.com" -> single "us."), 2) ensure hostnames with ports (e.g., "example.com:3000") preserve the port and produce correct "/v1" path, 3) cover unknown/undefined region values to confirm getRegionSubdomain returns the expected fallback and the endpoint remains valid, and 4) assert that when isMultiRegion=false the function returns the hostname unchanged (passthrough) with protocol and "/v1". Include assertions for both protocol variants and edge-case inputs to lock down normalization behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/lib/helpers/apiEndpoint.ts`:
- Around line 71-85: Add focused unit tests that exercise
buildRegionalV1Endpoint and its helpers (stripLeadingRegionSubdomain,
getRegionSubdomain): 1) verify repeated region prefixes are normalized (e.g.,
"us-us.example.com" -> single "us."), 2) ensure hostnames with ports (e.g.,
"example.com:3000") preserve the port and produce correct "/v1" path, 3) cover
unknown/undefined region values to confirm getRegionSubdomain returns the
expected fallback and the endpoint remains valid, and 4) assert that when
isMultiRegion=false the function returns the hostname unchanged (passthrough)
with protocol and "/v1". Include assertions for both protocol variants and
edge-case inputs to lock down normalization behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dae0f278-bde9-41db-89eb-598cb928dce8
📒 Files selected for processing (2)
src/lib/helpers/apiEndpoint.tssrc/lib/stores/sdk.ts
Greptile SummaryThis PR extracts regional API URL construction from Confidence Score: 5/5Safe to merge — refactoring is functionally correct and fixes a real region-switching bug All previously raised P1 concerns (region stripped on undefined, missing guard) are addressed in the current code via the early !subdomain return. No new P0/P1 issues found. Remaining gap (no test file) was already noted in prior review threads and is a P2. src/lib/helpers/apiEndpoint.ts — no accompanying test file Important Files Changed
Reviews (3): Last reviewed commit: "addressed commet" | Re-trigger Greptile |
… hosts
What does this PR do?
(Provide a description of what this PR does.)
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
(Write your answer here.)
Summary by CodeRabbit