Skip to content

Commit bbe3de1

Browse files
authored
[Ai] Fix test code to point to the right resource dir (#6932)
The devAPI helper method should read from the `googleai/` directory instead of the `vertexai/` one. Additionally, fixed tests broken by the change.
1 parent 24dd7c4 commit bbe3de1

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ internal constructor(
165165

166166
suspend fun getWebSocketSession(location: String): ClientWebSocketSession =
167167
client.webSocketSession(getBidiEndpoint(location))
168+
168169
fun generateContentStream(
169170
request: GenerateContentRequest
170171
): Flow<GenerateContentResponse.Internal> =

firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ internal class DevAPIStreamingSnapshotTests {
4242
withTimeout(testTimeout) {
4343
val responseList = responses.toList()
4444
responseList.isEmpty() shouldBe false
45-
responseList.first().candidates.first().finishReason shouldBe FinishReason.STOP
46-
responseList.first().candidates.first().content.parts.isEmpty() shouldBe false
47-
responseList.first().candidates.first().safetyRatings.isEmpty() shouldBe false
45+
responseList.last().candidates.first().apply {
46+
finishReason shouldBe FinishReason.STOP
47+
content.parts.isEmpty() shouldBe false
48+
}
4849
}
4950
}
5051

@@ -56,10 +57,9 @@ internal class DevAPIStreamingSnapshotTests {
5657
withTimeout(testTimeout) {
5758
val responseList = responses.toList()
5859
responseList.isEmpty() shouldBe false
59-
responseList.forEach {
60-
it.candidates.first().finishReason shouldBe FinishReason.STOP
61-
it.candidates.first().content.parts.isEmpty() shouldBe false
62-
it.candidates.first().safetyRatings.isEmpty() shouldBe false
60+
responseList.last().candidates.first().apply {
61+
finishReason shouldBe FinishReason.STOP
62+
content.parts.isEmpty() shouldBe false
6363
}
6464
}
6565
}

firebase-ai/src/test/java/com/google/firebase/ai/VertexAIStreamingSnapshotTests.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ internal class VertexAIStreamingSnapshotTests {
5151
withTimeout(testTimeout) {
5252
val responseList = responses.toList()
5353
responseList.isEmpty() shouldBe false
54-
responseList.first().candidates.first().finishReason shouldBe FinishReason.STOP
55-
responseList.first().candidates.first().content.parts.isEmpty() shouldBe false
56-
responseList.first().candidates.first().safetyRatings.isEmpty() shouldBe false
54+
responseList.last().candidates.first().apply {
55+
finishReason shouldBe FinishReason.STOP
56+
content.parts.isEmpty() shouldBe false
57+
safetyRatings.isEmpty() shouldBe false
58+
}
5759
}
5860
}
5961

@@ -65,10 +67,9 @@ internal class VertexAIStreamingSnapshotTests {
6567
withTimeout(testTimeout) {
6668
val responseList = responses.toList()
6769
responseList.isEmpty() shouldBe false
68-
responseList.forEach {
69-
it.candidates.first().finishReason shouldBe FinishReason.STOP
70-
it.candidates.first().content.parts.isEmpty() shouldBe false
71-
it.candidates.first().safetyRatings.isEmpty() shouldBe false
70+
responseList.last().candidates.first().apply {
71+
finishReason shouldBe FinishReason.STOP
72+
content.parts.isEmpty() shouldBe false
7273
}
7374
}
7475
}

firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import java.io.File
3939
import kotlinx.coroutines.launch
4040
import org.mockito.Mockito
4141

42-
private val TEST_CLIENT_ID = "firebase-vertexai-android/test"
42+
private val TEST_CLIENT_ID = "firebase-ai-android/test"
4343
private val TEST_APP_ID = "1:android:12345"
4444
private val TEST_VERSION = 1
4545

@@ -193,7 +193,7 @@ internal fun goldenDevAPIStreamingFile(
193193
name: String,
194194
httpStatusCode: HttpStatusCode = HttpStatusCode.OK,
195195
block: CommonTest,
196-
) = goldenStreamingFile("vertexai/$name", httpStatusCode, GenerativeBackend.googleAI(), block)
196+
) = goldenStreamingFile("googleai/$name", httpStatusCode, GenerativeBackend.googleAI(), block)
197197

198198
/**
199199
* A variant of [commonTest] for performing snapshot tests.

firebase-ai/update_responses.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# This script replaces mock response files for Vertex AI unit tests with a fresh
1818
# clone of the shared repository of Vertex AI test data.
1919

20-
RESPONSES_VERSION='v11.*' # The major version of mock responses to use
20+
RESPONSES_VERSION='v13.*' # The major version of mock responses to use
2121
REPO_NAME="vertexai-sdk-test-data"
2222
REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git"
2323

0 commit comments

Comments
 (0)