Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 25, 2025

Description

This PR fixes the broken URL construction for Requesty model fetching. The issue occurred when using custom base URLs with /v1 path - the models endpoint URL was incorrectly resolving to /models instead of /v1/models.

Problem

Given a custom URL like https://custom.requesty.ai/v1, the model listing URL was incorrectly becoming https://custom.requesty.ai/models instead of the expected https://custom.requesty.ai/v1/models.

This happened because the new URL() constructor replaces the last path segment when the base URL doesn't end with a slash.

Solution

  • Ensure the base URL ends with a slash before appending "models" path
  • Added comprehensive tests covering various URL scenarios
  • Added clarifying comment explaining the URL construction logic

Testing

  • ✅ All existing tests pass
  • ✅ Added 10 new test cases specifically for URL construction scenarios
  • ✅ Tests cover default URLs, custom URLs with/without /v1, trailing slashes, and API key handling

Fixes #7377


Important

Fixes URL construction in getRequestyModels to correctly append /models and adds comprehensive tests for various URL scenarios.

  • Behavior:
    • Fixes URL construction in getRequestyModels in requesty.ts to ensure base URL ends with a slash before appending /models.
    • Handles custom URLs with/without /v1 and trailing slashes.
  • Testing:
    • Adds requesty.spec.ts with 10 new test cases for URL construction, including default/custom URLs and API key handling.
    • Tests cover model parsing and error handling scenarios.
  • Misc:
    • Adds comments in requesty.ts explaining URL construction logic.

This description was created by Ellipsis for 29174b3. You can customize this summary. It will automatically update as commits are pushed.

- Fix URL construction in getRequestyModels to properly append /models path
- Ensure base URL with /v1 correctly resolves to /v1/models instead of /models
- Add comprehensive tests for URL construction scenarios

Fixes #7377
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 25, 2025 00:06
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working documentation Improvements or additions to documentation labels Aug 25, 2025
@mrubens mrubens closed this Aug 25, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 25, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 25, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.

// Ensure the base URL ends with a slash so "models" is appended correctly
// Without this, new URL("models", "https://custom.requesty.ai/v1") would incorrectly
// resolve to "https://custom.requesty.ai/models" instead of "https://custom.requesty.ai/v1/models"
const baseWithSlash = resolvedBaseUrl.endsWith("/") ? resolvedBaseUrl : `${resolvedBaseUrl}/`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks correct and the comment is helpful! Though I'm wondering - what happens if someone provides a base URL with query parameters like https://custom.requesty.ai/v1?key=value? The URL constructor should handle it, but might be worth adding a test case to ensure the behavior is as expected.

// Ensure the base URL ends with a slash so "models" is appended correctly
// Without this, new URL("models", "https://custom.requesty.ai/v1") would incorrectly
// resolve to "https://custom.requesty.ai/models" instead of "https://custom.requesty.ai/v1/models"
const baseWithSlash = resolvedBaseUrl.endsWith("/") ? resolvedBaseUrl : `${resolvedBaseUrl}/`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting this URL construction logic into a small helper function for better testability and reusability. Something like:

Suggested change
const baseWithSlash = resolvedBaseUrl.endsWith("/") ? resolvedBaseUrl : `${resolvedBaseUrl}/`
const ensureTrailingSlashForPath = (url: string): string => {
return url.endsWith("/") ? url : `${url}/`
}
const baseWithSlash = ensureTrailingSlashForPath(resolvedBaseUrl)

expect(mockAxios.get).toHaveBeenCalledWith("https://custom.requesty.ai/v1/models", {
headers: { Authorization: "Bearer test-api-key" },
})
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test coverage! Consider adding a few edge cases:

  • URLs with query parameters (?key=value)
  • URLs with fragments (#section)
  • URLs with unusual port numbers (:8080)

These would help ensure the URL construction is robust across all scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Requesty model fetching broken

3 participants