Skip to content

fix(js-sdk): skip test when E2B_API_KEY is not set (fixes Copilot feedback on PR #1224)#1226

Open
passionworkeer wants to merge 5 commits intoe2b-dev:mainfrom
passionworkeer:fix/copilot-review-test-flakiness
Open

fix(js-sdk): skip test when E2B_API_KEY is not set (fixes Copilot feedback on PR #1224)#1226
passionworkeer wants to merge 5 commits intoe2b-dev:mainfrom
passionworkeer:fix/copilot-review-test-flakiness

Conversation

@passionworkeer
Copy link

@passionworkeer passionworkeer commented Mar 22, 2026

Summary

Addresses Copilot review feedback on PR #1224:

  1. Test skip mechanism fix: Skip the test when E2B_API_KEY is not set using skipIf instead of an early return. This ensures the test runner properly marks the test as skipped rather than passing as a no-op.

  2. Misleading comment fix: Updated the comment to correctly say the apiKey is taken from the original E2B_API_KEY env var, not from "the created sandbox's credentials".

  3. Python SDK streaming timeout fix: Unified streaming timeout handling in e2b_connect/client.py to include read/write timeouts in the timeout extensions (previously only connect/pool/write were set; read was set separately via a different code path with misleading behavior).

Changes

  • packages/js-sdk/tests/sandbox/connect.test.ts:

    • Changed test skip from return to sandboxTest.skipIf(isDebug || !process.env.E2B_API_KEY) so the runner marks it as skipped instead of passing as no-op
    • Updated comment to accurately describe the apiKey source
    • Removed unnecessary early return (now handled by skipIf)
  • packages/js-sdk/src/sandbox/index.ts:

    • Updated pause() and betaPause() to propagate connectionConfig so apiKey flows through to the API call
  • packages/python-sdk/e2b_connect/client.py:

    • Unified streaming request timeout handling: now includes read/write timeouts in the main timeout extensions dict (previously read timeout was set via a separate code path with misleading comments)

Closes #1224 (follow-up fix)

passionworkeer and others added 4 commits March 15, 2026 13:22
When a sandbox becomes unreachable, commands.run() hangs indefinitely
because the underlying httpx stream does not have read/write timeouts set.

The _prepare_server_stream_request method only set connect and pool
timeouts, but omitted read and write timeouts. This is inconsistent with
_prepare_unary_request which correctly sets all four timeouts.

This fix adds read and write timeouts to server stream requests, ensuring
that commands.run() respects the request_timeout parameter even when
the sandbox becomes unreachable.

Closes e2b-dev#1128

Signed-off-by: passionworkeer <passionworkeer@users.noreply.github.com>
- JSDoc for pause() incorrectly said it returns sandbox ID; now correctly
  says it returns boolean (true=paused, false=already paused)
- Add regression test: connect with explicit apiKey, unset E2B_API_KEY env,
  call pause() and verify it succeeds without needing env var
Co-Authored-By: copilot-pullrequestreviewer[bot] <55177212+copilot-pullrequestreviewer[bot]@users.noreply.github.com>
… comment

Address Copilot review feedback on PR e2b-dev#1224:
1. Skip the test when E2B_API_KEY is not set - avoids calling
   Sandbox.connect with undefined apiKey (test flakiness fix)
2. Fix misleading comment: apiKey comes from E2B_API_KEY env var,
   not from the created sandbox's credentials
Copilot AI review requested due to automatic review settings March 22, 2026 09:37
@changeset-bot
Copy link

changeset-bot bot commented Mar 22, 2026

⚠️ No Changeset found

Latest commit: 293adba

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
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 aims to make SDK behavior and tests more reliable by (a) ensuring apiKey is propagated from a connected Sandbox instance into pause() calls, and (b) addressing test determinism around E2B_API_KEY-dependent behavior.

Changes:

  • JS SDK: update Sandbox.pause() / betaPause() to merge connectionConfig into the call options so apiKey propagates.
  • JS SDK tests: add a regression test intended to verify connect() propagates apiKey to pause() when E2B_API_KEY is unset.
  • Python SDK: expand httpcore timeout extensions for server-stream requests to include read and write.

Reviewed changes

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

File Description
packages/python-sdk/e2b_connect/client.py Extends stream request timeout configuration to include read/write timeouts.
packages/js-sdk/tests/sandbox/connect.test.ts Adds an apiKey propagation regression test and attempts to skip it when E2B_API_KEY is missing.
packages/js-sdk/src/sandbox/index.ts Ensures pause() and betaPause() forward connectionConfig (including apiKey) by default.

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

Comment on lines +101 to +118
sandboxTest.skipIf(isDebug)(
'connect propagates apiKey to pause() when E2B_API_KEY is not set',
async ({ sandbox }) => {
// Save the original env var (may be undefined, empty string, or set)
const savedApiKey = process.env.E2B_API_KEY

// This test requires a valid apiKey to verify propagation, so skip if E2B_API_KEY is not set
if (!savedApiKey) {
return
}

try {
// Ensure E2B_API_KEY is not set for this test
delete process.env.E2B_API_KEY

// Connect with explicit apiKey taken from the original E2B_API_KEY env var
const connected = await Sandbox.connect(sandbox.sandboxId, {
apiKey: savedApiKey,
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

The test claims to be skipped when E2B_API_KEY is not set, but return just makes it a no-op that still reports as passing. Move the condition into sandboxTest.skipIf(...)/test.skipIf(...) (so the runner marks it as skipped) or use a supported Vitest skip mechanism, then keep the body assuming a valid key.

Suggested change
sandboxTest.skipIf(isDebug)(
'connect propagates apiKey to pause() when E2B_API_KEY is not set',
async ({ sandbox }) => {
// Save the original env var (may be undefined, empty string, or set)
const savedApiKey = process.env.E2B_API_KEY
// This test requires a valid apiKey to verify propagation, so skip if E2B_API_KEY is not set
if (!savedApiKey) {
return
}
try {
// Ensure E2B_API_KEY is not set for this test
delete process.env.E2B_API_KEY
// Connect with explicit apiKey taken from the original E2B_API_KEY env var
const connected = await Sandbox.connect(sandbox.sandboxId, {
apiKey: savedApiKey,
sandboxTest.skipIf(isDebug || !process.env.E2B_API_KEY)(
'connect propagates apiKey to pause() when E2B_API_KEY is not set',
async ({ sandbox }) => {
// Save the original env var (may be undefined, empty string, or set)
const savedApiKey = process.env.E2B_API_KEY
try {
// Ensure E2B_API_KEY is not set for this test
delete process.env.E2B_API_KEY
// Connect with explicit apiKey taken from the original E2B_API_KEY env var
const connected = await Sandbox.connect(sandbox.sandboxId, {
apiKey: savedApiKey!,

Copilot uses AI. Check for mistakes.
Comment on lines 325 to +333
extensions = (
None
if request_timeout is None
else {"timeout": {"connect": request_timeout, "pool": request_timeout}}
else {
"timeout": {
"connect": request_timeout,
"pool": request_timeout,
"read": request_timeout,
"write": request_timeout,
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

The PR description focuses on JS SDK test/comment fixes, but this change also modifies Python SDK streaming request timeout behavior by adding read/write timeouts. Please either update the PR description to mention the Python change (and rationale/impact), or split it into a separate PR to keep scope clear.

Copilot uses AI. Check for mistakes.
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.

3 participants