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 | /** |
| 2 | * Sidebar nav index tests. |
| 3 | * |
| 4 | * Exercises the real docs page tree: `docs_sidebar_click` reports the group, |
| 5 | * folder and depth from this index, so a traversal bug silently drops pages |
| 6 | * from analytics rather than breaking the site. |
| 7 | */ |
| 8 | import { describe, expect, test } from 'bun:test'; |
| 9 | import { readFile } from 'node:fs/promises'; |
| 10 | import { join } from 'node:path'; |
| 11 | import { flattenTree } from 'fumadocs-core/page-tree'; |
| 12 | |
| 13 | import { buildSidebarNavIndex } from '../../lib/sidebar-nav-index'; |
| 14 | import { examplesSource, source } from '../../lib/source'; |
| 15 | |
| 16 | const index = buildSidebarNavIndex(source.pageTree); |
| 17 | |
| 18 | describe('buildSidebarNavIndex', () => { |
| 19 | test('example sections retain every page once and group the SDK walkthroughs', () => { |
| 20 | const pages = flattenTree(examplesSource.pageTree.children); |
| 21 | const urls = pages.map(page => page.url); |
| 22 | expect(new Set(urls).size).toBe(urls.length); |
| 23 | expect([...urls].sort()).toEqual(examplesSource.getPages().map(page => page.url).sort()); |
| 24 | |
| 25 | const examplesIndex = buildSidebarNavIndex(examplesSource.pageTree); |
| 26 | const groups = { |
| 27 | '/examples/sdk-examples': 'SDK examples', |
| 28 | '/examples/csv-report-agent': 'Complete agents', |
| 29 | '/examples/email-triggered-agent': 'Complete agents', |
| 30 | '/examples/multiple-accounts': 'Integration patterns', |
| 31 | '/examples/custom-tools': 'Integration patterns', |
| 32 | '/examples/cloudflare-workers': 'Deployment', |
| 33 | }; |
| 34 | for (const [url, group] of Object.entries(groups)) { |
| 35 | expect(examplesIndex[url]?.group).toBe(group); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | test('folder children carry their group, folder and depth', () => { |
| 40 | expect(index['/docs/authentication/white-labeling-authentication']).toEqual({ |
| 41 | group: 'Core concepts', |
| 42 | folder: 'Authentication', |
| 43 | depth: 2, |
| 44 | position: index['/docs/authentication/controlling-scopes'].position + 1, |
| 45 | }); |
| 46 | |
| 47 | expect(index['/docs/extending-sessions/shared-connections']).toEqual({ |
| 48 | group: 'Guides', |
| 49 | folder: 'Extend sessions', |
| 50 | depth: 2, |
| 51 | position: index['/docs/extending-sessions/local-tools-and-toolkits'].position + 1, |
| 52 | }); |
| 53 | }); |
| 54 | |
| 55 | test('top-level pages have no folder', () => { |
| 56 | expect(index['/docs/quickstart']).toEqual({ |
| 57 | group: 'Get Started', |
| 58 | folder: null, |
| 59 | depth: 1, |
| 60 | position: index['/docs'].position + 1, |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | test('governance guides stay top-level within the Governance section', () => { |
| 65 | expect(index['/docs/governance/action-permissions']).toEqual({ |
| 66 | group: 'Governance', |
| 67 | folder: null, |
| 68 | depth: 1, |
| 69 | position: 1, |
| 70 | }); |
| 71 | expect(index['/docs/governance/tool-hints']).toEqual({ |
| 72 | group: 'Governance', |
| 73 | folder: null, |
| 74 | depth: 1, |
| 75 | position: 2, |
| 76 | }); |
| 77 | expect(index['/docs/governance/approvals']).toEqual({ |
| 78 | group: 'Governance', |
| 79 | folder: null, |
| 80 | depth: 1, |
| 81 | position: 3, |
| 82 | }); |
| 83 | }); |
| 84 | |
| 85 | test('folder index pages resolve to the folder row', () => { |
| 86 | expect(index['/docs/authentication']).toEqual({ |
| 87 | group: 'Core concepts', |
| 88 | folder: 'Authentication', |
| 89 | depth: 1, |
| 90 | position: index['/docs/toolkits'].position + 1, |
| 91 | }); |
| 92 | }); |
| 93 | |
| 94 | test('position resets at the next separator', () => { |
| 95 | // Core concepts opens a new group, so its first entry restarts at 1 rather |
| 96 | // than continuing Get Started's numbering. |
| 97 | expect(index['/docs'].position).toBe(1); |
| 98 | expect(index['/docs/how-composio-works'].position).toBe(1); |
| 99 | }); |
| 100 | |
| 101 | test('a folder counts as one entry for its siblings', () => { |
| 102 | // A folder's children must not advance the parent-level position counter. |
| 103 | expect(index['/docs/triggers'].position).toBe(index['/docs/authentication'].position + 1); |
| 104 | expect(index['/docs/skills'].position).toBe(index['/docs/triggers'].position + 1); |
| 105 | }); |
| 106 | |
| 107 | test('nested folders restart the sequence at each level', () => { |
| 108 | expect(index['/docs/providers/custom-providers']).toEqual({ |
| 109 | group: 'Get Started', |
| 110 | folder: 'Custom providers', |
| 111 | depth: 2, |
| 112 | position: index['/docs/providers/mastra'].position + 1, |
| 113 | }); |
| 114 | expect(index['/docs/providers/custom-providers/typescript'].position).toBe(1); |
| 115 | }); |
| 116 | |
| 117 | test('a separator nested in a folder does not leak into the folder siblings', () => { |
| 118 | // No meta.json nests a separator today, but fumadocs allows it: the group |
| 119 | // and the counter are per-level, so "Inner" and its numbering stay inside |
| 120 | // the folder instead of resuming Outer's siblings mid-sequence. |
| 121 | const nested = buildSidebarNavIndex({ |
| 122 | name: 'root', |
| 123 | children: [ |
| 124 | { type: 'separator', name: 'Outer' }, |
| 125 | { type: 'page', name: 'First', url: '/a' }, |
| 126 | { |
| 127 | type: 'folder', |
| 128 | name: 'Folder', |
| 129 | children: [ |
| 130 | { type: 'separator', name: 'Inner' }, |
| 131 | { type: 'page', name: 'Child', url: '/a/child' }, |
| 132 | ], |
| 133 | }, |
| 134 | { type: 'page', name: 'Last', url: '/b' }, |
| 135 | ], |
| 136 | }); |
| 137 | |
| 138 | expect(nested['/a']).toEqual({ group: 'Outer', folder: null, depth: 1, position: 1 }); |
| 139 | expect(nested['/a/child']).toEqual({ |
| 140 | group: 'Inner', |
| 141 | folder: 'Folder', |
| 142 | depth: 2, |
| 143 | position: 1, |
| 144 | }); |
| 145 | expect(nested['/b']).toEqual({ group: 'Outer', folder: null, depth: 1, position: 3 }); |
| 146 | }); |
| 147 | |
| 148 | test('every page in the sidebar tree resolves to a non-null group', () => { |
| 149 | const missing = flattenTree(source.pageTree.children) |
| 150 | .map(page => page.url) |
| 151 | .filter(url => index[url]?.group == null); |
| 152 | |
| 153 | expect(missing).toEqual([]); |
| 154 | }); |
| 155 | |
| 156 | test('every root meta.json entry that is a page is indexed', async () => { |
| 157 | const meta = JSON.parse( |
| 158 | await readFile(join(import.meta.dir, '../../content/docs/meta.json'), 'utf-8') |
| 159 | ) as { pages: string[] }; |
| 160 | |
| 161 | const indexed = meta.pages |
| 162 | .filter(entry => !entry.startsWith('---') && entry !== '...') |
| 163 | .map(entry => (entry === 'index' ? '/docs' : `/docs/${entry}`)) |
| 164 | .filter(url => index[url] != null); |
| 165 | |
| 166 | // Entries that are folders without an index page have no url of their own. |
| 167 | expect(indexed).toContain('/docs/quickstart'); |
| 168 | expect(indexed).toContain('/docs/authentication'); |
| 169 | expect(indexed).toContain('/docs/providers'); |
| 170 | }); |
| 171 | }); |