@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 86 lines 4.55 KB
Raw
1 import { describe, expect, test } from 'bun:test';
2 import { instantDiscount, instantPricingDescription, instantSchema, toolkitSupportsInstant } from '../../lib/instant';
3 import { readFileSync } from 'node:fs';
4 import { toolFromApi } from '../../lib/toolkit-schema';
5 import { parseNamedItems, transformToolkit } from '../../scripts/generate-toolkits';
6 import { spawnSync } from 'node:child_process';
7 import { join } from 'node:path';
8
9 describe('Instant catalog metadata', () => {
10 test('toolkit headers show live tool eligibility when the snapshot lacks Instant metadata', () => {
11 // Other suites mock next/navigation; render with real Next exports in a fresh process.
12 const rendered = spawnSync(process.execPath, ['--eval', `
13 import { createElement } from 'react';
14 import { renderToStaticMarkup } from 'react-dom/server';
15 import { ToolkitDetail } from './components/toolkits/toolkit-detail';
16 import { toolFromApi } from './lib/toolkit-schema';
17 const toolkit = {
18 slug: 'example', name: 'Example', logo: null, category: null,
19 description: 'Example toolkit', authSchemes: [], toolCount: 1,
20 triggerCount: 0, version: null, tools: [], triggers: [],
21 };
22 console.log(renderToStaticMarkup(createElement(ToolkitDetail, {
23 toolkit,
24 tools: [toolFromApi({ slug: 'EXAMPLE_SEARCH', instant: { supported: true } })],
25 triggers: [], path: '/toolkits/example',
26 })));
27 `], { cwd: join(import.meta.dir, '../..'), encoding: 'utf8', timeout: 10000 });
28 expect(rendered.status, rendered.stderr).toBe(0);
29 const html = rendered.stdout;
30 expect(html).toContain('is available on the latest version. Check each tool for support and pricing.');
31 expect(html.match(/title="Instant is supported on the latest version"/g)).toHaveLength(2);
32 });
33
34 test('missing, false, and partial support never imply eligibility', () => {
35 for (const instant of [undefined, null, {}, { supported: false }, { supported: 'true' }, { price: { description: 'A price' } }]) {
36 const parsed = instantSchema.parse(instant);
37 expect(parsed?.supported === true).toBe(false);
38 expect(instantPricingDescription(parsed)).toBeUndefined();
39 }
40 });
41
42 test('toolkit support requires explicit eligibility from the toolkit or at least one tool', () => {
43 const tools = [
44 { instant: { supported: false } },
45 {},
46 { instant: { price: { description: '$1 per call' } } },
47 ];
48 expect(toolkitSupportsInstant(undefined, tools)).toBe(false);
49 expect(toolkitSupportsInstant({ supported: false }, tools)).toBe(false);
50 expect(toolkitSupportsInstant(undefined, [...tools, { instant: { supported: true } }])).toBe(true);
51 expect(toolkitSupportsInstant({ supported: true }, [])).toBe(true);
52 });
53
54 test('missing or malformed pricing is not free', () => {
55 for (const price of [undefined, null, {}, { description: '' }, { description: 0 }]) {
56 expect(instantPricingDescription(instantSchema.parse({ supported: true, price }))).toBe('Pricing is not available.');
57 }
58 });
59
60 test('generator and API parsers preserve the same metadata, including string discounts', () => {
61 const instant = { supported: true, price: { description: '$1 per request', discount: '0' } };
62 const raw = { slug: 'EXAMPLE', instant };
63 expect(transformToolkit(raw).instant).toEqual(instant);
64 expect(parseNamedItems({ items: [raw] })[0].instant).toEqual(instant);
65 expect(toolFromApi(raw).instant).toEqual(instant);
66 expect(instantPricingDescription(instant)).toBe('$1 per request');
67 expect(toolFromApi({ slug: 'OTHER' }).instant).toBeUndefined();
68 });
69
70 test('shows meaningful discount strings without interpreting units', () => {
71 for (const discount of ['15', '$0.20', '20% off']) {
72 expect(instantDiscount(instantSchema.parse({ supported: true, price: { discount } }))).toBe(discount);
73 }
74 for (const discount of [undefined, null, '', ' ', '0', ' 0 ', 15]) {
75 expect(instantDiscount(instantSchema.parse({ supported: true, price: { discount } }))).toBeUndefined();
76 }
77 expect(instantDiscount(instantSchema.parse({ supported: false, price: { discount: '15' } }))).toBeUndefined();
78 expect(instantDiscount(undefined)).toBeUndefined();
79 });
80
81 test('tool expansions request latest schemas while triggers retain their toolkit version', () => {
82 const source = readFileSync(new URL('../../components/toolkits/toolkit-detail.tsx', import.meta.url), 'utf8');
83 expect(source).toContain('item={tool} toolkitVersion="latest"');
84 expect(source).toContain('item={trigger} toolkitVersion={toolkit.version}');
85 });
86 });