From acd6026f84b867d9c6b96b376327ff051fc541e7 Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Fri, 2 May 2025 13:21:33 -0400 Subject: [PATCH 1/8] [Ai] Fix test code to point to the right resource dir The devAPI helper method should read from the `googleai/` directory instead of the `vertexai/` one. --- .../src/test/java/com/google/firebase/ai/util/tests.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt b/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt index dff254b7adf..393a2a16adc 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt @@ -39,7 +39,7 @@ import java.io.File import kotlinx.coroutines.launch import org.mockito.Mockito -private val TEST_CLIENT_ID = "firebase-vertexai-android/test" +private val TEST_CLIENT_ID = "firebase-ai-android/test" private val TEST_APP_ID = "1:android:12345" private val TEST_VERSION = 1 @@ -193,7 +193,7 @@ internal fun goldenDevAPIStreamingFile( name: String, httpStatusCode: HttpStatusCode = HttpStatusCode.OK, block: CommonTest, -) = goldenStreamingFile("vertexai/$name", httpStatusCode, GenerativeBackend.googleAI(), block) +) = goldenStreamingFile("googleai/$name", httpStatusCode, GenerativeBackend.googleAI(), block) /** * A variant of [commonTest] for performing snapshot tests. From fc66bf6896c4cd7a334dfd2778da543e6a62e19f Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Fri, 2 May 2025 20:48:42 -0400 Subject: [PATCH 2/8] Add missing empty line --- .../main/kotlin/com/google/firebase/ai/common/APIController.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt index a0287c161c2..9e38045f432 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt @@ -165,6 +165,7 @@ internal constructor( suspend fun getWebSocketSession(location: String): ClientWebSocketSession = client.webSocketSession(getBidiEndpoint(location)) + fun generateContentStream( request: GenerateContentRequest ): Flow = From 394c321e7d04141db9b091658fb971ad45786553 Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Fri, 2 May 2025 20:48:54 -0400 Subject: [PATCH 3/8] Address broken tests Tests were failing because they were looking at the finish reason in every data chunck instead of the last one. --- .../firebase/ai/DevAPIStreamingSnapshotTests.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt b/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt index fde573fd634..21f9de3a303 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt @@ -42,9 +42,10 @@ internal class DevAPIStreamingSnapshotTests { withTimeout(testTimeout) { val responseList = responses.toList() responseList.isEmpty() shouldBe false - responseList.first().candidates.first().finishReason shouldBe FinishReason.STOP - responseList.first().candidates.first().content.parts.isEmpty() shouldBe false - responseList.first().candidates.first().safetyRatings.isEmpty() shouldBe false + responseList.last().candidates.first().let { + it.finishReason shouldBe FinishReason.STOP + it.content.parts.isEmpty() shouldBe false + } } } @@ -56,10 +57,9 @@ internal class DevAPIStreamingSnapshotTests { withTimeout(testTimeout) { val responseList = responses.toList() responseList.isEmpty() shouldBe false - responseList.forEach { - it.candidates.first().finishReason shouldBe FinishReason.STOP - it.candidates.first().content.parts.isEmpty() shouldBe false - it.candidates.first().safetyRatings.isEmpty() shouldBe false + responseList.last().candidates.first().let { + it.finishReason shouldBe FinishReason.STOP + it.content.parts.isEmpty() shouldBe false } } } From 776e8a2f361ff740cda3e5e11b237f6992f30e3c Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Sat, 3 May 2025 00:13:50 -0400 Subject: [PATCH 4/8] Prefer apply over let for test --- .../firebase/ai/DevAPIStreamingSnapshotTests.kt | 12 ++++++------ .../ai/VertexAIStreamingSnapshotTests.kt | 17 ++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt b/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt index 21f9de3a303..967254a096c 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt @@ -42,9 +42,9 @@ internal class DevAPIStreamingSnapshotTests { withTimeout(testTimeout) { val responseList = responses.toList() responseList.isEmpty() shouldBe false - responseList.last().candidates.first().let { - it.finishReason shouldBe FinishReason.STOP - it.content.parts.isEmpty() shouldBe false + responseList.last().candidates.first().apply { + finishReason shouldBe FinishReason.STOP + content.parts.isEmpty() shouldBe false } } } @@ -57,9 +57,9 @@ internal class DevAPIStreamingSnapshotTests { withTimeout(testTimeout) { val responseList = responses.toList() responseList.isEmpty() shouldBe false - responseList.last().candidates.first().let { - it.finishReason shouldBe FinishReason.STOP - it.content.parts.isEmpty() shouldBe false + responseList.last().candidates.first().apply { + finishReason shouldBe FinishReason.STOP + content.parts.isEmpty() shouldBe false } } } diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt b/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt index 8b6079cc6a5..e645f587267 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt @@ -51,9 +51,12 @@ internal class VertexAIStreamingSnapshotTests { withTimeout(testTimeout) { val responseList = responses.toList() responseList.isEmpty() shouldBe false - responseList.first().candidates.first().finishReason shouldBe FinishReason.STOP - responseList.first().candidates.first().content.parts.isEmpty() shouldBe false - responseList.first().candidates.first().safetyRatings.isEmpty() shouldBe false + responseList.last().candidates.first().apply { + finishReason shouldBe FinishReason.STOP + content.parts.isEmpty() shouldBe false + safetyRatings.isEmpty() shouldBe false + } + } } @@ -65,10 +68,10 @@ internal class VertexAIStreamingSnapshotTests { withTimeout(testTimeout) { val responseList = responses.toList() responseList.isEmpty() shouldBe false - responseList.forEach { - it.candidates.first().finishReason shouldBe FinishReason.STOP - it.candidates.first().content.parts.isEmpty() shouldBe false - it.candidates.first().safetyRatings.isEmpty() shouldBe false + responseList.last().candidates.first().apply { + finishReason shouldBe FinishReason.STOP + content.parts.isEmpty() shouldBe false + safetyRatings.isEmpty() shouldBe false } } } From 867c9c4580cd343fc224c5381e8ca263fad5dd77 Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Sat, 3 May 2025 00:37:52 -0400 Subject: [PATCH 5/8] Update vertex success long response --- .../com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt b/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt index e645f587267..98699f71e85 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt @@ -71,7 +71,6 @@ internal class VertexAIStreamingSnapshotTests { responseList.last().candidates.first().apply { finishReason shouldBe FinishReason.STOP content.parts.isEmpty() shouldBe false - safetyRatings.isEmpty() shouldBe false } } } From 96bacd05705295f9fd8bd304153c47062c93c97b Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Mon, 5 May 2025 10:51:30 -0400 Subject: [PATCH 6/8] Fix format --- .../com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt b/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt index 98699f71e85..e6331401fde 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt @@ -56,7 +56,6 @@ internal class VertexAIStreamingSnapshotTests { content.parts.isEmpty() shouldBe false safetyRatings.isEmpty() shouldBe false } - } } From ba2b65ac60d21ad043343e08709c0aa00feb8e22 Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Mon, 5 May 2025 15:04:09 -0400 Subject: [PATCH 7/8] Use the latest version of the tests files --- firebase-ai/update_responses.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-ai/update_responses.sh b/firebase-ai/update_responses.sh index a6dea7785d4..99ea106cda4 100755 --- a/firebase-ai/update_responses.sh +++ b/firebase-ai/update_responses.sh @@ -17,7 +17,7 @@ # This script replaces mock response files for Vertex AI unit tests with a fresh # clone of the shared repository of Vertex AI test data. -RESPONSES_VERSION='v11.*' # The major version of mock responses to use +RESPONSES_VERSION='v12.*' # The major version of mock responses to use REPO_NAME="vertexai-sdk-test-data" REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git" From 93905bc32507a6ff42d66c0303a0289846c3495d Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Date: Mon, 5 May 2025 17:38:02 -0400 Subject: [PATCH 8/8] Update update_responses.sh --- firebase-ai/update_responses.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-ai/update_responses.sh b/firebase-ai/update_responses.sh index 99ea106cda4..7d6ea18e0ee 100755 --- a/firebase-ai/update_responses.sh +++ b/firebase-ai/update_responses.sh @@ -17,7 +17,7 @@ # This script replaces mock response files for Vertex AI unit tests with a fresh # clone of the shared repository of Vertex AI test data. -RESPONSES_VERSION='v12.*' # The major version of mock responses to use +RESPONSES_VERSION='v13.*' # The major version of mock responses to use REPO_NAME="vertexai-sdk-test-data" REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git"