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 125 lines 4.4 KB
Raw
1 /**
2 * LLM endpoint integration tests.
3 *
4 * Validates that .md endpoints return well-formed markdown with proper
5 * content-type headers and guardrails.
6 */
7 import { describe, test, expect } from "bun:test";
8 import { fetchPage } from "./helpers";
9
10 describe("LLM endpoints - llms.txt", () => {
11 test("/llms.txt returns 200 with text content", async () => {
12 const res = await fetchPage("/llms.txt");
13 expect(res.status).toBe(200);
14
15 const text = await res.text();
16 expect(text.length).toBeGreaterThan(100);
17 // Should contain page links
18 expect(text).toContain("composio");
19 });
20 });
21
22 /**
23 * Version labelling of the machine-readable indexes.
24 *
25 * `/reference/v3/` is the only version-shaped path in the corpus, so a search
26 * for "composio api v3" matches the superseded tree exactly. Both index files
27 * used to list the two trees interleaved under one unlabelled `## API
28 * Reference` heading with no v3.1 string anywhere.
29 */
30 describe("LLM endpoints - API reference version labelling", () => {
31 const CURRENT_HEADING = "## API Reference (v3.1, current)";
32 const LEGACY_HEADING_PREFIX = "## API Reference (v3.0, legacy";
33
34 test("/llms.txt labels the current reference group", async () => {
35 const text = await (await fetchPage("/llms.txt")).text();
36 expect(text).toContain(CURRENT_HEADING);
37 });
38
39 test("/llms.txt has no unlabelled API Reference heading", async () => {
40 const text = await (await fetchPage("/llms.txt")).text();
41 expect(text.split("\n")).not.toContain("## API Reference");
42 });
43
44 test("/llms-index.txt groups every legacy URL under the legacy heading, not interleaved", async () => {
45 const lines = (await (await fetchPage("/llms-index.txt")).text()).split("\n");
46
47 const legacyStart = lines.findIndex(line => line.startsWith(LEGACY_HEADING_PREFIX));
48 expect(legacyStart, "no legacy reference group").toBeGreaterThan(-1);
49
50 // The legacy group runs to the next ## heading.
51 let legacyEnd = lines.findIndex(
52 (line, i) => i > legacyStart && line.startsWith("## "),
53 );
54 if (legacyEnd === -1) legacyEnd = lines.length;
55
56 const strays = lines
57 .map((line, i) => ({ line, i }))
58 .filter(
59 ({ line, i }) =>
60 line.includes("/reference/v3/") && (i < legacyStart || i >= legacyEnd),
61 )
62 .map(({ line }) => line);
63
64 expect(strays, `legacy URLs outside the legacy group:\n${strays.join("\n")}`).toEqual([]);
65 });
66
67 test("/llms-full.txt carries no v3.0 page bodies", async () => {
68 const text = await (await fetchPage("/llms-full.txt")).text();
69 expect(text).not.toContain("/reference/v3/");
70 expect(text).toContain("# Tools (/reference/api-reference/tools)");
71 });
72 });
73
74 describe("LLM endpoints - .md pages", () => {
75 const MD_PAGES = [
76 { path: "/docs/quickstart.md", name: "Quickstart" },
77 { path: "/docs/authentication.md", name: "Authentication" },
78 { path: "/docs/how-composio-works.md", name: "How Composio works" },
79 ];
80
81 for (const { path, name } of MD_PAGES) {
82 test(`${name} (${path}) returns markdown`, async () => {
83 const res = await fetchPage(path);
84 expect(res.status).toBe(200);
85
86 const contentType = res.headers.get("content-type") || "";
87 expect(contentType).toContain("text/markdown");
88
89 // Metadata alone must not satisfy the documentation body checks.
90 const body = (await res.text())
91 .replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, "")
92 .trimStart();
93 expect(body).toMatch(/^#\s+.+/);
94 expect(body.length).toBeGreaterThan(200);
95 });
96 }
97 });
98
99 describe("LLM endpoints - guardrails", () => {
100 test("quickstart.md includes guardrail content", async () => {
101 const res = await fetchPage("/docs/quickstart.md");
102 const text = await res.text();
103 // Default guardrails should be appended (session-based pattern)
104 // The exact content varies but should include the footer
105 expect(text).toContain("More documentation");
106 });
107 });
108
109 describe("LLM endpoints - toolkit markdown", () => {
110 test("/toolkits.md returns toolkit index", async () => {
111 const res = await fetchPage("/toolkits.md");
112 expect(res.status).toBe(200);
113
114 const text = await res.text();
115 expect(text).toContain("Toolkits");
116 expect(text.toLowerCase()).toContain("github");
117 });
118 });
119
120 describe("LLM endpoints - error handling", () => {
121 test("non-existent .md page returns 404", async () => {
122 const res = await fetchPage("/docs/nonexistent-page-xyz.md");
123 expect(res.status).toBe(404);
124 });
125 });