Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
test(desktop-js): run the Desktop suite under Bun, Deno and Cloudflare workerd (#1773)
devin-ai-integration[bot]8e36fea0fbb3
diff --git a/.github/workflows/desktop_js_tests.yml b/.github/workflows/desktop_js_tests.ymlindex 8ce2aa65d..ea56c166b 100644--- a/.github/workflows/desktop_js_tests.yml+++ b/.github/workflows/desktop_js_tests.yml@@ -64,9 +64,41 @@ jobs:- name: Test buildrun: pnpm build- - name: Run tests+ - name: Run Node testsif: inputs.run_testsrun: pnpm testenv:E2B_API_KEY: ${{ secrets.E2B_API_KEY }}E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}++ - name: Install Bun+ if: inputs.run_tests+ uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0++ - name: Run Bun tests+ if: inputs.run_tests+ run: pnpm test:bun+ env:+ E2B_API_KEY: ${{ secrets.E2B_API_KEY }}+ E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}++ - name: Install Deno+ if: inputs.run_tests+ uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5+ with:+ deno-version: 'v${{ env.TOOL_VERSION_DENO }}'++ - name: Run Deno tests+ if: inputs.run_tests+ run: pnpm test:deno+ env:+ E2B_API_KEY: ${{ secrets.E2B_API_KEY }}+ E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}++ # Runs the same suite as the Node leg inside workerd (vitest-pool-workers).+ - name: Run test suite under Cloudflare workerd+ if: inputs.run_tests+ run: pnpm test:cf+ env:+ E2B_API_KEY: ${{ secrets.E2B_API_KEY }}+ E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}diff --git a/packages/desktop-js/package.json b/packages/desktop-js/package.jsonindex 3605f704b..c13e7907f 100644--- a/packages/desktop-js/package.json+++ b/packages/desktop-js/package.json@@ -50,11 +50,15 @@"build": "tsc --noEmit && tsdown","dev": "tsdown --watch","test": "vitest run --disable-console-intercept",+ "test:bun": "bunx --bun vitest run",+ "test:cf": "vitest run --config tests/runtimes/cloudflare/vitest.config.mts",+ "test:deno": "deno run -A ./node_modules/vitest/vitest.mjs run","typecheck": "tsc --noEmit","lint": "oxlint --config ../../.oxlintrc.json src tests","format": "prettier --write src/ tests/"},"devDependencies": {+ "@cloudflare/vitest-pool-workers": "^0.18.7","@typescript/native": "catalog:","@types/node": "catalog:","dotenv": "^16.4.5",diff --git a/packages/desktop-js/src/sandbox.ts b/packages/desktop-js/src/sandbox.tsindex 9e2a13507..01ef93d38 100644--- a/packages/desktop-js/src/sandbox.ts+++ b/packages/desktop-js/src/sandbox.ts@@ -266,7 +266,10 @@ export class Sandbox extends SandboxBase {// @ts-expect-errorconst file = await this.files.read(path, { format })- this.files.remove(path)+ // Cleanup of the temporary file is best-effort: it must not block the+ // returned file (which may be an unconsumed stream) and must not reject+ // if the sandbox is already gone.+ void this.files.remove(path).catch(() => {})return file}diff --git a/packages/desktop-js/tests/runtimes/cloudflare/vitest.config.mts b/packages/desktop-js/tests/runtimes/cloudflare/vitest.config.mtsnew file mode 100644index 000000000..31a82c426--- /dev/null+++ b/packages/desktop-js/tests/runtimes/cloudflare/vitest.config.mts@@ -0,0 +1,50 @@+import { cloudflareTest } from '@cloudflare/vitest-pool-workers'+import { config } from 'dotenv'+import { defineConfig } from 'vitest/config'++const env = config()++// Runs the Desktop suite inside Cloudflare's workerd via vitest-pool-workers,+// against src — the same coverage as test:bun / test:deno get from the Node+// suite, but exercising the Workers runtime's fetch/streams implementations.+export default defineConfig({+ plugins: [+ cloudflareTest({+ miniflare: {+ compatibilityDate: '2026-03-01',+ // nodejs_compat is a hard requirement for the SDK on Workers. It also+ // mirrors the bindings below into process.env (default since compat+ // date 2025-04-01), which is how tests and the SDK read E2B_*.+ compatibilityFlags: ['nodejs_compat'],+ bindings: {+ E2B_API_KEY: process.env.E2B_API_KEY ?? env.parsed?.E2B_API_KEY ?? '',+ E2B_DOMAIN: process.env.E2B_DOMAIN ?? env.parsed?.E2B_DOMAIN ?? '',+ },+ },+ }),+ ],+ test: {+ name: 'cloudflare',+ include: ['tests/**/*.test.ts'],+ exclude: ['tests/runtimes/**'],+ globals: false,+ testTimeout: 60_000,+ bail: 0,+ // workerd reports a rejection as unhandled unless a handler is attached+ // within the same microtask drain, and vitest never processes the+ // rejectionhandled retraction, so the aborts the SDK itself provokes when+ // a test's sandbox is killed mid-stream false-positive the run. Drop only+ // those shapes; uncaught exceptions and any unknown rejection still fail.+ onUnhandledError(error) {+ const message = String(error.message ?? '')+ const expectedRejection =+ error.type === 'Unhandled Rejection' &&+ (error.name === 'AbortError' ||+ error.name === 'ConnectError' ||+ message.startsWith('ConnectError:') ||+ // workerd's teardown error for in-flight streams.+ message === 'Network connection lost.')+ if (expectedRejection) return false+ },+ },+})diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 655dcf703..4b652335a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -211,6 +211,9 @@ importers:specifier: workspace:^version: link:../js-sdkdevDependencies:+ '@cloudflare/vitest-pool-workers':+ specifier: ^0.18.7+ version: 0.18.7(@types/[email protected])(@vitest/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])'@types/node':specifier: 'catalog:'version: 20.19.43