Skip to content

Commit ff7138a

Browse files
committed
Run JS tests on base image and use dynamic version in error message
JavaScript-only E2E tests now run against the base image to validate the lean image works correctly for non-Python workloads. This provides coverage for the bundled JS executor without requiring Python. The Python unavailable error message now uses SANDBOX_VERSION env var when available, falling back to <version> placeholder. This gives users the exact version to use in production while keeping the placeholder for development.
1 parent f9bea1a commit ff7138a

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

packages/sandbox-container/src/runtime/process-pool.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ export class ProcessPoolManager {
231231

232232
// Check if Python is available
233233
if (language === 'python' && !PYTHON_AVAILABLE) {
234+
const version = process.env.SANDBOX_VERSION || '<version>';
234235
return {
235236
stdout: '',
236-
stderr:
237-
'Python interpreter not available. Use the cloudflare/sandbox:<version>-python image variant for Python code execution. See https://developers.cloudflare.com/sandbox/configuration/dockerfile/',
237+
stderr: `Python interpreter not available. Use the cloudflare/sandbox:${version}-python image variant for Python code execution. See https://developers.cloudflare.com/sandbox/configuration/dockerfile/`,
238238
success: false,
239239
executionId: randomUUID(),
240240
outputs: [],
@@ -563,8 +563,9 @@ export class ProcessPoolManager {
563563
): Promise<void> {
564564
// Check if Python is available before trying to create a context
565565
if (language === 'python' && !PYTHON_AVAILABLE) {
566+
const version = process.env.SANDBOX_VERSION || '<version>';
566567
throw new Error(
567-
'Python interpreter not available. Use the cloudflare/sandbox:<version>-python image variant for Python code execution. See https://developers.cloudflare.com/sandbox/configuration/dockerfile/'
568+
`Python interpreter not available. Use the cloudflare/sandbox:${version}-python image variant for Python code execution. See https://developers.cloudflare.com/sandbox/configuration/dockerfile/`
568569
);
569570
}
570571

tests/e2e/code-interpreter-workflow.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('Code Interpreter Workflow (E2E)', () => {
267267

268268
test('should execute simple JavaScript code', async () => {
269269
currentSandboxId = createSandboxId();
270-
const headers = createTestHeaders(currentSandboxId);
270+
const headers = createBaseImageHeaders(currentSandboxId);
271271

272272
// Create JavaScript context
273273
const ctxResponse = await fetch(`${workerUrl}/api/code/context/create`, {
@@ -297,7 +297,7 @@ describe('Code Interpreter Workflow (E2E)', () => {
297297

298298
test('should maintain JavaScript state across executions', async () => {
299299
currentSandboxId = createSandboxId();
300-
const headers = createTestHeaders(currentSandboxId);
300+
const headers = createBaseImageHeaders(currentSandboxId);
301301

302302
// Create context
303303
const ctxResponse = await fetch(`${workerUrl}/api/code/context/create`, {
@@ -337,7 +337,7 @@ describe('Code Interpreter Workflow (E2E)', () => {
337337

338338
test('should handle JavaScript errors gracefully', async () => {
339339
currentSandboxId = createSandboxId();
340-
const headers = createTestHeaders(currentSandboxId);
340+
const headers = createBaseImageHeaders(currentSandboxId);
341341

342342
// Create context
343343
const ctxResponse = await fetch(`${workerUrl}/api/code/context/create`, {
@@ -583,7 +583,7 @@ console.log('Sum:', sum);
583583

584584
test('should maintain isolation across many contexts (12+)', async () => {
585585
currentSandboxId = createSandboxId();
586-
const headers = createTestHeaders(currentSandboxId);
586+
const headers = createBaseImageHeaders(currentSandboxId);
587587

588588
// Create 12 contexts
589589
const contexts: CodeContext[] = [];
@@ -653,7 +653,7 @@ console.log('Sum:', sum);
653653

654654
test('should maintain state isolation with concurrent context execution', async () => {
655655
currentSandboxId = createSandboxId();
656-
const headers = createTestHeaders(currentSandboxId);
656+
const headers = createBaseImageHeaders(currentSandboxId);
657657

658658
// Create contexts sequentially
659659
const contexts: CodeContext[] = [];
@@ -734,7 +734,7 @@ console.log('Sum:', sum);
734734

735735
test('should prevent concurrent execution on same context', async () => {
736736
currentSandboxId = createSandboxId();
737-
const headers = createTestHeaders(currentSandboxId);
737+
const headers = createBaseImageHeaders(currentSandboxId);
738738

739739
// Create single context
740740
const ctxResponse = await fetch(`${workerUrl}/api/code/context/create`, {
@@ -911,6 +911,6 @@ console.log('Sum:', sum);
911911

912912
// Error should guide users to the correct image variant
913913
expect(errorData.message).toContain('Python interpreter not available');
914-
expect(errorData.message).toContain('-python');
914+
expect(errorData.message).toMatch(/-python/);
915915
}, 120000);
916916
});

tests/e2e/helpers/test-fixtures.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ export function createTestHeaders(
6666
* The base image is smaller but only supports JavaScript/shell execution.
6767
*
6868
* @param sandboxId - Which container instance to use
69+
* @param sessionId - (Optional) Which session within that container
6970
*/
7071
export function createBaseImageHeaders(
71-
sandboxId: string
72+
sandboxId: string,
73+
sessionId?: string
7274
): Record<string, string> {
7375
return {
74-
'Content-Type': 'application/json',
75-
'X-Sandbox-Id': sandboxId,
76+
...createTestHeaders(sandboxId, sessionId),
7677
'X-Sandbox-Type': 'base'
7778
};
7879
}

0 commit comments

Comments
 (0)