Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/ext-tasks/src/core/v2/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,29 @@ describe("V2 runtime wire contracts", () => {
).toBe(false);
});

it("keeps extension fields on task creation and tasks/get results", () => {
// Both results extend the open pinned Result type, like the notification
// params: stripping unknown top-level keys here would hide extensions from
// projectTask() on the polling path only.
const [task] = fc.sample(taskFor("working"), 1);
const created = CreateTaskResultV2Schema.safeParse(
asJson({ ...task, resultType: "task", "vendor/trace": { hop: 1 } }),
);
const fetched = GetTaskResultV2Schema.safeParse(
asJson({ ...task, resultType: "complete", "vendor/trace": { hop: 1 } }),
);
expect(created.success).toBe(true);
if (created.success)
expect((created.data as Record<string, unknown>)["vendor/trace"]).toEqual(
{ hop: 1 },
);
expect(fetched.success).toBe(true);
if (fetched.success)
expect((fetched.data as Record<string, unknown>)["vendor/trace"]).toEqual(
{ hop: 1 },
);
});

it("decodes detailed task notifications with exact envelope discriminators", () => {
fc.assert(
fc.property(taskFor("working"), (task) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/ext-tasks/src/core/v2/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ const DetailedTaskV2Schema = z.discriminatedUnion("status", [
CancelledTaskV2Schema,
]);

const CreateTaskResultV2Schema = z.object({
// CreateTaskResult and GetTaskResult extend the open pinned Result type, so
// they keep unknown top-level keys, like the notification params below.
const CreateTaskResultV2Schema = openObject({
...TaskBaseShape,
status: TaskStatusV2Schema,
resultType: z.literal("task"),
Expand All @@ -392,7 +394,7 @@ const UpdateTaskRequestV2Schema = z.object({
const CancelTaskRequestV2Schema = taskIdRequestV2Schema("tasks/cancel");
const GetTaskResultV2Schema = z.intersection(
DetailedTaskV2Schema,
z.object({
openObject({
resultType: CompleteResultTypeSchema,
_meta: MetaSchema.optional(),
}),
Expand Down