-
Notifications
You must be signed in to change notification settings - Fork 4.1k
chore(firebaseai): setup for mock response e2e test #18029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
11352e0
setup for mock response e2e test
cynthiajoan 3382ad6
fix the failing parse
cynthiajoan 3912a21
update test to address unary-success-unknown-enum-safety-ratings.json
cynthiajoan d39d210
analyzer
cynthiajoan c810cfd
Merge branch 'main' into firebaseai/local_integration_test
cynthiajoan 6921f4a
clean up and add ai e2e test coverage
cynthiajoan 07d1e8c
fix analyzer
cynthiajoan 5059528
remove extra import
cynthiajoan b029838
fix web test failure on CI
cynthiajoan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
setup for mock response e2e test
- Loading branch information
commit 11352e09366819b2ce99c5abd9a2394a95cfa7bf
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
tests/integration_test/firebase_ai/firebase_ai_e2e_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import 'dart:convert'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
| import 'package:http/http.dart' as http; | ||
| import 'package:firebase_core/firebase_core.dart'; | ||
| import 'package:firebase_ai/src/api.dart'; | ||
| import 'package:firebase_ai/src/developer/api.dart'; | ||
| import 'package:firebase_ai/src/imagen/imagen_content.dart'; | ||
| import 'package:tests/firebase_options.dart'; | ||
|
|
||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| group('firebase_ai e2e', () { | ||
| setUpAll(() async { | ||
| await Firebase.initializeApp( | ||
| options: DefaultFirebaseOptions.currentPlatform, | ||
| ); | ||
| }); | ||
|
|
||
| test('test against all json responses from vertexai-sdk-test-data', | ||
| () async { | ||
| final treeUrl = Uri.parse( | ||
| 'https://api.github.com/repos/FirebaseExtended/vertexai-sdk-test-data/git/trees/main?recursive=1'); | ||
| final treeResponse = await http.get(treeUrl); | ||
| if (treeResponse.statusCode != 200) { | ||
| fail('Failed to fetch tree: ${treeResponse.statusCode}'); | ||
| } | ||
| final treeData = jsonDecode(treeResponse.body); | ||
| final tree = treeData['tree'] as List; | ||
|
|
||
| final jsonFiles = tree.where((item) { | ||
| final path = item['path'] as String; | ||
| return path.startsWith('mock-responses/') && path.endsWith('.json'); | ||
| }).toList(); | ||
|
|
||
| for (final file in jsonFiles) { | ||
| final path = file['path'] as String; | ||
| final rawUrl = Uri.parse( | ||
| 'https://raw.githubusercontent.com/FirebaseExtended/vertexai-sdk-test-data/main/$path'); | ||
| final response = await http.get(rawUrl); | ||
| if (response.statusCode != 200) { | ||
| continue; | ||
| } | ||
|
|
||
| final jsonData = jsonDecode(response.body); | ||
|
|
||
| final isVertex = path.contains('vertexai'); | ||
| final serializer = | ||
| isVertex ? VertexSerialization() : DeveloperSerialization(); | ||
|
|
||
| try { | ||
| if (path.contains('generate-images')) { | ||
| if (path.contains('gcs')) { | ||
| parseImagenGenerationResponse<ImagenGCSImage>(jsonData); | ||
| } else { | ||
| parseImagenGenerationResponse<ImagenInlineImage>(jsonData); | ||
| } | ||
| } else if (path.contains('total-tokens') || path.contains('token')) { | ||
| if (jsonData is Map && | ||
| (jsonData.containsKey('totalTokens') || | ||
| jsonData.containsKey('error'))) { | ||
| serializer.parseCountTokensResponse(jsonData); | ||
| } else { | ||
| serializer.parseGenerateContentResponse(jsonData); | ||
| } | ||
| } else { | ||
| serializer.parseGenerateContentResponse(jsonData); | ||
| } | ||
|
cynthiajoan marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (path.contains('failure') && !path.contains('success')) { | ||
| fail('Expected parsing to fail for $path, but it succeeded.'); | ||
| } | ||
| } catch (e) { | ||
| if (path.contains('failure') && !path.contains('success')) { | ||
| // Expected to fail | ||
| expect(e, isA<Exception>(), | ||
| reason: 'Expected an Exception but got $e for $path'); | ||
| } else { | ||
| fail('Failed to parse success file $path: $e'); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.