Repository navigation
feat(app): add request level app - #8294
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughAdds a per-request "App mode" that embeds user JavaScript inside an Electron ChangesApp Mode: Per-Request Webview with ctx API
Sequence Diagram(s)sequenceDiagram
rect rgba(100, 149, 237, 0.5)
Note over AppView,Redux: App Mode Activation
AppView->>Redux: dispatch(toggleAppMode, enabled=true)
Redux-->>RequestTabPanel: item.app.enabled = true
RequestTabPanel->>AppView: render AppView(item, collection, code)
end
rect rgba(144, 238, 144, 0.5)
Note over AppView,Guest: Webview Bootstrap
AppView->>Webview: set src (data: URL with ctx bootstrap + user code)
Webview-->>AppView: dom-ready event
AppView->>Guest: pushMessage(state, theme, response, results, variables)
Guest-->>AppView: sentinel console-message(ready)
end
rect rgba(255, 165, 0, 0.5)
Note over Guest,sendNetworkRequest: sendRequest Flow
Guest->>AppView: sentinel console-message(sendRequest, overrides)
AppView->>Redux: dispatch(requestSentEvent)
AppView->>sendNetworkRequest: execute(request, mergedVariables)
sendNetworkRequest-->>AppView: response / error
AppView->>Redux: dispatch(responseReceived)
AppView->>Guest: pushMessage(responseUpdate)
end
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
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)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.44.0)packages/bruno-app/src/providers/ReduxStore/slices/collections/index.jsThanks 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js (1)
2747-2764:⚠️ Potential issue | 🟠 Major | ⚡ Quick winSync
appwhen reusing an existing item in add-file rename flow.Line 2747-2764 updates
currentItemfromfile.databut skipscurrentItem.app, while the new-item path at Line 2774 sets it. In add-before-unlink rename ordering, this leaves stale app state in memory.Suggested minimal fix
if (currentItem) { currentItem.name = file.data.name; currentItem.type = file.data.type; currentItem.seq = file.data.seq; currentItem.tags = file.data.tags; currentItem.request = mergeRequestWithPreservedUids(currentItem.request, file.data.request); + const currentEnabled = currentItem.draft?.app?.enabled ?? currentItem.app?.enabled ?? false; + if (file.data.app) { + currentItem.app = { ...file.data.app, enabled: currentEnabled }; + } else if (currentEnabled) { + currentItem.app = { code: null, enabled: true }; + } else { + currentItem.app = null; + } currentItem.filename = file.meta.name; currentItem.pathname = file.meta.pathname; currentItem.raw = file.data.raw; currentItem.settings = file.data.settings; currentItem.examples = file.data.examples;Also applies to: 2774-2774
🤖 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 `@packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js` around lines 2747 - 2764, The currentItem update block starting at line 2747 is missing the assignment of the app property from file.data.app, while the new-item path at line 2774 correctly includes it. This causes stale app state to remain in memory. Add the assignment currentItem.app = file.data.app to the currentItem update block alongside the other property assignments like currentItem.name, currentItem.type, and currentItem.request to ensure the app property is properly synced when reusing an existing item.
🧹 Nitpick comments (3)
tests/apps/apps-ctx-api.spec.ts (1)
179-183: ⚡ Quick winReplace the fixed 700ms sleep with a state-driven wait.
Line 181 uses a magic timeout for Redux/AppView propagation; this is brittle in CI. Poll the guest-visible state (
ctx.variables.q) before sending.Suggested change
- // allow the redux update + AppView re-render to settle before the send reads runtimeVariables - await page.waitForTimeout(700); + // Wait for runtime variable propagation into guest ctx before sending. + await expect.poll( + () => guestEval(electronApp, "window.ctx?.variables?.q"), + { timeout: 15000 } + ).toBe('viaSet'); await guestEval(electronApp, 'void window.__send()'); await expect.poll(() => guestResult(electronApp), { timeout: 15000 }).toBe('viaSet');🤖 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/apps/apps-ctx-api.spec.ts` around lines 179 - 183, Replace the hardcoded 700ms timeout using `page.waitForTimeout(700)` with a state-driven polling approach that checks the guest-visible state before sending. Use the `expect.poll()` pattern (already used for the final assertion) to poll `ctx.variables.q` and wait until it equals 'viaSet' before calling `window.__send()`, which ensures the Redux/AppView updates have propagated in a reliable way rather than relying on a fixed delay that may be too short or too long in different CI environments.Source: Coding guidelines
packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js (1)
617-653: ⚡ Quick winExpose view-mode buttons as an accessible toggle group.
The new icon-only buttons should include
aria-labelandaria-pressedso active mode is announced reliably.Proposed fix
<button type="button" + aria-label="Request view" + aria-pressed={!appEnabled && !collection.fileMode} data-testid="view-mode-request" @@ <button type="button" + aria-label="App view" + aria-pressed={appEnabled && !collection.fileMode} data-testid="view-mode-app" @@ <button type="button" + aria-label="File view" + aria-pressed={collection.fileMode} data-testid="view-mode-file"🤖 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 `@packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js` around lines 617 - 653, Add accessibility attributes to the three view-mode toggle buttons (view-mode-request, view-mode-app, and view-mode-file). For each button, add an aria-label attribute with a descriptive name for the mode (Request, App, and File respectively) and add an aria-pressed attribute that reflects the button's active state. For the Request button, aria-pressed should match the condition when it is active (when appEnabled is false and collection.fileMode is false), for the App button it should match when appEnabled is true and collection.fileMode is false, and for the File button it should match when collection.fileMode is true.packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts (1)
11-11: Consider using a type-only import forOpenCollectionApp.
OpenCollectionAppis used only as a type annotation (line 217) and is not referenced at runtime. Usingimport typeclarifies intent and is a best practice.Suggested change
-import { toOpenCollectionApp, OpenCollectionApp } from '../common/app'; +import { toOpenCollectionApp } from '../common/app'; +import type { OpenCollectionApp } from '../common/app';🤖 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 `@packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts` at line 11, The import statement for OpenCollectionApp mixes runtime imports with type-only imports. Since OpenCollectionApp is used only as a type annotation and not at runtime, refactor the import statement to use import type syntax for OpenCollectionApp while keeping the toOpenCollectionApp function as a regular import from '../common/app'. This clarifies that OpenCollectionApp is purely a type import and improves code clarity.
🤖 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/AppView/index.js`:
- Around line 258-279: The `sendNetworkRequest` function can resolve with an
error object rather than throwing an exception, but the current code does not
check for this error condition before dispatching the success state. After the
`const result = await sendNetworkRequest(...)` line, add a check to determine if
the result object contains an error payload. If an error is detected in the
result, dispatch an appropriate error action or handle it in the catch block
path instead of proceeding with the `responseReceived` dispatch. This ensures
that error responses from `sendNetworkRequest` are properly handled according to
the host/guest error contract rather than being treated as successful responses.
In `@packages/bruno-app/src/components/AppView/StyledWrapper.js`:
- Around line 34-42: Replace the hardcoded background color `#ffffff` in the
`.app-webview-container` styled component with a theme token by using the theme
prop. Access the appropriate background color from the theme object (similar to
how `props.theme.border.border1` is being used for the border property) to
ensure the webview container respects dark and custom theme settings and
complies with the styled-components color guidelines.
In `@packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js`:
- Line 113: The StatusDot component rendered in the conditional expression for
the app status indicator on line 113 is missing a test identifier. Add a stable
dataTestId prop to the StatusDot component with the value 'app' to match the
existing pattern used throughout the codebase, ensuring Playwright selectors
remain robust and consistent with the coding guidelines for testable React
elements.
In `@packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js`:
- Around line 26-27: The activeItem lookup for the view-mode toggle is missing a
pathname-based fallback mechanism, causing it to miss valid request tabs and
making the toggle disappear. Modify the code that resolves activeItem (likely
using the findItemInCollection function or the lodash find function) to include
a fallback that matches items by pathname when the primary lookup fails. Apply
this fix at all locations where activeItem is resolved for the view-mode toggle
functionality, including the locations referenced in lines 62-64.
In `@packages/bruno-lang/v2/src/jsonToBru.js`:
- Around line 760-763: The app code indentation in the jsonToBru function is
using only 2 spaces via indentString(app.code, 2), but the BRU parser's
multiline handler strips 4 characters per line during parsing, causing the code
to be truncated on reload. Change the indentString call to use 4 spaces instead
of 2 spaces so that when the parser strips 4 characters, the original code
indentation is preserved correctly during round-trip serialization and
deserialization.
In `@tests/apps/apps-ctx-api.spec.ts`:
- Around line 18-29: The guestEval function uses a generic find() condition on
getAllWebContents() that will match the first webview encountered, but fails to
discriminate when multiple webviews coexist (such as AppView and HTML Preview).
Add a discriminator to the find condition to filter webviews by a stable
identifier such as URL pattern or a specific context selector, ensuring the
function consistently selects the correct guest webview for evaluation rather
than whichever webview happens to be found first.
---
Outside diff comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js`:
- Around line 2747-2764: The currentItem update block starting at line 2747 is
missing the assignment of the app property from file.data.app, while the
new-item path at line 2774 correctly includes it. This causes stale app state to
remain in memory. Add the assignment currentItem.app = file.data.app to the
currentItem update block alongside the other property assignments like
currentItem.name, currentItem.type, and currentItem.request to ensure the app
property is properly synced when reusing an existing item.
---
Nitpick comments:
In `@packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js`:
- Around line 617-653: Add accessibility attributes to the three view-mode
toggle buttons (view-mode-request, view-mode-app, and view-mode-file). For each
button, add an aria-label attribute with a descriptive name for the mode
(Request, App, and File respectively) and add an aria-pressed attribute that
reflects the button's active state. For the Request button, aria-pressed should
match the condition when it is active (when appEnabled is false and
collection.fileMode is false), for the App button it should match when
appEnabled is true and collection.fileMode is false, and for the File button it
should match when collection.fileMode is true.
In `@packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts`:
- Line 11: The import statement for OpenCollectionApp mixes runtime imports with
type-only imports. Since OpenCollectionApp is used only as a type annotation and
not at runtime, refactor the import statement to use import type syntax for
OpenCollectionApp while keeping the toOpenCollectionApp function as a regular
import from '../common/app'. This clarifies that OpenCollectionApp is purely a
type import and improves code clarity.
In `@tests/apps/apps-ctx-api.spec.ts`:
- Around line 179-183: Replace the hardcoded 700ms timeout using
`page.waitForTimeout(700)` with a state-driven polling approach that checks the
guest-visible state before sending. Use the `expect.poll()` pattern (already
used for the final assertion) to poll `ctx.variables.q` and wait until it equals
'viaSet' before calling `window.__send()`, which ensures the Redux/AppView
updates have propagated in a reliable way rather than relying on a fixed delay
that may be too short or too long in different CI environments.
🪄 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: 0fe7a1fe-4a94-4658-a8b8-3895ac5cb623
📒 Files selected for processing (22)
packages/bruno-app/src/components/AppView/StyledWrapper.jspackages/bruno-app/src/components/AppView/index.jspackages/bruno-app/src/components/RequestPane/AppCodeEditor/StyledWrapper.jspackages/bruno-app/src/components/RequestPane/AppCodeEditor/index.jspackages/bruno-app/src/components/RequestPane/HttpRequestPane/index.jspackages/bruno-app/src/components/RequestTabPanel/index.jspackages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.jspackages/bruno-app/src/components/RequestTabs/CollectionHeader/index.jspackages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/utils/collections/index.jspackages/bruno-filestore/src/formats/bru/index.tspackages/bruno-filestore/src/formats/yml/common/app.tspackages/bruno-filestore/src/formats/yml/items/parseHttpRequest.tspackages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.tspackages/bruno-lang/v2/src/bruToJson.jspackages/bruno-lang/v2/src/jsonToBru.jspackages/bruno-schema-types/src/collection/item.tspackages/bruno-schema/src/collections/index.jstests/apps/apps-ctx-api.spec.tstests/apps/apps-ui.spec.tstests/utils/page/actions.ts
utkarsh-bruno
left a comment
There was a problem hiding this comment.
If this isn't going to cause a problem : https://github.com/usebruno/bruno/pull/8294/changes#r3430801787 , then it's fine. We could probably implement a stricter CSP but it might also restrict the user a lot. Rest looks good.
# Conflicts: # packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js # tests/utils/page/actions.ts
aa0d6e8 to
b9150f1
Compare
Description
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
ctxAPI (theme, logging, requests, and runtime variables).appmetadata.ctx, switching, and persistence.