-
Notifications
You must be signed in to change notification settings - Fork 149
fix(client-python): normalize server URI paths before appending task service #738
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
base: develop
Are you sure you want to change the base?
Changes from all commits
508664f
6b7d776
4de158d
77bb5c5
540e254
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import pytest | ||
|
|
||
| from rocketride.mixins.connection import ConnectionMixin | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ('input_uri', 'expected_uri'), | ||
| [ | ||
| ('http://localhost:5565', 'ws://localhost:5565/task/service'), | ||
| ('http://localhost:5565/', 'ws://localhost:5565/task/service'), | ||
| ('https://cloud.rocketride.ai', 'wss://cloud.rocketride.ai/task/service'), | ||
| ('https://cloud.rocketride.ai/', 'wss://cloud.rocketride.ai/task/service'), | ||
| ('wss://cloud.rocketride.ai', 'wss://cloud.rocketride.ai/task/service'), | ||
| ('wss://cloud.rocketride.ai/', 'wss://cloud.rocketride.ai/task/service'), | ||
| ('wss://cloud.rocketride.ai/task/service', 'wss://cloud.rocketride.ai/task/service'), | ||
| ('ws://localhost:5565', 'ws://localhost:5565/task/service'), | ||
| ('ws://localhost:5565/', 'ws://localhost:5565/task/service'), | ||
| ('ws://localhost:5565/task/service', 'ws://localhost:5565/task/service'), | ||
| ], | ||
| ) | ||
| def test_get_websocket_uri_normalizes_task_service_path(input_uri, expected_uri): | ||
| assert ConnectionMixin._get_websocket_uri(input_uri) == expected_uri | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -435,13 +435,23 @@ export class RocketRideClient extends DAPClient { | |
| */ | ||
| private _getWebsocketUri(uri: string): string { | ||
| const httpUrl = RocketRideClient.normalizeUri(uri); | ||
| const SERVICE_PATH = '/task/service'; | ||
|
|
||
| try { | ||
| const url = new URL(httpUrl); | ||
| const wsScheme = url.protocol === 'https:' || url.protocol === 'wss:' ? 'wss:' : 'ws:'; | ||
| return `${wsScheme}//${url.host}/task/service`; | ||
| // Normalize the path: strip trailing slash, then append /task/service | ||
| // only if it isn't already present (prevents double-path when callers | ||
| // pass an already-normalized WebSocket endpoint). | ||
| let path = url.pathname.replace(/\/+$/, ''); | ||
| if (!path.endsWith(SERVICE_PATH)) { | ||
| path = path ? `${path}${SERVICE_PATH}` : SERVICE_PATH; | ||
| } | ||
| return `${wsScheme}//${url.host}${path}`; | ||
| } catch { | ||
| return `${httpUrl}/task/service`; | ||
| // Fallback for unparseable URIs — same trailing-slash + dedup logic | ||
| const stripped = httpUrl.replace(/\/+$/, ''); | ||
| return stripped.endsWith(SERVICE_PATH) ? stripped : `${stripped}${SERVICE_PATH}`; | ||
|
Comment on lines
+446
to
+454
Contributor
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. 🧹 Nitpick | 🔵 Trivial 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify whether the TS test file already covers trailing-slash and pre-normalized-path cases.
rg -n "trailing|task/service" --type=ts packages/client-typescript/tests/Repository: rocketride-org/rocketride-server Length of output: 608 🏁 Script executed: # First, read the actual test file context around the URI normalization tests
sed -n '2186,2200p' packages/client-typescript/tests/RocketRideClient.test.tsRepository: rocketride-org/rocketride-server Length of output: 681 🏁 Script executed: # Read the code being tested to verify the logic matches the suggested test cases
sed -n '440,460p' packages/client-typescript/src/client/client.tsRepository: rocketride-org/rocketride-server Length of output: 880 TypeScript tests are missing the exact regression cases this PR fixes. The existing Suggested additions: it.each([
['wss://cloud.rocketride.ai', 'wss://cloud.rocketride.ai/task/service'],
['https://cloud.rocketride.ai', 'wss://cloud.rocketride.ai/task/service'],
['ws://localhost:5565', 'ws://localhost:5565/task/service'],
['http://localhost:5565', 'ws://localhost:5565/task/service'],
+ // trailing-slash regression: must not produce double slash
+ ['wss://cloud.rocketride.ai/', 'wss://cloud.rocketride.ai/task/service'],
+ ['https://cloud.rocketride.ai/', 'wss://cloud.rocketride.ai/task/service'],
+ ['http://localhost:5565/', 'ws://localhost:5565/task/service'],
+ // pre-normalized path: must not duplicate /task/service
+ ['wss://cloud.rocketride.ai/task/service', 'wss://cloud.rocketride.ai/task/service'],
+ ['https://cloud.rocketride.ai/task/service', 'wss://cloud.rocketride.ai/task/service'],
])('normalizes %s to %s', (inputUri, expectedUri) => {🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.