Skip to content

feat(ws): multiple messages support in websockets - #8115

Merged
sid-bruno merged 15 commits into
usebruno:mainfrom
pooja-bruno:fix/ws-message-name-cursor-and-overflow
Jun 8, 2026
Merged

sid-bruno merged 15 commits into
usebruno:mainfrom
pooja-bruno:fix/ws-message-name-cursor-and-overflow

Conversation

@pooja-bruno

@pooja-bruno pooja-bruno commented May 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

BRU-3293
BRU-3295
BRU-2483
BRU-2932

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.
Screen.Recording.2026-05-27.at.1.58.22.PM.mov

@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR implements multi-message WebSocket support with selection-based sending. Changes span UI components (accordion-style message UI), Redux state (selection tracking, UID preservation), serialization formats (BRU, YAML, OpenCollection), IPC layer (indexed message queuing), and comprehensive E2E tests for both BRU and YAML formats.

Changes

WebSocket Multi-Message Feature Implementation

Layer / File(s) Summary
Schema and Type Contract
packages/bruno-schema-types/src/requests/websocket.ts
WebSocketMessage interface adds optional selected?: boolean | null field to track which message should be sent.
Language Parser Support for Selected Field
packages/bruno-lang/v2/src/bruToJson.js, packages/bruno-lang/v2/src/jsonToBru.js, packages/bruno-lang/v2/tests/bruToJson.spec.js
BRU parser reads/emits selected field on websocket messages; tests verify single-message selected: true, multi-message selection, and default-false behavior.
File Format Serialization
packages/bruno-filestore/src/formats/yml/items/parseWebsocketRequest.ts, packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts, packages/bruno-converters/src/opencollection/items/websocket.ts
YAML and OpenCollection converters support multi-message arrays with selected field, detecting legacy single-message format and emitting both flat (backward-compatible) and array variants.
Redux State Management and Message Selection
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js, packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js, packages/bruno-app/src/utils/collections/index.js
Redux actions compute selected message index from request body; UID preservation extended to body.ws messages; request transformation includes selected field with default false.
IPC and Backend Message Queuing
packages/bruno-app/src/utils/network/index.js, packages/bruno-electron/src/ipc/network/ws-event-handlers.js, packages/bruno-electron/src/utils/collection.js
Refactored to accept selectedMessageIndex instead of messageContent; IPC handler queues only the message at that index; electron collection utils hydrate UUIDs for ws messages.
Single Message Component and Styling
packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js, packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/StyledWrapper.js
Component refactored to accordion-style with inline name editing, per-message send/delete actions, expansion state, and lifecycle callbacks (isExpanded, onToggle, isNew, onSelect); CSS rewritten for header/body/action layout.
WSBody Container Refactoring
packages/bruno-app/src/components/RequestPane/WsBody/index.js, packages/bruno-app/src/components/RequestPane/WsBody/StyledWrapper.js
Manages UI state (expanded UIDs, selection, new-message marking); routes selection to Redux; receives onAddMessage callback; auto-scrolls latest message; simplified .messages-container CSS and replaced footer with inline add-message link.
Request Pane Integration
packages/bruno-app/src/components/RequestPane/WSRequestPane/index.js
Adds addNewMessage handler (creates message with uid, default JSON, selected: true) and onPrettifyAll handler (prettifies JSON/XML content); wires buttons; derives body from draft/persisted request; passes onAddMessage to WsBody.
E2E Tests: BRU Format
tests/websockets/multi-message-bru/*
Fixtures and Playwright tests for message add/edit/delete/rename, per-message types, send routing, prettify, and name styling (truncation/ellipsis).
E2E Tests: YAML Format
tests/websockets/multi-message-yml/*
Fixtures and Playwright tests for multi-message and legacy-format migration, covering add/edit/delete/rename, type persistence, selection routing, prettify, and YAML round-trips.

Sequence Diagram

sequenceDiagram
  participant User
  participant RequestPane
  participant WSBody
  participant SingleMessage
  participant Redux
  participant IPC
  participant Electron

  User->>RequestPane: Click "Add Message"
  RequestPane->>RequestPane: addNewMessage()
  RequestPane->>Redux: updateRequestBody (new msg with uid, selected:true)
  Redux->>RequestPane: update state
  RequestPane->>WSBody: onAddMessage passed as prop
  
  User->>SingleMessage: Click message header to select
  SingleMessage->>Redux: dispatch setSelectedIndex
  Redux->>RequestPane: update request.body.ws[i].selected
  
  User->>SingleMessage: Click "Send" button
  SingleMessage->>SingleMessage: connectWS if needed
  SingleMessage->>IPC: queueWsMessage(selectedMessageIndex)
  IPC->>Electron: renderer:ws:queue-message with index
  Electron->>Electron: queue only message at that index
  
  User->>RequestPane: Click "Prettify All"
  RequestPane->>RequestPane: onPrettifyAll()
  RequestPane->>Redux: updateRequestBody (prettified contents)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


Possibly related PRs

  • usebruno/bruno#7921: Directly opposing changes—this PR reintroduces multi-message UI behaviors (Add Message, Prettify All, per-message selection/sending) in WSRequestPane/WsBody/SingleWSMessage, while PR #7921 explicitly reverts those same features.
  • usebruno/bruno#7719: Parallel implementation of the same core multi-message accordion UI refactor, SingleWSMessage component rewrite, and StyledWrapper layout changes.

Suggested labels

size/L

Suggested reviewers

  • lohit-bruno
  • naman-bruno
  • sid-bruno
  • bijin-bruno

Poem

🌊 Messages flow in a river now,
each one marked, each one chosen—
accordion headers expand and bow,
selection keeps its promise unbroken.
WebSocket dances with multi-step grace,
persistence blooms in every place. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main feature: adding support for multiple WebSocket messages within a single request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 9

🧹 Nitpick comments (2)
tests/websockets/multi-message-yml/multi-message.spec.ts (2)

32-294: ⚡ Quick win

Consider wrapping logical test phases in test.step for clearer reports.

Using test.step improves trace readability and makes CI reports easier to debug. Each test contains multiple logical phases (arrange, act, assert) that would benefit from step labeling.

Example refactor for the backward compatibility test:

📊 Example with test.step
 test('backward compatibility: old single-message format loads correctly', async ({ pageWithUserData: page }) => {
-  await openRequest(page, COLLECTION_NAME, SINGLE_MSG_REQ);
-
-  // The old format (message: { type, data }) should load as a single accordion
-  await expect(page.getByTestId(/^ws-message-header-/)).toHaveCount(1);
+  await test.step('Load single-message request from old format', async () => {
+    await openRequest(page, COLLECTION_NAME, SINGLE_MSG_REQ);
+    await expect(page.getByTestId(/^ws-message-header-/)).toHaveCount(1);
+  });
 
-  // Expand the first message if not already expanded
-  if (!(await page.getByTestId('ws-message-body-0').isVisible())) {
-    await page.getByTestId('ws-message-header-0').click();
-  }
-  await expect(page.getByTestId('ws-message-body-0')).toBeVisible();
-  await expect(page.getByTestId('ws-message-header-0').locator('.selected-body-mode')).toContainText('JSON');
+  await test.step('Verify old format loads as single accordion with correct type', async () => {
+    if (!(await page.getByTestId('ws-message-body-0').isVisible())) {
+      await page.getByTestId('ws-message-header-0').click();
+    }
+    await expect(page.getByTestId('ws-message-body-0')).toBeVisible();
+    await expect(page.getByTestId('ws-message-header-0').locator('.selected-body-mode')).toContainText('JSON');
+  });
 
-  // Add a second message to trigger format migration
-  await page.getByTestId('ws-add-message').click();
-  const nameInput = page.getByTestId(/^ws-message-name-input-/);
-  await expect(nameInput).toBeVisible();
-  await nameInput.selectText();
-  await page.keyboard.type('new message');
-  await nameInput.press('Enter');
-  await saveRequest(page);
+  await test.step('Add second message to trigger format migration', async () => {
+    await page.getByTestId('ws-add-message').click();
+    const nameInput = page.getByTestId(/^ws-message-name-input-/);
+    await expect(nameInput).toBeVisible();
+    await nameInput.selectText();
+    await page.keyboard.type('new message');
+    await nameInput.press('Enter');
+    await saveRequest(page);
+  });
 
-  // Verify the yml file now uses the array format (WebSocketMessageVariant[])
-  const ymlContent = await readFile(SINGLE_MSG_YML_PATH, 'utf8');
-  expect(ymlContent).toContain('- title:');
-  expect(ymlContent).toContain('new message');
+  await test.step('Verify YAML migrated to array format', async () => {
+    const ymlContent = await readFile(SINGLE_MSG_YML_PATH, 'utf8');
+    expect(ymlContent).toContain('- title:');
+    expect(ymlContent).toContain('new message');
+  });
 
-  // Re-open to verify it still loads correctly after format migration
-  await openRequest(page, COLLECTION_NAME, MULTI_MSG_REQ);
-  await openRequest(page, COLLECTION_NAME, SINGLE_MSG_REQ);
-  await expect(page.getByTestId(/^ws-message-header-/)).toHaveCount(2);
+  await test.step('Re-open and verify both messages load', async () => {
+    await openRequest(page, COLLECTION_NAME, MULTI_MSG_REQ);
+    await openRequest(page, COLLECTION_NAME, SINGLE_MSG_REQ);
+    await expect(page.getByTestId(/^ws-message-header-/)).toHaveCount(2);
+  });
 });

As per coding guidelines: "Promote the use of test.step as much as possible so the generated reports are easier to read."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/websockets/multi-message-yml/multi-message.spec.ts` around lines 32 -
294, Wrap each logical phase (arrange, act, assert) inside test.step calls to
improve test-report clarity by updating the test blocks (e.g., the test named
"backward compatibility: old single-message format loads correctly" and other
tests in this file like "add a new message and save", "edit message content and
verify persistence", etc.) — locate the test(...) functions and enclose setup
interactions (openRequest, clicks), actions (saving, modifying, sending) and
assertions (expect(...)) in descriptive await test.step('phase name', async ()
=> { ... }) blocks so each phase is reported separately; keep existing calls and
order unchanged, just move the relevant lines into appropriately named test.step
closures for each logical phase.

51-51: Refine websocket multi-message e2e assertions: remove selectText() concern; add test.step for readability

  • nameInput.selectText() is part of the standard Playwright Locator API, and this repo uses Playwright ^1.51.1, so it doesn’t need changes.
  • These websocket multi-message specs don’t use test.step(...); wrap the main user actions/assertions (add/rename message, type, save, verify persisted YAML, etc.) to match the guideline and improve report readability.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/websockets/multi-message-yml/multi-message.spec.ts` at line 51, The
review says keep nameInput.selectText() as-is and instead wrap the main scenario
actions in test.step() calls to improve readability; update the test in
multi-message.spec.ts so the sequence that manipulates the UI (the blocks around
nameInput.selectText(), the add/rename message flow, typing into inputs,
clicking save, and the verification that persisted YAML matches expectations)
are each wrapped in descriptive test.step("...") blocks, using Playwright's
test.step API to group actions/assertions and leaving nameInput.selectText()
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 138-146: onDeleteMessage removes an item from body.ws but doesn't
preserve/adjust the selected flag, so deleting the currently selected row can
leave no item marked selected in the persisted request; modify onDeleteMessage
to compute the new selected index (prefer index-1 if deleting a selected item,
otherwise preserve existing selected index, clamped to array bounds), update the
remaining messages array to set selected: true on the chosen message and clear
selected on others, then call dispatch(updateRequestBody({ content:
currentMessages, itemUid: item.uid, collectionUid: collection.uid })); reference
the onDeleteMessage function, body.ws array, and updateRequestBody call when
implementing this change.
- Around line 148-166: The onSendMessage callback captures stale values because
its dependency array only lists collections; include all external values it
reads so React can recreate the callback when they change. Update the
useCallback dependency array for onSendMessage to include collection (or
collection.uid), index, item and collections (and any other external helpers if
not stable) so that references used inside (collection.uid, index, item,
findCollectionByUid, findEnvironmentInCollection, isWsConnectionActive,
connectWS, queueWsMessage) are current after deletes/reindexes.
- Around line 207-214: The span with className "message-label" is causing a
double-toggle because its onClick calls onToggle() without stopping event
propagation so the parent .accordion-header onClick={onToggle} also fires;
update the span's onClick handler (and also the onDoubleClick handler if needed)
to call e.stopPropagation() before calling onToggle() or handleNameClick to
prevent the parent onClick from running twice, referencing the "message-label"
span, its onClick/onDoubleClick handlers, and the onToggle function to locate
and fix the code.
- Around line 81-92: handle the rename/toggle bugs by: 1) Changing
handleNameKeyDown so Escape sets editValue back to displayName, sets isEditing
false, and sets a flag or uses a ref to indicate the change was canceled so
handleNameBlur does not call saveName; update handleNameBlur to only call
saveName when not canceled (or when isEditing is still true and not canceled).
2) Prevent double-toggle by stopping propagation on the label click handler (the
element with class "message-label" that currently calls onToggle) or remove one
of the duplicate onClick handlers so only one onToggle is invoked (reference
onToggle and the header container/label click handlers). 3) Fix onSendMessage
useCallback by including collection, item, and index in its dependency array so
it cannot capture stale values (update the useCallback declaration to list
collection, item, index alongside existing deps).

In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/StyledWrapper.js`:
- Around line 53-85: The hover-only visibility rule for the .hover-actions block
prevents keyboard users from tabbing to the Send/Delete buttons; update the
StyledWrapper styles so the same reveal used for &:hover also applies on
keyboard focus by including &:focus-within (e.g. make the rule that currently
targets "&:hover .hover-actions" also target "&:focus-within .hover-actions"),
leaving the .hover-actions properties (visibility, opacity, transition) and
.hover-action-btn styles unchanged so keyboard users can access the buttons.

In `@packages/bruno-app/src/components/RequestPane/WSRequestPane/index.js`:
- Around line 191-197: The toolbar Add Message ActionIcon currently uses the
same data-testid ("ws-add-message") as the empty-state element rendered by
WsBody, causing ambiguous Playwright selectors; update the ActionIcon in
RequestPane/WSRequestPane (the ToolHint/ActionIcon that calls addNewMessage) to
use a unique data-testid (e.g., "ws-add-message-toolbar" or
"ws-toolbar-add-message") so it no longer conflicts with WsBody's test id and
Playwright can reliably target the toolbar button.

In `@packages/bruno-electron/src/ipc/network/ws-event-handlers.js`:
- Around line 409-418: The handler currently returns { success: true } even when
the selectedMessageIndex is invalid or no message is queued; update the logic
around messages, selectedMessageIndex and wsClient.queueMessage so that if
messages is empty/invalid or messages[selectedMessageIndex] is missing (or
message.content is falsy) the function returns { success: false, error: 'No
message selected to send' } (or a similar error), and only after successfully
calling wsClient.queueMessage(preparedRequest.uid, collection.uid,
message.content, message.type) return { success: true }; ensure you reference
the existing symbols messages, selectedMessageIndex, message.content,
message.type, preparedRequest.uid, collection.uid and wsClient.queueMessage when
making the change.

In `@packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts`:
- Around line 48-53: The current hasCustomName check treats any non-empty name
as custom (in stringifyWebsocketRequest.ts), causing auto-generated names like
"message 1" to force WebSocketMessageVariant[] serialization; update the logic
used by hasCustomName to ignore default auto-generated names (e.g., treat names
matching /^message\s*\d+$/i or other generator patterns as not custom) so that
when messages.length === 1 it will fall back to flat WebSocketMessage
serialization; modify the hasCustomName assignment (and any downstream use of
hasCustomName) to perform this regex check against messages[0].name instead of
only checking for non-empty strings.

In `@tests/websockets/multi-message-bru/multi-message.spec.ts`:
- Around line 10-26: The tests currently mutate repo-level fixture files via
MULTI_MSG_BRU_PATH and SINGLE_MSG_BRU_PATH in test.beforeAll/test.afterEach
which makes runs non-parallel-safe; change the setup to create per-test (or
per-worker) isolated copies of those fixtures in a unique temp directory (use
mkdtemp or tmpdir) in test.beforeEach or test.beforeAll and point the tests to
the copied file paths instead of the originals, and remove the write-back logic
in test.afterEach; update references to MULTI_MSG_BRU_PATH/SINGLE_MSG_BRU_PATH
to use the temp paths so each spec worker has its own workspace and no repo
fixtures are mutated.

---

Nitpick comments:
In `@tests/websockets/multi-message-yml/multi-message.spec.ts`:
- Around line 32-294: Wrap each logical phase (arrange, act, assert) inside
test.step calls to improve test-report clarity by updating the test blocks
(e.g., the test named "backward compatibility: old single-message format loads
correctly" and other tests in this file like "add a new message and save", "edit
message content and verify persistence", etc.) — locate the test(...) functions
and enclose setup interactions (openRequest, clicks), actions (saving,
modifying, sending) and assertions (expect(...)) in descriptive await
test.step('phase name', async () => { ... }) blocks so each phase is reported
separately; keep existing calls and order unchanged, just move the relevant
lines into appropriately named test.step closures for each logical phase.
- Line 51: The review says keep nameInput.selectText() as-is and instead wrap
the main scenario actions in test.step() calls to improve readability; update
the test in multi-message.spec.ts so the sequence that manipulates the UI (the
blocks around nameInput.selectText(), the add/rename message flow, typing into
inputs, clicking save, and the verification that persisted YAML matches
expectations) are each wrapped in descriptive test.step("...") blocks, using
Playwright's test.step API to group actions/assertions and leaving
nameInput.selectText() unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 605d9a91-034c-4bec-b8be-4d79ee5a37a6

📥 Commits

Reviewing files that changed from the base of the PR and between 6b7e5f3 and 78bb7a7.

📒 Files selected for processing (30)
  • packages/bruno-app/src/components/RequestPane/WSRequestPane/index.js
  • packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/StyledWrapper.js
  • packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js
  • packages/bruno-app/src/components/RequestPane/WsBody/StyledWrapper.js
  • packages/bruno-app/src/components/RequestPane/WsBody/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-app/src/utils/network/index.js
  • packages/bruno-converters/src/opencollection/items/websocket.ts
  • packages/bruno-electron/src/ipc/network/ws-event-handlers.js
  • packages/bruno-electron/src/utils/collection.js
  • packages/bruno-filestore/src/formats/yml/items/parseWebsocketRequest.ts
  • packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts
  • packages/bruno-lang/v2/src/bruToJson.js
  • packages/bruno-lang/v2/src/jsonToBru.js
  • packages/bruno-lang/v2/tests/bruToJson.spec.js
  • packages/bruno-schema-types/src/requests/websocket.ts
  • tests/websockets/multi-message-bru/fixtures/collection/bruno.json
  • tests/websockets/multi-message-bru/fixtures/collection/collection.bru
  • tests/websockets/multi-message-bru/fixtures/collection/ws-multi-msg.bru
  • tests/websockets/multi-message-bru/fixtures/collection/ws-single-msg.bru
  • tests/websockets/multi-message-bru/init-user-data/preferences.json
  • tests/websockets/multi-message-bru/message-name-style.spec.ts
  • tests/websockets/multi-message-bru/multi-message.spec.ts
  • tests/websockets/multi-message-yml/fixtures/collection/opencollection.yml
  • tests/websockets/multi-message-yml/fixtures/collection/ws-multi-msg.yml
  • tests/websockets/multi-message-yml/fixtures/collection/ws-single-msg.yml
  • tests/websockets/multi-message-yml/init-user-data/preferences.json
  • tests/websockets/multi-message-yml/multi-message.spec.ts

@sid-bruno sid-bruno changed the title Fix/ws message name cursor and overflow feat(ws): multiple messages support in websockets Jun 8, 2026
@sid-bruno
sid-bruno merged commit b9d8bdf into usebruno:main Jun 8, 2026
26 of 30 checks passed
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 2026
* feat: ws multi message

* fix

* fix

* fix

* improve: UX

* improve: new message ui

* fix

* fix

* fix

* fix

* fix

* fix: rename message title

* chore: cleanup

* change: add message color

* fix(websocket): correct cursor and truncate long message names

---------

Co-authored-by: Sid <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants