@@ -20,16 +20,16 @@ const makeTextResponse = (body: string, status: number): Response =>
2020 new Response ( body , { status } ) ;
2121
2222const sampleRunResult = {
23- stdout : "Hello\n " ,
23+ stdout : "SGVsbG8K " ,
2424 stderr : "" ,
25- output : "Hello\n " ,
25+ output : "SGVsbG8K " ,
2626 exit_code : 0 ,
2727 signal : null ,
28- status : "SUCCESS " ,
28+ status : "OK " ,
2929} ;
3030
3131const sampleRequest = {
32- language : "python" as const ,
32+ runtime : "python" as const ,
3333 files : [ { name : "main.py" , content : 'print("Hello")' } ] ,
3434} ;
3535
@@ -108,7 +108,48 @@ describe("CodizeClient", () => {
108108 await client . sandbox . execute ( sampleRequest ) ;
109109
110110 const init = fetchFn . mock . calls [ 0 ] ! [ 1 ] as RequestInit ;
111- expect ( JSON . parse ( init . body as string ) ) . toEqual ( sampleRequest ) ;
111+ expect ( JSON . parse ( init . body as string ) ) . toEqual ( {
112+ runtime : "python" ,
113+ files : [ { name : "main.py" , content : 'print("Hello")' , base64_encoded : false } ] ,
114+ } ) ;
115+ } ) ;
116+
117+ it ( "sends base64_encoded flag when specified" , async ( ) => {
118+ const fetchFn = vi . fn ( ) . mockResolvedValue (
119+ makeJsonResponse ( { compile : null , run : sampleRunResult } ) ,
120+ ) ;
121+ const client = new CodizeClient ( { apiKey : "key" , fetchFn } ) ;
122+ await client . sandbox . execute ( {
123+ runtime : "python" ,
124+ files : [ { name : "data.bin" , content : "aGVsbG8=" , base64Encoded : true } ] ,
125+ } ) ;
126+
127+ const init = fetchFn . mock . calls [ 0 ] ! [ 1 ] as RequestInit ;
128+ const body = JSON . parse ( init . body as string ) ;
129+ expect ( body . files [ 0 ] . base64_encoded ) . toBe ( true ) ;
130+ } ) ;
131+
132+ it ( "handles mixed base64Encoded values across multiple files" , async ( ) => {
133+ const fetchFn = vi . fn ( ) . mockResolvedValue (
134+ makeJsonResponse ( { compile : null , run : sampleRunResult } ) ,
135+ ) ;
136+ const client = new CodizeClient ( { apiKey : "key" , fetchFn } ) ;
137+ await client . sandbox . execute ( {
138+ runtime : "python" ,
139+ files : [
140+ { name : "main.py" , content : 'print("Hello")' } ,
141+ { name : "data.bin" , content : "aGVsbG8=" , base64Encoded : true } ,
142+ { name : "config.json" , content : '{}' , base64Encoded : false } ,
143+ ] ,
144+ } ) ;
145+
146+ const init = fetchFn . mock . calls [ 0 ] ! [ 1 ] as RequestInit ;
147+ const body = JSON . parse ( init . body as string ) ;
148+ expect ( body . files ) . toEqual ( [
149+ { name : "main.py" , content : 'print("Hello")' , base64_encoded : false } ,
150+ { name : "data.bin" , content : "aGVsbG8=" , base64_encoded : true } ,
151+ { name : "config.json" , content : '{}' , base64_encoded : false } ,
152+ ] ) ;
112153 } ) ;
113154 } ) ;
114155
@@ -123,9 +164,9 @@ describe("CodizeClient", () => {
123164 output : "" ,
124165 exit_code : 0 ,
125166 signal : null ,
126- status : "SUCCESS " ,
167+ status : "OK " ,
127168 } ,
128- run : { stdout : "ok\n " , stderr : "" , output : "ok\n " , exit_code : 0 , signal : null , status : "SUCCESS " } ,
169+ run : { stdout : "b2sK " , stderr : "" , output : "b2sK " , exit_code : 0 , signal : null , status : "OK " } ,
129170 } ;
130171 const fetchFn = vi . fn ( ) . mockResolvedValue ( makeJsonResponse ( body ) ) ;
131172 const client = new CodizeClient ( { apiKey : "key" , fetchFn } ) ;
@@ -137,22 +178,22 @@ describe("CodizeClient", () => {
137178 output : "" ,
138179 exitCode : 0 ,
139180 signal : null ,
140- status : "SUCCESS " ,
181+ status : "OK " ,
141182 } ) ;
142183 expect ( result . data . run ) . toEqual ( {
143- stdout : "ok\n " ,
184+ stdout : "b2sK " ,
144185 stderr : "" ,
145- output : "ok\n " ,
186+ output : "b2sK " ,
146187 exitCode : 0 ,
147188 signal : null ,
148- status : "SUCCESS " ,
189+ status : "OK " ,
149190 } ) ;
150191 } ) ;
151192
152193 it ( "returns compile as null when the API returns null" , async ( ) => {
153194 const body = {
154195 compile : null ,
155- run : { stdout : "" , stderr : "" , output : "" , exit_code : 0 , signal : null , status : "SUCCESS " } ,
196+ run : { stdout : "" , stderr : "" , output : "" , exit_code : 0 , signal : null , status : "OK " } ,
156197 } ;
157198 const fetchFn = vi . fn ( ) . mockResolvedValue ( makeJsonResponse ( body ) ) ;
158199 const client = new CodizeClient ( { apiKey : "key" , fetchFn } ) ;
@@ -193,7 +234,8 @@ describe("CodizeClient", () => {
193234 describe ( "structured API error" , ( ) => {
194235 it ( "throws CodizeApiError for a structured error response" , async ( ) => {
195236 const errorBody = {
196- error : { code : "UNAUTHORIZED" , message : "Invalid API key" } ,
237+ code : "UNAUTHORIZED" ,
238+ message : "Invalid API key" ,
197239 } ;
198240 const fetchFn = vi . fn ( ) . mockResolvedValue (
199241 makeJsonResponse ( errorBody , 401 ) ,
@@ -207,7 +249,8 @@ describe("CodizeClient", () => {
207249
208250 it ( "sets the correct status on CodizeApiError" , async ( ) => {
209251 const errorBody = {
210- error : { code : "RATE_LIMITED" , message : "Too many requests" } ,
252+ code : "RATE_LIMITED" ,
253+ message : "Too many requests" ,
211254 } ;
212255 const fetchFn = vi . fn ( ) . mockResolvedValue (
213256 makeJsonResponse ( errorBody , 429 ) ,
@@ -223,7 +266,8 @@ describe("CodizeClient", () => {
223266
224267 it ( "sets the correct code on CodizeApiError" , async ( ) => {
225268 const errorBody = {
226- error : { code : "RATE_LIMITED" , message : "Too many requests" } ,
269+ code : "RATE_LIMITED" ,
270+ message : "Too many requests" ,
227271 } ;
228272 const fetchFn = vi . fn ( ) . mockResolvedValue (
229273 makeJsonResponse ( errorBody , 429 ) ,
@@ -238,7 +282,8 @@ describe("CodizeClient", () => {
238282
239283 it ( "sets the correct message on CodizeApiError" , async ( ) => {
240284 const errorBody = {
241- error : { code : "UNAUTHORIZED" , message : "Invalid API key" } ,
285+ code : "UNAUTHORIZED" ,
286+ message : "Invalid API key" ,
242287 } ;
243288 const fetchFn = vi . fn ( ) . mockResolvedValue (
244289 makeJsonResponse ( errorBody , 401 ) ,
@@ -253,13 +298,11 @@ describe("CodizeClient", () => {
253298
254299 it ( "includes validation errors array when present" , async ( ) => {
255300 const errorBody = {
256- error : {
257- code : "VALIDATION_ERROR" ,
258- message : "Validation failed" ,
259- errors : [
260- { message : "'files' is required" , path : [ "files" ] } ,
261- ] ,
262- } ,
301+ code : "VALIDATION_ERROR" ,
302+ message : "Validation failed" ,
303+ errors : [
304+ { message : "'files' is required" , path : [ "files" ] } ,
305+ ] ,
263306 } ;
264307 const fetchFn = vi . fn ( ) . mockResolvedValue (
265308 makeJsonResponse ( errorBody , 422 ) ,
@@ -270,13 +313,14 @@ describe("CodizeClient", () => {
270313 . catch ( ( e : unknown ) => e ) ;
271314
272315 expect ( ( error as CodizeApiError ) . errors ) . toEqual (
273- errorBody . error . errors ,
316+ errorBody . errors ,
274317 ) ;
275318 } ) ;
276319
277320 it ( "attaches response headers to CodizeApiError" , async ( ) => {
278321 const errorBody = {
279- error : { code : "UNAUTHORIZED" , message : "Invalid API key" } ,
322+ code : "UNAUTHORIZED" ,
323+ message : "Invalid API key" ,
280324 } ;
281325 const fetchFn = vi . fn ( ) . mockResolvedValue (
282326 makeJsonResponse ( errorBody , 401 , {
0 commit comments