-
-
Notifications
You must be signed in to change notification settings - Fork 360
refactor(ios): Migrate from PrivateSentrySDKOnly to SentrySDK.internal #6380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alwx
wants to merge
13
commits into
main
Choose a base branch
from
alwx/refactor/migrate-private-sentry-sdk-only
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1185b2c
refactor(ios): Migrate from PrivateSentrySDKOnly to SentrySDK.internal
alwx a27be9e
test(ios): Migrate Swift Cocoa tests off PrivateSentrySDKOnly
alwx 9be362c
fix(ios): Include visionOS in the RNSScreen swizzle bridge
alwx ca6ceb3
fix(ios): Scope RNSScreen swizzle key pointer inside withUnsafePointer
alwx 2b58a75
fix(ios): Use conditional import for RNSentry-Swift.h
alwx e05cf3e
fix(ios): Guard against nil NSData and pin tests to SPI import
alwx faf391d
fix(ios): Resolve fetchViewHierarchy with nil on capture failure
alwx aee23dc
test(ios): Add smoke tests for RNSentryInternal Swift bridge
alwx c3803b9
fix(ci): Enable modular headers in e2e Podfile patch
alwx b652c4f
fix(ci): Only mark Podfile patched when anchor actually matched
alwx 18a00a7
docs: Note visionOS setCurrentScreen no-op in CHANGELOG
alwx 87aa884
fix(test): Import RNSentry in RNSentryInternalTests
alwx 23f1729
docs: Move iOS use_modular_headers note to Changes; reorder Unreleased
alwx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
104 changes: 104 additions & 0 deletions
104
packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryInternalTests.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| @_spi(Private) import RNSentry | ||
| @_spi(Private) import Sentry | ||
| import XCTest | ||
|
|
||
| /// Smoke coverage for the `RNSentryInternal` ObjCโSwift bridge. | ||
| /// | ||
| /// These are not exhaustive tests of the underlying `SentrySDK.internal.*` | ||
| /// surface โ sentry-cocoa owns that. We only assert the wrapper does not | ||
| /// crash, forwards data correctly, and honours the nil / platform guards | ||
| /// documented in `RNSentryInternal.swift`. | ||
| final class RNSentryInternalTests: XCTestCase { | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
| // Start the native SDK so `SentrySDK.internal.*` returns real state | ||
| // instead of the no-op hub. A minimal, offline-safe DSN is enough. | ||
| RNSentrySDK.start { options in | ||
| options.dsn = "https://abcd@efgh.ingest.sentry.io/123456" | ||
| } | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| SentrySDK.close() | ||
| super.tearDown() | ||
| } | ||
|
|
||
| // MARK: - envelope(fromData:) | ||
|
|
||
| func testEnvelopeFromNilDataReturnsNil() { | ||
| // Regression guard: the old ObjC `PrivateSentrySDKOnly.envelopeWithData:` | ||
| // tolerated nil. `RNSentryInternal.envelope(fromData:)` must too, or | ||
| // the ObjC bridge boundary would crash on a nil `NSData*` before the | ||
| // Swift body runs. See RNSentry.mm captureEnvelope path. | ||
| XCTAssertNil(RNSentryInternal.envelope(fromData: nil)) | ||
| } | ||
|
|
||
| func testEnvelopeFromInvalidDataReturnsNil() { | ||
| let junk = Data("this is not an envelope".utf8) | ||
| XCTAssertNil(RNSentryInternal.envelope(fromData: junk)) | ||
| } | ||
|
|
||
| // MARK: - SDK metadata | ||
|
|
||
| func testSdkMetadataAccessorsAreNonEmpty() { | ||
| XCTAssertFalse(RNSentryInternal.sdkName.isEmpty) | ||
| XCTAssertFalse(RNSentryInternal.sdkVersionString.isEmpty) | ||
| XCTAssertFalse(RNSentryInternal.installationID.isEmpty) | ||
| // `extraContext` may be empty on an unstarted SDK; here we only | ||
| // assert the accessor does not crash and returns a dictionary. | ||
| _ = RNSentryInternal.extraContext | ||
| } | ||
|
|
||
| func testSetSdkNameAndAddPackageRoundTrip() { | ||
| RNSentryInternal.setSdkName("sentry.cocoa.react-native.test", version: "42.42.42") | ||
| XCTAssertEqual(RNSentryInternal.sdkName, "sentry.cocoa.react-native.test") | ||
| XCTAssertEqual(RNSentryInternal.sdkVersionString, "42.42.42") | ||
|
|
||
| // Add-package is void; assert it does not throw. Idempotency across | ||
| // sentry-cocoa releases is not part of the bridge's contract. | ||
| RNSentryInternal.addSdkPackage("test-package", version: "1.0.0") | ||
| } | ||
|
|
||
| // MARK: - Options | ||
|
|
||
| func testOptionsAccessorReturnsLiveOptions() { | ||
| let options = RNSentryInternal.options | ||
| XCTAssertNotNil(options.dsn) | ||
| } | ||
|
|
||
| func testOptionsFromDictionaryValidatesInput() throws { | ||
| let dict: [String: Any] = ["dsn": "https://abcd@efgh.ingest.sentry.io/123456"] | ||
| let options = try RNSentryInternal.options(fromDictionary: dict) | ||
| XCTAssertNotNil(options.dsn) | ||
| } | ||
|
|
||
| // MARK: - App start / performance hybrid flags | ||
|
|
||
| func testAppStartHybridSDKModeIsReadWrite() { | ||
| let previous = RNSentryInternal.appStartMeasurementHybridSDKMode | ||
| RNSentryInternal.appStartMeasurementHybridSDKMode = !previous | ||
| XCTAssertEqual(RNSentryInternal.appStartMeasurementHybridSDKMode, !previous) | ||
| RNSentryInternal.appStartMeasurementHybridSDKMode = previous | ||
| } | ||
|
|
||
| #if os(iOS) || os(tvOS) || os(visionOS) | ||
| func testFramesTrackingHybridSDKModeIsReadWrite() { | ||
| let previous = RNSentryInternal.framesTrackingMeasurementHybridSDKMode | ||
| RNSentryInternal.framesTrackingMeasurementHybridSDKMode = !previous | ||
| XCTAssertEqual(RNSentryInternal.framesTrackingMeasurementHybridSDKMode, !previous) | ||
| RNSentryInternal.framesTrackingMeasurementHybridSDKMode = previous | ||
| } | ||
| #endif | ||
|
|
||
| // MARK: - Swizzle bridge | ||
|
|
||
| func testSwizzleRNSScreenViewDidAppearNoOpWhenClassMissing() { | ||
| // `RNSScreen` is not linked in this test target; the bridge should | ||
| // early-return without invoking the hook and without touching the | ||
| // ObjC runtime. | ||
| var hookCalled = false | ||
| RNSentryInternal.swizzleRNSScreenViewDidAppear { hookCalled = true } | ||
| XCTAssertFalse(hookCalled, "hook must not be called at registration time") | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Shouldn't we point to the PR
([#6380](https://github.com/getsentry/sentry-react-native/pull/6380))instead of the issue([#6370](https://github.com/getsentry/sentry-react-native/issues/6370))?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for line 23 and 31