import { describe, expect, it, vi } from 'vitest' import { FIFTH_DOMAIN_DISCOVERY_URL, fetchFifthDomainDiscovery, parseFifthDomainDiscovery, } from './fifthDomainDiscovery' const validDiscovery = { schema: 'guanghu.ai-discovery/v1', name: '光湖语言世界 · 第五域', canonical_repository: 'https://guanghulab.com/fifth-domain/bingshuo/fifth-domain', repository_map: 'https://guanghulab.com/api/ai/v1/repositories', server_node_map: 'https://guanghulab.com/api/ai/v1/nodes', search_api: 'https://guanghulab.com/api/ai/v1/search?q={query}', resolve_api: 'https://guanghulab.com/api/ai/v1/resolve?id={NUMBER}', access: 'public-read-only', } describe('Fifth Domain discovery', () => { it('accepts the canonical public read-only discovery document', () => { expect(parseFifthDomainDiscovery(validDiscovery)).toMatchObject({ access: 'public-read-only', canonicalRepository: validDiscovery.canonical_repository, nodeMap: validDiscovery.server_node_map, }) }) it('rejects a document that claims write access', () => { expect(() => parseFifthDomainDiscovery({ ...validDiscovery, access: 'write' })) .toThrow('public-read-only') }) it('loads the well-known endpoint without sending credentials', async () => { const fetcher = vi.fn().mockResolvedValue({ ok: true, json: () => Promise.resolve(validDiscovery) }) await fetchFifthDomainDiscovery(fetcher) expect(fetcher).toHaveBeenCalledWith(FIFTH_DOMAIN_DISCOVERY_URL, { cache: 'no-store', credentials: 'omit', signal: undefined, }) }) })