test(postgrest): migrate PostgRESTTests to Swift Testing + Replay (Phase 4)#1095
Open
grdsdev wants to merge 2 commits into
Open
test(postgrest): migrate PostgRESTTests to Swift Testing + Replay (Phase 4)#1095grdsdev wants to merge 2 commits into
grdsdev wants to merge 2 commits into
Conversation
…ase 4) Converts all 10 files in Tests/PostgRESTTests from XCTest+Mocker to Swift Testing (#expect/#require/@Test/@suite) and Replay for HTTP mocking, per the Phase 0 decision (SDK-1247). Drops Mocker's `.snapshotRequest` curl assertions entirely, replacing them with Replay stubs matched on method+path (mirroring the original `ignoreQuery: true` semantics). BuildURLRequestTests keeps its `assertSnapshot(as: .curl)` request-shape snapshots unchanged, but switches its `#file` default to `#filePath` since Swift Testing resolves `#file` to a module-relative path (breaking snapshot directory resolution under both `swift test` and `xcodebuild`). PostgrestQueryTests.swift (an XCTestCase base class shared via inheritance) is replaced by a composed `PostgrestQueryFixture` struct, since Swift Testing suites don't support shared state through subclassing; the file is renamed to PostgrestQueryFixture.swift to reflect its new contents. PostgrestBuilderTests keeps `@Suite(.serialized)` and is now a class (not a struct) so `deinit` can restore the process-global `_clock` seam after its retry tests run, matching the old `tearDown()` — a struct has no equivalent hook, so the initial conversion silently dropped the clock reset. PostgRESTTests moves off the blanket `.swiftLanguageMode(.v5)` pin onto full Swift 6 language mode, matching production targets' swiftSettings. Adds `Replay` as a new package dependency. Verified via both `swift test` and `xcodebuild test` (97/97 tests, 9 suites, both hosts). Linear: SDK-1251
Contributor
|
Coverage Report for CI Build 28980249909Coverage remained the same at 83.221%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
…ration Path-only stub matching (matching: [.method, .path]) silently dropped all query-string and request-body verification that the old Mocker-based tests enforced via .snapshotRequest curl assertions. Every filter/transform/rpc/ query builder test would have passed even if the underlying query-string or body construction regressed. Switch to Replay's default exact-URL matcher (byte-identical query string) for deterministic cases, .query (order-insensitive) for the two RPC tests with non-deterministic dictionary-iteration-ordered params, and a custom .custom body matcher (reading httpBodyStream, since URLSession moves the body out of httpBody in flight) for insert/update/upsert body assertions. Query strings were re-derived from actual runtime request output, not copied from the stale pre-migration snapshot text, since Mocker's curl pretty-printer didn't reflect real percent-encoding/param order.
4 tasks
grdsdev
added a commit
that referenced
this pull request
Jul 9, 2026
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
grdsdev
added a commit
that referenced
this pull request
Jul 9, 2026
… 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
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
Converts all 10 files in
Tests/PostgRESTTests(2,948 lines) from XCTest+Mocker to Swift Testing (#expect/#require/@Test/@Suite) and Replay for HTTP mocking, per the Phase 0 decision (SDK-1247). This is Phase 4 of the migration tracked in SDK-435.Changes
import XCTest, zeroimport Mockerremain in the target..snapshotRequest { curl ... }assertions (66 occurrences) are dropped entirely — no shim — replaced with Replay.replay(stubs: [...], matching: [.method, .path], scope: .test), mirroring the original mocks'ignoreQuery: truesemantics.BuildURLRequestTestskeeps itsassertSnapshot(as: .curl)request-shape snapshots (32 files in__Snapshots__/) unchanged in intent, but switches the#filedefault to#filePath— Swift Testing resolves#fileto a module-relative path, which broke snapshot directory resolution under bothswift testandxcodebuild(writing to<repo-root>/PostgRESTTests/__Snapshots__instead ofTests/PostgRESTTests/__Snapshots__).PostgresQueryTests.swift, anXCTestCasebase class shared via inheritance by 5 other test classes, is replaced by a composedPostgrestQueryFixturestruct (Swift Testing suites don't support shared state through subclassing) and renamed toPostgrestQueryFixture.swiftto reflect its new contents.PostgrestBuilderTestsis afinal class(not a struct) with@Suite(.serialized), sodeinitcan restore the process-global_clocktest seam (Sources/Helpers/_Clock.swift) after its retry tests run — matching the oldtearDown(). A struct has no equivalent teardown hook, so an early version of this migration silently dropped the clock reset; caught in review.PostgRESTTestsmoves off the blanket.swiftLanguageMode(.v5)pin onto full Swift 6 language mode, matching production targets'swiftSettings.Replay(from: "0.4.0") as a new package dependency; dropsMocker/InlineSnapshotTestingfromPostgRESTTests' target dependencies.Test plan
swift test --filter PostgRESTTests: 97/97 tests, 9 suites, green.PLATFORM=MACOS XCODEBUILD_ARGUMENT=test SCHEME=PostgREST ./scripts/xcodebuild.sh: Test Succeeded, 97/97.swift testrun: no regressions in other targets (pre-existingIntegrationTestsfailures require a live local Supabase instance, unrelated to this change)../scripts/spell-check.sh: clean../scripts/format.shscoped to changed files.Linear
Closes SDK-1251