Skip to content

Commit 6bc752c

Browse files
fix(core): fix RunEvent schema mismatch and nullable parentId
1 parent 0fba878 commit 6bc752c

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

packages/core/src/v3/apiClient/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
EnvironmentVariableResponseBody,
2929
EnvironmentVariableWithSecret,
3030
ListQueueOptions,
31+
ListRunEventsResponse,
3132
ListRunResponseItem,
3233
ListScheduleOptions,
3334
QueueItem,
@@ -701,7 +702,7 @@ export class ApiClient {
701702

702703
listRunEvents(runId: string, requestOptions?: ZodFetchOptions) {
703704
return zodfetch(
704-
RunEvent.array(),
705+
ListRunEventsResponse,
705706
`${this.baseUrl}/api/v1/runs/${runId}/events`,
706707
{
707708
method: "GET",

packages/core/src/v3/schemas/api-type.test.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from "vitest";
2-
import { InitializeDeploymentRequestBody, RunEvent } from "./api.js";
2+
import { InitializeDeploymentRequestBody, RunEvent, ListRunEventsResponse } from "./api.js";
33
import type { InitializeDeploymentRequestBody as InitializeDeploymentRequestBodyType } from "./api.js";
44

55
describe("InitializeDeploymentRequestBody", () => {
@@ -189,10 +189,47 @@ describe("RunEvent Schema", () => {
189189
expect(result.startTime.toISOString()).toBe("2024-03-14T00:00:00.000Z");
190190
});
191191

192-
it("allows optional parentId", () => {
192+
it("allows optional/null parentId", () => {
193193
const eventWithoutParent = { ...validEvent };
194194
delete (eventWithoutParent as any).parentId;
195-
const result = RunEvent.safeParse(eventWithoutParent);
195+
expect(RunEvent.safeParse(eventWithoutParent).success).toBe(true);
196+
197+
const eventWithNullParent = { ...validEvent, parentId: null };
198+
expect(RunEvent.safeParse(eventWithNullParent).success).toBe(true);
199+
});
200+
});
201+
202+
describe("ListRunEventsResponse Schema", () => {
203+
it("parses a valid wrapped response", () => {
204+
const response = {
205+
events: [
206+
{
207+
spanId: "span_1",
208+
runId: "run_1",
209+
message: "Event 1",
210+
style: {},
211+
startTime: "2024-03-14T00:00:00Z",
212+
duration: 100,
213+
isError: false,
214+
isPartial: false,
215+
isCancelled: false,
216+
level: "INFO",
217+
kind: "TASK",
218+
},
219+
],
220+
};
221+
222+
const result = ListRunEventsResponse.safeParse(response);
196223
expect(result.success).toBe(true);
224+
if (result.success) {
225+
expect(result.data.events).toHaveLength(1);
226+
expect(result.data.events[0].spanId).toBe("span_1");
227+
}
228+
});
229+
230+
it("fails on plain array", () => {
231+
const response = [{ spanId: "span_1" }];
232+
const result = ListRunEventsResponse.safeParse(response);
233+
expect(result.success).toBe(false);
197234
});
198235
});

packages/core/src/v3/schemas/api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ export type TaskEventLevel = z.infer<typeof TaskEventLevel>;
16461646

16471647
export const RunEvent = z.object({
16481648
spanId: z.string(),
1649-
parentId: z.string().optional(),
1649+
parentId: z.string().nullish(),
16501650
runId: z.string(),
16511651
message: z.string(),
16521652
style: TaskEventStyle,
@@ -1662,3 +1662,9 @@ export const RunEvent = z.object({
16621662
});
16631663

16641664
export type RunEvent = z.infer<typeof RunEvent>;
1665+
1666+
export const ListRunEventsResponse = z.object({
1667+
events: z.array(RunEvent),
1668+
});
1669+
1670+
export type ListRunEventsResponse = z.infer<typeof ListRunEventsResponse>;

0 commit comments

Comments
 (0)