Skip to content

Commit 3b748af

Browse files
committed
Remove createSandboxFetch and inline the one-liner
1 parent cf181ee commit 3b748af

File tree

9 files changed

+22
-138
lines changed

9 files changed

+22
-138
lines changed

examples/opencode/src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { getSandbox } from '@cloudflare/sandbox';
99
import { createOpencode, proxyToOpencode } from '@cloudflare/sandbox/opencode';
1010
import type { Config, OpencodeClient } from '@opencode-ai/sdk';
1111

12+
export { Sandbox } from '@cloudflare/sandbox';
13+
1214
const getConfig = (env: Env): Config => ({
1315
provider: {
1416
anthropic: {
@@ -52,7 +54,6 @@ async function handleSdkTest(
5254
config: getConfig(env)
5355
});
5456

55-
console.log('Client created:', client);
5657
// Create a session
5758
const session = await client.session.create({
5859
body: { title: 'Test Session' },
@@ -63,7 +64,6 @@ async function handleSdkTest(
6364
throw new Error(`Failed to create session: ${JSON.stringify(session)}`);
6465
}
6566

66-
console.log('Session created:', session.data);
6767
// Send a prompt using the SDK
6868
const promptResult = await client.session.prompt({
6969
path: { id: session.data.id },
@@ -82,7 +82,6 @@ async function handleSdkTest(
8282
}
8383
});
8484

85-
console.log('Prompt result:', promptResult.data);
8685
// Extract text response from result
8786
const parts = promptResult.data?.parts ?? [];
8887
const textPart = parts.find((p: { type: string }) => p.type === 'text') as
@@ -102,6 +101,3 @@ async function handleSdkTest(
102101
);
103102
}
104103
}
105-
106-
// Export Sandbox DO for wrangler
107-
export { Sandbox } from '@cloudflare/sandbox';

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sandbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"check": "biome check && npm run typecheck",
4040
"fix": "biome check --fix && npm run typecheck",
4141
"typecheck": "tsc --noEmit",
42-
"docker:local": "cd ../.. && docker build -f packages/sandbox/Dockerfile --target default --platform linux/amd64 --build-arg SANDBOX_VERSION=$npm_package_version -t cloudflare/sandbox-test:$npm_package_version . && docker build -f packages/sandbox/Dockerfile --target python --platform linux/amd64 --build-arg SANDBOX_VERSION=$npm_package_version -t cloudflare/sandbox-test:$npm_package_version-python .",
42+
"docker:local": "cd ../.. && docker build -f packages/sandbox/Dockerfile --target default --platform linux/amd64 --build-arg SANDBOX_VERSION=$npm_package_version -t cloudflare/sandbox-test:$npm_package_version . && docker build -f packages/sandbox/Dockerfile --target python --platform linux/amd64 --build-arg SANDBOX_VERSION=$npm_package_version -t cloudflare/sandbox-test:$npm_package_version-python . && docker build -f packages/sandbox/Dockerfile --target opencode --platform linux/amd64 --build-arg SANDBOX_VERSION=$npm_package_version -t cloudflare/sandbox-test:$npm_package_version-opencode .",
4343
"test": "vitest run --config vitest.config.ts \"$@\"",
4444
"test:e2e": "cd ../../tests/e2e/test-worker && ./generate-config.sh && cd ../../.. && vitest run --config vitest.e2e.config.ts \"$@\""
4545
},

packages/sandbox/src/opencode/fetch.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/sandbox/src/opencode/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
* @packageDocumentation
3838
*/
3939

40-
export { createSandboxFetch } from './fetch';
4140
export { createOpencode, proxyToOpencode } from './opencode';
4241
export type {
4342
OpencodeOptions,

packages/sandbox/src/opencode/opencode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Config } from '@opencode-ai/sdk';
22
import { createLogger, type Logger, type Process } from '@repo/shared';
33
import type { Sandbox } from '../sandbox';
4-
import { createSandboxFetch } from './fetch';
54
import type {
65
OpencodeOptions,
76
OpencodeResult,
@@ -248,7 +247,7 @@ export async function createOpencode<TClient = unknown>(
248247

249248
const client = clientFactory({
250249
baseUrl: `http://localhost:${port}`,
251-
fetch: createSandboxFetch(sandbox, port)
250+
fetch: (request: Request) => sandbox.containerFetch(request, port)
252251
});
253252

254253
// Build server handle

packages/sandbox/tests/opencode/fetch.test.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/sandbox/tests/opencode/opencode.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ describe('createOpencode', () => {
158158
stderr: 'Server crashed'
159159
});
160160

161-
await expect(
162-
createOpencode(mockSandbox as unknown as Sandbox)
163-
).rejects.toThrow(OpencodeStartupError);
164161
await expect(
165162
createOpencode(mockSandbox as unknown as Sandbox)
166163
).rejects.toThrow(/Server crashed/);
@@ -242,9 +239,6 @@ describe('createOpencode', () => {
242239
});
243240
mockSandbox.listProcesses.mockResolvedValue([startingProcess]);
244241

245-
await expect(
246-
createOpencode(mockSandbox as unknown as Sandbox)
247-
).rejects.toThrow(OpencodeStartupError);
248242
await expect(
249243
createOpencode(mockSandbox as unknown as Sandbox)
250244
).rejects.toThrow(/Startup failed/);

tests/e2e/opencode-workflow.test.ts

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
/**
22
* E2E Test: OpenCode Integration Workflow
33
*
4-
* Tests the complete OpenCode integration including:
5-
* - OpenCode CLI availability in the container
6-
* - Server startup via SDK
7-
* - Process reuse for existing servers
8-
* - Basic SDK client operations
9-
*
10-
* These tests require the -opencode container variant which includes
11-
* the OpenCode CLI pre-installed.
4+
* Tests:
5+
* - OpenCode CLI availability in the -opencode container variant
6+
* - Server startup and lifecycle via process API
127
*/
138

149
import { beforeAll, describe, expect, test } from 'vitest';
@@ -28,31 +23,16 @@ describe('OpenCode Workflow (E2E)', () => {
2823
headers = sandbox.createOpencodeHeaders(createUniqueSession());
2924
}, 120000);
3025

31-
describe('OpenCode CLI availability', () => {
32-
test('should have opencode command available', async () => {
33-
const res = await fetch(`${workerUrl}/api/execute`, {
34-
method: 'POST',
35-
headers,
36-
body: JSON.stringify({ command: 'which opencode' })
37-
});
38-
expect(res.status).toBe(200);
39-
const result = (await res.json()) as ExecResult;
40-
expect(result.exitCode).toBe(0);
41-
expect(result.stdout).toContain('opencode');
42-
});
43-
44-
test('should report opencode version', async () => {
45-
const res = await fetch(`${workerUrl}/api/execute`, {
46-
method: 'POST',
47-
headers,
48-
body: JSON.stringify({ command: 'opencode --version' })
49-
});
50-
expect(res.status).toBe(200);
51-
const result = (await res.json()) as ExecResult;
52-
expect(result.exitCode).toBe(0);
53-
// Version output should contain version number
54-
expect(result.stdout).toMatch(/\d+\.\d+/);
26+
test('should have opencode CLI available', async () => {
27+
const res = await fetch(`${workerUrl}/api/execute`, {
28+
method: 'POST',
29+
headers,
30+
body: JSON.stringify({ command: 'opencode --version' })
5531
});
32+
expect(res.status).toBe(200);
33+
const result = (await res.json()) as ExecResult;
34+
expect(result.exitCode).toBe(0);
35+
expect(result.stdout).toMatch(/\d+\.\d+/);
5636
});
5737

5838
describe('OpenCode server lifecycle', () => {
@@ -100,13 +80,12 @@ describe('OpenCode Workflow (E2E)', () => {
10080
expect(opencodeProcess).toBeDefined();
10181
expect(opencodeProcess?.status).toBe('running');
10282

103-
// Kill the server
83+
// Kill the server (DELETE method)
10484
const killRes = await fetch(
105-
`${workerUrl}/api/process/${startResult.id}/kill`,
85+
`${workerUrl}/api/process/${startResult.id}`,
10686
{
107-
method: 'POST',
108-
headers,
109-
body: JSON.stringify({ signal: 'SIGTERM' })
87+
method: 'DELETE',
88+
headers
11089
}
11190
);
11291
expect(killRes.status).toBe(200);

0 commit comments

Comments
 (0)