Repository navigation
Let beta settings inherit remote defaults #9283
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f55f7f8
test: prove explicit todo setting beats remote default
azooz2003-bit 60f45f8
feat: add inherited remote defaults for beta settings
azooz2003-bit 18794a6
Merge remote-tracking branch 'origin/main' into feat-beta-remote-defa…
azooz2003-bit caeb06f
fix: address beta remote default review feedback
azooz2003-bit 2df356c
Merge remote-tracking branch 'origin/main' into feat-beta-remote-defa…
azooz2003-bit cad2aeb
fix: harden beta default debug responses
azooz2003-bit 9a830bd
Merge remote-tracking branch 'origin/main' into feat-beta-remote-defa…
azooz2003-bit 0b4ac52
Merge remote-tracking branch 'origin/main' into feat-beta-remote-defa…
azooz2003-bit 63a11c3
fix: declare panelArtifactAuthorizationStore and accept workspaceID i…
azooz2003-bit ffd2cf5
fix: make MobileSurfaces switches exhaustive
azooz2003-bit 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
70 changes: 70 additions & 0 deletions
70
...uxControlSocket/Coordinator/Debug/ControlCommandCoordinator+DebugBetaRemoteDefaults.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,70 @@ | ||
| #if DEBUG | ||
| extension ControlCommandCoordinator { | ||
| func debugBetaRemoteDefaultGet( | ||
| _ params: [String: JSONValue] | ||
| ) -> ControlCallResult { | ||
| guard let debugContext else { | ||
| return .err(code: "unavailable", message: Self.debugContextUnavailableResponse, data: nil) | ||
| } | ||
| let strings = debugContext.controlDebugBetaRemoteDefaultStrings() | ||
| guard let key = string(params, "key") else { | ||
| return .err(code: "invalid_params", message: strings.missingKey, data: nil) | ||
| } | ||
| guard let snapshot = debugContext.controlDebugBetaRemoteDefaultSnapshot( | ||
| identifier: key | ||
| ) else { | ||
| return .err(code: "not_found", message: strings.notFound, data: nil) | ||
| } | ||
| return debugBetaRemoteDefaultResult(snapshot) | ||
| } | ||
|
|
||
| func debugBetaRemoteDefaultSet( | ||
| _ params: [String: JSONValue] | ||
| ) -> ControlCallResult { | ||
| guard let debugContext else { | ||
| return .err(code: "unavailable", message: Self.debugContextUnavailableResponse, data: nil) | ||
| } | ||
| let strings = debugContext.controlDebugBetaRemoteDefaultStrings() | ||
| guard let key = string(params, "key") else { | ||
| return .err(code: "invalid_params", message: strings.missingKey, data: nil) | ||
| } | ||
| guard let rawValue = params["value"] else { | ||
| return .err(code: "invalid_params", message: strings.missingValue, data: nil) | ||
| } | ||
| let value: Bool? | ||
| switch rawValue { | ||
| case .bool(let enabled): | ||
| value = enabled | ||
| case .null: | ||
| value = nil | ||
| default: | ||
| return .err( | ||
| code: "invalid_params", | ||
| message: strings.invalidValue, | ||
| data: nil | ||
| ) | ||
| } | ||
| guard let snapshot = debugContext.controlDebugSetBetaRemoteDefault( | ||
| identifier: key, | ||
| value: value | ||
| ) else { | ||
| return .err(code: "not_found", message: strings.notFound, data: nil) | ||
| } | ||
| return debugBetaRemoteDefaultResult(snapshot) | ||
| } | ||
|
|
||
| private func debugBetaRemoteDefaultResult( | ||
| _ snapshot: ControlDebugBetaRemoteDefaultSnapshot | ||
| ) -> ControlCallResult { | ||
| .ok(.object([ | ||
| "setting_id": .string(snapshot.settingID), | ||
| "flag_key": .string(snapshot.flagKey), | ||
| "user_key_present": .bool(snapshot.userKeyPresent), | ||
| "user_value": snapshot.userValue.map { .bool($0) } ?? .null, | ||
| "remote_default": snapshot.remoteDefault.map { .bool($0) } ?? .null, | ||
| "effective_value": .bool(snapshot.effectiveValue), | ||
| "source": .string(snapshot.source), | ||
| ])) | ||
| } | ||
| } | ||
| #endif | ||
30 changes: 30 additions & 0 deletions
30
...t/Sources/CmuxControlSocket/Coordinator/Debug/ControlDebugBetaRemoteDefaultSnapshot.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,30 @@ | ||
| #if DEBUG | ||
| /// A DEBUG readback of one Beta Features remote-default resolution. | ||
| public struct ControlDebugBetaRemoteDefaultSnapshot: Sendable, Equatable { | ||
| public let settingID: String | ||
| public let flagKey: String | ||
| public let userKeyPresent: Bool | ||
| public let userValue: Bool? | ||
| public let remoteDefault: Bool? | ||
| public let effectiveValue: Bool | ||
| public let source: String | ||
|
|
||
| public init( | ||
| settingID: String, | ||
| flagKey: String, | ||
| userKeyPresent: Bool, | ||
| userValue: Bool?, | ||
| remoteDefault: Bool?, | ||
| effectiveValue: Bool, | ||
| source: String | ||
| ) { | ||
| self.settingID = settingID | ||
| self.flagKey = flagKey | ||
| self.userKeyPresent = userKeyPresent | ||
| self.userValue = userValue | ||
| self.remoteDefault = remoteDefault | ||
| self.effectiveValue = effectiveValue | ||
| self.source = source | ||
| } | ||
| } | ||
| #endif |
21 changes: 21 additions & 0 deletions
21
...et/Sources/CmuxControlSocket/Coordinator/Debug/ControlDebugBetaRemoteDefaultStrings.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,21 @@ | ||
| /// App-bundle-resolved validation messages for the beta remote-default debug | ||
| /// RPCs. The coordinator package has no copy of the app's localization catalog, | ||
| /// so its context supplies these strings. | ||
| public struct ControlDebugBetaRemoteDefaultStrings: Sendable, Equatable { | ||
| public let missingKey: String | ||
| public let notFound: String | ||
| public let missingValue: String | ||
| public let invalidValue: String | ||
|
|
||
| public init( | ||
| missingKey: String, | ||
| notFound: String, | ||
| missingValue: String, | ||
| invalidValue: String | ||
| ) { | ||
| self.missingKey = missingKey | ||
| self.notFound = notFound | ||
| self.missingValue = missingValue | ||
| self.invalidValue = invalidValue | ||
| } | ||
| } |
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
153 changes: 153 additions & 0 deletions
153
.../Tests/CmuxControlSocketTests/ControlCommandCoordinatorDebugBetaRemoteDefaultsTests.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,153 @@ | ||
| import Foundation | ||
| import Testing | ||
|
|
||
| @testable import CmuxControlSocket | ||
|
|
||
| #if DEBUG | ||
| @MainActor | ||
| @Suite("ControlCommandCoordinator beta remote-default debug dispatch") | ||
| struct ControlCommandCoordinatorDebugBetaRemoteDefaultsTests { | ||
| @Test func getReturnsTypedResolutionReadback() { | ||
| let context = FakeBetaRemoteDefaultControlCommandContext() | ||
| let coordinator = ControlCommandCoordinator(context: context) | ||
|
|
||
| let result = coordinator.handle( | ||
| ControlRequest( | ||
| id: .int(1), | ||
| method: "debug.beta_remote_defaults.get", | ||
| params: ["key": .string("tests.beta.enabled")] | ||
| ) | ||
| ) | ||
|
|
||
| #expect(result == .ok(.object([ | ||
| "setting_id": .string("tests.beta.enabled"), | ||
| "flag_key": .string("tests-beta-default-experiment"), | ||
| "user_key_present": .bool(false), | ||
| "user_value": .null, | ||
| "remote_default": .bool(true), | ||
| "effective_value": .bool(true), | ||
| "source": .string("remoteDefault"), | ||
| ]))) | ||
| } | ||
|
|
||
| @Test func setAcceptsNullAsCacheClearAndRejectsOtherTypes() { | ||
| let context = FakeBetaRemoteDefaultControlCommandContext() | ||
| let coordinator = ControlCommandCoordinator(context: context) | ||
|
|
||
| let cleared = coordinator.handle( | ||
| ControlRequest( | ||
| id: .int(1), | ||
| method: "debug.beta_remote_defaults.set", | ||
| params: [ | ||
| "key": .string("tests.beta.enabled"), | ||
| "value": .null, | ||
| ] | ||
| ) | ||
| ) | ||
| #expect(context.lastValueWasSet) | ||
| #expect(context.lastValue == nil) | ||
| guard case .ok = cleared else { | ||
| Issue.record("expected cache clear to succeed") | ||
| return | ||
| } | ||
|
|
||
| guard case .err(let code, _, let data) = coordinator.handle( | ||
| ControlRequest( | ||
| id: .int(2), | ||
| method: "debug.beta_remote_defaults.set", | ||
| params: [ | ||
| "key": .string("tests.beta.enabled"), | ||
| "value": .string("true"), | ||
| ] | ||
| ) | ||
| ) else { | ||
| Issue.record("expected invalid value to fail") | ||
| return | ||
| } | ||
| #expect(code == "invalid_params") | ||
| #expect(data == nil) | ||
| } | ||
|
|
||
| @Test func validationErrorsUseContextProvidedStrings() { | ||
| let context = FakeBetaRemoteDefaultControlCommandContext() | ||
| context.strings = ControlDebugBetaRemoteDefaultStrings( | ||
| missingKey: "localized missing key", | ||
| notFound: "localized not found", | ||
| missingValue: "localized missing value", | ||
| invalidValue: "localized invalid value" | ||
| ) | ||
| let coordinator = ControlCommandCoordinator(context: context) | ||
|
|
||
| guard case .err(_, let missingKey, _) = coordinator.handle( | ||
| ControlRequest( | ||
| id: .int(1), | ||
| method: "debug.beta_remote_defaults.get", | ||
| params: [:] | ||
| ) | ||
| ) else { | ||
| Issue.record("expected missing-key error") | ||
| return | ||
| } | ||
| guard case .err(_, let invalidValue, _) = coordinator.handle( | ||
| ControlRequest( | ||
| id: .int(2), | ||
| method: "debug.beta_remote_defaults.set", | ||
| params: [ | ||
| "key": .string("tests.beta.enabled"), | ||
| "value": .string("true"), | ||
| ] | ||
| ) | ||
| ) else { | ||
| Issue.record("expected invalid-value error") | ||
| return | ||
| } | ||
| #expect(missingKey == "localized missing key") | ||
| #expect(invalidValue == "localized invalid value") | ||
| } | ||
| } | ||
|
|
||
| @MainActor | ||
| private final class FakeBetaRemoteDefaultControlCommandContext: ControlCommandContext { | ||
| var lastValueWasSet = false | ||
| var lastValue: Bool? | ||
| var strings = ControlDebugBetaRemoteDefaultStrings( | ||
| missingKey: "Missing key", | ||
| notFound: "Beta remote default not found", | ||
| missingValue: "Missing value", | ||
| invalidValue: "value must be a bool or null" | ||
| ) | ||
|
|
||
| func controlDebugBetaRemoteDefaultStrings() -> ControlDebugBetaRemoteDefaultStrings { | ||
| strings | ||
| } | ||
|
|
||
| func controlDebugBetaRemoteDefaultSnapshot( | ||
| identifier: String | ||
| ) -> ControlDebugBetaRemoteDefaultSnapshot? { | ||
| snapshot(remoteDefault: true) | ||
| } | ||
|
|
||
| func controlDebugSetBetaRemoteDefault( | ||
| identifier: String, | ||
| value: Bool? | ||
| ) -> ControlDebugBetaRemoteDefaultSnapshot? { | ||
| lastValueWasSet = true | ||
| lastValue = value | ||
| return snapshot(remoteDefault: value) | ||
| } | ||
|
|
||
| private func snapshot( | ||
| remoteDefault: Bool? | ||
| ) -> ControlDebugBetaRemoteDefaultSnapshot { | ||
| ControlDebugBetaRemoteDefaultSnapshot( | ||
| settingID: "tests.beta.enabled", | ||
| flagKey: "tests-beta-default-experiment", | ||
| userKeyPresent: false, | ||
| userValue: nil, | ||
| remoteDefault: remoteDefault, | ||
| effectiveValue: remoteDefault ?? false, | ||
| source: remoteDefault == nil ? "compileDefault" : "remoteDefault" | ||
| ) | ||
| } | ||
| } | ||
| #endif |
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
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.
Uh oh!
There was an error while loading. Please reload this page.