From 9ae14634559d71169d73b09a7e3d456b94b598a7 Mon Sep 17 00:00:00 2001 From: vAPI Development <336934719+vapi-development@users.noreply.github.com> Date: Wed, 2 Dec 2026 23:03:02 +0100 Subject: [PATCH 1/2] fix(tasks): parse pool claims, pool cards and repository-bound PR requirements from the server Order views list pool claims as proposals with kind "claim" and preset proof fills; the client reused its request schema and rejected them, so task claim, show and cancel failed on any pool with a claim. Response payloads now mirror the server view (kinds, proof bounds, invite codes) and keep signed proof bytes unchanged. Public cards accept shape "pool"; pr requirements accept repository, merged and challenge. Co-Authored-By: Claude Opus 5.5 Signed-off-by: vAPI Development <336934719+vapi-development@users.noreply.github.com> --- packages/core/src/tasks/server-parity.test.ts | 105 ++++++++++++++++++ packages/core/src/tasks/types.ts | 76 ++++++++++++- packages/core/src/tasks/v2.ts | 12 +- 3 files changed, 190 insertions(+), 3 deletions(-) diff --git a/packages/core/src/tasks/server-parity.test.ts b/packages/core/src/tasks/server-parity.test.ts index 4962499..d17267a 100644 --- a/packages/core/src/tasks/server-parity.test.ts +++ b/packages/core/src/tasks/server-parity.test.ts @@ -5,6 +5,7 @@ import { prepareDeliveryManifest } from "./delivery-manifest.js"; import { parseFeeBp, taskMoney } from "./money.js"; import { missingTasksChain } from "./chain-port.js"; import { postTask, searchTasks, submitTask } from "./operations.js"; +import { proofRequirementSchema } from "./v2.js"; import { createOrderInputSchema, deliverEscrowInputSchema, @@ -244,6 +245,110 @@ describe("merged server response contracts", () => { }, ); + it("parses a pool order whose proposals carry pool claims, as the server returns them", async () => { + // Server view schema (vapi-app order-view.ts workProposalPayloadViewSchema): kind + // proposal|submission|claim, a claim carries preset proof fills and an optional inviteCode. + const claim = (value: string, extra: Record = {}) => ({ + ...proposal, + signedPayload: { + ...proposal.signedPayload, + kind: "claim", + proof: [{ preset: "text", value }], + ...extra, + }, + }); + const parsed = tasksResponseSchemas.getOrder.parse({ + workOrder: { + ...privateOrder, + state: "open", + proposals: [claim("dada"), claim("invited-user", { inviteCode: "ABCD2345" })], + }, + }); + expect(parsed.workOrder).toMatchObject({ + proposals: [ + { signedPayload: { kind: "claim", proof: [{ preset: "text", value: "dada" }] } }, + { signedPayload: { kind: "claim", inviteCode: "ABCD2345" } }, + ], + }); + // The transport path `vapi task claim|show|cancel` uses parses the same order. + const fetch = vi.fn(async () => Response.json(parsed)); + const client = createTasksClient({ baseUrl: "https://tasks.example", fetch }); + expect(await client.getOrder(ORDER)).toEqual(parsed); + const order = (proposals: unknown[]) => + tasksResponseSchemas.getOrder.safeParse({ workOrder: { ...privateOrder, proposals } }); + // Signed proof bytes come back unchanged, never normalized. + const signedLink = "https://example.org/a\tb"; + expect( + order([ + { + ...proposal, + signedPayload: { + ...proposal.signedPayload, + kind: "claim", + proof: [{ preset: "link", value: signedLink }], + }, + }, + ]), + ).toMatchObject({ + success: true, + data: { workOrder: { proposals: [{ signedPayload: { proof: [{ value: signedLink }] } }] } }, + }); + // Server rules: a malformed invite code, empty proof, and proof on a plain proposal fail. + expect(order([claim("x", { inviteCode: "ABCD-1234" })]).success).toBe(false); + expect( + order([ + { ...proposal, signedPayload: { ...proposal.signedPayload, kind: "claim", proof: [] } }, + ]).success, + ).toBe(false); + expect( + order([ + { + ...proposal, + signedPayload: { + ...proposal.signedPayload, + proof: [{ kind: "url", value: "https://example.org/work" }], + }, + }, + ]).success, + ).toBe(false); + // A claim without proof stays invalid, as on the server. + expect( + tasksResponseSchemas.getOrder.safeParse({ + workOrder: { + ...privateOrder, + proposals: [{ ...proposal, signedPayload: { ...proposal.signedPayload, kind: "claim" } }], + }, + }).success, + ).toBe(false); + }); + + it("parses public pool cards and repository-bound pull request requirements", () => { + expect( + tasksResponseSchemas.publicTask.parse({ + ...card, + shape: "pool", + briefFull: card.brief, + children: [], + })?.shape, + ).toBe("pool"); + expect( + proofRequirementSchema.parse({ + preset: "pr", + repository: "vAPI-Network/vapi-network", + merged: true, + challenge: true, + }), + ).toEqual({ + preset: "pr", + repository: "vAPI-Network/vapi-network", + merged: true, + challenge: true, + }); + expect( + proofRequirementSchema.safeParse({ preset: "pr", repository: "not a repo" }).success, + ).toBe(false); + }); + it("allows 600-second terms in requests and nested proposal and scope responses", () => { expect(milestoneTermsSchema.parse(terms).workDurationSeconds).toBe(600); expect(milestoneTermsSchema.safeParse({ ...terms, workDurationSeconds: 599 }).success).toBe( diff --git a/packages/core/src/tasks/types.ts b/packages/core/src/tasks/types.ts index bb30ff6..6e8bc5f 100644 --- a/packages/core/src/tasks/types.ts +++ b/packages/core/src/tasks/types.ts @@ -341,12 +341,84 @@ export const feedQuerySchema = z.object({ limit: z.number().int().positive().optional(), }); +// Mirrors the server's order-view payload (vapi-app workProposalPayloadViewSchema): a +// pool order lists its pool claims as proposals with kind "claim" and preset proof fills. +// Response proof is checked by shape only and never normalized, so the parsed payload keeps +// the exact signed bytes. +const proofLabelViewSchema = z.string().optional(); +const legacyProofViewSchema = z + .array( + z.discriminatedUnion("kind", [ + z.strictObject({ kind: z.literal("url"), value: z.string(), label: proofLabelViewSchema }), + z.strictObject({ kind: z.literal("file"), value: z.string(), label: proofLabelViewSchema }), + ]), + ) + .min(1) + .max(20); +const presetProofViewSchema = z + .array( + z.strictObject({ + preset: z.enum(["link", "file", "x-post", "onchain-tx", "pr", "text", "media"]), + value: z.string(), + label: proofLabelViewSchema, + }), + ) + .min(1) + .max(20); +const proposalPayloadViewSchema = z + .looseObject({ + version: z.literal("work-proposal-v1"), + workOrderId: uuidSchema, + providerAddress: addressSchema, + pricingModel: z.literal("fixed"), + milestones: z.array(milestoneTermsBoundarySchema).length(1), + kind: z.enum(["proposal", "submission", "claim"]).optional(), + inviteCode: z + .string() + .regex(/^[A-Z2-7]{8}$/u) + .optional(), + proof: z.union([legacyProofViewSchema, presetProofViewSchema]).optional(), + }) + .superRefine((payload, context) => { + if ( + payload.kind !== "claim" && + payload.proof !== undefined && + !legacyProofViewSchema.safeParse(payload.proof).success + ) { + context.addIssue({ + code: "custom", + path: ["proof"], + message: "Preset proof fills require a pool claim", + }); + } + if ( + (payload.kind === "submission" || payload.kind === "claim") && + payload.proof === undefined + ) { + context.addIssue({ + code: "custom", + path: ["proof"], + message: "Submission proof is required", + }); + } + if (payload.inviteCode !== undefined && payload.kind !== "claim") { + context.addIssue({ + code: "custom", + path: ["inviteCode"], + message: "Invite codes are only accepted with a pool claim", + }); + } + if (payload.kind !== "submission" && payload.kind !== "claim" && payload.proof !== undefined) { + context.addIssue({ code: "custom", path: ["proof"], message: "Proposal proof is forbidden" }); + } + }); + const proposalResponseSchema = z.looseObject({ id: uuidSchema, workOrderId: uuidSchema, providerAddress: addressSchema, state: z.enum(["pending", "accepted", "rejected", "withdrawn"]), - signedPayload: proposalSigningPayloadSchema.loose(), + signedPayload: proposalPayloadViewSchema, signature: signatureSchema, signatureHash: bytes32Schema, proposedMilestones: z.array(milestoneTermsBoundarySchema).length(1), @@ -846,7 +918,7 @@ export const publicTaskCardSchema = z.looseObject({ id: z.string(), title: z.string(), brief: z.string(), - shape: z.enum(["task", "open-bounty"]), + shape: z.enum(["task", "open-bounty", "pool"]), amount: publicAmountSchema.nullable(), deadlineAt: z.string().nullable(), durationSeconds: z.number().nullable(), diff --git a/packages/core/src/tasks/v2.ts b/packages/core/src/tasks/v2.ts index 0d895d0..64c3e98 100644 --- a/packages/core/src/tasks/v2.ts +++ b/packages/core/src/tasks/v2.ts @@ -21,7 +21,17 @@ export const proofRequirementSchema = z.discriminatedUnion("preset", [ ...label, chain: z.enum(["base", "base-sepolia", "solana"]).optional(), }), - z.strictObject({ preset: z.literal("pr"), ...label, ...contains }), + z.strictObject({ + preset: z.literal("pr"), + ...label, + ...contains, + repository: z + .string() + .regex(/^[A-Za-z0-9_-]+\/[A-Za-z0-9_.-]+$/u) + .optional(), + merged: z.literal(true).optional(), + challenge: z.literal(true).optional(), + }), z.strictObject({ preset: z.literal("text"), ...label, From 731e3e76d306f3203b51d04d617fd6dad8aff068 Mon Sep 17 00:00:00 2001 From: vAPI Development <336934719+vapi-development@users.noreply.github.com> Date: Wed, 2 Dec 2026 23:08:35 +0100 Subject: [PATCH 2/2] fix(tasks): validate response proof values without normalizing; pr binding fields go together Co-Authored-By: Claude Opus 5.5 Signed-off-by: vAPI Development <336934719+vapi-development@users.noreply.github.com> --- packages/core/src/tasks/server-parity.test.ts | 29 ++++++++++++++++++ packages/core/src/tasks/types.ts | 11 ++++--- packages/core/src/tasks/v2.ts | 30 ++++++++++++------- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/packages/core/src/tasks/server-parity.test.ts b/packages/core/src/tasks/server-parity.test.ts index d17267a..2656f4d 100644 --- a/packages/core/src/tasks/server-parity.test.ts +++ b/packages/core/src/tasks/server-parity.test.ts @@ -293,6 +293,31 @@ describe("merged server response contracts", () => { success: true, data: { workOrder: { proposals: [{ signedPayload: { proof: [{ value: signedLink }] } }] } }, }); + // Values are still validated: a bogus file hash or pr link fails, as on the server. + expect( + order([ + { + ...proposal, + signedPayload: { + ...proposal.signedPayload, + kind: "submission", + proof: [{ kind: "file", value: "bogus" }], + }, + }, + ]).success, + ).toBe(false); + expect( + order([ + { + ...proposal, + signedPayload: { + ...proposal.signedPayload, + kind: "claim", + proof: [{ preset: "pr", value: "bogus" }], + }, + }, + ]).success, + ).toBe(false); // Server rules: a malformed invite code, empty proof, and proof on a plain proposal fail. expect(order([claim("x", { inviteCode: "ABCD-1234" })]).success).toBe(false); expect( @@ -344,6 +369,10 @@ describe("merged server response contracts", () => { merged: true, challenge: true, }); + expect( + proofRequirementSchema.safeParse({ preset: "pr", repository: "vAPI-Network/vapi-network" }) + .success, + ).toBe(false); expect( proofRequirementSchema.safeParse({ preset: "pr", repository: "not a repo" }).success, ).toBe(false); diff --git a/packages/core/src/tasks/types.ts b/packages/core/src/tasks/types.ts index 6e8bc5f..ae2924b 100644 --- a/packages/core/src/tasks/types.ts +++ b/packages/core/src/tasks/types.ts @@ -1,5 +1,6 @@ import { z } from "zod"; import { taskTermsFields, taskViewFields } from "./v2.js"; +import { taskV2ProofSchema } from "./v2-write.js"; import { milestoneTermsSchema, @@ -343,8 +344,8 @@ export const feedQuerySchema = z.object({ // Mirrors the server's order-view payload (vapi-app workProposalPayloadViewSchema): a // pool order lists its pool claims as proposals with kind "claim" and preset proof fills. -// Response proof is checked by shape only and never normalized, so the parsed payload keeps -// the exact signed bytes. +// Response proof is validated with the request validators but returned unchanged, so the +// parsed payload keeps the exact signed bytes. const proofLabelViewSchema = z.string().optional(); const legacyProofViewSchema = z .array( @@ -354,7 +355,8 @@ const legacyProofViewSchema = z ]), ) .min(1) - .max(20); + .max(20) + .refine((proof) => z.array(submissionProofSchema).safeParse(proof).success, "Invalid proof"); const presetProofViewSchema = z .array( z.strictObject({ @@ -364,7 +366,8 @@ const presetProofViewSchema = z }), ) .min(1) - .max(20); + .max(20) + .refine((proof) => taskV2ProofSchema.safeParse(proof).success, "Invalid proof"); const proposalPayloadViewSchema = z .looseObject({ version: z.literal("work-proposal-v1"), diff --git a/packages/core/src/tasks/v2.ts b/packages/core/src/tasks/v2.ts index 64c3e98..d95cf54 100644 --- a/packages/core/src/tasks/v2.ts +++ b/packages/core/src/tasks/v2.ts @@ -21,17 +21,25 @@ export const proofRequirementSchema = z.discriminatedUnion("preset", [ ...label, chain: z.enum(["base", "base-sepolia", "solana"]).optional(), }), - z.strictObject({ - preset: z.literal("pr"), - ...label, - ...contains, - repository: z - .string() - .regex(/^[A-Za-z0-9_-]+\/[A-Za-z0-9_.-]+$/u) - .optional(), - merged: z.literal(true).optional(), - challenge: z.literal(true).optional(), - }), + z + .strictObject({ + preset: z.literal("pr"), + ...label, + ...contains, + repository: z + .string() + .regex(/^[A-Za-z0-9_-]+\/[A-Za-z0-9_.-]+$/u) + .optional(), + merged: z.literal(true).optional(), + challenge: z.literal(true).optional(), + }) + .refine( + // Server rule: a repository binding needs all three fields, or none. + (pr) => + [pr.repository, pr.merged, pr.challenge].every((v) => v === undefined) || + [pr.repository, pr.merged, pr.challenge].every((v) => v !== undefined), + "repository, merged and challenge go together", + ), z.strictObject({ preset: z.literal("text"), ...label,