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 210 lines 10.1 KB
Raw
1 /**
2 * Redirect integration tests.
3 *
4 * Validates that key redirect patterns work correctly — old URLs redirect
5 * to valid destinations that return 200.
6 */
7 import { describe, test, expect } from "bun:test";
8 import { fetchPage, fetchNoRedirect, BASE_URL } from "./helpers";
9
10 /** Exact failed requests from DEVREL-304, including machine-readable routes. */
11 const EVIDENCED_REDIRECTS = [
12 { from: "/docs/auth-and-connected-accounts", to: "/docs/authentication", markdown: false },
13 { from: "/docs/getting-started", to: "/docs/quickstart", markdown: false },
14 { from: "/authentication/authentication-overview", to: "/docs/authentication", markdown: false },
15 { from: "/authentication/connected-accounts/overview", to: "/docs/authentication/manually-authenticating", markdown: false },
16 { from: "/llms.mdx/authentication/connected-accounts/overview", to: "/docs/authentication/manually-authenticating.md", markdown: true },
17 { from: "/llms.mdx/sessions/sessions-via-mcp", to: "/docs/sessions-via-mcp.md", markdown: true },
18 { from: "/docs/manually-authenticating.md", to: "/docs/authentication/manually-authenticating.md", markdown: true },
19 ];
20
21 /** Sample of important redirects to test (from next.config.mjs) */
22 const REDIRECTS = [
23 ...EVIDENCED_REDIRECTS,
24 { from: "/", to: "/docs" },
25 { from: "/cookbooks", to: "/examples" },
26 { from: "/api-reference", to: "/reference" },
27 { from: "/providers/openai", to: "/docs/providers/openai" },
28 { from: "/providers/anthropic", to: "/docs/providers/anthropic" },
29 { from: "/providers/openai-agents", to: "/docs/providers/openai" },
30 { from: "/docs/providers/openai-agents", to: "/docs/providers/openai" },
31 { from: "/docs/providers/claude-agent-sdk", to: "/docs/providers/anthropic" },
32 { from: "/providers/google-adk", to: "/docs/providers/google" },
33 { from: "/docs/providers/google-adk", to: "/docs/providers/google" },
34 { from: "/providers/langgraph", to: "/docs/providers/langchain" },
35 { from: "/docs/providers/langgraph", to: "/docs/providers/langchain" },
36 { from: "/tools", to: "/toolkits" },
37 { from: "/docs/fetching-tools", to: "/docs/tools-direct/fetching-tools" },
38 { from: "/docs/custom-tools", to: "/docs/extending-sessions/local-tools-and-toolkits" },
39 { from: "/docs/tools-direct/custom-tools", to: "/docs/extending-sessions/local-tools-and-toolkits" },
40 { from: "/docs/tools-direct/custom-tools/github", to: "/docs/extending-sessions/local-tools-and-toolkits" },
41 { from: "/custom-tools/github", to: "/docs/extending-sessions/local-tools-and-toolkits" },
42 { from: "/docs/how-tools-work", to: "/docs/how-composio-works" },
43 { from: "/authentication", to: "/docs/authentication" },
44 { from: "/changelog", to: "/docs/changelog" },
45 { from: "/docs/mcp-quickstart", to: "/docs/single-toolkit-mcp" },
46 { from: "/docs/tool-tags", to: "/docs/governance/tool-hints" },
47 { from: "/docs/tool-tags.md", to: "/docs/governance/tool-hints.md" },
48 { from: "/docs/approvals", to: "/docs/governance/approvals" },
49 { from: "/docs/approvals.md", to: "/docs/governance/approvals.md" },
50 { from: "/docs/welcome", to: "/docs" },
51 { from: "/docs/managed-authentication", to: "/docs/authentication" },
52 { from: "/docs/workbench", to: "/docs/sandbox/remote" },
53 { from: "/docs/sandbox", to: "/docs/sandbox/remote" },
54 { from: "/docs/custom-tools-and-toolkits", to: "/docs/extending-sessions/local-tools-and-toolkits" },
55 { from: "/docs/extending-sessions/custom-tools-and-toolkits", to: "/docs/extending-sessions/local-tools-and-toolkits" },
56 { from: "/docs/proxy-execute", to: "/docs/extending-sessions/proxy-execute" },
57 { from: "/docs/white-labeling-authentication", to: "/docs/authentication/white-labeling-authentication" },
58 { from: "/docs/shared-connections", to: "/docs/extending-sessions/shared-connections" },
59 { from: "/docs/manually-authenticating", to: "/docs/authentication/manually-authenticating" },
60 { from: "/docs/security", to: "/docs/security/overview" },
61 { from: "/docs/self-hosting", to: "/docs/security/token-custody#deployment-options" },
62 { from: "/docs/auth", to: "/docs/authentication" },
63 { from: "/docs/auth-management/overview", to: "/docs/authentication" },
64 { from: "/docs/managed-auth", to: "/docs/authentication/custom-app-vs-managed-app" },
65 { from: "/docs/authentication/overview", to: "/docs/authentication" },
66 // URL guesses from DEVREL-330 (Gauge agent sessions hit every 404 below).
67 { from: "/docs/mastra", to: "/docs/providers/mastra" },
68 { from: "/docs/vercel-ai-sdk", to: "/docs/providers/vercel" },
69 { from: "/docs/integrations/vercel-ai-sdk", to: "/docs/providers/vercel" },
70 { from: "/docs/langchain", to: "/docs/providers/langchain" },
71 { from: "/docs/langgraph", to: "/docs/providers/langchain" },
72 { from: "/docs/providers/vercel-ai-sdk", to: "/docs/providers/vercel" },
73 { from: "/providers/vercel-ai-sdk", to: "/docs/providers/vercel" },
74 { from: "/docs/connect-links", to: "/docs/authentication" },
75 { from: "/docs/mcp-auth", to: "/docs/authentication/managed-auth-for-custom-tools" },
76 { from: "/docs/auth-tools/auth-on-mcp", to: "/docs/authentication/managed-auth-for-custom-tools" },
77 { from: "/providers/mcp", to: "/docs/single-toolkit-mcp" },
78 { from: "/docs/providers/mcp", to: "/docs/single-toolkit-mcp" },
79 { from: "/auth/token-custody", to: "/docs/security/token-custody" },
80 { from: "/auth/proxy-execute", to: "/docs/extending-sessions/proxy-execute" },
81 ];
82
83 describe('Vendor security review - retired KB routes', () => {
84 const retiredPaths = [
85 '/kb/guide/platform-compliance-data-handling',
86 '/kb/security-and-trust/platform-compliance-data-handling',
87 '/kb/sdk-and-api/platform-compliance-data-handling',
88 '/kb/guide/canonical-public-sources',
89 '/kb/guide/model-training',
90 '/kb/guide/third-party-providers',
91 '/kb/guide/zero-data-retention-and-no-training-requirements',
92 ];
93 for (const path of retiredPaths) {
94 for (const from of [path, `${path}.md`, `${path}.mdx`, `/llms.mdx${path}`]) {
95 test(`${from} permanently redirects into docs`, async () => {
96 const markdown = from !== path;
97 const to = `/docs/security/vendor-security-review${markdown ? '.md' : ''}`;
98 const redirect = await fetchNoRedirect(from);
99 expect(redirect.status).toBe(308);
100 expect(new URL(redirect.headers.get('location')!, BASE_URL).pathname).toBe(to);
101 const response = await fetchPage(from);
102 expect(response.status).toBe(200);
103 expect(new URL(response.url).pathname).toBe(to);
104 expect(response.headers.get('content-type')).toContain(markdown ? 'text/markdown' : 'text/html');
105 expect(await response.text()).toContain('Zero data retention and no-training requirements');
106 });
107 }
108 }
109 });
110
111 describe("Redirects - key patterns", () => {
112 for (const { from, to } of REDIRECTS) {
113 test(`${from} → ${to}`, async () => {
114 const res = await fetchNoRedirect(from);
115 // Should be a 301 or 308 redirect
116 expect([301, 302, 307, 308]).toContain(res.status);
117
118 const location = res.headers.get("location") || "";
119 // Location might be absolute or relative
120 const normalizedLocation = location
121 .replace(BASE_URL, "")
122 .split("?")[0]; // Strip query params
123 expect(normalizedLocation).toBe(to);
124 });
125 }
126 });
127
128 describe("Redirects - destinations are valid", () => {
129 test("all redirect destinations return 200", async () => {
130 const destinations = [...new Set(REDIRECTS.map((r) => r.to))];
131 const failures: string[] = [];
132
133 for (const dest of destinations) {
134 const res = await fetchPage(dest);
135 if (res.status !== 200) {
136 failures.push(`${dest} returned ${res.status}`);
137 }
138 }
139
140 expect(failures).toEqual([]);
141 });
142 });
143
144 describe("Evidenced legacy routes - response representations", () => {
145 for (const { from, to, markdown } of EVIDENCED_REDIRECTS) {
146 test(`${from} serves the canonical ${markdown ? "Markdown" : "HTML"} topic`, async () => {
147 const response = await fetchPage(from, {
148 headers: { Accept: "text/html", "User-Agent": "facebookexternalhit/1.1" },
149 timeout: 30_000,
150 });
151 expect(response.status).toBe(200);
152 expect(new URL(response.url).pathname).toBe(to);
153 expect(response.headers.get("content-type")).toContain(markdown ? "text/markdown" : "text/html");
154 const body = await response.text();
155 const canonical = `https://docs.composio.dev${to.replace(/\.md$/, "")}`;
156 if (markdown) {
157 expect(body).toContain(`canonical_url: "${canonical}"`);
158 expect(body).toMatch(/^# .+/m);
159 expect(body).not.toMatch(/<!doctype html/i);
160 } else {
161 expect(body).toContain(`<link rel="canonical" href="${canonical}"`);
162 expect(body).toContain("<h1");
163 }
164 });
165
166 if (!markdown) {
167 for (const accept of ["text/markdown", "text/plain"]) {
168 test(`${from} preserves ${accept} negotiation`, async () => {
169 const response = await fetchPage(from, { headers: { Accept: accept }, timeout: 30_000 });
170 expect(response.status).toBe(200);
171 expect(response.headers.get("content-type")).toContain("text/markdown");
172 expect(await response.text()).toContain(`canonical_url: "https://docs.composio.dev${to}"`);
173 });
174 }
175 }
176 }
177
178 test("unknown documentation routes remain 404s", async () => {
179 for (const path of [
180 "/authentication/not-a-real-guide",
181 "/llms.mdx/authentication/not-a-real-guide",
182 "/docs/not-a-real-guide.md",
183 ]) {
184 const response = await fetchPage(path, { timeout: 30_000 });
185 expect(response.status).toBe(404);
186 expect(new URL(response.url).pathname).toBe(path);
187 }
188 });
189 });
190
191 describe("Redirects - saved tool tag section links", () => {
192 test("legacy anchors survive the redirect alongside the renamed headings", async () => {
193 const res = await fetchPage("/docs/tool-tags", { timeout: 30_000 });
194 const html = await res.text();
195
196 expect(res.status).toBe(200);
197 expect(new URL(res.url).pathname).toBe("/docs/governance/tool-hints");
198
199 for (const id of [
200 "tags",
201 "how-tools-are-tagged",
202 "using-tags-in-a-session",
203 "hints",
204 "how-tools-get-hints",
205 "using-hints-in-a-session",
206 ]) {
207 expect(html).toContain(`id="${id}"`);
208 }
209 });
210 });