Skip to content

fix: system proxy refresh - #8535

Merged
bijin-bruno merged 2 commits into
usebruno:mainfrom
sid-bruno:fix/system-proxy-refresh
Jul 8, 2026
Merged

bijin-bruno merged 2 commits into
usebruno:mainfrom
sid-bruno:fix/system-proxy-refresh

Conversation

@sid-bruno

@sid-bruno sid-bruno commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Layered on #8159 to move to bruno-electron

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

    • Improved system proxy refresh behavior by syncing proxy settings from your shell configuration when available.
    • Added support for fetching shell environment proxy values with a safer fallback when unavailable.
  • Bug Fixes

    • Prevents proxy settings from being overwritten on failures or timeouts.
    • Keeps existing proxy values unchanged on Windows and when no refresh is requested.
    • Removes proxy entries that are no longer present in shell configuration.

abhishekp-bruno and others added 2 commits July 8, 2026 18:16
RESOLVED pr conversations

ADD test cases and os specific test casess

REVERTE comment removed for windows refetch

refactor: remove redundant afterEach cleanup in shell-env-proxy-refresh tests

RENAME the  test file and add more test for wider coverage among the test cases

test: add integration tests for refreshShellEnvProxyVars

delete: remove outdated system proxy integration test file

fix: enhance proxy variable restoration on shell-env subprocess failure

fix: implement timeout for shellEnv to prevent hanging on misconfigured shells

feat: add refreshShellEnvProxyVars function to shell-env-state.ts and update shell environment initialization logic

refactor: simplify shell environment refresh and update system proxy integration

refactor: implement withTimeout utility for shell environment operations to prevent indefinite hangs
@sid-bruno
sid-bruno force-pushed the fix/system-proxy-refresh branch from 0d11517 to f6e3172 Compare July 8, 2026 12:46

Copilot AI 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.

Pull request overview

This PR updates Bruno’s Electron system-proxy refresh behavior so a “refresh” re-reads proxy-related environment variables from the user’s login shell (instead of relying on stale process.env values), and exposes fetchShellEnv() from @usebruno/requests to support that flow.

Changes:

  • Exported fetchShellEnv() from bruno-requests and adjusted its failure semantics to return null (callers can distinguish failure from an empty env).
  • Added shell proxy env var refresh logic + timeout handling to the Electron system proxy store when fetchSystemProxy({ refresh: true }) is used.
  • Added Jest coverage for env var refresh, removal, Windows no-op behavior, and timeout fallback.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/bruno-requests/src/utils/shell-env.ts Exports fetchShellEnv() and makes shell-fetch failures explicit via null, with initializeShellEnv() handling that case.
packages/bruno-requests/src/index.ts Re-exports fetchShellEnv from the package entrypoint for external consumers (Electron store).
packages/bruno-electron/src/store/system-proxy.js On refresh, clears/reloads proxy env vars from shell (with timeout) before calling getSystemProxy().
packages/bruno-electron/src/store/tests/system-proxy.spec.js Adds regression tests validating refresh behavior, failure fallback, Windows behavior, and timeout restoration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds shell-env proxy synchronization: fetchShellEnv is exported from bruno-requests with a nullable return type, and bruno-electron's system-proxy module gains refreshShellEnvProxyVars to snapshot, refresh (with timeout), or restore proxy-related process.env values before loading the system proxy. Tests cover the new behavior.

Changes

Shell env proxy refresh

Layer / File(s) Summary
fetchShellEnv export and nullable return
packages/bruno-requests/src/utils/shell-env.ts, packages/bruno-requests/src/index.ts
fetchShellEnv is exported with return type widened to Record<string, string> | null, returns null on error instead of {}, and initializeShellEnv short-circuits to {} when null is returned.
refreshShellEnvProxyVars and loadSystemProxy wiring
packages/bruno-electron/src/store/system-proxy.js
Adds refreshShellEnvProxyVars to snapshot/clear/restore proxy env vars using fetchShellEnv with a timeout race, and wires loadSystemProxy/fetchSystemProxy to invoke this refresh via a refreshShellEnv/refresh option before caching the proxy.
Refresh behavior test suite
packages/bruno-electron/src/store/tests/system-proxy.spec.js
Adds Jest tests covering refresh-driven env updates, key removal, null-fetch restoration, Windows skip behavior, no-refresh calls, and timeout-based restoration with fake timers.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • usebruno/bruno#6990: Both PRs change the Electron system-proxy caching/refresh flow in the same file, adding refresh-triggering logic on top of the caching mechanism.
  • usebruno/bruno#7264: Both PRs modify the fetchSystemProxy/loadSystemProxy loading path, layering the new refreshShellEnv logic onto the existing promise/caching refactor.
  • usebruno/bruno#8173: The retrieved PR's IPC handler calls fetchSystemProxy({ refresh: true }), directly triggering the new shell-env resync path added in this PR.

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

Poem

A rabbit sniffs the shell's fresh air,
Snapshots proxies with utmost care,
If sixty seconds tick too slow,
Old values return, safe in tow. 🐇
http_proxy, no_proxy too,
Refreshed and tested, tried and true!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing system proxy refresh behavior.
✨ 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.

🧹 Nitpick comments (1)
packages/bruno-electron/src/store/system-proxy.js (1)

12-38: 🩺 Stability & Availability | 🔵 Trivial

Orphaned subprocess on timeout — known trade-off worth documenting.

When the 60s timeout fires, fetchShellEnv() is still pending. The shell-env library spawns a child process (e.g., $SHELL -i -c 'env') that won't be cancelled or cleaned up. The timeout correctly prevents the caller from hanging, but the orphaned process persists until it exits naturally or the app closes. Since shell-env doesn't expose cancellation, consider adding a brief inline note near the timeout logic so future maintainers understand this is an accepted limitation, not an oversight.

🤖 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-electron/src/store/system-proxy.js` around lines 12 - 38, The
timeout path in refreshShellEnvProxyVars leaves the fetchShellEnv child process
running, so add a brief inline note near the Promise.race timeout logic
explaining that shell-env has no cancellation support and the orphaned
subprocess is an accepted limitation. Keep the comment close to the timeout
handling in refreshShellEnvProxyVars so future maintainers understand why no
cleanup is attempted when result is null.
🤖 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.

Nitpick comments:
In `@packages/bruno-electron/src/store/system-proxy.js`:
- Around line 12-38: The timeout path in refreshShellEnvProxyVars leaves the
fetchShellEnv child process running, so add a brief inline note near the
Promise.race timeout logic explaining that shell-env has no cancellation support
and the orphaned subprocess is an accepted limitation. Keep the comment close to
the timeout handling in refreshShellEnvProxyVars so future maintainers
understand why no cleanup is attempted when result is null.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f9a29c4a-61af-4655-b74e-6179866b4638

📥 Commits

Reviewing files that changed from the base of the PR and between 7a1ea5e and f6e3172.

📒 Files selected for processing (4)
  • packages/bruno-electron/src/store/system-proxy.js
  • packages/bruno-electron/src/store/tests/system-proxy.spec.js
  • packages/bruno-requests/src/index.ts
  • packages/bruno-requests/src/utils/shell-env.ts

@bijin-bruno
bijin-bruno merged commit 7ce3bf4 into usebruno:main Jul 8, 2026
14 of 16 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 20, 2026
3 of 6 tasks
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.

4 participants