Skip to content

Commit 06eb19a

Browse files
committed
avoid duplication and re-enable tests
1 parent c6ce763 commit 06eb19a

File tree

2 files changed

+250
-437
lines changed

2 files changed

+250
-437
lines changed

packages/google/src/google-generative-ai-language-model.test.ts

Lines changed: 137 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import {
44
} from '@ai-sdk/provider';
55
import { createTestServer } from '@ai-sdk/test-server/with-vitest';
66
import { convertReadableStreamToArray } from '@ai-sdk/provider-utils/test';
7-
import { GoogleGenerativeAILanguageModel } from './google-generative-ai-language-model';
7+
import {
8+
GoogleGenerativeAILanguageModel,
9+
getGroundingMetadataSchema,
10+
getUrlContextMetadataSchema,
11+
} from './google-generative-ai-language-model';
812

913
import {
1014
GoogleGenerativeAIGroundingMetadata,
1115
GoogleGenerativeAIUrlContextMetadata,
1216
} from './google-generative-ai-prompt';
1317
import { createGoogleGenerativeAI } from './google-provider';
14-
// import { groundingMetadataSchema } from './tool/google-search';
15-
// import { urlContextMetadataSchema } from './tool/url-context';
1618
import { describe, it, expect, vi } from 'vitest';
1719

1820
vi.mock('./version', () => ({
@@ -48,135 +50,138 @@ const provider = createGoogleGenerativeAI({
4850
});
4951
const model = provider.chat('gemini-pro');
5052

51-
// describe('groundingMetadataSchema', () => {
52-
// it('validates complete grounding metadata with web search results', () => {
53-
// const metadata = {
54-
// webSearchQueries: ["What's the weather in Chicago this weekend?"],
55-
// searchEntryPoint: {
56-
// renderedContent: 'Sample rendered content for search results',
57-
// },
58-
// groundingChunks: [
59-
// {
60-
// web: {
61-
// uri: 'https://example.com/weather',
62-
// title: 'Chicago Weather Forecast',
63-
// },
64-
// },
65-
// ],
66-
// groundingSupports: [
67-
// {
68-
// segment: {
69-
// startIndex: 0,
70-
// endIndex: 65,
71-
// text: 'Chicago weather changes rapidly, so layers let you adjust easily.',
72-
// },
73-
// groundingChunkIndices: [0],
74-
// confidenceScores: [0.99],
75-
// },
76-
// ],
77-
// retrievalMetadata: {
78-
// webDynamicRetrievalScore: 0.96879,
79-
// },
80-
// };
81-
82-
// const result = groundingMetadataSchema.safeParse(metadata);
83-
// expect(result.success).toBe(true);
84-
// });
85-
86-
// it('validates complete grounding metadata with Vertex AI Search results', () => {
87-
// const metadata = {
88-
// retrievalQueries: ['How to make appointment to renew driving license?'],
89-
// groundingChunks: [
90-
// {
91-
// retrievedContext: {
92-
// uri: 'https://vertexaisearch.cloud.google.com/grounding-api-redirect/AXiHM.....QTN92V5ePQ==',
93-
// title: 'dmv',
94-
// },
95-
// },
96-
// ],
97-
// groundingSupports: [
98-
// {
99-
// segment: {
100-
// startIndex: 25,
101-
// endIndex: 147,
102-
// },
103-
// segment_text: 'ipsum lorem ...',
104-
// supportChunkIndices: [1, 2],
105-
// confidenceScore: [0.9541752, 0.97726375],
106-
// },
107-
// ],
108-
// };
109-
110-
// const result = groundingMetadataSchema.safeParse(metadata);
111-
// expect(result.success).toBe(true);
112-
// });
113-
114-
// it('validates partial grounding metadata', () => {
115-
// const metadata = {
116-
// webSearchQueries: ['sample query'],
117-
// // Missing other optional fields
118-
// };
119-
120-
// const result = groundingMetadataSchema.safeParse(metadata);
121-
// expect(result.success).toBe(true);
122-
// });
123-
124-
// it('validates empty grounding metadata', () => {
125-
// const metadata = {};
126-
127-
// const result = groundingMetadataSchema.safeParse(metadata);
128-
// expect(result.success).toBe(true);
129-
// });
130-
131-
// it('validates metadata with empty retrievalMetadata', () => {
132-
// const metadata = {
133-
// webSearchQueries: ['sample query'],
134-
// retrievalMetadata: {},
135-
// };
136-
137-
// const result = groundingMetadataSchema.safeParse(metadata);
138-
// expect(result.success).toBe(true);
139-
// });
140-
141-
// it('rejects invalid data types', () => {
142-
// const metadata = {
143-
// webSearchQueries: 'not an array', // Should be an array
144-
// groundingSupports: [
145-
// {
146-
// confidenceScores: 'not an array', // Should be an array of numbers
147-
// },
148-
// ],
149-
// };
150-
151-
// const result = groundingMetadataSchema.safeParse(metadata);
152-
// expect(result.success).toBe(false);
153-
// });
154-
// });
155-
156-
// describe('urlContextMetadata', () => {
157-
// it('validates complete url context output', () => {
158-
// const output = {
159-
// urlMetadata: [
160-
// {
161-
// retrievedUrl: 'https://example.com/weather',
162-
// urlRetrievalStatus: 'URL_RETRIEVAL_STATUS_SUCCESS',
163-
// },
164-
// ],
165-
// };
166-
167-
// const result = urlContextMetadataSchema.safeParse(output);
168-
// expect(result.success).toBe(true);
169-
// });
170-
171-
// it('validates empty url context output', () => {
172-
// const output = {
173-
// urlMetadata: [],
174-
// };
175-
176-
// const result = urlContextMetadataSchema.safeParse(output);
177-
// expect(result.success).toBe(true);
178-
// });
179-
// });
53+
const groundingMetadataSchema = getGroundingMetadataSchema()
54+
const urlContextMetadataSchema = getUrlContextMetadataSchema()
55+
56+
describe('groundingMetadataSchema', () => {
57+
it('validates complete grounding metadata with web search results', () => {
58+
const metadata = {
59+
webSearchQueries: ["What's the weather in Chicago this weekend?"],
60+
searchEntryPoint: {
61+
renderedContent: 'Sample rendered content for search results',
62+
},
63+
groundingChunks: [
64+
{
65+
web: {
66+
uri: 'https://example.com/weather',
67+
title: 'Chicago Weather Forecast',
68+
},
69+
},
70+
],
71+
groundingSupports: [
72+
{
73+
segment: {
74+
startIndex: 0,
75+
endIndex: 65,
76+
text: 'Chicago weather changes rapidly, so layers let you adjust easily.',
77+
},
78+
groundingChunkIndices: [0],
79+
confidenceScores: [0.99],
80+
},
81+
],
82+
retrievalMetadata: {
83+
webDynamicRetrievalScore: 0.96879,
84+
},
85+
};
86+
87+
const result = groundingMetadataSchema.safeParse(metadata);
88+
expect(result.success).toBe(true);
89+
});
90+
91+
it('validates complete grounding metadata with Vertex AI Search results', () => {
92+
const metadata = {
93+
retrievalQueries: ['How to make appointment to renew driving license?'],
94+
groundingChunks: [
95+
{
96+
retrievedContext: {
97+
uri: 'https://vertexaisearch.cloud.google.com/grounding-api-redirect/AXiHM.....QTN92V5ePQ==',
98+
title: 'dmv',
99+
},
100+
},
101+
],
102+
groundingSupports: [
103+
{
104+
segment: {
105+
startIndex: 25,
106+
endIndex: 147,
107+
},
108+
segment_text: 'ipsum lorem ...',
109+
supportChunkIndices: [1, 2],
110+
confidenceScore: [0.9541752, 0.97726375],
111+
},
112+
],
113+
};
114+
115+
const result = groundingMetadataSchema.safeParse(metadata);
116+
expect(result.success).toBe(true);
117+
});
118+
119+
it('validates partial grounding metadata', () => {
120+
const metadata = {
121+
webSearchQueries: ['sample query'],
122+
// Missing other optional fields
123+
};
124+
125+
const result = groundingMetadataSchema.safeParse(metadata);
126+
expect(result.success).toBe(true);
127+
});
128+
129+
it('validates empty grounding metadata', () => {
130+
const metadata = {};
131+
132+
const result = groundingMetadataSchema.safeParse(metadata);
133+
expect(result.success).toBe(true);
134+
});
135+
136+
it('validates metadata with empty retrievalMetadata', () => {
137+
const metadata = {
138+
webSearchQueries: ['sample query'],
139+
retrievalMetadata: {},
140+
};
141+
142+
const result = groundingMetadataSchema.safeParse(metadata);
143+
expect(result.success).toBe(true);
144+
});
145+
146+
it('rejects invalid data types', () => {
147+
const metadata = {
148+
webSearchQueries: 'not an array', // Should be an array
149+
groundingSupports: [
150+
{
151+
confidenceScores: 'not an array', // Should be an array of numbers
152+
},
153+
],
154+
};
155+
156+
const result = groundingMetadataSchema.safeParse(metadata);
157+
expect(result.success).toBe(false);
158+
});
159+
});
160+
161+
describe('urlContextMetadata', () => {
162+
it('validates complete url context output', () => {
163+
const output = {
164+
urlMetadata: [
165+
{
166+
retrievedUrl: 'https://example.com/weather',
167+
urlRetrievalStatus: 'URL_RETRIEVAL_STATUS_SUCCESS',
168+
},
169+
],
170+
};
171+
172+
const result = urlContextMetadataSchema.safeParse(output);
173+
expect(result.success).toBe(true);
174+
});
175+
176+
it('validates empty url context output', () => {
177+
const output = {
178+
urlMetadata: [],
179+
};
180+
181+
const result = urlContextMetadataSchema.safeParse(output);
182+
expect(result.success).toBe(true);
183+
});
184+
});
180185

181186
describe('doGenerate', () => {
182187
const TEST_URL_GEMINI_PRO =

0 commit comments

Comments
 (0)