Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | import { describe, expect, test } from 'bun:test'; |
| 2 | import { z } from 'zod'; |
| 3 | import { getPublishedKbGuides, getKbGuideUrl } from '@/lib/kb/repository'; |
| 4 | import { fetchPage } from './helpers'; |
| 5 | |
| 6 | const metadataSchema = z.object({ |
| 7 | canonical_url: z.url(), |
| 8 | markdown_url: z.url(), |
| 9 | product: z.enum(['platform', 'for-you']), |
| 10 | version: z.enum(['3.1', '3.0']).nullable(), |
| 11 | last_updated: z.iso.datetime().nullable(), |
| 12 | }); |
| 13 | |
| 14 | function parseMetadata(text: string) { |
| 15 | const match = text.match(/^---\n([\s\S]*?)\n---\n\n/); |
| 16 | expect(match, 'Markdown starts with YAML metadata').not.toBeNull(); |
| 17 | return metadataSchema.parse(Bun.YAML.parse(match![1])); |
| 18 | } |
| 19 | |
| 20 | describe('agent-readable Markdown metadata', () => { |
| 21 | test('suffix, direct and negotiated representations identify the same resource', async () => { |
| 22 | const responses = await Promise.all([ |
| 23 | fetchPage('/docs/quickstart.md'), |
| 24 | fetchPage('/docs/quickstart.mdx'), |
| 25 | fetchPage('/llms.mdx/docs/quickstart'), |
| 26 | fetchPage('/docs/quickstart', { headers: { Accept: 'text/markdown' } }), |
| 27 | fetchPage('/docs/quickstart', { headers: { Accept: 'text/plain' } }), |
| 28 | ]); |
| 29 | const metadata = await Promise.all(responses.map(async response => { |
| 30 | expect(response.status).toBe(200); |
| 31 | expect(response.headers.get('content-type')).toContain('text/markdown'); |
| 32 | return parseMetadata(await response.text()); |
| 33 | })); |
| 34 | expect(metadata[0]).toMatchObject({ |
| 35 | canonical_url: 'https://docs.composio.dev/docs/quickstart', |
| 36 | markdown_url: 'https://docs.composio.dev/docs/quickstart.md', |
| 37 | product: 'platform', |
| 38 | version: null, |
| 39 | }); |
| 40 | for (const item of metadata.slice(1)) expect(item).toEqual(metadata[0]); |
| 41 | |
| 42 | const sitemap = await (await fetchPage('/sitemap.xml')).text(); |
| 43 | const entry = sitemap.match(/<url>\s*<loc>https:\/\/docs\.composio\.dev\/docs\/quickstart<\/loc>\s*<lastmod>([^<]+)<\/lastmod>/); |
| 44 | expect(entry, 'known source freshness is published in the sitemap').not.toBeNull(); |
| 45 | expect(metadata[0].last_updated).toBe(entry![1]); |
| 46 | }); |
| 47 | |
| 48 | test('shared catalogs and manifests do not claim page freshness', async () => { |
| 49 | const guide = getPublishedKbGuides()[0]; |
| 50 | expect(guide).toBeDefined(); |
| 51 | const sitemap = await (await fetchPage('/sitemap.xml')).text(); |
| 52 | const entries = sitemap.match(/<url>[\s\S]*?<\/url>/g) ?? []; |
| 53 | for (const path of [ |
| 54 | '/reference/api-reference/files/postFilesUploadRequest', |
| 55 | '/reference/v3/api-reference/files/postFilesUploadRequest', |
| 56 | '/toolkits/github', '/toolkits/meta-tools/search_tools', |
| 57 | '/toolkits', '/toolkits/managed-auth', '/examples', |
| 58 | '/kb', '/kb/topic/authentication-and-connected-accounts', |
| 59 | getKbGuideUrl(guide), |
| 60 | ]) { |
| 61 | const response = await fetchPage(`${path}.md`, { timeout: 30_000 }); |
| 62 | expect(response.status).toBe(200); |
| 63 | expect(parseMetadata(await response.text()).last_updated, path).toBeNull(); |
| 64 | const entry = entries.find(item => item.includes(`<loc>https://docs.composio.dev${path}</loc>`)); |
| 65 | expect(entry, path).toBeDefined(); |
| 66 | expect(entry, path).not.toContain('<lastmod>'); |
| 67 | } |
| 68 | }); |
| 69 | |
| 70 | test('REST versions and product routes support filtering without guessing SDK versions', async () => { |
| 71 | for (const [path, product, version] of [ |
| 72 | ['/reference/authenticating-to-composio', 'platform', '3.1'], |
| 73 | ['/reference/v3/authentication', 'platform', '3.0'], |
| 74 | ['/docs/agent-plugins', 'for-you', null], |
| 75 | ] as const) { |
| 76 | const response = await fetchPage(`${path}.md`); |
| 77 | expect(response.status).toBe(200); |
| 78 | expect(parseMetadata(await response.text())).toMatchObject({ product, version }); |
| 79 | } |
| 80 | }); |
| 81 | |
| 82 | for (const path of ['/docs/devrel-36-missing-synthetic', '/unknown-devrel-36/page']) { |
| 83 | for (const negotiated of [false, true]) { |
| 84 | test(`${path} (${negotiated ? 'negotiated' : 'suffix'}) stays useful without false success`, async () => { |
| 85 | const response = await fetchPage(negotiated ? path : `${path}.md`, |
| 86 | negotiated ? { headers: { Accept: 'text/markdown' } } : undefined); |
| 87 | expect(response.status).toBe(404); |
| 88 | expect(response.headers.get('content-type')).toContain('text/markdown'); |
| 89 | const text = await response.text(); |
| 90 | expect(parseMetadata(text)).toMatchObject({ |
| 91 | canonical_url: `https://docs.composio.dev${path}`, |
| 92 | markdown_url: `https://docs.composio.dev${path}.md`, |
| 93 | last_updated: null, |
| 94 | }); |
| 95 | for (const link of ['/llms.txt', '/llms-index.txt', '/kb/search', '/docs/quickstart.md']) { |
| 96 | expect(text).toContain(`](${link})`); |
| 97 | } |
| 98 | expect(text).not.toContain('<!DOCTYPE html>'); |
| 99 | }); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | test('a missing dated changelog keeps Markdown and 404 on its direct route', async () => { |
| 104 | const response = await fetchPage('/llms.mdx/docs/changelog/1900/01/01'); |
| 105 | expect(response.status).toBe(404); |
| 106 | expect(response.headers.get('content-type')).toContain('text/markdown'); |
| 107 | expect(parseMetadata(await response.text())).toMatchObject({ |
| 108 | canonical_url: 'https://docs.composio.dev/docs/changelog/1900/01/01', |
| 109 | markdown_url: 'https://docs.composio.dev/docs/changelog/1900/01/01.md', |
| 110 | last_updated: null, |
| 111 | }); |
| 112 | }); |
| 113 | }); |