Skip to content

fix: address Copilot review comments on PR #1219 (pause regression tests)#1221

Closed
passionworkeer wants to merge 5 commits intoe2b-dev:mainfrom
passionworkeer:pr-1219-fix
Closed

fix: address Copilot review comments on PR #1219 (pause regression tests)#1221
passionworkeer wants to merge 5 commits intoe2b-dev:mainfrom
passionworkeer:pr-1219-fix

Conversation

@passionworkeer
Copy link
Copy Markdown

@passionworkeer passionworkeer commented Mar 21, 2026

Summary

Addresses Copilot review feedback on PR #1219:

  1. Removed unused expect import - The expect import from vitest was only used for toBeDefined() assertions which don't narrow TypeScript types. Removed since it's no longer needed.

  2. Replaced expect(apiKey).toBeDefined() with explicit type guard - Runtime assertions don't help TypeScript's type narrowing. Used explicit if (apiKey === undefined) throw new Error(...) pattern which properly narrows the type and is more explicit about the failure mode.

  3. Remove redundant apiKey read in test - After deleting process.env.E2B_API_KEY, reading it again is always undefined. Use savedApiKey directly to make intent explicit.

  4. Fix JSDoc for pause() - Changed "Pause a sandbox by its ID" (sounds static) to "Pause this sandbox" to correctly describe the instance method.

Changes

Runtime behavior

  • packages/js-sdk/src/sandbox/index.ts:
    • pause(): Merges this.connectionConfig into opts before passing to SandboxApi.pause()
    • betaPause(): Merges this.connectionConfig into opts before passing to SandboxApi.betaPause()
    • JSDoc: "Pause a sandbox by its ID" -> "Pause this sandbox"

Test-only

  • packages/js-sdk/tests/sandbox/pause.test.ts:
    • Removed expect import (only assert is used)
    • Test 1: Removed redundant process.env.E2B_API_KEY re-read; use savedApiKey directly
    • Test 3: Same pattern

Copilot issues addressed

Issue Fix
Unused expect import (lint risk) Removed import entirely
toBeDefined() doesn't narrow TS type Replaced with explicit if-check + throw
Non-null assertion apiKey! is fragile Type is now properly narrowed via guard
Redundant env read after delete Use savedApiKey directly
JSDoc says "by ID" for instance method Changed to "Pause this sandbox"

Closes #1219 (as a follow-up fix)

passionworkeer added 4 commits March 20, 2026 05:33
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
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 21, 2026

⚠️ No Changeset found

Latest commit: 6704294

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
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 follows up on the “pause regression tests” work by tightening the Vitest regression tests around apiKey handling and updating Sandbox.pause()/betaPause() to consistently forward the instance’s connectionConfig into the underlying API calls.

Changes:

  • Updated Sandbox.pause() and Sandbox.betaPause() to merge this.connectionConfig into the options passed to SandboxApi.
  • Updated pause regression tests to remove an unused expect import and replace toBeDefined()/non-null assertions with explicit runtime guards.

Reviewed changes

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

File Description
packages/js-sdk/tests/sandbox/pause.test.ts Adjusts pause regression tests to avoid unused imports and use explicit apiKey guards for TS narrowing.
packages/js-sdk/src/sandbox/index.ts Ensures pause()/betaPause() use the sandbox instance’s connectionConfig when calling SandboxApi.

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

Comment on lines +21 to +25
const apiKey = process.env.E2B_API_KEY || savedApiKey
if (apiKey === undefined) {
throw new Error('apiKey must be defined at this point')
}
const finalApiKey = apiKey
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

After deleting process.env.E2B_API_KEY, reading it again here is redundant (it will always be undefined). This makes the intent harder to follow; consider just using savedApiKey (and/or capture the value before deleting) so the source of finalApiKey is explicit.

Suggested change
const apiKey = process.env.E2B_API_KEY || savedApiKey
if (apiKey === undefined) {
throw new Error('apiKey must be defined at this point')
}
const finalApiKey = apiKey
const finalApiKey = savedApiKey
if (finalApiKey === undefined) {
throw new Error('apiKey must be defined at this point')
}

Copilot uses AI. Check for mistakes.
Comment on lines 574 to 576
/**
* Pause a sandbox by its ID.
*
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

This is an instance method, but the docstring says "Pause a sandbox by its ID", which reads like a static/ID-based API. Consider updating the wording to reflect that it pauses the current sandbox instance (e.g., "Pause this sandbox").

Copilot uses AI. Check for mistakes.
Comment on lines 587 to 596
async pause(opts?: ConnectionOpts): Promise<boolean> {
return await SandboxApi.pause(this.sandboxId, opts)
return await SandboxApi.pause(this.sandboxId, { ...this.connectionConfig, ...opts })
}

/**
* @deprecated Use {@link Sandbox.pause} instead.
*/
async betaPause(opts?: ConnectionOpts): Promise<boolean> {
return await SandboxApi.betaPause(this.sandboxId, opts)
return await SandboxApi.betaPause(this.sandboxId, { ...this.connectionConfig, ...opts })
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

The PR description lists only test-only changes, but this diff also changes runtime behavior in Sandbox.pause() / betaPause() by merging this.connectionConfig into the options passed to SandboxApi. Please update the PR description (or split the change) so reviewers are aware of the SDK behavior change.

Copilot uses AI. Check for mistakes.
@ValentaTomas ValentaTomas removed their request for review March 21, 2026 06:40
- Remove redundant process.env.E2B_API_KEY read after env deletion
  (savedApiKey is always the source after delete, per Copilot feedback)
- Update docstring: 'Pause a sandbox by its ID' -> 'Pause this sandbox instance'
  (pause() is an instance method, not a static ID-based API)
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