fix(file-block): fix get op#4590
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR introduces a new
Confidence Score: 4/5Safe to merge; the new get operation is correctly gated behind workspace-access verification, and the file retrieval query filters by both workspaceId and fileId. The core logic — workspace guard, fileId resolution, DB lookup — is correct. The two findings are in the Zod contract: the refine predicate admits null fileInput (handled by a secondary check in the route), and the switch to z.union produces less descriptive errors on invalid operations. Neither is a runtime defect, but the contract layer is slightly weaker than it could be. apps/sim/lib/api/contracts/tools/file.ts — the refine check and the discriminatedUnion→union change both sit here. Important Files Changed
Reviews (1): Last reviewed commit: "Fix auth" | Re-trigger Greptile |
| .refine((data) => data.fileId !== undefined || data.fileInput !== undefined, { | ||
| message: 'Either fileId or fileInput is required for get operation', | ||
| }) |
There was a problem hiding this comment.
The
.refine() predicate uses strict !== undefined, so { operation: 'get', fileInput: null } passes Zod validation (since null !== undefined). The route handler catches this downstream with its own empty-ID check, but the schema's intent is to block such payloads early. Using != null (loose inequality) or an explicit truthiness check would keep the two layers consistent.
| .refine((data) => data.fileId !== undefined || data.fileInput !== undefined, { | |
| message: 'Either fileId or fileInput is required for get operation', | |
| }) | |
| .refine((data) => data.fileId != null || data.fileInput != null, { | |
| message: 'Either fileId or fileInput is required for get operation', | |
| }) |
| export const fileManageBodySchema = z.union([ | ||
| fileManageWriteBodySchema, | ||
| fileManageAppendBodySchema, | ||
| fileManageGetBodySchema, | ||
| ]) |
There was a problem hiding this comment.
discriminatedUnion → union downgrades error quality
The schema was changed from z.discriminatedUnion('operation', [...]) to z.union([...]) because fileManageGetBodySchema uses .refine(), which produces a ZodEffects type incompatible with discriminatedUnion. The trade-off is that with z.union, an invalid operation (e.g. { operation: 'delete' }) causes Zod to try every branch sequentially and return a multi-branch error message rather than a clear discriminant mismatch. Not a runtime bug since invalid operations are still rejected, but consider moving the cross-field validation into the route handler to restore discriminatedUnion and its targeted error messages.
Summary
Add another guard for user
Type of Change
Testing
Manual
Checklist