Repository navigation
Conversation
WalkthroughThis 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. ChangesWebSocket Multi-Message Feature Implementation
Sequence DiagramsequenceDiagram
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)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🧹 Nitpick comments (2)
tests/websockets/multi-message-yml/multi-message.spec.ts (2)
32-294: ⚡ Quick winConsider wrapping logical test phases in
test.stepfor clearer reports.Using
test.stepimproves 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.stepas 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: removeselectText()concern; addtest.stepfor readability
nameInput.selectText()is part of the standard PlaywrightLocatorAPI, 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
📒 Files selected for processing (30)
packages/bruno-app/src/components/RequestPane/WSRequestPane/index.jspackages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/StyledWrapper.jspackages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.jspackages/bruno-app/src/components/RequestPane/WsBody/StyledWrapper.jspackages/bruno-app/src/components/RequestPane/WsBody/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/utils/collections/index.jspackages/bruno-app/src/utils/network/index.jspackages/bruno-converters/src/opencollection/items/websocket.tspackages/bruno-electron/src/ipc/network/ws-event-handlers.jspackages/bruno-electron/src/utils/collection.jspackages/bruno-filestore/src/formats/yml/items/parseWebsocketRequest.tspackages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.tspackages/bruno-lang/v2/src/bruToJson.jspackages/bruno-lang/v2/src/jsonToBru.jspackages/bruno-lang/v2/tests/bruToJson.spec.jspackages/bruno-schema-types/src/requests/websocket.tstests/websockets/multi-message-bru/fixtures/collection/bruno.jsontests/websockets/multi-message-bru/fixtures/collection/collection.brutests/websockets/multi-message-bru/fixtures/collection/ws-multi-msg.brutests/websockets/multi-message-bru/fixtures/collection/ws-single-msg.brutests/websockets/multi-message-bru/init-user-data/preferences.jsontests/websockets/multi-message-bru/message-name-style.spec.tstests/websockets/multi-message-bru/multi-message.spec.tstests/websockets/multi-message-yml/fixtures/collection/opencollection.ymltests/websockets/multi-message-yml/fixtures/collection/ws-multi-msg.ymltests/websockets/multi-message-yml/fixtures/collection/ws-single-msg.ymltests/websockets/multi-message-yml/init-user-data/preferences.jsontests/websockets/multi-message-yml/multi-message.spec.ts
* 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]>
Description
BRU-3293
BRU-3295
BRU-2483
BRU-2932
Contribution Checklist:
Screen.Recording.2026-05-27.at.1.58.22.PM.mov