Skip to content

Commit 861bd2c

Browse files
Merge branch 'refs/heads/main' into fix-background-disconnect
2 parents 3763470 + 4c4c7c9 commit 861bd2c

File tree

9 files changed

+46
-37
lines changed

9 files changed

+46
-37
lines changed

.github/workflows/check-vertexai-responses.yml renamed to .github/workflows/check-firebaseai-responses.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Check Vertex AI Responses
1+
name: Check Firebase AI Responses
22

33
on: pull_request
44

@@ -10,30 +10,30 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1212
- name: Clone mock responses
13-
run: firebase-vertexai/update_responses.sh
13+
run: firebase-ai/update_responses.sh
1414
- name: Find cloned and latest versions
1515
run: |
1616
CLONED=$(git describe --tags)
1717
LATEST=$(git tag --sort=v:refname | tail -n1)
1818
echo "cloned_tag=$CLONED" >> $GITHUB_ENV
1919
echo "latest_tag=$LATEST" >> $GITHUB_ENV
20-
working-directory: firebase-vertexai/src/test/resources/vertexai-sdk-test-data
20+
working-directory: firebase-ai/src/test/resources/vertexai-sdk-test-data
2121
- name: Find comment from previous run if exists
2222
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
2323
id: fc
2424
with:
2525
issue-number: ${{github.event.number}}
26-
body-includes: Vertex AI Mock Responses Check
26+
body-includes: Firebase AI Mock Responses Check
2727
- name: Comment on PR if newer version is available
2828
if: ${{env.cloned_tag != env.latest_tag && !steps.fc.outputs.comment-id}}
2929
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
3030
with:
3131
issue-number: ${{github.event.number}}
3232
body: >
33-
### Vertex AI Mock Responses Check :warning:
33+
### Firebase AI Mock Responses Check :warning:
3434
35-
A newer major version of the mock responses for Vertex AI unit tests is available.
36-
[update_responses.sh](https://github.com/firebase/firebase-android-sdk/blob/main/firebase-vertexai/update_responses.sh)
35+
A newer major version of the mock responses for Firebase AI unit tests is available.
36+
[update_responses.sh](https://github.com/firebase/firebase-android-sdk/blob/main/firebase-ai/update_responses.sh)
3737
should be updated to clone the latest version of the responses: `${{env.latest_tag}}`
3838
- name: Delete comment when version gets updated
3939
if: ${{env.cloned_tag == env.latest_tag && steps.fc.outputs.comment-id}}

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ internal constructor(
164164
"wss://firebasevertexai.googleapis.com/ws/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent/locations/$location?key=$key"
165165

166166
suspend fun getWebSocketSession(location: String): ClientWebSocketSession =
167-
client.webSocketSession(getBidiEndpoint(location))
167+
client.webSocketSession(getBidiEndpoint(location)) { applyCommonHeaders() }
168+
168169
fun generateContentStream(
169170
request: GenerateContentRequest
170171
): Flow<GenerateContentResponse.Internal> =
@@ -190,12 +191,7 @@ internal constructor(
190191
throw FirebaseCommonAIException.from(e)
191192
}
192193

193-
private fun HttpRequestBuilder.applyCommonConfiguration(request: Request) {
194-
when (request) {
195-
is GenerateContentRequest -> setBody<GenerateContentRequest>(request)
196-
is CountTokensRequest -> setBody<CountTokensRequest>(request)
197-
is GenerateImageRequest -> setBody<GenerateImageRequest>(request)
198-
}
194+
private fun HttpRequestBuilder.applyCommonHeaders() {
199195
contentType(ContentType.Application.Json)
200196
header("x-goog-api-key", key)
201197
header("x-goog-api-client", apiClient)
@@ -204,6 +200,14 @@ internal constructor(
204200
header("X-Firebase-AppVersion", appVersion)
205201
}
206202
}
203+
private fun HttpRequestBuilder.applyCommonConfiguration(request: Request) {
204+
when (request) {
205+
is GenerateContentRequest -> setBody<GenerateContentRequest>(request)
206+
is CountTokensRequest -> setBody<CountTokensRequest>(request)
207+
is GenerateImageRequest -> setBody<GenerateImageRequest>(request)
208+
}
209+
applyCommonHeaders()
210+
}
207211

208212
private suspend fun HttpRequestBuilder.applyHeaderProvider() {
209213
if (headerProvider != null) {

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

firebase-storage/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [fixed] Fixed an issue where tests were depending on a deprecated feature of the test framework (#6927)
23

34
# 21.0.1
45
* [fixed] Fixed an issue where `maxUploadRetryTimeMillis` parameter is ignored when uploading using

firebase-storage/src/test/java/com/google/firebase/storage/DownloadTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
import static org.junit.Assert.assertNotNull;
1919
import static org.junit.Assert.assertTrue;
2020
import static org.junit.Assert.fail;
21+
import static org.robolectric.Shadows.shadowOf;
2122

2223
import android.net.Uri;
2324
import android.os.Build;
25+
import android.os.Looper;
2426
import com.google.android.gms.tasks.Task;
2527
import com.google.firebase.FirebaseApp;
2628
import com.google.firebase.storage.TestDownloadHelper.StreamDownloadResponse;
@@ -40,14 +42,13 @@
4042
import org.junit.Test;
4143
import org.junit.rules.TemporaryFolder;
4244
import org.junit.runner.RunWith;
43-
import org.robolectric.Robolectric;
4445
import org.robolectric.RobolectricTestRunner;
4546
import org.robolectric.annotation.Config;
4647

4748
/** Tests for {@link FirebaseStorage}. */
4849
@SuppressWarnings("ConstantConditions")
4950
@RunWith(RobolectricTestRunner.class)
50-
@Config(sdk = Build.VERSION_CODES.LOLLIPOP_MR1)
51+
@Config(sdk = Build.VERSION_CODES.M)
5152
public class DownloadTest {
5253

5354
@Rule public RetryRule retryRule = new RetryRule(3);
@@ -137,7 +138,7 @@ public void streamDownloadStateVerification() throws Exception {
137138
ControllableSchedulerHelper.getInstance().resume();
138139

139140
for (int i = 0; i < 3000; i++) {
140-
Robolectric.flushForegroundThreadScheduler();
141+
shadowOf(Looper.getMainLooper()).runToEndOfTasks();
141142
if (semaphore.tryAcquire(2, 1, TimeUnit.MILLISECONDS)) {
142143
Assert.assertEquals(bytesDownloaded.get(), bytesTransferred.get());
143144
return;
@@ -256,7 +257,7 @@ public void byteDownload() throws Exception {
256257
TestDownloadHelper.byteDownload(
257258
new StringBuilder(), bitmap -> assertEquals(1076408, bitmap.length));
258259
for (int i = 0; i < 3000; i++) {
259-
Robolectric.flushForegroundThreadScheduler();
260+
shadowOf(Looper.getMainLooper()).runToEndOfTasks();
260261
if (semaphore.tryAcquire(1, 1, TimeUnit.MILLISECONDS)) {
261262
// success!
262263
factory.verifyOldMock();

firebase-storage/src/test/java/com/google/firebase/storage/TestUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
package com.google.firebase.storage;
1616

17+
import static org.robolectric.Shadows.shadowOf;
18+
19+
import android.os.Looper;
1720
import androidx.annotation.Nullable;
1821
import androidx.test.core.app.ApplicationProvider;
1922
import com.google.android.gms.tasks.Task;
@@ -26,7 +29,6 @@
2629
import java.io.StringReader;
2730
import java.util.concurrent.TimeUnit;
2831
import org.junit.Assert;
29-
import org.robolectric.Robolectric;
3032

3133
/** Test helpers. */
3234
public class TestUtil {
@@ -138,7 +140,7 @@ static void await(Task<?> task, int timeout, TimeUnit timeUnit) throws Interrupt
138140
long timeoutMillis = timeUnit.toMillis(timeout);
139141

140142
for (int i = 0; i < timeoutMillis; i++) {
141-
Robolectric.flushForegroundThreadScheduler();
143+
shadowOf(Looper.getMainLooper()).runToEndOfTasks();
142144
if (task.isComplete()) {
143145
// success!
144146
return;

0 commit comments

Comments
 (0)