@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.
- package/.turbo/turbo-build.log +17 -9
- package/CHANGELOG.md +18 -0
- package/dist/dist-gVyG2H2h.js +612 -0
- package/dist/dist-gVyG2H2h.js.map +1 -0
- package/dist/index.d.ts +14 -1720
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -698
- package/dist/index.js.map +1 -1
- package/dist/openai/index.d.ts +67 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +362 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/sandbox-HQazw9bn.d.ts +1741 -0
- package/dist/sandbox-HQazw9bn.d.ts.map +1 -0
- package/package.json +15 -1
- package/src/clients/command-client.ts +31 -13
- package/src/clients/process-client.ts +20 -2
- package/src/openai/index.ts +465 -0
- package/src/sandbox.ts +103 -47
- package/src/version.ts +1 -1
- package/tests/git-client.test.ts +7 -39
- package/tests/openai-shell-editor.test.ts +434 -0
- package/tests/port-client.test.ts +25 -35
- package/tests/process-client.test.ts +73 -107
- package/tests/sandbox.test.ts +65 -35
- package/tsconfig.json +2 -2
- package/tsdown.config.ts +1 -1
package/tests/sandbox.test.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
{
|
|
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
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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
|
-
|
|
751
|
-
|
|
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
|
-
|
|
765
|
-
|
|
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
|
-
|
|
784
|
-
|
|
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
|
-
|
|
801
|
-
|
|
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
|
-
|
|
819
|
-
|
|
848
|
+
url: '',
|
|
849
|
+
timestamp: '2023-01-01T00:00:00Z'
|
|
820
850
|
});
|
|
821
851
|
|
|
822
852
|
await expect(
|
package/tsconfig.json
CHANGED