Skip to content

js-sdk: run the msw-mocked suites in the browser leg - #1871

Draft
devin-ai-integration[bot] wants to merge 2 commits into
browser-test-suitefrom
devin/1789147597-browser-msw-worker
Draft

js-sdk: run the msw-mocked suites in the browser leg#1871
devin-ai-integration[bot] wants to merge 2 commits into
browser-test-suitefrom
devin/1789147597-browser-msw-worker

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1609. The ten suites that mock the API with msw (client, abortSignal, egressProxy, iam, lifecycleRequest, networkTransform, onResumeRequest, secret, volume, volume/file — 181 tests) were excluded from the browser leg only because they imported msw/node, whose entry pulls in node:http. The SDK code they cover (Secrets, Volumes, cancellation, workload identity, lifecycle/network request shapes, E2B client binding) is browser-runnable, so this makes them run in Chromium too, unchanged for Node/Bun/Deno/Workers.

Runtime-aware helper. The suites now import setupMockApi from tests/mockApi.ts instead of setupServer from msw/node:

interface MockApi {
  listen(options?: SharedOptions): Promise<void>  // async: a browser has to activate the worker first
  close(): Promise<void>
  use / resetHandlers / events                     // same as SetupServer
}
  • tests/mockApi.ts wraps setupServer (Node and the compat runtimes).
  • tests/runtimes/browser/mockApi.ts wraps setupWorker from msw/browser (listen → worker.start({ quiet: true }), close → worker.stop()).

The browser vitest config gets a small enforce: 'pre' Vite plugin that resolves any import of tests/mockApi.ts to the browser implementation, and serves /mockServiceWorker.js straight from node_modules/msw/lib/ (no checked-in copy to drift from the msw version). The ten suites are dropped from the browser exclude list.

Per-suite diff is the import swap + setupServer(...)setupMockApi(...); listen/close were already called from beforeAll/afterAll so awaiting them needed no restructuring. secret, volume and mockVolumeContent swap node:crypto randomUUID() for crypto.randomUUID(). One test in client.test.ts (client.Template builds template instances) is skipIf(runtime === 'browser'): the template builder is Node-only (node:path), same reason tests/template/** is excluded.

Verified

pnpm test:browser   # 85 passed, the 10 ported suites included (the only failure is network.test.ts needing an `httpbin` template this account lacks)
pnpm exec vitest run --project unit tests/client.test.ts tests/sandbox/{abortSignal,egressProxy,iam,lifecycleRequest,networkTransform,onResumeRequest}.test.ts tests/secret/secret.test.ts tests/volume/{file,volume}.test.ts   # 181 passed, 1 skipped
pnpm lint && pnpm typecheck

No SDK source changes, so no changeset.

Link to Devin session: https://app.devin.ai/sessions/5c01919711e14a1a8ec90fba1505e4e8
Open in Devin Desktop: https://app.devin.ai/desktop/session/5c01919711e14a1a8ec90fba1505e4e8?variant=devin
Requested by: @mishushakov

Add a runtime-aware setupMockApi helper: msw/node's setupServer on Node and
the compat runtimes, msw/browser's setupWorker behind a Service Worker in
Chromium. The browser vitest config swaps the module and serves
mockServiceWorker.js from the installed msw package. Port the ten suites that
imported msw/node directly and drop them from the browser exclude list.

Co-Authored-By: mish@e2b.dev <mish@e2b.dev>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@cla-bot cla-bot Bot added the cla-signed label Sep 11, 2026
@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 80db902

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

@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 87518c4. Download artifacts from this workflow run.

JS SDK (e2b@2.48.1-devin-1789147597-browser-msw-worker.0):

npm install ./e2b-2.48.1-devin-1789147597-browser-msw-worker.0.tgz

CLI (@e2b/cli@2.18.3-devin-1789147597-browser-msw-worker.0):

npm install ./e2b-cli-2.18.3-devin-1789147597-browser-msw-worker.0.tgz

Code Interpreter JS SDK (@e2b/code-interpreter@2.8.1-devin-1789147597-browser-msw-worker.0):

npm install ./e2b-code-interpreter-2.8.1-devin-1789147597-browser-msw-worker.0.tgz

Desktop JS SDK (@e2b/desktop@2.4.1-devin-1789147597-browser-msw-worker.0):

npm install ./e2b-desktop-2.4.1-devin-1789147597-browser-msw-worker.0.tgz

Python SDK (e2b==2.48.0+devin.1789147597.browser.msw.worker):

pip install ./e2b-2.48.0+devin.1789147597.browser.msw.worker-py3-none-any.whl

Code Interpreter Python SDK (e2b-code-interpreter==2.10.0+devin.1789147597.browser.msw.worker):

pip install ./e2b_code_interpreter-2.10.0+devin.1789147597.browser.msw.worker-py3-none-any.whl

Desktop Python SDK (e2b-desktop==2.5.0+devin.1789147597.browser.msw.worker):

pip install ./e2b_desktop-2.5.0+devin.1789147597.browser.msw.worker-py3-none-any.whl

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TASTE.md review — no violations found.

The diff is test infrastructure only (tests/mockApi.ts, tests/runtimes/browser/mockApi.ts, the browser vitest config, and the import swap in the ten msw suites) — no public SDK surface changes, so most of TASTE.md doesn't bind here. Checked anyway against the rules that could apply to new SDK-owned code: T-1/T-2 (no JS-only behavior added that needs a Python mirror — this is JS test tooling), T-3/T-3a (setupMockApi(...handlers) mirrors setupServer; listen(options?) keeps optionals in a trailing object), T-12 (MockApi, nodeMockApi, browserMockApi case the acronym as a word; the all-caps secretID/volumeID are wire fields, which T-12 explicitly exempts), T-19 (MockApi is a type, not a class), T-20 (resolveId returns undefined, not null), T-54 (nothing added to the package entry point), T-56 (msw's worker script is resolved from the installed package rather than pinned/copied, so no version string is hardcoded).

Two notes that are deliberate rather than violations: the listen/close pair reads against T-30 ("what you start, you stop"), but T-30 governs SDK *Handle classes and close() is the right name when mirroring the wrapped msw SetupServer/SetupWorker API — consistency with the library beats local optimality. And test.skipIf(runtime === 'browser') on client.Template builds template instances is a test-harness exclusion, not a parity break in the surface itself (the builder is Node-only for the same reason tests/template/** is excluded).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant