@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, 03:37 UTC

next
ts 88 lines 2.93 KB
Raw
1 import { describe, expect, test } from 'bun:test';
2 import { metaToolSchema } from '../../lib/meta-tools-data';
3
4 const tool = {
5 slug: 'EXAMPLE_TOOL',
6 name: 'example_tool',
7 displayName: 'Example Tool',
8 description: 'Example API description.',
9 tags: [],
10 inputParameters: {},
11 responseSchema: {},
12 };
13
14 describe('meta-tool display model', () => {
15 test('normalizes unrestricted JSON and absent schema fields before rendering', () => {
16 const parsed = metaToolSchema.parse({
17 ...tool,
18 inputParameters: { properties: { body: { description: '**Any**\nJSON' } } },
19 });
20 expect(parsed.summary).toBe(tool.description);
21 expect(parsed.inputParameters.properties.body).toEqual({
22 typeLabel: 'any',
23 description: 'Any JSON',
24 defaultLabel: null,
25 properties: {},
26 required: [],
27 enum: [],
28 });
29 expect(parsed.responseSchema.properties).toEqual({});
30 expect(parsed.responseSchema.required).toEqual([]);
31 });
32
33 test('normalizes nested arrays and retains required item properties', () => {
34 const parsed = metaToolSchema.parse({
35 ...tool,
36 inputParameters: {
37 properties: {
38 rows: {
39 type: 'array',
40 items: {
41 type: 'array',
42 items: {
43 type: 'object',
44 required: ['id'],
45 properties: { id: { type: 'integer' } },
46 },
47 },
48 },
49 untyped_items: { type: 'array' },
50 nullable: { type: ['string', 'null'] },
51 },
52 },
53 });
54 const { rows, untyped_items, nullable } = parsed.inputParameters.properties;
55 expect(rows.typeLabel).toBe('array<array<object>>');
56 expect(rows.items?.items?.required).toEqual(['id']);
57 expect(rows.items?.items?.properties.id.typeLabel).toBe('integer');
58 expect(untyped_items.typeLabel).toBe('array<any>');
59 expect(nullable.typeLabel).toBe('string | null');
60 });
61
62 test('preserves falsy defaults and scalar enum values', () => {
63 const parsed = metaToolSchema.parse({
64 ...tool,
65 inputParameters: {
66 properties: {
67 count: { type: 'integer', default: 0, enum: [0, 1] },
68 enabled: { type: 'boolean', default: false, enum: [false, true] },
69 },
70 },
71 });
72 expect(parsed.inputParameters.properties.count.defaultLabel).toBe('0');
73 expect(parsed.inputParameters.properties.count.enum).toEqual(['0', '1']);
74 expect(parsed.inputParameters.properties.enabled.defaultLabel).toBe('false');
75 expect(parsed.inputParameters.properties.enabled.enum).toEqual(['false', 'true']);
76 });
77
78 test.each([{ type: 'invalid' }, { type: 42 }, { required: true }, { items: 'invalid' }])(
79 'rejects malformed schema fields instead of silently displaying any (%j)',
80 parameter => {
81 const result = metaToolSchema.safeParse({
82 ...tool,
83 inputParameters: { properties: { body: parameter } },
84 });
85 expect(result.success).toBe(false);
86 }
87 );
88 });