-
Notifications
You must be signed in to change notification settings - Fork 831
fix: update pause() JSDoc and add regression tests for apiKey propagation #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
dd26a14
725d362
1e9f602
9268067
2f9021c
bf8afcb
7358071
3af7447
6a14636
2fbcda3
95e3ef0
6221c8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||
| import { assert, expect } from 'vitest' | ||||||||||||||
|
|
||||||||||||||
| import { Sandbox } from '../../src' | ||||||||||||||
| import { isDebug, sandboxTest, template } from '../setup' | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Regression test: Sandbox.connect() with explicit apiKey should allow | ||||||||||||||
| * pause() to succeed even when E2B_API_KEY is not set in the environment. | ||||||||||||||
| * | ||||||||||||||
| * See: https://github.com/e2b-dev/E2B/pull/1218 | ||||||||||||||
| */ | ||||||||||||||
| sandboxTest.skipIf(isDebug)( | ||||||||||||||
| 'pause() uses apiKey from connectionConfig when E2B_API_KEY is not set', | ||||||||||||||
| async ({ sandbox }) => { | ||||||||||||||
| // Save and clear the environment API key | ||||||||||||||
| const savedApiKey = process.env.E2B_API_KEY | ||||||||||||||
| delete process.env.E2B_API_KEY | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
| // Get the apiKey that was used to create this sandbox | ||||||||||||||
| 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 }) | ||||||||||||||
|
||||||||||||||
|
|
||||||||||||||
| // pause() should succeed using the apiKey from connectionConfig | ||||||||||||||
| // rather than requiring E2B_API_KEY to be set | ||||||||||||||
| const paused = await connected.pause() | ||||||||||||||
| assert.isTrue(paused, 'pause() should return true when successfully pausing a running sandbox') | ||||||||||||||
|
|
||||||||||||||
| // Verify the sandbox is actually paused | ||||||||||||||
| assert.isFalse(await connected.isRunning(), 'sandbox should be paused after pause()') | ||||||||||||||
| } finally { | ||||||||||||||
| // Restore the environment API key | ||||||||||||||
| if (savedApiKey) { | ||||||||||||||
| process.env.E2B_API_KEY = savedApiKey | ||||||||||||||
|
||||||||||||||
| if (savedApiKey) { | |
| process.env.E2B_API_KEY = savedApiKey | |
| if (savedApiKey !== undefined) { | |
| process.env.E2B_API_KEY = savedApiKey | |
| } else { | |
| delete process.env.E2B_API_KEY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
templateis 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.