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
| 1 | import { describe, expect, test } from 'bun:test'; |
| 2 | import { |
| 3 | countMarkdownTools, |
| 4 | cacheEntryBytes, |
| 5 | CACHE_ENTRY_LIMIT, |
| 6 | findInstantProblems, |
| 7 | findProblems, |
| 8 | PAGE_BYTES_BUDGET, |
| 9 | productionToolCounts, |
| 10 | selectWatchList, |
| 11 | } from '../../scripts/check-toolkit-parity'; |
| 12 | |
| 13 | const markdown = [ |
| 14 | '# Tableau', |
| 15 | '', |
| 16 | '- **Tools:** 436', |
| 17 | '', |
| 18 | '## Frequently Asked Questions', |
| 19 | '', |
| 20 | '### Does it support OAuth?', |
| 21 | '', |
| 22 | '## Tools', |
| 23 | '', |
| 24 | '### List Users', |
| 25 | '', |
| 26 | '**Slug:** `TABLEAU_LIST_USERS`', |
| 27 | '', |
| 28 | '## Pagination', |
| 29 | '', |
| 30 | 'Use the cursor to retrieve more users.', |
| 31 | '', |
| 32 | '### List Views', |
| 33 | '', |
| 34 | '**Slug:** `TABLEAU_LIST_VIEWS`', |
| 35 | '', |
| 36 | '## Triggers', |
| 37 | '', |
| 38 | '### New View', |
| 39 | '', |
| 40 | '**Slug:** `TABLEAU_NEW_VIEW_TRIGGER`', |
| 41 | ].join('\n'); |
| 42 | |
| 43 | const healthy = { |
| 44 | slug: 'tableau', |
| 45 | snapshotCount: 436, |
| 46 | productionCount: 436, |
| 47 | deployedCount: 436, |
| 48 | largestPageBytes: 1_231_773, |
| 49 | }; |
| 50 | |
| 51 | describe('countMarkdownTools', () => { |
| 52 | test('counts tools after a heading in a description and excludes triggers', () => { |
| 53 | expect(countMarkdownTools(markdown)).toBe(2); |
| 54 | }); |
| 55 | |
| 56 | test('returns 0 for a page without a Tools section', () => { |
| 57 | expect(countMarkdownTools('# Empty toolkit\n\n## Triggers\n\n**Slug:** `X`')).toBe(0); |
| 58 | }); |
| 59 | }); |
| 60 | |
| 61 | describe('findProblems', () => { |
| 62 | test('accepts a page that matches production and the snapshot', () => { |
| 63 | expect(findProblems(healthy)).toEqual([]); |
| 64 | }); |
| 65 | |
| 66 | test('flags the stale tableau.md listing 10 of 436 tools', () => { |
| 67 | expect(findProblems({ ...healthy, deployedCount: 10 })).toEqual([ |
| 68 | 'tableau.md lists 10 tools; production has 436, the snapshot has 436', |
| 69 | ]); |
| 70 | }); |
| 71 | |
| 72 | test('accepts a page that still matches a snapshot awaiting its data-sync PR', () => { |
| 73 | expect(findProblems({ ...healthy, snapshotCount: 10, deployedCount: 10 })).toEqual([]); |
| 74 | }); |
| 75 | |
| 76 | test('flags a snapshot cut off at the API page cap', () => { |
| 77 | expect(findProblems({ ...healthy, slug: 'microsoft_365', snapshotCount: 1000, productionCount: 1208, deployedCount: 1208 })).toEqual([ |
| 78 | 'the microsoft_365 snapshot stops at 1000 of 1208 tools, the API page cap; the committed snapshot predates the paginated generator, so re-run generate:toolkits', |
| 79 | ]); |
| 80 | }); |
| 81 | |
| 82 | test('measures the page budget on the base64 cache entry, not the raw body', () => { |
| 83 | // 1.6 MB raw stays under 2 MiB, but its base64 entry (2.13 MB) does not fit. |
| 84 | expect(cacheEntryBytes(1_600_000)).toBeGreaterThan(CACHE_ENTRY_LIMIT); |
| 85 | expect(findProblems({ ...healthy, largestPageBytes: 1_600_000 })).toHaveLength(1); |
| 86 | expect(cacheEntryBytes(healthy.largestPageBytes)).toBeLessThanOrEqual(PAGE_BYTES_BUDGET); |
| 87 | }); |
| 88 | }); |
| 89 | |
| 90 | describe('findInstantProblems', () => { |
| 91 | const instant = { productionSlugs: ['exa', 'tavily'], deployedSlugs: ['tavily', 'exa'], largestPageBytes: 400_000 }; |
| 92 | |
| 93 | test('accepts the same slugs in any order', () => { |
| 94 | expect(findInstantProblems(instant)).toEqual([]); |
| 95 | }); |
| 96 | |
| 97 | test('flags a deployed list frozen before a toolkit gained Instant support', () => { |
| 98 | expect(findInstantProblems({ ...instant, deployedSlugs: ['exa'] })).toEqual([ |
| 99 | '/api/toolkits/instant lists 1 toolkits; production has 2 (missing: tavily; extra: none)', |
| 100 | ]); |
| 101 | }); |
| 102 | |
| 103 | test('flags a production /toolkits page whose cache entry is over budget', () => { |
| 104 | expect(findInstantProblems({ ...instant, largestPageBytes: 1_600_000 })).toHaveLength(1); |
| 105 | }); |
| 106 | }); |
| 107 | |
| 108 | describe('selectWatchList', () => { |
| 109 | const snapshot = [ |
| 110 | { slug: 'github', toolCount: 905 }, |
| 111 | { slug: 'tableau', toolCount: 10 }, |
| 112 | { slug: 'gmail', toolCount: 60 }, |
| 113 | { slug: 'slack', toolCount: 150 }, |
| 114 | ]; |
| 115 | |
| 116 | test('keeps a toolkit whose snapshot count collapsed, using production counts', () => { |
| 117 | const production = [ |
| 118 | { slug: 'github', toolCount: 905 }, |
| 119 | { slug: 'tableau', toolCount: 436 }, |
| 120 | { slug: 'gmail', toolCount: 60 }, |
| 121 | { slug: 'slack', toolCount: 150 }, |
| 122 | ]; |
| 123 | |
| 124 | expect(selectWatchList(snapshot, production, 2).map(toolkit => toolkit.slug)).toEqual([ |
| 125 | 'github', |
| 126 | 'tableau', |
| 127 | 'slack', |
| 128 | ]); |
| 129 | }); |
| 130 | |
| 131 | test('carries snapshot counts and skips production toolkits without a published page', () => { |
| 132 | const production = [{ slug: 'unpublished', toolCount: 5000 }, { slug: 'tableau', toolCount: 436 }]; |
| 133 | |
| 134 | expect(selectWatchList(snapshot, production, 1)).toEqual([ |
| 135 | { slug: 'tableau', toolCount: 10 }, |
| 136 | { slug: 'github', toolCount: 905 }, |
| 137 | ]); |
| 138 | }); |
| 139 | |
| 140 | test('falls back to the snapshot ranking without production counts', () => { |
| 141 | expect(selectWatchList(snapshot, [], 2).map(toolkit => toolkit.slug)).toEqual(['github', 'slack']); |
| 142 | }); |
| 143 | }); |
| 144 | |
| 145 | describe('productionToolCounts', () => { |
| 146 | test('reads meta.tools_count and lowercases slugs', () => { |
| 147 | expect(productionToolCounts([{ slug: 'TABLEAU', meta: { tools_count: 436 } }])).toEqual([ |
| 148 | { slug: 'tableau', toolCount: 436 }, |
| 149 | ]); |
| 150 | }); |
| 151 | |
| 152 | test('rejects a listing without tool counts', () => { |
| 153 | expect(() => productionToolCounts([{ slug: 'tableau' }])).toThrow(); |
| 154 | }); |
| 155 | }); |