Skip to content

Commit d49b277

Browse files
authored
Merge branch 'main' into auth-actioncode
2 parents 6366ac0 + d3e26c0 commit d49b277

File tree

8 files changed

+85
-42
lines changed

8 files changed

+85
-42
lines changed

.github/workflows/abtesting.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ jobs:
2323
strategy:
2424
matrix:
2525
include:
26+
- os: macos-13
27+
xcode: Xcode_15.2
28+
target: ios
2629
- os: macos-14
27-
xcode: Xcode_16.2
30+
xcode: Xcode_15.4
2831
target: ios
2932
- os: macos-15
30-
xcode: Xcode_16.3
33+
xcode: Xcode_16.2
3134
target: ios
3235
- os: macos-15
33-
xcode: Xcode_16.3
36+
xcode: Xcode_16.2
3437
target: tvos
3538
- os: macos-15
36-
xcode: Xcode_16.3
39+
xcode: Xcode_16.2
3740
target: macos
3841
- os: macos-15
39-
xcode: Xcode_16.3
42+
xcode: Xcode_16.2
4043
target: watchos
4144
runs-on: ${{ matrix.os }}
4245
steps:
@@ -84,26 +87,29 @@ jobs:
8487
strategy:
8588
matrix:
8689
include:
90+
- os: macos-13
91+
xcode: Xcode_15.2
92+
target: iOS
8793
- os: macos-14
88-
xcode: Xcode_16.2
94+
xcode: Xcode_15.4
8995
target: iOS
9096
- os: macos-15
91-
xcode: Xcode_16.3
97+
xcode: Xcode_16.2
9298
target: iOS
9399
- os: macos-15
94-
xcode: Xcode_16.3
100+
xcode: Xcode_16.2
95101
target: tvOS
96102
- os: macos-15
97-
xcode: Xcode_16.3
103+
xcode: Xcode_16.2
98104
target: macOS
99105
- os: macos-15
100-
xcode: Xcode_16.3
106+
xcode: Xcode_16.2
101107
target: watchOS
102108
- os: macos-15
103-
xcode: Xcode_16.3
109+
xcode: Xcode_16.2
104110
target: catalyst
105111
- os: macos-15
106-
xcode: Xcode_16.3
112+
xcode: Xcode_16.2
107113
target: visionOS
108114
runs-on: ${{ matrix.os }}
109115
steps:
@@ -207,7 +213,7 @@ jobs:
207213
# Don't run on private repo.
208214
if: github.event_name == 'schedule' && github.repository == 'Firebase/firebase-ios-sdk'
209215

210-
runs-on: macos-15
216+
runs-on: macos-14
211217
strategy:
212218
matrix:
213219
target: [ios, tvos, macos]

FirebaseAuth/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
- [fixed] Fix a `fatalError` unenrolling from MFA. An invalid user token now throws an
3+
`invalidUserToken` error instead of crashing. (#14663)
24
- [fixed] Fix the parameter from "languageCode" to "lang" in ActionCodeURL (#14664)
35

46
# 11.9.0

FirebaseAuth/Sources/Swift/User/User.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ extension User: NSSecureCoding {}
10811081
anonymous: Bool) async throws -> User {
10821082
guard let accessToken = accessToken,
10831083
let refreshToken = refreshToken else {
1084-
fatalError("Internal FirebaseAuth Error: nil token")
1084+
throw AuthErrorUtils.invalidUserTokenError(message: "Invalid user token: accessToken or refreshToken is nil")
10851085
}
10861086
let tokenService = SecureTokenService(withRequestConfiguration: auth.requestConfiguration,
10871087
accessToken: accessToken,

FirebaseAuth/Tests/Unit/UserTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,23 @@ class UserTests: RPCBaseTests {
15541554
}
15551555
#endif
15561556

1557+
func testRetrieveUserWithInvalidToken() async throws {
1558+
let auth = try XCTUnwrap(self.auth)
1559+
do {
1560+
_ = try await User.retrieveUser(
1561+
withAuth: auth,
1562+
accessToken: nil,
1563+
accessTokenExpirationDate: Date(),
1564+
refreshToken: nil,
1565+
anonymous: false
1566+
)
1567+
XCTFail("Expected an error to be thrown")
1568+
} catch let error as NSError {
1569+
XCTAssertEqual(error.domain, AuthErrors.domain)
1570+
XCTAssertEqual(error.code, AuthErrorCode.invalidUserToken.rawValue)
1571+
}
1572+
}
1573+
15571574
// MARK: Private helper functions
15581575

15591576
private func expectVerifyPhoneNumberRequest(isLink: Bool = false) {

FirebaseVertexAI/Tests/TestApp/Tests/Integration/CountTokensIntegrationTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,46 @@ struct CountTokensIntegrationTests {
121121
}
122122
)
123123
}
124+
125+
@Test(arguments: [
126+
InstanceConfig.vertexV1,
127+
InstanceConfig.vertexV1Staging,
128+
InstanceConfig.vertexV1Beta,
129+
InstanceConfig.vertexV1BetaStaging,
130+
/* System instructions are not supported on the v1 Developer API. */
131+
InstanceConfig.developerV1Beta,
132+
])
133+
func countTokens_jsonSchema(_ config: InstanceConfig) async throws {
134+
let model = VertexAI.componentInstance(config).generativeModel(
135+
modelName: ModelNames.gemini2Flash,
136+
generationConfig: GenerationConfig(
137+
responseMIMEType: "application/json",
138+
responseSchema: Schema.object(properties: [
139+
"startDate": .string(format: .custom("date-time")),
140+
"yearsSince": .integer(format: .custom("int32")),
141+
"hoursSince": .integer(format: .int32),
142+
"minutesSince": .integer(format: .int64),
143+
])
144+
),
145+
safetySettings: safetySettings
146+
)
147+
let prompt = "It is 2050-01-01, how many years, hours and minutes since 2000-01-01?"
148+
149+
let response = try await model.countTokens(prompt)
150+
151+
switch config.apiConfig.service {
152+
case .vertexAI:
153+
#expect(response.totalTokens == 65)
154+
#expect(response.totalBillableCharacters == 165)
155+
case .developer:
156+
// The Developer API erroneously ignores the `responseSchema` when counting tokens, resulting
157+
// in a lower total count than Vertex AI.
158+
#expect(response.totalTokens == 34)
159+
#expect(response.totalBillableCharacters == nil)
160+
}
161+
#expect(response.promptTokensDetails.count == 1)
162+
let promptTokensDetails = try #require(response.promptTokensDetails.first)
163+
#expect(promptTokensDetails.modality == .text)
164+
#expect(promptTokensDetails.tokenCount == response.totalTokens)
165+
}
124166
}

FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ struct GenerateContentIntegrationTests {
105105
#expect(text == "Blue")
106106

107107
let usageMetadata = try #require(response.usageMetadata)
108-
#expect(usageMetadata.promptTokenCount == 14)
108+
#expect(usageMetadata.promptTokenCount.isEqual(to: 15, accuracy: tokenCountAccuracy))
109109
#expect(usageMetadata.candidatesTokenCount.isEqual(to: 1, accuracy: tokenCountAccuracy))
110-
#expect(usageMetadata.totalTokenCount.isEqual(to: 15, accuracy: tokenCountAccuracy))
110+
#expect(usageMetadata.totalTokenCount
111+
== usageMetadata.promptTokenCount + usageMetadata.candidatesTokenCount)
111112
#expect(usageMetadata.promptTokensDetails.count == 1)
112113
let promptTokensDetails = try #require(usageMetadata.promptTokensDetails.first)
113114
#expect(promptTokensDetails.modality == .text)

FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -203,31 +203,6 @@ final class IntegrationTests: XCTestCase {
203203
XCTAssertEqual(promptTokensDetails.tokenCount, 24)
204204
}
205205

206-
func testCountTokens_jsonSchema() async throws {
207-
model = vertex.generativeModel(
208-
modelName: "gemini-2.0-flash",
209-
generationConfig: GenerationConfig(
210-
responseMIMEType: "application/json",
211-
responseSchema: Schema.object(properties: [
212-
"startDate": .string(format: .custom("date")),
213-
"yearsSince": .integer(format: .custom("int16")),
214-
"hoursSince": .integer(format: .int32),
215-
"minutesSince": .integer(format: .int64),
216-
])
217-
)
218-
)
219-
let prompt = "It is 2050-01-01, how many years, hours and minutes since 2000-01-01?"
220-
221-
let response = try await model.countTokens(prompt)
222-
223-
XCTAssertEqual(response.totalTokens, 58)
224-
XCTAssertEqual(response.totalBillableCharacters, 160)
225-
XCTAssertEqual(response.promptTokensDetails.count, 1)
226-
let promptTokensDetails = try XCTUnwrap(response.promptTokensDetails.first)
227-
XCTAssertEqual(promptTokensDetails.modality, .text)
228-
XCTAssertEqual(promptTokensDetails.tokenCount, 58)
229-
}
230-
231206
func testCountTokens_appCheckNotConfigured_shouldFail() async throws {
232207
let app = try XCTUnwrap(FirebaseApp.app(name: FirebaseAppNames.appCheckNotConfigured))
233208
let vertex = VertexAI.vertexAI(app: app)

FirebaseVertexAI/Tests/TestApp/Tests/Utilities/IntegrationTestUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ enum IntegrationTestUtils {
4040

4141
extension Numeric where Self: Strideable, Self.Stride.Magnitude: Comparable {
4242
func isEqual(to other: Self, accuracy: Self.Stride) -> Bool {
43-
return distance(to: other).magnitude < accuracy.magnitude
43+
return distance(to: other).magnitude <= accuracy.magnitude
4444
}
4545
}

0 commit comments

Comments
 (0)