|
1 | 1 | import { describe, expect, it } from 'bun:test'; |
2 | 2 | import { getContentTestURL } from './utils'; |
3 | 3 |
|
| 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 | + |
4 | 53 | describe('markdown pages', () => { |
5 | 54 | it('should expose a markdown page with the .md extension', async () => { |
6 | 55 | const response = await fetch( |
|
0 commit comments