Skip to content

fix: update pause() JSDoc and add regression tests for apiKey propagation#1219

Open
passionworkeer wants to merge 5 commits intoe2b-dev:mainfrom
passionworkeer:fix/pause-method-jsdoc-and-test
Open

fix: update pause() JSDoc and add regression tests for apiKey propagation#1219
passionworkeer wants to merge 5 commits intoe2b-dev:mainfrom
passionworkeer:fix/pause-method-jsdoc-and-test

Conversation

@passionworkeer
Copy link

Summary

Fixes Copilot review feedback on PR #1218:

  1. JSDoc fix: pause() method was documented as returning "sandbox ID" but the actual return type is Promise<boolean> (true=paused, false=already paused). Updated @returns to reflect the correct boolean semantics.

  2. Regression tests: Added tests verifying that Sandbox.connect() with an explicit apiKey correctly propagates credentials to pause() even when E2B_API_KEY is not set in the environment.

Changes

  • packages/js-sdk/src/sandbox/index.ts: Updated pause() JSDoc @returns from "sandbox ID" to "true if paused successfully, false if already paused"
  • packages/js-sdk/tests/sandbox/pause.test.ts: New test file with 3 regression tests

Test coverage

  • pause() uses apiKey from connectionConfig when E2B_API_KEY is not set
  • pause() returns false when sandbox is already paused
  • pause() works on connected sandbox with apiKey in connectionConfig

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
@passionworkeer passionworkeer requested a review from jakubno as a code owner March 20, 2026 16:07
Copilot AI review requested due to automatic review settings March 20, 2026 16:07
@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 2f9021c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
e2b Patch

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

Copy link
Contributor

Copilot AI left a comment

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 corrects the pause() JSDoc return semantics and adds regression tests ensuring apiKey passed via Sandbox.connect() propagates to pause() even when E2B_API_KEY is unset.

Changes:

  • Fix pause() JSDoc @returns to accurately describe Promise<boolean> semantics.
  • Ensure Sandbox.pause() / betaPause() pass merged connectionConfig + per-call opts to the underlying API.
  • Add integration regression tests covering apiKey propagation and paused-state return behavior.

Reviewed changes

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

File Description
packages/js-sdk/src/sandbox/index.ts Corrects pause() documentation and merges connectionConfig into pause()/betaPause() API calls.
packages/js-sdk/tests/sandbox/pause.test.ts Adds regression tests for apiKey propagation and pause() boolean return behavior.

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

import { assert, expect } from 'vitest'

import { Sandbox } from '../../src'
import { isDebug, sandboxTest, template } from '../setup'
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

template is imported but not used anywhere in this new test file. Removing it will keep the test file cleaner and avoid lint failures in stricter configurations.

Suggested change
import { isDebug, sandboxTest, template } from '../setup'
import { isDebug, sandboxTest } from '../setup'

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +37
if (savedApiKey) {
process.env.E2B_API_KEY = savedApiKey
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

Environment restoration is currently conditional on savedApiKey being truthy; if it was set to an empty string, the test will not restore the original value and could leak mutated process state into subsequent tests. Prefer checking savedApiKey !== undefined (restore), and otherwise explicitly delete process.env.E2B_API_KEY.

Suggested change
if (savedApiKey) {
process.env.E2B_API_KEY = savedApiKey
if (savedApiKey !== undefined) {
process.env.E2B_API_KEY = savedApiKey
} else {
delete process.env.E2B_API_KEY

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +25
const apiKey = process.env.E2B_API_KEY || savedApiKey
expect(apiKey).toBeDefined()

// Connect to the sandbox with an explicit apiKey (E2B_API_KEY is now unset)
const connected = Sandbox.connect(sandbox.sandboxId, { apiKey })
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

expect(apiKey).toBeDefined() is a runtime check but does not help TypeScript narrow apiKey to string at compile time. To avoid accidentally passing undefined into Sandbox.connect (and to satisfy TS if apiKey is typed as required), assign with an explicit guard (throw/assert) and/or pass apiKey! after the assertion.

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 725d362766

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

expect(apiKey).toBeDefined()

// Connect to the sandbox with an explicit apiKey (E2B_API_KEY is now unset)
const connected = Sandbox.connect(sandbox.sandboxId, { apiKey })

Choose a reason for hiding this comment

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

P1 Badge Await Sandbox.connect before calling instance methods

Sandbox.connect(...) is async and returns a Promise<Sandbox>, but this test stores it without await and then calls connected.pause()/connected.isRunning(). In Node this means connected is a Promise, so method calls fail with TypeError before the pause behavior is exercised; the same pattern appears again later in this file (line 63).

Useful? React with 👍 / 👎.

- 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
- Use savedApiKey directly instead of re-reading from process.env after deletion
- Update pause() JSDoc to say 'Pause this sandbox' (instance method, not static)

Co-Authored-By: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@passionworkeer
Copy link
Author

Hi, checking in - this PR updates pause() JSDoc and adds regression tests for apiKey propagation. Copilot reviewed with no issues. Is there anything needed to move forward?

@passionworkeer
Copy link
Author

The P1 bug (missing �wait on Sandbox.connect()) has been fixed and pushed to a new PR #1223 targeting main. The fix addresses:

  1. All Sandbox.connect() calls now properly use �wait
  2. Env restoration logic corrected: if (savedApiKey !== undefined) with proper else branch to delete the env var
  3. Redundant apiKey variable removed

Please review the new PR #1223.

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.

2 participants