Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { serviceIndex } from '../routes/v1/index.ts'
4import { llmsTxt } from './llms-txt.ts'
5import {
6 NARRATIVE_INSTRUCTIONS,
7 narrativeRoot,
8 wantsJsonRoot,
9} from './narrative.ts'
10
11const ORIGIN = 'https://modelschemas.com'
12
13describe('narrative API root (task 11.2)', () => {
14 it('shares one source with llms.txt / MCP initialize instructions', () => {
15 expect(NARRATIVE_INSTRUCTIONS).toBe(llmsTxt)
16 const root = narrativeRoot(ORIGIN)
17 expect(root.instructions).toBe(llmsTxt)
18 })
19
20 it('carries HAL links and inline examples', () => {
21 const root = narrativeRoot(ORIGIN) as {
22 _links: typeof serviceIndex._links
23 quickstart: Array<string>
24 mcp: { endpoint: string }
25 }
26 expect(root._links).toBe(serviceIndex._links)
27 expect(root._links.self.href).toBe('/v1')
28 expect(root.quickstart.some((q) => q.includes('/v1/validate'))).toBe(true)
29 expect(root.mcp.endpoint).toBe(`${ORIGIN}/mcp`)
30 })
31
32 it('negotiates only explicit JSON GETs', () => {
33 const request = (accept: string, method = 'GET') =>
34 new Request('https://x.test/', { method, headers: { accept } })
35 expect(wantsJsonRoot(request('application/json'))).toBe(true)
36 // Browsers lead with text/html — they keep the landing page.
37 expect(wantsJsonRoot(request('text/html,application/json;q=0.8'))).toBe(
38 false,
39 )
40 expect(wantsJsonRoot(request('*/*'))).toBe(false)
41 expect(wantsJsonRoot(request('application/json', 'POST'))).toBe(false)
42 })
43})