Skip to content

chore(test-app): start a second environment when a second key is set - #550

Open
abelonogov-ld wants to merge 7 commits into
andrey/apple-test-appfrom
andrey/apple-test-app-two-environments
Open

abelonogov-ld wants to merge 7 commits into
andrey/apple-test-appfrom
andrey/apple-test-app-two-environments

Conversation

@abelonogov-ld

@abelonogov-ld abelonogov-ld commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #545.

What

When Config/Secrets.xcconfig sets LAUNCHDARKLY_SECONDARY_MOBILE_KEY (or the app is launched with -LDSecondaryMobileKey mob-...), the client is started with that key as a secondary environment through LDConfig.setSecondaryMobileKeys. An Environment picker at the top of Client chooses which environment's client the buttons use. Without the key nothing changes.

The selected environment is used by:

  • Eval, All flags, and the flag-change observer;
  • Track;
  • Kill 5s, Kill now, Fatal now, Over-refresh and Fill 3 batches;
  • Post 20 MB (which key it posts with);
  • the connection status;
  • Event storage, which shows that environment's own directory.

These reach both environments whichever is selected, because the SDK applies close, flush, flushAndWait, setOnline and identify to every environment it started: Restart and the persistence picker, Flush, Flush+Wait, Offline, and Identify. A footer under Client says so.

The choice is saved in UserDefaults, so the launch that answers a kill scenario shows the same environment. InstanceLauncher forwards -LDSecondaryMobileKey to the instances it starts.

Testing

  • All five targets build: iOS (simulator and Mac Catalyst), macOS, tvOS and watchOS.
  • Ran on an iPhone 17 simulator with both keys set:
    • the picker appears and switches the connection status;
    • with immediate persistence, each environment writes its own event directory (<bundle hash>.<key hash>), each holding its startup log.

Note

The SDK keeps ConnectionInformation under one UserDefaults key for every environment (ConnectionInformationStore). Each environment's status therefore starts out showing whichever environment saved last, until its own connection updates it. This PR doesn't change that SDK behavior.


Note

Overview
Adds payloadFilter to LDConfig (Swift and ObjcLDConfig), with validatedPayloadFilter() enforcing LaunchDarkly’s key rules and logging when a bad value is ignored. DarklyService sends the validated key as a filter query parameter on streaming and polling flag URLs, combined with withReasons when needed. Contract tests advertise filtering / filtering-strict and map harness filter fields from streaming or polling config.

TestApp can load a LAUNCHDARKLY_SECONDARY_MOBILE_KEY (or -LDSecondaryMobileKey) and start a second environment via setSecondaryMobileKeys. An Environment picker selects which LDClient drives evals, tracking, stress flows, connection status, and per-environment event storage; Restart/Flush/Offline/Identify still affect every started environment. The choice persists in UserDefaults, and InstanceLauncher forwards the secondary key to spawned instances.

Reviewed by Cursor Bugbot for commit 993471e. Bugbot is set up for automated code reviews on this repo. Configure here.

abelonogov-ld and others added 2 commits November 4, 2026 18:10
Co-authored-by: Cursor <cursoragent@cursor.com>
LAUNCHDARKLY_SECONDARY_MOBILE_KEY in Secrets.xcconfig, or -LDSecondaryMobileKey at launch, adds a
secondary mobile key to the client's LDConfig. An Environment picker then chooses which environment's
client the buttons, the connection status, Post 20 MB and the Event storage section use. Restart,
Flush, Flush+Wait, Offline and Identify still reach both, as the SDK applies them to every environment.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abelonogov-ld
abelonogov-ld requested a review from a team as a code owner November 11, 2026 01:46
abelonogov-ld and others added 3 commits November 10, 2026 18:23
Co-authored-by: Cursor <cursoragent@cursor.com>
…nvironments

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	LaunchDarkly/LaunchDarkly/Networking/DarklyService.swift
#	LaunchDarkly/LaunchDarkly/ObjectiveC/ObjcLDConfig.swift
#	LaunchDarkly/LaunchDarklyTests/Networking/DarklyServiceSpec.swift

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cf9e5b5. Configure here.

self.config = config
self.context = context
self.serviceFactory = serviceFactory
self.payloadFilter = config.validatedPayloadFilter()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Flag cache ignores payload filter

Medium Severity

payloadFilter is applied only to stream and poll URLs. Cached flags and their etags stay keyed by mobile key and context, so a new or changed filter still loads the previous payload. Evaluations can then return flags the filter should have excluded, and a polling 304 can keep that stale set, especially while offline.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cf9e5b5. Configure here.

@cursor cursor Bot added the risk:medium label Nov 17, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: medium.

Automated risk review (dry run): Medium

This PR would not be automatically approved. Human approval required.

Why: The diff adds a public SDK payloadFilter option (LDConfig, DarklyService, ObjcLDConfig) and TestApp secondary-environment wiring, and Cursor Bugbot has an unresolved medium-severity finding that flag cache and etags ignore the filter. Human review is needed and no reviewers were assigned.

If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.

Open in Web View Automation 

Sent by Cursor Approval Agent: Dry-Run PR Approver

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant