Skip to content

feat(app): migrate ctx API to bru.ctx - #8557

Merged
naman-bruno merged 2 commits into
usebruno:mainfrom
gopu-bruno:feat/app-bru-ctx-api
Jul 14, 2026
Merged

naman-bruno merged 2 commits into
usebruno:mainfrom
gopu-bruno:feat/app-bru-ctx-api

Conversation

@gopu-bruno

@gopu-bruno gopu-bruno commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Migrates the Apps context API to a namespaced bru.ctx.*
  • Introduces a richer theme object and scoped variables.
  • Applies to both request level and collection level apps.

What changed

Before After
window.ctx window.bru.ctx
ctx.theme ('light' / 'dark') bru.ctx.theme ({ name, mode, config })
ctx.response bru.ctx.http.response
ctx.assertionResults / ctx.testResults bru.ctx.assertions / bru.ctx.tests
ctx.variables bru.ctx.variables.resolved
ctx.sendRequest(overrides?) bru.ctx.submitRequest(options?) with { runtimeVariables }
ctx.setRuntimeVariable(key, value) bru.ctx.variables.runtime.set(name, value)
ctx.onResponseUpdate bru.ctx.http.onResponseChange
ctx.onResultsUpdate bru.ctx.onAssertionsChange + bru.ctx.onTestsChange
ctx.onVariablesUpdate bru.ctx.onVariablesChange
ctx.onCollectionUpdate bru.ctx.onCollectionChange

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.

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

  • New Features

    • Introduced the window.bru.ctx runtime API for embedded request and collection apps (replacing window.ctx), including updated request execution, resolved variables, and callback naming.
    • Enhanced theme synchronization by delivering structured theme mode/config and applying updates to the guest.
    • Updated app starter behavior to use bru.ctx for listing requests.
  • Documentation

    • Updated AI-assisted app-generation prompts and inline webview guidance to use the new bru.ctx contract and best-practice initialization.
  • Tests

    • Updated Electron/Playwright coverage to validate bru.ctx bootstrapping, request/variable flow, and theme behavior.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66f42d73-f7d6-4276-ab4e-7c37ea54c1e5

📥 Commits

Reviewing files that changed from the base of the PR and between 26965ef and fdd140b.

📒 Files selected for processing (9)
  • packages/bruno-app/src/components/AIAssist/index.js
  • packages/bruno-app/src/components/AppView/index.js
  • packages/bruno-app/src/components/AppView/webview-bridge.js
  • packages/bruno-app/src/components/CollectionApp/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-electron/src/ipc/ai/chat-prompts.js
  • packages/bruno-electron/src/ipc/ai/script-prompts.js
  • tests/apps/apps-ctx-api.spec.ts
  • tests/apps/collection-apps.spec.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-electron/src/ipc/ai/chat-prompts.js
  • packages/bruno-app/src/components/AppView/webview-bridge.js
  • packages/bruno-app/src/components/AIAssist/index.js
  • packages/bruno-electron/src/ipc/ai/script-prompts.js
  • tests/apps/apps-ctx-api.spec.ts
  • packages/bruno-app/src/components/CollectionApp/index.js
  • tests/apps/collection-apps.spec.ts
  • packages/bruno-app/src/components/AppView/index.js

Walkthrough

The PR migrates request and collection webviews from window.ctx to window.bru.ctx, restructuring runtime state, callbacks, theming, and request options. AI prompts, starter content, bridge documentation, and Electron tests are updated to reflect and validate the new contract.

Changes

bru.ctx Runtime Contract

Layer / File(s) Summary
Request runtime bootstrap and messaging
packages/bruno-app/src/components/AppView/index.js, packages/bruno-app/src/components/AppView/webview-bridge.js, tests/apps/apps-ctx-api.spec.ts
Request apps now use nested bru.ctx state, renamed callbacks, submitRequest(options), structured runtime variables, and richer theme payloads.
Collection runtime bootstrap and execution
packages/bruno-app/src/components/CollectionApp/index.js, tests/apps/collection-apps.spec.ts
Collection apps now use nested variables and theme state, collection change hooks, and runRequest(pathname, options).
Prompt and starter API guidance
packages/bruno-app/src/components/AIAssist/index.js, packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js, packages/bruno-electron/src/ipc/ai/*
AI guidance, bridge comments, and the default starter app now document the bru.ctx APIs and renamed methods and callbacks.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Webview
  participant AppView
  participant RequestRunner
  Webview->>AppView: bru.ctx.submitRequest(options)
  AppView->>RequestRunner: handleSendRequest(requestId, options)
  RequestRunner-->>AppView: response, results, variables
  AppView-->>Webview: state updates and callbacks
Loading

Possibly related PRs

Suggested reviewers: helloanoop, lohit-bruno, naman-bruno, sid-bruno, bijin-bruno

Poem

Old ctx sails away,
bru.ctx lights the view,
Requests and themes align,
Callbacks sing anew,
Tests guard the bridge true.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: migrating the app context API from ctx to bru.ctx.
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.
✨ 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.

@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: 1

🤖 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 `@tests/apps/apps-ctx-api.spec.ts`:
- Around line 168-176: Fix the guest webview selection and readiness handling in
guestEval and the runtimeVariables test setup. Ensure waitForGuestReady
completes before invoking __send, and disambiguate the target webview instead of
selecting the first data:text/html entry, using the expected collection/app
identifier or an equivalent readiness guard. Verify both runtimeVariables
override steps execute against the intended guest webview.
🪄 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: edb70e84-944a-4228-a12f-ce81b68423a1

📥 Commits

Reviewing files that changed from the base of the PR and between 81f9a40 and 6890da0.

📒 Files selected for processing (9)
  • packages/bruno-app/src/components/AIAssist/index.js
  • packages/bruno-app/src/components/AppView/index.js
  • packages/bruno-app/src/components/AppView/webview-bridge.js
  • packages/bruno-app/src/components/CollectionApp/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-electron/src/ipc/ai/chat-prompts.js
  • packages/bruno-electron/src/ipc/ai/script-prompts.js
  • tests/apps/apps-ctx-api.spec.ts
  • tests/apps/collection-apps.spec.ts

Comment thread tests/apps/apps-ctx-api.spec.ts Resolved
@gopu-bruno
gopu-bruno force-pushed the feat/app-bru-ctx-api branch from f122be8 to 26965ef Compare July 10, 2026 07:45
@gopu-bruno
gopu-bruno force-pushed the feat/app-bru-ctx-api branch from 26965ef to fdd140b Compare July 13, 2026 12:51
@naman-bruno
naman-bruno merged commit 4d63acb into usebruno:main Jul 14, 2026
11 of 16 checks passed

@intekhabalamkhan402-dev intekhabalamkhan402-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Submit general feedback without explicit approval

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.

3 participants