Verify Swift against the shared conformance fixtures

Merged
JE
4mo ago
+2243-11

Swift was the only SDK not fixture-verified; the #508/#509 retry-lifecycle bugs lived exactly where no runner watched. This adds the sixth conformance runner, executing every mock fixture in conformance/tests/ through the SDK's public Transport seam — no @testable anywhere.

Rebased over all six prerequisites (#563, #568, #571, #561, #560, #549). The gate is open and the temporary skips are gone.

Result — 136 passed / 0 failed / 1 skipped of 137

The one skip is architectural and shared with Kotlin and TypeScript: link-header-tagged cases assert a first-page-only requestCount, which does not apply to an SDK that auto-paginates by design. No capability skips. temporarySkips is empty.

Cross-runner, same fixture set (make conformance, REAL_EXIT_CONFORMANCE=0): Go 135/0/2, Kotlin 136/0/1, TypeScript 168 passed, Ruby 126/0/11, Python 137/0/0, Swift 136/0/1.

Acceptance evidence — SWIFT_CONFORMANCE_NO_SKIPS=1, live

The four named gates, by name, from SWIFT_CONFORMANCE_NO_SKIPS=1 swift run ConformanceRunner:

  PASS: DownloadURL retries on 503 at the auth'd first hop
  PASS: DownloadURL honors Retry-After on 429 at the auth'd first hop
  PASS: DownloadURL retries hop 1 on a network error
  PASS: DownloadURL does not retry hop 1 on 500

  PASS: GET operation retries on 503
  PASS: GET operation retries on 429 with Retry-After
  PASS: Retry-After HTTP-date format respected
  PASS: Network error on an idempotent POST is retried then succeeds
  PASS: Network error on a non-idempotent POST is not retried
  PASS: GET 500 is not retried
  PASS: POST operation does NOT retry (not idempotent)
  PASS: POST with 429 is not retried
  PASS: 403 Forbidden is not retried
  PASS: 422 on create is not retried
  PASS: ReorderUpNext POST does NOT retry (positional move)

=== Summary ===
Passed: 136, Failed: 0, Skipped: 1, Total: 137
REAL_EXIT=0

The two download-retry cases are the ones this branch previously skipped. They pass because #563 landed the hop-1 retry — deleted on evidence, not on faith. REAL_EXIT is grep-backed from the process, not read off a mid-run banner.

The runner's own false greens, fixed before it gates anything

A verification sweep found this branch reporting green on things it was not checking. A runner that does that is worse than no runner: it converts an untested SDK into a tested-looking one.

The delay contract now bites in six runners, not five. The delayBetweenRequests evaluator measured gap 0, ignored the assertion's index, and skipped the check entirely below two requests — the identical defect #568 had just fixed in the other five. Not hypothetical here: the two download fixtures this branch un-skips carry index: 0 and index: 1, so the second backoff was never measured. checkDelayGaps moves into an SDK-free ConformanceSupport target with #568's semantics and its committed test roster ported — omitted index checks every gap, zero gaps fails, out-of-range fails, negative is rejected, Int.max does not overflow.

Red proof. Swapping the shipped evaluator back in, 12 of the 13 delay-gap cases fail (14 assertion failures). The one that passes is a green case that should. The split into a library target exists because an executable carrying @main cannot host XCTest.

resolveRequestIndex moved alongside it, mainly to pin that it wraps on negatives while checkDelayGaps rejects them — they share the index fixture key and are easy to conflate. Those six cases pass against the pre-fix resolver; they are characterization, not regression, and the file says so.

Seventeen review findings, each a way a malformed fixture could have passed:

FindingFix
A case with no assertions verified nothing (assertions: [] is schema-legal)Fails loudly
Absent mockResponses decoded as an empty queuePresence preserved — empty is a declaration (the HTTPS case), absent is malformed
networkError: false + status slipped past the exactly-one-of backstopSchema pins the literal true; so does the runner
Path params coerced to 0/"", sending requests to the wrong resourceAll five accessors throw; the two timesheet == 0 sentinels became longParam(anyOf:)
configOverrides.maxItems silently ignored outside one dispatch armEnforced roster — a fixture that sets it elsewhere fails rather than paginating unbounded
headerInjected ignored its indexIndex-aware, matching the schema and the other runners
errorType: "ambiguous" could never passAdded to the vocabulary
Explicit expected: null always failedAssertion decodes presence; compareValue handles .null
HTTPS probe routed only http:// to the crash childEvery non-HTTPS scheme routes to the probe — an ftp:// fixture would have killed the run mid-suite
SWIFT_CONFORMANCE_NO_SKIPS triggered on presenceCompares to "1"
requestCount was a lower bound on auto-paginating fixturesExact — see below
The implicit invariant checked the request's method but not its pathExact path invariant — see below
The invariants stood down for any assertion of their type, whatever request it namedExemption requires one naming that exact request
The path invariant checked only the first hopEvery hop — see below
The path match accepted an unscoped requestThe fixture decides which form is required
Captured paths dropped the query, so refetching page 1 looked like following the linkRequests carry their query; rel="next" pins the following URL
An operation short-circuited before the transport skipped every invariant at onceA queued fixture that made no request fails
The method invariant still stopped at the first hopEvery hop, matching the path rule

One was not a runner bug at all. The single-key array unwrap that lets list fixtures decode also rewrote {"payload_url": ["is not a valid URL"]} into a bare array, so the SDK found no field errors and reported "bad request". That surfaced as a false FAIL, but the same heuristic could as easily manufacture a pass. Kotlin took the success-only status guard in #549; this port predated it and now carries it too.

And one more, found by Codex after undrafting. requestCount checked only a lower bound on fixtures carrying a Link rel="next" header. That is backwards for the fixtures it covered: three of them queue MORE pages than they expect requests, because stopping early is the behavior under test.

FixtureQueued pagesExpected requests
Pagination stops at maxPages safety cap32
maxItems caps results across pages32
Auto-pagination follows Link headers across multiple pages33

An SDK that ignored maxPages and walked all three satisfied 3 >= 2, so the cap assertions were unfailable in the only direction they exist to test. The third is the exposed case — requestCount and noError are its only assertions, so an over-fetch had nothing else to catch it.

Proven both ways against a simulated regression that drops the cap: with the exact comparison the count assertion itself fails (Expected 2 requests, got 3); with the lower bound it stays silent and only the unrelated meta.truncated assertion fires. The suite is unchanged at 136/0/1 — Swift already made exactly the expected number of requests everywhere, so the relaxation was pure false-green surface. The one fixture where a count genuinely does not apply to an auto-paginating SDK is excluded by its link-header tag before reaching the evaluator, so it was protecting nothing still running.

The transport keeps its auto-pagination tolerance on purpose: answering an over-walk with a terminal empty page rather than a 500 is what lets the tightened assertion report a clean count mismatch instead of a decode error. Kotlin's evaluator has the identical shape — filed as #573 rather than widening this PR.

And the one that mattered most, also Codex. The runner checked the first request's METHOD against the fixture but never its PATH, and the transport answers any URL — so an operation aimed at the wrong endpoint consumed the queued responses and passed anyway. Its retry, status, error-mapping, auth-header and pagination assertions all hold just as well against a resource the fixture never named. Both invariants exist for the same reason and only one was there.

The first request must now match the fixture's declared path with pathParams substituted, unless the fixture carries an explicit requestPath assertion. Exact, against both the account-scoped form the SDK builds and the absolute form the download fixtures state — deliberately not a suffix test, since /999/my/projects.json ends with /projects.json and both endpoints exist.

Red proof: pointing GetProject at a hardcoded id makes 20 previously-passing fixtures fail, each naming the endpoint it expected and the one it got. Every one had been verifying error mapping or retry behavior against the wrong project.

  FAIL: 403 maps to forbidden error code
        Expected first request path /999/projects/12345, got /999/projects/424242
  FAIL: X-Request-Id header extracted into error
        Expected first request path /999/projects/99999, got /999/projects/424242
  FAIL: Large integer IDs preserved without precision loss
        Expected first request path /999/projects/9007199254740993, got /999/projects/424242
  ... 17 more

Passed: 116, Failed: 20, Skipped: 1

Unchanged at 136/0/1 on the real code: all 135 fixtures that reach the check already went where they said they would.

Codex then found the follow-on in the same round: both implicit invariants stood down whenever the fixture carried any assertion of that type, regardless of which request it named. One fixture has exactly that shape — edit-clear pins requestPath at index 1, the composite's PUT, and nothing at index 0 — so a read-modify-write composite's leading GET was unchecked. The exemption now requires an assertion that resolves to request 0.

Isolated by diverging the composite's GET alone (the SDK's edit reads todo 777777, writes todo 456):

coarse exemption:   PASS: edit-clear ...
narrowed exemption: FAIL: edit-clear ...
                    Expected first request path /999/todos/456, got /999/todos/777777

Recorded because it nearly fooled me: my first attempt at that proof changed the todoId the runner passes, which moves both hops — the run went red under either carve-out, looking like a proof while demonstrating nothing.

Then the mirror image, same class from the other end: the invariant checked captured.first and stopped, so a composite's second hop was unpinned. update-preserves-due-on GETs a card and PUTs it back; a PUT that regressed while the GET stayed correct kept method, body, count and noError all green.

Rather than pin that one fixture, I measured whether the rule generalizes. Probing every hop across the suite, exactly five diverge, and all five are the download redirect and delegation flows (a 302 to a signed URL; UploadsDownload following an upload's download_url). Retries, pagination and every composite already stay on the fixture's path.

So the rule is now every hop matches the fixture path unless an explicit requestPath assertion names that index — and those five fixtures carry their own indexed assertions rather than the runner encoding a carve-out, since a carve-out is precisely what produced the previous round's bug. Those fixture assertions are the better half: they are shared, so all six runners now pin the redirect target instead of only counting hops.

Red proof, diverging the card composite's PUT alone:

  FAIL: update-preserves-due-on: composite refetches and resends the due date
        Expected request 1 at path /999/card_tables/cards/1069479350, got /999/card_tables/cards/888888

The last two, and the deepest. The path match accepted either the account-scoped form or the bare fixture path, so an SDK that dropped the account prefix and asked for /projects.json satisfied a fixture meaning /999/projects.json. Which form is required is now decided by the fixture, not by whichever the SDK sent.

And request.url?.path discards the query — so refetching page 1 and following the link to page 2 were the same string to the runner, and the transport served page 2's body anyway. Three requests, three pages, green, while production would have looped. Requests now carry their query, and a response advertising rel="next" pins the request that follows it to exactly that URL.

Tightening the first exposed why the second is the right shape: with scoping enforced, five pagination fixtures failed, because their Link headers are root-relative and the SDK correctly follows them unscoped. The hop was being judged by two rules that disagreed. A link-following hop is now governed by the link rule alone — the most specific available, and the stronger, since it pins the query too.

Red proof, dropping the query inside the SDK's own parseNextLink:

with the link invariant:      FAIL x5   Passed: 131, Failed: 5
  Response 0 advertised rel="next" /projects.json?page=2,
  so request 1 must fetch /projects.json?page=2, got /projects.json

without it, same regression:  PASS x5   Passed: 136, Failed: 0

And the last. Every invariant above is guarded on having captured a request, so an operation that short-circuits before the transport skips all of them at once. HTTP allowed for localhost asserts only noError, so nothing was left holding it. A fixture that queues responses is testing a wire operation, so one must have happened — while an empty queue stays the deliberate no-request case (the HTTPS fixture, the only one, which declares requestCount: 0).

with the guard:     FAIL: HTTP allowed for localhost
                    fixture queues 1 mock response(s) but the operation made no request
without it:         PASS   Passed: 136, Failed: 0

Finally the symmetry: the path invariant covered every hop while the method invariant still stopped at the first, so a download could POST its signed final hop and satisfy path, authorization, count and noError. Both cover every request now — measured first, and no hop in the suite diverges.

every hop:   FAIL x5   Expected request 1 to use method GET, got POST
first only:  PASS x5   Passed: 136, Failed: 0

Design

  • Dedicated package conformance/runner/swift/, port model = Kotlin Main.kt: Codable fixture models, per-test scripted response queue, full assertion evaluator, 57-operation dispatch table.
  • Path-dependency wrinkle: the package depends on the ROOT distribution manifest, not swift/Package.swift — SwiftPM derives package identity from the directory name, so a path dependency on .../swift collides with conformance/runner/swift's own identity and is silently treated as a self-reference. Documented in the manifest.
  • #555 policy from day one: a mock body that flunks required-field decoding is a FAIL (fixture bug to fix), not a skip.
  • HTTPS enforcement is a preconditionFailure — a trap, not a thrown error — so the runner re-executes itself as a --https-probe child and requires it to die. A surviving child is a FAIL, never a silent pass.

CI fan-in

Verified against .github/workflows/test.yml as it stands post-rebase, not assumed:

  • test-swift runs on macos-15, so the Makefile's IS_MACOS gate is satisfied rather than silently printing SKIP.
  • It runs make conformance-swift-runner-tests and make conformance-swift.
  • test-swift is in the required Conformance Tests job's needs: [test-go, test-typescript, test-ruby, test-kotlin, test-python, test-swift].
  • That job runs if: always() and fails when any need's result is not success, so a Swift conformance failure fails the required check instead of leaving it green.

make conformance-runner-tests also reaches the Swift unit tests through the platform-gated sub-make, so the cross-language aggregate stays complete.

SPEC

  • §18 composite rule: the "native test mirrors where a runner does not exist yet, e.g. Swift" carve-out is retired — all six SDKs have a runner.
  • §21 gate table: swift added to the conformance runner roster.
  • §19 skip roster: a Swift section with the one architectural link-header line, and an explicit note that Swift carries no capability skips.
  • network-retry.json's "passes in all five runners" is now six.