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 { readFileSync } from 'node:fs'; |
| 3 | import { join } from 'node:path'; |
| 4 | import type { ComponentType } from 'react'; |
| 5 | import { renderToStaticMarkup } from 'react-dom/server'; |
| 6 | import KnowledgeBaseLayout from '@/app/(home)/kb/layout'; |
| 7 | import { KnowledgeHub } from '@/components/kb/knowledge-hub'; |
| 8 | import { |
| 9 | getKnowledgeSearchHref, |
| 10 | KnowledgeSearchForm, |
| 11 | } from '@/components/kb/knowledge-search-form'; |
| 12 | import { KnowledgeSearchResults } from '@/components/kb/knowledge-search-results'; |
| 13 | import { AIToolsBanner } from '@/components/ai-tools-banner'; |
| 14 | import * as knowledgeSearchResultsModule from '@/components/kb/knowledge-search-results'; |
| 15 | import type { KnowledgeSearchResult } from '@/lib/knowledge/search'; |
| 16 | |
| 17 | const initialSearchResponse = { |
| 18 | query: 'authentication', |
| 19 | filter: 'all' as const, |
| 20 | total: 3, |
| 21 | mode: 'keyword' as const, |
| 22 | results: [ |
| 23 | { |
| 24 | objectID: 'docs-authentication', |
| 25 | title: 'Authentication overview', |
| 26 | excerpt: 'Configure authentication for Composio.', |
| 27 | canonicalUrl: '/docs/authentication', |
| 28 | sourceType: 'docs' as const, |
| 29 | sourceLabel: 'Docs', |
| 30 | breadcrumbs: [], |
| 31 | productAreas: [], |
| 32 | toolkitSlugs: [], |
| 33 | lastVerifiedAt: null, |
| 34 | section: null, |
| 35 | }, |
| 36 | { |
| 37 | objectID: 'toolkit-github', |
| 38 | title: 'GitHub toolkit', |
| 39 | excerpt: 'Use GitHub actions through Composio.', |
| 40 | canonicalUrl: '/toolkits/github', |
| 41 | sourceType: 'toolkit' as const, |
| 42 | sourceLabel: 'Toolkit', |
| 43 | breadcrumbs: [], |
| 44 | productAreas: [], |
| 45 | toolkitSlugs: ['github'], |
| 46 | lastVerifiedAt: null, |
| 47 | section: null, |
| 48 | }, |
| 49 | { |
| 50 | objectID: 'reference-tools', |
| 51 | title: 'Tools API reference', |
| 52 | excerpt: 'Reference for tool APIs.', |
| 53 | canonicalUrl: '/reference/tools', |
| 54 | sourceType: 'reference' as const, |
| 55 | sourceLabel: 'Reference', |
| 56 | breadcrumbs: [], |
| 57 | productAreas: [], |
| 58 | toolkitSlugs: [], |
| 59 | lastVerifiedAt: null, |
| 60 | section: null, |
| 61 | }, |
| 62 | ], |
| 63 | }; |
| 64 | |
| 65 | function source(path: string): string { |
| 66 | return readFileSync(join(import.meta.dir, '../..', path), 'utf8'); |
| 67 | } |
| 68 | |
| 69 | describe('knowledge hub', () => { |
| 70 | test('does not add a second viewport height below the shared header', () => { |
| 71 | const html = renderToStaticMarkup( |
| 72 | <KnowledgeBaseLayout> |
| 73 | <main>Short knowledge page</main> |
| 74 | </KnowledgeBaseLayout>, |
| 75 | ); |
| 76 | |
| 77 | expect(html).not.toContain('min-h-dvh'); |
| 78 | expect(html).toContain('class="flex-1'); |
| 79 | }); |
| 80 | |
| 81 | test('renders a search-first landing page with curated recovery paths', async () => { |
| 82 | const html = renderToStaticMarkup(await KnowledgeHub()); |
| 83 | |
| 84 | expect(html).toContain('Search Composio support knowledge'); |
| 85 | expect(html).not.toContain('Composio Knowledge Base'); |
| 86 | const linkedTopics = new Set( |
| 87 | [...html.matchAll(/href="\/kb\/topic\/([a-z0-9-]+)"/g)].map((match) => match[1]), |
| 88 | ); |
| 89 | expect(linkedTopics.size).toBe(5); |
| 90 | expect(html.match(/href="\/kb\/topic\//g)?.length).toBe(linkedTopics.size); |
| 91 | expect(html).toContain('Support topics'); |
| 92 | expect(html).toContain('Browse by toolkit'); |
| 93 | expect(html).toContain('View all toolkits'); |
| 94 | expect(html).toContain('sm:justify-between'); |
| 95 | expect(html).toContain('lg:grid-cols-5'); |
| 96 | expect(html).not.toContain('lg:col-span'); |
| 97 | expect(html).toContain('space-y-12'); |
| 98 | expect(html).not.toContain('Featured answers and guides'); |
| 99 | expect(html).not.toContain('href="/kb/guide/platform-pagination"'); |
| 100 | expect(html).not.toContain('Popular searches'); |
| 101 | expect(html).not.toContain('href="/kb/search?q=OAuth+errors&filter=kb"'); |
| 102 | expect(html).toContain('width="28"'); |
| 103 | expect(html).toContain('height="28"'); |
| 104 | }); |
| 105 | |
| 106 | test('keeps homepage discovery sections actionable', async () => { |
| 107 | const html = renderToStaticMarkup(await KnowledgeHub()); |
| 108 | const discoverySections = [ |
| 109 | ...html.matchAll(/<section[^>]*aria-labelledby="[^"]+"[^>]*>[\s\S]*?<\/section>/g), |
| 110 | ].map((match) => match[0]); |
| 111 | |
| 112 | expect(discoverySections.length).toBeGreaterThanOrEqual(2); |
| 113 | expect(discoverySections.every((section) => section.includes('href='))).toBe(true); |
| 114 | }); |
| 115 | |
| 116 | test('presents the primary getting-started paths before support browsing', async () => { |
| 117 | const html = renderToStaticMarkup(await KnowledgeHub()); |
| 118 | const startHere = html.match( |
| 119 | /<section[^>]*aria-labelledby="start-here-title"[^>]*>[\s\S]*?<\/section>/, |
| 120 | )?.[0]; |
| 121 | |
| 122 | expect(startHere).toBeDefined(); |
| 123 | expect(startHere?.match(/href="[^"]+"/g)).toEqual([ |
| 124 | 'href="/docs/quickstart"', |
| 125 | 'href="/docs/using-composio-skill"', |
| 126 | 'href="/docs/consumer-agents"', |
| 127 | 'href="/docs/b2b-agents"', |
| 128 | 'href="/docs/production-readiness"', |
| 129 | ]); |
| 130 | |
| 131 | const startHereIndex = html.indexOf('aria-labelledby="start-here-title"'); |
| 132 | const supportTopicsIndex = html.indexOf('aria-labelledby="support-topics-title"'); |
| 133 | const toolkitsIndex = html.indexOf('aria-labelledby="toolkits-title"'); |
| 134 | |
| 135 | expect(startHereIndex).toBeGreaterThan(-1); |
| 136 | expect(startHereIndex).toBeLessThan(supportTopicsIndex); |
| 137 | expect(supportTopicsIndex).toBeLessThan(toolkitsIndex); |
| 138 | }); |
| 139 | |
| 140 | test('builds a shareable search URL and exposes a screen-reader-only label', () => { |
| 141 | expect(getKnowledgeSearchHref('oauth github')) |
| 142 | .toBe('/kb/search?q=oauth+github'); |
| 143 | const html = renderToStaticMarkup(<KnowledgeSearchForm defaultQuery="oauth github" />); |
| 144 | |
| 145 | expect(html).toContain('<label'); |
| 146 | expect(html).toContain('Search support knowledge'); |
| 147 | expect(html).toContain('class="sr-only"'); |
| 148 | expect(html).toContain('name="q"'); |
| 149 | expect(html).not.toContain('name="filter"'); |
| 150 | expect(html).toContain('focus-visible:ring-2'); |
| 151 | expect(html).toContain('focus-within:ring-2'); |
| 152 | expect(html).toContain('border-l border-fd-border'); |
| 153 | expect(html).not.toContain('absolute right-2'); |
| 154 | }); |
| 155 | |
| 156 | test('renders initial results with concise mixed-source labels', () => { |
| 157 | const html = renderToStaticMarkup( |
| 158 | <KnowledgeSearchResults |
| 159 | query="authentication" |
| 160 | initialResponse={initialSearchResponse} |
| 161 | failed={false} |
| 162 | />, |
| 163 | ); |
| 164 | |
| 165 | expect(html).toContain('href="/docs/authentication"'); |
| 166 | expect(html).toContain('Documentation'); |
| 167 | expect(html).toContain('Toolkit'); |
| 168 | expect(html).toContain('API Reference'); |
| 169 | expect(html).not.toContain('Guide'); |
| 170 | }); |
| 171 | |
| 172 | test('keeps initial search results free of mount-time fetching', () => { |
| 173 | const resultsSource = source('components/kb/knowledge-search-results.tsx'); |
| 174 | |
| 175 | expect(resultsSource).not.toContain('fetch('); |
| 176 | expect(resultsSource).not.toContain('useEffect'); |
| 177 | }); |
| 178 | |
| 179 | test('shows the canonical Composio skill install command and repository', () => { |
| 180 | const html = renderToStaticMarkup(<AIToolsBanner />); |
| 181 | |
| 182 | expect(html).toContain('npx skills add ComposioHQ/composio --skill composio -y'); |
| 183 | expect(html).toContain('https://github.com/ComposioHQ/composio/tree/next/skills/composio'); |
| 184 | expect(html).not.toContain('npx skills add composiohq/skills'); |
| 185 | }); |
| 186 | |
| 187 | test('identifies matching query terms for result emphasis', () => { |
| 188 | const getHighlightedSegments = ( |
| 189 | knowledgeSearchResultsModule as { |
| 190 | getHighlightedSegments?: ( |
| 191 | text: string, |
| 192 | query: string, |
| 193 | ) => Array<{ text: string; highlighted: boolean }>; |
| 194 | } |
| 195 | ).getHighlightedSegments; |
| 196 | |
| 197 | expect(typeof getHighlightedSegments).toBe('function'); |
| 198 | expect(getHighlightedSegments?.('GitHub OAuth redirect URI', 'github uri')).toEqual([ |
| 199 | { text: 'GitHub', highlighted: true }, |
| 200 | { text: ' OAuth redirect ', highlighted: false }, |
| 201 | { text: 'URI', highlighted: true }, |
| 202 | ]); |
| 203 | }); |
| 204 | |
| 205 | test('uses customer-facing fallback copy in search results', () => { |
| 206 | const getKnowledgeSearchDisplayExcerpt = ( |
| 207 | knowledgeSearchResultsModule as { |
| 208 | getKnowledgeSearchDisplayExcerpt?: ( |
| 209 | excerpt: string, |
| 210 | section?: string | null, |
| 211 | ) => string; |
| 212 | } |
| 213 | ).getKnowledgeSearchDisplayExcerpt; |
| 214 | |
| 215 | expect(typeof getKnowledgeSearchDisplayExcerpt).toBe('function'); |
| 216 | expect(getKnowledgeSearchDisplayExcerpt?.('Public support knowledge for Airtable.')) |
| 217 | .toBe('Setup and troubleshooting guidance for Airtable in Composio.'); |
| 218 | expect(getKnowledgeSearchDisplayExcerpt?.('Current navigation for connecting apps.')) |
| 219 | .toBe('Current navigation for connecting apps.'); |
| 220 | expect(getKnowledgeSearchDisplayExcerpt?.('Heading; details', 'Heading')) |
| 221 | .toBe('details'); |
| 222 | expect(getKnowledgeSearchDisplayExcerpt?.('Heading - details', 'Heading')) |
| 223 | .toBe('details'); |
| 224 | expect(getKnowledgeSearchDisplayExcerpt?.('Heading,', 'Heading')) |
| 225 | .toBe(''); |
| 226 | expect(getKnowledgeSearchDisplayExcerpt?.('Sending attachments', 'Send')) |
| 227 | .toBe('Sending attachments'); |
| 228 | expect(getKnowledgeSearchDisplayExcerpt?.('API-key authentication', 'API')) |
| 229 | .toBe('API-key authentication'); |
| 230 | }); |
| 231 | |
| 232 | test('omits the redundant guide label from search result cards', () => { |
| 233 | const KnowledgeSearchResultCard = ( |
| 234 | knowledgeSearchResultsModule as { |
| 235 | KnowledgeSearchResultCard?: ComponentType<{ |
| 236 | result: KnowledgeSearchResult; |
| 237 | query: string; |
| 238 | onClick?: () => void; |
| 239 | }>; |
| 240 | } |
| 241 | ).KnowledgeSearchResultCard; |
| 242 | expect(typeof KnowledgeSearchResultCard).toBe('function'); |
| 243 | if (!KnowledgeSearchResultCard) return; |
| 244 | |
| 245 | const html = renderToStaticMarkup(<KnowledgeSearchResultCard |
| 246 | query="notion" |
| 247 | result={{ |
| 248 | objectID: 'notion', |
| 249 | title: 'Notion', |
| 250 | excerpt: 'Troubleshoot connection and response-size issues.', |
| 251 | canonicalUrl: '/kb/guide/toolkits-notion', |
| 252 | sourceType: 'kb', |
| 253 | sourceLabel: 'Knowledge Base', |
| 254 | breadcrumbs: ['Guide'], |
| 255 | productAreas: [], |
| 256 | toolkitSlugs: ['notion'], |
| 257 | lastVerifiedAt: '2026-08-17', |
| 258 | section: null, |
| 259 | }} |
| 260 | />); |
| 261 | |
| 262 | expect(html).toContain('Support'); |
| 263 | expect(html).toContain('Notion'); |
| 264 | expect(html).not.toContain('Guide'); |
| 265 | }); |
| 266 | |
| 267 | test('keeps the page title primary and renders the matched section as context', () => { |
| 268 | const html = renderToStaticMarkup( |
| 269 | <knowledgeSearchResultsModule.KnowledgeSearchResultCard |
| 270 | query="support" |
| 271 | result={{ |
| 272 | objectID: 'gmail-attachments', |
| 273 | title: 'Gmail', |
| 274 | excerpt: 'Send attachments safely, Upload files before tool execution.', |
| 275 | canonicalUrl: '/kb/guide/toolkits-gmail', |
| 276 | sourceType: 'kb', |
| 277 | sourceLabel: 'Knowledge Base', |
| 278 | breadcrumbs: ['Guide'], |
| 279 | productAreas: [], |
| 280 | toolkitSlugs: ['gmail'], |
| 281 | lastVerifiedAt: '2026-08-17', |
| 282 | section: 'Send attachments safely,', |
| 283 | }} |
| 284 | />, |
| 285 | ); |
| 286 | |
| 287 | expect(html).toContain('Support'); |
| 288 | expect(html).not.toContain('Support · Gmail'); |
| 289 | expect(html).toContain('>Gmail</h3>'); |
| 290 | expect(html.match(/Send attachments safely/g)?.length).toBe(1); |
| 291 | expect(html).not.toContain('Send attachments safely,'); |
| 292 | expect(html).toContain('Upload files before tool execution.'); |
| 293 | expect(html.indexOf('Support')).toBeLessThan(html.indexOf('>Gmail</h3>')); |
| 294 | expect(html.indexOf('>Gmail</h3>')).toBeLessThan(html.indexOf('Send ')); |
| 295 | expect(html.indexOf('Send ')).toBeLessThan(html.indexOf('Upload files')); |
| 296 | }); |
| 297 | |
| 298 | test('does not repeat a section that only differs from the page title by punctuation', () => { |
| 299 | const html = renderToStaticMarkup( |
| 300 | <knowledgeSearchResultsModule.KnowledgeSearchResultCard |
| 301 | query="support" |
| 302 | result={{ |
| 303 | objectID: 'gmail-overview', |
| 304 | title: 'Gmail', |
| 305 | excerpt: 'Gmail: Send and receive email.', |
| 306 | canonicalUrl: '/toolkits/gmail', |
| 307 | sourceType: 'toolkit', |
| 308 | sourceLabel: 'Toolkit', |
| 309 | breadcrumbs: [], |
| 310 | productAreas: [], |
| 311 | toolkitSlugs: ['gmail'], |
| 312 | lastVerifiedAt: null, |
| 313 | section: 'Gmail:', |
| 314 | }} |
| 315 | />, |
| 316 | ); |
| 317 | |
| 318 | expect(html.match(/Gmail/g)?.length).toBe(1); |
| 319 | expect(html).toContain('Send and receive email.'); |
| 320 | }); |
| 321 | |
| 322 | test('does not repeat a section-only match as its own excerpt', () => { |
| 323 | const section = 'Create a SHARED Gmail connection that any userId can use,'; |
| 324 | const html = renderToStaticMarkup( |
| 325 | <knowledgeSearchResultsModule.KnowledgeSearchResultCard |
| 326 | query="gmail" |
| 327 | result={{ |
| 328 | objectID: 'shared-gmail', |
| 329 | title: 'Shared connections', |
| 330 | excerpt: section, |
| 331 | canonicalUrl: '/docs/shared-connections', |
| 332 | sourceType: 'docs', |
| 333 | sourceLabel: 'Docs', |
| 334 | breadcrumbs: [], |
| 335 | productAreas: [], |
| 336 | toolkitSlugs: [], |
| 337 | lastVerifiedAt: null, |
| 338 | section, |
| 339 | }} |
| 340 | />, |
| 341 | ); |
| 342 | |
| 343 | expect(html.match(/Create a SHARED/g)?.length).toBe(1); |
| 344 | }); |
| 345 | |
| 346 | test('renders Markdown-formatted section context as plain text without repeating it', () => { |
| 347 | const html = renderToStaticMarkup( |
| 348 | <knowledgeSearchResultsModule.KnowledgeSearchResultCard |
| 349 | query="context" |
| 350 | result={{ |
| 351 | objectID: 'custom-tools-context', |
| 352 | title: 'Custom Tools and Toolkits', |
| 353 | excerpt: 'Context object (ctx) Every custom tool receives context.', |
| 354 | canonicalUrl: '/docs/custom-tools', |
| 355 | sourceType: 'docs', |
| 356 | sourceLabel: 'Docs', |
| 357 | breadcrumbs: [], |
| 358 | productAreas: [], |
| 359 | toolkitSlugs: [], |
| 360 | lastVerifiedAt: null, |
| 361 | section: 'Context object (`ctx`)', |
| 362 | }} |
| 363 | />, |
| 364 | ); |
| 365 | |
| 366 | expect(html).not.toContain('`'); |
| 367 | expect(html.match(/object \(ctx\)/g)?.length).toBe(1); |
| 368 | expect(html).toContain('Every custom tool receives'); |
| 369 | }); |
| 370 | |
| 371 | test('implements accessible result, empty, and failure states', () => { |
| 372 | const resultsSource = source('components/kb/knowledge-search-results.tsx'); |
| 373 | |
| 374 | expect(resultsSource).toContain('aria-live="polite"'); |
| 375 | expect(resultsSource).toContain('No results for'); |
| 376 | expect(resultsSource).toContain('Browse support topics'); |
| 377 | expect(resultsSource).toContain('Browse toolkits'); |
| 378 | expect(resultsSource).toContain('Search is temporarily unavailable'); |
| 379 | expect(resultsSource).toContain('source_type'); |
| 380 | }); |
| 381 | |
| 382 | test('removes the generated Fumadocs tree from the KB layout', () => { |
| 383 | const layoutSource = source('app/(home)/kb/layout.tsx'); |
| 384 | expect(layoutSource).not.toContain('createDocsLayout'); |
| 385 | expect(layoutSource).not.toContain('knowledgeBaseSource.pageTree'); |
| 386 | }); |
| 387 | }); |