| import { describe, expect, test } from 'vitest' |
| import { get } from '@/tests/helpers/e2etest' |
|
|
| describe('llms.txt endpoint', () => { |
| test('returns 200 OK', async () => { |
| const res = await get('/llms.txt') |
| expect(res.statusCode).toBe(200) |
| }) |
|
|
| test('returns markdown content type', async () => { |
| const res = await get('/llms.txt') |
| expect(res.headers['content-type']).toMatch(/text\/markdown/) |
| }) |
|
|
| test('includes GitHub Docs title', async () => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| expect(content).toMatch(/^# .*GitHub.*Docs/m) |
| }) |
|
|
| test('includes programmatic access section', async () => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| expect(content).toMatch(/Article API/i) |
| expect(content).toMatch(/Page List API/i) |
| expect(content).toMatch(/api\/article/i) |
| expect(content).toMatch(/api\/pagelist\/en\/free-pro-team@latest/i) |
| }) |
|
|
| test('includes all main sections', async () => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| expect(content).toMatch(/## Docs Content/i) |
| expect(content).toMatch(/## Translations/i) |
| expect(content).toMatch(/## Versions/i) |
| }) |
|
|
| test('contains valid markdown links', async () => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g |
| const links = Array.from(content.matchAll(linkRegex)) |
|
|
| expect(links.length).toBeGreaterThan(0) |
|
|
| |
| for (const match of links) { |
| const [, linkText, linkUrl] = match as RegExpMatchArray |
| expect(linkText.trim()).not.toBe('') |
| expect(linkUrl.trim()).not.toBe('') |
|
|
| |
| expect(linkUrl).toMatch(/^https:\/\/docs\.github\.com/i) |
| } |
| }) |
|
|
| test('has proper cache headers', async () => { |
| const res = await get('/llms.txt') |
|
|
| |
| expect(res.headers).toHaveProperty('cache-control') |
| }) |
|
|
| test('references pagelist API for content discovery', async () => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| expect(content).toMatch(/Page List API.*api\/pagelist\/en\/free-pro-team@latest/i) |
| expect(content).not.toMatch(/Machine-readable list/i) |
| }) |
|
|
| test.each(['free-pro-team@latest', 'enterprise-cloud@latest'])( |
| 'includes %s version in versions section', |
| async (versionPattern) => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| expect(content).toMatch(/## Versions/i) |
|
|
| |
| expect(content).toMatch(new RegExp(`api/pagelist/en/${versionPattern}`)) |
| }, |
| ) |
|
|
| test('includes enterprise server versions', async () => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| expect(content).toMatch(/api\/pagelist\/en\/enterprise-server@\d+\.\d+/) |
| }) |
|
|
| test('follows llms.txt specification structure and has reasonable length', async () => { |
| const res = await get('/llms.txt') |
| const content = res.body |
|
|
| |
| expect(content).toMatch(/^# .+/m) |
|
|
| |
| expect(content).toMatch(/^> .+/m) |
|
|
| |
| expect(content).toMatch(/^## .+/m) |
|
|
| |
| expect(content).toMatch(/\[.+\]\(.+\)/m) |
|
|
| |
| expect(content.length).toBeGreaterThan(500) |
| expect(content.length).toBeLessThan(5000) |
|
|
| |
| const lines = content.split('\n') |
|
|
| |
| const firstContentLine = lines.find((line: string) => line.trim() !== '') |
| expect(firstContentLine).toMatch(/^# /) |
|
|
| |
| const hasBlockquote = lines.some((line: string) => line.trim().startsWith('>')) |
| expect(hasBlockquote).toBe(true) |
|
|
| |
| const h2Sections = lines.filter((line: string) => line.trim().startsWith('## ')) |
| expect(h2Sections.length).toBeGreaterThanOrEqual(3) |
| }) |
| }) |
|
|