@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
ts 50 lines 2.25 KB
Raw
1 import Ajv from 'ajv';
2 import { describe, expect, it } from 'vitest';
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 const ajv = new Ajv({ strict: false });
9
10 describe('v4 acceptance matches v3 without rewriting the input', () => {
11 it.each([
12 { name: 'a uri with surrounding spaces', value: ' https://example.com/a b ' },
13 { name: 'a uri with a mixed-case host', value: 'https://Example.COM/Path?Q=1' },
14 { name: 'a uri with a trailing newline', value: 'https://example.com/\n' },
15 ])('keeps $name as given', ({ value }) => {
16 const schema: JsonSchema = { type: 'string', format: 'uri' };
17 const v3 = toV3(schema).safeParse(value);
18 const v4 = toV4(schema).safeParse(value);
19 expect(v4.success).toBe(v3.success);
20 expect(v4.success && v4.data).toBe(v3.success && v3.data);
21 expect(v4.success && v4.data).toBe(value);
22 });
23
24 it('accepts a uuid with a non-RFC variant, as v3 does', () => {
25 const schema: JsonSchema = { type: 'string', format: 'uuid' };
26 const value = '123e4567-e89b-12d3-c456-426614174000';
27 expect(toV3(schema).safeParse(value).success).toBe(true);
28 expect(toV4(schema).safeParse(value).success).toBe(true);
29 expect(toV4(schema).safeParse('not-a-uuid').success).toBe(false);
30 });
31
32 it('accepts an integer above 2^53, as v3 and Ajv do', () => {
33 const schema: JsonSchema = { type: 'integer' };
34 const value = 2 ** 53 + 2;
35 expect(ajv.compile(schema)(value)).toBe(true);
36 expect(toV3(schema).safeParse(value).success).toBe(true);
37 expect(toV4(schema).safeParse(value).success).toBe(true);
38 expect(toV4(schema).safeParse(1.5).success).toBe(false);
39 expect(toV4({ type: 'number', format: 'int64' }).safeParse(value).success).toBe(true);
40 expect(toV4({ type: 'number', multipleOf: 1 }).safeParse(value).success).toBe(true);
41 });
42
43 it.each(['127.0.0.1', '::1', '2001:db8::ff00:42:8329'])('accepts ip %s', value => {
44 expect(toV4({ type: 'string', format: 'ip' }).safeParse(value).success).toBe(true);
45 });
46
47 it('rejects a value that is neither an IPv4 nor an IPv6 address', () => {
48 expect(toV4({ type: 'string', format: 'ip' }).safeParse('999.1.1.1').success).toBe(false);
49 });
50 });