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, 11:00 UTC
test(docs): check rendered MDX for nested paragraphs
The line-based check flagged a standalone <p> inside fenced code examples and missed <p> tags whose attributes span several lines. Compile each page with @mdx-js/mdx and fail when the rendered tree has a <p> inside a <p>. This also catches a <p> placed in running text and covers every page under content/.
tarunvashishth committed
Sep 30, 2026 at 09:34 UTC
91aa113ca66d5a7e60242b8f852de163deacc095
3 files changed
+38
-10
docs/bun.lock
+1
@@ -67,6 +67,7 @@
67
"@llamaindex/workflow": "^1.1.25",
68
"@mastra/core": "1.53.0",
69
"@mastra/mcp": "1.17.2",
70
+ "@mdx-js/mdx": "^3.1.1",
71
"@openai/agents": "^0.13.5",
72
"@shikijs/vitepress-twoslash": "^4.4.3",
73
"@tailwindcss/postcss": "^4.3.3",
docs/package.json
+1
@@ -99,6 +99,7 @@
99
"@llamaindex/workflow": "^1.1.25",
100
"@mastra/core": "1.53.0",
101
"@mastra/mcp": "1.17.2",
102
+ "@mdx-js/mdx": "^3.1.1",
103
"@openai/agents": "^0.13.5",
104
"@shikijs/vitepress-twoslash": "^4.4.3",
105
"@tailwindcss/postcss": "^4.3.3",
docs/tests/static/content.test.ts
+36
-10
@@ -5,9 +5,11 @@
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");
@@ -101,25 +103,49 @@ describe("Content - no empty pages", () => {
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", () => {
105
- test("no <p> tag sits alone on a line", async () => {
106
- // MDX parses the lines inside a block-level <p> as a markdown paragraph,
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
108
- // fails and the page re-renders on the client. Use a <div> wrapper instead.
109
- const files = [...(await findMdxFiles(DOCS_DIR)), ...(await findMdxFiles(EXAMPLES_DIR))];
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) {
113
- const lines = (await readFile(file, "utf-8")).split("\n");
114
- lines.forEach((line, i) => {
115
- if (/^\s*<p(\s[^>]*)?>\s*$/.test(line)) {
116
- nested.push(`${relative(join(DOCS_DIR, ".."), file)}:${i + 1}`);
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
}
118
- });
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([]);
122
- });
148
+ }, 30_000);
149
});
150
151
describe("Content - provider compatibility", () => {