@devries-cameron20 / composio-1 / commits / 92d078e94
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(docs): accept links to files served from public/

The link validator only knew page routes, so the downloadable migration helper at /assets/migrations/... failed lint:links. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Shashwat [zen] committed Oct 28, 2026 at 17:25 UTC 92d078e944935e828398862e2982e3b796d39ee2
2 files changed +33 -2
docs/scripts/validate-links.ts
+22 -2
@@ -1,6 +1,7 @@
1 +import { statSync } from 'node:fs';
2 import { readFile } from 'node:fs/promises';
3 import { glob } from 'node:fs/promises';
3 -import { resolve } from 'node:path';
4 +import { relative, resolve } from 'node:path';
5 import { type FileObject, printErrors, scanURLs, validateFiles } from 'next-validate-link';
6 import GithubSlugger from 'github-slugger';
7 import { z } from 'zod';
@@ -30,6 +31,25 @@ type AnySource =
31
32 type PageOf = ReturnType<AnySource['getPages']>[number];
33
34 +/**
35 + * Static files in `public/` (such as downloadable `/assets/...` helpers) are
36 + * served at the site root but aren't pages, so `scanURLs` doesn't know them.
37 + */
38 +export function isPublicFileUrl(url: string, publicDir = 'public'): boolean {
39 + if (!url.startsWith('/') || url.startsWith('//')) return false;
40 + let pathname: string;
41 + try {
42 + pathname = decodeURI(url.split(/[?#]/, 1)[0]);
43 + } catch {
44 + return false;
45 + }
46 + const root = resolve(publicDir);
47 + const target = resolve(root, '.' + pathname);
48 + const inside = relative(root, target);
49 + if (!inside || inside.startsWith('..')) return false;
50 + return statSync(target, { throwIfNoEntry: false })?.isFile() ?? false;
51 +}
52 +
53 export function withoutFrontmatter(content: string): string {
54 return content.replace(/^(?:\uFEFF)?---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
55 }
@@ -249,7 +269,7 @@ async function checkLinks() {
269 const filteredErrors = errors
270 .map(fileError => ({
271 ...fileError,
252 - errors: fileError.errors.filter(e => !ignoredUrls.includes(e.url)),
272 + errors: fileError.errors.filter(e => !ignoredUrls.includes(e.url) && !isPublicFileUrl(e.url)),
273 detected: fileError.detected.filter(d => !ignoredUrls.includes(d[0] as string)),
274 }))
275 .filter(fileError => fileError.errors.length > 0);
docs/tests/static/validate-links.test.ts
+11
@@ -13,6 +13,17 @@ describe('link validation', () => {
13 expect(withoutFrontmatter!(fixture)).toBe('Read [the guide](/kb/guide/example).\r\n');
14 });
15
16 + test('accepts links to files served from public/ and rejects missing or escaping paths', () => {
17 + expect(linkValidation.isPublicFileUrl('/assets/migrations/migrate_no_auth_to_instant.py')).toBe(true);
18 + expect(linkValidation.isPublicFileUrl('/assets/migrations/migrate_no_auth_to_instant.py#usage')).toBe(true);
19 + expect(linkValidation.isPublicFileUrl('/assets/migrations/missing.py')).toBe(false);
20 + expect(linkValidation.isPublicFileUrl('/assets/migrations')).toBe(false);
21 + expect(linkValidation.isPublicFileUrl('/../package.json')).toBe(false);
22 + expect(linkValidation.isPublicFileUrl('/%2e%2e/package.json')).toBe(false);
23 + expect(linkValidation.isPublicFileUrl('//example.com/robots.txt')).toBe(false);
24 + expect(linkValidation.isPublicFileUrl('/%E0%A4%A.py')).toBe(false);
25 + });
26 +
27 test('accepts redirecting toolkit knowledge routes as resolvable links', async () => {
28 const redirectingToolkit = (await getKnowledgeToolkitSummaries()).find(
29 toolkit => toolkit.knowledgeCount === 1,