fix: clone sentryConfig before mutation#28
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| const [config, context] = args; | ||
|
|
||
| this.options = config.projectConfig.testEnvironmentOptions?.sentryConfig; | ||
| this.options = structuredClone(config.projectConfig.testEnvironmentOptions?.sentryConfig) |
There was a problem hiding this comment.
structuredClone throws on configs containing functions
Medium Severity
structuredClone throws a DataCloneError if the sentryConfig object (or its nested init property) contains any function values. Sentry's init options commonly include callbacks like beforeSend, tracesSampler, beforeBreadcrumb, or integrations as a function. Users passing any of these will now get a runtime error that didn't exist before this change. A shallow spread of only the mutated paths (init and init.integrations) would avoid this while still preventing the shared-config mutation the PR intends to fix.


Fixes the crash discovered in getsentry/sentry#110568: Sentry's Jest unit tests normally run in worker processes. Modifying the shared config object in them is fine because they're already copies of the original. But when switching to in-band, the environment needs to manually copy them.