-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix tests for baseUrl parameter in getRequestyModels #7336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5e812cf
f0a5bd6
e74ca6f
64ac30d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -103,7 +103,7 @@ describe("getModels with new GetModelsOptions", () => { | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const result = await getModels({ provider: "requesty", apiKey: DUMMY_REQUESTY_KEY }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| expect(mockGetRequestyModels).toHaveBeenCalledWith(DUMMY_REQUESTY_KEY) | ||||||||||||||||||||||||||||||
| expect(mockGetRequestyModels).toHaveBeenCalledWith(undefined, DUMMY_REQUESTY_KEY) | ||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test expects
Suggested change
|
||||||||||||||||||||||||||||||
| expect(result).toEqual(mockModels) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| const REQUESTY_BASE_URL = "https://router.requesty.ai/v1" | ||
|
|
||
| type URLType = "router" | "app" | "api" | ||
|
|
||
| const replaceCname = (baseUrl: string, type: URLType): string => { | ||
| if (type === "router") { | ||
| return baseUrl | ||
| } else { | ||
| return baseUrl.replace("router", type).replace("v1", "") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URL transformation logic here (replacing 'router' with service type and removing 'v1') seems fragile. What happens if the baseUrl doesn't contain 'router' or 'v1'? Should we add some validation or tests to ensure this works correctly for different URL formats? |
||
| } | ||
| } | ||
|
|
||
| export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): string => { | ||
| let url = replaceCname(baseUrl ?? REQUESTY_BASE_URL, service) | ||
|
|
||
| try { | ||
| return new URL(url).toString() | ||
| } catch (error) { | ||
| // If the provided baseUrl is invalid, fall back to the default | ||
| console.warn(`Invalid base URL "${baseUrl}", falling back to default`) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional that we silently fall back to the default URL when an invalid baseUrl is provided? In development/test environments, throwing an error might help catch configuration issues early. What do you think about adding an environment check here? |
||
| return new URL(replaceCname(REQUESTY_BASE_URL, service)).toString() | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this test name more descriptive? Something like "initializes OpenAI client with custom base URL when provided" would be clearer about what's being tested.