Skip to content

Commit d1957fa

Browse files
koki-developclaude
andcommitted
fix: Map API's snake_case exit_code to camelCase exitCode in SandboxStageResult
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 57767c5 commit d1957fa

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

typescript/src/client.spec.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const sampleRunResult = {
2323
stdout: "Hello\n",
2424
stderr: "",
2525
output: "Hello\n",
26-
exitCode: 0,
26+
exit_code: 0,
2727
};
2828

2929
const sampleRequest = {
@@ -119,22 +119,32 @@ describe("CodizeClient", () => {
119119
stdout: "",
120120
stderr: "",
121121
output: "",
122-
exitCode: 0,
122+
exit_code: 0,
123123
},
124-
run: { stdout: "ok\n", stderr: "", output: "ok\n", exitCode: 0 },
124+
run: { stdout: "ok\n", stderr: "", output: "ok\n", exit_code: 0 },
125125
};
126126
const fetchFn = vi.fn().mockResolvedValue(makeJsonResponse(body));
127127
const client = new CodizeClient({ apiKey: "key", fetchFn });
128128
const result = await client.sandbox.execute(sampleRequest);
129129

130-
expect(result.data.compile).toEqual(body.compile);
131-
expect(result.data.run).toEqual(body.run);
130+
expect(result.data.compile).toEqual({
131+
stdout: "",
132+
stderr: "",
133+
output: "",
134+
exitCode: 0,
135+
});
136+
expect(result.data.run).toEqual({
137+
stdout: "ok\n",
138+
stderr: "",
139+
output: "ok\n",
140+
exitCode: 0,
141+
});
132142
});
133143

134144
it("returns compile as null when the API returns null", async () => {
135145
const body = {
136146
compile: null,
137-
run: { stdout: "", stderr: "", output: "", exitCode: 0 },
147+
run: { stdout: "", stderr: "", output: "", exit_code: 0 },
138148
};
139149
const fetchFn = vi.fn().mockResolvedValue(makeJsonResponse(body));
140150
const client = new CodizeClient({ apiKey: "key", fetchFn });

typescript/src/client.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,28 @@ export type SandboxStageResult = {
9797
exitCode: number | null;
9898
};
9999

100+
/**
101+
* Raw stage result shape returned by the API (snake_case keys).
102+
*/
103+
type RawStageResult = {
104+
stdout: string;
105+
stderr: string;
106+
output: string;
107+
exit_code: number | null;
108+
};
109+
110+
/**
111+
* Maps a raw API stage result to the SDK's camelCase format.
112+
*/
113+
function mapStageResult(raw: RawStageResult): SandboxStageResult {
114+
return {
115+
stdout: raw.stdout,
116+
stderr: raw.stderr,
117+
output: raw.output,
118+
exitCode: raw.exit_code,
119+
};
120+
}
121+
100122
/**
101123
* API client for Codize.
102124
*/
@@ -158,10 +180,16 @@ export class CodizeClient {
158180
throw await this._apiError(response);
159181
}
160182

161-
const data = (await response.json()) as SandboxExecuteResponse["data"];
183+
const data = (await response.json()) as {
184+
compile: RawStageResult | null;
185+
run: RawStageResult;
186+
};
162187
return {
163188
headers: response.headers,
164-
data: { compile: data.compile, run: data.run },
189+
data: {
190+
compile: data.compile ? mapStageResult(data.compile) : null,
191+
run: mapStageResult(data.run),
192+
},
165193
};
166194
}
167195

0 commit comments

Comments
 (0)