Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { llmsTxt } from './llms-txt.ts'
4import {
5 markdownForPath,
6 markdownResponse,
7 wantsMarkdown,
8} from './markdown-pages.ts'
9
10const ORIGIN = 'https://modelschemas.com'
11
12describe('markdown negotiation (task 10.5)', () => {
13 it('detects Accept: text/markdown on GET only', () => {
14 const get = (accept?: string) =>
15 new Request('https://x.test/', {
16 headers: accept ? { accept } : {},
17 })
18 expect(wantsMarkdown(get('text/markdown'))).toBe(true)
19 expect(wantsMarkdown(get('text/html, text/markdown;q=0.9'))).toBe(true)
20 expect(wantsMarkdown(get('text/html'))).toBe(false)
21 expect(wantsMarkdown(get())).toBe(false)
22 expect(
23 wantsMarkdown(
24 new Request('https://x.test/', {
25 method: 'POST',
26 headers: { accept: 'text/markdown' },
27 }),
28 ),
29 ).toBe(false)
30 })
31
32 it('serves the llms.txt source for /docs and a summary for /', () => {
33 expect(markdownForPath('/docs', ORIGIN)).toBe(llmsTxt)
34 const landing = markdownForPath('/', ORIGIN)
35 expect(landing).toContain('# modelschemas')
36 expect(landing).toContain(`${ORIGIN}/v1/models`)
37 expect(landing).toContain(`${ORIGIN}/mcp`)
38 expect(landing).toContain(`${ORIGIN}/llms.txt`)
39 expect(markdownForPath('/login', ORIGIN)).toBeNull()
40 })
41
42 it('markdown responses are 200 text/markdown with Vary: Accept', () => {
43 const response = markdownResponse('# hi')
44 expect(response.status).toBe(200)
45 expect(response.headers.get('content-type')).toBe(
46 'text/markdown; charset=utf-8',
47 )
48 expect(response.headers.get('vary')).toBe('Accept')
49 })
50})