@cloudflare/sandbox 0.0.0-db09b4d โ†’ 0.0.0-e1fa354

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/Dockerfile +99 -11
  3. package/README.md +806 -22
  4. package/container_src/bun.lock +122 -0
  5. package/container_src/circuit-breaker.ts +121 -0
  6. package/container_src/control-process.ts +784 -0
  7. package/container_src/handler/exec.ts +185 -0
  8. package/container_src/handler/file.ts +406 -0
  9. package/container_src/handler/git.ts +130 -0
  10. package/container_src/handler/ports.ts +314 -0
  11. package/container_src/handler/process.ts +568 -0
  12. package/container_src/handler/session.ts +92 -0
  13. package/container_src/index.ts +448 -2467
  14. package/container_src/isolation.ts +1038 -0
  15. package/container_src/jupyter-server.ts +579 -0
  16. package/container_src/jupyter-service.ts +461 -0
  17. package/container_src/jupyter_config.py +48 -0
  18. package/container_src/mime-processor.ts +255 -0
  19. package/container_src/package.json +9 -0
  20. package/container_src/shell-escape.ts +42 -0
  21. package/container_src/startup.sh +84 -0
  22. package/container_src/types.ts +131 -0
  23. package/package.json +6 -8
  24. package/src/client.ts +477 -1192
  25. package/src/errors.ts +218 -0
  26. package/src/index.ts +63 -78
  27. package/src/interpreter-types.ts +383 -0
  28. package/src/interpreter.ts +150 -0
  29. package/src/jupyter-client.ts +349 -0
  30. package/src/request-handler.ts +144 -0
  31. package/src/sandbox.ts +747 -0
  32. package/src/security.ts +113 -0
  33. package/src/sse-parser.ts +147 -0
  34. package/src/types.ts +502 -0
  35. package/tsconfig.json +1 -1
  36. package/tests/client.example.ts +0 -308
  37. package/tests/connection-test.ts +0 -81
  38. package/tests/simple-test.ts +0 -81
  39. package/tests/test1.ts +0 -281
  40. package/tests/test2.ts +0 -710
package/tests/test2.ts DELETED
@@ -1,710 +0,0 @@
1
- import {
2
- createClient,
3
- HttpClient,
4
- quickDeleteFile,
5
- quickDeleteFileStream,
6
- quickExecute,
7
- quickExecuteStream,
8
- quickMoveFile,
9
- quickMoveFileStream,
10
- quickRenameFile,
11
- quickRenameFileStream,
12
- quickWriteFile,
13
- quickWriteFileStream,
14
- } from "../../sandbox/src/client";
15
-
16
- async function testHttpClient() {
17
- console.log("๐Ÿงช Testing HTTP Client...\n");
18
-
19
- // Test 1: Basic connection and ping
20
- console.log("Test 1: Basic connection and ping");
21
- try {
22
- const client = createClient();
23
- const pingResult = await client.ping();
24
- console.log("โœ… Ping result:", pingResult);
25
-
26
- const sessionId = await client.createSession();
27
- console.log("โœ… Session created:", sessionId);
28
- console.log("โœ… Connection test completed\n");
29
- } catch (error) {
30
- console.error("โŒ Test 1 failed:", error);
31
- }
32
-
33
- // Test 2: Command execution
34
- console.log("Test 2: Command execution");
35
- try {
36
- const result = await quickExecute("echo", ["Hello from HTTP client!"]);
37
- console.log("โœ… Command executed:", result.success);
38
- console.log(" Output:", result.stdout.trim());
39
- console.log(" Exit code:", result.exitCode, "\n");
40
- } catch (error) {
41
- console.error("โŒ Test 2 failed:", error);
42
- }
43
-
44
- // Test 3: Multiple commands with session
45
- console.log("Test 3: Multiple commands with session");
46
- try {
47
- const client = createClient();
48
- const sessionId = await client.createSession();
49
-
50
- const commands: [string, string[]][] = [
51
- ["pwd", []],
52
- ["ls", ["-la"]],
53
- ["echo", ["Multiple commands test"]],
54
- ];
55
-
56
- for (const [command, args] of commands) {
57
- console.log(`Executing: ${command} ${args.join(" ")}`);
58
- const result = await client.execute(command, args, sessionId);
59
- console.log(` Success: ${result.success}, Exit: ${result.exitCode}`);
60
- }
61
-
62
- client.clearSession();
63
- console.log("โœ… Multiple commands test completed\n");
64
- } catch (error) {
65
- console.error("โŒ Test 3 failed:", error);
66
- }
67
-
68
- // Test 4: Error handling
69
- console.log("Test 4: Error handling");
70
- try {
71
- const result = await quickExecute("nonexistentcommand");
72
- console.log("โœ… Error handled gracefully");
73
- console.log(" Success:", result.success);
74
- console.log(" Exit code:", result.exitCode);
75
- console.log(" Error output:", result.stderr.trim(), "\n");
76
- } catch (error) {
77
- console.error("โŒ Test 4 failed:", error);
78
- }
79
-
80
- // Test 5: Session management
81
- console.log("Test 5: Session management");
82
- try {
83
- const client = createClient();
84
-
85
- // Create session
86
- const sessionId1 = await client.createSession();
87
- console.log("โœ… Session 1 created:", sessionId1);
88
-
89
- // Create another session
90
- const sessionId2 = await client.createSession();
91
- console.log("โœ… Session 2 created:", sessionId2);
92
-
93
- // List sessions
94
- const sessions = await client.listSessions();
95
- console.log("โœ… Sessions listed:", sessions.count, "active sessions");
96
-
97
- // Execute command in specific session
98
- const result = await client.execute("whoami", [], sessionId1);
99
- console.log("โœ… Command executed in session 1:", result.stdout.trim());
100
-
101
- client.clearSession();
102
- console.log("โœ… Session management test completed\n");
103
- } catch (error) {
104
- console.error("โŒ Test 5 failed:", error);
105
- }
106
-
107
- // Test 6: Available commands
108
- console.log("Test 6: Available commands");
109
- try {
110
- const client = createClient();
111
- const commands = await client.getCommands();
112
- console.log("โœ… Available commands:", commands.length);
113
- console.log(" Commands:", commands.slice(0, 5).join(", "), "...\n");
114
- } catch (error) {
115
- console.error("โŒ Test 6 failed:", error);
116
- }
117
-
118
- // Test 7: Streaming command execution
119
- console.log("Test 7: Streaming command execution");
120
- try {
121
- const client = createClient();
122
- await client.createSession();
123
-
124
- console.log(" Starting streaming command...");
125
- await client.executeStream("ls", ["-la"]);
126
- console.log("โœ… Streaming command completed\n");
127
-
128
- client.clearSession();
129
- } catch (error) {
130
- console.error("โŒ Test 7 failed:", error);
131
- }
132
-
133
- // Test 8: Quick streaming execution
134
- console.log("Test 8: Quick streaming execution");
135
- try {
136
- console.log(" Starting quick streaming command...");
137
- await quickExecuteStream("echo", ["Hello from quick streaming!"]);
138
- console.log("โœ… Quick streaming command completed\n");
139
- } catch (error) {
140
- console.error("โŒ Test 8 failed:", error);
141
- }
142
-
143
- // Test 9: File writing
144
- console.log("Test 9: File writing");
145
- try {
146
- const testContent = "Hello, this is a test file!\nLine 2\nLine 3";
147
- const result = await quickWriteFile("test-file.txt", testContent);
148
- console.log("โœ… File written successfully:", result.success);
149
- console.log(" Path:", result.path);
150
- console.log(" Exit code:", result.exitCode);
151
-
152
- // Verify the file was created by reading it
153
- const readResult = await quickExecute("cat", ["test-file.txt"]);
154
- console.log(
155
- "โœ… File content verified:",
156
- readResult.stdout.trim() === testContent
157
- );
158
- console.log(" Content length:", readResult.stdout.length, "characters\n");
159
- } catch (error) {
160
- console.error("โŒ Test 9 failed:", error);
161
- }
162
-
163
- // Test 10: File writing with custom encoding
164
- console.log("Test 10: File writing with custom encoding");
165
- try {
166
- const jsonContent = '{"name": "test", "value": 42, "active": true}';
167
- const result = await quickWriteFile("test-data.json", jsonContent, "utf-8");
168
- console.log("โœ… JSON file written successfully:", result.success);
169
- console.log(" Path:", result.path);
170
-
171
- // Verify the JSON file
172
- const readResult = await quickExecute("cat", ["test-data.json"]);
173
- console.log(
174
- "โœ… JSON content verified:",
175
- readResult.stdout.trim() === jsonContent
176
- );
177
- console.log(" JSON content:", readResult.stdout.trim(), "\n");
178
- } catch (error) {
179
- console.error("โŒ Test 10 failed:", error);
180
- }
181
-
182
- // Test 11: File writing in nested directories
183
- console.log("Test 11: File writing in nested directories");
184
- try {
185
- const nestedContent = "This file is in a nested directory";
186
- const result = await quickWriteFile(
187
- "nested/dir/test-nested.txt",
188
- nestedContent
189
- );
190
- console.log("โœ… Nested file written successfully:", result.success);
191
- console.log(" Path:", result.path);
192
-
193
- // Verify the nested directory was created
194
- const dirResult = await quickExecute("ls", ["-la", "nested/dir"]);
195
- console.log("โœ… Nested directory created and file exists");
196
- console.log(
197
- " Directory listing:",
198
- dirResult.stdout.includes("test-nested.txt")
199
- );
200
-
201
- // Verify the file content
202
- const readResult = await quickExecute("cat", [
203
- "nested/dir/test-nested.txt",
204
- ]);
205
- console.log(
206
- "โœ… Nested file content verified:",
207
- readResult.stdout.trim() === nestedContent,
208
- "\n"
209
- );
210
- } catch (error) {
211
- console.error("โŒ Test 11 failed:", error);
212
- }
213
-
214
- // Test 12: Streaming file writing
215
- console.log("Test 12: Streaming file writing");
216
- try {
217
- const client = createClient();
218
- await client.createSession();
219
-
220
- const largeContent = `${"Line 1\n".repeat(100)}Final line`;
221
- console.log(" Starting streaming file write...");
222
-
223
- await client.writeFileStream("large-file.txt", largeContent);
224
- console.log("โœ… Streaming file write completed");
225
-
226
- // Verify the file
227
- const readResult = await client.execute("wc", ["-l", "large-file.txt"]);
228
- console.log(
229
- "โœ… Large file verified:",
230
- readResult.stdout.trim().includes("101")
231
- );
232
- console.log(" Line count:", readResult.stdout.trim());
233
-
234
- client.clearSession();
235
- console.log("โœ… Streaming file writing test completed\n");
236
- } catch (error) {
237
- console.error("โŒ Test 12 failed:", error);
238
- }
239
-
240
- // Test 13: Quick streaming file writing
241
- console.log("Test 13: Quick streaming file writing");
242
- try {
243
- const quickContent = "Quick streaming test content";
244
- console.log(" Starting quick streaming file write...");
245
-
246
- await quickWriteFileStream("quick-stream.txt", quickContent);
247
- console.log("โœ… Quick streaming file write completed");
248
-
249
- // Verify the file
250
- const readResult = await quickExecute("cat", ["quick-stream.txt"]);
251
- console.log(
252
- "โœ… Quick streaming file verified:",
253
- readResult.stdout.trim() === quickContent,
254
- "\n"
255
- );
256
- } catch (error) {
257
- console.error("โŒ Test 13 failed:", error);
258
- }
259
-
260
- // Test 14: File writing with session management
261
- console.log("Test 14: File writing with session management");
262
- try {
263
- const client = createClient();
264
- const sessionId = await client.createSession();
265
-
266
- const sessionContent = "This file was written with session management";
267
- const result = await client.writeFile(
268
- "session-file.txt",
269
- sessionContent,
270
- "utf-8",
271
- sessionId
272
- );
273
- console.log("โœ… Session file written successfully:", result.success);
274
- console.log(" Session ID:", sessionId);
275
-
276
- // Verify the file
277
- const readResult = await client.execute(
278
- "cat",
279
- ["session-file.txt"],
280
- sessionId
281
- );
282
- console.log(
283
- "โœ… Session file content verified:",
284
- readResult.stdout.trim() === sessionContent
285
- );
286
-
287
- client.clearSession();
288
- console.log("โœ… Session file writing test completed\n");
289
- } catch (error) {
290
- console.error("โŒ Test 14 failed:", error);
291
- }
292
-
293
- // Test 15: Error handling for file writing
294
- console.log("Test 15: Error handling for file writing");
295
- try {
296
- // Try to write to a dangerous path (should be blocked)
297
- await quickWriteFile("/etc/test.txt", "This should fail");
298
- console.log("โŒ Should have failed for dangerous path");
299
- } catch (error) {
300
- console.log("โœ… Error handling works for dangerous paths");
301
- console.log(
302
- " Error:",
303
- error instanceof Error ? error.message : "Unknown error"
304
- );
305
- }
306
-
307
- try {
308
- // Try to write with invalid parameters
309
- await quickWriteFile("", "Empty path should fail");
310
- console.log("โŒ Should have failed for empty path");
311
- } catch (error) {
312
- console.log("โœ… Error handling works for invalid parameters");
313
- console.log(
314
- " Error:",
315
- error instanceof Error ? error.message : "Unknown error",
316
- "\n"
317
- );
318
- }
319
-
320
- // Test 16: File deletion
321
- console.log("Test 16: File deletion");
322
- try {
323
- // First create a file to delete
324
- const deleteContent = "This file will be deleted";
325
- await quickWriteFile("file-to-delete.txt", deleteContent);
326
- console.log("โœ… Test file created for deletion");
327
-
328
- // Delete the file
329
- const result = await quickDeleteFile("file-to-delete.txt");
330
- console.log("โœ… File deleted successfully:", result.success);
331
- console.log(" Path:", result.path);
332
- console.log(" Exit code:", result.exitCode);
333
-
334
- // Verify the file was deleted
335
- try {
336
- await quickExecute("cat", ["file-to-delete.txt"]);
337
- console.log("โŒ File still exists after deletion");
338
- } catch (error) {
339
- console.log("โœ… File successfully deleted (not found)");
340
- }
341
- console.log("โœ… File deletion test completed\n");
342
- } catch (error) {
343
- console.error("โŒ Test 16 failed:", error);
344
- }
345
-
346
- // Test 17: File renaming
347
- console.log("Test 17: File renaming");
348
- try {
349
- // First create a file to rename
350
- const renameContent = "This file will be renamed";
351
- await quickWriteFile("file-to-rename.txt", renameContent);
352
- console.log("โœ… Test file created for renaming");
353
-
354
- // Rename the file
355
- const result = await quickRenameFile(
356
- "file-to-rename.txt",
357
- "renamed-file.txt"
358
- );
359
- console.log("โœ… File renamed successfully:", result.success);
360
- console.log(" Old path:", result.oldPath);
361
- console.log(" New path:", result.newPath);
362
- console.log(" Exit code:", result.exitCode);
363
-
364
- // Verify the old file doesn't exist
365
- try {
366
- await quickExecute("cat", ["file-to-rename.txt"]);
367
- console.log("โŒ Old file still exists");
368
- } catch (error) {
369
- console.log("โœ… Old file successfully removed");
370
- }
371
-
372
- // Verify the new file exists with correct content
373
- const readResult = await quickExecute("cat", ["renamed-file.txt"]);
374
- console.log(
375
- "โœ… Renamed file content verified:",
376
- readResult.stdout.trim() === renameContent
377
- );
378
- console.log(" New file content:", readResult.stdout.trim());
379
- console.log("โœ… File renaming test completed\n");
380
- } catch (error) {
381
- console.error("โŒ Test 17 failed:", error);
382
- }
383
-
384
- // Test 18: File moving
385
- console.log("Test 18: File moving");
386
- try {
387
- // First create a file to move
388
- const moveContent = "This file will be moved";
389
- await quickWriteFile("file-to-move.txt", moveContent);
390
- console.log("โœ… Test file created for moving");
391
-
392
- // Create destination directory
393
- await quickExecute("mkdir", ["-p", "move-destination"]);
394
- console.log("โœ… Destination directory created");
395
-
396
- // Move the file
397
- const result = await quickMoveFile(
398
- "file-to-move.txt",
399
- "move-destination/moved-file.txt"
400
- );
401
- console.log("โœ… File moved successfully:", result.success);
402
- console.log(" Source path:", result.sourcePath);
403
- console.log(" Destination path:", result.destinationPath);
404
- console.log(" Exit code:", result.exitCode);
405
-
406
- // Verify the source file doesn't exist
407
- try {
408
- await quickExecute("cat", ["file-to-move.txt"]);
409
- console.log("โŒ Source file still exists");
410
- } catch (error) {
411
- console.log("โœ… Source file successfully removed");
412
- }
413
-
414
- // Verify the destination file exists with correct content
415
- const readResult = await quickExecute("cat", [
416
- "move-destination/moved-file.txt",
417
- ]);
418
- console.log(
419
- "โœ… Moved file content verified:",
420
- readResult.stdout.trim() === moveContent
421
- );
422
- console.log(" Moved file content:", readResult.stdout.trim());
423
- console.log("โœ… File moving test completed\n");
424
- } catch (error) {
425
- console.error("โŒ Test 18 failed:", error);
426
- }
427
-
428
- // Test 19: Streaming file deletion
429
- console.log("Test 19: Streaming file deletion");
430
- try {
431
- const client = createClient();
432
- await client.createSession();
433
-
434
- // First create a file to delete
435
- const streamDeleteContent = "This file will be deleted via streaming";
436
- await client.writeFile("stream-delete-file.txt", streamDeleteContent);
437
- console.log("โœ… Test file created for streaming deletion");
438
-
439
- console.log(" Starting streaming file deletion...");
440
- await client.deleteFileStream("stream-delete-file.txt");
441
- console.log("โœ… Streaming file deletion completed");
442
-
443
- // Verify the file was deleted
444
- try {
445
- await client.execute("cat", ["stream-delete-file.txt"]);
446
- console.log("โŒ File still exists after streaming deletion");
447
- } catch (error) {
448
- console.log("โœ… File successfully deleted via streaming");
449
- }
450
-
451
- client.clearSession();
452
- console.log("โœ… Streaming file deletion test completed\n");
453
- } catch (error) {
454
- console.error("โŒ Test 19 failed:", error);
455
- }
456
-
457
- // Test 20: Streaming file renaming
458
- console.log("Test 20: Streaming file renaming");
459
- try {
460
- const client = createClient();
461
- await client.createSession();
462
-
463
- // First create a file to rename
464
- const streamRenameContent = "This file will be renamed via streaming";
465
- await client.writeFile("stream-rename-file.txt", streamRenameContent);
466
- console.log("โœ… Test file created for streaming renaming");
467
-
468
- console.log(" Starting streaming file renaming...");
469
- await client.renameFileStream(
470
- "stream-rename-file.txt",
471
- "stream-renamed-file.txt"
472
- );
473
- console.log("โœ… Streaming file renaming completed");
474
-
475
- // Verify the renamed file exists with correct content
476
- const readResult = await client.execute("cat", ["stream-renamed-file.txt"]);
477
- console.log(
478
- "โœ… Stream renamed file content verified:",
479
- readResult.stdout.trim() === streamRenameContent
480
- );
481
-
482
- client.clearSession();
483
- console.log("โœ… Streaming file renaming test completed\n");
484
- } catch (error) {
485
- console.error("โŒ Test 20 failed:", error);
486
- }
487
-
488
- // Test 21: Streaming file moving
489
- console.log("Test 21: Streaming file moving");
490
- try {
491
- const client = createClient();
492
- await client.createSession();
493
-
494
- // First create a file to move
495
- const streamMoveContent = "This file will be moved via streaming";
496
- await client.writeFile("stream-move-file.txt", streamMoveContent);
497
- console.log("โœ… Test file created for streaming moving");
498
-
499
- // Create destination directory
500
- await client.execute("mkdir", ["-p", "stream-move-dest"]);
501
- console.log("โœ… Stream destination directory created");
502
-
503
- console.log(" Starting streaming file moving...");
504
- await client.moveFileStream(
505
- "stream-move-file.txt",
506
- "stream-move-dest/stream-moved-file.txt"
507
- );
508
- console.log("โœ… Streaming file moving completed");
509
-
510
- // Verify the moved file exists with correct content
511
- const readResult = await client.execute("cat", [
512
- "stream-move-dest/stream-moved-file.txt",
513
- ]);
514
- console.log(
515
- "โœ… Stream moved file content verified:",
516
- readResult.stdout.trim() === streamMoveContent
517
- );
518
-
519
- client.clearSession();
520
- console.log("โœ… Streaming file moving test completed\n");
521
- } catch (error) {
522
- console.error("โŒ Test 21 failed:", error);
523
- }
524
-
525
- // Test 22: Quick streaming file operations
526
- console.log("Test 22: Quick streaming file operations");
527
- try {
528
- // Create files for quick operations
529
- await quickWriteFile("quick-delete.txt", "Quick delete test");
530
- await quickWriteFile("quick-rename.txt", "Quick rename test");
531
- await quickWriteFile("quick-move.txt", "Quick move test");
532
- console.log("โœ… Test files created for quick operations");
533
-
534
- // Quick streaming delete
535
- console.log(" Starting quick streaming delete...");
536
- await quickDeleteFileStream("quick-delete.txt");
537
- console.log("โœ… Quick streaming delete completed");
538
-
539
- // Quick streaming rename
540
- console.log(" Starting quick streaming rename...");
541
- await quickRenameFileStream("quick-rename.txt", "quick-renamed.txt");
542
- console.log("โœ… Quick streaming rename completed");
543
-
544
- // Quick streaming move
545
- console.log(" Starting quick streaming move...");
546
- await quickMoveFileStream("quick-move.txt", "quick-moved.txt");
547
- console.log("โœ… Quick streaming move completed");
548
-
549
- // Verify results
550
- const renameResult = await quickExecute("cat", ["quick-renamed.txt"]);
551
- const moveResult = await quickExecute("cat", ["quick-moved.txt"]);
552
- console.log(
553
- "โœ… Quick operations verified:",
554
- renameResult.stdout.trim() === "Quick rename test" &&
555
- moveResult.stdout.trim() === "Quick move test"
556
- );
557
- console.log("โœ… Quick streaming file operations test completed\n");
558
- } catch (error) {
559
- console.error("โŒ Test 22 failed:", error);
560
- }
561
-
562
- // Test 23: File operations with session management
563
- console.log("Test 23: File operations with session management");
564
- try {
565
- const client = createClient();
566
- const sessionId = await client.createSession();
567
-
568
- // Create test files in session
569
- await client.writeFile(
570
- "session-delete.txt",
571
- "Session delete test",
572
- "utf-8",
573
- sessionId
574
- );
575
- await client.writeFile(
576
- "session-rename.txt",
577
- "Session rename test",
578
- "utf-8",
579
- sessionId
580
- );
581
- await client.writeFile(
582
- "session-move.txt",
583
- "Session move test",
584
- "utf-8",
585
- sessionId
586
- );
587
- console.log("โœ… Session test files created");
588
-
589
- // Delete file in session
590
- const deleteResult = await client.deleteFile(
591
- "session-delete.txt",
592
- sessionId
593
- );
594
- console.log("โœ… Session file deleted:", deleteResult.success);
595
-
596
- // Rename file in session
597
- const renameResult = await client.renameFile(
598
- "session-rename.txt",
599
- "session-renamed.txt",
600
- sessionId
601
- );
602
- console.log("โœ… Session file renamed:", renameResult.success);
603
-
604
- // Move file in session
605
- const moveResult = await client.moveFile(
606
- "session-move.txt",
607
- "session-moved.txt",
608
- sessionId
609
- );
610
- console.log("โœ… Session file moved:", moveResult.success);
611
-
612
- // Verify session operations
613
- const renameContent = await client.execute(
614
- "cat",
615
- ["session-renamed.txt"],
616
- sessionId
617
- );
618
- const moveContent = await client.execute(
619
- "cat",
620
- ["session-moved.txt"],
621
- sessionId
622
- );
623
- console.log(
624
- "โœ… Session operations verified:",
625
- renameContent.stdout.trim() === "Session rename test" &&
626
- moveContent.stdout.trim() === "Session move test"
627
- );
628
-
629
- client.clearSession();
630
- console.log("โœ… File operations with session management test completed\n");
631
- } catch (error) {
632
- console.error("โŒ Test 23 failed:", error);
633
- }
634
-
635
- // Test 24: Error handling for file operations
636
- console.log("Test 24: Error handling for file operations");
637
- try {
638
- // Try to delete a non-existent file
639
- await quickDeleteFile("non-existent-file.txt");
640
- console.log("โŒ Should have failed for non-existent file");
641
- } catch (error) {
642
- console.log("โœ… Error handling works for non-existent files");
643
- console.log(
644
- " Error:",
645
- error instanceof Error ? error.message : "Unknown error"
646
- );
647
- }
648
-
649
- try {
650
- // Try to delete a dangerous path
651
- await quickDeleteFile("/etc/passwd");
652
- console.log("โŒ Should have failed for dangerous path");
653
- } catch (error) {
654
- console.log("โœ… Error handling works for dangerous paths");
655
- console.log(
656
- " Error:",
657
- error instanceof Error ? error.message : "Unknown error"
658
- );
659
- }
660
-
661
- try {
662
- // Try to rename with invalid parameters
663
- await quickRenameFile("", "new-name.txt");
664
- console.log("โŒ Should have failed for empty old path");
665
- } catch (error) {
666
- console.log("โœ… Error handling works for invalid rename parameters");
667
- console.log(
668
- " Error:",
669
- error instanceof Error ? error.message : "Unknown error"
670
- );
671
- }
672
-
673
- try {
674
- // Try to move with invalid parameters
675
- await quickMoveFile("source.txt", "");
676
- console.log("โŒ Should have failed for empty destination path");
677
- } catch (error) {
678
- console.log("โœ… Error handling works for invalid move parameters");
679
- console.log(
680
- " Error:",
681
- error instanceof Error ? error.message : "Unknown error",
682
- "\n"
683
- );
684
- }
685
-
686
- console.log("๐ŸŽ‰ All tests completed!");
687
- }
688
-
689
- // Run tests if this file is executed directly
690
- if (import.meta.main) {
691
- // Add a timeout to prevent hanging
692
- const timeout = setTimeout(() => {
693
- console.error("โŒ Tests timed out after 60 seconds");
694
- process.exit(1);
695
- }, 60000);
696
-
697
- testHttpClient()
698
- .then(() => {
699
- clearTimeout(timeout);
700
- console.log("โœ… Tests finished successfully");
701
- process.exit(0);
702
- })
703
- .catch((error) => {
704
- clearTimeout(timeout);
705
- console.error("โŒ Tests failed:", error);
706
- process.exit(1);
707
- });
708
- }
709
-
710
- export { testHttpClient };