-
Notifications
You must be signed in to change notification settings - Fork 190
fix(rivetkit): fix routing of /websocket
#3995
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
Closed
NathanFlurry
wants to merge
1
commit into
01-21-fix_rivetkit_add_config_parameters_to_spawned_serverless_engine_for_local_dev
from
01-21-fix_rivetkit_fix_routing_of__websocket_
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
rivetkit-typescript/packages/rivetkit/src/actor/router-websocket-endpoints.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import { | ||
| PATH_WEBSOCKET_BASE, | ||
| PATH_WEBSOCKET_PREFIX, | ||
| } from "@/common/actor-router-consts"; | ||
|
|
||
| /** | ||
| * Unit tests for WebSocket path routing logic. | ||
| * | ||
| * These tests verify the path matching behavior in routeWebSocket | ||
| * without needing a full actor setup. | ||
| * | ||
| * NOTE: The driver-file-system end-to-end tests pass because the driver | ||
| * correctly strips query parameters before calling routeWebSocket | ||
| * (see FileSystemManagerDriver.openWebSocket). However, the bug still | ||
| * exists in routeWebSocket itself and could be triggered by other callers | ||
| * (e.g., engine driver's runnerWebSocket which passes requestPath directly). | ||
| */ | ||
| describe("websocket path routing", () => { | ||
| // Helper that replicates the routing logic from routeWebSocket | ||
| // After fix: strips query params before comparing | ||
| function matchesWebSocketPath(requestPath: string): boolean { | ||
| const requestPathWithoutQuery = requestPath.split("?")[0]; | ||
| return ( | ||
| requestPathWithoutQuery === PATH_WEBSOCKET_BASE || | ||
| requestPathWithoutQuery.startsWith(PATH_WEBSOCKET_PREFIX) | ||
| ); | ||
| } | ||
|
|
||
| test("should match base websocket path without query", () => { | ||
| expect(matchesWebSocketPath("/websocket")).toBe(true); | ||
| }); | ||
|
|
||
| test("should match websocket path with trailing slash", () => { | ||
| expect(matchesWebSocketPath("/websocket/")).toBe(true); | ||
| }); | ||
|
|
||
| test("should match websocket path with subpath", () => { | ||
| expect(matchesWebSocketPath("/websocket/foo")).toBe(true); | ||
| expect(matchesWebSocketPath("/websocket/foo/bar")).toBe(true); | ||
| }); | ||
|
|
||
| test("should match websocket path with subpath and query", () => { | ||
| // This works because "/websocket/foo?query" starts with "/websocket/" | ||
| expect(matchesWebSocketPath("/websocket/foo?query=value")).toBe(true); | ||
| }); | ||
|
|
||
| // FIX: Query parameters are now stripped before routing comparison. | ||
| // This ensures /websocket?query correctly routes to the websocket handler. | ||
| test("should match base websocket path with query parameters", () => { | ||
| expect(matchesWebSocketPath("/websocket?token=abc")).toBe(true); | ||
| expect(matchesWebSocketPath("/websocket?foo=bar&baz=123")).toBe(true); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The imports are not properly sorted. Biome linter typically expects imports to be sorted with internal imports (starting with '@/') coming before external module imports (like 'vitest'). Swap the order of these import statements to fix the linting error.
Spotted by Graphite Agent (based on CI logs)

Is this helpful? React 👍 or 👎 to let us know.