Open
Conversation
Comment on lines
12
to
+17
| class StorageTests: XCTestCase { | ||
| func test_makeDependencyContainer_configuresApiKeySynchronously() { | ||
| let dependencyContainer = Superwall.makeDependencyContainer(apiKey: "pk_test_123") | ||
|
|
||
| XCTAssertEqual(dependencyContainer.storage.apiKey, "pk_test_123") | ||
| } |
There was a problem hiding this comment.
New test uses XCTest instead of Swift Testing
CLAUDE.md explicitly requires: "This project uses Swift's Testing framework (not XCTest) for all unit tests. Always use the Testing framework when writing new tests."
The new test was added to the existing XCTestCase subclass rather than creating a new Swift Testing file. It should live in its own file using import Testing with @Test and #expect.
Context Used: CLAUDE.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: Tests/SuperwallKitTests/Storage/StorageTests.swift
Line: 12-17
Comment:
**New test uses XCTest instead of Swift Testing**
`CLAUDE.md` explicitly requires: *"This project uses Swift's Testing framework (not XCTest) for all unit tests. Always use the Testing framework when writing new tests."*
The new test was added to the existing `XCTestCase` subclass rather than creating a new Swift Testing file. It should live in its own file using `import Testing` with `@Test` and `#expect`.
**Context Used:** CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=ae0afcf7-0b55-482b-9764-29f361e46714))
How can I resolve this? If you propose a fix, please make it concise.
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
/redeemfrom racing ahead withAuthorization: BearerwhenReceiptManagerregisters the app transaction id earlyWhy
ReceiptManagerstartssetAppTransactionId()during dependency construction. If that resolves quickly afterSuperwall.isInitializedbecomes true, it can callredeem(.existingCodes)before the old async startup task had populatedstorage.apiKey, which means the shared header builder would emit an empty bearer token.Testing
swift test --filter StorageTests(fails in this environment because the active developer directory is Command Line Tools and the package imports UIKit:no such module "UIKit")Greptile Summary
This PR fixes a startup race condition where
ReceiptManagercould callredeem(.existingCodes)beforestorage.apiKeywas populated, because the previous code set the key inside an asyncTaskrather than synchronously during initialization.\n\nKey changes:\n- IntroducesSuperwall.makeDependencyContainer(...)— a static factory that constructsDependencyContainerand immediately callsstorage.configure(apiKey:)synchronously before any async work begins.\n- Theprivate convenience initnow delegates container creation to this factory, removing thestorage.configurecall from inside theTask.\n- Adds a regression test asserting that storage is configured synchronously aftermakeDependencyContainerreturns — though the test usesXCTestCaserather than the project-required Swift Testing framework (CLAUDE.md).Confidence Score: 4/5
Safe to merge — the fix is minimal, well-targeted, and correctly resolves the race condition with no risky side effects.
The core change is straightforward and correct: moving storage.configure(apiKey:) from inside an async Task to synchronous initialization eliminates the race. The only non-blocking issue is that the new regression test uses XCTest instead of the project-mandated Swift Testing framework.
Tests/SuperwallKitTests/Storage/StorageTests.swift — test should be rewritten using Swift Testing framework per CLAUDE.md.
Important Files Changed
Sequence Diagram
sequenceDiagram participant C as Caller (configure) participant S as Superwall.init participant MDC as makeDependencyContainer participant DC as DependencyContainer.init participant ST as Storage participant RM as ReceiptManager Note over S,RM: After fix — synchronous path C->>S: Superwall.configure(apiKey:) S->>MDC: makeDependencyContainer(apiKey:) MDC->>DC: DependencyContainer.init() DC->>ST: Storage.init() DC->>RM: ReceiptManager.init() [may start async work] DC-->>MDC: dependencyContainer MDC->>ST: storage.configure(apiKey:) synchronous before Task MDC-->>S: dependencyContainer (apiKey already set) S->>S: Task { recordAppInstall, fetchConfig } Note right of RM: If ReceiptManager calls redeem() here storage.apiKey is already populatedPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "Fix redeem auth race during startup" | Re-trigger Greptile
Context used: