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 89 lines 4.09 KB
Raw
1 import { describe, expect, test } from 'bun:test';
2 import { readFileSync, readdirSync } from 'node:fs';
3 import { join } from 'node:path';
4 import { getAlgoliaSearchDocuments } from '@/lib/search-index';
5 import { getKbGuideUrl, getKbCatalog, getPublishedKbGuides } from '@/lib/kb/repository';
6 import { getLocalKnowledgeDiscoveryPaths } from '@/lib/knowledge/discovery';
7 import { getKnowledgeToolkitSummaries } from '@/lib/knowledge/catalog';
8 import { getToolkitKnowledgeRedirect } from '@/lib/knowledge/toolkit-routing';
9
10 function source(path: string): string {
11 return readFileSync(join(import.meta.dir, '../..', path), 'utf8');
12 }
13
14 describe('public KB discovery', () => {
15 test('indexes published KB pages below conceptual docs and above examples', async () => {
16 const records = await getAlgoliaSearchDocuments();
17 const kbRecords = records.filter((record) => record.source_type === 'kb');
18
19 expect(kbRecords.length).toBeGreaterThan(0);
20 expect(kbRecords.every((record) => record.page_rank === 1_900)).toBe(true);
21 });
22
23 test('discovers every published guide and keeps article files aligned with the manifest', async () => {
24 const authoredGuides = getPublishedKbGuides().filter((guide) => guide.articlePath);
25 const articlePaths = readdirSync(join(process.cwd(), 'kb/articles'))
26 .filter((file) => file.endsWith('.md'))
27 .sort();
28 const discoveryPaths = await getLocalKnowledgeDiscoveryPaths();
29 const records = await getAlgoliaSearchDocuments();
30
31 expect(authoredGuides).toHaveLength(getPublishedKbGuides().length);
32 // Every published guide resolves to a file, and no file is orphaned from
33 // the manifest. This remains valid regardless of what the KB says.
34 const publishedPaths = new Set(authoredGuides.map((guide) => guide.articlePath));
35 const manifestPaths = new Set(
36 getKbCatalog()
37 .guides.map((guide) => guide.articlePath)
38 .filter((path): path is string => Boolean(path)),
39 );
40 for (const path of publishedPaths) {
41 expect(articlePaths).toContain(path);
42 }
43 for (const file of articlePaths) {
44 expect(manifestPaths).toContain(file);
45 }
46
47 for (const guide of authoredGuides) {
48 const url = getKbGuideUrl(guide);
49 expect(discoveryPaths).toContain(url);
50 expect(records.some((record) => record.source_type === 'kb' && record.canonical_url === url)).toBe(true);
51 }
52 });
53
54 test('registers the KB source with sitemap, links, and LLM endpoints', () => {
55 expect(source('app/sitemap.ts')).toContain('knowledgeBaseSource');
56 expect(source('app/sitemap.ts')).toContain('getLocalKnowledgeDiscoveryPaths');
57 expect(source('scripts/validate-links.ts')).toContain('knowledgeBaseSource');
58 expect(source('scripts/validate-links.ts')).toContain('getLocalKnowledgeDiscoveryPaths');
59 expect(source('app/llms-index.txt/route.ts')).toContain('knowledgeBaseSource');
60 expect(source('app/llms-index.txt/route.ts')).toContain('getLocalKnowledgeDiscoveryPaths');
61 expect(source('app/llms-full.txt/route.ts')).toContain('knowledgeBaseSource');
62 expect(source('app/llms-full.txt/route.ts')).toContain('getLocalKnowledgeDiscoveryPaths');
63 expect(source('app/llms.mdx/[[...slug]]/route.ts')).toContain("prefix: 'kb'");
64 expect(source('app/llms.mdx/[[...slug]]/route.ts')).toContain('knowledgeBrowseToMarkdown');
65 });
66
67 test('publishes toolkit collection pages but not redirect-only aliases', async () => {
68 const summaries = await getKnowledgeToolkitSummaries();
69 const discoveryPaths = await getLocalKnowledgeDiscoveryPaths();
70
71 for (const toolkit of summaries) {
72 const legacyPath = `/kb/toolkit/${toolkit.slug}`;
73 if (getToolkitKnowledgeRedirect(toolkit)) {
74 expect(discoveryPaths).not.toContain(legacyPath);
75 } else {
76 expect(discoveryPaths).toContain(legacyPath);
77 }
78 }
79 });
80
81 test('explicitly traces runtime KB files into Vercel routes', () => {
82 const nextConfig = source('next.config.mjs');
83
84 expect(nextConfig).toContain("'/kb/**': ['./kb/**']");
85 expect(nextConfig).toContain(
86 "'/api/knowledge-search/**': [...OPENAPI_SPEC_FILES, './content/**', './kb/**']",
87 );
88 });
89 });