Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/js-sdk/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ async function buildTemplate(
memoryMB: 1024,
skipCache: options?.skipCache,
onBuildLogs: captureLogs,
// The placeholder key keeps the mocked template tests independent of
// E2B_API_KEY being set in the environment.
apiKey: process.env.E2B_API_KEY ?? TEST_API_KEY,

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.

T-50 — an env var set to the empty string means unset. ?? only falls through on undefined/null, so an exported-but-empty E2B_API_KEY='' gets passed as an explicit (highest-precedence) apiKey option and reaches the transport as a malformed credential instead of falling back to TEST_API_KEY.

Suggested change
apiKey: process.env.E2B_API_KEY ?? TEST_API_KEY,
apiKey: process.env.E2B_API_KEY || TEST_API_KEY,

The same pattern appears in the other new fallbacks: template/backgroundBuild.test.ts:15, template/exists.test.ts:15, and template/tags.test.ts:64.

})
} catch (e) {
console.error(
Expand Down
17 changes: 15 additions & 2 deletions packages/js-sdk/tests/template/backgroundBuild.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { randomUUID } from 'node:crypto'
import { expect, test } from 'vitest'
import { afterAll, beforeAll, expect, test } from 'vitest'
import { setupServer } from 'msw/node'
import { Template, waitForTimeout } from '../../src'
import { TEST_API_KEY } from '../setup'
import { createMockBuildApi } from './mockBuildApi'

const server = setupServer(...createMockBuildApi().handlers)

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
afterAll(() => server.close())

// The placeholder key keeps the mocked template tests independent of
// E2B_API_KEY being set in the environment.
const apiKey = process.env.E2B_API_KEY ?? TEST_API_KEY

test('build template in background', async () => {
const template = Template()
Expand All @@ -14,12 +26,13 @@ test('build template in background', async () => {
const buildInfo = await Template.buildInBackground(template, name, {
cpuCount: 1,
memoryMB: 1024,
apiKey,
})

// Should return quickly (within a few seconds), not wait for the full build
expect(buildInfo).toBeDefined()

// Verify the build is actually running
const status = await Template.getBuildStatus(buildInfo)
const status = await Template.getBuildStatus(buildInfo, { apiKey })
expect(status.status).toEqual('building')
}, 10_000)
7 changes: 7 additions & 0 deletions packages/js-sdk/tests/template/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { afterAll, beforeAll } from 'vitest'
import { setupServer } from 'msw/node'
import { defaultBuildLogger, Template, waitForTimeout } from '../../src'
import { buildTemplateTest } from '../setup'
import { createMockBuildApi } from './mockBuildApi'

const server = setupServer(...createMockBuildApi().handlers)

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
afterAll(() => server.close())

// The file context lives in a temp directory so a test run never writes into
// the repository tree. It is created in beforeAll rather than at module load so
Expand Down
18 changes: 15 additions & 3 deletions packages/js-sdk/tests/template/exists.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { randomUUID } from 'node:crypto'
import { expect, test } from 'vitest'
import { afterAll, beforeAll, expect, test } from 'vitest'
import { setupServer } from 'msw/node'
import { Template } from '../../src'
import { TEST_API_KEY } from '../setup'
import { createMockBuildApi } from './mockBuildApi'

const server = setupServer(...createMockBuildApi().handlers)

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
afterAll(() => server.close())

// The placeholder key keeps the mocked template tests independent of
// E2B_API_KEY being set in the environment.
const apiKey = process.env.E2B_API_KEY ?? TEST_API_KEY

test('check if base template name exists', async () => {
const exists = await Template.exists('base')
const exists = await Template.exists('base', { apiKey })
expect(exists).toBe(true)
})

test('check non existing name', async () => {
const nonExistingName = `nonexistent-${randomUUID()}`
const exists = await Template.exists(nonExistingName)
const exists = await Template.exists(nonExistingName, { apiKey })
expect(exists).toBe(false)
})
8 changes: 8 additions & 0 deletions packages/js-sdk/tests/template/methods/makeSymlink.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { afterAll, beforeAll } from 'vitest'
import { setupServer } from 'msw/node'
import { Template } from '../../../src'
import { buildTemplateTest } from '../../setup'
import { createMockBuildApi } from '../mockBuildApi'

const server = setupServer(...createMockBuildApi().handlers)

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
afterAll(() => server.close())

buildTemplateTest('make symlink', async ({ buildTemplate }) => {
const template = Template()
Expand Down
9 changes: 8 additions & 1 deletion packages/js-sdk/tests/template/methods/runCmd.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { expect } from 'vitest'
import { afterAll, beforeAll, expect } from 'vitest'
import { setupServer } from 'msw/node'
import { Template } from '../../../src'
import { buildTemplateTest } from '../../setup'
import { createMockBuildApi } from '../mockBuildApi'

const server = setupServer(...createMockBuildApi().handlers)

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
afterAll(() => server.close())

buildTemplateTest('run command', async ({ buildTemplate }) => {
const template = Template()
Expand Down
Loading
Loading