@cloudflare/sandbox 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -76,6 +76,7 @@ describe('Sandbox - Automatic Session Management', () => {
76
76
  .mockImplementation(
77
77
  <T>(callback: () => Promise<T>): Promise<T> => callback()
78
78
  ),
79
+ waitUntil: vi.fn(),
79
80
  id: {
80
81
  toString: () => 'test-sandbox-id',
81
82
  equals: vi.fn(),
@@ -86,7 +87,7 @@ describe('Sandbox - Automatic Session Management', () => {
86
87
  mockEnv = {};
87
88
 
88
89
  // Create Sandbox instance - SandboxClient is created internally
89
- const stub = new Sandbox(mockCtx, mockEnv);
90
+ const stub = new Sandbox(mockCtx as DurableObjectState<{}>, mockEnv);
90
91
 
91
92
  // Wait for blockConcurrencyWhile to complete
92
93
  await vi.waitFor(() => {
@@ -138,15 +139,35 @@ describe('Sandbox - Automatic Session Management', () => {
138
139
  await sandbox.exec('echo test');
139
140
 
140
141
  expect(sandbox.client.utils.createSession).toHaveBeenCalledTimes(1);
141
- expect(sandbox.client.utils.createSession).toHaveBeenCalledWith({
142
- id: expect.stringMatching(/^sandbox-/),
143
- env: {},
144
- cwd: '/workspace'
145
- });
142
+ expect(sandbox.client.utils.createSession).toHaveBeenCalledWith(
143
+ expect.objectContaining({
144
+ id: expect.stringMatching(/^sandbox-/),
145
+ cwd: '/workspace'
146
+ })
147
+ );
146
148
 
147
149
  expect(sandbox.client.commands.execute).toHaveBeenCalledWith(
148
150
  'echo test',
149
- expect.stringMatching(/^sandbox-/)
151
+ expect.stringMatching(/^sandbox-/),
152
+ undefined
153
+ );
154
+ });
155
+
156
+ it('should forward exec options to the command client', async () => {
157
+ await sandbox.exec('echo $OPTION', {
158
+ env: { OPTION: 'value' },
159
+ cwd: '/workspace/project',
160
+ timeout: 5000
161
+ });
162
+
163
+ expect(sandbox.client.commands.execute).toHaveBeenCalledWith(
164
+ 'echo $OPTION',
165
+ expect.stringMatching(/^sandbox-/),
166
+ {
167
+ timeoutMs: 5000,
168
+ env: { OPTION: 'value' },
169
+ cwd: '/workspace/project'
170
+ }
150
171
  );
151
172
  });
152
173
 
@@ -240,11 +261,12 @@ describe('Sandbox - Automatic Session Management', () => {
240
261
 
241
262
  await sandbox.exec('pwd');
242
263
 
243
- expect(sandbox.client.utils.createSession).toHaveBeenCalledWith({
244
- id: 'sandbox-my-sandbox',
245
- env: {},
246
- cwd: '/workspace'
247
- });
264
+ expect(sandbox.client.utils.createSession).toHaveBeenCalledWith(
265
+ expect.objectContaining({
266
+ id: 'sandbox-my-sandbox',
267
+ cwd: '/workspace'
268
+ })
269
+ );
248
270
  });
249
271
  });
250
272
 
@@ -288,7 +310,8 @@ describe('Sandbox - Automatic Session Management', () => {
288
310
 
289
311
  expect(sandbox.client.commands.execute).toHaveBeenCalledWith(
290
312
  'echo test',
291
- 'isolated-session'
313
+ 'isolated-session',
314
+ undefined
292
315
  );
293
316
  });
294
317
 
@@ -366,11 +389,11 @@ describe('Sandbox - Automatic Session Management', () => {
366
389
 
367
390
  await sandbox.createSession();
368
391
 
369
- expect(sandbox.client.utils.createSession).toHaveBeenCalledWith({
370
- id: expect.stringMatching(/^session-/),
371
- env: undefined,
372
- cwd: undefined
373
- });
392
+ expect(sandbox.client.utils.createSession).toHaveBeenCalledWith(
393
+ expect.objectContaining({
394
+ id: expect.stringMatching(/^session-/)
395
+ })
396
+ );
374
397
  });
375
398
  });
376
399
 
@@ -391,7 +414,8 @@ describe('Sandbox - Automatic Session Management', () => {
391
414
  await session.exec('pwd');
392
415
  expect(sandbox.client.commands.execute).toHaveBeenCalledWith(
393
416
  'pwd',
394
- 'test-session'
417
+ 'test-session',
418
+ undefined
395
419
  );
396
420
  });
397
421
 
@@ -412,7 +436,7 @@ describe('Sandbox - Automatic Session Management', () => {
412
436
  expect(sandbox.client.processes.startProcess).toHaveBeenCalledWith(
413
437
  'sleep 10',
414
438
  'test-session',
415
- { processId: undefined }
439
+ {}
416
440
  );
417
441
  });
418
442
 
@@ -467,11 +491,12 @@ describe('Sandbox - Automatic Session Management', () => {
467
491
  it('should initialize with empty environment when not set', async () => {
468
492
  await sandbox.exec('pwd');
469
493
 
470
- expect(sandbox.client.utils.createSession).toHaveBeenCalledWith({
471
- id: expect.any(String),
472
- env: {},
473
- cwd: '/workspace'
474
- });
494
+ expect(sandbox.client.utils.createSession).toHaveBeenCalledWith(
495
+ expect.objectContaining({
496
+ id: expect.any(String),
497
+ cwd: '/workspace'
498
+ })
499
+ );
475
500
  });
476
501
 
477
502
  it('should use updated environment after setEnvVars', async () => {
@@ -746,9 +771,10 @@ describe('Sandbox - Automatic Session Management', () => {
746
771
  await sandbox.setSandboxName('MyProject-123', false);
747
772
 
748
773
  vi.spyOn(sandbox.client.ports, 'exposePort').mockResolvedValue({
774
+ success: true,
749
775
  port: 8080,
750
- token: 'test-token-1234',
751
- previewUrl: ''
776
+ url: '',
777
+ timestamp: '2023-01-01T00:00:00Z'
752
778
  });
753
779
 
754
780
  await expect(
@@ -760,9 +786,10 @@ describe('Sandbox - Automatic Session Management', () => {
760
786
  await sandbox.setSandboxName('my-project', false);
761
787
 
762
788
  vi.spyOn(sandbox.client.ports, 'exposePort').mockResolvedValue({
789
+ success: true,
763
790
  port: 8080,
764
- token: 'mock-token',
765
- previewUrl: ''
791
+ url: '',
792
+ timestamp: '2023-01-01T00:00:00Z'
766
793
  });
767
794
 
768
795
  const result = await sandbox.exposePort(8080, {
@@ -779,9 +806,10 @@ describe('Sandbox - Automatic Session Management', () => {
779
806
  await sandbox.setSandboxName('myproject-123', true);
780
807
 
781
808
  vi.spyOn(sandbox.client.ports, 'exposePort').mockResolvedValue({
809
+ success: true,
782
810
  port: 4000,
783
- token: 'mock-token',
784
- previewUrl: ''
811
+ url: '',
812
+ timestamp: '2023-01-01T00:00:00Z'
785
813
  });
786
814
 
787
815
  const result = await sandbox.exposePort(4000, { hostname: 'my-app.dev' });
@@ -796,9 +824,10 @@ describe('Sandbox - Automatic Session Management', () => {
796
824
  await sandbox.setSandboxName('test-sandbox', false);
797
825
 
798
826
  vi.spyOn(sandbox.client.ports, 'exposePort').mockResolvedValue({
827
+ success: true,
799
828
  port: 8080,
800
- token: 'mock-token',
801
- previewUrl: ''
829
+ url: '',
830
+ timestamp: '2023-01-01T00:00:00Z'
802
831
  });
803
832
 
804
833
  const result = await sandbox.exposePort(8080, {
@@ -814,9 +843,10 @@ describe('Sandbox - Automatic Session Management', () => {
814
843
  await sandbox.setSandboxName('MyProject-ABC', false);
815
844
 
816
845
  vi.spyOn(sandbox.client.ports, 'exposePort').mockResolvedValue({
846
+ success: true,
817
847
  port: 8080,
818
- token: 'test-token-1234',
819
- previewUrl: ''
848
+ url: '',
849
+ timestamp: '2023-01-01T00:00:00Z'
820
850
  });
821
851
 
822
852
  await expect(
package/tsconfig.json CHANGED
@@ -6,6 +6,6 @@
6
6
  "lib": ["ES2022"],
7
7
  "resolveJsonModule": true
8
8
  },
9
- "include": ["src/**/*.ts"],
10
- "exclude": ["tests/**", "node_modules", "dist"]
9
+ "include": ["src/**/*.ts", "tests/**/*.ts"],
10
+ "exclude": ["node_modules", "dist"]
11
11
  }
package/tsdown.config.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineConfig } from 'tsdown';
2
2
 
3
3
  export default defineConfig({
4
- entry: 'src/index.ts',
4
+ entry: ['src/index.ts', 'src/openai/index.ts'],
5
5
  outDir: 'dist',
6
6
  dts: {
7
7
  sourcemap: true,