From 00bc88d2c52df4867eafb1fa86d3d8a008546179 Mon Sep 17 00:00:00 2001 From: Dorian de Koning Date: Thu, 6 Nov 2025 12:54:07 +0100 Subject: [PATCH] fix(openfeature-go-feature-flag-provider): fallback to sdkDefault if reason is DISABLED Currently, when go-feature-flags has a disabled flag it returns a response in the following format: {"key":"my_flag","value":"thisisadefaultvaluethatItest1233%%","reason":"DISABLED","variant":"SdkDefault"} This `thisisadefault...` comes directly from go-feature-flags. The client package returns this, but sdkDefault makes more sense. Signed-off-by: Dorian de Koning --- .../go_feature_flag_provider.rb | 7 +++++ .../gofeatureflag/provider_spec.rb | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb index 7fbbc72..d66e6c0 100644 --- a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb +++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb @@ -52,6 +52,13 @@ def evaluate(flag_key:, default_value:, allowed_classes:, evaluation_context: ni ) end + if parsed_response.reason == SDK::Provider::Reason::DISABLED + return SDK::Provider::ResolutionDetails.new( + value: default_value, + reason: SDK::Provider::Reason::DISABLED + ) + end + unless allowed_classes.include?(parsed_response.value.class) return SDK::Provider::ResolutionDetails.new( value: default_value, diff --git a/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/provider_spec.rb b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/provider_spec.rb index 5bdd49d..adc6060 100644 --- a/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/provider_spec.rb +++ b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/provider_spec.rb @@ -314,6 +314,36 @@ ) expect(got).to eql(want) end + + it "should return the default value if the reason is DISABLED" do + test_name = RSpec.current_example.description + stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag") + .to_return(status: 200, body: + { + key: "boolean_flag", + metadata: {"website" => "https://gofeatureflag.org"}, + value: true, + reason: "DISABLED", + variant: "variantA" + }.to_json) + OpenFeature::SDK.configure do |config| + config.set_provider(goff_provider, domain: test_name) + end + client = OpenFeature::SDK.build_client(domain: test_name) + got = client.fetch_boolean_details( + flag_key: "boolean_flag", + default_value: false, + evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "1234") + ) + want = OpenFeature::SDK::EvaluationDetails.new( + flag_key: "boolean_flag", + resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new( + value: false, + reason: OpenFeature::SDK::Provider::Reason::DISABLED + ) + ) + expect(got).to eql(want) + end end context "#fetch_string_value with openfeature" do