-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: onResume option on connect/resume #1800
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
Changes from all commits
e89a403
d0a8d4a
5155388
39424d6
9489ac4
0e5788d
0380d8d
a42b3ef
9ab04ef
c02e943
d876b2a
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,6 @@ | ||
| --- | ||
| 'e2b': minor | ||
| '@e2b/python-sdk': minor | ||
| --- | ||
|
|
||
| Add `onResume` / `on_resume` to `Sandbox.connect()`: `'reboot'` resumes a paused sandbox from its disk state alone, leaving the memory snapshot untouched, for the case where restoring that memory wedges the guest. `'restore'` stays the default. Where filesystem-only resume is not enabled, a `'reboot'` that would actually drop memory is rejected with an error rather than silently restoring it. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { afterAll, afterEach, beforeAll, expect, test } from 'vitest' | ||
| import { http, HttpResponse } from 'msw' | ||
| import { setupServer } from 'msw/node' | ||
|
|
||
| import { Sandbox } from '../../src' | ||
| import { TEST_API_KEY, apiUrl } from '../setup' | ||
|
|
||
| let lastConnectBody: Record<string, unknown> | undefined | ||
|
|
||
| const server = setupServer( | ||
| http.post(apiUrl('/sandboxes/:sandboxID/connect'), async ({ request }) => { | ||
| lastConnectBody = (await request.json()) as Record<string, unknown> | ||
| return HttpResponse.json({ | ||
| sandboxID: 'test-sandbox-id', | ||
| templateID: 'base', | ||
| envdVersion: '0.2.4', | ||
| }) | ||
| }) | ||
| ) | ||
|
|
||
| beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) | ||
|
|
||
| afterAll(() => server.close()) | ||
|
|
||
| afterEach(() => { | ||
| lastConnectBody = undefined | ||
| server.resetHandlers() | ||
| }) | ||
|
|
||
| test('Sandbox.connect omits memory when onResume is not given', async () => { | ||
| await Sandbox.connect('test-sandbox-id', { apiKey: TEST_API_KEY }) | ||
|
|
||
| expect(lastConnectBody).toBeDefined() | ||
| expect(lastConnectBody).not.toHaveProperty('memory') | ||
| }) | ||
|
|
||
| test("Sandbox.connect omits memory for onResume: 'restore'", async () => { | ||
| // 'restore' is the API's own default, so it must travel as an absent field | ||
| // rather than memory: true — the two are not interchangeable on the wire. | ||
| await Sandbox.connect('test-sandbox-id', { | ||
| apiKey: TEST_API_KEY, | ||
| onResume: 'restore', | ||
| }) | ||
|
|
||
| expect(lastConnectBody).not.toHaveProperty('memory') | ||
| }) | ||
|
|
||
| test("Sandbox.connect sends memory: false for onResume: 'reboot'", async () => { | ||
| await Sandbox.connect('test-sandbox-id', { | ||
| apiKey: TEST_API_KEY, | ||
| onResume: 'reboot', | ||
| }) | ||
|
|
||
| expect(lastConnectBody?.memory).toBe(false) | ||
| }) | ||
|
|
||
| test('sandbox.connect carries onResume on the instance form too', async () => { | ||
| const sandbox = await Sandbox.connect('test-sandbox-id', { | ||
| apiKey: TEST_API_KEY, | ||
| }) | ||
| lastConnectBody = undefined | ||
|
|
||
| await sandbox.connect({ onResume: 'reboot' }) | ||
| expect(lastConnectBody?.memory).toBe(false) | ||
|
|
||
| await sandbox.connect() | ||
| expect(lastConnectBody).not.toHaveProperty('memory') | ||
| }) | ||
|
|
||
| test('an untyped onResume value never sends memory: false', async () => { | ||
| // Untyped callers can pass anything; only the 'reboot' literal opts into a | ||
| // cold boot, so an unrecognized value must fall back to a memory restore. | ||
| await Sandbox.connect('test-sandbox-id', { | ||
| apiKey: TEST_API_KEY, | ||
| // @ts-expect-error 'Reboot' is not a valid onResume value | ||
| onResume: 'Reboot', | ||
| }) | ||
|
|
||
| expect(lastConnectBody).not.toHaveProperty('memory') | ||
| }) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.