@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
ts 257 lines 9.79 KB
Raw
1 /**
2 * Page rendering integration tests.
3 *
4 * Validates that critical pages render successfully (200), return HTML,
5 * and contain expected content markers.
6 */
7 import { describe, test, expect } from "bun:test";
8 import {
9 getKnowledgeByToolkit,
10 getKnowledgeToolkitSummaries,
11 } from "@/lib/knowledge/catalog";
12 import { fetchNoRedirect, fetchPage } from "./helpers";
13
14 /** Critical pages that must always render */
15 const CRITICAL_PAGES = [
16 { path: "/docs", name: "Docs home" },
17 { path: "/docs/quickstart", name: "Quickstart" },
18 { path: "/docs/authentication", name: "Authentication" },
19 { path: "/docs/how-composio-works", name: "How Composio works" },
20 { path: "/docs/users-and-sessions", name: "Users & Sessions" },
21 { path: "/examples", name: "Examples index" },
22 { path: "/toolkits", name: "Toolkits index" },
23 { path: "/reference", name: "Reference index" },
24 ];
25
26 const DEPRECATED_API_LEGACY_TITLE =
27 "Deprecated API endpoint; kept for existing integrations and may be removed in a future release";
28
29 const DEPRECATED_API_PAGES = [
30 "/reference/api-reference/connected-accounts/postConnectedAccountsByNanoidRefresh",
31 "/reference/api-reference/files/getFilesList",
32 "/reference/v3/api-reference/connected-accounts/postConnectedAccountsByNanoidRefresh",
33 "/reference/v3/api-reference/files/getFilesList",
34 ];
35
36 const ACTIVE_API_PAGES = [
37 "/reference/api-reference/files/postFilesUploadRequest",
38 "/reference/v3/api-reference/files/postFilesUploadRequest",
39 ];
40
41 function getPageHeading(html: string): string | undefined {
42 return html.match(/<h1[^>]*>[\s\S]*?<\/h1>/)?.[0];
43 }
44
45 describe("Page rendering - critical pages", () => {
46 for (const { path, name } of CRITICAL_PAGES) {
47 test(`${name} (${path}) returns 200`, async () => {
48 const res = await fetchPage(path);
49 expect(res.status).toBe(200);
50 });
51
52 test(`${name} (${path}) returns HTML`, async () => {
53 const res = await fetchPage(path);
54 const contentType = res.headers.get("content-type") || "";
55 expect(contentType).toContain("text/html");
56 });
57 }
58 });
59
60 describe("Page rendering - content markers", () => {
61 test("docs homepage social metadata survives the root redirect", async () => {
62 const res = await fetchPage("/", { timeout: 30_000, headers: { "User-Agent": "facebookexternalhit/1.1" } });
63 const html = await res.text();
64 expect(res.status).toBe(200);
65 expect(new URL(res.url).pathname).toBe('/docs');
66 expect(html).toContain('<title>Build and operate AI agents | Composio Documentation</title>');
67 expect(html).toContain('<meta property="og:site_name" content="Composio Docs"');
68 expect(html).toContain('<meta property="og:title" content="Build and operate AI agents"');
69 expect(html).toContain('<meta property="og:image" content="https://docs.composio.dev/api/og?section=home&amp;description=');
70 expect(html).toContain('<meta name="twitter:image" content="https://docs.composio.dev/api/og?section=home&amp;description=');
71 const description = html.match(/<meta property="og:description" content="([^"]+)"/)?.[1];
72 expect(description).toBe('Give your agents tools, managed authentication, and secure execution. Get started with the SDK, CLI, or MCP.');
73 expect(description!.length).toBeLessThanOrEqual(125);
74 });
75
76 test("docs home contains navigation elements", async () => {
77 const res = await fetchPage("/docs");
78 const html = await res.text();
79 // Should have some sidebar/nav content
80 expect(html).toContain("Quickstart");
81 });
82
83 test("quickstart page contains expected content", async () => {
84 const res = await fetchPage("/docs/quickstart");
85 const html = await res.text();
86 expect(html.toLowerCase()).toContain("composio");
87 });
88
89 test("toolkits page renders toolkit cards", async () => {
90 const res = await fetchPage("/toolkits");
91 const html = await res.text();
92 // Should contain at least one well-known toolkit
93 expect(html.toLowerCase()).toContain("github");
94 });
95
96 test("knowledge topic pages link back to the Knowledge Base home", async () => {
97 const res = await fetchPage("/kb/topic/authentication-and-connected-accounts");
98 const html = await res.text();
99 const topicNavigation = html.match(
100 /<nav[^>]*aria-label="Knowledge Base topic navigation"[^>]*>[\s\S]*?<\/nav>/,
101 )?.[0];
102
103 expect(res.status).toBe(200);
104 expect(topicNavigation).toContain('href="/kb"');
105 expect(topicNavigation).toContain('Knowledge Base');
106 });
107
108 test("toolkit knowledge pages omit duplicate search and page-count controls", async () => {
109 const toolkit = (await getKnowledgeToolkitSummaries()).find(
110 (candidate) => candidate.knowledgeCount > 1,
111 );
112 expect(toolkit).toBeDefined();
113
114 const res = await fetchPage(`/kb/toolkit/${toolkit!.slug}`);
115 const html = await res.text();
116
117 expect(res.status).toBe(200);
118 expect(html).not.toContain('name="knowledge-browse-search"');
119 expect(html).not.toMatch(
120 /\d+(?:<!-- -->)? public page(?:<!-- -->)?s?(?:<!-- -->)? across Composio sources\./,
121 );
122 });
123
124 test("routes toolkit knowledge pages based on their resource count", async () => {
125 const summaries = await getKnowledgeToolkitSummaries();
126 const singleResourceToolkit = summaries.find(
127 (toolkit) => toolkit.knowledgeCount === 1,
128 );
129 const multiResourceToolkit = summaries.find(
130 (toolkit) => toolkit.knowledgeCount > 1,
131 );
132
133 expect(singleResourceToolkit).toBeDefined();
134 expect(multiResourceToolkit).toBeDefined();
135
136 const redirectResponse = await fetchNoRedirect(
137 `/kb/toolkit/${singleResourceToolkit!.slug}`,
138 );
139 expect(redirectResponse.status).toBe(307);
140 const redirectLocation = redirectResponse.headers.get("location");
141 expect(redirectLocation).toBeTruthy();
142 expect(
143 new URL(redirectLocation!, "http://localhost").pathname,
144 ).toBe(`/toolkits/${singleResourceToolkit!.slug}`);
145
146 const knowledgeResponse = await fetchNoRedirect(
147 `/kb/toolkit/${multiResourceToolkit!.slug}`,
148 );
149 expect(knowledgeResponse.status).toBe(200);
150 });
151
152 test("keeps agent-readable toolkit routes aligned with HTML routes", async () => {
153 const summaries = await getKnowledgeToolkitSummaries();
154 const singleResourceToolkit = summaries.find(
155 (toolkit) => toolkit.knowledgeCount === 1,
156 );
157 const multiResourceToolkit = summaries.find(
158 (toolkit) => toolkit.knowledgeCount > 1,
159 );
160
161 expect(singleResourceToolkit).toBeDefined();
162 expect(multiResourceToolkit).toBeDefined();
163
164 const redirectResponse = await fetchNoRedirect(
165 `/kb/toolkit/${singleResourceToolkit!.slug}.md`,
166 );
167 expect(redirectResponse.status).toBe(307);
168 const redirectLocation = redirectResponse.headers.get("location");
169 expect(redirectLocation).toBe(`/toolkits/${singleResourceToolkit!.slug}.md`);
170
171 const knowledgeResponse = await fetchNoRedirect(
172 `/kb/toolkit/${multiResourceToolkit!.slug}.md`,
173 );
174 expect(knowledgeResponse.status).toBe(200);
175 });
176
177 test("toolkit knowledge pages open only external cards in a new tab", async () => {
178 const summaries = await getKnowledgeToolkitSummaries();
179 const toolkit = summaries.find((candidate) => candidate.knowledgeCount > 1);
180 expect(toolkit).toBeDefined();
181 const toolkitLinks = await getKnowledgeByToolkit(toolkit!.slug);
182 const res = await fetchPage(`/kb/toolkit/${toolkit!.slug}`);
183 const html = await res.text();
184 const collection = html.match(
185 /<ul[^>]*aria-label="Toolkit knowledge sources"[^>]*>[\s\S]*?<\/ul>/,
186 )?.[0];
187 const externalLinkCount = toolkitLinks.filter((link) =>
188 /^https?:\/\//.test(link.href),
189 ).length;
190 const internalLink = toolkitLinks.find((link) => !/^https?:\/\//.test(link.href));
191
192 expect(res.status).toBe(200);
193 expect(collection).toBeDefined();
194 expect((collection?.match(/target="_blank"/g) ?? []).length).toBe(
195 externalLinkCount,
196 );
197 expect(collection).toContain(`href="${internalLink!.href}"`);
198 });
199
200 test("guide pages omit the redundant Knowledge Base home link", async () => {
201 const res = await fetchPage("/kb/guide/toolkits-airtable");
202 const html = await res.text();
203
204 expect(res.status).toBe(200);
205 expect(html).not.toContain("Knowledge Base home");
206 expect(html).toContain("Support topics");
207 });
208 });
209
210 describe("Page rendering - deprecated API endpoints", () => {
211 for (const path of DEPRECATED_API_PAGES) {
212 test(`${path} renders the Legacy badge`, async () => {
213 const res = await fetchPage(path);
214 const html = await res.text();
215 const heading = getPageHeading(html);
216
217 expect(res.status).toBe(200);
218 expect(heading).toBeDefined();
219 expect(heading).toContain(DEPRECATED_API_LEGACY_TITLE);
220 });
221 }
222
223 for (const path of ACTIVE_API_PAGES) {
224 test(`${path} omits the Legacy badge`, async () => {
225 const res = await fetchPage(path);
226 const html = await res.text();
227 const heading = getPageHeading(html);
228
229 expect(res.status).toBe(200);
230 expect(heading).toBeDefined();
231 expect(heading).not.toContain(DEPRECATED_API_LEGACY_TITLE);
232 });
233 }
234
235 test("deprecated endpoint sidebar links replace the title marker with Legacy", async () => {
236 const path = DEPRECATED_API_PAGES[0];
237 const res = await fetchPage(path);
238 const html = await res.text();
239 const escapedPath = path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
240 const sidebarLink = html.match(
241 new RegExp(`<a[^>]*href="${escapedPath}"[^>]*>[\\s\\S]*?<\\/a>`),
242 )?.[0];
243
244 expect(res.status).toBe(200);
245 expect(sidebarLink).toBeDefined();
246 expect(sidebarLink).toContain(">Legacy</span>");
247 expect(sidebarLink).not.toContain("(DEPRECATED)");
248 expect(sidebarLink).toContain(">POST</span>");
249 });
250 });
251
252 describe("Page rendering - error handling", () => {
253 test("non-existent page returns 404", async () => {
254 const res = await fetchPage("/docs/this-page-does-not-exist-ever");
255 expect(res.status).toBe(404);
256 });
257 });