Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 25, 2025

Summary

Adds missing test coverage for error handling paths in executeSafePromise introduced by the browser compatibility refactor (#3310).

Changes

  • Node/Electron environment tests: Verify process.exit(1) is called on promise rejection and fatal errors are logged
  • Browser environment tests: Verify errors are thrown with proper error chaining via cause property

The environment detection behavior is implicitly verified by the Node and browser test blocks, which mock or remove process.exit and verify the appropriate code path is taken.

Checklist before requesting a review

  • Is this a breaking change? If it is, be clear in summary.
  • Read through code myself one more time.
  • Make sure any and all TODO comments left behind are meant to be left in.
  • Has reasonable passing test coverage?
  • Updated changelog if applicable.
  • Updated documentation if applicable.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Note

Expands test coverage for executeSafePromise to validate error-handling in different runtimes.

  • Adds Node/Electron tests in packages/utils/test/executeSafePromise.test.ts to assert process.exit(1) is invoked on rejection and that exit is triggered after fatal errors
  • Adds browser-environment tests by removing process.exit to assert a thrown error with message executeSafePromise: Assertion failure! and proper cause chaining
  • Retains success-path test to confirm resolved value handling

Written by Cursor Bugbot for commit ff0e81f. This will update automatically on new commits. Configure here.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor Author

Copilot AI commented Dec 25, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.184/linux64/chromedriver-linux64.zip
    • Triggering command: /usr/local/bin/node node install.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Update executeSafePromise for browser compatibility Add test coverage for executeSafePromise error handling paths Dec 25, 2025
Copilot AI requested a review from mondoreale December 25, 2025 23:48
Comment on lines 87 to 114
describe('environment detection', () => {
it('should detect Node environment when process.exit is defined', async () => {
const mockExit = jest.fn() as any
const originalProcessExit = process.exit
process.exit = mockExit

await executeSafePromise(async () => {
throw new Error('Test')
})

expect(mockExit).toHaveBeenCalled()
// eslint-disable-next-line require-atomic-updates
process.exit = originalProcessExit
})

it('should detect browser environment when process.exit is undefined', async () => {
const originalProcess = global.process
// @ts-expect-error - intentionally setting to undefined for test
delete (global as any).process.exit

await expect(executeSafePromise(async () => {
throw new Error('Test')
})).rejects.toThrow('executeSafePromise: Assertion failure!')

// eslint-disable-next-line require-atomic-updates
global.process = originalProcess
})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot isn't this block redundant? Envs are already part of the earlier tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, that block was redundant. The environment detection is already tested by the Node/Electron and browser environment test blocks. Removed in ff0e81f.

Copy link
Contributor Author

Copilot AI commented Dec 25, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.184/linux64/chromedriver-linux64.zip
    • Triggering command: /usr/local/bin/node node install.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@mondoreale mondoreale marked this pull request as ready for review December 25, 2025 23:58
@mondoreale mondoreale changed the title Add test coverage for executeSafePromise error handling paths feat: Add test coverage for executeSafePromise error handling paths Dec 25, 2025
@mondoreale mondoreale merged commit 245d1c8 into cross-environment-executeSafePromise Dec 25, 2025
1 check passed
@mondoreale mondoreale deleted the copilot/sub-pr-3310 branch December 25, 2025 23:59
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

afterEach(() => {
// Restore process
global.process = originalProcess
})
Copy link

Choose a reason for hiding this comment

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

Global process.exit remains deleted after browser tests

In the browser environment test block, process.exit is deleted from the global process object. Since originalProcess is a reference to the same object, assigning it back in afterEach fails to restore the deleted property. This leaves process.exit as undefined for subsequent tests, potentially breaking other parts of the test suite.

Fix in Cursor Fix in Web

mondoreale added a commit that referenced this pull request Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants