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

embedding.spec.ts

45 lines1.5 KB

1import { test, expect } from './fixtures'
2import {
3 fillPrompt,
4 clickGenerate,
5 waitForGenerationComplete,
6 featureUrl,
7} from './helpers'
8import { providersFor } from './test-matrix'
9​
10/**
11 * Expected embedding dimension: every provider's mock (the OpenAI JSON
12 * fixture in fixtures/embedding/basic.json and the gemini/ollama/mistral
13 * mounts in global-setup.ts) returns the same deterministic 8-dim vector.
14 */
15const EXPECTED_DIMENSIONS = 8
16​
17for (const provider of providersFor('embedding')) {
18 test.describe(`${provider} -- embedding`, () => {
19 test('embeds a batch of two texts', async ({
20 page,
21 testId,
22 aimockPort,
23 }) => {
24 await page.goto(featureUrl(provider, 'embedding', testId, aimockPort))
25​
26 // The page splits the textarea on newlines — two lines make a
27 // two-item batch. The first line matches the OpenAI fixture's
28 // `inputText` (aimock joins batch inputs before matching).
29 await fillPrompt(page, 'a red guitar\na blue drum kit')
30 await clickGenerate(page)
31 await waitForGenerationComplete(page)
32​
33 const vectors = page.getByTestId('embedding-vector')
34 await expect(vectors).toHaveCount(2)
35 for (let i = 0; i < 2; i++) {
36 await expect(vectors.nth(i)).toHaveText(String(EXPECTED_DIMENSIONS))
37 await expect(vectors.nth(i)).toHaveAttribute(
38 'data-dimensions',
39 String(EXPECTED_DIMENSIONS),
40 )
41 }
42 await expect(page.getByTestId('embedding-model')).not.toBeEmpty()
43 })
44 })