From f3784c85c93db58bbe85a5b25cd030469ee8b9a3 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Tue, 14 Oct 2025 15:56:26 +0100 Subject: [PATCH 1/5] feat: Add `FeatureValue.variants[].priority` sorting tests --- ..._a_stronger_priority__expected_flags.jsonc | 47 +++++++++++++++++++ ..._b_stronger_priority__expected_flags.jsonc | 47 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc create mode 100644 test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc diff --git a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc new file mode 100644 index 0000000..55b96ea --- /dev/null +++ b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc @@ -0,0 +1,47 @@ +{ + "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", + "context": { + "environment": { + "key": "test_env", + "name": "Test Environment" + }, + "identity": { + "identifier": "0cfd0d72-4de4-4ed7-9cfb-d80dc3dacead", + "key": "32103813" + }, + "features": { + "multivariate_feature": { + "enabled": true, + "feature_key": "15062", + "key": "78986", + "name": "mv_feature", + "value": "foo", + "variants": [ + { + "value": "option_a", + "weight": 30, + "priority": 10 + }, + { + "value": "option_b", + "weight": 30, + "priority": 20 + } + ] + } + }, + "segments": {} + }, + "result": { + "flags": { + "multivariate_feature": { + "enabled": true, + "feature_key": "15062", + "name": "multivariate_feature", + "reason": "SPLIT; weight=30", + "value": "option_a" + } + }, + "segments": [] + } +} \ No newline at end of file diff --git a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc new file mode 100644 index 0000000..bf55263 --- /dev/null +++ b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc @@ -0,0 +1,47 @@ +{ + "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", + "context": { + "environment": { + "key": "test_env", + "name": "Test Environment" + }, + "identity": { + "identifier": "0cfd0d72-4de4-4ed7-9cfb-d80dc3dacead", + "key": "32103813" + }, + "features": { + "multivariate_feature": { + "enabled": true, + "feature_key": "15062", + "key": "78986", + "name": "mv_feature", + "value": "foo", + "variants": [ + { + "value": "option_a", + "weight": 30, + "priority": 20 + }, + { + "value": "option_b", + "weight": 30, + "priority": 10 + } + ] + } + }, + "segments": {} + }, + "result": { + "flags": { + "multivariate_feature": { + "enabled": true, + "feature_key": "15062", + "name": "multivariate_feature", + "reason": "SPLIT; weight=30", + "value": "option_b" + } + }, + "segments": [] + } +} \ No newline at end of file From cb9e084b9c17d57fbe4fd5f3db8834eed9af800a Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Tue, 14 Oct 2025 16:00:12 +0100 Subject: [PATCH 2/5] add comments --- ...tivariate__option_a_stronger_priority__expected_flags.jsonc | 3 +++ ...tivariate__option_b_stronger_priority__expected_flags.jsonc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc index 55b96ea..c9a51cb 100644 --- a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc @@ -1,4 +1,7 @@ { + // Given: A multivariate feature with two variants of equal weight, where option_a has a stronger priority (lower priority number) + // When: Evaluating the feature for the given identity + // Then: The variant with stronger priority (option_a) should be selected as the feature value "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", "context": { "environment": { diff --git a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc index bf55263..198e5f4 100644 --- a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc @@ -1,4 +1,7 @@ { + // Given: A multivariate feature with two variants of equal weight, where option_b has a stronger priority (lower priority number) + // When: Evaluating the feature for the given identity + // Then: The variant with stronger priority (option_b) should be selected as the feature value "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", "context": { "environment": { From 429c192a2d7dcd76d787e71941ad8c65e1171033 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Tue, 14 Oct 2025 17:09:52 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Zaimwa9 --- ...ltivariate__option_a_stronger_priority__expected_flags.jsonc | 2 +- ...ltivariate__option_b_stronger_priority__expected_flags.jsonc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc index c9a51cb..6571574 100644 --- a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc @@ -17,7 +17,7 @@ "enabled": true, "feature_key": "15062", "key": "78986", - "name": "mv_feature", + "name": "multivariate_feature", "value": "foo", "variants": [ { diff --git a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc index 198e5f4..23483df 100644 --- a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc @@ -17,7 +17,7 @@ "enabled": true, "feature_key": "15062", "key": "78986", - "name": "mv_feature", + "name": "multivariate_feature", "value": "foo", "variants": [ { From c1cf82e871ba7eb86687e5700f01afdf25b0af67 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Tue, 14 Oct 2025 18:48:33 +0100 Subject: [PATCH 4/5] use 50/50 splits --- ...ariate__option_a_stronger_priority__expected_flags.jsonc | 6 +++--- ...ariate__option_b_stronger_priority__expected_flags.jsonc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc index 6571574..401cf2b 100644 --- a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc @@ -22,12 +22,12 @@ "variants": [ { "value": "option_a", - "weight": 30, + "weight": 50, "priority": 10 }, { "value": "option_b", - "weight": 30, + "weight": 50, "priority": 20 } ] @@ -41,7 +41,7 @@ "enabled": true, "feature_key": "15062", "name": "multivariate_feature", - "reason": "SPLIT; weight=30", + "reason": "SPLIT; weight=50", "value": "option_a" } }, diff --git a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc index 23483df..bd915fc 100644 --- a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc @@ -22,12 +22,12 @@ "variants": [ { "value": "option_a", - "weight": 30, + "weight": 50, "priority": 20 }, { "value": "option_b", - "weight": 30, + "weight": 50, "priority": 10 } ] @@ -41,7 +41,7 @@ "enabled": true, "feature_key": "15062", "name": "multivariate_feature", - "reason": "SPLIT; weight=30", + "reason": "SPLIT; weight=50", "value": "option_b" } }, From aca26aab9da190ee8d007f80ca265db60ef83be5 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Tue, 14 Oct 2025 18:52:30 +0100 Subject: [PATCH 5/5] improve docs --- ...tivariate__option_a_stronger_priority__expected_flags.jsonc | 3 ++- ...tivariate__option_b_stronger_priority__expected_flags.jsonc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc index 401cf2b..f08e3dd 100644 --- a/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_a_stronger_priority__expected_flags.jsonc @@ -1,5 +1,6 @@ { - // Given: A multivariate feature with two variants of equal weight, where option_a has a stronger priority (lower priority number) + // Given: A multivariate feature with two variants of equal weight, where option_b has a stronger priority (lower priority number) + // and an identity resulting in 49.27% percentage allocation // When: Evaluating the feature for the given identity // Then: The variant with stronger priority (option_a) should be selected as the feature value "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", diff --git a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc index bd915fc..a2878e8 100644 --- a/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc +++ b/test_cases/test_multivariate__option_b_stronger_priority__expected_flags.jsonc @@ -1,5 +1,6 @@ { // Given: A multivariate feature with two variants of equal weight, where option_b has a stronger priority (lower priority number) + // and an identity resulting in 49.27% percentage allocation // When: Evaluating the feature for the given identity // Then: The variant with stronger priority (option_b) should be selected as the feature value "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",