Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { describe, expect, test } from 'bun:test'; |
| 2 | import { |
| 3 | classifyKnowledgeRecord, |
| 4 | normalizeKnowledgeKeywords, |
| 5 | normalizeToolkitSlug, |
| 6 | } from '@/lib/knowledge/metadata'; |
| 7 | import { isProductAreaSlug, PRODUCT_AREAS } from '@/lib/knowledge/taxonomy'; |
| 8 | import * as taxonomyModule from '@/lib/knowledge/taxonomy'; |
| 9 | import { getAlgoliaSearchDocuments } from '@/lib/search-index'; |
| 10 | |
| 11 | describe('unified knowledge metadata', () => { |
| 12 | test('defines five support topics that reflect the current corpus', () => { |
| 13 | const defaultAreas = PRODUCT_AREAS.filter((area) => area.defaultBrowse); |
| 14 | |
| 15 | expect(defaultAreas).toHaveLength(5); |
| 16 | expect(defaultAreas.map((area) => area.slug)).toEqual([ |
| 17 | 'authentication-and-connected-accounts', |
| 18 | 'tools-actions-and-execution', |
| 19 | 'triggers-and-workflows', |
| 20 | 'sdk-api-and-mcp', |
| 21 | 'account-billing-and-security', |
| 22 | ]); |
| 23 | expect(PRODUCT_AREAS.every((area) => area.defaultBrowse)).toBe(true); |
| 24 | expect(isProductAreaSlug('sdk-api-and-mcp')).toBe(true); |
| 25 | expect(isProductAreaSlug('sdk-and-api')).toBe(false); |
| 26 | expect(isProductAreaSlug('incidents-and-known-issues')).toBe(false); |
| 27 | }); |
| 28 | |
| 29 | test('maps current KB topics to a focused support topic and useful intents', () => { |
| 30 | expect(classifyKnowledgeRecord({ |
| 31 | sourceType: 'kb', |
| 32 | canonicalUrl: '/kb/guide/custom-connection-data-fields-are-toolkit-specific', |
| 33 | topics: ['authentication', 'auth-config', 'errors-and-troubleshooting'], |
| 34 | lastVerifiedAt: '2026-07-22', |
| 35 | })).toEqual({ |
| 36 | source_type: 'kb', |
| 37 | canonical_url: '/kb/guide/custom-connection-data-fields-are-toolkit-specific', |
| 38 | product_areas: ['authentication-and-connected-accounts'], |
| 39 | toolkit_slugs: [], |
| 40 | intents: ['how-to', 'troubleshooting'], |
| 41 | last_verified_at: '2026-07-22', |
| 42 | }); |
| 43 | }); |
| 44 | |
| 45 | test('redirects old product-area URLs to the replacement support topic', () => { |
| 46 | const getProductAreaRedirect = ( |
| 47 | taxonomyModule as { getProductAreaRedirect?: (slug: string) => string | null } |
| 48 | ).getProductAreaRedirect; |
| 49 | |
| 50 | expect(typeof getProductAreaRedirect).toBe('function'); |
| 51 | expect(getProductAreaRedirect?.('tools-and-actions')) |
| 52 | .toBe('/kb/topic/tools-actions-and-execution'); |
| 53 | expect(getProductAreaRedirect?.('tool-router-mcp-and-workbench')) |
| 54 | .toBe('/kb/topic/sdk-api-and-mcp'); |
| 55 | expect(getProductAreaRedirect?.('composio-for-you')) |
| 56 | .toBe('/kb/search?q=Composio+For+You'); |
| 57 | expect(getProductAreaRedirect?.('not-a-topic')).toBeNull(); |
| 58 | }); |
| 59 | |
| 60 | test.each([ |
| 61 | ['/docs/auth-configuration/custom-auth-configs', 'authentication-and-connected-accounts'], |
| 62 | ['/docs/providers/langchain', 'sdk-api-and-mcp'], |
| 63 | ['/docs/tools-direct/executing-tools', 'tools-actions-and-execution'], |
| 64 | ['/docs/setting-up-triggers/creating-triggers', 'triggers-and-workflows'], |
| 65 | ['/docs/extending-sessions/proxy-execute', 'tools-actions-and-execution'], |
| 66 | ['/docs/migration-guide/new-sdk', 'sdk-api-and-mcp'], |
| 67 | ['/docs/sandbox/remote', 'tools-actions-and-execution'], |
| 68 | ['/docs/sessions-via-mcp', 'sdk-api-and-mcp'], |
| 69 | ['/docs/configuring-sessions', 'tools-actions-and-execution'], |
| 70 | ])('maps %s to %s', (canonicalUrl, expectedArea) => { |
| 71 | const metadata = classifyKnowledgeRecord({ sourceType: 'docs', canonicalUrl }); |
| 72 | expect(metadata.product_areas).toContain(expectedArea); |
| 73 | }); |
| 74 | |
| 75 | test('normalizes toolkit and deprecated product aliases', () => { |
| 76 | expect(normalizeToolkitSlug(' Google Calendar ')).toBe('google-calendar'); |
| 77 | expect(normalizeKnowledgeKeywords(['Rube', 'rube MCP', 'Composio For You', 'MCP'])) |
| 78 | .toEqual(['Composio For You', 'MCP']); |
| 79 | }); |
| 80 | |
| 81 | test('classifies toolkit and reference records without prose guessing', () => { |
| 82 | expect(classifyKnowledgeRecord({ |
| 83 | sourceType: 'toolkit', |
| 84 | canonicalUrl: '/toolkits/github', |
| 85 | toolkitSlugs: ['github'], |
| 86 | })).toMatchObject({ |
| 87 | product_areas: [], |
| 88 | toolkit_slugs: ['github'], |
| 89 | }); |
| 90 | expect(classifyKnowledgeRecord({ |
| 91 | sourceType: 'reference', |
| 92 | canonicalUrl: '/reference/sdk-reference/typescript', |
| 93 | })).toMatchObject({ |
| 94 | source_type: 'reference', |
| 95 | product_areas: ['sdk-api-and-mcp'], |
| 96 | intents: ['reference'], |
| 97 | }); |
| 98 | }); |
| 99 | |
| 100 | test('adds normalized metadata to every local search record', async () => { |
| 101 | const records = await getAlgoliaSearchDocuments(); |
| 102 | const toolkitKbRecord = records.find(record => |
| 103 | record.source_type === 'kb' && record.toolkit_slugs.length > 0, |
| 104 | ); |
| 105 | |
| 106 | expect(records.length).toBeGreaterThan(0); |
| 107 | expect(records.every((record) => Boolean(record.canonical_url))).toBe(true); |
| 108 | expect(records.every((record) => Boolean(record.source_type))).toBe(true); |
| 109 | expect(records.every((record) => Array.isArray(record.product_areas))).toBe(true); |
| 110 | expect(records.every((record) => Array.isArray(record.toolkit_slugs))).toBe(true); |
| 111 | expect(records.every((record) => Array.isArray(record.intents))).toBe(true); |
| 112 | expect(toolkitKbRecord).toMatchObject({ |
| 113 | source_type: 'kb', |
| 114 | page_rank: 1_900, |
| 115 | }); |
| 116 | expect(toolkitKbRecord?.canonical_url.startsWith('/kb/guide/')).toBe(true); |
| 117 | expect(toolkitKbRecord?.toolkit_slugs.every(slug => slug === normalizeToolkitSlug(slug))) |
| 118 | .toBe(true); |
| 119 | }); |
| 120 | }); |