chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:47:58 +08:00
commit b16403ea71
789 changed files with 115226 additions and 0 deletions
@@ -0,0 +1,53 @@
import { test, assert } from 'vitest'
import Sandbox from '../../src/index.js'
import { isIntegrationTest } from '../setup.js'
const integrationTestTemplate = 'en716jw99aj63v1k8ugh'
test.skipIf(!isIntegrationTest)(
'test python random number generation in same sandbox',
async () => {
const sbx = await Sandbox.create(integrationTestTemplate, {
timeoutMs: 120,
})
console.log('sandboxId', sbx.sandboxId)
const cmd1 = await sbx.commands.run(
'python -c "import numpy as np; print([np.random.normal(),np.random.normal(),np.random.normal()])"'
)
console.log('cmd1 stdout', cmd1.stdout)
const cmd2 = await sbx.commands.run(
'python -c "import numpy as np; print([np.random.normal(),np.random.normal(),np.random.normal()])"'
)
console.log('cmd2 stdout', cmd2.stdout)
assert.notEqual(cmd1.stdout, cmd2.stdout)
}
)
test.skipIf(!isIntegrationTest)(
'test python random number generation with same template',
async () => {
const sbx = await Sandbox.create(integrationTestTemplate, {
timeoutMs: 120,
})
console.log('sandboxId 1', sbx.sandboxId)
const cmd1 = await sbx.commands.run(
'python -c "import numpy as np; print([np.random.normal(),np.random.normal(),np.random.normal()])"'
)
console.log('cmd1 stdout', cmd1.stdout)
await sbx.kill()
const sbx2 = await Sandbox.create(integrationTestTemplate, {
timeoutMs: 120,
})
console.log('sandboxId 2', sbx2.sandboxId)
const cmd2 = await sbx2.commands.run(
'python -c "import numpy as np; print([np.random.normal(),np.random.normal(),np.random.normal()])"'
)
console.log('cmd2 stdout', cmd2.stdout)
assert.notEqual(cmd1.stdout, cmd2.stdout)
}
)
@@ -0,0 +1,77 @@
import { test } from 'vitest'
import Sandbox from '../../src/index.js'
import { isIntegrationTest, wait } from '../setup.js'
const heavyArray = new ArrayBuffer(256 * 1024 * 1024) // 256 MiB = 256 * 1024 * 1024 bytes
const view = new Uint8Array(heavyArray)
for (let i = 0; i < view.length; i++) {
view[i] = Math.floor(Math.random() * 256)
}
const integrationTestTemplate = 'integration-test-v1'
const sandboxCount = 10
test.skipIf(!isIntegrationTest)(
'stress test heavy file writes and reads',
async () => {
const promises: Array<Promise<string | void>> = []
for (let i = 0; i < sandboxCount; i++) {
promises.push(
Sandbox.create(integrationTestTemplate, { timeoutMs: 60 })
.then((sbx) => {
console.log(sbx.sandboxId)
return sbx.files
.write('heavy-file', heavyArray)
.then(() => sbx.files.read('heavy-file'))
})
.catch(console.error)
)
}
await wait(10_000)
await Promise.all(promises)
}
)
test.skipIf(!isIntegrationTest)('stress requests to nextjs app', async () => {
const hostPromises: Array<Promise<string | void>> = []
for (let i = 0; i < sandboxCount; i++) {
hostPromises.push(
Sandbox.create(integrationTestTemplate, { timeoutMs: 60_000 }).then(
(sbx) => {
console.log('created sandbox', sbx.sandboxId)
return new Promise((resolve, reject) => {
try {
resolve(sbx.getHost(3000))
} catch (e) {
console.error('error getting sbx host', e)
reject(e)
}
})
}
)
)
}
await wait(10_000)
const hosts = await Promise.all(hostPromises)
const fetchPromises: Array<Promise<string | void>> = []
for (let i = 0; i < 100; i++) {
for (const host of hosts) {
fetchPromises.push(
new Promise((resolve) => {
fetch('https://' + host)
.then((res) => {
console.log(`response for ${host}: ${res.status}`)
})
.then(resolve)
})
)
}
}
await Promise.all(fetchPromises)
})
@@ -0,0 +1,5 @@
# Integration test template
# Build the template
`$ e2b template build -c "cd /basic-nextjs-app/ && sudo npm run dev"`
@@ -0,0 +1,11 @@
FROM e2bdev/code-interpreter:latest
# Install stress-ng, a tool to load and stress computer systems
RUN apt update
RUN apt install -y stress-ng
# Create a basic Next.js app
RUN npx -y create-next-app@latest basic-nextjs-app --yes --ts --use-npm
# Install dependencies
RUN cd basic-nextjs-app && npm install
@@ -0,0 +1,18 @@
# This is a config for E2B sandbox template.
# You can use template ID (2e2z80zhv34yumbrybvn) or template name (integration-test-v1) to create a sandbox:
# Python SDK
# from e2b import Sandbox, AsyncSandbox
# sandbox = Sandbox("integration-test-v1") # Sync sandbox
# sandbox = await AsyncSandbox.create("integration-test-v1") # Async sandbox
# JS SDK
# import { Sandbox } from 'e2b'
# const sandbox = await Sandbox.create('integration-test-v1')
team_id = "460355b3-4f64-48f9-9a16-4442817f79f5"
memory_mb = 512
start_cmd = "npm run dev"
dockerfile = "e2b.Dockerfile"
template_name = "integration-test-v1"
template_id = "2e2z80zhv34yumbrybvn"