Skip to content

test: drop tautological assertions, cover real OAuth + expiry invariants#4

Merged
atom2ueki merged 1 commit into
mainfrom
worktree-test-tdd-cleanup
May 1, 2026
Merged

test: drop tautological assertions, cover real OAuth + expiry invariants#4
atom2ueki merged 1 commit into
mainfrom
worktree-test-tdd-cleanup

Conversation

@atom2ueki

Copy link
Copy Markdown
Owner

Summary

Removed three tests that pass by luck of the universe (not by checking anything) and one that lied about what it tests, then added coverage for invariants that would actually break sign-in or sign users out if they regressed.

Removed

  • PKCETests.verifierAndChallengeAreDifferent / eachGenerationIsUnique — SHA-256 doesn't collide with its input, and two random 64-byte buffers don't repeat. Neither could ever fail.
  • PKCETests.generatedPKCEHasVerifierAndChallenge — empty-string smoke check, subsumed by the length+charset test.
  • CredentialsTests.equalityAndCodingRoundTrip — encoded then decoded with the same JSONEncoder/JSONDecoder, asserting equality. Tests the Swift compiler's synthesized Codable, not our contract.
  • LocalCallbackServerTests.parseCallbackExtractsCodeAndState — the body only asserted server.callbackPath == "/auth/callback" after constructing the server with that string. Init-parameter echo masquerading as a parser test.

Added

  • PKCETests.challengeIsBase64URLEncodedSHA256OfVerifier — RFC 7636 §4.2: challenge == BASE64URL(SHA256(verifier)). If this drifts, the OpenAI token endpoint rejects the auth-code exchange with invalid_grant.
  • CredentialsTests.credentialsAreExpiredWithinDefaultLeewayWindow — a token expiring in 30s must already count as expired so AuthService.credentials(for:) triggers a refresh before clock skew causes a 401 mid-request.
  • CredentialsTests.customLeewayChangesTheExpiryThreshold — same token, different leeway → flips the result either way.
  • CredentialsTests.persistedJSONKeysAreStable — protects the on-disk Keychain shape: any key rename silently signs every existing user out on the next launch.

Test plan

  • swift test — 45/45 pass
  • CI passes on PR

- PKCE: replace "verifier != challenge" / "two generations differ"
  (universe-luck passes) with the RFC 7636 4.2 invariant:
  challenge == base64url(SHA256(verifier))
- Credentials: drop the synthesized-Codable round-trip; add coverage
  for the 60s leeway window (existing -120s/+300s tests skipped it)
  and a Keychain key-stability check
- LocalCallbackServer: drop parseCallbackExtractsCodeAndState — it
  only echoed the init parameter back
@atom2ueki atom2ueki force-pushed the worktree-test-tdd-cleanup branch from 10704cf to d81334e Compare May 1, 2026 08:23
@atom2ueki atom2ueki merged commit 2714ad0 into main May 1, 2026
4 checks passed
@atom2ueki atom2ueki deleted the worktree-test-tdd-cleanup branch May 1, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant