fix: await Sandbox.connect in pause regression tests#1223
fix: await Sandbox.connect in pause regression tests#1223passionworkeer 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 |
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.
|
Fix it in original PR |
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