test(auth): migrate AuthTests to Swift Testing + Replay (Phase 5)#1098
Open
grdsdev wants to merge 16 commits into
Open
test(auth): migrate AuthTests to Swift Testing + Replay (Phase 5)#1098grdsdev wants to merge 16 commits into
grdsdev wants to merge 16 commits into
Conversation
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
Linear: SDK-1252
Linear: SDK-1252
Linear: SDK-1252
Linear: SDK-1252
Linear: SDK-1252
Linear: SDK-1252
…king Linear: SDK-1252
Linear: SDK-1252
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
Linear: SDK-1252
Contributor
|
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
Coverage Report for CI Build 28984874484Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage decreased (-0.09%) to 83.136%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions25 previously-covered lines in 3 files lost coverage.
Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
mattt/Replaydependency, wires it intoAuthTests, addsAuthTeststoswift6TestTargets(full Swift 6 language mode, matching production targets'swiftSettings).Dependencies.mockchanged fromstatic vartostatic let— required for Sendable-safety under Swift 6 strict concurrency.XCTestCase→@Suite/@Test,XCTAssert*→#expect/#require), no Mocker involved:AuthClientMultipleInstancesTests,AuthErrorTests,AuthResponseTests,ExtractParamsTests,JWTCryptoTests,PKCETests,URLOpenerTests,SessionManagerTests,StoredSessionTests(the latter two use the in-houseHTTPClientMock, unrelated to Mocker).Mock()calls, 53 curl-snapshot assertions. Converted to Replay stubs with:.method, .path, .querymatching (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)..custommatcher that decodes both sides asAnyJSONfor 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).withMainSerialExecutorwrapping moved fromXCTestCase.invokeTestinto the@Testbodies that actually spawn concurrentauthStateChanges-drivenTasks.ReplayErroron a routing mismatch) is the request-shape enforcement now, replacing the dropped curl-snapshot assertions.@Suite(.serialized)—withMainSerialExecutormutates 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 inPostgrestBuilderTests(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.import XCTest/import Mockerremaining anywhere inTests/AuthTests.AuthClientTests.swift/AuthAdminOAuthTests.swiftagainst the original Mocker fixtures for parity (response fields, status codes, and JSON bodies checked against the original curl--datadumps).Linear
Closes SDK-1252