Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 27, 2025

Enables different toggle values per scope (user, environment, tenant). The existing scope infrastructure in the database was present but unexposed in the client APIs.

Changes

Core

  • Added SCOPE query parameter to TogglesProviderContract URI builders
  • Added getScopeByName() to ProviderScopeDao for name-based lookups
  • Updated TogglesProvider.query() to extract scope from URI, falling back to default scope if not found

Client Libraries

  • Added optional scope constructor parameter to TogglesImpl (flow) and TogglesPreferencesImpl (prefs)
  • Scope parameter passes through to provider via URI query string

Testing & Demo

  • Added ScopedFlowTest, ScopedTogglesPreferencesTest, ScopedTogglesProviderTest
  • Created sample app demo screen showing admin/guest/default scopes
  • Updated README with usage examples

Usage

// Different scopes see different values for the same toggle
val adminToggles = TogglesImpl(context, scope = "admin")
val guestToggles = TogglesImpl(context, scope = "guest")

adminToggles.toggle("advanced_mode", false).collect { enabled -> /* ... */ }
guestToggles.toggle("advanced_mode", false).collect { enabled -> /* ... */ }

// Omitting scope uses currently selected scope (backward compatible)
val toggles = TogglesImpl(context)

Use cases: per-user flags, A/B testing, environment-specific settings, multi-tenant apps.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/java-21-openjdk-amd64/bin/java /usr/lib/jvm/java-21-openjdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xms500m -Xmx12120m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)
  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/java-21-openjdk-amd64/bin/java /usr/lib/jvm/java-21-openjdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xms500m -Xmx12120m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Scoped instances of toggles</issue_title>
<issue_description>It would be nice to have different instances of toggles for different scopes. like if you can have multiple users and i want a separate scope for each users i would like to enable and disable flags per user.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits November 27, 2025 10:00
- Add scope query parameter to TogglesProviderContract URI builders
- Add scope constructor parameter to Toggles (flow) API
- Add scope constructor parameter to TogglesPreferences API
- Add getScopeByName method to ProviderScopeDao
- Update provider to handle scope parameter from URI and route to correct scope

Co-authored-by: warting <[email protected]>
- Add ScopedFlowTest to verify scope isolation in flow library
- Add ScopedTogglesPreferencesTest to verify scope isolation in prefs library
- Update README with scoped toggles examples and use cases
- Document per-user feature flags, A/B testing, and multi-tenant use cases

Co-authored-by: warting <[email protected]>
- Add ScopedTogglesProviderTest to verify provider handles scope query parameters
- Test scope parameter routing to correct scope values
- Test fallback to default scope when custom scope not found
- Test multiple scopes with different values for the same toggle

Co-authored-by: warting <[email protected]>
- Create ScopedTogglesViewModel demonstrating per-scope toggle instances
- Create ScopedTogglesView showing real-time scope-specific values
- Add scoped toggles navigation entry and bottom nav item
- Demonstrate admin, guest, and default scope usage
- Add user instructions for testing scoped toggles

Co-authored-by: warting <[email protected]>
- Move @OptIn annotations to function level in ScopedFlowTest
- Use getValue delegate for state observation in ScopedTogglesView to enable recomposition
- Remove inline @OptIn usages for cleaner code organization

Co-authored-by: warting <[email protected]>
Copilot AI changed the title [WIP] Add support for scoped instances of toggles per user Add scoped toggle instances for per-user feature flags Nov 27, 2025
Copilot AI requested a review from warting November 27, 2025 10:12
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.

Scoped instances of toggles

2 participants