Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 50 lines 2.05 KB
Raw
1 import { describe, expect, test } from 'bun:test';
2 import { scanURLs, validateFiles } from 'next-validate-link';
3 import { getKnowledgeToolkitSummaries } from '@/lib/knowledge/catalog';
4 import * as linkValidation from '../../scripts/validate-links';
5
6 describe('link validation', () => {
7 test('accepts known toolkit HTML and Markdown routes while rejecting unknown toolkits', async () => {
8 const scanned = await scanURLs({
9 preset: 'next',
10 populate: {
11 '(home)/toolkits/[[...slug]]': await linkValidation.getDynamicToolkitEntries(),
12 },
13 });
14 const errors = await validateFiles([{
15 path: 'toolkit-links.mdx',
16 url: '/kb/guide/toolkits-gmail',
17 content: [
18 '[Gmail](/toolkits/gmail)',
19 '[Gmail Markdown](/toolkits/gmail.md)',
20 '[Gmail MDX](/toolkits/gmail.mdx)',
21 '[Unknown toolkit](/toolkits/not-a-real-toolkit.md)',
22 ].join('\n'),
23 }], { scanned, checkRelativePaths: 'as-url', checkExternal: false });
24
25 expect(errors.flatMap(file => file.errors.map(error => error.url))).toEqual([
26 '/toolkits/not-a-real-toolkit.md',
27 ]);
28 });
29
30 test('strips BOM and CRLF YAML provenance without removing body links', () => {
31 const fixture = '\uFEFF---\r\nsources: [{"sourcePath":"kb/toolkits/example/public.md","sourceHeading":"Example"}]\r\n---\r\nRead [the guide](/kb/guide/example).\r\n';
32 const withoutFrontmatter = (linkValidation as {
33 withoutFrontmatter?: (content: string) => string;
34 }).withoutFrontmatter;
35
36 expect(withoutFrontmatter).toBeTypeOf('function');
37 expect(withoutFrontmatter!(fixture)).toBe('Read [the guide](/kb/guide/example).\r\n');
38 });
39
40 test('accepts redirecting toolkit knowledge routes as resolvable links', async () => {
41 const redirectingToolkit = (await getKnowledgeToolkitSummaries()).find(
42 toolkit => toolkit.knowledgeCount === 1,
43 );
44
45 expect(redirectingToolkit).toBeDefined();
46
47 const entries = await linkValidation.getKnowledgeToolkitRouteEntries();
48 expect(entries.map(entry => entry.value)).toContain(redirectingToolkit!.slug);
49 });
50 });