Skip to content

Commit 61ee4e3

Browse files
authored
Add tests for markdown serving based on user agents (#4227)
1 parent 927aa89 commit 61ee4e3

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

packages/gitbook/tests/markdown.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
import { describe, expect, it } from 'bun:test';
22
import { getContentTestURL } from './utils';
33

4+
const TEST_PAGE_URL = 'https://gitbook.gitbook.io/test-gitbook-open/text-page';
5+
6+
describe('markdown serving based on user agent', () => {
7+
it('should serve markdown to GPTBot (ua-match AI agent)', async () => {
8+
const response = await fetch(getContentTestURL(TEST_PAGE_URL), {
9+
headers: {
10+
'User-Agent': 'GPTBot/1.2',
11+
},
12+
});
13+
14+
expect(response.status).toBe(200);
15+
expect(response.headers.get('content-type')).toContain('text/markdown');
16+
});
17+
18+
it('should serve markdown to ClaudeBot (ua-match AI agent)', async () => {
19+
const response = await fetch(getContentTestURL(TEST_PAGE_URL), {
20+
headers: {
21+
'User-Agent': 'ClaudeBot/1.0',
22+
},
23+
});
24+
25+
expect(response.status).toBe(200);
26+
expect(response.headers.get('content-type')).toContain('text/markdown');
27+
});
28+
29+
it('should NOT serve markdown to Slackbot (heuristic detection only)', async () => {
30+
const response = await fetch(getContentTestURL(TEST_PAGE_URL), {
31+
headers: {
32+
'User-Agent': 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)',
33+
},
34+
});
35+
36+
expect(response.status).toBe(200);
37+
expect(response.headers.get('content-type')).toContain('text/html');
38+
});
39+
40+
it('should NOT serve markdown to Googlebot (traditional bot, not an AI agent)', async () => {
41+
const response = await fetch(getContentTestURL(TEST_PAGE_URL), {
42+
headers: {
43+
'User-Agent':
44+
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
45+
},
46+
});
47+
48+
expect(response.status).toBe(200);
49+
expect(response.headers.get('content-type')).toContain('text/html');
50+
});
51+
});
52+
453
describe('markdown pages', () => {
554
it('should expose a markdown page with the .md extension', async () => {
655
const response = await fetch(

0 commit comments

Comments
 (0)