Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(flags): lock v1 evaluator and projections to corpus (#96161)

Anders06feaad198b7
diff --git a/rust/feature-flags/src/flags/flag_matching.rs b/rust/feature-flags/src/flags/flag_matching.rs
index 1a2e41c9388f..a8250dbe0fe8 100644
--- a/rust/feature-flags/src/flags/flag_matching.rs
+++ b/rust/feature-flags/src/flags/flag_matching.rs
@@ -2172,9 +2172,9 @@ impl FeatureFlagMatcher {
request_hash_key_override,
)?;
if hashed_identifier.is_empty() {
- // Return a hash value that will make the flag evaluate to false; since we
- // can't evaluate a flag without an identifier.
- return Ok(0.0); // NB: A flag with 0.0 hash will always evaluate to false
+ // Nothing to hash. `check_rollout` compares `hash <= percentage / 100.0`, so a
+ // 0.0 hash matches every rollout threshold, including 0.
+ return Ok(0.0);
}
calculate_hash(&format!("{}.", feature_flag.key), &hashed_identifier, salt)
diff --git a/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/SOURCE.json b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/SOURCE.json
new file mode 100644
index 000000000000..0d627ae24753
--- /dev/null
+++ b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/SOURCE.json
@@ -0,0 +1,21 @@
+{
+ "source_repository": "https://github.com/PostHog/posthog-sdk-test-harness",
+ "source_path": "contracts/feature_flag_rules_v2",
+ "source_revision": "3de40b77efbe978057ea1d16a519b72cf6ec8e16",
+ "contract_version": "1.2.0",
+ "corpus_version": "1.1.0",
+ "source_sha256sums_digest": "b3457d860277f89407762abcf48774e3ef37bbf7c45693fee35cb4096a343e71",
+ "files": {
+ "manifest.json": "822b6d654bea1d928068c30477a9d437094d5a36edd8ad14cba94b5871bcbbfa",
+ "corpus/hash_sha1_60_v1.json": "e9bea9cff58bac0c6c1021e9c8842c53594055b6874a2c58bc4350d0c28a93ca",
+ "corpus/legacy_projection.json": "536c8386eefa75721d113bd8718ddeb7fb1aad3b4f2cce1fbcf516a346a16e26",
+ "corpus/v1_evaluation.json": "752ff88dcb943ab1e21f9552b0c4ec606029393fca2b565b01a497da89cd8675"
+ },
+ "update_procedure": [
+ "Never edit a vendored file in place. A changed expectation needs a new corpus version upstream and a review explanation there.",
+ "To move to a new version: check out the harness at the revision to vendor, copy manifest.json and corpus/*.json from source_path into a sibling directory named after the new contract version, and delete this one.",
+ "Record the revision, versions, and the SHA-256 of the upstream SHA256SUMS file (shasum -a 256 SHA256SUMS) in the new SOURCE.json.",
+ "Regenerate files with: (cd <new directory> && shasum -a 256 manifest.json corpus/*.json).",
+ "Point CORPUS_DIR in tests/test_rules_v2_v1_contract.rs at the new directory and reconcile UNSUPPORTED_CASE_IDS with the new manifest."
+ ]
+}
diff --git a/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/hash_sha1_60_v1.json b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/hash_sha1_60_v1.json
new file mode 100644
index 000000000000..21ddff6534f3
--- /dev/null
+++ b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/hash_sha1_60_v1.json
@@ -0,0 +1,660 @@
+{
+ "corpus_version": "1.1.0",
+ "algorithm": "sha1_60_v1",
+ "definition": {
+ "input": "UTF-8 bytes of prefix + identifier + salt concatenated with no separator and no escaping.",
+ "identifier_truncation": "Resolved identifiers are truncated to the first 200 Unicode scalar values before hashing. Bytes and UTF-16 code units are not the unit.",
+ "group_key_normalization": "Group keys that are JSON safe integers normalize to ordinary decimal strings. No Unicode normalization is applied to any identifier.",
+ "digest": "SHA-1 of the input bytes.",
+ "n": "The unsigned integer represented by the first 15 hexadecimal digest characters, equal to the first 60 digest bits. It is recorded as a decimal string because it exceeds the safe integer range of JSON consumers.",
+ "scale": "0xFFFFFFFFFFFFFFF, which is 2^60 - 1.",
+ "hash01": "binary64(n) / binary64(scale) using one IEEE-754 round-to-nearest-even division. binary64(scale) is exactly 2^60. Rounding the exact rational quotient once can differ in the last bit; vectors that differ record that alternative under hash01_if_quotient_rounded_once and it is not the contract value.",
+ "rollout": "rollout_percentage of 100 includes every identifier without hashing. Otherwise the identifier is included when hash01 <= rollout_percentage / 100, with the division performed in binary64.",
+ "holdout": "Legacy-era holdout membership uses prefix holdout-, an empty salt, and the same comparison as rollout against exclusion_percentage.",
+ "variant": "Each variant boundary is the previous boundary plus rollout_percentage / 100, accumulated left to right in binary64 in stored order. The first variant whose boundary satisfies hash01 < boundary is selected.",
+ "final_variant_fallback": "When no boundary satisfies the comparison, version 1 returns no variant and version 2 selects the final variant.",
+ "empty_identifier": "The hash arithmetic applied to an empty identifier hashes the prefix alone when the salt is empty, or the prefix plus salt otherwise. The version 1 Rust reference evaluator short-circuits rollout and variant hashing to 0.0 for an empty identifier and hashes the prefix alone only for holdouts. Version 2 never enters rollout, holdout, or variant assignment with an empty identifier, including at 100 percent.",
+ "salts": {
+ "rollout": "",
+ "variant": "variant",
+ "holdout": ""
+ },
+ "prefixes": {
+ "v1_rollout_and_variant": "flag key followed by a dot",
+ "v2_rollout_and_variant": "seed followed by a dot",
+ "legacy_era_holdout": "holdout-"
+ }
+ },
+ "vectors": [
+ {
+ "id": "hash.rollout.ascii_division_edge",
+ "purpose": "Ordinary rollout input whose quotient rounds differently when both operands convert to binary64 first.",
+ "prefix": "beta-search.",
+ "identifier": "user-17",
+ "salt": "",
+ "input": "beta-search.user-17",
+ "input_utf8_hex": "626574612d7365617263682e757365722d3137",
+ "sha1_hex": "02547515f0f76d52dc6ef8a6d021cde30b790da7",
+ "first_15_hex": "02547515f0f76d5",
+ "n": "10492988951066325",
+ "hash01": 0.009101217133290002,
+ "hash01_binary64_hex": "3f82a3a8af87bb6a",
+ "hash01_if_quotient_rounded_once": 0.009101217133290004,
+ "hash01_if_quotient_rounded_once_binary64_hex": "3f82a3a8af87bb6b",
+ "rollout_checks": [
+ {
+ "rollout_percentage": 0,
+ "threshold": 0.0,
+ "included": false
+ },
+ {
+ "rollout_percentage": 1,
+ "threshold": 0.01,
+ "included": true
+ },
+ {
+ "rollout_percentage": 25.5,
+ "threshold": 0.255,
+ "included": true
+ },
+ {
+ "rollout_percentage": 100,
+ "threshold": 1.0,
+ "included": true,
+ "short_circuit": true
+ }
+ ]
+ },
+ {
+ "id": "hash.rollout.ascii_excluded",
+ "purpose": "Rollout input just above a 28 percent threshold and just below a 29 percent threshold.",
+ "prefix": "beta-search-rollout.",
+ "identifier": "user-105",
+ "salt": "",
+ "input": "beta-search-rollout.user-105",
+ "input_utf8_hex": "626574612d7365617263682d726f6c6c6f75742e757365722d313035",
+ "sha1_hex": "48fe3fe11eaff7b8ffd4c3925d7ba32a2c34f1ce",
+ "first_15_hex": "48fe3fe11eaff7b",
+ "n": "328731978183147387",
+ "hash01": 0.2851295399293007,
+ "hash01_binary64_hex": "3fd23f8ff847abfe",
+ "rollout_checks": [
+ {
+ "rollout_percentage": 25.5,
+ "threshold": 0.255,
+ "included": false
+ },
+ {
+ "rollout_percentage": 28,
+ "threshold": 0.28,
+ "included": false
+ },
+ {
+ "rollout_percentage": 29,
+ "threshold": 0.29,
+ "included": true
+ }
+ ]
+ },
+ {
+ "id": "hash.variant.ascii",
+ "purpose": "Variant input with the literal salt appended after the identifier.",
+ "prefix": "checkout-layout.",
+ "identifier": "user-61",
+ "salt": "variant",
+ "input": "checkout-layout.user-61variant",
+ "input_utf8_hex": "636865636b6f75742d6c61796f75742e757365722d363176617269616e74",
+ "sha1_hex": "91e010d6e11120222c2b2541f8056a8b965d5efd",
+ "first_15_hex": "91e010d6e111202",
+ "n": "656963752835486210",
+ "hash01": 0.5698252224547713,
+ "hash01_binary64_hex": "3fe23c021adc2224",
+ "variant_check": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "compact",
+ "rollout_percentage": 25
+ },
+ {
+ "key": "spacious",
+ "rollout_percentage": 25
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.5,
+ 0.75,
+ 1.0
+ ],
+ "selected": "compact"
+ }
+ },
+ {
+ "id": "hash.holdout.literal_prefix",
+ "purpose": "Legacy-era holdout input uses the literal prefix holdout- with no dot separator and no salt.",
+ "prefix": "holdout-",
+ "identifier": "user-31",
+ "salt": "",
+ "input": "holdout-user-31",
+ "input_utf8_hex": "686f6c646f75742d757365722d3331",
+ "sha1_hex": "04fc4895fdca19f473ef6ac6cd7b3534c3e897d5",
+ "first_15_hex": "04fc4895fdca19f",
+ "n": "22452617458000287",
+ "hash01": 0.0194745413007599,
+ "hash01_binary64_hex": "3f93f12257f72868",
+ "holdout_checks": [
+ {
+ "exclusion_percentage": 10,
+ "threshold": 0.1,
+ "member": true
+ },
+ {
+ "exclusion_percentage": 1,
+ "threshold": 0.01,
+ "member": false
+ },
+ {
+ "exclusion_percentage": 100,
+ "threshold": 1.0,
+ "member": true,
+ "short_circuit": true
+ }
+ ]
+ },
+ {
+ "id": "hash.concatenation.no_separator_escaping",
+ "purpose": "Prefix, identifier, and salt concatenate as plain UTF-8 with no escaping, even when they contain dots.",
+ "prefix": "release.v2.",
+ "identifier": "a.b",
+ "salt": "variant",
+ "input": "release.v2.a.bvariant",
+ "input_utf8_hex": "72656c656173652e76322e612e6276617269616e74",
+ "sha1_hex": "c3605430acad3c22ec778899eb9e577d59032dea",
+ "first_15_hex": "c3605430acad3c2",
+ "n": "879896562699523010",
+ "hash01": 0.7631886118730806,
+ "hash01_binary64_hex": "3fe86c0a861595a8"
+ },
+ {
+ "id": "hash.identifier.empty",
+ "purpose": "The hash arithmetic applied to an empty identifier hashes the prefix alone when the salt is empty, or the prefix plus salt otherwise. The version 1 Rust reference evaluator short-circuits rollout and variant hashing to 0.0 for an empty identifier and hashes the prefix alone only for holdouts. Version 2 never enters rollout, holdout, or variant assignment with an empty identifier, including at 100 percent.",
+ "prefix": "beta-search.",
+ "identifier": "",
+ "salt": "",
+ "input": "beta-search.",
+ "input_utf8_hex": "626574612d7365617263682e",
+ "sha1_hex": "9f06c3435db4fc81881a8f50a9f1b58a465ba5f6",
+ "first_15_hex": "9f06c3435db4fc8",
+ "n": "716191312249573320",
+ "hash01": 0.6211969413249854,
+ "hash01_binary64_hex": "3fe3e0d8686bb6a0",
+ "identifier_empty": true,
+ "v2_rule": "empty_identifier_never_enters_rollout"
+ },
+ {
+ "id": "hash.identifier.unicode_utf8",
+ "purpose": "Non-ASCII identifiers hash their UTF-8 bytes with no Unicode normalization.",
+ "prefix": "beta-search.",
+ "identifier": "ünïcødé-😀",
+ "salt": "",
+ "input": "beta-search.ünïcødé-😀",
+ "input_utf8_hex": "626574612d7365617263682ec3bc6ec3af63c3b864c3a92df09f9880",
+ "sha1_hex": "bdd4564f8af8aaeea949f8f15e2b34613dabda56",
+ "first_15_hex": "bdd4564f8af8aae",
+ "n": "854915804241562286",
+ "hash01": 0.7415212578007152,
+ "hash01_binary64_hex": "3fe7ba8ac9f15f15",
+ "rollout_checks": [
+ {
+ "rollout_percentage": 50,
+ "threshold": 0.5,
+ "included": false
+ }
+ ]
+ },
+ {
+ "id": "hash.identifier.truncated_ascii",
+ "purpose": "Identifiers longer than 200 Unicode scalar values are truncated to the first 200 before hashing.",
+ "prefix": "beta-search.",
+ "identifier": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "salt": "",
+ "input": "beta-search.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "input_utf8_hex": "626574612d7365617263682e6161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161",
+ "sha1_hex": "1b8416aab94af161be4c63449a6f4075192bc570",
+ "first_15_hex": "1b8416aab94af16",
+ "n": "123920916153675542",
+ "hash01": 0.10748426120816724,
+ "hash01_binary64_hex": "3fbb8416aab94af1",
+ "identifier_before_truncation": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "identifier_before_truncation_scalar_values": 205,
+ "identifier_scalar_values": 200,
+ "identifier_utf8_bytes": 200,
+ "identifier_utf16_code_units": 200
+ },
+ {
+ "id": "hash.identifier.truncated_scalar_values",
+ "purpose": "Truncation counts Unicode scalar values: the 200th value is a non-BMP character, which a UTF-16 code unit slice or a byte slice would split.",
+ "prefix": "beta-search.",
+ "identifier": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀",
+ "salt": "",
+ "input": "beta-search.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀",
+ "input_utf8_hex": "626574612d7365617263682e61616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161f09f9880",
+ "sha1_hex": "a0ea6b953860b06b72512954d56751650e87aae3",
+ "first_15_hex": "a0ea6b953860b06",
+ "n": "724699904953682694",
+ "hash01": 0.6285769690806571,
+ "hash01_binary64_hex": "3fe41d4d72a70c16",
+ "identifier_before_truncation": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀bbbbbbbbbb",
+ "identifier_before_truncation_scalar_values": 210,
+ "identifier_scalar_values": 200,
+ "identifier_utf8_bytes": 203,
+ "identifier_utf16_code_units": 201
+ },
+ {
+ "id": "hash.identifier.exactly_200_multibyte",
+ "purpose": "An identifier of exactly 200 scalar values is not truncated even though it is 400 UTF-8 bytes.",
+ "prefix": "beta-search.",
+ "identifier": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
+ "salt": "",
+ "input": "beta-search.éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
+ "input_utf8_hex": "626574612d7365617263682ec3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9c3a9",
+ "sha1_hex": "6963dfbb1a9856a6c8997cd4a98b1847fb4f30a4",
+ "first_15_hex": "6963dfbb1a9856a",
+ "n": "474634961960928618",
+ "hash01": 0.41168020551649087,
+ "hash01_binary64_hex": "3fda58f7eec6a616",
+ "identifier_before_truncation": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
+ "identifier_before_truncation_scalar_values": 200,
+ "identifier_scalar_values": 200,
+ "identifier_utf8_bytes": 400,
+ "identifier_utf16_code_units": 200
+ },
+ {
+ "id": "hash.identifier.integer_group_key",
+ "purpose": "A JSON number group key 42 normalizes to the decimal string 42 before hashing.",
+ "prefix": "org-dashboard.",
+ "identifier": "42",
+ "salt": "",
+ "input": "org-dashboard.42",
+ "input_utf8_hex": "6f72672d64617368626f6172642e3432",
+ "sha1_hex": "9988fe571337916302049584762d1ecf2e589d1a",
+ "first_15_hex": "9988fe571337916",
+ "n": "691460758410852630",
+ "hash01": 0.5997466051660167,
+ "hash01_binary64_hex": "3fe3311fcae266f2",
+ "rollout_checks": [
+ {
+ "rollout_percentage": 60,
+ "threshold": 0.6,
+ "included": true
+ },
+ {
+ "rollout_percentage": 59,
+ "threshold": 0.59,
+ "included": false
+ }
+ ],
+ "identifier_source": {
+ "json_group_key": 42
+ }
+ }
+ ],
+ "threshold_vectors": [
+ {
+ "id": "threshold.equal_is_included",
+ "hash01": 0.5,
+ "rollout_percentage": 50,
+ "threshold": 0.5,
+ "included": true,
+ "note": "hash01 equal to the threshold is included because the comparison is less than or equal."
+ },
+ {
+ "id": "threshold.next_binary64_above_is_excluded",
+ "hash01": 0.5000000000000001,
+ "rollout_percentage": 50,
+ "threshold": 0.5,
+ "included": false,
+ "note": "The next binary64 value above the threshold is excluded."
+ },
+ {
+ "id": "threshold.zero_percent_zero_hash",
+ "hash01": 0.0,
+ "rollout_percentage": 0,
+ "threshold": 0.0,
+ "included": true,
+ "note": "Zero percent has no special case; only a hash01 of exactly zero satisfies the comparison."
+ },
+ {
+ "id": "threshold.zero_percent_smallest_hash",
+ "hash01": 8.673617379884035e-19,
+ "rollout_percentage": 0,
+ "threshold": 0.0,
+ "included": false,
+ "note": "The smallest nonzero hash01 is excluded at zero percent."
+ },
+ {
+ "id": "threshold.hundred_percent_short_circuit",
+ "hash01": 1.0,
+ "rollout_percentage": 100,
+ "threshold": 1.0,
+ "included": true,
+ "short_circuit": true,
+ "note": "One hundred percent includes every identifier without computing a hash."
+ },
+ {
+ "id": "threshold.two_decimal_division_equal",
+ "hash01": 0.33340000000000003,
+ "rollout_percentage": 33.34,
+ "threshold": 0.33340000000000003,
+ "included": true,
+ "note": "The threshold is the binary64 quotient rollout_percentage / 100, which differs from the parsed decimal literal 0.3334.",
+ "parsed_decimal_literal": 0.3334
+ },
+ {
+ "id": "threshold.two_decimal_division_excluded",
+ "hash01": 0.6667000000000002,
+ "rollout_percentage": 66.67,
+ "threshold": 0.6667000000000001,
+ "included": false,
+ "note": "The next binary64 value above the 66.67 quotient is excluded."
+ },
+ {
+ "id": "threshold.two_decimal_division_included_below_quotient",
+ "hash01": 0.999,
+ "rollout_percentage": 99.9,
+ "threshold": 0.9990000000000001,
+ "included": true,
+ "note": "The parsed literal 0.999 is below the 99.9 quotient and is included.",
+ "parsed_decimal_literal": 0.999
+ }
+ ],
+ "variant_vectors": [
+ {
+ "id": "variant.zero_hash_first_variant",
+ "hash01": 0.0,
+ "note": "A hash01 of zero selects the first variant.",
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.5,
+ 1.0
+ ],
+ "selected": "control"
+ },
+ {
+ "id": "variant.boundary_is_exclusive",
+ "hash01": 0.5,
+ "note": "A hash01 equal to a cumulative boundary belongs to the next variant because the comparison is strictly less than.",
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.5,
+ 1.0
+ ],
+ "selected": "test"
+ },
+ {
+ "id": "variant.just_below_boundary",
+ "hash01": 0.49999999999999994,
+ "note": "The largest binary64 value below the first boundary selects the first variant.",
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.5,
+ 1.0
+ ],
+ "selected": "control"
+ },
+ {
+ "id": "variant.accumulated_boundary_left_to_right",
+ "hash01": 0.3,
+ "note": "Boundaries accumulate left to right in binary64, so the second boundary is 0.30000000000000004 and a hash01 of 0.3 still selects the second variant.",
+ "variants": [
+ {
+ "key": "ten",
+ "rollout_percentage": 10
+ },
+ {
+ "key": "twenty",
+ "rollout_percentage": 20
+ },
+ {
+ "key": "thirty",
+ "rollout_percentage": 30
+ },
+ {
+ "key": "forty",
+ "rollout_percentage": 40
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.1,
+ 0.30000000000000004,
+ 0.6000000000000001,
+ 1.0
+ ],
+ "selected": "twenty",
+ "parsed_decimal_literal_boundary": 0.3
+ },
+ {
+ "id": "variant.accumulated_boundary_third",
+ "hash01": 0.6,
+ "note": "The third accumulated boundary is 0.6000000000000001, so a hash01 of 0.6 selects the third variant.",
+ "variants": [
+ {
+ "key": "ten",
+ "rollout_percentage": 10
+ },
+ {
+ "key": "twenty",
+ "rollout_percentage": 20
+ },
+ {
+ "key": "thirty",
+ "rollout_percentage": 30
+ },
+ {
+ "key": "forty",
+ "rollout_percentage": 40
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.1,
+ 0.30000000000000004,
+ 0.6000000000000001,
+ 1.0
+ ],
+ "selected": "thirty",
+ "parsed_decimal_literal_boundary": 0.6
+ },
+ {
+ "id": "variant.two_decimal_weights_boundary",
+ "hash01": 0.6666,
+ "note": "Two-decimal weights accumulate to 0.3333, 0.6666, and exactly 1.0; a hash01 equal to the second boundary selects the third variant.",
+ "variants": [
+ {
+ "key": "a",
+ "rollout_percentage": 33.33
+ },
+ {
+ "key": "b",
+ "rollout_percentage": 33.33
+ },
+ {
+ "key": "c",
+ "rollout_percentage": 33.34
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.3333,
+ 0.6666,
+ 1.0
+ ],
+ "selected": "c"
+ },
+ {
+ "id": "variant.hash_one_off_the_end",
+ "hash01": 1.0,
+ "note": "A hash01 of exactly 1.0 is beyond the final boundary. Version 1 returns no variant, which projects as boolean true. Version 2 selects the final variant.",
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.5,
+ 1.0
+ ],
+ "selected": null,
+ "v1_result": "no_variant_boolean_true",
+ "v2_rule": "final_variant_fallback",
+ "v2_selected": "test"
+ },
+ {
+ "id": "variant.sum_below_one_off_the_end",
+ "hash01": 0.9999999999999999,
+ "note": "Weights that sum to exactly 100 can accumulate to 0.9999999999999999 in binary64, so a hash01 of 0.9999999999999999 is beyond the final boundary.",
+ "variants": [
+ {
+ "key": "a",
+ "rollout_percentage": 1.01
+ },
+ {
+ "key": "b",
+ "rollout_percentage": 10.02
+ },
+ {
+ "key": "c",
+ "rollout_percentage": 88.97
+ }
+ ],
+ "cumulative_boundaries": [
+ 0.0101,
+ 0.1103,
+ 0.9999999999999999
+ ],
+ "selected": null,
+ "v1_result": "no_variant_boolean_true",
+ "v2_rule": "final_variant_fallback",
+ "v2_selected": "c"
+ }
+ ],
+ "seed_parity": [
+ {
+ "id": "parity.rollout_identical_bytes",
+ "flag_key": "beta-search",
+ "identifier": "user-17",
+ "salt": "",
+ "v1_input": "beta-search.user-17",
+ "v2": {
+ "seed": "beta-search",
+ "prefix": "beta-search.",
+ "identifier": "user-17",
+ "salt": "",
+ "input": "beta-search.user-17"
+ },
+ "identical_bytes": true,
+ "identical_outcome": true,
+ "hash01": 0.009101217133290002,
+ "note": "Conversion sets seed = flag key, so the v2 rollout input is byte-identical to the v1 input."
+ },
+ {
+ "id": "parity.variant_identical_bytes",
+ "flag_key": "checkout-layout",
+ "identifier": "user-61",
+ "salt": "variant",
+ "v1_input": "checkout-layout.user-61variant",
+ "v2": {
+ "seed": "checkout-layout",
+ "prefix": "checkout-layout.",
+ "identifier": "user-61",
+ "salt": "variant",
+ "input": "checkout-layout.user-61variant"
+ },
+ "identical_bytes": true,
+ "identical_outcome": true,
+ "hash01": 0.5698252224547713,
+ "note": "The variant salt is unchanged by conversion."
+ },
+ {
+ "id": "parity.holdout_identical_bytes",
+ "flag_key": "checkout-experiment",
+ "identifier": "user-31",
+ "salt": "",
+ "v1_input": "holdout-user-31",
+ "v2": {
+ "seed": "holdout-",
+ "prefix": "holdout-",
+ "identifier": "user-31",
+ "salt": "",
+ "input": "holdout-user-31"
+ },
+ "identical_bytes": true,
+ "identical_outcome": true,
+ "hash01": 0.0194745413007599,
+ "note": "The legacy-era holdout seed is the literal holdout- prefix in both versions."
+ },
+ {
+ "id": "parity.empty_identifier_divergent",
+ "flag_key": "beta-search",
+ "identifier": "",
+ "salt": "",
+ "v1_input": "beta-search.",
+ "v2": {
+ "seed": "beta-search",
+ "prefix": "beta-search.",
+ "identifier": "",
+ "salt": "",
+ "input": "beta-search."
+ },
+ "identical_bytes": true,
+ "identical_outcome": false,
+ "hash01": 0.6211969413249854,
+ "divergence": "empty_identifier",
+ "note": "The recorded arithmetic inputs have identical bytes; hash01 describes prefix-alone hashing, not the version 1 rollout outcome. The hash arithmetic applied to an empty identifier hashes the prefix alone when the salt is empty, or the prefix plus salt otherwise. The version 1 Rust reference evaluator short-circuits rollout and variant hashing to 0.0 for an empty identifier and hashes the prefix alone only for holdouts. Version 2 never enters rollout, holdout, or variant assignment with an empty identifier, including at 100 percent."
+ },
+ {
+ "id": "parity.final_variant_fallback_divergent",
+ "flag_key": "checkout-layout",
+ "identifier": null,
+ "salt": "variant",
+ "hash01": 1.0,
+ "identical_bytes": true,
+ "identical_outcome": false,
+ "divergence": "final_variant_fallback",
+ "note": "White-box hash01 of 1.0. Version 1 returns no variant and projects boolean true; version 2 selects the final variant. See variant.hash_one_off_the_end."
+ }
+ ]
+}
diff --git a/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/legacy_projection.json b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/legacy_projection.json
new file mode 100644
index 000000000000..3a144281c81d
--- /dev/null
+++ b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/legacy_projection.json
@@ -0,0 +1,661 @@
+{
+ "corpus_version": "1.1.0",
+ "config_version": 1,
+ "description": "Projection matrix from a version 1 evaluation outcome to each response protocol version. Response protocol versions are independent of the config version, which is 1 for every case.",
+ "response_protocols": {
+ "flags_v2": {
+ "endpoint": "/flags",
+ "selected_by": "v=2 or higher, or /decide with v=4 or higher",
+ "shape": "flags map of evaluation details with reason and metadata; errorsWhileComputingFlags at the top level"
+ },
+ "flags_v1": {
+ "endpoint": "/flags",
+ "selected_by": "v=1 or absent, or /decide with v=3",
+ "shape": "featureFlags map of every evaluated flag plus featureFlagPayloads for flags with a payload; errorsWhileComputingFlags at the top level"
+ },
+ "decide_v2": {
+ "endpoint": "/decide",
+ "selected_by": "v=2",
+ "shape": "featureFlags map of enabled flags only"
+ },
+ "decide_v1": {
+ "endpoint": "/decide",
+ "selected_by": "v=1 or absent",
+ "shape": "featureFlags list of enabled flag keys"
+ }
+ },
+ "asserted_fields": "flags_v2 records key, enabled, variant, failed when true, reason.code, reason.condition_index, metadata.id, metadata.version, and metadata.payload. Live responses carry additional request-level and metadata fields that this corpus does not pin.",
+ "cases": [
+ {
+ "id": "projection.boolean_true",
+ "config_version": 1,
+ "outcome": {
+ "key": "beta-search",
+ "flag_id": 101,
+ "flag_version": 3,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "beta-search": {
+ "key": "beta-search",
+ "enabled": true,
+ "variant": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "metadata": {
+ "id": 101,
+ "version": 3,
+ "payload": null
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "beta-search": true
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {
+ "beta-search": true
+ }
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": [
+ "beta-search"
+ ]
+ }
+ }
+ },
+ {
+ "id": "projection.boolean_true_with_payload",
+ "config_version": 1,
+ "outcome": {
+ "key": "beta-search",
+ "flag_id": 101,
+ "flag_version": 3,
+ "enabled": true,
+ "variant": null,
+ "payload": "{\"cta\":\"Try beta search\"}",
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "beta-search": {
+ "key": "beta-search",
+ "enabled": true,
+ "variant": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "metadata": {
+ "id": 101,
+ "version": 3,
+ "payload": "{\"cta\":\"Try beta search\"}"
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "beta-search": true
+ },
+ "featureFlagPayloads": {
+ "beta-search": "{\"cta\":\"Try beta search\"}"
+ }
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {
+ "beta-search": true
+ }
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": [
+ "beta-search"
+ ]
+ }
+ },
+ "notes": "The payload is the stored JSON string; no response version parses it."
+ },
+ {
+ "id": "projection.boolean_false_targeting_miss",
+ "config_version": 1,
+ "outcome": {
+ "key": "beta-search",
+ "flag_id": 101,
+ "flag_version": 3,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "no_condition_match",
+ "condition_index": 0
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "beta-search": {
+ "key": "beta-search",
+ "enabled": false,
+ "variant": null,
+ "reason": {
+ "code": "no_condition_match",
+ "condition_index": 0
+ },
+ "metadata": {
+ "id": 101,
+ "version": 3,
+ "payload": null
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "beta-search": false
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {}
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": []
+ }
+ },
+ "notes": "Every evaluated flag appears in the flags_v1 map, including false results. decide_v2 and decide_v1 carry enabled flags only."
+ },
+ {
+ "id": "projection.boolean_false_out_of_rollout",
+ "config_version": 1,
+ "outcome": {
+ "key": "beta-search-rollout",
+ "flag_id": 102,
+ "flag_version": 1,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 0
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "beta-search-rollout": {
+ "key": "beta-search-rollout",
+ "enabled": false,
+ "variant": null,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 0
+ },
+ "metadata": {
+ "id": 102,
+ "version": 1,
+ "payload": null
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "beta-search-rollout": false
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {}
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": []
+ }
+ }
+ },
+ {
+ "id": "projection.variant",
+ "config_version": 1,
+ "outcome": {
+ "key": "checkout-layout",
+ "flag_id": 106,
+ "flag_version": 5,
+ "enabled": true,
+ "variant": "control",
+ "payload": null,
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "checkout-layout": {
+ "key": "checkout-layout",
+ "enabled": true,
+ "variant": "control",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ },
+ "metadata": {
+ "id": 106,
+ "version": 5,
+ "payload": null
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "checkout-layout": "control"
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {
+ "checkout-layout": "control"
+ }
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": [
+ "checkout-layout"
+ ]
+ }
+ },
+ "notes": "A variant projects as its string in every map and as membership in the list."
+ },
+ {
+ "id": "projection.variant_with_payload",
+ "config_version": 1,
+ "outcome": {
+ "key": "checkout-layout",
+ "flag_id": 106,
+ "flag_version": 5,
+ "enabled": true,
+ "variant": "compact",
+ "payload": "{\"density\":\"compact\"}",
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "checkout-layout": {
+ "key": "checkout-layout",
+ "enabled": true,
+ "variant": "compact",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ },
+ "metadata": {
+ "id": 106,
+ "version": 5,
+ "payload": "{\"density\":\"compact\"}"
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "checkout-layout": "compact"
+ },
+ "featureFlagPayloads": {
+ "checkout-layout": "{\"density\":\"compact\"}"
+ }
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {
+ "checkout-layout": "compact"
+ }
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": [
+ "checkout-layout"
+ ]
+ }
+ }
+ },
+ {
+ "id": "projection.holdout_variant",
+ "config_version": 1,
+ "outcome": {
+ "key": "checkout-experiment",
+ "flag_id": 113,
+ "flag_version": 4,
+ "enabled": true,
+ "variant": "holdout-7",
+ "payload": null,
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "holdout_condition_value",
+ "condition_index": null
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "checkout-experiment": {
+ "key": "checkout-experiment",
+ "enabled": true,
+ "variant": "holdout-7",
+ "reason": {
+ "code": "holdout_condition_value",
+ "condition_index": null
+ },
+ "metadata": {
+ "id": 113,
+ "version": 4,
+ "payload": null
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "checkout-experiment": "holdout-7"
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {
+ "checkout-experiment": "holdout-7"
+ }
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": [
+ "checkout-experiment"
+ ]
+ }
+ },
+ "notes": "The synthesized holdout variant projects like any other string value."
+ },
+ {
+ "id": "projection.no_group_type",
+ "config_version": 1,
+ "outcome": {
+ "key": "org-dashboard",
+ "flag_id": 109,
+ "flag_version": 2,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "no_group_type",
+ "condition_index": 0
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "org-dashboard": {
+ "key": "org-dashboard",
+ "enabled": false,
+ "variant": null,
+ "reason": {
+ "code": "no_group_type",
+ "condition_index": 0
+ },
+ "metadata": {
+ "id": 109,
+ "version": 2,
+ "payload": null
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "org-dashboard": false
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {}
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": []
+ }
+ }
+ },
+ {
+ "id": "projection.missing_dependency",
+ "config_version": 1,
+ "outcome": {
+ "key": "beta-search-suggestions-orphan",
+ "flag_id": 112,
+ "flag_version": 1,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "failed": false,
+ "omitted": false,
+ "reason": {
+ "code": "missing_dependency",
+ "condition_index": null
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {
+ "beta-search-suggestions-orphan": {
+ "key": "beta-search-suggestions-orphan",
+ "enabled": false,
+ "variant": null,
+ "reason": {
+ "code": "missing_dependency",
+ "condition_index": null
+ },
+ "metadata": {
+ "id": 112,
+ "version": 1,
+ "payload": null
+ }
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {
+ "beta-search-suggestions-orphan": false
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {}
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": []
+ }
+ },
+ "notes": "A missing dependency is a closed false result, not an evaluation failure, so errorsWhileComputingFlags stays false."
+ },
+ {
+ "id": "projection.failed_evaluation",
+ "config_version": 1,
+ "outcome": {
+ "key": "beta-search",
+ "flag_id": 101,
+ "flag_version": 3,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "failed": true,
+ "omitted": false,
+ "reason": {
+ "code": "timeout",
+ "condition_index": null
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": true,
+ "flags": {
+ "beta-search": {
+ "key": "beta-search",
+ "enabled": false,
+ "variant": null,
+ "reason": {
+ "code": "timeout",
+ "condition_index": null
+ },
+ "metadata": {
+ "id": 101,
+ "version": 3,
+ "payload": null
+ },
+ "failed": true
+ }
+ }
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": true,
+ "featureFlags": {
+ "beta-search": false
+ },
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {}
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": []
+ }
+ },
+ "notes": "A failed evaluation projects as false in the flags_v1 map with errorsWhileComputingFlags true, is omitted from decide_v2 and decide_v1, and carries failed true in flags_v2. The reason code is representative."
+ },
+ {
+ "id": "projection.inactive_omitted",
+ "config_version": 1,
+ "outcome": {
+ "key": "retired-banner",
+ "flag_id": 114,
+ "flag_version": 9,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "failed": false,
+ "omitted": true,
+ "reason": {
+ "code": "no_condition_match",
+ "condition_index": null
+ }
+ },
+ "projections": {
+ "flags_v2": {
+ "response_version": 2,
+ "errorsWhileComputingFlags": false,
+ "flags": {}
+ },
+ "flags_v1": {
+ "response_version": 1,
+ "errorsWhileComputingFlags": false,
+ "featureFlags": {},
+ "featureFlagPayloads": {}
+ },
+ "decide_v2": {
+ "response_version": 2,
+ "featureFlags": {}
+ },
+ "decide_v1": {
+ "response_version": 1,
+ "featureFlags": []
+ }
+ },
+ "notes": "Inactive, archived, and deleted flags are omitted from every response version."
+ }
+ ]
+}
diff --git a/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/v1_evaluation.json b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/v1_evaluation.json
new file mode 100644
index 000000000000..bd2d69467e15
--- /dev/null
+++ b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/corpus/v1_evaluation.json
@@ -0,0 +1,2255 @@
+{
+ "corpus_version": "1.1.0",
+ "config_version": 1,
+ "description": "Lock-down fixtures for the frozen version 1 evaluation arm. Each case supplies complete flag definitions and an evaluation context and records the hand-derived outcome.",
+ "definition_shape": "definitions.flags uses the local evaluation feed shape: id, key, version, active, and filters with groups, multivariate, payloads, aggregation_group_type_index, holdout, and early_exit. Flag dependency filters carry the target flag key in key plus dependency_chain; server-side evaluators map the key to the fixture flag id.",
+ "context_shape": "context carries distinct_id, person_properties, and optionally groups, group_properties. definitions.group_type_mapping maps group type index strings to group type names. An empty distinct_id is valid in version 1; the field remains required.",
+ "expectation_rules": {
+ "value": "Every conforming evaluator returns this value: boolean, or the assigned variant string.",
+ "enabled_and_variant": "The detailed projection fields: enabled is true for any truthy value and variant is the string value or null.",
+ "payload": "The stored payload under the key true or the assigned variant key, or null.",
+ "reason": "The authoritative evaluator's reason code and condition index. condition_index is the stored position of the condition that produced the reason, or null.",
+ "local_evaluation": "conclusive: a local evaluator must return value. inconclusive: a local evaluator must not return a value and must fall back to the authoritative evaluator. remote_only: the case pins authoritative behavior for a feature that local evaluators do not implement; a local evaluator that implements it must match.",
+ "omitted_flags": "Flags absent from every remote response version. A local evaluator reports them as false.",
+ "hash_evidence": "sha1_60_v1 arithmetic computed from the recorded input. included and selected describe that arithmetic. For empty-identifier rollout and variant cases this is counterfactual evidence: the reference uses 0.0 without computing SHA-1, so expected records the authoritative outcome and notes explain its difference from the evidence. Empty-identifier holdouts use the recorded hash normally. Cases without evidence require no hash arithmetic to explain their outcome.",
+ "empty_identifier": "The frozen version 1 arm is defined by the Rust /flags reference evaluator. It accepts an empty distinct_id, short-circuits rollout and variant hashing to 0.0, and hashes the prefix alone for holdouts. The empty-identifier cases are remote_only because Python local evaluation does not implement the reference short-circuit or holdouts. This marker does not claim that the SDK falls back: it currently returns divergent values. A later deliberate reference change requires a new corpus version."
+ },
+ "reason_codes": [
+ "condition_match",
+ "no_condition_match",
+ "out_of_rollout_bound",
+ "no_group_type",
+ "holdout_condition_value",
+ "missing_dependency"
+ ],
+ "cases": [
+ {
+ "id": "v1.boolean.targeted_match_with_payload",
+ "definitions": {
+ "flags": [
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ],
+ "payloads": {
+ "true": "{\"cta\":\"Try beta search\"}"
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": "{\"cta\":\"Try beta search\"}",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "The property filter matches and rollout_percentage 100 short-circuits, so no hash is computed. The payload stored under the key true is attached."
+ },
+ {
+ "id": "v1.boolean.targeting_miss",
+ "definitions": {
+ "flags": [
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ],
+ "payloads": {
+ "true": "{\"cta\":\"Try beta search\"}"
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "no_condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "The only condition fails its property filter, so no rollout check runs."
+ },
+ {
+ "id": "v1.boolean.rollout_included",
+ "definitions": {
+ "flags": [
+ {
+ "id": 102,
+ "key": "beta-search-rollout",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 25.5
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-61",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "beta-search-rollout": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search-rollout.user-61",
+ "hash01": 0.0042305989144046955,
+ "threshold_percentage": 25.5,
+ "threshold": 0.255,
+ "included": true
+ }
+ ],
+ "notes": "An empty property list means the condition is a pure rollout check."
+ },
+ {
+ "id": "v1.boolean.rollout_excluded",
+ "definitions": {
+ "flags": [
+ {
+ "id": 102,
+ "key": "beta-search-rollout",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 25.5
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-105",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "beta-search-rollout": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search-rollout.user-105",
+ "hash01": 0.2851295399293007,
+ "threshold_percentage": 25.5,
+ "threshold": 0.255,
+ "included": false
+ }
+ ]
+ },
+ {
+ "id": "v1.boolean.rollout_miss_continues_to_lower_condition",
+ "definitions": {
+ "flags": [
+ {
+ "id": 103,
+ "key": "beta-search-staged",
+ "version": 2,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 10
+ },
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-105",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search-staged": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search-staged.user-105",
+ "hash01": 0.16767177534121008,
+ "threshold_percentage": 10,
+ "threshold": 0.1,
+ "included": false
+ }
+ ],
+ "notes": "Without early_exit a rollout miss on condition 0 continues; condition 1 matches at 100 percent and reports its own index."
+ },
+ {
+ "id": "v1.boolean.rollout_miss_early_exit",
+ "definitions": {
+ "flags": [
+ {
+ "id": 104,
+ "key": "beta-search-staged-early-exit",
+ "version": 2,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 10
+ },
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ],
+ "early_exit": true
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-105",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search-staged-early-exit": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search-staged-early-exit.user-105",
+ "hash01": 0.5658264965789109,
+ "threshold_percentage": 10,
+ "threshold": 0.1,
+ "included": false
+ }
+ ],
+ "notes": "With early_exit true the rollout miss on condition 0 is terminal even though condition 1 would match."
+ },
+ {
+ "id": "v1.boolean.reason_priority_keeps_earlier_rollout_miss",
+ "definitions": {
+ "flags": [
+ {
+ "id": 103,
+ "key": "beta-search-staged",
+ "version": 2,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 10
+ },
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-105",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search-staged": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search-staged.user-105",
+ "hash01": 0.16767177534121008,
+ "threshold_percentage": 10,
+ "threshold": 0.1,
+ "included": false
+ }
+ ],
+ "notes": "Condition 0 misses rollout and condition 1 misses targeting. out_of_rollout_bound outranks no_condition_match, so the reported index stays 0."
+ },
+ {
+ "id": "v1.boolean.reason_priority_prefers_later_rollout_miss",
+ "definitions": {
+ "flags": [
+ {
+ "id": 105,
+ "key": "beta-search-staged-reversed",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ },
+ {
+ "properties": [],
+ "rollout_percentage": 10
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-105",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search-staged-reversed": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 1
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search-staged-reversed.user-105",
+ "hash01": 0.18439866572143454,
+ "threshold_percentage": 10,
+ "threshold": 0.1,
+ "included": false
+ }
+ ],
+ "notes": "Condition 0 misses targeting and condition 1 misses rollout. The higher-priority reason wins regardless of order, so the reported index is 1."
+ },
+ {
+ "id": "v1.boolean.null_rollout_is_100",
+ "definitions": {
+ "flags": [
+ {
+ "id": 115,
+ "key": "nav-refresh",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": null
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "nav-refresh": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "A null rollout_percentage behaves as 100 and computes no hash."
+ },
+ {
+ "id": "v1.boolean.empty_distinct_id_included_at_zero_percent",
+ "definitions": {
+ "flags": [
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 0
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "remote_only"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search.",
+ "hash01": 0.6211969413249854,
+ "threshold_percentage": 0,
+ "threshold": 0.0,
+ "included": false
+ }
+ ],
+ "notes": "The version 1 Rust reference accepts the empty distinct_id and get_hash returns 0.0 without calling calculate_hash. Zero percent pins the inclusive comparison at its lowest threshold: 0.0 <= 0 / 100. The hash_evidence records the counterfactual prefix-alone arithmetic, including its false inclusion result; the authoritative expected value uses 0.0 and is true with condition_match. Python local evaluation at a1002c577e7c69e3f321f8f0832ee037316135a3 hashes the prefix alone and returns false, rather than falling back. remote_only pins the reference behavior that the SDK does not implement; this is a known SDK divergence, not an inconclusive result."
+ },
+ {
+ "id": "v1.boolean.empty_distinct_id_included_below_prefix_hash",
+ "definitions": {
+ "flags": [
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 62
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "remote_only"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "beta-search.",
+ "hash01": 0.6211969413249854,
+ "threshold_percentage": 62,
+ "threshold": 0.62,
+ "included": false
+ }
+ ],
+ "notes": "The version 1 Rust reference accepts the empty distinct_id and get_hash returns 0.0 without calling calculate_hash. 62 percent is just below the prefix-alone hash 0.6211969413249854: hashing beta-search. would exclude at 62 percent and include at 63 percent, while the reference includes at both. The hash_evidence records the counterfactual prefix-alone arithmetic, including its false inclusion result; the authoritative expected value uses 0.0 and is true with condition_match. Python local evaluation at a1002c577e7c69e3f321f8f0832ee037316135a3 hashes the prefix alone and returns false, rather than falling back. remote_only pins the reference behavior that the SDK does not implement; this is a known SDK divergence, not an inconclusive result."
+ },
+ {
+ "id": "v1.multivariate.variant_from_hash_with_payload",
+ "definitions": {
+ "flags": [
+ {
+ "id": 106,
+ "key": "checkout-layout",
+ "version": 5,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100,
+ "variant": "spacious"
+ },
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "compact",
+ "rollout_percentage": 25
+ },
+ {
+ "key": "spacious",
+ "rollout_percentage": 25
+ }
+ ]
+ },
+ "payloads": {
+ "compact": "{\"density\":\"compact\"}"
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-61",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout": {
+ "value": "compact",
+ "enabled": true,
+ "variant": "compact",
+ "payload": "{\"density\":\"compact\"}",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "variant",
+ "input": "checkout-layout.user-61variant",
+ "hash01": 0.5698252224547713,
+ "cumulative_boundaries": [
+ 0.5,
+ 0.75,
+ 1.0
+ ],
+ "selected": "compact"
+ }
+ ],
+ "notes": "Condition 0 misses targeting. Condition 1 matches at 100 percent, so only the variant hash is computed. The payload stored under the variant key is attached."
+ },
+ {
+ "id": "v1.multivariate.variant_from_hash_control",
+ "definitions": {
+ "flags": [
+ {
+ "id": 106,
+ "key": "checkout-layout",
+ "version": 5,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100,
+ "variant": "spacious"
+ },
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "compact",
+ "rollout_percentage": 25
+ },
+ {
+ "key": "spacious",
+ "rollout_percentage": 25
+ }
+ ]
+ },
+ "payloads": {
+ "compact": "{\"density\":\"compact\"}"
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout": {
+ "value": "control",
+ "enabled": true,
+ "variant": "control",
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "variant",
+ "input": "checkout-layout.user-17variant",
+ "hash01": 0.13678069113210306,
+ "cumulative_boundaries": [
+ 0.5,
+ 0.75,
+ 1.0
+ ],
+ "selected": "control"
+ }
+ ],
+ "notes": "No payload is stored under control, so payload is null."
+ },
+ {
+ "id": "v1.multivariate.variant_override",
+ "definitions": {
+ "flags": [
+ {
+ "id": 106,
+ "key": "checkout-layout",
+ "version": 5,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100,
+ "variant": "spacious"
+ },
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "compact",
+ "rollout_percentage": 25
+ },
+ {
+ "key": "spacious",
+ "rollout_percentage": 25
+ }
+ ]
+ },
+ "payloads": {
+ "compact": "{\"density\":\"compact\"}"
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-61",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout": {
+ "value": "spacious",
+ "enabled": true,
+ "variant": "spacious",
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "Condition 0 matches targeting and carries a valid variant override, so the override replaces the hashed assignment."
+ },
+ {
+ "id": "v1.multivariate.invalid_variant_override_uses_hash",
+ "definitions": {
+ "flags": [
+ {
+ "id": 107,
+ "key": "checkout-layout-bad-override",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100,
+ "variant": "wide"
+ },
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "compact",
+ "rollout_percentage": 25
+ },
+ {
+ "key": "spacious",
+ "rollout_percentage": 25
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout-bad-override": {
+ "value": "compact",
+ "enabled": true,
+ "variant": "compact",
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "variant",
+ "input": "checkout-layout-bad-override.user-17variant",
+ "hash01": 0.5028208481218698,
+ "cumulative_boundaries": [
+ 0.5,
+ 0.75,
+ 1.0
+ ],
+ "selected": "compact"
+ }
+ ],
+ "notes": "The override wide is not a declared variant key, so the hashed assignment is used while the matching condition index is still reported."
+ },
+ {
+ "id": "v1.multivariate.partial_rollout_included",
+ "definitions": {
+ "flags": [
+ {
+ "id": 108,
+ "key": "checkout-layout-partial",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 50
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-77",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout-partial": {
+ "value": "test",
+ "enabled": true,
+ "variant": "test",
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "checkout-layout-partial.user-77",
+ "hash01": 0.34759874309962885,
+ "threshold_percentage": 50,
+ "threshold": 0.5,
+ "included": true
+ },
+ {
+ "purpose": "variant",
+ "input": "checkout-layout-partial.user-77variant",
+ "hash01": 0.6250982837254144,
+ "cumulative_boundaries": [
+ 0.5,
+ 1.0
+ ],
+ "selected": "test"
+ }
+ ],
+ "notes": "Rollout and variant assignment use two independent hashes that differ only by the salt."
+ },
+ {
+ "id": "v1.multivariate.partial_rollout_excluded",
+ "definitions": {
+ "flags": [
+ {
+ "id": 108,
+ "key": "checkout-layout-partial",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 50
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-105",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout-partial": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "checkout-layout-partial.user-105",
+ "hash01": 0.6993197170202352,
+ "threshold_percentage": 50,
+ "threshold": 0.5,
+ "included": false
+ }
+ ],
+ "notes": "A rollout miss on a multivariate flag returns false and computes no variant hash."
+ },
+ {
+ "id": "v1.multivariate.empty_distinct_id_first_variant",
+ "definitions": {
+ "flags": [
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": "control",
+ "enabled": true,
+ "variant": "control",
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "remote_only"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "variant",
+ "input": "beta-search.variant",
+ "hash01": 0.6953518749808109,
+ "cumulative_boundaries": [
+ 0.5,
+ 1.0
+ ],
+ "selected": "test"
+ }
+ ],
+ "notes": "The 100 percent condition includes without a rollout hash. For variant assignment the version 1 Rust reference short-circuits the empty identifier to 0.0, selecting control, the first variant in stored order. The 50/50 split places the counterfactual hash of the prefix plus variant salt, 0.6953518749808109, in the later test variant; hash_evidence records that arithmetic, not the reference assignment. Python local evaluation at a1002c577e7c69e3f321f8f0832ee037316135a3 returns test. remote_only records this known SDK divergence from the reference empty-identifier behavior; the SDK does not fall back."
+ },
+ {
+ "id": "v1.group.included_by_group_key",
+ "definitions": {
+ "flags": [
+ {
+ "id": 109,
+ "key": "org-dashboard",
+ "version": 2,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "tier",
+ "type": "group",
+ "group_type_index": 0,
+ "operator": "exact",
+ "value": "gold"
+ }
+ ],
+ "rollout_percentage": 60
+ }
+ ],
+ "aggregation_group_type_index": 0
+ }
+ }
+ ],
+ "group_type_mapping": {
+ "0": "organization"
+ }
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {},
+ "groups": {
+ "organization": "org-9"
+ },
+ "group_properties": {
+ "organization": {
+ "tier": "gold"
+ }
+ }
+ },
+ "expected": {
+ "flags": {
+ "org-dashboard": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "org-dashboard.org-9",
+ "hash01": 0.5753119444222963,
+ "threshold_percentage": 60,
+ "threshold": 0.6,
+ "included": true
+ }
+ ],
+ "notes": "A group flag hashes the group key, never the distinct_id."
+ },
+ {
+ "id": "v1.group.excluded_by_group_key",
+ "definitions": {
+ "flags": [
+ {
+ "id": 109,
+ "key": "org-dashboard",
+ "version": 2,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "tier",
+ "type": "group",
+ "group_type_index": 0,
+ "operator": "exact",
+ "value": "gold"
+ }
+ ],
+ "rollout_percentage": 60
+ }
+ ],
+ "aggregation_group_type_index": 0
+ }
+ }
+ ],
+ "group_type_mapping": {
+ "0": "organization"
+ }
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {},
+ "groups": {
+ "organization": "org-12"
+ },
+ "group_properties": {
+ "organization": {
+ "tier": "gold"
+ }
+ }
+ },
+ "expected": {
+ "flags": {
+ "org-dashboard": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "out_of_rollout_bound",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "org-dashboard.org-12",
+ "hash01": 0.6727351878871999,
+ "threshold_percentage": 60,
+ "threshold": 0.6,
+ "included": false
+ }
+ ]
+ },
+ {
+ "id": "v1.group.integer_group_key_normalized",
+ "definitions": {
+ "flags": [
+ {
+ "id": 109,
+ "key": "org-dashboard",
+ "version": 2,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "tier",
+ "type": "group",
+ "group_type_index": 0,
+ "operator": "exact",
+ "value": "gold"
+ }
+ ],
+ "rollout_percentage": 60
+ }
+ ],
+ "aggregation_group_type_index": 0
+ }
+ }
+ ],
+ "group_type_mapping": {
+ "0": "organization"
+ }
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {},
+ "groups": {
+ "organization": 42
+ },
+ "group_properties": {
+ "organization": {
+ "tier": "gold"
+ }
+ }
+ },
+ "expected": {
+ "flags": {
+ "org-dashboard": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "rollout",
+ "input": "org-dashboard.42",
+ "hash01": 0.5997466051660167,
+ "threshold_percentage": 60,
+ "threshold": 0.6,
+ "included": true
+ }
+ ],
+ "notes": "The JSON number 42 normalizes to the decimal string 42 before hashing."
+ },
+ {
+ "id": "v1.group.missing_group_key",
+ "definitions": {
+ "flags": [
+ {
+ "id": 109,
+ "key": "org-dashboard",
+ "version": 2,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "tier",
+ "type": "group",
+ "group_type_index": 0,
+ "operator": "exact",
+ "value": "gold"
+ }
+ ],
+ "rollout_percentage": 60
+ }
+ ],
+ "aggregation_group_type_index": 0
+ }
+ }
+ ],
+ "group_type_mapping": {
+ "0": "organization"
+ }
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "org-dashboard": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "no_group_type",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "The context has no organization key, so the group condition is skipped and no hash is computed."
+ },
+ {
+ "id": "v1.dependency.satisfied",
+ "definitions": {
+ "flags": [
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ],
+ "payloads": {
+ "true": "{\"cta\":\"Try beta search\"}"
+ }
+ }
+ },
+ {
+ "id": 110,
+ "key": "beta-search-suggestions",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "beta-search",
+ "type": "flag",
+ "operator": "flag_evaluates_to",
+ "value": true,
+ "dependency_chain": [
+ "beta-search"
+ ]
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": "{\"cta\":\"Try beta search\"}",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ },
+ "beta-search-suggestions": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "The dependency filter names the target flag key and expects boolean true, which matches any enabled result."
+ },
+ {
+ "id": "v1.dependency.unsatisfied",
+ "definitions": {
+ "flags": [
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ],
+ "payloads": {
+ "true": "{\"cta\":\"Try beta search\"}"
+ }
+ }
+ },
+ {
+ "id": 110,
+ "key": "beta-search-suggestions",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "beta-search",
+ "type": "flag",
+ "operator": "flag_evaluates_to",
+ "value": true,
+ "dependency_chain": [
+ "beta-search"
+ ]
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "no_condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ },
+ "beta-search-suggestions": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "no_condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "A dependency that evaluates to false fails the dependent condition as a targeting miss, not a rollout miss."
+ },
+ {
+ "id": "v1.dependency.variant_match",
+ "definitions": {
+ "flags": [
+ {
+ "id": 106,
+ "key": "checkout-layout",
+ "version": 5,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100,
+ "variant": "spacious"
+ },
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "compact",
+ "rollout_percentage": 25
+ },
+ {
+ "key": "spacious",
+ "rollout_percentage": 25
+ }
+ ]
+ },
+ "payloads": {
+ "compact": "{\"density\":\"compact\"}"
+ }
+ }
+ },
+ {
+ "id": 111,
+ "key": "compact-checkout-banner",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "checkout-layout",
+ "type": "flag",
+ "operator": "flag_evaluates_to",
+ "value": "compact",
+ "dependency_chain": [
+ "checkout-layout"
+ ]
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-61",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout": {
+ "value": "compact",
+ "enabled": true,
+ "variant": "compact",
+ "payload": "{\"density\":\"compact\"}",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ },
+ "local_evaluation": "conclusive"
+ },
+ "compact-checkout-banner": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "variant",
+ "input": "checkout-layout.user-61variant",
+ "hash01": 0.5698252224547713,
+ "cumulative_boundaries": [
+ 0.5,
+ 0.75,
+ 1.0
+ ],
+ "selected": "compact"
+ }
+ ],
+ "notes": "A string expected value matches only the exact assigned variant key."
+ },
+ {
+ "id": "v1.dependency.variant_mismatch",
+ "definitions": {
+ "flags": [
+ {
+ "id": 106,
+ "key": "checkout-layout",
+ "version": 5,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100,
+ "variant": "spacious"
+ },
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "compact",
+ "rollout_percentage": 25
+ },
+ {
+ "key": "spacious",
+ "rollout_percentage": 25
+ }
+ ]
+ },
+ "payloads": {
+ "compact": "{\"density\":\"compact\"}"
+ }
+ }
+ },
+ {
+ "id": 111,
+ "key": "compact-checkout-banner",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "checkout-layout",
+ "type": "flag",
+ "operator": "flag_evaluates_to",
+ "value": "compact",
+ "dependency_chain": [
+ "checkout-layout"
+ ]
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "free"
+ }
+ },
+ "expected": {
+ "flags": {
+ "checkout-layout": {
+ "value": "control",
+ "enabled": true,
+ "variant": "control",
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 1
+ },
+ "local_evaluation": "conclusive"
+ },
+ "compact-checkout-banner": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "no_condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "variant",
+ "input": "checkout-layout.user-17variant",
+ "hash01": 0.13678069113210306,
+ "cumulative_boundaries": [
+ 0.5,
+ 0.75,
+ 1.0
+ ],
+ "selected": "control"
+ }
+ ]
+ },
+ {
+ "id": "v1.dependency.missing_target",
+ "definitions": {
+ "flags": [
+ {
+ "id": 112,
+ "key": "beta-search-suggestions-orphan",
+ "version": 1,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "beta-search-legacy",
+ "type": "flag",
+ "operator": "flag_evaluates_to",
+ "value": true,
+ "dependency_chain": []
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search-suggestions-orphan": {
+ "value": false,
+ "enabled": false,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "missing_dependency",
+ "condition_index": null
+ },
+ "local_evaluation": "inconclusive"
+ }
+ },
+ "omitted_flags": []
+ },
+ "notes": "The target key is not in the definitions and the dependency chain is empty. The authoritative evaluator fails the flag closed; a local evaluator must report the flag as inconclusive and fall back."
+ },
+ {
+ "id": "v1.holdout.member",
+ "definitions": {
+ "flags": [
+ {
+ "id": 113,
+ "key": "checkout-experiment",
+ "version": 4,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ]
+ },
+ "payloads": {
+ "test": "{\"layout\":\"test\"}"
+ },
+ "holdout": {
+ "id": 7,
+ "exclusion_percentage": 10
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-31",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "checkout-experiment": {
+ "value": "holdout-7",
+ "enabled": true,
+ "variant": "holdout-7",
+ "payload": null,
+ "reason": {
+ "code": "holdout_condition_value",
+ "condition_index": null
+ },
+ "local_evaluation": "remote_only"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "holdout",
+ "input": "holdout-user-31",
+ "hash01": 0.0194745413007599,
+ "threshold_percentage": 10,
+ "threshold": 0.1,
+ "included": true
+ }
+ ],
+ "notes": "Holdout membership is checked before any condition. The synthesized variant is holdout- followed by the holdout id, no condition index is reported, and no condition or variant hash is computed."
+ },
+ {
+ "id": "v1.holdout.not_member",
+ "definitions": {
+ "flags": [
+ {
+ "id": 113,
+ "key": "checkout-experiment",
+ "version": 4,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": {
+ "variants": [
+ {
+ "key": "control",
+ "rollout_percentage": 50
+ },
+ {
+ "key": "test",
+ "rollout_percentage": 50
+ }
+ ]
+ },
+ "payloads": {
+ "test": "{\"layout\":\"test\"}"
+ },
+ "holdout": {
+ "id": 7,
+ "exclusion_percentage": 10
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-77",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "checkout-experiment": {
+ "value": "test",
+ "enabled": true,
+ "variant": "test",
+ "payload": "{\"layout\":\"test\"}",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "remote_only"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "holdout",
+ "input": "holdout-user-77",
+ "hash01": 0.1256029476953561,
+ "threshold_percentage": 10,
+ "threshold": 0.1,
+ "included": false
+ },
+ {
+ "purpose": "variant",
+ "input": "checkout-experiment.user-77variant",
+ "hash01": 0.9625813403348775,
+ "cumulative_boundaries": [
+ 0.5,
+ 1.0
+ ],
+ "selected": "test"
+ }
+ ],
+ "notes": "Outside the holdout the ordinary conditions run and the variant hash assigns test."
+ },
+ {
+ "id": "v1.holdout.empty_distinct_id_hashes_prefix",
+ "definitions": {
+ "flags": [
+ {
+ "id": 115,
+ "key": "beta-search-holdout-92",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "holdout": {
+ "id": 7,
+ "exclusion_percentage": 92
+ }
+ }
+ },
+ {
+ "id": 116,
+ "key": "beta-search-holdout-93",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ],
+ "holdout": {
+ "id": 7,
+ "exclusion_percentage": 93
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "",
+ "person_properties": {}
+ },
+ "expected": {
+ "flags": {
+ "beta-search-holdout-92": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": null,
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "remote_only"
+ },
+ "beta-search-holdout-93": {
+ "value": "holdout-7",
+ "enabled": true,
+ "variant": "holdout-7",
+ "payload": null,
+ "reason": {
+ "code": "holdout_condition_value",
+ "condition_index": null
+ },
+ "local_evaluation": "remote_only"
+ }
+ },
+ "omitted_flags": []
+ },
+ "hash_evidence": [
+ {
+ "purpose": "holdout",
+ "input": "holdout-",
+ "hash01": 0.9268829483920294,
+ "threshold_percentage": 92,
+ "threshold": 0.92,
+ "included": false
+ },
+ {
+ "purpose": "holdout",
+ "input": "holdout-",
+ "hash01": 0.9268829483920294,
+ "threshold_percentage": 93,
+ "threshold": 0.93,
+ "included": true
+ }
+ ],
+ "notes": "The version 1 Rust reference does not short-circuit empty identifiers for holdouts: calculate_hash(\"holdout-\", \"\", \"\") is 0.9268829483920294. 92 and 93 percent straddle this hash. At 92 percent the subject is not a member and the ordinary 100 percent boolean condition matches without a rollout hash; at 93 percent the subject is a member and receives holdout-7 with no condition index. If holdout hashing incorrectly reused the rollout/variant 0.0 guard, both flags would assign holdout-7. Python local evaluation at a1002c577e7c69e3f321f8f0832ee037316135a3 ignores holdout configuration and returns true for both flags. remote_only follows the existing holdout cases: local evaluators implementing holdouts must match the reference."
+ },
+ {
+ "id": "v1.omission.inactive_flag",
+ "definitions": {
+ "flags": [
+ {
+ "id": 114,
+ "key": "retired-banner",
+ "version": 9,
+ "active": false,
+ "filters": {
+ "groups": [
+ {
+ "properties": [],
+ "rollout_percentage": 100
+ }
+ ]
+ }
+ },
+ {
+ "id": 101,
+ "key": "beta-search",
+ "version": 3,
+ "active": true,
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "plan",
+ "type": "person",
+ "operator": "exact",
+ "value": "enterprise"
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ],
+ "payloads": {
+ "true": "{\"cta\":\"Try beta search\"}"
+ }
+ }
+ }
+ ]
+ },
+ "context": {
+ "distinct_id": "user-17",
+ "person_properties": {
+ "plan": "enterprise"
+ }
+ },
+ "expected": {
+ "flags": {
+ "beta-search": {
+ "value": true,
+ "enabled": true,
+ "variant": null,
+ "payload": "{\"cta\":\"Try beta search\"}",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0
+ },
+ "local_evaluation": "conclusive"
+ }
+ },
+ "omitted_flags": [
+ "retired-banner"
+ ]
+ },
+ "notes": "An inactive flag is omitted from every remote response version. A local evaluator reports it as false."
+ }
+ ]
+}
diff --git a/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/manifest.json b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/manifest.json
new file mode 100644
index 000000000000..e5fe51232421
--- /dev/null
+++ b/rust/feature-flags/tests/fixtures/rules_v2_contract/1.2.0/manifest.json
@@ -0,0 +1,419 @@
+{
+ "manifest_version": 1,
+ "contract": {
+ "name": "feature_flag_rules_v2",
+ "version": "1.2.0",
+ "config_version": 2
+ },
+ "corpus": {
+ "version": "1.1.0",
+ "config_version_locked": 1,
+ "case_id_pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)+$",
+ "published_versions_are_immutable": true,
+ "expectation_change": "Any changed expected value requires a new corpus version and a review explanation."
+ },
+ "schema_dialect": "https://json-schema.org/draft/2020-12/schema",
+ "compatibility": {
+ "published_versions_are_immutable": true,
+ "patch": "Documentation or integrity-tool changes that do not change accepted configs or frozen literals.",
+ "minor": "Additive fixtures or artifacts that do not change accepted configs or frozen literals.",
+ "major": "Any change to accepted configs, rejected configs, or frozen literals."
+ },
+ "integrity": {
+ "algorithm": "sha256",
+ "index": "SHA256SUMS",
+ "content": "raw_file_bytes",
+ "entry_format": "<lowercase_hex_digest><two_spaces><relative_posix_path><line_feed>",
+ "entry_order": "bytewise_path",
+ "excluded_from_index": [
+ "SHA256SUMS"
+ ]
+ },
+ "artifacts": [
+ {
+ "path": "README.md",
+ "kind": "documentation"
+ },
+ {
+ "path": "registries/literals.json",
+ "kind": "registry",
+ "version": "1.0.0"
+ },
+ {
+ "path": "schemas/config.schema.json",
+ "kind": "schema",
+ "version": "1.0.0"
+ },
+ {
+ "path": "fixtures/config/valid/boolean_all_rule_types.json",
+ "kind": "fixture",
+ "fixture_id": "config.valid.boolean_all_rule_types",
+ "expected": "valid"
+ },
+ {
+ "path": "fixtures/config/valid/string_group_assignment.json",
+ "kind": "fixture",
+ "fixture_id": "config.valid.string_group_assignment",
+ "expected": "valid"
+ },
+ {
+ "path": "fixtures/config/valid/reserved_number_value.json",
+ "kind": "fixture",
+ "fixture_id": "config.valid.reserved_number_value",
+ "expected": "valid"
+ },
+ {
+ "path": "fixtures/config/valid/reserved_object_value.json",
+ "kind": "fixture",
+ "fixture_id": "config.valid.reserved_object_value",
+ "expected": "valid"
+ },
+ {
+ "path": "fixtures/config/valid/version_float_literal.json",
+ "kind": "fixture",
+ "fixture_id": "config.valid.version_float_literal",
+ "expected": "valid"
+ },
+ {
+ "path": "fixtures/config/invalid/unknown_config_version.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.unknown_config_version",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "const",
+ "instance_path": "/version",
+ "message_contains": "2 was expected"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/version_string.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.version_string",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "const",
+ "instance_path": "/version"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/version_boolean.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.version_boolean",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "const",
+ "instance_path": "/version"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/unknown_config_field.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.unknown_config_field",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "additionalProperties",
+ "instance_path": "",
+ "message_contains": "groups"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/unknown_rule_field.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.unknown_rule_field",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "additionalProperties",
+ "instance_path": "/rules/0",
+ "message_contains": "implicit_default"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/missing_on_rollout_miss.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.missing_on_rollout_miss",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "required",
+ "instance_path": "/rules/0",
+ "message_contains": "on_rollout_miss"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/missing_experiment_paused.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.missing_experiment_paused",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "required",
+ "instance_path": "/rules/0",
+ "message_contains": "paused"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/non_uuid_rule_id.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.non_uuid_rule_id",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "pattern",
+ "instance_path": "/rules/0/id"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/empty_seed.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.empty_seed",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "minLength",
+ "instance_path": "/rules/0/seed"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/empty_string_value.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.empty_string_value",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "minLength",
+ "instance_path": "/rules/0/value"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/return_value_type_mismatch.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.return_value_type_mismatch",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "type",
+ "instance_path": "/rules/0/value"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/variant_value_type_mismatch.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.variant_value_type_mismatch",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "type",
+ "instance_path": "/rules/0/variants/0/value"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/null_experiment_id.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.null_experiment_id",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "type",
+ "instance_path": "/rules/0/experiment_id",
+ "message_contains": "integer"
+ }
+ },
+ {
+ "path": "fixtures/config/valid/object_value_max_depth.json",
+ "kind": "fixture",
+ "fixture_id": "config.valid.object_value_max_depth",
+ "expected": "valid"
+ },
+ {
+ "path": "fixtures/config/invalid/object_value_too_deep.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.object_value_too_deep",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "oneOf",
+ "instance_path": "/rules/0/value/child/child/child/child/child/child/child/child/child/child/child/child/child/child/child/child/child/child/child/child"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/rollout_percentage_above_maximum.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.rollout_percentage_above_maximum",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "maximum",
+ "instance_path": "/rules/0/rollout_percentage"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/variant_key_invalid_characters.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.variant_key_invalid_characters",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "pattern",
+ "instance_path": "/rules/0/variants/0/key"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/too_few_variants.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.too_few_variants",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "minItems",
+ "instance_path": "/rules/0/variants"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/too_many_variants.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.too_many_variants",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "maxItems",
+ "instance_path": "/rules/0/variants"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/seed_too_long.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.seed_too_long",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "maxLength",
+ "instance_path": "/rules/0/seed"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/group_percentage_rollout_with_assign_by.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.group_percentage_rollout_with_assign_by",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "not",
+ "instance_path": "/rules/0"
+ }
+ },
+ {
+ "path": "fixtures/config/invalid/group_experiment_with_assign_by.json",
+ "kind": "fixture",
+ "fixture_id": "config.invalid.group_experiment_with_assign_by",
+ "expected": "invalid",
+ "expected_failure": {
+ "keyword": "not",
+ "instance_path": "/rules/0"
+ }
+ },
+ {
+ "path": "fixtures/config/valid/group_all_rule_types.json",
+ "kind": "fixture",
+ "fixture_id": "config.valid.group_all_rule_types",
+ "expected": "valid"
+ },
+ {
+ "path": "schemas/hash_sha1_60_v1.schema.json",
+ "kind": "schema",
+ "version": "1.1.0"
+ },
+ {
+ "path": "schemas/v1_evaluation.schema.json",
+ "kind": "schema",
+ "version": "1.1.0"
+ },
+ {
+ "path": "schemas/legacy_projection.schema.json",
+ "kind": "schema",
+ "version": "1.1.0"
+ },
+ {
+ "path": "corpus/hash_sha1_60_v1.json",
+ "kind": "corpus",
+ "version": "1.1.0",
+ "schema": "schemas/hash_sha1_60_v1.schema.json",
+ "case_ids": [
+ "hash.rollout.ascii_division_edge",
+ "hash.rollout.ascii_excluded",
+ "hash.variant.ascii",
+ "hash.holdout.literal_prefix",
+ "hash.concatenation.no_separator_escaping",
+ "hash.identifier.empty",
+ "hash.identifier.unicode_utf8",
+ "hash.identifier.truncated_ascii",
+ "hash.identifier.truncated_scalar_values",
+ "hash.identifier.exactly_200_multibyte",
+ "hash.identifier.integer_group_key",
+ "threshold.equal_is_included",
+ "threshold.next_binary64_above_is_excluded",
+ "threshold.zero_percent_zero_hash",
+ "threshold.zero_percent_smallest_hash",
+ "threshold.hundred_percent_short_circuit",
+ "threshold.two_decimal_division_equal",
+ "threshold.two_decimal_division_excluded",
+ "threshold.two_decimal_division_included_below_quotient",
+ "variant.zero_hash_first_variant",
+ "variant.boundary_is_exclusive",
+ "variant.just_below_boundary",
+ "variant.accumulated_boundary_left_to_right",
+ "variant.accumulated_boundary_third",
+ "variant.two_decimal_weights_boundary",
+ "variant.hash_one_off_the_end",
+ "variant.sum_below_one_off_the_end",
+ "parity.rollout_identical_bytes",
+ "parity.variant_identical_bytes",
+ "parity.holdout_identical_bytes",
+ "parity.empty_identifier_divergent",
+ "parity.final_variant_fallback_divergent"
+ ]
+ },
+ {
+ "path": "corpus/v1_evaluation.json",
+ "kind": "corpus",
+ "version": "1.1.0",
+ "schema": "schemas/v1_evaluation.schema.json",
+ "case_ids": [
+ "v1.boolean.targeted_match_with_payload",
+ "v1.boolean.targeting_miss",
+ "v1.boolean.rollout_included",
+ "v1.boolean.rollout_excluded",
+ "v1.boolean.rollout_miss_continues_to_lower_condition",
+ "v1.boolean.rollout_miss_early_exit",
+ "v1.boolean.reason_priority_keeps_earlier_rollout_miss",
+ "v1.boolean.reason_priority_prefers_later_rollout_miss",
+ "v1.boolean.null_rollout_is_100",
+ "v1.boolean.empty_distinct_id_included_at_zero_percent",
+ "v1.boolean.empty_distinct_id_included_below_prefix_hash",
+ "v1.multivariate.variant_from_hash_with_payload",
+ "v1.multivariate.variant_from_hash_control",
+ "v1.multivariate.variant_override",
+ "v1.multivariate.invalid_variant_override_uses_hash",
+ "v1.multivariate.partial_rollout_included",
+ "v1.multivariate.partial_rollout_excluded",
+ "v1.multivariate.empty_distinct_id_first_variant",
+ "v1.group.included_by_group_key",
+ "v1.group.excluded_by_group_key",
+ "v1.group.integer_group_key_normalized",
+ "v1.group.missing_group_key",
+ "v1.dependency.satisfied",
+ "v1.dependency.unsatisfied",
+ "v1.dependency.variant_match",
+ "v1.dependency.variant_mismatch",
+ "v1.dependency.missing_target",
+ "v1.holdout.member",
+ "v1.holdout.not_member",
+ "v1.holdout.empty_distinct_id_hashes_prefix",
+ "v1.omission.inactive_flag"
+ ]
+ },
+ {
+ "path": "corpus/legacy_projection.json",
+ "kind": "corpus",
+ "version": "1.1.0",
+ "schema": "schemas/legacy_projection.schema.json",
+ "case_ids": [
+ "projection.boolean_true",
+ "projection.boolean_true_with_payload",
+ "projection.boolean_false_targeting_miss",
+ "projection.boolean_false_out_of_rollout",
+ "projection.variant",
+ "projection.variant_with_payload",
+ "projection.holdout_variant",
+ "projection.no_group_type",
+ "projection.missing_dependency",
+ "projection.failed_evaluation",
+ "projection.inactive_omitted"
+ ]
+ }
+ ]
+}
diff --git a/rust/feature-flags/tests/test_rules_v2_v1_contract.rs b/rust/feature-flags/tests/test_rules_v2_v1_contract.rs
new file mode 100644
index 000000000000..e0bf5bb0c5ad
--- /dev/null
+++ b/rust/feature-flags/tests/test_rules_v2_v1_contract.rs
@@ -0,0 +1,704 @@
+//! Runs the vendored Feature Flag Rules v2 contract corpus against production code:
+//! the `sha1_60_v1` hash vectors against `calculate_hash` and the evaluator's rollout,
+//! holdout, and variant paths; the version 1 lock-down cases against
+//! `FeatureFlagMatcher::evaluate_all_feature_flags`; and the legacy projection matrix
+//! against the `/flags` and `/decide` response conversions.
+//!
+//! The corpus lives under `tests/fixtures/rules_v2_contract/<contract version>/`.
+//! `SOURCE.json` there records the upstream revision, the digests this test verifies, and
+//! the update procedure. CI never fetches the harness repository.
+
+use std::collections::{BTreeSet, HashMap, HashSet};
+use std::fs;
+use std::path::{Path, PathBuf};
+use std::sync::Arc;
+
+use feature_flags::api::types::{
+ DecideV1Response, DecideV2Response, FlagDetails, FlagDetailsMetadata, FlagEvaluationReason,
+ FlagsResponse, LegacyFlagsResponse,
+};
+use feature_flags::cohorts::cohort_cache_manager::CohortCacheManager;
+use feature_flags::flags::cache_builder::compute_flag_dependencies;
+use feature_flags::flags::feature_flag_list::PreparedFlags;
+use feature_flags::flags::flag_matching::FeatureFlagMatcher;
+use feature_flags::flags::flag_matching_utils::calculate_hash;
+use feature_flags::flags::flag_models::{FeatureFlag, FeatureFlagList};
+use feature_flags::flags::flag_request::FlagRequest;
+use feature_flags::utils::test_utils::{mock_group_type_cache, TestContext};
+use regex::Regex;
+use serde_json::{json, Value};
+use sha2::{Digest, Sha256};
+use uuid::Uuid;
+
+const CORPUS_DIR: &str = "tests/fixtures/rules_v2_contract/1.2.0";
+
+/// Corpus rows that supply a precomputed `hash01` instead of hash inputs. The evaluator
+/// computes its hash internally and exposes no seam that accepts one, so these rows stay
+/// unsupported until the shared hashing primitives are extracted behind such a seam.
+const UNSUPPORTED_CASE_IDS: &[&str] = &[
+ "threshold.equal_is_included",
+ "threshold.next_binary64_above_is_excluded",
+ "threshold.zero_percent_zero_hash",
+ "threshold.zero_percent_smallest_hash",
+ "threshold.hundred_percent_short_circuit",
+ "threshold.two_decimal_division_equal",
+ "threshold.two_decimal_division_excluded",
+ "threshold.two_decimal_division_included_below_quotient",
+ "variant.zero_hash_first_variant",
+ "variant.boundary_is_exclusive",
+ "variant.just_below_boundary",
+ "variant.accumulated_boundary_left_to_right",
+ "variant.accumulated_boundary_third",
+ "variant.two_decimal_weights_boundary",
+ "variant.hash_one_off_the_end",
+ "variant.sum_below_one_off_the_end",
+ "parity.final_variant_fallback_divergent",
+];
+
+/// A dependency target absent from the fixture definitions maps to an id no fixture flag
+/// uses, so the target is missing from the flag list entirely. That is the only way the
+/// evaluator reports `missing_dependency`: a deleted target that another flag references
+/// stays in the cached list and pre-seeds as false.
+const MISSING_DEPENDENCY_ID: i64 = 0;
+
+#[test]
+fn vendored_corpus_is_intact() {
+ let source = load_json("SOURCE.json");
+ let manifest = load_json("manifest.json");
+
+ let recorded = source["files"].as_object().expect("SOURCE.json files");
+ let mut on_disk = BTreeSet::new();
+ collect_files(&corpus_dir(), &corpus_dir(), &mut on_disk);
+ on_disk.remove("SOURCE.json");
+ assert_eq!(
+ on_disk,
+ recorded.keys().cloned().collect::<BTreeSet<_>>(),
+ "vendored files must match the files listed in SOURCE.json"
+ );
+ for (rel, digest) in recorded {
+ let bytes = fs::read(corpus_dir().join(rel)).unwrap();
+ assert_eq!(
+ hex::encode(Sha256::digest(&bytes)),
+ digest.as_str().unwrap(),
+ "{rel}: bytes differ from the digest in SOURCE.json; a changed expectation needs a new corpus version, see update_procedure"
+ );
+ }
+
+ assert_eq!(source["contract_version"], manifest["contract"]["version"]);
+ assert_eq!(source["corpus_version"], manifest["corpus"]["version"]);
+ for artifact in corpus_artifacts(&manifest) {
+ let path = str_field(artifact, "path");
+ let file = load_json(path);
+ assert_eq!(
+ file["corpus_version"], manifest["corpus"]["version"],
+ "{path}: corpus_version"
+ );
+ let in_file = file_case_ids(&file);
+ let unique: BTreeSet<&String> = in_file.iter().collect();
+ assert_eq!(unique.len(), in_file.len(), "{path}: duplicate case ids");
+ let declared: BTreeSet<String> = artifact["case_ids"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .map(|id| id.as_str().unwrap().to_string())
+ .collect();
+ assert_eq!(
+ unique.into_iter().cloned().collect::<BTreeSet<_>>(),
+ declared,
+ "{path}: case ids differ from the manifest"
+ );
+ }
+}
+
+#[tokio::test]
+async fn corpus_matches_production_evaluator_and_projections() {
+ let manifest = load_json("manifest.json");
+ let db = TestContext::new(None).await;
+ let team_id = db.insert_new_team(None).await.expect("insert team").id;
+
+ let mut covered = HashSet::new();
+ covered.extend(run_hash_corpus(&db, team_id).await);
+ covered.extend(run_v1_corpus(&db, team_id).await);
+ covered.extend(run_projection_corpus());
+
+ let unsupported: HashSet<String> = UNSUPPORTED_CASE_IDS.iter().map(|s| s.to_string()).collect();
+ let declared: HashSet<String> = corpus_artifacts(&manifest)
+ .flat_map(|artifact| artifact["case_ids"].as_array().unwrap().iter())
+ .map(|id| id.as_str().unwrap().to_string())
+ .collect();
+ let both: BTreeSet<_> = covered.intersection(&unsupported).collect();
+ assert!(
+ both.is_empty(),
+ "cases both run and listed as unsupported: {both:?}"
+ );
+ let accounted: HashSet<String> = covered.union(&unsupported).cloned().collect();
+ let missing: BTreeSet<_> = declared.difference(&accounted).collect();
+ assert!(
+ missing.is_empty(),
+ "manifest cases neither run nor listed as unsupported: {missing:?}"
+ );
+ let unknown: BTreeSet<_> = accounted.difference(&declared).collect();
+ assert!(
+ unknown.is_empty(),
+ "cases run or listed that the manifest does not declare: {unknown:?}"
+ );
+}
+
+async fn run_hash_corpus(db: &TestContext, team_id: i32) -> HashSet<String> {
+ let corpus = load_json("corpus/hash_sha1_60_v1.json");
+ let mut covered = HashSet::new();
+
+ for vector in corpus["vectors"].as_array().unwrap() {
+ let id = str_field(vector, "id");
+ let prefix = str_field(vector, "prefix");
+ let identifier = str_field(vector, "identifier");
+ let salt = str_field(vector, "salt");
+
+ let input = format!("{prefix}{identifier}{salt}");
+ assert_eq!(
+ input,
+ str_field(vector, "input"),
+ "{id}: input concatenation"
+ );
+ assert_eq!(
+ hex::encode(input.as_bytes()),
+ str_field(vector, "input_utf8_hex"),
+ "{id}: input bytes"
+ );
+ let hash = calculate_hash(prefix, identifier, salt).unwrap();
+ assert_hash01(id, hash, &vector["hash01"]);
+ assert_eq!(
+ format!("{:016x}", hash.to_bits()),
+ str_field(vector, "hash01_binary64_hex"),
+ "{id}: hash01 binary64 bits"
+ );
+
+ if let Some(before) = vector["identifier_before_truncation"].as_str() {
+ let request = FlagRequest {
+ distinct_id: Some(before.to_string()),
+ ..Default::default()
+ };
+ assert_eq!(
+ request.extract_distinct_id().unwrap(),
+ identifier,
+ "{id}: request-level identifier truncation"
+ );
+ }
+
+ // Rollout, holdout, and variant checks run through the evaluator so the comparison
+ // and the boundary accumulation are the production ones, not a copy kept here.
+ // Production hashes `<flag key>.`, so the flag key is the prefix minus its dot. The
+ // holdout vector's `holdout-` prefix has no dot: `get_holdout_hash` always hashes
+ // that literal, so the flag key never reaches it.
+ let key = prefix.strip_suffix('.').unwrap_or(prefix);
+ let (context, group_type_mapping, aggregation) = match vector["identifier_source"]
+ .get("json_group_key")
+ {
+ Some(group_key) => (
+ json!({"distinct_id": "person", "person_properties": {}, "groups": {"organization": group_key}}),
+ json!({"0": "organization"}),
+ Some(0),
+ ),
+ None => (
+ json!({"distinct_id": identifier, "person_properties": {}}),
+ Value::Null,
+ None,
+ ),
+ };
+
+ for check in vector["rollout_checks"].as_array().into_iter().flatten() {
+ let percentage = check["rollout_percentage"].as_f64().unwrap();
+ assert_eq!(
+ percentage / 100.0,
+ check["threshold"].as_f64().unwrap(),
+ "{id}: threshold for {percentage}"
+ );
+ let flag = hash_check_flag(
+ team_id,
+ key,
+ aggregation,
+ json!({"groups": [{"properties": [], "rollout_percentage": percentage}]}),
+ );
+ let details = evaluate_single(db, team_id, flag, &group_type_mapping, &context).await;
+ assert_eq!(
+ json!(details.enabled),
+ check["included"],
+ "{id}: rollout at {percentage} percent"
+ );
+ }
+ for check in vector["holdout_checks"].as_array().into_iter().flatten() {
+ let percentage = check["exclusion_percentage"].as_f64().unwrap();
+ let flag = hash_check_flag(
+ team_id,
+ key,
+ None,
+ json!({"groups": [{"properties": [], "rollout_percentage": 100}], "holdout": {"id": 7, "exclusion_percentage": percentage}}),
+ );
+ let details = evaluate_single(db, team_id, flag, &group_type_mapping, &context).await;
+ assert_eq!(
+ json!(details.variant.as_deref() == Some("holdout-7")),
+ check["member"],
+ "{id}: holdout membership at {percentage} percent"
+ );
+ }
+ if let Some(check) = vector.get("variant_check") {
+ let flag = hash_check_flag(
+ team_id,
+ key,
+ aggregation,
+ json!({"groups": [{"properties": [], "rollout_percentage": 100}], "multivariate": {"variants": check["variants"]}}),
+ );
+ let details = evaluate_single(db, team_id, flag, &group_type_mapping, &context).await;
+ assert_eq!(
+ details.variant.as_deref(),
+ check["selected"].as_str(),
+ "{id}: variant selection"
+ );
+ }
+ covered.insert(id.to_string());
+ }
+
+ // Parity rows pin that the v1 input and the converted v2 input hash identically.
+ // `identical_outcome` and `divergence` describe version 2 semantics, which nothing in
+ // this crate implements yet, so they are not asserted here.
+ for parity in corpus["seed_parity"].as_array().unwrap() {
+ let id = str_field(parity, "id");
+ let Some(v2) = parity.get("v2") else {
+ continue; // white-box row, listed in UNSUPPORTED_CASE_IDS
+ };
+ let v1_input = str_field(parity, "v1_input");
+ let v1_hash = hash_of_input(v1_input);
+ let v2_hash = calculate_hash(
+ str_field(v2, "prefix"),
+ str_field(v2, "identifier"),
+ str_field(v2, "salt"),
+ )
+ .unwrap();
+ assert_hash01(id, v2_hash, &parity["hash01"]);
+ assert_eq!(
+ v1_hash.to_bits(),
+ v2_hash.to_bits(),
+ "{id}: v1 and converted v2 inputs must hash identically"
+ );
+ assert_eq!(
+ json!(v1_input == str_field(v2, "input")),
+ parity["identical_bytes"],
+ "{id}: identical_bytes"
+ );
+ covered.insert(id.to_string());
+ }
+ covered
+}
+
+async fn run_v1_corpus(db: &TestContext, team_id: i32) -> HashSet<String> {
+ let corpus = load_json("corpus/v1_evaluation.json");
+ let mut covered = HashSet::new();
+
+ for case in corpus["cases"].as_array().unwrap() {
+ let id = str_field(case, "id");
+ for evidence in case["hash_evidence"].as_array().into_iter().flatten() {
+ assert_hash01(
+ id,
+ hash_of_input(str_field(evidence, "input")),
+ &evidence["hash01"],
+ );
+ }
+
+ let (flags, filtered_out) = corpus_flags(team_id, &case["definitions"]["flags"]);
+ let response = evaluate(
+ db,
+ team_id,
+ flags,
+ filtered_out,
+ &case["definitions"]["group_type_mapping"],
+ &case["context"],
+ )
+ .await;
+ assert!(
+ !response.errors_while_computing_flags,
+ "{id}: errorsWhileComputingFlags"
+ );
+
+ let mut unexpected: BTreeSet<&String> = response.flags.keys().collect();
+ for (key, expected) in case["expected"]["flags"].as_object().unwrap() {
+ let actual = response
+ .flags
+ .get(key)
+ .unwrap_or_else(|| panic!("{id}: flag {key} missing from the response"));
+ unexpected.remove(key);
+ assert_eq!(
+ json!(actual.to_value()),
+ expected["value"],
+ "{id}: {key} value"
+ );
+ assert_eq!(
+ json!(actual.enabled),
+ expected["enabled"],
+ "{id}: {key} enabled"
+ );
+ assert_eq!(
+ json!(actual.variant),
+ expected["variant"],
+ "{id}: {key} variant"
+ );
+ assert_eq!(
+ json!(actual.metadata.payload),
+ expected["payload"],
+ "{id}: {key} payload"
+ );
+ assert_eq!(
+ json!(actual.reason.code),
+ expected["reason"]["code"],
+ "{id}: {key} reason code"
+ );
+ assert_eq!(
+ json!(actual.reason.condition_index),
+ expected["reason"]["condition_index"],
+ "{id}: {key} condition index"
+ );
+ }
+ for omitted in case["expected"]["omitted_flags"].as_array().unwrap() {
+ let omitted = omitted.as_str().unwrap();
+ assert!(
+ !response.flags.contains_key(omitted),
+ "{id}: {omitted} must be omitted from the response"
+ );
+ }
+ assert!(
+ unexpected.is_empty(),
+ "{id}: response carries flags the corpus does not expect: {unexpected:?}"
+ );
+ covered.insert(id.to_string());
+ }
+ covered
+}
+
+fn run_projection_corpus() -> HashSet<String> {
+ let corpus = load_json("corpus/legacy_projection.json");
+ let mut covered = HashSet::new();
+
+ for case in corpus["cases"].as_array().unwrap() {
+ let id = str_field(case, "id");
+ let outcome = &case["outcome"];
+ let build = || response_from_outcome(outcome);
+ let actuals = [
+ ("flags_v2", serde_json::to_value(build()).unwrap()),
+ (
+ "flags_v1",
+ serde_json::to_value(LegacyFlagsResponse::from_response(build())).unwrap(),
+ ),
+ (
+ "decide_v2",
+ serde_json::to_value(DecideV2Response::from_response(build())).unwrap(),
+ ),
+ (
+ "decide_v1",
+ serde_json::to_value(DecideV1Response::from_response(build())).unwrap(),
+ ),
+ ];
+ for (protocol, actual) in actuals {
+ assert_projection(id, protocol, &case["projections"][protocol], &actual);
+ }
+ covered.insert(id.to_string());
+ }
+ covered
+}
+
+/// Builds the detailed response the evaluator would have produced for a corpus outcome.
+fn response_from_outcome(outcome: &Value) -> FlagsResponse {
+ let mut flags = HashMap::new();
+ if !outcome["omitted"].as_bool().unwrap() {
+ let key = str_field(outcome, "key").to_string();
+ let detail = FlagDetails {
+ key: key.clone(),
+ enabled: outcome["enabled"].as_bool().unwrap(),
+ variant: outcome["variant"].as_str().map(String::from),
+ failed: outcome["failed"].as_bool().unwrap(),
+ reason: FlagEvaluationReason {
+ code: str_field(&outcome["reason"], "code").to_string(),
+ condition_index: outcome["reason"]["condition_index"]
+ .as_i64()
+ .map(|i| i as i32),
+ description: None,
+ },
+ metadata: FlagDetailsMetadata {
+ id: outcome["flag_id"].as_i64().unwrap() as i32,
+ version: outcome["flag_version"].as_i64().unwrap() as i32,
+ description: None,
+ payload: Some(outcome["payload"].clone()).filter(|p| !p.is_null()),
+ has_experiment: false,
+ },
+ conditions: None,
+ };
+ flags.insert(key, detail);
+ }
+ FlagsResponse::new(
+ outcome["failed"].as_bool().unwrap(),
+ flags,
+ None,
+ Uuid::nil(),
+ )
+}
+
+/// The corpus pins a subset of each response: every listed field must match, the flag maps
+/// must contain exactly the listed keys, and `failed` must be absent unless listed.
+fn assert_projection(id: &str, protocol: &str, expected: &Value, actual: &Value) {
+ for (field, expected_value) in expected.as_object().unwrap() {
+ if field == "response_version" {
+ continue;
+ }
+ let actual_value = actual
+ .get(field)
+ .unwrap_or_else(|| panic!("{id}: {protocol} response lacks {field}"));
+ assert_subset(id, protocol, field, expected_value, actual_value);
+ if let (Some(e), Some(a)) = (expected_value.as_object(), actual_value.as_object()) {
+ assert_eq!(
+ e.keys().collect::<BTreeSet<_>>(),
+ a.keys().collect::<BTreeSet<_>>(),
+ "{id}: {protocol} {field} keys"
+ );
+ }
+ }
+ for (key, detail) in expected["flags"].as_object().into_iter().flatten() {
+ if detail.get("failed").is_none() {
+ assert!(
+ actual["flags"][key].get("failed").is_none(),
+ "{id}: {protocol} {key} must not carry failed"
+ );
+ }
+ }
+}
+
+fn assert_subset(id: &str, protocol: &str, path: &str, expected: &Value, actual: &Value) {
+ match (expected.as_object(), actual.as_object()) {
+ (Some(e), Some(a)) => {
+ for (field, expected_value) in e {
+ let actual_value = a
+ .get(field)
+ .unwrap_or_else(|| panic!("{id}: {protocol} {path}.{field} missing"));
+ assert_subset(
+ id,
+ protocol,
+ &format!("{path}.{field}"),
+ expected_value,
+ actual_value,
+ );
+ }
+ }
+ _ => assert_eq!(expected, actual, "{id}: {protocol} {path}"),
+ }
+}
+
+/// Maps corpus flag definitions onto the evaluator's input shape: the team id is attached,
+/// dependency filters name their target by id instead of key, and inactive flags join the
+/// filtered-out set exactly as the request handler builds it.
+fn corpus_flags(team_id: i32, definitions: &Value) -> (Vec<FeatureFlag>, HashSet<i32>) {
+ let definitions = definitions.as_array().unwrap();
+ let key_to_id: HashMap<&str, i64> = definitions
+ .iter()
+ .map(|flag| (str_field(flag, "key"), flag["id"].as_i64().unwrap()))
+ .collect();
+
+ let mut flags = Vec::new();
+ let mut filtered_out = HashSet::new();
+ for definition in definitions {
+ let mut definition = definition.clone();
+ definition["team_id"] = json!(team_id);
+ for group in definition["filters"]["groups"]
+ .as_array_mut()
+ .into_iter()
+ .flatten()
+ {
+ for property in group["properties"].as_array_mut().into_iter().flatten() {
+ if property["type"] == "flag" {
+ let target = key_to_id
+ .get(str_field(property, "key"))
+ .copied()
+ .unwrap_or(MISSING_DEPENDENCY_ID);
+ property["key"] = json!(target.to_string());
+ }
+ }
+ }
+ let flag: FeatureFlag =
+ serde_json::from_value(definition).expect("corpus flag must deserialize");
+ if !flag.active {
+ filtered_out.insert(flag.id);
+ }
+ flags.push(flag);
+ }
+ (flags, filtered_out)
+}
+
+fn hash_check_flag(
+ team_id: i32,
+ key: &str,
+ aggregation: Option<i32>,
+ mut filters: Value,
+) -> FeatureFlag {
+ if let Some(index) = aggregation {
+ filters["aggregation_group_type_index"] = json!(index);
+ }
+ serde_json::from_value(
+ json!({"id": 1, "team_id": team_id, "key": key, "active": true, "filters": filters}),
+ )
+ .expect("hash check flag must deserialize")
+}
+
+async fn evaluate_single(
+ db: &TestContext,
+ team_id: i32,
+ flag: FeatureFlag,
+ group_type_mapping: &Value,
+ context: &Value,
+) -> FlagDetails {
+ let key = flag.key.clone();
+ let mut response = evaluate(
+ db,
+ team_id,
+ vec![flag],
+ HashSet::new(),
+ group_type_mapping,
+ context,
+ )
+ .await;
+ response
+ .flags
+ .remove(&key)
+ .unwrap_or_else(|| panic!("flag {key} missing from the response"))
+}
+
+async fn evaluate(
+ db: &TestContext,
+ team_id: i32,
+ flags: Vec<FeatureFlag>,
+ filtered_out_flag_ids: HashSet<i32>,
+ group_type_mapping: &Value,
+ context: &Value,
+) -> FlagsResponse {
+ let types_to_indexes: HashMap<String, i32> = group_type_mapping
+ .as_object()
+ .into_iter()
+ .flatten()
+ .map(|(index, name)| (name.as_str().unwrap().to_string(), index.parse().unwrap()))
+ .collect();
+ let groups: Option<HashMap<String, Value>> = context
+ .get("groups")
+ .map(|g| serde_json::from_value(g.clone()).unwrap());
+ let person_properties: HashMap<String, Value> =
+ serde_json::from_value(context["person_properties"].clone()).unwrap();
+ let group_properties: Option<HashMap<String, HashMap<String, Value>>> = context
+ .get("group_properties")
+ .map(|g| serde_json::from_value(g.clone()).unwrap());
+
+ let mut matcher = FeatureFlagMatcher::new(
+ str_field(context, "distinct_id").to_string(),
+ None,
+ team_id,
+ db.create_postgres_router(),
+ Arc::new(CohortCacheManager::new(
+ db.non_persons_reader.clone(),
+ None,
+ None,
+ )),
+ mock_group_type_cache(types_to_indexes),
+ groups,
+ );
+ // Dependency stages and missing targets come from the production builder, the same
+ // way the batch evaluation handler assembles its flag list.
+ let evaluation_metadata = compute_flag_dependencies(&flags).expect("dependency metadata");
+ let flag_list = FeatureFlagList {
+ flags: PreparedFlags::seal(flags),
+ filtered_out_flag_ids,
+ evaluation_metadata: Arc::new(evaluation_metadata),
+ cohorts: None,
+ };
+ matcher
+ .evaluate_all_feature_flags(
+ flag_list,
+ Some(person_properties),
+ group_properties,
+ None,
+ Uuid::new_v4(),
+ None,
+ false,
+ )
+ .await
+ .expect("evaluation must not fail")
+}
+
+/// Hashes a corpus row that supplies the whole concatenated input instead of its parts.
+fn hash_of_input(input: &str) -> f64 {
+ calculate_hash(input, "", "").unwrap()
+}
+
+fn assert_hash01(id: &str, actual: f64, expected: &Value) {
+ let expected: f64 = expected
+ .as_str()
+ .and_then(|literal| literal.parse().ok())
+ .unwrap_or_else(|| panic!("{id}: hash01 must be a decimal literal"));
+ assert_eq!(
+ actual.to_bits(),
+ expected.to_bits(),
+ "{id}: hash01 is {actual:?}, corpus expects {expected:?}"
+ );
+}
+
+fn corpus_dir() -> PathBuf {
+ Path::new(env!("CARGO_MANIFEST_DIR")).join(CORPUS_DIR)
+}
+
+/// serde_json parses long decimals with best-effort precision unless its `float_roundtrip`
+/// feature is on, and 17-digit `hash01` literals can land one ulp off. Those literals are
+/// quoted here so `assert_hash01` can parse them exactly with `str::parse::<f64>`.
+fn load_json(rel: &str) -> Value {
+ let path = corpus_dir().join(rel);
+ let text = fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()));
+ let text = Regex::new(r#"("hash01"\s*:\s*)([-+.0-9eE]+)"#)
+ .unwrap()
+ .replace_all(&text, "$1\"$2\"");
+ serde_json::from_str(&text).unwrap_or_else(|e| panic!("parse {rel}: {e}"))
+}
+
+fn corpus_artifacts(manifest: &Value) -> impl Iterator<Item = &Value> {
+ manifest["artifacts"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .filter(|artifact| artifact["kind"] == "corpus")
+}
+
+/// Every `id` of an object inside a top-level array, which is how all three corpus files
+/// lay out their cases and vectors.
+fn file_case_ids(file: &Value) -> Vec<String> {
+ file.as_object()
+ .unwrap()
+ .values()
+ .filter_map(Value::as_array)
+ .flatten()
+ .filter_map(|row| row["id"].as_str())
+ .map(String::from)
+ .collect()
+}
+
+fn collect_files(root: &Path, dir: &Path, out: &mut BTreeSet<String>) {
+ for entry in fs::read_dir(dir).unwrap() {
+ let path = entry.unwrap().path();
+ if path.is_dir() {
+ collect_files(root, &path, out);
+ } else {
+ let rel = path.strip_prefix(root).unwrap();
+ out.insert(
+ rel.iter()
+ .map(|s| s.to_string_lossy())
+ .collect::<Vec<_>>()
+ .join("/"),
+ );
+ }
+ }
+}
+
+fn str_field<'a>(value: &'a Value, field: &str) -> &'a str {
+ value[field]
+ .as_str()
+ .unwrap_or_else(|| panic!("corpus field {field} must be a string in {value}"))
+}