11import { $ } from "dax" ;
2- import { assertEquals , assertExists } from "@std/assert" ;
2+ import { assert , assertEquals } from "@std/assert" ;
33
44if ( ! Deno . env . get ( "DENO_DEPLOY_TOKEN" ) ) {
55 console . error ( "DENO_DEPLOY_TOKEN environment variable is required." ) ;
@@ -8,7 +8,7 @@ if (!Deno.env.get("DENO_DEPLOY_TOKEN")) {
88
99const sandbox = async ( ...args : string [ ] ) => {
1010 console . log ( `deno sandbox ${ args . join ( " " ) } ` ) ;
11- return await $ . raw `deno sandbox ${ args . join ( " " ) } ` . text ( ) ;
11+ return ( await $ . raw `deno sandbox ${ args . join ( " " ) } ` . text ( ) ) . trim ( ) ;
1212} ;
1313
1414Deno . test ( "sandbox create" , async ( ) => {
@@ -20,36 +20,33 @@ Deno.test("sandbox create", async () => {
2020 "echo" ,
2121 "test" ,
2222 ) ;
23- await sandbox ( "kill" , sandboxId . trim ( ) ) ;
23+ await sandbox ( "kill" , sandboxId ) ;
2424} ) ;
2525
2626Deno . test ( "sandbox exec" , async ( ) => {
2727 const sandboxId = await sandbox ( "create" , "--quiet" , "--lifetime" , "60s" ) ;
28- const cleanId = sandboxId . trim ( ) ;
29- console . log ( cleanId ) ;
3028
31- const res = await sandbox ( "exec" , cleanId , "echo" , "'exec test'" ) ;
32- assertEquals ( res . trim ( ) , "exec test" ) ;
29+ const res = await sandbox ( "exec" , sandboxId , "echo" , "'exec test'" ) ;
30+ assertEquals ( res , "exec test" ) ;
3331
34- await sandbox ( "kill" , cleanId ) ;
32+ await sandbox ( "kill" , sandboxId ) ;
3533} ) ;
3634
3735Deno . test ( "sandbox copy" , async ( ) => {
3836 const sandboxId = await sandbox ( "create" , "--quiet" , "--lifetime" , "60s" ) ;
39- const cleanId = sandboxId . trim ( ) ;
4037
4138 await Deno . writeTextFile ( "test.txt" , "test content" ) ;
4239
43- await sandbox ( "copy" , "test.txt" , `${ cleanId } :/tmp/test.txt` ) ;
40+ await sandbox ( "copy" , "test.txt" , `${ sandboxId } :/tmp/test.txt` ) ;
4441
45- await sandbox ( "copy" , `${ cleanId } :/tmp/test.txt` , "./downloaded.txt" ) ;
42+ await sandbox ( "copy" , `${ sandboxId } :/tmp/test.txt` , "./downloaded.txt" ) ;
4643 const downloadedContent = await Deno . readTextFile ( "./downloaded.txt" ) ;
4744 assertEquals ( downloadedContent , "test content" ) ;
4845
4946 await Deno . remove ( "test.txt" ) ;
5047 await Deno . remove ( "downloaded.txt" ) ;
5148
52- await sandbox ( "kill" , cleanId ) ;
49+ await sandbox ( "kill" , sandboxId ) ;
5350} ) ;
5451
5552Deno . test ( "sandbox extend" , async ( ) => {
@@ -61,50 +58,47 @@ Deno.test("sandbox extend", async () => {
6158 "sleep" ,
6259 "10" ,
6360 ) ;
64- const cleanId = sandboxId . trim ( ) ;
6561
66- await sandbox ( "extend" , cleanId , "120s" ) ;
62+ await sandbox ( "extend" , sandboxId , "120s" ) ;
6763
68- await sandbox ( "kill" , cleanId ) ;
64+ await sandbox ( "kill" , sandboxId ) ;
6965} ) ;
7066
7167Deno . test ( "sandbox exec with complex commands" , async ( ) => {
7268 const sandboxId = await sandbox ( "create" , "--quiet" , "--lifetime" , "60s" ) ;
73- const cleanId = sandboxId . trim ( ) ;
7469
75- const result = await sandbox ( "exec" , cleanId , "'echo hello && echo world'" ) ;
76- assertEquals ( result . includes ( "hello" ) , true ) ;
77- assertEquals ( result . includes ( "world" ) , true ) ;
70+ const result = await sandbox ( "exec" , sandboxId , "'echo hello && echo world'" ) ;
71+ assert ( result . includes ( "hello" ) ) ;
72+ assert ( result . includes ( "world" ) ) ;
7873
79- await sandbox ( "kill" , cleanId ) ;
74+ await sandbox ( "kill" , sandboxId ) ;
8075} ) ;
8176
8277Deno . test ( "sandbox copy directory structure" , async ( ) => {
8378 const sandboxId = await sandbox ( "create" , "--quiet" , "--lifetime" , "60s" ) ;
84- const cleanId = sandboxId . trim ( ) ;
8579
8680 await Deno . mkdir ( "testdir" , { recursive : true } ) ;
8781 await Deno . writeTextFile ( "testdir/file1.txt" , "content1" ) ;
8882 await Deno . writeTextFile ( "testdir/file2.txt" , "content2" ) ;
8983
90- await sandbox ( "exec" , cleanId , "'mkdir -p /tmp/testdir'" ) ;
84+ await sandbox ( "exec" , sandboxId , "'mkdir -p /tmp/testdir'" ) ;
9185 await sandbox (
9286 "copy" ,
9387 "testdir/file1.txt" ,
94- `${ cleanId } :/tmp/testdir/file1.txt` ,
88+ `${ sandboxId } :/tmp/testdir/file1.txt` ,
9589 ) ;
9690 await sandbox (
9791 "copy" ,
9892 "testdir/file2.txt" ,
99- `${ cleanId } :/tmp/testdir/file2.txt` ,
93+ `${ sandboxId } :/tmp/testdir/file2.txt` ,
10094 ) ;
10195
102- const result = await sandbox ( "exec" , cleanId , "ls" , "/tmp/testdir" ) ;
103- assertEquals ( result . includes ( "file1.txt" ) , true ) ;
104- assertEquals ( result . includes ( "file2.txt" ) , true ) ;
96+ const result = await sandbox ( "exec" , sandboxId , "ls" , "/tmp/testdir" ) ;
97+ assert ( result . includes ( "file1.txt" ) ) ;
98+ assert ( result . includes ( "file2.txt" ) ) ;
10599
106100 await Deno . remove ( "testdir" , { recursive : true } ) ;
107- await sandbox ( "kill" , cleanId ) ;
101+ await sandbox ( "kill" , sandboxId ) ;
108102} ) ;
109103
110104Deno . test ( "volumes create" , async ( ) => {
@@ -119,9 +113,8 @@ Deno.test("volumes create", async () => {
119113 "--region" ,
120114 "ord" ,
121115 ) ;
122- assertExists ( volumeId . trim ( ) ) ;
123116
124- await sandbox ( "volumes" , "delete" , volumeId . trim ( ) ) ;
117+ await sandbox ( "volumes" , "delete" , volumeId ) ;
125118} ) ;
126119
127120Deno . test ( "sandbox with volume mount" , async ( ) => {
@@ -136,31 +129,29 @@ Deno.test("sandbox with volume mount", async () => {
136129 "--region" ,
137130 "ord" ,
138131 ) ;
139- const cleanVolumeId = volumeId . trim ( ) ;
140132
141133 const sandboxId = await sandbox (
142134 "create" ,
143135 "--quiet" ,
144136 "--lifetime" ,
145137 "60s" ,
146138 "--volume" ,
147- `${ cleanVolumeId } :/data/dataset` ,
139+ `${ volumeId } :/data/dataset` ,
148140 ) ;
149- const cleanId = sandboxId . trim ( ) ;
150141
151142 await sandbox (
152143 "exec" ,
153- cleanId ,
144+ sandboxId ,
154145 "\"echo 'volume test' > /data/dataset/test.txt\"" ,
155146 ) ;
156147 const result = await sandbox (
157148 "exec" ,
158- cleanId ,
149+ sandboxId ,
159150 "cat" ,
160151 "/data/dataset/test.txt" ,
161152 ) ;
162- assertEquals ( result . trim ( ) , "volume test" ) ;
153+ assertEquals ( result , "volume test" ) ;
163154
164- await sandbox ( "kill" , cleanId ) ;
165- await sandbox ( "volumes" , "delete" , cleanVolumeId ) ;
155+ await sandbox ( "kill" , sandboxId ) ;
156+ await sandbox ( "volumes" , "delete" , volumeId ) ;
166157} ) ;
0 commit comments