Skip to content

test(auth): migrate AuthTests to Swift Testing + Replay (Phase 5)#1098

Open
grdsdev wants to merge 16 commits into
mainfrom
test/sdk-1252-swift-testing-migration-phase-5-authtests
Open

test(auth): migrate AuthTests to Swift Testing + Replay (Phase 5)#1098
grdsdev wants to merge 16 commits into
mainfrom
test/sdk-1252-swift-testing-migration-phase-5-authtests

Conversation

@grdsdev

@grdsdev grdsdev commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Completes SDK-1252 (Phase 5 of the Swift Testing migration, SDK-435). Converts all of Tests/AuthTests (13 files, the largest target and heaviest Mocker user in the repo) from XCTest + Mocker to Swift Testing + Replay, per the Phase 0 decision (SDK-1247) and the conversion patterns already landed in PR #1095 (PostgRESTTests) and PR #1096 (StorageTests).

Changes

  • Package.swift: adds the mattt/Replay dependency, wires it into AuthTests, adds AuthTests to swift6TestTargets (full Swift 6 language mode, matching production targets' swiftSettings).
  • MockHelpers.swift: Dependencies.mock changed from static var to static let — required for Sendable-safety under Swift 6 strict concurrency.
  • 9 mechanical conversions (XCTestCase@Suite/@Test, XCTAssert*#expect/#require), no Mocker involved: AuthClientMultipleInstancesTests, AuthErrorTests, AuthResponseTests, ExtractParamsTests, JWTCryptoTests, PKCETests, URLOpenerTests, SessionManagerTests, StoredSessionTests (the latter two use the in-house HTTPClientMock, unrelated to Mocker).
  • AuthAdminOAuthTests.swift: Mocker → Replay conversion (6 stubs). Curl-snapshot assertions dropped per the Phase 0 "no shim" decision.
  • AuthClientTests.swift: the big one — 87 tests, 81 Mocker Mock() calls, 53 curl-snapshot assertions. Converted to Replay stubs with:
    • Query-string verification preserved via .method, .path, .query matching (not path-only — path-only matching would have silently dropped query-string regression coverage, the gap PR test(postgrest): migrate PostgRESTTests to Swift Testing + Replay (Phase 4) #1095's follow-up commit found and fixed for PostgRESTTests).
    • Request-body verification via a custom .custom matcher that decodes both sides as AnyJSON for structural comparison (key order/whitespace insensitive) — important here since most Mocker bodies in this file carry auth-relevant payloads (passwords, PKCE code verifiers, MFA/passkey credentials, OAuth tokens).
    • withMainSerialExecutor wrapping moved from XCTestCase.invokeTest into the @Test bodies that actually spawn concurrent authStateChanges-driven Tasks.
  • RequestsTests.swift: converts the last remaining file. These tests only verify request routing (method+path) rather than response handling; Replay's stub-matching failure (a thrown ReplayError on a routing mismatch) is the request-shape enforcement now, replacing the dropped curl-snapshot assertions.
  • AuthClientTests / SessionManagerTests: marked @Suite(.serialized)withMainSerialExecutor mutates a process-global flag (ConcurrencyExtras.uncheckedUseMainSerialExecutor), and Swift Testing runs same-suite tests concurrently by default, so two tests racing to flip that global would interfere with each other. Mirrors the _clock-swap precedent in PostgrestBuilderTests (PR test(postgrest): migrate PostgRESTTests to Swift Testing + Replay (Phase 4) #1095).

Test plan

  • swift build --target AuthTests — 0 errors, full Swift 6 language mode.
  • swift test --filter AuthTests — 206/206 tests passing.
  • Zero import XCTest / import Mocker remaining anywhere in Tests/AuthTests.
  • Manual review of the Replay stub bodies in AuthClientTests.swift/AuthAdminOAuthTests.swift against the original Mocker fixtures for parity (response fields, status codes, and JSON bodies checked against the original curl --data dumps).

Linear

Closes SDK-1252

grdsdev added 14 commits July 8, 2026 19:05
Adds Replay (mattt/Replay) as a package dependency and wires it into
AuthTests, mirroring the Phase 4 (PostgRESTTests) pattern. Enables full
Swift 6 language mode for AuthTests per the SDK-1252 migration.

Linear: SDK-1252
Converts Mocker + curl-snapshot assertions to Replay stubs per the
Phase 0 decision (SDK-1247) and the Phase 4 conversion pattern
(PostgRESTTests, PR #1095).

Linear: SDK-1252
@github-actions github-actions Bot added the auth label Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Potential Breaking API Changes Detected

This PR appears to contain breaking API changes. Please review the changes below:

API Check Output
  💔 API breakage: struct File has been removed
  💔 API breakage: class FormData has been removed
  💔 API breakage: class StorageApi has been removed
  💔 API breakage: class StorageBucketApi has been removed
  💔 API breakage: struct StorageError has been removed
  💔 API breakage: class StorageFileApi has been removed
  💔 API breakage: struct StorageHTTPSession has been removed
  💔 API breakage: struct StorageClientConfiguration has been removed
  💔 API breakage: class SupabaseStorageClient has been removed
  💔 API breakage: struct SearchOptions has been removed
  💔 API breakage: struct SortBy has been removed
  💔 API breakage: struct FileOptions has been removed
  💔 API breakage: struct SignedURL has been removed
  💔 API breakage: enum SignedURLResult has been removed
  💔 API breakage: struct SignedUploadURL has been removed
  💔 API breakage: struct FileUploadResponse has been removed
  💔 API breakage: struct SignedURLUploadResponse has been removed
  💔 API breakage: struct CreateSignedUploadURLOptions has been removed
  💔 API breakage: struct DestinationOptions has been removed
  💔 API breakage: struct FileObject has been removed
  💔 API breakage: struct FileObjectV2 has been removed
  💔 API breakage: struct Bucket has been removed
  💔 API breakage: struct StorageByteCount has been removed
  💔 API breakage: struct ResizeMode has been removed
  💔 API breakage: struct ImageFormat has been removed
  💔 API breakage: struct SortOrder has been removed
  💔 API breakage: enum DownloadBehavior has been removed
  💔 API breakage: struct BucketOptions has been removed
  💔 API breakage: struct TransformOptions has been removed
  💔 API breakage: var JSONEncoder.defaultStorageEncoder has been removed
  💔 API breakage: var JSONDecoder.defaultStorageDecoder has been removed
  💔 API breakage: struct AuthAdmin has been removed
  💔 API breakage: struct AuthAdminOAuth has been removed
  💔 API breakage: class AuthClient has been removed
  💔 API breakage: struct ErrorCode has been removed
  💔 API breakage: enum AuthError has been removed
  💔 API breakage: struct AuthMFA has been removed
  💔 API breakage: protocol AuthStateChangeListenerRegistration has been removed
  💔 API breakage: typealias AuthStateChangeListener has been removed
  💔 API breakage: typealias GoTrueClient has been removed
  💔 API breakage: typealias GoTrueMFA has been removed
  💔 API breakage: typealias GoTrueLocalStorage has been removed
  💔 API breakage: typealias GoTrueMetaSecurity has been removed
  💔 API breakage: typealias GoTrueError has been removed
  💔 API breakage: typealias MFAEnrollParams has been removed
  💔 API breakage: protocol AuthLocalStorage has been removed
  💔 API breakage: struct KeychainLocalStorage has been removed
  💔 API breakage: enum AuthChangeEvent has been removed
  💔 API breakage: struct UserCredentials has been removed
  💔 API breakage: struct Session has been removed
  💔 API breakage: struct User has been removed
  💔 API breakage: struct UserIdentity has been removed
  💔 API breakage: enum Provider has been removed
  💔 API breakage: struct OpenIDConnectCredentials has been removed
  💔 API breakage: struct AuthMetaSecurity has been removed
  💔 API breakage: enum MobileOTPType has been removed
  💔 API breakage: enum EmailOTPType has been removed
  💔 API breakage: enum AuthResponse has been removed
  💔 API breakage: struct UserAttributes has been removed
  💔 API breakage: struct AdminUserAttributes has been removed
  💔 API breakage: enum AuthFlowType has been removed
  💔 API breakage: typealias FactorType has been removed
  💔 API breakage: enum FactorStatus has been removed
  💔 API breakage: struct Factor has been removed
  💔 API breakage: protocol MFAEnrollParamsType has been removed
  💔 API breakage: struct MFATotpEnrollParams has been removed
  💔 API breakage: struct MFAPhoneEnrollParams has been removed
  💔 API breakage: struct AuthMFAEnrollResponse has been removed
  💔 API breakage: struct MFAChallengeParams has been removed
  💔 API breakage: struct MFAVerifyParams has been removed
  💔 API breakage: struct MFAUnenrollParams has been removed
  💔 API breakage: struct MFAChallengeAndVerifyParams has been removed
  💔 API breakage: struct AuthMFAChallengeResponse has been removed
  💔 API breakage: typealias AuthMFAVerifyResponse has been removed
  💔 API breakage: struct AuthMFAUnenrollResponse has been removed
  💔 API breakage: struct AuthMFAListFactorsResponse has been removed
  💔 API breakage: typealias AuthenticatorAssuranceLevels has been removed
  💔 API breakage: struct AMREntry has been removed
  💔 API breakage: struct AuthMFAGetAuthenticatorAssuranceLevelResponse has been removed
  💔 API breakage: enum SignOutScope has been removed
  💔 API breakage: enum ResendEmailType has been removed
  💔 API breakage: enum ResendMobileType has been removed
  💔 API breakage: struct ResendMobileResponse has been removed
  💔 API breakage: struct WeakPassword has been removed
  💔 API breakage: enum MessagingChannel has been removed
  💔 API breakage: struct SSOResponse has been removed
  💔 API breakage: struct OAuthResponse has been removed
  💔 API breakage: struct PageParams has been removed
  💔 API breakage: struct ListUsersPaginatedResponse has been removed
  💔 API breakage: struct OAuthClientGrantType has been removed
  💔 API breakage: struct OAuthClientResponseType has been removed
  💔 API breakage: struct OAuthClientType has been removed
  💔 API breakage: struct OAuthClientRegistrationType has been removed
  💔 API breakage: struct OAuthClient has been removed
  💔 API breakage: struct CreateOAuthClientParams has been removed
  💔 API breakage: struct UpdateOAuthClientParams has been removed
  💔 API breakage: struct ListOAuthClientsPaginatedResponse has been removed
  💔 API breakage: struct JWK has been removed
  💔 API breakage: struct JWKS has been removed
  💔 API breakage: struct JWTHeader has been removed
  💔 API breakage: struct JWTClaims has been removed
  💔 API breakage: enum AudienceClaim has been removed
  💔 API breakage: struct JWTClaimsResponse has been removed
  💔 API breakage: struct GetClaimsOptions has been removed
  💔 API breakage: struct MFAWebAuthnEnrollParams has been removed
  💔 API breakage: struct WebAuthnChallengeOptions has been removed
  💔 API breakage: enum WebAuthnChallengeType has been removed
  💔 API breakage: struct WebAuthnChallengeResponseData has been removed
  💔 API breakage: struct PasskeyListItem has been removed
  💔 API breakage: struct PasskeyRegistrationOptions has been removed
  💔 API breakage: struct PasskeyAuthenticationOptions has been removed
  💔 API breakage: var JSONEncoder.goTrue has been removed
  💔 API breakage: var JSONDecoder.goTrue has been removed
  💔 API breakage: class SupabaseClient has been removed
  💔 API breakage: struct SupabaseClientOptions has been removed
  💔 API breakage: class FunctionsClient has been removed
  💔 API breakage: enum FunctionsError has been removed
  💔 API breakage: struct FunctionInvokeOptions has been removed
  💔 API breakage: enum FunctionRegion has been removed
  💔 API breakage: typealias URLQueryRepresentable has been removed
  💔 API breakage: class PostgrestBuilder has been removed
  💔 API breakage: class PostgrestClient has been removed
  💔 API breakage: class PostgrestFilterBuilder has been removed
  💔 API breakage: protocol PostgrestFilterValue has been removed
  💔 API breakage: class PostgrestQueryBuilder has been removed
  💔 API breakage: class PostgrestTransformBuilder has been removed
  💔 API breakage: struct PostgrestResponse has been removed
  💔 API breakage: enum CountOption has been removed
  💔 API breakage: enum PostgrestReturningOptions has been removed
  💔 API breakage: enum TextSearchType has been removed
  💔 API breakage: struct ExplainFormat has been removed
  💔 API breakage: struct FetchOptions has been removed
  💔 API breakage: var String.rawValue has been removed
  💔 API breakage: var Int.rawValue has been removed
  💔 API breakage: var Double.rawValue has been removed
  💔 API breakage: var Bool.rawValue has been removed
  💔 API breakage: var UUID.rawValue has been removed
  💔 API breakage: var Date.rawValue has been removed
  💔 API breakage: var Array.rawValue has been removed
  💔 API breakage: var AnyJSON.rawValue has been removed
  💔 API breakage: var Optional.rawValue has been removed
  💔 API breakage: var Dictionary.rawValue has been removed
  💔 API breakage: enum Defaults has been removed
  💔 API breakage: enum ChannelState has been removed
  💔 API breakage: struct Delegated has been removed
  💔 API breakage: typealias Message has been removed
  💔 API breakage: protocol PhoenixTransport has been removed
  💔 API breakage: protocol PhoenixTransportDelegate has been removed
  💔 API breakage: enum PhoenixTransportReadyState has been removed
  💔 API breakage: class URLSessionTransport has been removed
  💔 API breakage: class Presence has been removed
  💔 API breakage: class Push has been removed
  💔 API breakage: struct ChannelFilter has been removed
  💔 API breakage: enum ChannelResponse has been removed
  💔 API breakage: enum RealtimeListenTypes has been removed
  💔 API breakage: struct RealtimeChannelOptions has been removed
  💔 API breakage: enum RealtimeSubscribeStates has been removed
  💔 API breakage: class RealtimeChannel has been removed
  💔 API breakage: enum SocketError has been removed
  💔 API breakage: typealias Payload has been removed
  💔 API breakage: typealias PayloadClosure has been removed
  💔 API breakage: class RealtimeClient has been removed
  💔 API breakage: struct RealtimeMessage has been removed
  💔 API breakage: var RealtimeClientV2.subscriptions has been removed
  💔 API breakage: struct RealtimeClientV2.Configuration has been removed
  💔 API breakage: typealias RealtimeClientV2.Status has been removed
  💔 API breakage: constructor RealtimeClientV2.init(config:) has been removed
  💔 API breakage: typealias RealtimeChannelV2.Subscription has been removed
  💔 API breakage: typealias RealtimeChannelV2.Status has been removed

If this is intentional, please update your PR title or commit message to include:

  • ! after the type (e.g., feat!: remove deprecated method)
  • Or include BREAKING CHANGE: in the commit body

If this is a false positive, you can safely ignore this warning.

grdsdev added 2 commits July 8, 2026 21:07
Converts the largest AuthTests file (87 tests, 81 Mocker Mock() calls,
53 curl-snapshot assertions) to Swift Testing + Replay, per the Phase 0
decision (SDK-1247) and the Phase 4/Phase 3 conversion patterns
(PostgRESTTests PR #1095, StorageTests PR #1096).

- Curl-snapshot request-shape assertions dropped per the Phase 0 "no
  shim" decision, replaced by Replay's matcher-based enforcement.
- Query strings preserved via exact-URL matching (.method, .url) rather
  than path-only matching, so query-string regressions are still
  caught (the gap PR #1095's follow-up commit found and fixed).
- Request bodies verified via a custom .custom matcher that decodes
  both sides as AnyJSON for structural comparison (key order/whitespace
  insensitive), following the pattern from StorageTests PR #1096's
  jsonBody(of:) helper -- important here since most of this file's
  Mocker bodies carry auth-relevant payloads (passwords, tokens, PKCE
  code verifiers, MFA/passkey credentials).
- withMainSerialExecutor wrapping moved from XCTestCase.invokeTest into
  the handful of @test bodies that actually spawn concurrent
  authStateChanges-driven Tasks.
- HTTPResponse.stub(...) helper (used cross-file by SessionManagerTests)
  preserved at the bottom of the file.

Linear: SDK-1252
… bugs

- RequestsTests.swift: converts the last remaining XCTest/Mocker file.
  These tests only verify request routing (method+path); response
  bodies are minimal but decodable fixtures where AuthClient actually
  decodes a response (Session/User), reusing AuthClientTests' MockData.
- Fixes two real bugs surfaced by actually running the suite (not just
  compiling): AuthClientTests/SessionManagerTests used
  `.method, .url` exact-URL matching, which broke on percent-encoding
  differences between how the stub URL string parses vs. how the live
  request is constructed (e.g. `:`/`/` in a redirect_to query value).
  Switched to `.method, .path, .query` throughout, matching the
  Matcher type's own documented guidance to prefer composed matchers
  over whole-URL comparison.
- SessionManagerTests/AuthClientTests: withMainSerialExecutor mutates
  a process-global flag; Swift Testing runs same-suite tests
  concurrently by default, so mark both suites .serialized to avoid
  cross-test interference, mirroring the _clock precedent in
  PostgrestBuilderTests (PR #1095).
- setSessionWithAFutureExpirationDate/updateUser: fixed stubs that
  decoded the wrong response type (Session vs User) — caught by
  running tests, not visible from a clean compile.

swift build --target AuthTests: 0 errors.
swift test --filter AuthTests: 206/206 passed.

Linear: SDK-1252
@grdsdev grdsdev marked this pull request as ready for review July 9, 2026 00:18
@grdsdev grdsdev requested a review from a team as a code owner July 9, 2026 00:18
@grdsdev grdsdev changed the title test(auth): migrate AuthTests to Swift Testing + Replay (Phase 5, partial) test(auth): migrate AuthTests to Swift Testing + Replay (Phase 5) Jul 9, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 28984874484

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.09%) to 83.136%

Details

  • Coverage decreased (-0.09%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 25 coverage regressions across 3 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

25 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
Sources/Auth/Internal/Keychain.swift 21 25.55%
Sources/Helpers/FoundationExtensions.swift 3 90.74%
Sources/Helpers/HTTP/RetryRequestInterceptor.swift 1 94.64%

Coverage Stats

Coverage Status
Relevant Lines: 9470
Covered Lines: 7873
Line Coverage: 83.14%
Coverage Strength: 1360641.08 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants