@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, 04:45 UTC

next
ts 100 lines 3.41 KB
Raw
1 import { describe, expect, it } from '@effect/vitest';
2 import {
3 guessToolkitFromToolSlug,
4 longestPrefix,
5 matchToolkitFromToolSlug,
6 } from 'src/utils/toolkit-from-tool-slug';
7
8 describe('guessToolkitFromToolSlug', () => {
9 it('takes the text before the first underscore', () => {
10 expect(guessToolkitFromToolSlug('GITHUB_CREATE_ISSUE')).toBe('github');
11 });
12
13 it('lowercases a slug without underscores', () => {
14 expect(guessToolkitFromToolSlug('GITHUB')).toBe('github');
15 });
16
17 it('returns undefined for composio meta slugs', () => {
18 expect(guessToolkitFromToolSlug('COMPOSIO_ENABLE_TRIGGER')).toBeUndefined();
19 });
20
21 it('cannot recover multi-word toolkit slugs', () => {
22 expect(guessToolkitFromToolSlug('GOOGLE_ANALYTICS_RUN_REPORT')).toBe('google');
23 });
24 });
25
26 describe('longestPrefix', () => {
27 it('tries candidates longest-first at each underscore boundary', () => {
28 const known = ['a', 'a_b', 'a_b_c'];
29 expect(longestPrefix('A_B_C_D', known)).toBe('a_b_c');
30 expect(longestPrefix('A_B_X_Y', known)).toBe('a_b');
31 expect(longestPrefix('A_X_Y_Z', known)).toBe('a');
32 });
33
34 it('returns undefined when no candidate is known', () => {
35 expect(longestPrefix('A_B_C_D', ['other'])).toBeUndefined();
36 expect(longestPrefix('A_B_C_D', [])).toBeUndefined();
37 });
38
39 it('never matches the whole tool slug as a toolkit', () => {
40 expect(longestPrefix('A_B', ['a_b'])).toBeUndefined();
41 });
42
43 it('applies no policy: the composio candidate is returned as-is', () => {
44 expect(longestPrefix('COMPOSIO_ENABLE_TRIGGER', ['composio'])).toBe('composio');
45 });
46 });
47
48 describe('matchToolkitFromToolSlug', () => {
49 const knownToolkits = [
50 'github',
51 'google',
52 'google_analytics',
53 'gmail',
54 'microsoft',
55 'microsoft_teams',
56 ];
57
58 it('resolves multi-word toolkits by longest known prefix', () => {
59 expect(matchToolkitFromToolSlug('GOOGLE_ANALYTICS_RUN_REPORT', knownToolkits)).toBe(
60 'google_analytics'
61 );
62 expect(matchToolkitFromToolSlug('MICROSOFT_TEAMS_SEND_MESSAGE', knownToolkits)).toBe(
63 'microsoft_teams'
64 );
65 });
66
67 it('tries candidates longest-first at each underscore boundary', () => {
68 const known = ['reddit', 'reddit_ads'];
69 expect(matchToolkitFromToolSlug('REDDIT_ADS_GET_CAMPAIGN', known)).toBe('reddit_ads');
70 expect(matchToolkitFromToolSlug('REDDIT_GET_POST', known)).toBe('reddit');
71 });
72
73 it('resolves single-word toolkits', () => {
74 expect(matchToolkitFromToolSlug('GITHUB_CREATE_ISSUE', knownToolkits)).toBe('github');
75 });
76
77 it('is independent of the known-list order', () => {
78 expect(
79 matchToolkitFromToolSlug('MICROSOFT_TEAMS_SEND_MESSAGE', [...knownToolkits].reverse())
80 ).toBe('microsoft_teams');
81 });
82
83 it('falls back to the guess when no known toolkit matches', () => {
84 expect(matchToolkitFromToolSlug('NOTION_CREATE_PAGE', knownToolkits)).toBe('notion');
85 });
86
87 it('falls back to the guess with an empty known list', () => {
88 expect(matchToolkitFromToolSlug('GOOGLE_ANALYTICS_RUN_REPORT', [])).toBe('google');
89 });
90
91 it('returns undefined for composio meta slugs even when composio is known', () => {
92 expect(matchToolkitFromToolSlug('COMPOSIO_ENABLE_TRIGGER', ['composio'])).toBeUndefined();
93 });
94
95 it('prefers a longer composio-prefixed toolkit over the meta guard', () => {
96 expect(
97 matchToolkitFromToolSlug('COMPOSIO_SEARCH_NEWS_SEARCH', ['composio', 'composio_search'])
98 ).toBe('composio_search');
99 });
100 });