Skip to content

Commit 3d02fe2

Browse files
koki-developclaude
andcommitted
fix: Make SandboxExecuteResponse's run field nullable to match compile
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2a0536c commit 3d02fe2

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

typescript/CLAUDE.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,21 @@ npx tsc --noEmit
3333

3434
tsc is type-check only (`noEmit: true`). tsdown handles the actual compilation and emit.
3535

36-
## Testing / Linting
36+
## Testing
3737

38-
No test framework or linting tools are configured yet. `CodizeClient` accepts a `fetchFn` option for future test mocking.
38+
**Vitest** is the test framework. Test files use the `*.spec.ts` naming convention and live alongside source files in `src/`.
39+
40+
```sh
41+
bun test # run all tests via vitest
42+
```
43+
44+
`CodizeClient` accepts a `fetchFn` option for injecting a mock `fetch` in tests.
3945

4046
## Architecture
4147

4248
Three source files:
4349

44-
- **`src/client.ts`**`CodizeClient` class. Takes `{ apiKey, fetchFn? }`. Makes `POST https://codize.dev/api/v1/sandbox/execute` with Bearer auth. Returns `SandboxExecuteResponse` containing `data.compile` (nullable) and `data.run` stage results plus `headers`.
50+
- **`src/client.ts`**`CodizeClient` class. Takes `{ apiKey, fetchFn? }`. Makes `POST https://codize.dev/api/v1/sandbox/execute` with Bearer auth. Returns `SandboxExecuteResponse` containing `data.compile` (nullable) and `data.run` (nullable) stage results plus `headers`.
4551
- **`src/error.ts`**`CodizeApiError` class. Thrown on non-2xx responses. Parses error body using valibot's `apiErrorResponseSchema`. Exposes `.code`, `.status`, `.headers`, `.errors`.
4652
- **`src/index.ts`** — Barrel file re-exporting all public types and classes from `client.ts` and `error.ts`.
4753

typescript/src/client.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ describe("CodizeClient", () => {
153153
expect(result.data.compile).toBeNull();
154154
});
155155

156+
it("returns run as null when the API returns null", async () => {
157+
const body = {
158+
compile: null,
159+
run: null,
160+
};
161+
const fetchFn = vi.fn().mockResolvedValue(makeJsonResponse(body));
162+
const client = new CodizeClient({ apiKey: "key", fetchFn });
163+
const result = await client.sandbox.execute(sampleRequest);
164+
165+
expect(result.data.run).toBeNull();
166+
});
167+
156168
it("returns the response headers", async () => {
157169
const fetchFn = vi.fn().mockResolvedValue(
158170
makeJsonResponse(

typescript/src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export type SandboxExecuteResponse = {
7171
/**
7272
* Run-stage output.
7373
*/
74-
run: SandboxStageResult;
74+
run: SandboxStageResult | null;
7575
};
7676
};
7777

@@ -182,13 +182,13 @@ export class CodizeClient {
182182

183183
const data = (await response.json()) as {
184184
compile: RawStageResult | null;
185-
run: RawStageResult;
185+
run: RawStageResult | null;
186186
};
187187
return {
188188
headers: response.headers,
189189
data: {
190190
compile: data.compile ? mapStageResult(data.compile) : null,
191-
run: mapStageResult(data.run),
191+
run: data.run ? mapStageResult(data.run) : null,
192192
},
193193
};
194194
}

0 commit comments

Comments
 (0)