|
| 1 | +import { describe, expect, test } from 'vitest' |
| 2 | +import { get } from '@/tests/helpers/e2etest.js' |
| 3 | + |
| 4 | +describe('llms.txt endpoint', () => { |
| 5 | + test('returns 200 OK', async () => { |
| 6 | + const res = await get('/llms.txt') |
| 7 | + expect(res.statusCode).toBe(200) |
| 8 | + }) |
| 9 | + |
| 10 | + test('returns markdown content type', async () => { |
| 11 | + const res = await get('/llms.txt') |
| 12 | + expect(res.headers['content-type']).toMatch(/text\/markdown/) |
| 13 | + }) |
| 14 | + |
| 15 | + test('includes GitHub Docs title', async () => { |
| 16 | + const res = await get('/llms.txt') |
| 17 | + const content = res.body |
| 18 | + |
| 19 | + // Should contain GitHub in the title |
| 20 | + expect(content).toMatch(/^# .*GitHub.*Docs/m) |
| 21 | + }) |
| 22 | + |
| 23 | + test('includes programmatic access section', async () => { |
| 24 | + const res = await get('/llms.txt') |
| 25 | + const content = res.body |
| 26 | + |
| 27 | + // Should mention the existing APIs |
| 28 | + expect(content).toMatch(/Article API/i) |
| 29 | + expect(content).toMatch(/Page List API/i) |
| 30 | + expect(content).toMatch(/api\/article/i) |
| 31 | + expect(content).toMatch(/api\/pagelist\/en\/free-pro-team@latest/i) |
| 32 | + }) |
| 33 | + |
| 34 | + test('includes all main sections', async () => { |
| 35 | + const res = await get('/llms.txt') |
| 36 | + const content = res.body |
| 37 | + |
| 38 | + // Should have all the main sections we expect |
| 39 | + expect(content).toMatch(/## Docs Content/i) |
| 40 | + expect(content).toMatch(/## Translations/i) |
| 41 | + expect(content).toMatch(/## Versions/i) |
| 42 | + }) |
| 43 | + |
| 44 | + test('contains valid markdown links', async () => { |
| 45 | + const res = await get('/llms.txt') |
| 46 | + const content = res.body |
| 47 | + |
| 48 | + // Extract all markdown links |
| 49 | + const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g |
| 50 | + const links = Array.from(content.matchAll(linkRegex)) |
| 51 | + |
| 52 | + expect(links.length).toBeGreaterThan(0) |
| 53 | + |
| 54 | + // Check that links are properly formatted |
| 55 | + for (const match of links) { |
| 56 | + const [, linkText, linkUrl] = match as RegExpMatchArray |
| 57 | + expect(linkText.trim()).not.toBe('') |
| 58 | + expect(linkUrl.trim()).not.toBe('') |
| 59 | + |
| 60 | + // All links should be absolute GitHub docs URLs |
| 61 | + expect(linkUrl).toMatch(/^https:\/\/docs\.github\.com/i) |
| 62 | + } |
| 63 | + }) |
| 64 | + |
| 65 | + test('has proper cache headers', async () => { |
| 66 | + const res = await get('/llms.txt') |
| 67 | + |
| 68 | + // Should have cache control headers set by defaultCacheControl |
| 69 | + expect(res.headers).toHaveProperty('cache-control') |
| 70 | + }) |
| 71 | + |
| 72 | + test('references pagelist API for content discovery', async () => { |
| 73 | + const res = await get('/llms.txt') |
| 74 | + const content = res.body |
| 75 | + |
| 76 | + // Should prominently feature the pagelist API as the main content source |
| 77 | + expect(content).toMatch(/Page List API.*api\/pagelist\/en\/free-pro-team@latest/i) |
| 78 | + expect(content).not.toMatch(/Machine-readable list/i) // Removed descriptions |
| 79 | + }) |
| 80 | + |
| 81 | + test.each(['free-pro-team@latest', 'enterprise-cloud@latest'])( |
| 82 | + 'includes %s version in versions section', |
| 83 | + async (versionPattern) => { |
| 84 | + const res = await get('/llms.txt') |
| 85 | + const content = res.body |
| 86 | + |
| 87 | + // Should include versions section |
| 88 | + expect(content).toMatch(/## Versions/i) |
| 89 | + |
| 90 | + // Should include this specific version pattern |
| 91 | + expect(content).toMatch(new RegExp(`api/pagelist/en/${versionPattern}`)) |
| 92 | + }, |
| 93 | + ) |
| 94 | + |
| 95 | + test('includes enterprise server versions', async () => { |
| 96 | + const res = await get('/llms.txt') |
| 97 | + const content = res.body |
| 98 | + |
| 99 | + // Should include enterprise server versions with pattern |
| 100 | + expect(content).toMatch(/api\/pagelist\/en\/enterprise-server@\d+\.\d+/) |
| 101 | + }) |
| 102 | + |
| 103 | + test('follows llms.txt specification structure and has reasonable length', async () => { |
| 104 | + const res = await get('/llms.txt') |
| 105 | + const content = res.body |
| 106 | + |
| 107 | + // Check for required H1 title |
| 108 | + expect(content).toMatch(/^# .+/m) |
| 109 | + |
| 110 | + // Check for blockquote description |
| 111 | + expect(content).toMatch(/^> .+/m) |
| 112 | + |
| 113 | + // Check for H2 sections |
| 114 | + expect(content).toMatch(/^## .+/m) |
| 115 | + |
| 116 | + // Check for markdown links |
| 117 | + expect(content).toMatch(/\[.+\]\(.+\)/m) |
| 118 | + |
| 119 | + // Should include translations and versions but still be reasonable |
| 120 | + expect(content.length).toBeGreaterThan(500) |
| 121 | + expect(content.length).toBeLessThan(5000) |
| 122 | + |
| 123 | + // Split into lines for structure analysis |
| 124 | + const lines = content.split('\n') |
| 125 | + |
| 126 | + // First non-empty line should be H1 |
| 127 | + const firstContentLine = lines.find((line: string) => line.trim() !== '') |
| 128 | + expect(firstContentLine).toMatch(/^# /) |
| 129 | + |
| 130 | + // Should contain blockquote after title |
| 131 | + const hasBlockquote = lines.some((line: string) => line.trim().startsWith('>')) |
| 132 | + expect(hasBlockquote).toBe(true) |
| 133 | + |
| 134 | + // Should have multiple H2 sections (Docs Content, Translations, Versions) |
| 135 | + const h2Sections = lines.filter((line: string) => line.trim().startsWith('## ')) |
| 136 | + expect(h2Sections.length).toBeGreaterThanOrEqual(3) |
| 137 | + }) |
| 138 | +}) |
0 commit comments