Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

discovery.test.ts

72 lines2.2 KB

1import { describe, expect, it } from 'vitest'
2​
3import {
4 agentSkillsIndex,
5 apiCatalog,
6 mcpServerCard,
7 skillSha256,
8} from './discovery.ts'
9import { TOOLS } from './mcp.ts'
10import { skillMd } from './skill.ts'
11​
12const ORIGIN = 'https://modelschemas.com'
13​
14describe('discovery trio (task 10.3)', () => {
15 it('api-catalog is an RFC 9727 linkset over our surfaces', () => {
16 const catalog = apiCatalog(ORIGIN) as {
17 linkset: Array<Record<string, unknown>>
18 }
19 expect(catalog.linkset).toHaveLength(1)
20 const entry = catalog.linkset[0]
21 expect(entry?.anchor).toBe(`${ORIGIN}/v1`)
22 expect(entry?.['service-desc']).toEqual([
23 { href: `${ORIGIN}/openapi.json`, type: 'application/json' },
24 ])
25 expect(JSON.stringify(entry?.['service-doc'])).toContain(`${ORIGIN}/docs`)
26 })
27​
28 it('mcp server card points at /mcp and mirrors the live tool list', () => {
29 const card = mcpServerCard(ORIGIN) as {
30 serverInfo: { name: string }
31 transport: { type: string; endpoint: string }
32 tools: Array<{ name: string }>
33 }
34 expect(card.serverInfo.name).toBe('modelschemas')
35 expect(card.transport).toEqual({
36 type: 'streamable-http',
37 endpoint: `${ORIGIN}/mcp`,
38 })
39 expect(card.tools.map((tool) => tool.name)).toEqual(
40 TOOLS.map((tool) => tool.name),
41 )
42 })
43​
44 it('agent-skills index sha256 matches the served SKILL.md body', async () => {
45 const index = (await agentSkillsIndex(ORIGIN)) as {
46 $schema: string
47 skills: Array<{
48 name: string
49 type: string
50 description: string
51 url: string
52 sha256: string
53 }>
54 }
55 expect(index.$schema).toContain('v0.2.0')
56 const skill = index.skills[0]
57 expect(skill?.name).toBe('modelschemas')
58 expect(skill?.url).toBe(`${ORIGIN}/skill`)
59 expect(skill?.sha256).toBe(await skillSha256())
60 expect(skill?.sha256).toMatch(/^[0-9a-f]{64}$/)
61 // The digest is of the exact bytes /skill serves.
62 const digest = await crypto.subtle.digest(
63 'SHA-256',
64 new TextEncoder().encode(skillMd),
65 )
66 const hex = [...new Uint8Array(digest)]
67 .map((byte) => byte.toString(16).padStart(2, '0'))
68 .join('')
69 expect(skill?.sha256).toBe(hex)
70 expect(skill?.description).toContain('model schema')
71 })
72})