fix(#338): Enforce WSS in production and add connect_error handling

- Add validateWebSocketSecurity() to warn when using ws:// in production
- Add connect_error event handler to capture connection failures
- Expose connectionError state to consumers via hook and provider
- Add comprehensive tests for WSS enforcement and error handling

Refs #338

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jason Woltje
2026-02-05 17:31:26 -06:00
parent 63a622cbef
commit dd46025d60
4 changed files with 194 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ describe("WebSocketProvider", (): void => {
mockUseWebSocket.mockReturnValue({
isConnected: true,
socket: null,
connectionError: null,
});
function TestComponent(): React.JSX.Element {
@@ -33,6 +34,7 @@ describe("WebSocketProvider", (): void => {
mockUseWebSocket.mockReturnValue({
isConnected: false,
socket: null,
connectionError: null,
});
const onTaskCreated = vi.fn();
@@ -86,6 +88,7 @@ describe("WebSocketProvider", (): void => {
mockUseWebSocket.mockReturnValue({
isConnected: false,
socket: null,
connectionError: null,
});
function TestComponent(): React.JSX.Element {
@@ -105,6 +108,7 @@ describe("WebSocketProvider", (): void => {
mockUseWebSocket.mockReturnValue({
isConnected: true,
socket: null,
connectionError: null,
});
rerender(

View File

@@ -22,9 +22,16 @@ interface DeletePayload {
id: string;
}
interface ConnectionError {
message: string;
type: string;
description?: string;
}
interface WebSocketContextValue {
isConnected: boolean;
socket: Socket | null;
connectionError: ConnectionError | null;
}
interface WebSocketProviderProps {
@@ -76,11 +83,12 @@ export function WebSocketProvider({
if (onEventDeleted) callbacks.onEventDeleted = onEventDeleted;
if (onProjectUpdated) callbacks.onProjectUpdated = onProjectUpdated;
const { isConnected, socket } = useWebSocket(workspaceId, token, callbacks);
const { isConnected, socket, connectionError } = useWebSocket(workspaceId, token, callbacks);
const value: WebSocketContextValue = {
isConnected,
socket,
connectionError,
};
return <WebSocketContext.Provider value={value}>{children}</WebSocketContext.Provider>;