fix: await Sandbox.connect in pause regression tests#1223
Open
passionworkeer wants to merge 6 commits intoe2b-dev:mainfrom
Open
fix: await Sandbox.connect in pause regression tests#1223passionworkeer wants to merge 6 commits intoe2b-dev:mainfrom
passionworkeer wants to merge 6 commits intoe2b-dev:mainfrom
Conversation
When using Sandbox.connect() with an apiKey, the pause() method was not passing the apiKey to the API call, causing auth failures. This fix ensures pause() (and deprecated betaPause()) use the same pattern as kill() - merging connectionConfig with provided opts. Fixes: e2b-dev#1215
…tion - Update @returns JSDoc: pause() returns boolean (true=paused, false=already paused) matching SandboxApi.pause semantics, not a sandbox ID - Add regression tests for apiKey propagation in Sandbox.connect(): - pause() succeeds when E2B_API_KEY is unset but apiKey is passed to connect() - pause() returns false when sandbox is already paused - pause() works on connected sandbox with apiKey in connectionConfig Refs: Copilot PR e2b-dev#1218 review comments
- Remove unused template import - Change savedApiKey truthy check to explicit undefined check - Add await before Sandbox.connect() calls (P1 - async Promise fix) - Add explicit non-null assertion after toBeDefined() for TypeScript
… Copilot review) - Remove unused 'expect' import from vitest - Use explicit if-check + throw instead of expect(apiKey).toBeDefined() - This properly narrows TypeScript type for apiKey without relying on assertion return type
- Remove redundant process.env.E2B_API_KEY read after delete (always undefined) - Update JSDoc: 'Pause a sandbox by its ID' -> 'Pause this sandbox' - PR e2b-dev#1221
🦋 Changeset detectedLatest commit: 034e2d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the JS SDK where calling pause() (and betaPause()) on a connected Sandbox instance could fail to authenticate when E2B_API_KEY was unset, because instance-level connection configuration (e.g., apiKey) was not being forwarded into the underlying SandboxApi calls.
Changes:
- Update
Sandbox.pause()/Sandbox.betaPause()to mergethis.connectionConfiginto the options passed toSandboxApi.*Pause(...). - Add/adjust regression tests to ensure
Sandbox.connect(..., { apiKey })works even whenprocess.env.E2B_API_KEYis cleared, and that repeatedpause()returnsfalsewhen already paused.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/js-sdk/tests/sandbox/pause.test.ts | Adds regression coverage for pause behavior on connected sandboxes and env var handling. |
| packages/js-sdk/src/sandbox/index.ts | Ensures instance pause() / betaPause() propagate connection config (e.g., apiKey) to API calls. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the P1 bug identified in PR #1219 where Sandbox.connect(...) was called without �wait, causing connected.pause() to fail with a TypeError since connected was a Promise rather than a Sandbox instance.
Changes in packages/js-sdk/tests/sandbox/pause.test.ts:
Test cases covered:
Closes #1219