Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import listing from '../fixtures/groq-models-owned-by.json'
4import { groqMakerFacts, provider } from './groq.ts'
5
6describe('groq classify', () => {
7 it('maps generation paths and drops platform surfaces', () => {
8 expect(provider.classify('/openai/v1/chat/completions', {})).toBe('chat')
9 expect(provider.classify('/openai/v1/responses', {})).toBe('chat')
10 expect(provider.classify('/openai/v1/audio/speech', {})).toBe('audio')
11 expect(provider.classify('/openai/v1/audio/transcriptions', {})).toBe(
12 'audio',
13 )
14 expect(provider.classify('/openai/v1/audio/translations', {})).toBe('audio')
15 expect(provider.classify('/openai/v1/embeddings', {})).toBe('embeddings')
16 expect(provider.classify('/openai/v1/batches', {})).toBeNull()
17 expect(provider.classify('/openai/v1/files', {})).toBeNull()
18 expect(provider.classify('/openai/v1/reranking', {})).toBeNull()
19 expect(provider.classify('/v1/fine_tunings', {})).toBeNull()
20 expect(provider.classify('/openai/v1/models', {})).toBeNull()
21 })
22})
23
24describe('groq listModels', () => {
25 it('skips with an empty catalog when GROQ_API_KEY is absent', async () => {
26 const result = await provider.listModels({})
27 expect(result.models).toEqual([])
28 expect(result.skipped).toBe('groq: GROQ_API_KEY not set — skipped')
29 })
30})
31
32describe('groq upstream identity', () => {
33 it('states the maker an id names, and nothing for a bare id', () => {
34 // Ids from the live listing, 2026-11-21.
35 expect(provider.upstreamModelIdentity?.('openai/gpt-oss-120b')).toEqual({
36 providerNamespace: 'openai',
37 rawId: 'gpt-oss-120b',
38 source: {
39 derivation: 'listing',
40 sourceUrl: 'https://api.groq.com/openai/v1/models',
41 path: 'data[].id',
42 },
43 })
44 expect(
45 provider.upstreamModelIdentity?.('meta-llama/llama-prompt-guard-2-86m'),
46 ).toMatchObject({
47 providerNamespace: 'meta-llama',
48 rawId: 'llama-prompt-guard-2-86m',
49 })
50 expect(provider.upstreamModelIdentity?.('whisper-large-v3')).toBeNull()
51 expect(provider.upstreamModelIdentity?.('allam-2-7b')).toBeNull()
52 })
53})
54
55describe('groq fetchSpec', () => {
56 const spec = {
57 openapi: '3.0.1',
58 info: { title: 'GroqCloud API' },
59 paths: { '/openai/v1/chat/completions': { post: { summary: 'chat' } } },
60 }
61
62 const mockScript = (embedded: string | null): string =>
63 embedded === null
64 ? '#!/usr/bin/env bash'
65 : `#!/usr/bin/env bash\n EMBEDDED_SPEC="${embedded}"`
66
67 async function withScript<T>(
68 script: string,
69 run: () => Promise<T>,
70 ): Promise<T> {
71 const original = globalThis.fetch
72 globalThis.fetch = ((url: string) =>
73 Promise.resolve(
74 String(url) === provider.specSourceUrl
75 ? new Response(script)
76 : new Response('not found', { status: 404 }),
77 )) as typeof fetch
78 try {
79 return await run()
80 } finally {
81 globalThis.fetch = original
82 }
83 }
84
85 async function gzipBase64(text: string): Promise<string> {
86 const bytes = new Uint8Array(
87 await new Response(
88 new Blob([text]).stream().pipeThrough(new CompressionStream('gzip')),
89 ).arrayBuffer(),
90 )
91 return btoa(String.fromCharCode(...bytes))
92 }
93
94 it('decodes the base64+gzip EMBEDDED_SPEC from scripts/mock', async () => {
95 const script = mockScript(await gzipBase64(JSON.stringify(spec)))
96 const fetched = await withScript(script, () => provider.fetchSpec({}))
97 expect(fetched.outputStrategy).toBe('post-200')
98 expect(fetched.specs[0]?.info?.title).toBe('GroqCloud API')
99 expect(fetched.sources[0]?.url).toBe(provider.specSourceUrl)
100 expect(fetched.specRevision).toMatch(/^[0-9a-f]{64}$/)
101 expect(fetched.specRevision).toBe(fetched.sources[0]?.hash)
102 })
103
104 it('throws when EMBEDDED_SPEC is missing', async () => {
105 await expect(
106 withScript(mockScript(null), () => provider.fetchSpec({})),
107 ).rejects.toThrow(/groq: no EMBEDDED_SPEC/)
108 })
109
110 it('throws when EMBEDDED_SPEC is not gzip', async () => {
111 await expect(
112 withScript(mockScript(btoa('plain text')), () => provider.fetchSpec({})),
113 ).rejects.toThrow(/not gzipped JSON/)
114 })
115})
116
117describe('groq maker (#710)', () => {
118 const byId = new Map(listing.data.map((row) => [row.id, row]))
119
120 it('reads owned_by as written (live listing, 2026-11-21)', () => {
121 const facts = (id: string) => groqMakerFacts(byId.get(id) ?? {})
122 expect(facts('openai/gpt-oss-120b').maker).toBe('OpenAI')
123 expect(facts('qwen/qwen3.8-27b').maker).toBe('Alibaba Cloud')
124 expect(facts('allam-2-7b').maker).toBe('SDAIA')
125 expect(facts('meta-llama/llama-prompt-guard-2-86m')).toEqual({
126 maker: 'Meta',
127 factSources: {
128 maker: {
129 derivation: 'listing',
130 sourceUrl: 'https://api.groq.com/openai/v1/models',
131 path: 'owned_by',
132 },
133 },
134 })
135 })
136
137 it('says a row with no owned_by names no maker', () => {
138 expect(groqMakerFacts({ owned_by: ' ' })).toMatchObject({
139 maker: null,
140 factSources: { maker: { path: 'unstated' } },
141 })
142 })
143})