Files
Andrew Heard ead1af3543 refactor(ai): revert renaming to Gemini Enterprise API (#16846)
Revert commit dd2cfa8df1 (#16685) to undo
the renaming from Gemini Enterprise Agent Platform to Gemini Enterprise
API.

- Restore Backend.agentPlatform(location:) as the primary public API
  and remove Backend.enterprise(location:).
- Revert APIConfig.Service.enterprise to .agentPlatform and restore
  agentPlatformStagingBypassProxy.
- Revert documentation comments, DocC topics, and guides back to
  Agent Platform Gemini API and Gemini Enterprise Agent Platform.
- Clean up leftover Vertex AI symbols to align with Agent Platform and
  FirebaseAILogic (isFirebaseAILogicServiceDisabledError and
  defaultAgentPlatformAPIConfig).
- Re-align tests and conflict resolutions from #16689, #16693, #16676,
  and #16756.
2026-10-05 23:54:12 +00:00
..

GeminiTestUtilities

Shared testing infrastructure, network mocking utilities, environment condition traits, and integration test backends for GeminiLanguageModel and GeminiAPIClient.

Overview

GeminiTestUtilities is an internal test support target consumed across all test suites in the package. It provides centralized utilities so tests avoid duplicating mock handlers, endpoint URLs, credential checks, or port probes.

Component Breakdown

Category Files Purpose
Network Mocking MockHTTPURLProtocol.swift, HTTPURLResponse+Mock.swift Offline URLSession request interception, response mocking, and SSE streaming simulation
Integration Backends IntegrationTestingBackend.swift, AppCheckDebugClient.swift Backend routing configurations, TCP socket probing, App Check debug token exchange and caching
Testing Traits & Tags ConditionTrait+Credentials.swift, ConditionTrait+FoundationModels.swift, Tag+Integration.swift Swift Testing conditional skip traits (.requireAPIKey, .requireFoundationModels) and .integration tag
Constants TestConstants.swift Centralized model resource IDs and canonical endpoint configurations

Common Recipes

1. Mocking HTTP URL Responses

Use MockHTTPURLProtocol and HTTPURLResponse.mock to simulate API responses without network access:

defer { MockHTTPURLProtocol.reset() }
let expectedURL = URL(string: "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash-lite:generateContent")!
let response = try HTTPURLResponse.mock(url: expectedURL, statusCode: 200)

MockHTTPURLProtocol.setHandler(for: expectedURL) { request, proto in
  proto.client?.urlProtocol(proto, didReceive: response, cacheStoragePolicy: .notAllowed)
  proto.client?.urlProtocol(proto, didLoad: Data("{}".utf8))
  proto.client?.urlProtocolDidFinishLoading(proto)
}

2. Guarding Tests with Condition Traits

Swift Testing condition traits allow tests to cleanly skip when prerequisites (like API keys or specific OS versions) are absent:

// Skip if neither local test-server nor remote credentials are available
@Test(.requireIntegrationTestingBackend)
func myBackendTest() async throws { ... }

// Skip on platforms where FoundationModels is unavailable (< macOS 27)
@Suite("Model Tests", .requireFoundationModels)
struct ModelTests { ... }

3. App Check Token Caching

AppCheckTokenCache manages debug token exchange for Firebase AI Logic integration tests, caching active tokens in-memory and deduplicating in-flight network requests:

let token = try await AppCheckTokenCache.shared.token(
  projectID: projectID,
  appID: appID,
  apiKey: apiKey,
  debugToken: debugToken
)