Skip to content

Fixed tests to use new API to disable auto init.#1580

Merged
NidhiDixit09 merged 8 commits into4.0.0-alpha.0from
ndixit/integration-test-fix
Feb 24, 2026
Merged

Fixed tests to use new API to disable auto init.#1580
NidhiDixit09 merged 8 commits into4.0.0-alpha.0from
ndixit/integration-test-fix

Conversation

@NidhiDixit09
Copy link
Copy Markdown
Collaborator

Reference

Summary

SDK Binary Integration tests were using API - setConsumerProtectionAttributionLevel along with initSession. Because of autoinitialization in setConsumerProtectionAttributionLevel initsession was losing deep link data.
This PR includes fix for above issue - it uses new API - - (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level resetSession:(BOOL)resetSession; - to avoid auto initialization.

Type Of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing Instructions

cc @BranchMetrics/saas-sdk-devs for visibility.

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Feb 24, 2026

Code Quality bug fix

Summary By MatterAI MatterAI logo

🔄 What Changed

Updated integration tests for iOS and tvOS to utilize the new setConsumerProtectionAttributionLevel(_:resetSession:) API with resetSession: false. This prevents unintended SDK auto-initialization that was causing deep link data loss. Added verbose logging and waitForExpectations to synchronize asynchronous session initialization before state assertions.

🔍 Impact of the Change

Fixes a critical issue where deep link data was lost during attribution level transitions. By using the non-resetting API, tests now accurately reflect privacy configuration scenarios without disrupting the session lifecycle, ensuring reliable SDK compliance verification.

📁 Total Files Changed

Click to Expand
File ChangeLog
API Update iOSReleaseTestTests.swift Switched to non-resetting attribution API and added verbose logging for iOS.
API Update tvOSReleaseTestTests.swift Mirrored iOS changes for tvOS to ensure cross-platform test parity.

🧪 Test Added/Recommended

Added

  • testInitSessionAndSetCPPLevel: Updated to verify attribution levels persist correctly without triggering a session reset.
  • Branch.enableLogging: Added verbose logging callback to capture SDK internal state during test execution.

Recommended

  • Timeout Optimization: Reduce the 90s timeout to 30s to prevent CI bottlenecks while still allowing for network latency.
  • Log Management: Replace standard print statements with XCTContext.runActivity to group logs within the XCTest report UI.

🔒 Security Vulnerabilities

No security vulnerabilities detected. The PR correctly focuses on privacy API implementation and test synchronization. 🛡️

⏳ Estimated code review effort

LOW (~8 minutes)

Tip

Quality Recommendations

  1. Reduce the 90-second timeout to 30 seconds to optimize CI pipeline duration.

  2. Use XCTContext.runActivity to organize verbose logs within the test report for better readability.

  3. Consider wrapping verbose logging in a conditional flag to avoid console noise in standard local runs.

♫ Tanka Poem

Deep links lost in time,
Auto-init caused the crime,
Flags set false today,
Data flows the proper way,
Tests now in their prime. 🧪✨

Sequence Diagram

sequenceDiagram
    participant T as Integration Test
    participant B as Branch SDK
    participant P as BNCPreferenceHelper
    
    T->>B: enableLogging(at: .verbose)
    T->>B: setConsumerProtectionAttributionLevel(.none)
    T->>B: setConsumerProtectionAttributionLevel(.full, resetSession: false)
    T->>B: initSession()
    B-->>T: callback(params, error)
    Note over T: waitForExpectations(timeout: 90)
    T->>P: attributionLevel
    P-->>T: currentLevel
    T->>T: XCTAssertEqual(currentLevel, .none)
Loading

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Feb 24, 2026

✅ Reviewed the changes: The PR looks good overall. The tests are updated to use the new API to disable auto-initialization and verify Consumer Protection Attribution (CPP) levels.

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Feb 24, 2026

✅ Reviewed the changes: The PR description mentions using a new API to disable auto-initialization, but the code changes only add a waitForExpectations timeout and do not actually implement the new API call.

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Feb 24, 2026

✅ Reviewed the changes: The changes correctly implement the new setConsumerProtectionAttributionLevel:resetSession: API to prevent auto-initialization during the test setup. The test flow properly validates the fix described in the PR.

Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 PR Review is completed: The PR correctly introduces the new API to prevent auto-initialization, but there are instances where the old API is still being called, which might inadvertently trigger the issue being fixed.


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: The PR description states that the old setConsumerProtectionAttributionLevel API causes auto-initialization and the fix is to use the new API with the resetSession parameter. However, this line still uses the old API, which might trigger the unwanted auto-initialization before the next line executes.

Fix: Use the new API with resetSession: false for setting the level to .none as well, to ensure auto-initialization is completely avoided.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: Similar to the iOS test, this line still uses the old setConsumerProtectionAttributionLevel API which the PR aims to replace to prevent auto-initialization.

Fix: Use the new API with resetSession: false for setting the level to .none to maintain consistency and prevent unintended side effects.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)

Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 PR Review is completed: The PR still contains calls to the old setConsumerProtectionAttributionLevel API which can trigger the unwanted auto-initialization.


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: The PR description states that the old setConsumerProtectionAttributionLevel API causes auto-initialization and the fix is to use the new API with the resetSession parameter. However, this line still uses the old API, which might trigger the unwanted auto-initialization before the next line executes.

Fix: Use the new API with resetSession: false for setting the level to .none as well, to ensure auto-initialization is completely avoided.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: Similar to the iOS test, this line still uses the old setConsumerProtectionAttributionLevel API which the PR aims to replace to prevent auto-initialization.

Fix: Use the new API with resetSession: false for setting the level to .none to maintain consistency and prevent unintended side effects.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)

Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 PR Review is completed: The PR correctly introduces the new API to prevent auto-initialization, but there are still instances where the old API is being called, which defeats the purpose of the fix.


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: The PR description states that the old setConsumerProtectionAttributionLevel API causes auto-initialization and the fix is to use the new API with the resetSession parameter. However, this line still uses the old API, which might trigger the unwanted auto-initialization before the next line executes.

Fix: Use the new API with resetSession: false for setting the level to .none as well, to ensure auto-initialization is completely avoided.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: Similar to the iOS test, this line still uses the old setConsumerProtectionAttributionLevel API which the PR aims to replace to prevent auto-initialization.

Fix: Use the new API with resetSession: false for setting the level to .none to maintain consistency and prevent unintended side effects.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)

Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 PR Review is completed: The PR partially addresses the auto-initialization issue by using the new API on line 56, but line 55 still uses the old API which can trigger the unwanted auto-initialization.


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: The PR description states that the old setConsumerProtectionAttributionLevel API causes auto-initialization and the fix is to use the new API with the resetSession parameter. However, this line still uses the old API, which might trigger the unwanted auto-initialization before the next line executes.

Fix: Use the new API with resetSession: false for setting the level to .none as well, to ensure auto-initialization is completely avoided.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: Similar to the iOS test, this line still uses the old setConsumerProtectionAttributionLevel API which the PR aims to replace to prevent auto-initialization.

Fix: Use the new API with resetSession: false for setting the level to .none to maintain consistency and prevent unintended side effects.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)

Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 PR Review is completed: The PR introduces the new API to prevent auto-initialization, but still uses the old API in the preceding line, which defeats the purpose of the fix.


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: The PR description states that the old setConsumerProtectionAttributionLevel API causes auto-initialization and the fix is to use the new API with the resetSession parameter. However, this line still uses the old API, which might trigger the unwanted auto-initialization before the next line executes.

Fix: Use the new API with resetSession: false for setting the level to .none as well, to ensure auto-initialization is completely avoided.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)


let sdk = BranchSDKTest(){ params, error in
print(params as? [String: AnyObject] ?? {})
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Logic

Issue: Similar to the iOS test, this line still uses the old setConsumerProtectionAttributionLevel API which the PR aims to replace to prevent auto-initialization.

Fix: Use the new API with resetSession: false for setting the level to .none to maintain consistency and prevent unintended side effects.

Impact: Prevents unintended auto-initialization and deep link data loss during the test setup.

Suggested change
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none)
Branch.getInstance().setConsumerProtectionAttributionLevel(BranchAttributionLevel.none, resetSession: false)

@BranchMetrics BranchMetrics deleted a comment from johnny1494 Feb 24, 2026
@johnny1494 johnny1494 mentioned this pull request Feb 24, 2026
@NidhiDixit09 NidhiDixit09 changed the title Fixed tests to use new API to disbale auto init. Fixed tests to use new API to disable auto init. Feb 24, 2026
@NidhiDixit09 NidhiDixit09 merged commit 9b4f654 into 4.0.0-alpha.0 Feb 24, 2026
10 checks passed
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.

2 participants