Skip to content

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

Draft
passionworkeer wants to merge 6 commits intoe2b-dev:mainfrom
passionworkeer:fix/copilot-review-1221-v2
Draft

fix: address Copilot review comments on PR #1219 (pause regression tests)#1222
passionworkeer wants to merge 6 commits intoe2b-dev:mainfrom
passionworkeer:fix/copilot-review-1221-v2

Conversation

@passionworkeer
Copy link

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 and others added 5 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
- 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-bot
Copy link

changeset-bot bot commented Mar 21, 2026

🦋 Changeset detected

Latest commit: 79342bf

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

@passionworkeer
Copy link
Author

Hi, checking in - this PR addresses Copilot review comments on PR #1219. The changesets for the pause-related PRs are also noted. Is there anything else needed?

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.

1 participant