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 | /** |
| 2 | * Content validation tests. |
| 3 | * |
| 4 | * Checks that all MDX pages have required frontmatter (title), are non-empty, |
| 5 | * and changelog entries use valid date formats. |
| 6 | */ |
| 7 | import { describe, test, expect } from "bun:test"; |
| 8 | import { compile } from "@mdx-js/mdx"; |
| 9 | import { readdir, readFile, stat } from "fs/promises"; |
| 10 | import { join, relative } from "path"; |
| 11 | |
| 12 | const CONTENT_DIR = join(import.meta.dir, "../../content"); |
| 13 | const DOCS_DIR = join(import.meta.dir, "../../content/docs"); |
| 14 | const EXAMPLES_DIR = join(import.meta.dir, "../../content/examples"); |
| 15 | const CHANGELOG_DIR = join(import.meta.dir, "../../content/changelog"); |
| 16 | const GOOGLE_PROVIDER_DOC = join(DOCS_DIR, "providers/google.mdx"); |
| 17 | |
| 18 | /** Recursively find all .mdx files */ |
| 19 | async function findMdxFiles(dir: string): Promise<string[]> { |
| 20 | const results: string[] = []; |
| 21 | let entries; |
| 22 | try { |
| 23 | entries = await readdir(dir, { withFileTypes: true }); |
| 24 | } catch { |
| 25 | return results; |
| 26 | } |
| 27 | |
| 28 | for (const entry of entries) { |
| 29 | const fullPath = join(dir, entry.name); |
| 30 | if (entry.isDirectory()) { |
| 31 | results.push(...(await findMdxFiles(fullPath))); |
| 32 | } else if (entry.name.endsWith(".mdx")) { |
| 33 | results.push(fullPath); |
| 34 | } |
| 35 | } |
| 36 | return results; |
| 37 | } |
| 38 | |
| 39 | /** Extract frontmatter from MDX content */ |
| 40 | function parseFrontmatter(content: string): Record<string, string> | null { |
| 41 | const match = content.match(/^---\n([\s\S]*?)\n---/); |
| 42 | if (!match) return null; |
| 43 | |
| 44 | const fm: Record<string, string> = {}; |
| 45 | for (const line of match[1].split("\n")) { |
| 46 | const colonIdx = line.indexOf(":"); |
| 47 | if (colonIdx > 0) { |
| 48 | const key = line.slice(0, colonIdx).trim(); |
| 49 | const value = line.slice(colonIdx + 1).trim(); |
| 50 | fm[key] = value; |
| 51 | } |
| 52 | } |
| 53 | return fm; |
| 54 | } |
| 55 | |
| 56 | describe("Content - frontmatter validation", () => { |
| 57 | test("all docs pages have a title", async () => { |
| 58 | const files = await findMdxFiles(DOCS_DIR); |
| 59 | const missingTitle: string[] = []; |
| 60 | |
| 61 | for (const file of files) { |
| 62 | const content = await readFile(file, "utf-8"); |
| 63 | const fm = parseFrontmatter(content); |
| 64 | if (!fm || !fm.title) { |
| 65 | missingTitle.push(relative(DOCS_DIR, file)); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | expect(missingTitle).toEqual([]); |
| 70 | }); |
| 71 | |
| 72 | test("all examples pages have a title", async () => { |
| 73 | const files = await findMdxFiles(EXAMPLES_DIR); |
| 74 | const missingTitle: string[] = []; |
| 75 | |
| 76 | for (const file of files) { |
| 77 | const content = await readFile(file, "utf-8"); |
| 78 | const fm = parseFrontmatter(content); |
| 79 | if (!fm || !fm.title) { |
| 80 | missingTitle.push(relative(EXAMPLES_DIR, file)); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | expect(missingTitle).toEqual([]); |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | describe("Content - no empty pages", () => { |
| 89 | test("docs pages have meaningful content (> 50 chars after frontmatter)", async () => { |
| 90 | const files = await findMdxFiles(DOCS_DIR); |
| 91 | const empty: string[] = []; |
| 92 | |
| 93 | for (const file of files) { |
| 94 | const content = await readFile(file, "utf-8"); |
| 95 | // Strip frontmatter |
| 96 | const body = content.replace(/^---[\s\S]*?---\n*/, "").trim(); |
| 97 | if (body.length < 50) { |
| 98 | empty.push(relative(DOCS_DIR, file)); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | expect(empty).toEqual([]); |
| 103 | }); |
| 104 | }); |
| 105 | |
| 106 | /** A node in the tree MDX renders: markdown elements and JSX elements. */ |
| 107 | type RenderedNode = { |
| 108 | type: string; |
| 109 | tagName?: string; |
| 110 | name?: string | null; |
| 111 | children?: RenderedNode[]; |
| 112 | position?: { start: { line: number } }; |
| 113 | }; |
| 114 | |
| 115 | function isParagraph(node: RenderedNode): boolean { |
| 116 | if (node.type === "element") return node.tagName === "p"; |
| 117 | return ( |
| 118 | (node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === "p" |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | describe("Content - valid HTML nesting", () => { |
| 123 | test("no page renders a <p> inside a <p>", async () => { |
| 124 | // MDX wraps the lines inside a block-level <p> in a markdown paragraph, |
| 125 | // rendering <p><p>…</p></p>. Browsers split that apart, so React hydration |
| 126 | // fails and the page re-renders on the client. Checking the compiled tree |
| 127 | // skips code examples and catches tags that span several lines. |
| 128 | const files = await findMdxFiles(CONTENT_DIR); |
| 129 | const nested: string[] = []; |
| 130 | |
| 131 | for (const file of files) { |
| 132 | // Blank out frontmatter so reported line numbers match the file. |
| 133 | const source = (await readFile(file, "utf-8")).replace(/^---\n[\s\S]*?\n---\n/, fm => |
| 134 | fm.replace(/[^\n]/g, ""), |
| 135 | ); |
| 136 | const visit = (node: RenderedNode, insideParagraph: boolean) => { |
| 137 | if (insideParagraph && isParagraph(node)) { |
| 138 | nested.push(`${relative(CONTENT_DIR, file)}:${node.position?.start.line}`); |
| 139 | } |
| 140 | for (const child of node.children ?? []) { |
| 141 | visit(child, insideParagraph || isParagraph(node)); |
| 142 | } |
| 143 | }; |
| 144 | await compile(source, { rehypePlugins: [() => (tree: RenderedNode) => visit(tree, false)] }); |
| 145 | } |
| 146 | |
| 147 | expect(nested).toEqual([]); |
| 148 | }, 30_000); |
| 149 | }); |
| 150 | |
| 151 | describe("Content - provider compatibility", () => { |
| 152 | test("Gemini Python docs use the google-genai-compatible provider", async () => { |
| 153 | const content = await readFile(GOOGLE_PROVIDER_DOC, "utf-8"); |
| 154 | |
| 155 | expect(content).toContain( |
| 156 | '<PackageInstall ecosystem="python" packages="composio composio_gemini google-genai" />', |
| 157 | ); |
| 158 | expect(content).toContain("from composio_gemini import GeminiProvider"); |
| 159 | expect(content).toContain("Composio(provider=GeminiProvider())"); |
| 160 | expect(content).not.toContain("composio_google google-genai"); |
| 161 | }); |
| 162 | }); |
| 163 | |
| 164 | describe("Content - Context7 ingest rules", () => { |
| 165 | test("context7.json states the current REST version without claiming route parity", async () => { |
| 166 | // Context7 ingests this repo for coding agents. Without a rule, nothing in |
| 167 | // the ingested corpus says which REST version is current. |
| 168 | const raw = await readFile(join(import.meta.dir, "../../../context7.json"), "utf-8"); |
| 169 | const rules: unknown = JSON.parse(raw).rules; |
| 170 | |
| 171 | expect(Array.isArray(rules)).toBe(true); |
| 172 | expect((rules as unknown[]).length).toBeGreaterThan(0); |
| 173 | expect( |
| 174 | (rules as string[]).some(rule => rule.includes("https://backend.composio.dev/api/v3.1")), |
| 175 | ).toBe(true); |
| 176 | expect( |
| 177 | (rules as string[]).some(rule => |
| 178 | rule.includes("Only those five endpoints change version defaults."), |
| 179 | ), |
| 180 | ).toBe(true); |
| 181 | expect((rules as string[]).join("\n")).not.toMatch(/every non-tool endpoint.*unchanged/i); |
| 182 | }); |
| 183 | }); |
| 184 | |
| 185 | describe("Content - changelog validation", () => { |
| 186 | test("changelog files use MM-DD-YY naming pattern", async () => { |
| 187 | let entries; |
| 188 | try { |
| 189 | entries = await readdir(CHANGELOG_DIR); |
| 190 | } catch { |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | // Files are named MM-DD-YY.mdx or MM-DD-YY-description.mdx |
| 195 | const nameRegex = /^\d{2}-\d{2}-\d{2}(-[\w-]+)?\.mdx$/; |
| 196 | const invalid: string[] = []; |
| 197 | |
| 198 | for (const entry of entries) { |
| 199 | if (entry === "meta.json" || entry === ".DS_Store") continue; |
| 200 | if (!nameRegex.test(entry)) { |
| 201 | invalid.push(entry); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | expect(invalid).toEqual([]); |
| 206 | }); |
| 207 | |
| 208 | test("changelog entries have a title and valid YYYY-MM-DD date in frontmatter", async () => { |
| 209 | let entries; |
| 210 | try { |
| 211 | entries = await readdir(CHANGELOG_DIR); |
| 212 | } catch { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | const dateRegex = /^\d{4}-\d{2}-\d{2}$/; |
| 217 | const errors: string[] = []; |
| 218 | |
| 219 | for (const entry of entries) { |
| 220 | if (!entry.endsWith(".mdx")) continue; |
| 221 | const content = await readFile(join(CHANGELOG_DIR, entry), "utf-8"); |
| 222 | const fm = parseFrontmatter(content); |
| 223 | |
| 224 | if (!fm || !fm.title) { |
| 225 | errors.push(`${entry}: missing title`); |
| 226 | } |
| 227 | |
| 228 | const dateValue = fm?.date?.replace(/["']/g, ""); |
| 229 | if (!dateValue || !dateRegex.test(dateValue)) { |
| 230 | errors.push(`${entry}: missing or invalid date (expected YYYY-MM-DD)`); |
| 231 | } else { |
| 232 | const parsed = new Date(`${dateValue}T12:00:00`); |
| 233 | if (isNaN(parsed.getTime())) { |
| 234 | errors.push(`${entry}: date "${dateValue}" is not a valid calendar date`); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | expect(errors).toEqual([]); |
| 240 | }); |
| 241 | }); |