Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 06:00 UTC
| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | import * as z4 from 'zod/v4'; |
| 3 | |
| 4 | import { jsonSchemaToZod as toV3 } from '../../src/index'; |
| 5 | import { jsonSchemaToZod as toV4 } from '../../src/v4'; |
| 6 | import type { JsonSchema } from '../../src/types'; |
| 7 | |
| 8 | describe('v4 intersections', () => { |
| 9 | const conflicting: JsonSchema = { |
| 10 | allOf: [ |
| 11 | { type: 'object', properties: { a: { type: 'string', default: 'left' } } }, |
| 12 | { type: 'object', properties: { a: { type: 'string', default: 'right' } } }, |
| 13 | ], |
| 14 | }; |
| 15 | |
| 16 | it('reports a failure instead of throwing when the branches cannot merge', () => { |
| 17 | expect(() => |
| 18 | z4.intersection(z4.any().prefault('left'), z4.any().prefault('right')).safeParse(undefined) |
| 19 | ).toThrow('Unmergable intersection'); |
| 20 | expect(toV3(conflicting).safeParse({}).success).toBe(false); |
| 21 | const result = toV4(conflicting).safeParse({}); |
| 22 | expect(result.success).toBe(false); |
| 23 | expect(result.success ? [] : result.error.issues.map(issue => issue.code)).toEqual(['custom']); |
| 24 | }); |
| 25 | |
| 26 | it('keeps the failure through a described clone', () => { |
| 27 | expect(toV4(conflicting).describe('conflict').safeParse({}).success).toBe(false); |
| 28 | expect(toV4(conflicting).describe('conflict').safeParse({ a: 'same' }).success).toBe(true); |
| 29 | }); |
| 30 | }); |