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 | |
| 3 | import { |
| 4 | classifyDocsProduct, |
| 5 | DEFAULT_DOCS_PRODUCT, |
| 6 | DOCS_PRODUCTS, |
| 7 | docsProductDestination, |
| 8 | parseDocsProduct, |
| 9 | resolveDocsProduct, |
| 10 | serializeDocsProductCookie, |
| 11 | shouldAnimateDocsProductSwitch, |
| 12 | } from '../../lib/home-navigation'; |
| 13 | import { buildProductPageTree, pageTreeUrls } from '../../lib/product-page-tree'; |
| 14 | import { knowledgeBaseSource, referenceSource, source } from '../../lib/source'; |
| 15 | |
| 16 | describe('Docs product navigation', () => { |
| 17 | test('defines the product labels, descriptions, landings, and themes once', () => { |
| 18 | expect(DEFAULT_DOCS_PRODUCT).toBe('platform'); |
| 19 | expect(DOCS_PRODUCTS['for-you']).toMatchObject({ |
| 20 | product: 'For You', |
| 21 | switcherDescription: 'Connect your apps to AI clients.', |
| 22 | landingRoute: '/docs/agent-plugins', |
| 23 | theme: 'light', |
| 24 | themeColor: '#ffffff', |
| 25 | }); |
| 26 | expect(DOCS_PRODUCTS.platform).toMatchObject({ |
| 27 | product: 'Platform', |
| 28 | switcherDescription: 'Build agents with the Composio SDK.', |
| 29 | landingRoute: '/docs/quickstart', |
| 30 | theme: 'dark', |
| 31 | themeColor: '#131211', |
| 32 | }); |
| 33 | }); |
| 34 | |
| 35 | test('classifies audience routes while leaving shared routes unclassified', () => { |
| 36 | expect(classifyDocsProduct('/docs/agent-setup')).toBe('platform'); |
| 37 | expect(classifyDocsProduct('/docs/agent-plugins')).toBe('for-you'); |
| 38 | expect(classifyDocsProduct('/docs/composio-connect')).toBe('for-you'); |
| 39 | expect(classifyDocsProduct('/docs/providers/openai')).toBe('platform'); |
| 40 | expect(classifyDocsProduct('/docs/authentication/controlling-scopes')).toBe('platform'); |
| 41 | expect(classifyDocsProduct('/docs/consumer-agents')).toBe('platform'); |
| 42 | expect(classifyDocsProduct('/docs/b2b-agents')).toBe('platform'); |
| 43 | expect(classifyDocsProduct('/docs/production-readiness')).toBe('platform'); |
| 44 | expect(classifyDocsProduct('/docs')).toBeNull(); |
| 45 | expect(classifyDocsProduct('/docs/using-composio-skill')).toBeNull(); |
| 46 | expect(classifyDocsProduct('/docs/security/overview')).toBe('platform'); |
| 47 | expect(classifyDocsProduct('/docs/security/token-custody')).toBe('platform'); |
| 48 | expect(classifyDocsProduct('/docs/security/data-retention')).toBe('platform'); |
| 49 | expect(classifyDocsProduct('/docs/security/zero-data-retention')).toBe('platform'); |
| 50 | }); |
| 51 | |
| 52 | test('uses route inference before persistence and the documented default last', () => { |
| 53 | expect(resolveDocsProduct('/docs/quickstart', 'for-you')).toBe('platform'); |
| 54 | expect(resolveDocsProduct('/docs/using-composio-skill', 'for-you')).toBe('for-you'); |
| 55 | expect(resolveDocsProduct('/docs/using-composio-skill', 'platform')).toBe('platform'); |
| 56 | expect(resolveDocsProduct('/docs/security/overview', 'for-you')).toBe('platform'); |
| 57 | expect(resolveDocsProduct('/docs', 'invalid')).toBe('platform'); |
| 58 | expect(parseDocsProduct('for-you')).toBe('for-you'); |
| 59 | expect(parseDocsProduct('anything-else')).toBeNull(); |
| 60 | expect(serializeDocsProductCookie('for-you')).toContain( |
| 61 | 'composio-docs-product=for-you', |
| 62 | ); |
| 63 | expect(serializeDocsProductCookie('for-you')).toContain('SameSite=Lax'); |
| 64 | }); |
| 65 | |
| 66 | test('uses meaningful counterparts and otherwise falls back to product landings', () => { |
| 67 | expect(docsProductDestination('/docs/quickstart', 'for-you')).toBe( |
| 68 | '/docs/agent-plugins', |
| 69 | ); |
| 70 | expect(docsProductDestination('/docs/agent-plugins', 'platform')).toBe( |
| 71 | '/docs/quickstart', |
| 72 | ); |
| 73 | expect(docsProductDestination('/docs/sessions-via-mcp', 'for-you')).toBe( |
| 74 | '/docs/composio-connect', |
| 75 | ); |
| 76 | expect(docsProductDestination('/docs/composio-connect', 'platform')).toBe( |
| 77 | '/docs/sessions-via-mcp', |
| 78 | ); |
| 79 | expect(docsProductDestination('/docs/authentication', 'for-you')).toBe( |
| 80 | '/docs/agent-plugins', |
| 81 | ); |
| 82 | expect(docsProductDestination('/docs/cli', 'platform')).toBe('/docs/quickstart'); |
| 83 | expect(docsProductDestination('/docs/using-composio-skill', 'for-you')).toBe( |
| 84 | '/docs/using-composio-skill', |
| 85 | ); |
| 86 | expect(docsProductDestination('/docs/security/overview', 'for-you')).toBe( |
| 87 | '/docs/agent-plugins', |
| 88 | ); |
| 89 | expect(docsProductDestination('/docs/security/data-retention', 'for-you')).toBe( |
| 90 | '/docs/agent-plugins', |
| 91 | ); |
| 92 | expect(docsProductDestination('/docs/security/zero-data-retention', 'for-you')).toBe( |
| 93 | '/docs/agent-plugins', |
| 94 | ); |
| 95 | }); |
| 96 | |
| 97 | test('animates only when view transitions are available and motion is allowed', () => { |
| 98 | expect(shouldAnimateDocsProductSwitch(true, false)).toBe(true); |
| 99 | expect(shouldAnimateDocsProductSwitch(false, false)).toBe(false); |
| 100 | expect(shouldAnimateDocsProductSwitch(true, true)).toBe(false); |
| 101 | }); |
| 102 | |
| 103 | test('fades the outgoing product snapshot while revealing the incoming product', async () => { |
| 104 | const globalCss = await Bun.file( |
| 105 | new URL('../../app/global.css', import.meta.url), |
| 106 | ).text(); |
| 107 | const outgoingSnapshotRule = globalCss.match( |
| 108 | /::view-transition-old\(docs-product-shell\)\s*\{(?<rule>[^}]*)\}/, |
| 109 | ); |
| 110 | |
| 111 | expect(outgoingSnapshotRule?.groups?.rule).toContain('docs-product-fade-out'); |
| 112 | expect(outgoingSnapshotRule?.groups?.rule).not.toContain('animation: none'); |
| 113 | expect(globalCss).toContain('@keyframes docs-product-fade-out'); |
| 114 | }); |
| 115 | |
| 116 | test('builds audience-specific trees and keeps shared resources in both', () => { |
| 117 | const forYouTree = buildProductPageTree(source.pageTree, 'for-you'); |
| 118 | const platformTree = buildProductPageTree(source.pageTree, 'platform'); |
| 119 | const forYouUrls = pageTreeUrls(forYouTree); |
| 120 | const platformUrls = pageTreeUrls(platformTree); |
| 121 | |
| 122 | expect(forYouTree.$id).not.toBe(platformTree.$id); |
| 123 | |
| 124 | expect(forYouUrls).toContain('/docs/agent-plugins'); |
| 125 | expect(forYouUrls).toContain('/docs/cli'); |
| 126 | expect(forYouUrls).toContain('/docs/composio-connect'); |
| 127 | expect(forYouUrls).not.toContain('/docs/quickstart'); |
| 128 | |
| 129 | for (const url of [ |
| 130 | '/docs/quickstart', |
| 131 | '/docs/providers', |
| 132 | '/docs/how-composio-works', |
| 133 | '/docs/authentication', |
| 134 | '/docs/authentication/session-cant-find-account', |
| 135 | '/docs/skills', |
| 136 | '/docs/triggers', |
| 137 | '/docs/consumer-agents', |
| 138 | '/docs/b2b-agents', |
| 139 | '/docs/production-readiness', |
| 140 | ]) { |
| 141 | expect(platformUrls).toContain(url); |
| 142 | } |
| 143 | expect(platformUrls).not.toContain('/docs/agent-plugins'); |
| 144 | expect(platformUrls).toContain('/docs/agent-setup'); |
| 145 | |
| 146 | const agentGuides = platformTree.children.find( |
| 147 | node => node.type === 'folder' && node.name === 'Guides & Examples', |
| 148 | ); |
| 149 | expect(agentGuides?.type).toBe('folder'); |
| 150 | if (agentGuides?.type !== 'folder') throw new Error('Guides & Examples group is missing'); |
| 151 | expect(agentGuides.index?.url).toBe('/docs/consumer-agents'); |
| 152 | expect(agentGuides.children.map(node => node.type === 'page' ? node.url : null)).toEqual( |
| 153 | ['/docs/consumer-agents', '/docs/b2b-agents', '/examples'], |
| 154 | ); |
| 155 | expect(platformUrls.filter(url => url === '/docs/consumer-agents')).toHaveLength(1); |
| 156 | |
| 157 | const agentSetup = platformTree.children.find( |
| 158 | node => node.type === 'folder' && node.$ref?.folder === 'agent-setup', |
| 159 | ); |
| 160 | expect(agentSetup?.type).toBe('folder'); |
| 161 | if (agentSetup?.type !== 'folder') throw new Error('Agent setup folder is missing'); |
| 162 | expect(agentSetup.children).toContainEqual( |
| 163 | expect.objectContaining({ |
| 164 | type: 'page', |
| 165 | name: 'llms.txt', |
| 166 | url: '/llms.txt', |
| 167 | external: true, |
| 168 | }), |
| 169 | ); |
| 170 | |
| 171 | expect(forYouUrls).not.toContain('/docs'); |
| 172 | expect(platformUrls).not.toContain('/docs'); |
| 173 | |
| 174 | expect(forYouUrls).toContain('/docs/using-composio-skill'); |
| 175 | expect(platformUrls).toContain('/docs/using-composio-skill'); |
| 176 | |
| 177 | const securityUrls = [ |
| 178 | '/docs/security/overview', |
| 179 | '/docs/security/vendor-security-review', |
| 180 | 'https://trust.composio.dev', |
| 181 | '/docs/security/data-retention', |
| 182 | '/docs/security/zero-data-retention', |
| 183 | '/docs/security/token-custody', |
| 184 | '/docs/security/audit-logs', |
| 185 | '/docs/security/outbound-ips', |
| 186 | ]; |
| 187 | const securityStart = platformTree.children.findIndex( |
| 188 | node => node.type === 'separator' && node.name === 'Security and Compliance', |
| 189 | ); |
| 190 | expect(securityStart).toBeGreaterThan(-1); |
| 191 | const securityPages = platformTree.children.slice( |
| 192 | securityStart + 1, |
| 193 | platformTree.children.findIndex( |
| 194 | (node, index) => index > securityStart && node.type === 'separator', |
| 195 | ), |
| 196 | ); |
| 197 | expect(securityPages).toMatchObject([ |
| 198 | { type: 'page', url: '/docs/security/overview' }, |
| 199 | { type: 'folder', name: 'Compliance' }, |
| 200 | { type: 'folder', name: 'Data privacy' }, |
| 201 | { type: 'folder', name: 'Security controls' }, |
| 202 | ]); |
| 203 | expect(pageTreeUrls({ children: securityPages })).toEqual(securityUrls); |
| 204 | expect(securityPages.slice(1).map(node => node.type)).toEqual(['folder', 'folder', 'folder']); |
| 205 | const compliance = securityPages[1]; |
| 206 | if (compliance.type !== 'folder') throw new Error('Compliance group missing'); |
| 207 | expect(compliance.index?.url).toBe('/docs/security/vendor-security-review'); |
| 208 | expect(compliance.children).toContainEqual(expect.objectContaining({ |
| 209 | type: 'page', url: 'https://trust.composio.dev', external: true, |
| 210 | })); |
| 211 | for (const url of securityUrls) { |
| 212 | expect(platformUrls.filter(candidate => candidate === url)).toHaveLength(1); |
| 213 | expect(forYouUrls).not.toContain(url); |
| 214 | } |
| 215 | expect(source.getPage(['security', 'vendor-security-review'])?.url).toBe( |
| 216 | '/docs/security/vendor-security-review', |
| 217 | ); |
| 218 | expect(knowledgeBaseSource.getPage(['guide', 'platform-compliance-data-handling'])).toBeUndefined(); |
| 219 | const governance = platformTree.children.find( |
| 220 | node => node.type === 'folder' && node.name === 'Governance', |
| 221 | ); |
| 222 | expect(governance?.type).toBe('folder'); |
| 223 | expect(securityPages).not.toContain(governance); |
| 224 | |
| 225 | const readiness = platformTree.children.flatMap(node => |
| 226 | node.type === 'folder' ? [node, ...node.children] : [node], |
| 227 | ).find(node => node.type === 'folder' && node.name === 'Production readiness'); |
| 228 | expect(readiness?.type).toBe('folder'); |
| 229 | if (readiness?.type !== 'folder') throw new Error('Production readiness folder missing'); |
| 230 | const readinessUrls = readiness.children.flatMap(node => node.type === 'page' ? [node.url] : []); |
| 231 | expect(readinessUrls).toEqual([ |
| 232 | '/docs/authentication/custom-app-vs-managed-app', |
| 233 | '/reference/rate-limits', |
| 234 | '/docs/poc-to-prod/avoid-rate-limits', |
| 235 | '/docs/poc-to-prod/stream-logs-to-a-siem', |
| 236 | ]); |
| 237 | for (const url of readinessUrls) { |
| 238 | expect(platformUrls.filter(candidate => candidate === url)).toHaveLength(1); |
| 239 | expect(forYouUrls).not.toContain(url); |
| 240 | } |
| 241 | expect(pageTreeUrls(referenceSource.pageTree)).not.toContain('/reference/rate-limits'); |
| 242 | expect(referenceSource.getPage(['rate-limits'])?.url).toBe('/reference/rate-limits'); |
| 243 | |
| 244 | const coveredUrls = new Set([...forYouUrls, ...platformUrls]); |
| 245 | const excludedUrls = new Set(['/docs']); |
| 246 | const omittedUrls = pageTreeUrls(source.pageTree).filter( |
| 247 | url => !coveredUrls.has(url) && !excludedUrls.has(url), |
| 248 | ); |
| 249 | expect(omittedUrls).toEqual([]); |
| 250 | }); |
| 251 | |
| 252 | test('keeps accessibility-critical switcher semantics and visible focus styles', async () => { |
| 253 | const switcherSource = await Bun.file( |
| 254 | new URL('../../components/product-switcher.tsx', import.meta.url), |
| 255 | ).text(); |
| 256 | const sharedLayoutSource = await Bun.file( |
| 257 | new URL('../../lib/layout.shared.tsx', import.meta.url), |
| 258 | ).text(); |
| 259 | const contextSource = await Bun.file( |
| 260 | new URL('../../components/docs-product-context.tsx', import.meta.url), |
| 261 | ).text(); |
| 262 | const rootLayoutSource = await Bun.file( |
| 263 | new URL('../../app/layout.tsx', import.meta.url), |
| 264 | ).text(); |
| 265 | |
| 266 | expect(switcherSource).toContain('aria-label={`Switch Composio product. Current product:'); |
| 267 | expect(switcherSource).toContain('ProductSelectionLink'); |
| 268 | expect(switcherSource).not.toContain('role="radiogroup"'); |
| 269 | expect(switcherSource).not.toContain('role="radio"'); |
| 270 | expect(switcherSource).not.toContain('aria-checked={isCurrent}'); |
| 271 | expect(switcherSource).toContain("aria-current={isCurrent ? 'page' : undefined}"); |
| 272 | expect(switcherSource).toContain('focus-visible:outline-2'); |
| 273 | expect(switcherSource).toContain('aria-label="Composio home"'); |
| 274 | expect(switcherSource).toContain('href="/"'); |
| 275 | expect(sharedLayoutSource).toContain('slots: { navTitle: ProductNavTitle }'); |
| 276 | expect(sharedLayoutSource).toContain('themeSwitch: { enabled: false }'); |
| 277 | expect(contextSource).toContain('applyProductTheme(product)'); |
| 278 | expect(contextSource).toContain('.querySelector(\'meta[name="theme-color"]\')'); |
| 279 | expect(contextSource).toContain("?.setAttribute('content', themeColor)"); |
| 280 | expect(contextSource).toContain('window.setTimeout(finish, 1500)'); |
| 281 | expect(rootLayoutSource).toContain('forcedTheme: initialTheme'); |
| 282 | expect(rootLayoutSource).toContain("storageKey: 'composio-docs-theme'"); |
| 283 | expect(rootLayoutSource).toContain( |
| 284 | 'content={DOCS_PRODUCTS[initialProduct].themeColor}', |
| 285 | ); |
| 286 | expect(contextSource).not.toContain("localStorage.setItem('theme'"); |
| 287 | expect(rootLayoutSource).not.toContain("localStorage.setItem('theme'"); |
| 288 | expect(rootLayoutSource).toContain('hotKey: false'); |
| 289 | }); |
| 290 | }); |