forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIBackendErrorNormalizationTests.swift
More file actions
65 lines (52 loc) · 2.38 KB
/
Copy pathAIBackendErrorNormalizationTests.swift
File metadata and controls
65 lines (52 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import XCTest
@testable import Omi_Computer
final class AIBackendErrorNormalizationTests: XCTestCase {
func testEmbeddingTrialExpiredIsProductGateAndNotSentryActionable() {
let error = EmbeddingService.EmbeddingError.serverError(
statusCode: 402,
body: #"{"error":"trial_expired"}"#)
XCTAssertEqual(error.reasonCode, "product_gate")
XCTAssertTrue(error.isExpectedProductState)
XCTAssertTrue(error.isNonActionableForSentry)
XCTAssertEqual(
error.localizedDescription,
"Embedding API unavailable: active plan or BYOK keys required.")
}
func testEmbeddingRateLimitAndUnavailableAreTransient() {
let rateLimited = EmbeddingService.EmbeddingError.serverError(
statusCode: 429,
body: #"{"error":"rate limit exceeded"}"#)
let unavailable = EmbeddingService.EmbeddingError.serverError(
statusCode: 503,
body: #"{"error":"service unavailable"}"#)
XCTAssertEqual(rateLimited.reasonCode, "rate_limited")
XCTAssertTrue(rateLimited.isTransient)
XCTAssertTrue(rateLimited.isNonActionableForSentry)
XCTAssertEqual(unavailable.reasonCode, "temporarily_unavailable")
XCTAssertTrue(unavailable.isTransient)
XCTAssertTrue(unavailable.isNonActionableForSentry)
}
func testEmbeddingMalformedResponseRemainsActionable() {
let error = EmbeddingService.EmbeddingError.invalidResponse
XCTAssertEqual(error.reasonCode, "malformed_response")
XCTAssertFalse(error.isNonActionableForSentry)
}
func testEmbeddingMissingConfigurationRemainsActionable() {
let error = EmbeddingService.EmbeddingError.missingAPIKey
XCTAssertEqual(error.reasonCode, "missing_api_key")
XCTAssertFalse(error.isExpectedProductState)
XCTAssertFalse(error.isNonActionableForSentry)
}
func testGeminiTrialExpiredIsExpectedProductState() {
let error = GeminiClient.GeminiClientError.apiError("HTTP 402: trial_expired")
XCTAssertTrue(error.isExpectedProductState)
XCTAssertFalse(error.isTransient)
XCTAssertEqual(error.localizedDescription, "AI features require an active plan or BYOK keys.")
}
func testGeminiQuotaExceededUsesProductGateMessage() {
let error = GeminiClient.GeminiClientError.apiError("quota exceeded")
XCTAssertTrue(error.isExpectedProductState)
XCTAssertFalse(error.isTransient)
XCTAssertEqual(error.localizedDescription, "AI features require an active plan or BYOK keys.")
}
}