standard_flags 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +158 -0
  3. data/README.md +566 -35
  4. data/conformance/README.md +166 -0
  5. data/conformance/bucket_vectors.json +46 -0
  6. data/conformance/guards_and_errors.json +35 -0
  7. data/conformance/legacy_env.json +38 -0
  8. data/conformance/legacy_exact.json +90 -0
  9. data/conformance/operations/write_path.json +723 -0
  10. data/conformance/permanent_flags.json +38 -0
  11. data/conformance/resolution.json +68 -0
  12. data/conformance/runtime/client.json +1431 -0
  13. data/conformance/runtime/rules.json +1305 -0
  14. data/conformance/schema/fixture.schema.json +1340 -0
  15. data/conformance/versions/legacy_ranges.json +183 -0
  16. data/conformance/versions/version_ranges.json +503 -0
  17. data/conformance/wire/client_state.json +1905 -0
  18. data/conformance/wire/delivery.json +1541 -0
  19. data/lib/standard_flags/audience.rb +49 -0
  20. data/lib/standard_flags/client.rb +157 -0
  21. data/lib/standard_flags/config.rb +21 -0
  22. data/lib/standard_flags/context.rb +70 -17
  23. data/lib/standard_flags/controller.rb +92 -10
  24. data/lib/standard_flags/definition.rb +71 -8
  25. data/lib/standard_flags/delivery.rb +195 -0
  26. data/lib/standard_flags/errors.rb +33 -0
  27. data/lib/standard_flags/job.rb +12 -1
  28. data/lib/standard_flags/mcp/flags.rb +3 -3
  29. data/lib/standard_flags/mcp/gating.rb +151 -0
  30. data/lib/standard_flags/mcp.rb +64 -5
  31. data/lib/standard_flags/notifiers/logger.rb +4 -0
  32. data/lib/standard_flags/ofrep/controller.rb +211 -0
  33. data/lib/standard_flags/ofrep.rb +115 -0
  34. data/lib/standard_flags/open_feature/provider.rb +1 -1
  35. data/lib/standard_flags/operations/rules.rb +17 -4
  36. data/lib/standard_flags/operations/validation.rb +25 -4
  37. data/lib/standard_flags/operations.rb +0 -2
  38. data/lib/standard_flags/payload.rb +8 -3
  39. data/lib/standard_flags/registry.rb +157 -12
  40. data/lib/standard_flags/runtime/cache.rb +1 -0
  41. data/lib/standard_flags/runtime/resolver.rb +26 -17
  42. data/lib/standard_flags/runtime/values.rb +8 -1
  43. data/lib/standard_flags/runtime.rb +42 -1
  44. data/lib/standard_flags/semantic_version.rb +141 -0
  45. data/lib/standard_flags/subscribers.rb +3 -0
  46. data/lib/standard_flags/testing.rb +4 -2
  47. data/lib/standard_flags/tooling.rb +25 -3
  48. data/lib/standard_flags/version.rb +1 -1
  49. data/lib/standard_flags/version_range.rb +309 -0
  50. data/lib/standard_flags.rb +38 -4
  51. metadata +24 -1
@@ -0,0 +1,1305 @@
1
+ {
2
+ "description": "Runtime rules: a stored rule (plus cohorts and memberships) and a context in; value, variant, reason, error code and rule_id out. Rules use the standard_flags_rules column names, stored values are strings, and salts default to the flag key. Each case's rules, cohorts and memberships stand alone. context.units maps unit name to unit key; context.segments lists the segments the context belongs to. Bucket numbers in case names come from bucket_vectors.json's functions.",
3
+ "suite": "runtime",
4
+ "scope": "server",
5
+ "registry": {
6
+ "units": [
7
+ "account"
8
+ ],
9
+ "flags": [
10
+ {
11
+ "kind": "flag",
12
+ "key": "new_checkout",
13
+ "owner": "payments",
14
+ "remove_by": "2027-01-01",
15
+ "final": true,
16
+ "unit": "account"
17
+ },
18
+ {
19
+ "kind": "flag",
20
+ "key": "global_banner",
21
+ "owner": "web",
22
+ "remove_by": "2027-01-01",
23
+ "final": true
24
+ },
25
+ {
26
+ "kind": "kill_switch",
27
+ "key": "ai_assistant",
28
+ "owner": "assistant",
29
+ "unit": "account"
30
+ },
31
+ {
32
+ "kind": "mode",
33
+ "key": "strict_gates",
34
+ "owner": "platform",
35
+ "preset": "sensor",
36
+ "unit": "account"
37
+ },
38
+ {
39
+ "kind": "experiment",
40
+ "key": "home_hero",
41
+ "owner": "growth",
42
+ "variants": [
43
+ "control",
44
+ "savings",
45
+ "privacy"
46
+ ],
47
+ "unit": "account"
48
+ }
49
+ ]
50
+ },
51
+ "cases": [
52
+ {
53
+ "name": "no rule serves the code default",
54
+ "flag": "new_checkout",
55
+ "environment": "production",
56
+ "context": {
57
+ "units": {
58
+ "account": "acct_1"
59
+ }
60
+ },
61
+ "rules": [],
62
+ "expected": {
63
+ "value": false,
64
+ "variant": "off",
65
+ "reason": "DEFAULT",
66
+ "rule_id": null,
67
+ "error_code": null
68
+ }
69
+ },
70
+ {
71
+ "name": "a draft rule is skipped",
72
+ "flag": "new_checkout",
73
+ "environment": "production",
74
+ "context": {
75
+ "units": {
76
+ "account": "acct_1"
77
+ }
78
+ },
79
+ "rules": [
80
+ {
81
+ "key": "new_checkout",
82
+ "status": "draft",
83
+ "fallthrough_value": "on"
84
+ }
85
+ ],
86
+ "expected": {
87
+ "value": false,
88
+ "variant": "off",
89
+ "reason": "DEFAULT",
90
+ "rule_id": null,
91
+ "error_code": null
92
+ }
93
+ },
94
+ {
95
+ "name": "a paused rule serves the code default",
96
+ "flag": "new_checkout",
97
+ "environment": "production",
98
+ "context": {
99
+ "units": {
100
+ "account": "acct_1"
101
+ }
102
+ },
103
+ "rules": [
104
+ {
105
+ "key": "new_checkout",
106
+ "status": "paused",
107
+ "percentage_bps": 10000
108
+ }
109
+ ],
110
+ "expected": {
111
+ "value": false,
112
+ "variant": "off",
113
+ "reason": "DEFAULT",
114
+ "rule_id": null,
115
+ "error_code": null
116
+ }
117
+ },
118
+ {
119
+ "name": "a stopped rule serves its stop value to everyone",
120
+ "flag": "new_checkout",
121
+ "environment": "production",
122
+ "context": {
123
+ "units": {
124
+ "account": "acct_1"
125
+ }
126
+ },
127
+ "rules": [
128
+ {
129
+ "key": "new_checkout",
130
+ "status": "stopped",
131
+ "stop_value": "on",
132
+ "fallthrough_value": "off"
133
+ }
134
+ ],
135
+ "memberships": [
136
+ {
137
+ "rule": "new_checkout",
138
+ "unit": "account",
139
+ "unit_key": "acct_1",
140
+ "value": "off"
141
+ }
142
+ ],
143
+ "expected": {
144
+ "value": true,
145
+ "variant": "on",
146
+ "reason": "STATIC",
147
+ "rule_id": "stopped",
148
+ "error_code": null
149
+ }
150
+ },
151
+ {
152
+ "name": "a stopped kill switch serving off reads as KILL_SWITCH",
153
+ "flag": "ai_assistant",
154
+ "environment": "production",
155
+ "context": {
156
+ "units": {
157
+ "account": "acct_1"
158
+ }
159
+ },
160
+ "rules": [
161
+ {
162
+ "key": "ai_assistant",
163
+ "status": "stopped",
164
+ "stop_value": "off"
165
+ }
166
+ ],
167
+ "expected": {
168
+ "value": false,
169
+ "variant": "off",
170
+ "reason": "KILL_SWITCH",
171
+ "rule_id": "stopped",
172
+ "error_code": null
173
+ }
174
+ },
175
+ {
176
+ "name": "a direct member serves its value",
177
+ "flag": "strict_gates",
178
+ "environment": "production",
179
+ "context": {
180
+ "units": {
181
+ "account": "acct_1"
182
+ }
183
+ },
184
+ "rules": [
185
+ {
186
+ "key": "strict_gates",
187
+ "status": "running",
188
+ "fallthrough_value": "sensor"
189
+ }
190
+ ],
191
+ "memberships": [
192
+ {
193
+ "rule": "strict_gates",
194
+ "unit": "account",
195
+ "unit_key": "acct_1",
196
+ "value": "on"
197
+ }
198
+ ],
199
+ "expected": {
200
+ "value": "on",
201
+ "variant": "on",
202
+ "reason": "TARGETING_MATCH",
203
+ "rule_id": "allow",
204
+ "error_code": null
205
+ }
206
+ },
207
+ {
208
+ "name": "a deny beats an allowing cohort",
209
+ "flag": "new_checkout",
210
+ "environment": "production",
211
+ "context": {
212
+ "units": {
213
+ "account": "acct_1"
214
+ }
215
+ },
216
+ "rules": [
217
+ {
218
+ "key": "new_checkout",
219
+ "status": "running",
220
+ "cohorts": [
221
+ {
222
+ "cohort": "staff",
223
+ "value": "on"
224
+ }
225
+ ]
226
+ }
227
+ ],
228
+ "cohorts": [
229
+ {
230
+ "key": "staff",
231
+ "unit": "account"
232
+ }
233
+ ],
234
+ "memberships": [
235
+ {
236
+ "rule": "new_checkout",
237
+ "unit": "account",
238
+ "unit_key": "acct_1",
239
+ "value": "off"
240
+ },
241
+ {
242
+ "cohort": "staff",
243
+ "unit": "account",
244
+ "unit_key": "acct_1",
245
+ "value": "on"
246
+ }
247
+ ],
248
+ "expected": {
249
+ "value": false,
250
+ "variant": "off",
251
+ "reason": "TARGETING_MATCH",
252
+ "rule_id": "deny",
253
+ "error_code": null
254
+ }
255
+ },
256
+ {
257
+ "name": "an expired membership never matches",
258
+ "flag": "new_checkout",
259
+ "environment": "production",
260
+ "context": {
261
+ "units": {
262
+ "account": "acct_1"
263
+ }
264
+ },
265
+ "rules": [
266
+ {
267
+ "key": "new_checkout",
268
+ "status": "running"
269
+ }
270
+ ],
271
+ "memberships": [
272
+ {
273
+ "rule": "new_checkout",
274
+ "unit": "account",
275
+ "unit_key": "acct_1",
276
+ "value": "on",
277
+ "expires_at": "2000-01-01T00:00:00Z"
278
+ }
279
+ ],
280
+ "expected": {
281
+ "value": false,
282
+ "variant": "off",
283
+ "reason": "DEFAULT",
284
+ "rule_id": null,
285
+ "error_code": null
286
+ }
287
+ },
288
+ {
289
+ "name": "a membership expiring later matches",
290
+ "flag": "new_checkout",
291
+ "environment": "production",
292
+ "context": {
293
+ "units": {
294
+ "account": "acct_1"
295
+ }
296
+ },
297
+ "rules": [
298
+ {
299
+ "key": "new_checkout",
300
+ "status": "running"
301
+ }
302
+ ],
303
+ "memberships": [
304
+ {
305
+ "rule": "new_checkout",
306
+ "unit": "account",
307
+ "unit_key": "acct_1",
308
+ "value": "on",
309
+ "expires_at": "2999-01-01T00:00:00Z"
310
+ }
311
+ ],
312
+ "expected": {
313
+ "value": true,
314
+ "variant": "on",
315
+ "reason": "TARGETING_MATCH",
316
+ "rule_id": "allow",
317
+ "error_code": null
318
+ }
319
+ },
320
+ {
321
+ "name": "the first matching cohort in declared order serves",
322
+ "flag": "strict_gates",
323
+ "environment": "production",
324
+ "context": {
325
+ "units": {
326
+ "account": "acct_1"
327
+ }
328
+ },
329
+ "rules": [
330
+ {
331
+ "key": "strict_gates",
332
+ "status": "running",
333
+ "cohorts": [
334
+ {
335
+ "cohort": "testers",
336
+ "value": "sensor"
337
+ },
338
+ {
339
+ "cohort": "staff",
340
+ "value": "on"
341
+ }
342
+ ]
343
+ }
344
+ ],
345
+ "cohorts": [
346
+ {
347
+ "key": "staff",
348
+ "unit": "account"
349
+ },
350
+ {
351
+ "key": "testers",
352
+ "unit": "account"
353
+ }
354
+ ],
355
+ "memberships": [
356
+ {
357
+ "cohort": "staff",
358
+ "unit": "account",
359
+ "unit_key": "acct_1",
360
+ "value": "on"
361
+ },
362
+ {
363
+ "cohort": "testers",
364
+ "unit": "account",
365
+ "unit_key": "acct_1",
366
+ "value": "on"
367
+ }
368
+ ],
369
+ "expected": {
370
+ "value": "sensor",
371
+ "variant": "sensor",
372
+ "reason": "TARGETING_MATCH",
373
+ "rule_id": "cohort:testers",
374
+ "error_code": null
375
+ }
376
+ },
377
+ {
378
+ "name": "a cohort serving the off value wins over earlier cohorts",
379
+ "flag": "new_checkout",
380
+ "environment": "production",
381
+ "context": {
382
+ "units": {
383
+ "account": "acct_1"
384
+ }
385
+ },
386
+ "rules": [
387
+ {
388
+ "key": "new_checkout",
389
+ "status": "running",
390
+ "cohorts": [
391
+ {
392
+ "cohort": "staff",
393
+ "value": "on"
394
+ },
395
+ {
396
+ "cohort": "testers",
397
+ "value": "off"
398
+ }
399
+ ]
400
+ }
401
+ ],
402
+ "cohorts": [
403
+ {
404
+ "key": "staff",
405
+ "unit": "account"
406
+ },
407
+ {
408
+ "key": "testers",
409
+ "unit": "account"
410
+ }
411
+ ],
412
+ "memberships": [
413
+ {
414
+ "cohort": "staff",
415
+ "unit": "account",
416
+ "unit_key": "acct_1",
417
+ "value": "on"
418
+ },
419
+ {
420
+ "cohort": "testers",
421
+ "unit": "account",
422
+ "unit_key": "acct_1",
423
+ "value": "on"
424
+ }
425
+ ],
426
+ "expected": {
427
+ "value": false,
428
+ "variant": "off",
429
+ "reason": "TARGETING_MATCH",
430
+ "rule_id": "cohort:testers",
431
+ "error_code": null
432
+ }
433
+ },
434
+ {
435
+ "name": "an archived cohort never matches",
436
+ "flag": "new_checkout",
437
+ "environment": "production",
438
+ "context": {
439
+ "units": {
440
+ "account": "acct_1"
441
+ }
442
+ },
443
+ "rules": [
444
+ {
445
+ "key": "new_checkout",
446
+ "status": "running",
447
+ "cohorts": [
448
+ {
449
+ "cohort": "staff",
450
+ "value": "on"
451
+ }
452
+ ]
453
+ }
454
+ ],
455
+ "cohorts": [
456
+ {
457
+ "key": "staff",
458
+ "unit": "account",
459
+ "archived": true
460
+ }
461
+ ],
462
+ "memberships": [
463
+ {
464
+ "cohort": "staff",
465
+ "unit": "account",
466
+ "unit_key": "acct_1",
467
+ "value": "on"
468
+ }
469
+ ],
470
+ "expected": {
471
+ "value": false,
472
+ "variant": "off",
473
+ "reason": "DEFAULT",
474
+ "rule_id": null,
475
+ "error_code": null
476
+ }
477
+ },
478
+ {
479
+ "name": "a matching segment serves its value",
480
+ "flag": "new_checkout",
481
+ "environment": "production",
482
+ "context": {
483
+ "units": {
484
+ "account": "acct_1"
485
+ },
486
+ "segments": [
487
+ "beta"
488
+ ]
489
+ },
490
+ "rules": [
491
+ {
492
+ "key": "new_checkout",
493
+ "status": "running",
494
+ "conditions": {
495
+ "segments": [
496
+ {
497
+ "name": "alpha",
498
+ "value": "off"
499
+ },
500
+ {
501
+ "name": "beta",
502
+ "value": "on"
503
+ }
504
+ ]
505
+ },
506
+ "fallthrough_value": "off"
507
+ }
508
+ ],
509
+ "expected": {
510
+ "value": true,
511
+ "variant": "on",
512
+ "reason": "TARGETING_MATCH",
513
+ "rule_id": "segment:beta",
514
+ "error_code": null
515
+ }
516
+ },
517
+ {
518
+ "name": "no matching segment goes on down the rule",
519
+ "flag": "new_checkout",
520
+ "environment": "production",
521
+ "context": {
522
+ "units": {
523
+ "account": "acct_1"
524
+ }
525
+ },
526
+ "rules": [
527
+ {
528
+ "key": "new_checkout",
529
+ "status": "running",
530
+ "conditions": {
531
+ "segments": [
532
+ {
533
+ "name": "beta",
534
+ "value": "on"
535
+ }
536
+ ]
537
+ },
538
+ "fallthrough_value": "off"
539
+ }
540
+ ],
541
+ "expected": {
542
+ "value": false,
543
+ "variant": "off",
544
+ "reason": "TARGETING_MATCH",
545
+ "rule_id": "fallthrough",
546
+ "error_code": null
547
+ }
548
+ },
549
+ {
550
+ "name": "met client conditions reach the percentage",
551
+ "flag": "new_checkout",
552
+ "environment": "production",
553
+ "context": {
554
+ "units": {
555
+ "account": "acct_1"
556
+ },
557
+ "client": {
558
+ "platform": "android",
559
+ "version": "1.4.0"
560
+ }
561
+ },
562
+ "rules": [
563
+ {
564
+ "key": "new_checkout",
565
+ "status": "running",
566
+ "percentage_bps": 10000,
567
+ "fallthrough_value": "off",
568
+ "conditions": {
569
+ "platforms": [
570
+ "android"
571
+ ],
572
+ "versions": {
573
+ "android": ">= 1.4.0"
574
+ }
575
+ }
576
+ }
577
+ ],
578
+ "expected": {
579
+ "value": true,
580
+ "variant": "on",
581
+ "reason": "SPLIT",
582
+ "rule_id": "percentage",
583
+ "error_code": null
584
+ }
585
+ },
586
+ {
587
+ "name": "a client below the version range skips to the fallthrough",
588
+ "flag": "new_checkout",
589
+ "environment": "production",
590
+ "context": {
591
+ "units": {
592
+ "account": "acct_1"
593
+ },
594
+ "client": {
595
+ "platform": "android",
596
+ "version": "1.3.9"
597
+ }
598
+ },
599
+ "rules": [
600
+ {
601
+ "key": "new_checkout",
602
+ "status": "running",
603
+ "percentage_bps": 10000,
604
+ "fallthrough_value": "off",
605
+ "conditions": {
606
+ "versions": {
607
+ "android": ">= 1.4.0"
608
+ }
609
+ }
610
+ }
611
+ ],
612
+ "expected": {
613
+ "value": false,
614
+ "variant": "off",
615
+ "reason": "TARGETING_MATCH",
616
+ "rule_id": "fallthrough",
617
+ "error_code": null
618
+ }
619
+ },
620
+ {
621
+ "name": "an unlisted platform skips to the fallthrough",
622
+ "flag": "new_checkout",
623
+ "environment": "production",
624
+ "context": {
625
+ "units": {
626
+ "account": "acct_1"
627
+ },
628
+ "client": {
629
+ "platform": "android",
630
+ "version": "9.0"
631
+ }
632
+ },
633
+ "rules": [
634
+ {
635
+ "key": "new_checkout",
636
+ "status": "running",
637
+ "percentage_bps": 10000,
638
+ "fallthrough_value": "off",
639
+ "conditions": {
640
+ "platforms": [
641
+ "ios"
642
+ ]
643
+ }
644
+ }
645
+ ],
646
+ "expected": {
647
+ "value": false,
648
+ "variant": "off",
649
+ "reason": "TARGETING_MATCH",
650
+ "rule_id": "fallthrough",
651
+ "error_code": null
652
+ }
653
+ },
654
+ {
655
+ "name": "v2: rollout bucket 6564 is inside percentage_bps 6565",
656
+ "flag": "new_checkout",
657
+ "environment": "production",
658
+ "context": {
659
+ "units": {
660
+ "account": "acct_1"
661
+ }
662
+ },
663
+ "rules": [
664
+ {
665
+ "key": "new_checkout",
666
+ "status": "running",
667
+ "salt": "rollout_salt",
668
+ "percentage_bps": 6565,
669
+ "fallthrough_value": "off"
670
+ }
671
+ ],
672
+ "expected": {
673
+ "value": true,
674
+ "variant": "on",
675
+ "reason": "SPLIT",
676
+ "rule_id": "percentage",
677
+ "error_code": null
678
+ }
679
+ },
680
+ {
681
+ "name": "v2: rollout bucket 6564 is outside percentage_bps 6564",
682
+ "flag": "new_checkout",
683
+ "environment": "production",
684
+ "context": {
685
+ "units": {
686
+ "account": "acct_1"
687
+ }
688
+ },
689
+ "rules": [
690
+ {
691
+ "key": "new_checkout",
692
+ "status": "running",
693
+ "salt": "rollout_salt",
694
+ "percentage_bps": 6564,
695
+ "fallthrough_value": "off"
696
+ }
697
+ ],
698
+ "expected": {
699
+ "value": false,
700
+ "variant": "off",
701
+ "reason": "TARGETING_MATCH",
702
+ "rule_id": "fallthrough",
703
+ "error_code": null
704
+ }
705
+ },
706
+ {
707
+ "name": "v1: bucket 7720 is inside percentage_bps 7721",
708
+ "flag": "new_checkout",
709
+ "environment": "production",
710
+ "context": {
711
+ "units": {
712
+ "account": "acct_2"
713
+ }
714
+ },
715
+ "rules": [
716
+ {
717
+ "key": "new_checkout",
718
+ "status": "running",
719
+ "hash_version": 1,
720
+ "salt": "legacy_salt",
721
+ "percentage_bps": 7721
722
+ }
723
+ ],
724
+ "expected": {
725
+ "value": true,
726
+ "variant": "on",
727
+ "reason": "SPLIT",
728
+ "rule_id": "percentage",
729
+ "error_code": null
730
+ }
731
+ },
732
+ {
733
+ "name": "v1: bucket 7720 is outside percentage_bps 7720",
734
+ "flag": "new_checkout",
735
+ "environment": "production",
736
+ "context": {
737
+ "units": {
738
+ "account": "acct_2"
739
+ }
740
+ },
741
+ "rules": [
742
+ {
743
+ "key": "new_checkout",
744
+ "status": "running",
745
+ "hash_version": 1,
746
+ "salt": "legacy_salt",
747
+ "percentage_bps": 7720
748
+ }
749
+ ],
750
+ "expected": {
751
+ "value": false,
752
+ "variant": "off",
753
+ "reason": "DEFAULT",
754
+ "rule_id": null,
755
+ "error_code": null
756
+ }
757
+ },
758
+ {
759
+ "name": "v2: variant bucket 3055 is inside a first weight of 3056",
760
+ "flag": "home_hero",
761
+ "environment": "production",
762
+ "context": {
763
+ "units": {
764
+ "account": "acct_1"
765
+ }
766
+ },
767
+ "rules": [
768
+ {
769
+ "key": "home_hero",
770
+ "status": "running",
771
+ "salt": "variant_salt",
772
+ "variant_weights": {
773
+ "control": 3056,
774
+ "savings": 6944
775
+ }
776
+ }
777
+ ],
778
+ "expected": {
779
+ "value": "control",
780
+ "variant": "control",
781
+ "reason": "SPLIT",
782
+ "rule_id": "variants",
783
+ "error_code": null
784
+ }
785
+ },
786
+ {
787
+ "name": "v2: variant bucket 3055 is past a first weight of 3055",
788
+ "flag": "home_hero",
789
+ "environment": "production",
790
+ "context": {
791
+ "units": {
792
+ "account": "acct_1"
793
+ }
794
+ },
795
+ "rules": [
796
+ {
797
+ "key": "home_hero",
798
+ "status": "running",
799
+ "salt": "variant_salt",
800
+ "variant_weights": {
801
+ "savings": 6945,
802
+ "control": 3055
803
+ }
804
+ }
805
+ ],
806
+ "expected": {
807
+ "value": "savings",
808
+ "variant": "savings",
809
+ "reason": "SPLIT",
810
+ "rule_id": "variants",
811
+ "error_code": null
812
+ }
813
+ },
814
+ {
815
+ "name": "v1: variant bucket 7720 is past a first weight of 7720",
816
+ "flag": "home_hero",
817
+ "environment": "production",
818
+ "context": {
819
+ "units": {
820
+ "account": "acct_2"
821
+ }
822
+ },
823
+ "rules": [
824
+ {
825
+ "key": "home_hero",
826
+ "status": "running",
827
+ "hash_version": 1,
828
+ "salt": "legacy_salt",
829
+ "variant_weights": {
830
+ "control": 7720,
831
+ "savings": 2280
832
+ }
833
+ }
834
+ ],
835
+ "expected": {
836
+ "value": "savings",
837
+ "variant": "savings",
838
+ "reason": "SPLIT",
839
+ "rule_id": "variants",
840
+ "error_code": null
841
+ }
842
+ },
843
+ {
844
+ "name": "v1: variant bucket 7720 is inside a first weight of 7721",
845
+ "flag": "home_hero",
846
+ "environment": "production",
847
+ "context": {
848
+ "units": {
849
+ "account": "acct_2"
850
+ }
851
+ },
852
+ "rules": [
853
+ {
854
+ "key": "home_hero",
855
+ "status": "running",
856
+ "hash_version": 1,
857
+ "salt": "legacy_salt",
858
+ "variant_weights": {
859
+ "control": 7721,
860
+ "privacy": 2279
861
+ }
862
+ }
863
+ ],
864
+ "expected": {
865
+ "value": "control",
866
+ "variant": "control",
867
+ "reason": "SPLIT",
868
+ "rule_id": "variants",
869
+ "error_code": null
870
+ }
871
+ },
872
+ {
873
+ "name": "variants wait behind the percentage",
874
+ "flag": "home_hero",
875
+ "environment": "production",
876
+ "context": {
877
+ "units": {
878
+ "account": "acct_1"
879
+ }
880
+ },
881
+ "rules": [
882
+ {
883
+ "key": "home_hero",
884
+ "status": "running",
885
+ "salt": "rollout_salt",
886
+ "percentage_bps": 6564,
887
+ "variant_weights": {
888
+ "savings": 10000
889
+ }
890
+ }
891
+ ],
892
+ "expected": {
893
+ "value": "control",
894
+ "variant": "control",
895
+ "reason": "DEFAULT",
896
+ "rule_id": null,
897
+ "error_code": null
898
+ }
899
+ },
900
+ {
901
+ "name": "percentage_bps 0 serves nobody",
902
+ "flag": "new_checkout",
903
+ "environment": "production",
904
+ "context": {
905
+ "units": {
906
+ "account": "acct_1"
907
+ }
908
+ },
909
+ "rules": [
910
+ {
911
+ "key": "new_checkout",
912
+ "status": "running",
913
+ "percentage_bps": 0
914
+ }
915
+ ],
916
+ "expected": {
917
+ "value": false,
918
+ "variant": "off",
919
+ "reason": "DEFAULT",
920
+ "rule_id": null,
921
+ "error_code": null
922
+ }
923
+ },
924
+ {
925
+ "name": "percentage_bps 10000 serves everybody",
926
+ "flag": "new_checkout",
927
+ "environment": "production",
928
+ "context": {
929
+ "units": {
930
+ "account": "acct_1"
931
+ }
932
+ },
933
+ "rules": [
934
+ {
935
+ "key": "new_checkout",
936
+ "status": "running",
937
+ "percentage_bps": 10000
938
+ }
939
+ ],
940
+ "expected": {
941
+ "value": true,
942
+ "variant": "on",
943
+ "reason": "SPLIT",
944
+ "rule_id": "percentage",
945
+ "error_code": null
946
+ }
947
+ },
948
+ {
949
+ "name": "a mode rolls out to its rollout value",
950
+ "flag": "strict_gates",
951
+ "environment": "production",
952
+ "context": {
953
+ "units": {
954
+ "account": "acct_1"
955
+ }
956
+ },
957
+ "rules": [
958
+ {
959
+ "key": "strict_gates",
960
+ "status": "running",
961
+ "percentage_bps": 10000,
962
+ "rollout_value": "sensor"
963
+ }
964
+ ],
965
+ "expected": {
966
+ "value": "sensor",
967
+ "variant": "sensor",
968
+ "reason": "SPLIT",
969
+ "rule_id": "percentage",
970
+ "error_code": null
971
+ }
972
+ },
973
+ {
974
+ "name": "a kill switch thrown off in the fallthrough reads as KILL_SWITCH",
975
+ "flag": "ai_assistant",
976
+ "environment": "production",
977
+ "context": {
978
+ "units": {
979
+ "account": "acct_1"
980
+ }
981
+ },
982
+ "rules": [
983
+ {
984
+ "key": "ai_assistant",
985
+ "status": "running",
986
+ "fallthrough_value": "off"
987
+ }
988
+ ],
989
+ "expected": {
990
+ "value": false,
991
+ "variant": "off",
992
+ "reason": "KILL_SWITCH",
993
+ "rule_id": "fallthrough",
994
+ "error_code": null
995
+ }
996
+ },
997
+ {
998
+ "name": "a fallthrough needs no unit",
999
+ "flag": "global_banner",
1000
+ "environment": "production",
1001
+ "context": {},
1002
+ "rules": [
1003
+ {
1004
+ "key": "global_banner",
1005
+ "status": "running",
1006
+ "fallthrough_value": "on"
1007
+ }
1008
+ ],
1009
+ "expected": {
1010
+ "value": true,
1011
+ "variant": "on",
1012
+ "reason": "TARGETING_MATCH",
1013
+ "rule_id": "fallthrough",
1014
+ "error_code": null
1015
+ }
1016
+ },
1017
+ {
1018
+ "name": "a running rule with no fallthrough serves the code default",
1019
+ "flag": "new_checkout",
1020
+ "environment": "production",
1021
+ "context": {
1022
+ "units": {
1023
+ "account": "acct_1"
1024
+ }
1025
+ },
1026
+ "rules": [
1027
+ {
1028
+ "key": "new_checkout",
1029
+ "status": "running"
1030
+ }
1031
+ ],
1032
+ "expected": {
1033
+ "value": false,
1034
+ "variant": "off",
1035
+ "reason": "DEFAULT",
1036
+ "rule_id": null,
1037
+ "error_code": null
1038
+ }
1039
+ },
1040
+ {
1041
+ "name": "a missing unit key serves the fallthrough with TARGETING_KEY_MISSING",
1042
+ "flag": "new_checkout",
1043
+ "environment": "production",
1044
+ "context": {},
1045
+ "rules": [
1046
+ {
1047
+ "key": "new_checkout",
1048
+ "status": "running",
1049
+ "percentage_bps": 10000,
1050
+ "fallthrough_value": "on"
1051
+ }
1052
+ ],
1053
+ "expected": {
1054
+ "value": true,
1055
+ "variant": "on",
1056
+ "reason": "ERROR",
1057
+ "rule_id": "fallthrough",
1058
+ "error_code": "TARGETING_KEY_MISSING"
1059
+ }
1060
+ },
1061
+ {
1062
+ "name": "a missing unit key without a fallthrough serves the code default",
1063
+ "flag": "strict_gates",
1064
+ "environment": "production",
1065
+ "context": {},
1066
+ "rules": [
1067
+ {
1068
+ "key": "strict_gates",
1069
+ "status": "running",
1070
+ "percentage_bps": 10000,
1071
+ "rollout_value": "on"
1072
+ }
1073
+ ],
1074
+ "expected": {
1075
+ "value": "off",
1076
+ "variant": "off",
1077
+ "reason": "ERROR",
1078
+ "rule_id": null,
1079
+ "error_code": "TARGETING_KEY_MISSING"
1080
+ }
1081
+ },
1082
+ {
1083
+ "name": "a stored value the flag can't take fails only that flag",
1084
+ "flag": "new_checkout",
1085
+ "environment": "production",
1086
+ "context": {
1087
+ "units": {
1088
+ "account": "acct_1"
1089
+ }
1090
+ },
1091
+ "rules": [
1092
+ {
1093
+ "key": "new_checkout",
1094
+ "status": "running",
1095
+ "fallthrough_value": "maybe"
1096
+ }
1097
+ ],
1098
+ "expected": {
1099
+ "value": false,
1100
+ "variant": "off",
1101
+ "reason": "ERROR",
1102
+ "rule_id": null,
1103
+ "error_code": "PARSE_ERROR"
1104
+ }
1105
+ },
1106
+ {
1107
+ "name": "a value outside the flag's values fails open for a kill switch",
1108
+ "flag": "ai_assistant",
1109
+ "environment": "production",
1110
+ "context": {
1111
+ "units": {
1112
+ "account": "acct_1"
1113
+ }
1114
+ },
1115
+ "rules": [
1116
+ {
1117
+ "key": "ai_assistant",
1118
+ "status": "stopped",
1119
+ "stop_value": "sensor"
1120
+ }
1121
+ ],
1122
+ "expected": {
1123
+ "value": true,
1124
+ "variant": "on",
1125
+ "reason": "ERROR",
1126
+ "rule_id": null,
1127
+ "error_code": "PARSE_ERROR"
1128
+ }
1129
+ },
1130
+ {
1131
+ "name": "variant weights not summing to 10000 fail the flag",
1132
+ "flag": "home_hero",
1133
+ "environment": "production",
1134
+ "context": {
1135
+ "units": {
1136
+ "account": "acct_1"
1137
+ }
1138
+ },
1139
+ "rules": [
1140
+ {
1141
+ "key": "home_hero",
1142
+ "status": "running",
1143
+ "variant_weights": {
1144
+ "control": 5000,
1145
+ "savings": 4000
1146
+ }
1147
+ }
1148
+ ],
1149
+ "expected": {
1150
+ "value": "control",
1151
+ "variant": "control",
1152
+ "reason": "ERROR",
1153
+ "rule_id": null,
1154
+ "error_code": "PARSE_ERROR"
1155
+ }
1156
+ },
1157
+ {
1158
+ "name": "a mode percentage without a rollout value fails the flag",
1159
+ "flag": "strict_gates",
1160
+ "environment": "production",
1161
+ "context": {
1162
+ "units": {
1163
+ "account": "acct_1"
1164
+ }
1165
+ },
1166
+ "rules": [
1167
+ {
1168
+ "key": "strict_gates",
1169
+ "status": "running",
1170
+ "percentage_bps": 10000
1171
+ }
1172
+ ],
1173
+ "expected": {
1174
+ "value": "off",
1175
+ "variant": "off",
1176
+ "reason": "ERROR",
1177
+ "rule_id": null,
1178
+ "error_code": "PARSE_ERROR"
1179
+ }
1180
+ },
1181
+ {
1182
+ "name": "conditions stored as a list fail the flag",
1183
+ "flag": "new_checkout",
1184
+ "environment": "production",
1185
+ "context": {
1186
+ "units": {
1187
+ "account": "acct_1"
1188
+ },
1189
+ "client": {
1190
+ "platform": "ios",
1191
+ "version": "3.0"
1192
+ }
1193
+ },
1194
+ "rules": [
1195
+ {
1196
+ "key": "new_checkout",
1197
+ "status": "running",
1198
+ "fallthrough_value": "on",
1199
+ "conditions": [
1200
+ "ios"
1201
+ ]
1202
+ }
1203
+ ],
1204
+ "expected": {
1205
+ "value": false,
1206
+ "variant": "off",
1207
+ "reason": "ERROR",
1208
+ "rule_id": null,
1209
+ "error_code": "PARSE_ERROR"
1210
+ }
1211
+ },
1212
+ {
1213
+ "name": "version ranges stored as a string fail the flag",
1214
+ "flag": "new_checkout",
1215
+ "environment": "production",
1216
+ "context": {
1217
+ "units": {
1218
+ "account": "acct_1"
1219
+ },
1220
+ "client": {
1221
+ "platform": "ios",
1222
+ "version": "3.0"
1223
+ }
1224
+ },
1225
+ "rules": [
1226
+ {
1227
+ "key": "new_checkout",
1228
+ "status": "running",
1229
+ "fallthrough_value": "on",
1230
+ "conditions": {
1231
+ "platforms": [
1232
+ "ios"
1233
+ ],
1234
+ "versions": "ios >= 2"
1235
+ }
1236
+ }
1237
+ ],
1238
+ "expected": {
1239
+ "value": false,
1240
+ "variant": "off",
1241
+ "reason": "ERROR",
1242
+ "rule_id": null,
1243
+ "error_code": "PARSE_ERROR"
1244
+ }
1245
+ },
1246
+ {
1247
+ "name": "platforms stored as a string fail the flag",
1248
+ "flag": "new_checkout",
1249
+ "environment": "production",
1250
+ "context": {
1251
+ "units": {
1252
+ "account": "acct_1"
1253
+ },
1254
+ "client": {
1255
+ "platform": "ios",
1256
+ "version": "3.0"
1257
+ }
1258
+ },
1259
+ "rules": [
1260
+ {
1261
+ "key": "new_checkout",
1262
+ "status": "running",
1263
+ "fallthrough_value": "on",
1264
+ "conditions": {
1265
+ "platforms": "ios"
1266
+ }
1267
+ }
1268
+ ],
1269
+ "expected": {
1270
+ "value": false,
1271
+ "variant": "off",
1272
+ "reason": "ERROR",
1273
+ "rule_id": null,
1274
+ "error_code": "PARSE_ERROR"
1275
+ }
1276
+ },
1277
+ {
1278
+ "name": "an ENV pin beats the rule",
1279
+ "flag": "new_checkout",
1280
+ "environment": "production",
1281
+ "env_vars": {
1282
+ "STANDARD_FLAGS_NEW_CHECKOUT": "off"
1283
+ },
1284
+ "context": {
1285
+ "units": {
1286
+ "account": "acct_1"
1287
+ }
1288
+ },
1289
+ "rules": [
1290
+ {
1291
+ "key": "new_checkout",
1292
+ "status": "running",
1293
+ "fallthrough_value": "on"
1294
+ }
1295
+ ],
1296
+ "expected": {
1297
+ "value": false,
1298
+ "variant": "off",
1299
+ "reason": "ENV_PIN",
1300
+ "rule_id": null,
1301
+ "error_code": null
1302
+ }
1303
+ }
1304
+ ]
1305
+ }