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 130 lines 4.34 KB
Raw
1 /**
2 * Dashboard link policy tests.
3 *
4 * Authored content must follow three rules for Composio dashboard links:
5 * 1. No app.composio.dev or platform.composio.dev hosts anywhere.
6 * 2. Every dashboard.composio.dev link carries utm_source, utm_medium, and
7 * utm_campaign so sign-ups can be attributed to docs.
8 * 3. Any dashboard.composio.dev link with a path must be a go-link
9 * (/~/project/... or /~/org/...) or /login, so it resolves to the right
10 * page inside the user's workspace.
11 *
12 * Code fences and inline mentions are exempt from rules 2-3; rule 1 applies
13 * to all file content. Scans .mdx and .md (toolkit FAQs) under docs,
14 * examples, changelog and toolkits. content/reference is generated upstream
15 * and excluded.
16 * TS/TSX is enforced by the no-restricted-syntax rules in .oxlintrc.json.
17 */
18 import { describe, test, expect } from "bun:test";
19 import { readdir, readFile } from "fs/promises";
20 import { join, relative } from "path";
21
22 const CONTENT_DIRS = ["docs", "examples", "changelog", "toolkits"].map((dir) =>
23 join(import.meta.dir, "../../content", dir),
24 );
25 const CONTENT_ROOT = join(import.meta.dir, "../../content");
26
27 const DASHBOARD_LINK_RE = /\]\((https:\/\/dashboard\.composio\.dev[^)\s]*)\)/g;
28 const BANNED_HOST_RE = /(?<![a-z0-9-])(?:app|platform)\.composio\.dev/;
29 const GO_LINK_PATH_RE = /^\/(?:~\/(?:project|org)(?:[/?#]|$)|login(?:[/?#]|$))/;
30 const REQUIRED_PARAMS = ["utm_source=", "utm_medium=", "utm_campaign="];
31
32 async function findMdxFiles(dir: string): Promise<string[]> {
33 const results: string[] = [];
34 let entries;
35 try {
36 entries = await readdir(dir, { withFileTypes: true });
37 } catch {
38 return results;
39 }
40
41 for (const entry of entries) {
42 const fullPath = join(dir, entry.name);
43 if (entry.isDirectory()) {
44 results.push(...(await findMdxFiles(fullPath)));
45 } else if (/\.mdx?$/.test(entry.name)) {
46 results.push(fullPath);
47 }
48 }
49 return results;
50 }
51
52 function dashboardLinks(content: string): { line: number; url: string }[] {
53 const links: { line: number; url: string }[] = [];
54 let inFence = false;
55 content.split("\n").forEach((line, index) => {
56 if (/^\s*(```|~~~)/.test(line)) {
57 inFence = !inFence;
58 return;
59 }
60 if (inFence) return;
61 for (const match of line.matchAll(DASHBOARD_LINK_RE)) {
62 links.push({ line: index + 1, url: match[1] });
63 }
64 });
65 return links;
66 }
67
68 async function collectViolations(
69 check: (content: string) => { line: number; url: string }[],
70 ): Promise<string[]> {
71 const violations: string[] = [];
72 for (const dir of CONTENT_DIRS) {
73 for (const file of await findMdxFiles(dir)) {
74 const content = await readFile(file, "utf-8");
75 for (const violation of check(content)) {
76 violations.push(
77 `${relative(CONTENT_ROOT, file)}:${violation.line} ${violation.url}`,
78 );
79 }
80 }
81 }
82 return violations;
83 }
84
85 describe("Content - dashboard link policy", () => {
86 test("no app/platform composio hosts anywhere", async () => {
87 const banned = await collectViolations((content) => {
88 const violations: { line: number; url: string }[] = [];
89 content.split("\n").forEach((line, index) => {
90 const match = line.match(BANNED_HOST_RE);
91 if (match) violations.push({ line: index + 1, url: match[0] });
92 });
93 return violations;
94 });
95
96 expect(
97 banned,
98 `banned hosts found (use dashboard go-links instead):\n${banned.join("\n")}`,
99 ).toEqual([]);
100 });
101
102 test("all dashboard links carry utm params", async () => {
103 const untagged = await collectViolations((content) =>
104 dashboardLinks(content).filter(
105 ({ url }) => !REQUIRED_PARAMS.every((param) => url.includes(param)),
106 ),
107 );
108
109 expect(
110 untagged,
111 `dashboard links missing utm_source=/utm_medium=/utm_campaign=:\n${untagged.join("\n")}`,
112 ).toEqual([]);
113 });
114
115 test("all dashboard links with a path are go-links or /login", async () => {
116 const invalid = await collectViolations((content) =>
117 dashboardLinks(content).filter(({ url }) => {
118 const path = url
119 .replace(/^https:\/\/dashboard\.composio\.dev/, "")
120 .split("?")[0];
121 return path !== "" && path !== "/" && !GO_LINK_PATH_RE.test(path);
122 }),
123 );
124
125 expect(
126 invalid,
127 `dashboard links must use /~/project/..., /~/org/..., or /login paths:\n${invalid.join("\n")}`,
128 ).toEqual([]);
129 });
130 });