fix(ios): prevent keychain precondition crash on unsigned and test builds#1440
Merged
Conversation
da29256 to
46c24c7
Compare
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.
Problem
The iOS Tests CI job has failed on every commit since it was added (back to mid-May), with:
The result bundle shows
passedTests: 0— the host app crashes at launch before a single test runs. Not specific to any recent PR.Root cause
KeychainSecureStore.resolveAccessGroup()calledpreconditionFailure(...)whenAppIdentifierPrefixis absent or still the unsubstituted literal$(AppIdentifierPrefix). That is exactly the case in the CI build, which runs withCODE_SIGNING_ALLOWED=NO(no signing means noAppIdentifierPrefix).KeychainSecureStore()is constructed inAppState.init, which runs at app launch, so the precondition trips (SIGTRAP) before tests connect. Signed device/TestFlight builds always have the prefix, so they never hit it.Fix
resolveAccessGroup()now returnsString?and logs a warning instead of crashing when the prefix is unavailable. Queries includekSecAttrAccessGrouponly when an access group is present. Signed builds are unchanged (they still get the shared group).XCTestConfigurationFilePath, which is not set under Swift Testing (the suite uses@Suite/@Test). NewTestRuntime.isActivealso checksXCTestBundlePathandNSClassFromString("XCTestCase"), so analytics, CloudKit sync, widget, and Spotlight side-effects are reliably skipped during tests as the author intended. Centralizes a check that was duplicated inAppStateandTableProMobileApp.Notes