Repository navigation
feat: ws multi message - #7719
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughRefactors WebSocket message UI into per-message accordions with inline renaming, explicit type↔mode mapping, lazy editor rendering, and per-message Send; filestore parse/stringify now handle single or multi-message formats; adds BRU/YML fixtures and Playwright E2E tests covering multi-message workflows and migration. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant UI as SingleWSMessage (Accordion)
participant Parent as WsBody (Container)
participant Queue as WsQueue
participant Conn as WsConnection
User->>UI: Click "Send" on message
UI->>UI: check isWsConnectionActive(uid)?
alt Connection inactive
UI->>User: show error toast
else Connection active
UI->>Parent: request collection & env context
Parent-->>UI: return context
UI->>Queue: queueWsMessage(payload, context)
Queue->>Conn: send payload
Conn-->>Queue: ack / echo
Queue-->>UI: confirm queued / result
UI->>User: show success toast
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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: 6
🧹 Nitpick comments (3)
tests/websockets/multi-message-bru/multi-message.spec.ts (1)
32-50: Consider wrapping test actions intest.stepfor clearer reports.Per coding guidelines, using
test.stepimproves generated report readability. The test logic is correct, but wrapping distinct actions (click, fill, assert, save, verify file) in steps would enhance debugging.♻️ Example refactor for `test.step` usage
test('add a new message and save', async ({ pageWithUserData: page }) => { - await openRequest(page, COLLECTION_NAME, MULTI_MSG_REQ); - - await page.getByTestId('ws-add-message').click(); - - const nameInput = page.getByTestId(/^ws-message-name-input-/); - await expect(nameInput).toBeVisible(); - - await nameInput.fill('ping message'); - await nameInput.press('Enter'); - - await expect(page.getByTestId(/^ws-message-label-/).filter({ hasText: 'ping message' })).toBeVisible(); - await expect(page.getByTestId(/^ws-message-header-/)).toHaveCount(3); - - await saveRequest(page); - - const bruContent = await readFile(MULTI_MSG_BRU_PATH, 'utf8'); - expect(bruContent).toContain('name: ping message'); + await openRequest(page, COLLECTION_NAME, MULTI_MSG_REQ); + + await test.step('Add new message', async () => { + await page.getByTestId('ws-add-message').click(); + const nameInput = page.getByTestId(/^ws-message-name-input-/); + await expect(nameInput).toBeVisible(); + await nameInput.fill('ping message'); + await nameInput.press('Enter'); + }); + + await test.step('Verify message appears in UI', async () => { + await expect(page.getByTestId(/^ws-message-label-/).filter({ hasText: 'ping message' })).toBeVisible(); + await expect(page.getByTestId(/^ws-message-header-/)).toHaveCount(3); + }); + + await test.step('Verify persistence', async () => { + await saveRequest(page); + const bruContent = await readFile(MULTI_MSG_BRU_PATH, 'utf8'); + expect(bruContent).toContain('name: ping message'); + }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/websockets/multi-message-bru/multi-message.spec.ts` around lines 32 - 50, Wrap the logical parts of the test 'add a new message and save' in test.step blocks to improve report readability: enclose the request opening (openRequest(COLLECTION_NAME, MULTI_MSG_REQ)), the UI interaction (clicking ws-add-message, filling and pressing Enter on the name input and asserting visibility/count on ws-message-label-/ and ws-message-header-/), the save action (saveRequest(page)), and the file verification (readFile(MULTI_MSG_BRU_PATH) and expect toContain) each in their own test.step with a short descriptive name so failures show clear, separate steps in reports.packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js (1)
172-191: Unconventional pattern: usingdispatchto access store state.Line 174 uses
dispatch((_, getState) => getState())which is a non-standard way to access Redux state. This works but is not idiomatic.♻️ Suggested refactor using useSelector
+const collections = useSelector((state) => state.collections.collections); const onSendMessage = async () => { try { - const state = dispatch((_, getState) => getState()); - const col = findCollectionByUid(state.collections.collections, collection.uid); + const col = findCollectionByUid(collections, collection.uid); const environment = findEnvironmentInCollection(col, col?.activeEnvironmentUid); // ... } };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js` around lines 172 - 191, The onSendMessage handler currently uses the non-idiomatic dispatch((_, getState) => getState()) to access Redux state; replace that pattern by selecting the needed slices with useSelector (e.g., get collections.collections and any active collection/environment data) at the top of the component and remove the dispatch-based getState call inside onSendMessage; ensure you import useSelector from react-redux, reference the same helpers (findCollectionByUid, findEnvironmentInCollection) using the selected slices (instead of state from dispatch), and keep the rest of onSendMessage (connection check, queueWsMessage, toasts) unchanged.tests/websockets/multi-message-yml/multi-message.spec.ts (1)
32-204: Consider addingtest.stepblocks in the longer scenarios.Several tests combine many actions/assertions;
test.stepwould improve Playwright report readability and failure localization.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 the current code and only fix it if needed. In `@tests/websockets/multi-message-yml/multi-message.spec.ts` around lines 32 - 204, Several long tests (e.g., the tests titled "backward compatibility: old single-message format loads correctly", "edit message content and verify persistence", "messages with different types persist correctly", and others) perform many actions and assertions without Playwright test.step demarcations; update these tests to wrap logical subsequences (setup via openRequest/COLLECTION_NAME, user interactions like page.getByTestId(...).click()/dblclick()/fill(), saving via saveRequest, and final yml assertions using readFile) in test.step calls so each major action/assertion group is reported separately — for example, add test.step blocks around: opening the request (openRequest), performing UI edits (message add/edit/delete/format change via ws-add-message, ws-message-name-input, ws-delete-msg-1, body-mode-selector), saving (saveRequest), and verifying file contents (readFile assertions); keep existing helper calls (openRequest, saveRequest, buildWebsocketCommonLocators) and locators intact, only wrap those blocks in test.step with descriptive names to improve test reporting and failure localization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js`:
- Around line 78-92: Messages are keyed by index which breaks state when items
are deleted; assign a stable unique id (uid) to each message when created and
use that uid as the React key on SingleWSMessage instead of index, then change
expandedMessages from tracking indices to tracking uids (e.g., a Set of uids).
Update usages: compute isExpanded as expandedMessages.has(message.uid), change
toggleMessage to add/remove message.uid, update isNew/newMessageIndex to compare
uids (or store newMessageUid), and when deleting a message (SingleWSMessage
deletion path) remove its uid from expandedMessages so expansion state stays
consistent. Ensure functions/props referenced (SingleWSMessage,
messagesContainerRef, toggleMessage, handleRun, handleNewMessageRendered,
newMessageIndex) are updated accordingly.
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 61-68: The useEffect that auto-focuses a new message (the hook
using isNew to call setIsEditing, setEditValue and onNewRendered) is missing
dependencies and can capture stale values; update the dependency array to
include displayName and onNewRendered (and any setter refs if non-stable) so the
effect runs when those change, or wrap onNewRendered in useCallback to stabilize
it before adding—modify the effect that references isNew, displayName, and
onNewRendered accordingly.
In `@tests/websockets/multi-message-bru/fixtures/collection/bruno.json`:
- Around line 2-4: The JSON fixture uses 4-space indentation for the keys
"version", "name", and "type"; change those lines to use 2-space indentation to
match repo style for JSON files. Update the indentation for the entire object so
every nested level uses 2 spaces (no tabs), verify the file remains valid JSON,
and run the repo's formatter/linter if available to ensure compliance.
In `@tests/websockets/multi-message-yml/multi-message.spec.ts`:
- Around line 137-145: The test currently asserts that
locators.messages().locator('.text-ellipsis').first() is attached after clicking
page.getByTestId('ws-send-msg-0'), but that element may already exist; instead
record the message count from locators.messages() before calling
page.getByTestId('ws-send-msg-0').click(), perform the click, then assert the
count increased by one and that the newly added message (use
messages().nth(previousCount) or messages().last() and its '.text-ellipsis'
locator) is attached/contains the expected text; update references:
locators.messages(), page.getByTestId('ws-send-msg-0').click() to implement this
stronger behavior-driven check.
- Around line 165-167: The current assertions only check for tokens that exist
regardless of formatting; update the test around editorContent (from
editor.locator('.CodeMirror-code').textContent()) to assert formatting-specific
output instead — for example verify a newline plus expected indentation before a
key (e.g. a substring or regex like '\n "name":' or '\n "bruno"' to ensure
prettify inserted newlines/indentation). Replace or augment the existing
expect(editorContent).toContain('"name"') / toContain('"bruno"') with a check
that ensures the correct newline/indentation pattern is present so the test
fails if prettify no longer formats output.
- Around line 28-30: The afterAll hook is using the test-scoped fixture
pageWithUserData (fixture name pageWithUserData) which is not valid in a
worker-level hook (test.afterAll); update the hook to avoid the lifecycle
mismatch by either: 1) switching the hook to test.afterEach and keep using
pageWithUserData so closeAllCollections(page) runs per-test, or 2) change the
hook parameter to the worker-scoped page fixture (use page instead of
pageWithUserData) so test.afterAll receives a worker-scoped fixture, or 3)
convert the pageWithUserData fixture to worker scope in its definition if its
state must persist across the worker; pick one approach and update the
test.afterAll signature or fixture scope accordingly, ensuring
closeAllCollections is called with the correct fixture variable.
---
Nitpick comments:
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 172-191: The onSendMessage handler currently uses the
non-idiomatic dispatch((_, getState) => getState()) to access Redux state;
replace that pattern by selecting the needed slices with useSelector (e.g., get
collections.collections and any active collection/environment data) at the top
of the component and remove the dispatch-based getState call inside
onSendMessage; ensure you import useSelector from react-redux, reference the
same helpers (findCollectionByUid, findEnvironmentInCollection) using the
selected slices (instead of state from dispatch), and keep the rest of
onSendMessage (connection check, queueWsMessage, toasts) unchanged.
In `@tests/websockets/multi-message-bru/multi-message.spec.ts`:
- Around line 32-50: Wrap the logical parts of the test 'add a new message and
save' in test.step blocks to improve report readability: enclose the request
opening (openRequest(COLLECTION_NAME, MULTI_MSG_REQ)), the UI interaction
(clicking ws-add-message, filling and pressing Enter on the name input and
asserting visibility/count on ws-message-label-/ and ws-message-header-/), the
save action (saveRequest(page)), and the file verification
(readFile(MULTI_MSG_BRU_PATH) and expect toContain) each in their own test.step
with a short descriptive name so failures show clear, separate steps in reports.
In `@tests/websockets/multi-message-yml/multi-message.spec.ts`:
- Around line 32-204: Several long tests (e.g., the tests titled "backward
compatibility: old single-message format loads correctly", "edit message content
and verify persistence", "messages with different types persist correctly", and
others) perform many actions and assertions without Playwright test.step
demarcations; update these tests to wrap logical subsequences (setup via
openRequest/COLLECTION_NAME, user interactions like
page.getByTestId(...).click()/dblclick()/fill(), saving via saveRequest, and
final yml assertions using readFile) in test.step calls so each major
action/assertion group is reported separately — for example, add test.step
blocks around: opening the request (openRequest), performing UI edits (message
add/edit/delete/format change via ws-add-message, ws-message-name-input,
ws-delete-msg-1, body-mode-selector), saving (saveRequest), and verifying file
contents (readFile assertions); keep existing helper calls (openRequest,
saveRequest, buildWebsocketCommonLocators) and locators intact, only wrap those
blocks in test.step with descriptive names to improve test reporting and failure
localization.
🪄 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: c284dbfc-9ab9-4d3a-b8c7-4b146eb29b67
📒 Files selected for processing (17)
packages/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-filestore/src/formats/yml/items/parseWebsocketRequest.tspackages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.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/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
19335be to
7800212
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (4)
tests/websockets/multi-message-yml/multi-message.spec.ts (3)
28-30:⚠️ Potential issue | 🔴 Critical
pageWithUserDatashould not be injected intoafterAll().
afterAllis a worker hook, butpageWithUserDatais a test-scoped fixture in this repo. That lifecycle mismatch can break teardown. Move this cleanup toafterEach, or make the fixture worker-scoped before using it here.#!/bin/bash set -euo pipefail echo '--- afterAll usage ---' sed -n '23,31p' tests/websockets/multi-message-yml/multi-message.spec.ts echo echo '--- fixture definition/scope ---' rg -n -C3 'pageWithUserData|scope:' playwright/index.tsExpected result:
afterAllconsumespageWithUserData, while the fixture definition shows no worker scope declaration for that fixture.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/websockets/multi-message-yml/multi-message.spec.ts` around lines 28 - 30, The test uses the test-scoped fixture pageWithUserData inside a worker hook afterAll which causes lifecycle mismatch; change the teardown to run in an afterEach hook instead of afterAll (move the call to closeAllCollections(page) from test.afterAll to test.afterEach and use the same pageWithUserData parameter), or alternatively make the pageWithUserData fixture worker-scoped in the fixture definition if you intend worker-level teardown (adjust the fixture in playwright/index.ts to scope: 'worker'); reference pageWithUserData, test.afterAll, test.afterEach, and closeAllCollections to locate the code to modify.
165-167:⚠️ Potential issue | 🟡 MinorThese prettify checks do not currently verify prettification.
The asserted tokens are present in both minified and formatted JSON, so this still passes when formatting regresses. Assert a formatting-specific signal instead, such as a newline/indentation pattern.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/websockets/multi-message-yml/multi-message.spec.ts` around lines 165 - 167, The current assertions on editorContent (from editor.locator('.CodeMirror-code').textContent()) only check token presence and not formatting; update the test in multi-message.spec.ts to assert a formatting-specific signal instead — e.g., test for a newline/indentation pattern such as a newline followed by two spaces before the "name" key (use a regex like one that checks for "\n \"name\"" or a more general /\n\s+"name"\s*:/) to ensure prettification actually occurred; replace or augment the expect(editorContent).toContain('"name"')/toContain('"bruno"') checks with this indentation/newline pattern assertion.
142-145:⚠️ Potential issue | 🟡 MinorThis send assertion can pass without proving a new message was emitted.
The first
.text-ellipsisnode may already exist before the click, sotoBeAttached()does not validate the send path. Capture the message count before sending and assert it increments afterward.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/websockets/multi-message-yml/multi-message.spec.ts` around lines 142 - 145, The current assertion uses await expect(locators.messages().locator('.text-ellipsis').first()).toBeAttached() which can pass if that node existed before clicking; instead capture the pre-send message count via locators.messages().locator('.text-ellipsis').count() (or use locators.messages() count) before calling await page.getByTestId('ws-send-msg-0').click(), then click and assert the post-send count is previousCount + 1 (e.g., with expect(await ...count()).toBe(previousCount + 1) or Playwright's toHaveCount) to prove a new message was emitted.packages/bruno-app/src/components/RequestPane/WsBody/index.js (1)
15-29:⚠️ Potential issue | 🟠 MajorIndex-based identity will corrupt accordion/edit state after a delete.
The list is still keyed by
index, andexpandedMessages/newMessageIndexare also tracked byindex. Once a message is removed, later items shift left, so React reuses the wrongSingleWSMessageinstance and the expanded/new state can attach to a different message. Please switch message identity to a stable per-message id and track UI state by that id instead.#!/bin/bash set -euo pipefail echo '--- WSBody identity/state ---' sed -n '12,95p' packages/bruno-app/src/components/RequestPane/WsBody/index.js echo echo '--- SingleWSMessage delete path ---' sed -n '160,175p' packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.jsExpected result: the output shows
key={index}, index-basedexpandedMessages/newMessageIndex, and deletion viasplice(index, 1), which together confirm the state/identity drift risk.Also applies to: 31-46, 79-90
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js` around lines 15 - 29, The current accordion/edit state uses array indices (expandedMessages Set of index, newMessageIndex, toggleMessage(index)) and the list/key={index} plus deletion via splice(index, 1) causes state/identity drift; change to stable per-message IDs: use each message's unique id (e.g., message.id) as the React key for SingleWSMessage, convert expandedMessages and newMessageIndex to store ids (e.g., Set of ids and newMessageId), update toggleMessage to accept an id and toggle that id, and update add/delete logic (stop using splice(index,1) — remove by id) and any places that set newMessageIndex to use the message.id so UI state remains tied to the message identity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 241-265: The accordion header currently uses a div with
onClick={onToggle} (className "accordion-header") which is not
keyboard-accessible; update the element to be keyboard-focusable and trigger
onToggle on Enter/Space—either replace the div with a <button> (preserving
data-testid={`ws-message-header-${index}`} and onClick={onToggle}) or keep the
div and add role="button", tabIndex={0}, and an onKeyDown handler that calls
onToggle when event.key is "Enter" or " " (Space); ensure the onKeyDown also
prevents default where appropriate and that existing click handlers and
stopPropagation behavior for nested elements (like name input and
.accordion-actions) remain unchanged so editing still works.
In `@packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts`:
- Around line 50-56: The lone-unnamed-message branch in
stringifyWebsocketRequest.ts currently always writes the legacy flat
websocket.message shape even for empty content, but parseWebsocketRequest.ts
only restores that flat form when message.data.trim().length > 0, causing empty
single messages to vanish on reload; fix by only serializing the flat
websocket.message for a single unnamed message when its content is non-empty
(e.g., check msg.content.trim().length > 0 before assigning websocket.message),
or alternatively update parseWebsocketRequest.ts to accept empty message.data
values—prefer changing stringifyWebsocketRequest.ts to guard with
msg.content.trim().length > 0 to keep behavior consistent with the parser.
---
Duplicate comments:
In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js`:
- Around line 15-29: The current accordion/edit state uses array indices
(expandedMessages Set of index, newMessageIndex, toggleMessage(index)) and the
list/key={index} plus deletion via splice(index, 1) causes state/identity drift;
change to stable per-message IDs: use each message's unique id (e.g.,
message.id) as the React key for SingleWSMessage, convert expandedMessages and
newMessageIndex to store ids (e.g., Set of ids and newMessageId), update
toggleMessage to accept an id and toggle that id, and update add/delete logic
(stop using splice(index,1) — remove by id) and any places that set
newMessageIndex to use the message.id so UI state remains tied to the message
identity.
In `@tests/websockets/multi-message-yml/multi-message.spec.ts`:
- Around line 28-30: The test uses the test-scoped fixture pageWithUserData
inside a worker hook afterAll which causes lifecycle mismatch; change the
teardown to run in an afterEach hook instead of afterAll (move the call to
closeAllCollections(page) from test.afterAll to test.afterEach and use the same
pageWithUserData parameter), or alternatively make the pageWithUserData fixture
worker-scoped in the fixture definition if you intend worker-level teardown
(adjust the fixture in playwright/index.ts to scope: 'worker'); reference
pageWithUserData, test.afterAll, test.afterEach, and closeAllCollections to
locate the code to modify.
- Around line 165-167: The current assertions on editorContent (from
editor.locator('.CodeMirror-code').textContent()) only check token presence and
not formatting; update the test in multi-message.spec.ts to assert a
formatting-specific signal instead — e.g., test for a newline/indentation
pattern such as a newline followed by two spaces before the "name" key (use a
regex like one that checks for "\n \"name\"" or a more general
/\n\s+"name"\s*:/) to ensure prettification actually occurred; replace or
augment the expect(editorContent).toContain('"name"')/toContain('"bruno"')
checks with this indentation/newline pattern assertion.
- Around line 142-145: The current assertion uses await
expect(locators.messages().locator('.text-ellipsis').first()).toBeAttached()
which can pass if that node existed before clicking; instead capture the
pre-send message count via locators.messages().locator('.text-ellipsis').count()
(or use locators.messages() count) before calling await
page.getByTestId('ws-send-msg-0').click(), then click and assert the post-send
count is previousCount + 1 (e.g., with expect(await
...count()).toBe(previousCount + 1) or Playwright's toHaveCount) to prove a new
message was emitted.
🪄 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: 3eebd382-71e9-4527-bd45-c3e82ffb147e
📒 Files selected for processing (17)
packages/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-filestore/src/formats/yml/items/parseWebsocketRequest.tspackages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.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/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
✅ Files skipped from review due to trivial changes (9)
- tests/websockets/multi-message-bru/fixtures/collection/bruno.json
- tests/websockets/multi-message-yml/init-user-data/preferences.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/init-user-data/preferences.json
- tests/websockets/multi-message-yml/fixtures/collection/ws-single-msg.yml
- tests/websockets/multi-message-yml/fixtures/collection/opencollection.yml
- tests/websockets/multi-message-bru/fixtures/collection/ws-single-msg.bru
- tests/websockets/multi-message-bru/multi-message.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/websockets/multi-message-yml/fixtures/collection/ws-multi-msg.yml
- packages/bruno-filestore/src/formats/yml/items/parseWebsocketRequest.ts
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
tests/websockets/multi-message-yml/multi-message.spec.ts (1)
28-30:⚠️ Potential issue | 🔴 Critical
pageWithUserDatashould not be injected intotest.afterAll().Line 28 uses a test-scoped fixture in a worker-level hook. That lifecycle mismatch can make the cleanup hook invalid before
closeAllCollections()ever runs. Use a worker-scoped fixture there, or move this cleanup intoafterEach.#!/bin/bash set -euo pipefail echo "afterAll hook in the spec:" sed -n '24,32p' tests/websockets/multi-message-yml/multi-message.spec.ts echo echo "fixture declaration and scope info:" rg -n -C4 --type=ts '\bpageWithUserData\b|scope:' playwright/index.ts🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/websockets/multi-message-yml/multi-message.spec.ts` around lines 28 - 30, The afterAll hook uses the test-scoped fixture pageWithUserData which causes a lifecycle mismatch; change the cleanup to use a worker-scoped fixture or move it into an afterEach hook so it runs with a valid page instance. Specifically, remove pageWithUserData from test.afterAll(...) and either (a) replace it with a worker-scoped fixture (e.g., a workerPage or a worker-level browser context) and call closeAllCollections(workerPage) inside test.afterAll, or (b) move the await closeAllCollections(page) call into test.afterEach(async ({ pageWithUserData: page }) => ...) so closeAllCollections runs per-test with the test-scoped page. Ensure references to test.afterAll, pageWithUserData, and closeAllCollections are updated accordingly.packages/bruno-app/src/components/RequestPane/WsBody/index.js (1)
10-17:⚠️ Potential issue | 🟠 MajorIndex-derived UIDs will still shift after delete/reorder.
ensureMessageUids()still keys identity off the current array position. If the user deletes an earlier message, the next message inherits that row's UID, so React will reuse the wrongSingleWSMessageinstance and expansion/editing state can jump to a different message. Please persist a stable UID with each message and drivekey,expandedUids, andnewMessageUidfrom that value instead of the index.Also applies to: 25-49, 53-68, 100-114
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js` around lines 10 - 17, ensureMessageUids currently derives stable IDs from array indices which break when messages are deleted/reordered; instead attach and persist a uid property on each message object and use that uid everywhere for identity. Update ensureMessageUids to read or assign message.uid (not index) and return a map keyed by message.uid; refactor any code that uses array index for React keys, expandedUids, and newMessageUid (including places that render SingleWSMessage and manage expansion/editing state) to use message.uid consistently so removal/reorder no longer reuses DOM instances. Ensure creation of new messages assigns a uuid() to message.uid and migrate any uidMapRef logic to map by uid.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/websockets/multi-message-yml/multi-message.spec.ts`:
- Around line 57-61: The test is re-opening requests with openRequest() which
just activates existing in-memory tabs (addTab deduplicates by uid), so it never
verifies disk persistence; change the test to force a full reload or close the
tab first: call the tab-close helper (or use page.reload/newPage) to close the
collection/request tab before calling openRequest(), or open the request in a
fresh browser context/page to ensure the YML is read from disk, then assert
ws-message-header count; update both occurrences (around the openRequest calls
and the other block at 124-129) to close/reload before re-opening.
---
Duplicate comments:
In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js`:
- Around line 10-17: ensureMessageUids currently derives stable IDs from array
indices which break when messages are deleted/reordered; instead attach and
persist a uid property on each message object and use that uid everywhere for
identity. Update ensureMessageUids to read or assign message.uid (not index) and
return a map keyed by message.uid; refactor any code that uses array index for
React keys, expandedUids, and newMessageUid (including places that render
SingleWSMessage and manage expansion/editing state) to use message.uid
consistently so removal/reorder no longer reuses DOM instances. Ensure creation
of new messages assigns a uuid() to message.uid and migrate any uidMapRef logic
to map by uid.
In `@tests/websockets/multi-message-yml/multi-message.spec.ts`:
- Around line 28-30: The afterAll hook uses the test-scoped fixture
pageWithUserData which causes a lifecycle mismatch; change the cleanup to use a
worker-scoped fixture or move it into an afterEach hook so it runs with a valid
page instance. Specifically, remove pageWithUserData from test.afterAll(...) and
either (a) replace it with a worker-scoped fixture (e.g., a workerPage or a
worker-level browser context) and call closeAllCollections(workerPage) inside
test.afterAll, or (b) move the await closeAllCollections(page) call into
test.afterEach(async ({ pageWithUserData: page }) => ...) so closeAllCollections
runs per-test with the test-scoped page. Ensure references to test.afterAll,
pageWithUserData, and closeAllCollections are updated accordingly.
🪄 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: d3811015-10d9-473d-8444-b2bbe40e6925
📒 Files selected for processing (4)
packages/bruno-app/src/components/RequestPane/WsBody/index.jstests/websockets/multi-message-bru/fixtures/collection/bruno.jsontests/websockets/multi-message-bru/multi-message.spec.tstests/websockets/multi-message-yml/multi-message.spec.ts
✅ Files skipped from review due to trivial changes (2)
- tests/websockets/multi-message-bru/fixtures/collection/bruno.json
- tests/websockets/multi-message-bru/multi-message.spec.ts
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js (1)
62-68:⚠️ Potential issue | 🟡 MinorInclude all referenced values in the
isNeweffect dependencies.Line 62-Line 68 reads
displayNameandonNewRendered, but the dependency list only includesisNew. This can capture stale values.Proposed fix
useEffect(() => { if (isNew) { setIsEditing(true); setEditValue(displayName); onNewRendered(); } - }, [isNew]); + }, [isNew, displayName, onNewRendered]);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js` around lines 62 - 68, The effect in SingleWSMessage that runs when an item is new references displayName and onNewRendered but only lists isNew in its dependency array; update the useEffect dependencies to include displayName and onNewRendered so the effect won't capture stale values (i.e., change the dependency array from [isNew] to [isNew, displayName, onNewRendered]); if onNewRendered is not stable, ensure it is memoized (e.g., with useCallback) where it's defined.
🧹 Nitpick comments (2)
packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts (1)
48-52: Consider renaming for clarity (optional nit).The variable
hasCustomNameis evaluated only whenmessages.length === 1, so the check on line 48 bakes in that condition. This makes the later guard on line 52 a bit redundant. A more descriptive name likesingleMsgHasCustomNamewould make the intent immediately obvious.- const hasCustomName = messages.length === 1 && messages[0].name && messages[0].name.trim().length > 0; + const singleMsgHasCustomName = messages.length === 1 && messages[0].name && messages[0].name.trim().length > 0; const hasContent = messages.length === 1 && (messages[0].content || '').trim().length > 0; - if (messages.length === 1 && !hasCustomName && hasContent) { + if (messages.length === 1 && !singleMsgHasCustomName && hasContent) {Totally optional—current code is functional and readable.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts` around lines 48 - 52, Rename the boolean that tests the single-message name to something that encodes the single-message context (e.g., change hasCustomName to singleMsgHasCustomName) and likewise rename hasContent to singleMsgHasContent; update their declarations and subsequent usage in the guard inside stringifyWebsocketRequest so the intent is explicit (replace references to hasCustomName and hasContent with the new names in the conditional that checks messages.length === 1).packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js (1)
106-123: Clear the pending single-click timer on unmount.If the component unmounts during the 250ms window, the timeout can still fire and call a stale
onToggle.Recommended refactor
const clickTimerRef = useRef(null); + + useEffect(() => { + return () => { + if (clickTimerRef.current) { + clearTimeout(clickTimerRef.current); + clickTimerRef.current = null; + } + }; + }, []);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js` around lines 106 - 123, The clickTimerRef timeout can fire after unmount causing a stale onToggle call; add a cleanup effect that clears clickTimerRef.current if present on unmount. Specifically, in the component add a useEffect with no dependencies that returns a cleanup function which checks clickTimerRef.current and calls clearTimeout(clickTimerRef.current) and sets clickTimerRef.current = null; keep handleNameClick, clickTimerRef and related logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 247-252: The parent div's onKeyDown (which calls onToggle) is
firing when the nested input's handleNameKeyDown handles Enter/Space; fix by
preventing the event from bubbling: update the input's keydown handler
(handleNameKeyDown) to call e.stopPropagation() (and keep e.preventDefault() as
needed) when it handles Enter/Space, or alternatively add a guard at the parent
onKeyDown to ignore events from inputs (e.g., return early if e.target.tagName
=== 'INPUT' or e.target.isContentEditable); reference handleNameKeyDown (input)
and the parent onKeyDown/onToggle when making the change.
---
Duplicate comments:
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 62-68: The effect in SingleWSMessage that runs when an item is new
references displayName and onNewRendered but only lists isNew in its dependency
array; update the useEffect dependencies to include displayName and
onNewRendered so the effect won't capture stale values (i.e., change the
dependency array from [isNew] to [isNew, displayName, onNewRendered]); if
onNewRendered is not stable, ensure it is memoized (e.g., with useCallback)
where it's defined.
---
Nitpick comments:
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 106-123: The clickTimerRef timeout can fire after unmount causing
a stale onToggle call; add a cleanup effect that clears clickTimerRef.current if
present on unmount. Specifically, in the component add a useEffect with no
dependencies that returns a cleanup function which checks clickTimerRef.current
and calls clearTimeout(clickTimerRef.current) and sets clickTimerRef.current =
null; keep handleNameClick, clickTimerRef and related logic unchanged.
In `@packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts`:
- Around line 48-52: Rename the boolean that tests the single-message name to
something that encodes the single-message context (e.g., change hasCustomName to
singleMsgHasCustomName) and likewise rename hasContent to singleMsgHasContent;
update their declarations and subsequent usage in the guard inside
stringifyWebsocketRequest so the intent is explicit (replace references to
hasCustomName and hasContent with the new names in the conditional that checks
messages.length === 1).
🪄 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: 358c511b-ea7e-425e-a7e0-fb645b6d0993
📒 Files selected for processing (2)
packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.jspackages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js`:
- Around line 93-104: The blur handler is persisting a stale editValue when
Escape or Enter unmounts the input; update handleNameKeyDown to mark that the
keyboard action handled the commit/cancel (e.g., set an ignoreBlurRef flag)
before calling saveName or setIsEditing, then change handleNameBlur to check
that flag and return early if set (and reset the flag after), ensuring keyboard
Save/Escape paths do not also trigger blur persistence and preventing double
dispatch; reference handleNameKeyDown, handleNameBlur, saveName, setEditValue,
setIsEditing, editValue, and displayName to locate the change.
🪄 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: 4e8dfcd9-d89c-4412-bf74-cc34ff18883c
📒 Files selected for processing (1)
packages/bruno-app/src/components/RequestPane/WsBody/SingleWSMessage/index.js
a695c7a to
8c3987c
Compare
|
LGTM , waiting on tests |
This reverts commit a305b41.
* feat: implement proxy-aware API fetching using axios instance (usebruno#7767) * fix(cli): skip headers with empty name when building request (usebruno#7869) * Revert "feat: ws multi message (usebruno#7719)" (usebruno#7921) This reverts commit a305b41. * fix: remove dragbar z-index that was bleeding through modals (usebruno#7924) * feat: ui state snapshots (usebruno#7794) * feat(snapshot): add session snapshot persistence and restoration - Add snapshot middleware to persist UI state (tabs, workspaces, environments) - Add SnapshotManager service in electron for atomic snapshot storage - Add accessor-based tab serialization using pathname for reliable restoration - Add loading states for tabs while collections are mounting - Add hydrateTabs to restore tabs from snapshots on app load - Add devTools state persistence (console open/height/tab) * fix(snapshot): preserve unloaded collections and fix async serialization Make serializeSnapshot async to fetch existing snapshot before saving, ensuring collections not currently loaded in Redux are preserved. Fix activeTab serialization to pass collection object instead of just UID. * refactor(snapshot): rewrite storage to map-based schema with granular IPC Replace array-based snapshot storage with key-value maps keyed by pathname for O(1) lookups. Separate tabs into their own top-level map, decoupled from collections. - Rewrite SnapshotManager with map-based schema and granular read/write methods (getWorkspace, getTabs, setCollection, removeWorkspace, etc.) - Add 12 granular IPC handlers (renderer:snapshot:*) replacing 4 coarse ones - Update middleware serialization to produce maps; remove activeCollectionUidCache in favor of lastActiveCollectionPathname on workspace objects - Fix mountCollection passing collectionUid instead of collection to restoreTabs - Preserve non-active workspace state from existing snapshot on save * wip * refactor: allow migration of old snapshot * refactor: trim down redundancy * fix: for workspace state * feat: fix for finalised schema * fix: schema cleanup * chore: simplify * chore: wait on hydration to finish * chore: snapshot changes to schema * chore: fix typo * fix: switch schema for saving and restoring extras * chore: correctness changes * chore: add active in the schema check * chore: fix lint * chore: comments * chore: make writes async * fix: sorting and cross workspace shared collection fixes * chore: add version * fix: wait on hydration * chore: fix backward compat for ui-snapshots * chore: dead code removal * Fix optional chaining in snapshot lookup --------- Co-authored-by: Chirag Chandrashekhar <[email protected]> * fix: scrollbar restoration (usebruno#7926) * fix: restore scrollbar * chore: remove comments --------- Co-authored-by: shubh-bruno <[email protected]> * fix: message in ConnectGitRemote and RemoveGitRemote (usebruno#7929) * fix: allow empty header names in CLI and gRPC request preparation (usebruno#7925) * refactor: remove idx from HeaderList, extend ReadOnlyPropertyList, add positional method translations (usebruno#7917) * refactor: remove 'idx' method from headerList and update related tests - Eliminated the 'idx' method from both req.headerList and res.headerList to streamline header management. - Updated associated tests and documentation to reflect the removal, ensuring clarity in the API usage and maintaining consistency across the header management system. * refactor: block unimplemented HeaderList methods with error messages - Added error handling for unimplemented methods in HeaderList, including idx, add, upsert, remove, each, prepend, insert, and insertAfter. - Each method now throws a descriptive error indicating the appropriate alternative methods to use, enhancing clarity in the API and guiding users towards correct usage. * refactor: update error message in idx() method of HeaderList for clarity - Modified the error message in the idx() method to guide users towards using all()[index] or get(name) instead of the unsupported idx() method, enhancing the clarity of the API documentation. * refactor: update HeaderList to extend ReadOnlyPropertyList and remove unimplemented methods - Changed HeaderList to extend ReadOnlyPropertyList instead of PropertyList, streamlining its functionality. - Removed unimplemented methods (prepend, insert, insertAfter) from HeaderList, clarifying the API and guiding users towards using supported methods. - Updated related tests to reflect these changes, ensuring consistency and accuracy in header management. * test: add translations for pm.request.headers methods in request tests - Introduced new tests to validate the translation of pm.request.headers methods (prepend, insert, insertAfter) to their corresponding req.headerList.append method. - Enhanced existing tests to ensure accurate conversion and functionality of header management in the Bruno converters. * feat: enhance header translation methods for pm.request.headers - Added translations for additional pm.request.headers methods (get, has, one, all, count, indexOf, find, filter, each, map, reduce, toObject, clear) to their corresponding req.headerList methods. - Updated tests to validate the new translations and ensure accurate header management functionality in the Bruno converters. --------- Co-authored-by: Pragadesh-45 <[email protected]> Co-authored-by: Sid <[email protected]> Co-authored-by: gopu-bruno <[email protected]> Co-authored-by: Chirag Chandrashekhar <[email protected]> Co-authored-by: shubh-bruno <[email protected]> Co-authored-by: shubh-bruno <[email protected]> Co-authored-by: naman-bruno <[email protected]> Co-authored-by: sanish chirayath <[email protected]>
Description
JIRA
Enable users to add multiple WebSocket messages within a single request. Messages are displayed as collapsible accordions with individual type selection, send, rename, and delete actions. Supports both BRU and YML file formats.
Contribution Checklist:
Screen.Recording.2026-04-09.at.10.19.35.AM.mov
Summary by CodeRabbit
New Features
Compatibility
Tests