From 3d07313a3eafce4e3988164aa89468308fdd7fd1 Mon Sep 17 00:00:00 2001 From: Oleh Marakhovskyi Date: Fri, 5 Jul 2024 08:57:41 +0300 Subject: [PATCH] Fix configuration for combined experiments Made sure configuration for parent experiment is available for children(combined) --- lib/split/configuration.rb | 8 +++++++- spec/configuration_spec.rb | 19 +++++++++++++++++-- spec/helper_spec.rb | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/split/configuration.rb b/lib/split/configuration.rb index b43e5920..7c2659d9 100644 --- a/lib/split/configuration.rb +++ b/lib/split/configuration.rb @@ -116,7 +116,13 @@ def bots def experiments=(experiments) raise InvalidExperimentsFormatError.new("Experiments must be a Hash") unless experiments.respond_to?(:keys) - @experiments = experiments + @experiments = experiments.clone + experiments.each do |name, settings| + value_for(settings, :combined_experiments)&.each do |combined_name| + @experiments[combined_name] = + settings.reject { |k, v| [:combined_experiments, "combined_experiments"].include?(k) } + end + end end def disabled? diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index 28c8ff91..4570ec72 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -136,13 +136,28 @@ alternatives: - a - b + combined_experiment: + alternatives: + - a + - b + combined_experiments: + - combined1 + - combined2 + resettable: false eos @config.experiments = YAML.load(experiments_yaml) end it "should normalize experiments" do - expect(@config.normalized_experiments).to eq({ my_experiment: { resettable: false, alternatives: [{ "Control Opt"=>0.67 }, - [{ "Alt One"=>0.1 }, { "Alt Two"=>0.23 }]] }, another_experiment: { alternatives: ["a", ["b"]] } }) + result = { + my_experiment: { resettable: false, alternatives: [{ "Control Opt"=>0.67 }, [{ "Alt One"=>0.1 }, { "Alt Two"=>0.23 }]] }, + another_experiment: { alternatives: ["a", ["b"]] }, + combined_experiment: { resettable: false, alternatives: ["a", ["b"]] }, + combined1: { resettable: false, alternatives: ["a", ["b"]] }, + combined2: { resettable: false, alternatives: ["a", ["b"]] } + } + + expect(@config.normalized_experiments).to eq(result) end it "should recognize metrics" do diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index bc76b7d8..30a4633b 100755 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -476,6 +476,24 @@ expect(ab_user[experiment.key]).to eq(alternative) expect(ab_user[experiment.finished_key]).to eq(true) end + + context "combined experiment" do + it "passes reset option" do + Split.configuration.experiments = { + combined: { + alternatives: ["one", "two"], + combined_experiments: [:combined1], + resettable: false, + }, + } + alternative = ab_test(:combined1) + experiment = Split::ExperimentCatalog.find :combined1 + + ab_finished :combined1 + expect(ab_user[experiment.key]).to eq(alternative) + expect(ab_user[experiment.finished_key]).to eq(true) + end + end end context "finished with metric name" do