broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(segment, user):
    key = user.get('key')
    def hit(clause):
        attr, values = clause
        value = user.get(attr)
        items = value if isinstance(value, list) else [value]
        return any(item in values for item in items)
    if key in segment.get('included', []):
        return [True, 'included']
    if key in segment.get('excluded', []):
        return [False, 'excluded']
    for i, rule in enumerate(segment.get('rules', [])):
        clauses = rule.get('clauses', [])
        if clauses and all(hit(c) for c in clauses):
            return [True, 'rule:%d' % i]
    return [False, 'none']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('explicit inclusion beats exclusion',
   [{'included': ['k1'], 'excluded': ['k1'], 'rules': []}, {'key': 'k1'}],
   [True, 'included']),
  ('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('segment sample 1',
   [{'included': ['k3'], 'excluded': ['k2', 'k1'], 'rules': [{'clauses': []}, {'clauses': []}]},
    {'key': 'k2', 'groups': ['beta'], 'tier': 'gold'}],
   [False, 'excluded']),
  ('segment sample 2',
   [{'included': [], 'excluded': ['k4', 'k1'], 'rules': [{'clauses': [['groups', ['staff', 'gold']]]}]},
    {'key': 'k4', 'region': 'eu'}],
   [False, 'excluded']),
  ('segment sample 3',
   [{'included': ['k4', 'k3'], 'excluded': ['k4'], 'rules': []}, {'key': 'k3'}],
   [True, 'included'])],
 [('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('segment sample 6',
   [{'included': ['k4'], 'excluded': [], 'rules': []}, {'key': 'k2', 'region': 'us'}],
   [False, 'none']),
  ('segment sample 20',
   [{'included': ['k3', 'k2'],
     'excluded': [],
     'rules': [{'clauses': [['tier', ['eu', 'gold']], ['tier', [None, 'gold']]]},
               {'clauses': [['tier', [None, '']]]}]},
    {'key': 'k4', 'region': ''}],
   [False, 'none']),
  ('segment sample 53',
   [{'included': ['k4', 'k3'],
     'excluded': ['k4'],
     'rules': [{'clauses': [['groups', ['', 'gold']], ['groups', ['', 'gold']]]}]},
    {'key': 'k9', 'region': 'eu', 'tier': 'gold'}],
   [False, 'none'])],
 [('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 11',
   [{'included': ['k1'], 'excluded': ['k3'], 'rules': [{'clauses': []}]},
    {'key': 'k2', 'groups': ['staff', 'eu'], 'tier': 'gold'}],
   [False, 'none']),
  ('segment sample 37',
   [{'included': ['k4', 'k3'],
     'excluded': [],
     'rules': [{'clauses': [['groups', [None, 'staff']]]}, {'clauses': [['region', ['staff', '']]]}]},
    {'key': 'k1', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 42',
   [{'included': [],
     'excluded': ['k4'],
     'rules': [{'clauses': [['region', ['gold', 'eu']], ['region', ['staff', '']]]},
               {'clauses': [['tier', [None, 'eu']]]}]},
    {'key': 'k3', 'groups': ['x'], 'region': ''}],
   [False, 'none'])],
 [('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('segment sample 9',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['tier', ['eu', None]]]}]},
    {'key': 'k2', 'groups': ['beta']}],
   [False, 'none']),
  ('segment sample 13',
   [{'included': ['k1', 'k4'],
     'excluded': [],
     'rules': [{'clauses': []}, {'clauses': [['region', ['', 'eu']]]}]},
    {'key': 'k3', 'groups': 'beta', 'tier': None}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0'])],
 [('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('second rule index',
   [{'included': [],
     'excluded': [],
     'rules': [{'clauses': [['region', ['us']]]}, {'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [True, 'rule:1']),
  ('segment sample 4',
   [{'included': ['k1', 'k2'], 'excluded': [], 'rules': [{'clauses': [['groups', ['', 'beta']]]}]},
    {'key': 'k4', 'region': 'eu'}],
   [False, 'none']),
  ('segment sample 21',
   [{'included': ['k3'], 'excluded': [], 'rules': []}, {'key': 'k9', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 31',
   [{'included': ['k2', 'k4'],
     'excluded': ['k4'],
     'rules': [{'clauses': [['groups', ['gold', None]]]}, {'clauses': [['groups', ['gold', 'beta']]]}]},
    {'key': 'k1', 'region': 'us'}],
   [False, 'none'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(segment, user):
    key = user.get('key')
    def hit(clause):
        attr, values = clause
        value = user.get(attr, '')
        items = value if isinstance(value, list) else [value]
        return any(item in values for item in items)
    if key in segment.get('included', []):
        return [True, 'included']
    if key in segment.get('excluded', []):
        return [False, 'excluded']
    for i, rule in enumerate(segment.get('rules', [])):
        clauses = rule.get('clauses', [])
        if clauses and all(hit(c) for c in clauses):
            return [True, 'rule:%d' % i]
    return [False, 'none']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('explicit inclusion beats exclusion',
   [{'included': ['k1'], 'excluded': ['k1'], 'rules': []}, {'key': 'k1'}],
   [True, 'included']),
  ('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('segment sample 1',
   [{'included': ['k3'], 'excluded': ['k2', 'k1'], 'rules': [{'clauses': []}, {'clauses': []}]},
    {'key': 'k2', 'groups': ['beta'], 'tier': 'gold'}],
   [False, 'excluded']),
  ('segment sample 2',
   [{'included': [], 'excluded': ['k4', 'k1'], 'rules': [{'clauses': [['groups', ['staff', 'gold']]]}]},
    {'key': 'k4', 'region': 'eu'}],
   [False, 'excluded']),
  ('segment sample 3',
   [{'included': ['k4', 'k3'], 'excluded': ['k4'], 'rules': []}, {'key': 'k3'}],
   [True, 'included'])],
 [('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('segment sample 6',
   [{'included': ['k4'], 'excluded': [], 'rules': []}, {'key': 'k2', 'region': 'us'}],
   [False, 'none']),
  ('segment sample 20',
   [{'included': ['k3', 'k2'],
     'excluded': [],
     'rules': [{'clauses': [['tier', ['eu', 'gold']], ['tier', [None, 'gold']]]},
               {'clauses': [['tier', [None, '']]]}]},
    {'key': 'k4', 'region': ''}],
   [False, 'none']),
  ('segment sample 53',
   [{'included': ['k4', 'k3'],
     'excluded': ['k4'],
     'rules': [{'clauses': [['groups', ['', 'gold']], ['groups', ['', 'gold']]]}]},
    {'key': 'k9', 'region': 'eu', 'tier': 'gold'}],
   [False, 'none'])],
 [('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 11',
   [{'included': ['k1'], 'excluded': ['k3'], 'rules': [{'clauses': []}]},
    {'key': 'k2', 'groups': ['staff', 'eu'], 'tier': 'gold'}],
   [False, 'none']),
  ('segment sample 37',
   [{'included': ['k4', 'k3'],
     'excluded': [],
     'rules': [{'clauses': [['groups', [None, 'staff']]]}, {'clauses': [['region', ['staff', '']]]}]},
    {'key': 'k1', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 42',
   [{'included': [],
     'excluded': ['k4'],
     'rules': [{'clauses': [['region', ['gold', 'eu']], ['region', ['staff', '']]]},
               {'clauses': [['tier', [None, 'eu']]]}]},
    {'key': 'k3', 'groups': ['x'], 'region': ''}],
   [False, 'none'])],
 [('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('segment sample 9',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['tier', ['eu', None]]]}]},
    {'key': 'k2', 'groups': ['beta']}],
   [False, 'none']),
  ('segment sample 13',
   [{'included': ['k1', 'k4'],
     'excluded': [],
     'rules': [{'clauses': []}, {'clauses': [['region', ['', 'eu']]]}]},
    {'key': 'k3', 'groups': 'beta', 'tier': None}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0'])],
 [('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('second rule index',
   [{'included': [],
     'excluded': [],
     'rules': [{'clauses': [['region', ['us']]]}, {'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [True, 'rule:1']),
  ('segment sample 4',
   [{'included': ['k1', 'k2'], 'excluded': [], 'rules': [{'clauses': [['groups', ['', 'beta']]]}]},
    {'key': 'k4', 'region': 'eu'}],
   [False, 'none']),
  ('segment sample 21',
   [{'included': ['k3'], 'excluded': [], 'rules': []}, {'key': 'k9', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 31',
   [{'included': ['k2', 'k4'],
     'excluded': ['k4'],
     'rules': [{'clauses': [['groups', ['gold', None]]]}, {'clauses': [['groups', ['gold', 'beta']]]}]},
    {'key': 'k1', 'region': 'us'}],
   [False, 'none'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Users without a tier attribute join a segment whose clause lists null among its values.

A user is in the segment if its key is in included (reason included, which beats excluded); else not if its key is in excluded; else if some rule with a non-empty clause list has every clause matching (reason rule:i). A clause [attr, values] matches only when the attribute is present and its value (or any element of a list value) is in values. Otherwise [False, none].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(segment, user):
    key = user.get('key')
    def hit(clause):
        attr, values = clause
        if attr not in user:
            return False
        value = user[attr]
        items = [value]
        return any(item in values for item in items)
    if key in segment.get('included', []):
        return [True, 'included']
    if key in segment.get('excluded', []):
        return [False, 'excluded']
    for i, rule in enumerate(segment.get('rules', [])):
        clauses = rule.get('clauses', [])
        if clauses and all(hit(c) for c in clauses):
            return [True, 'rule:%d' % i]
    return [False, 'none']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('explicit inclusion beats exclusion',
   [{'included': ['k1'], 'excluded': ['k1'], 'rules': []}, {'key': 'k1'}],
   [True, 'included']),
  ('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 1',
   [{'included': ['k3'], 'excluded': ['k2', 'k1'], 'rules': [{'clauses': []}, {'clauses': []}]},
    {'key': 'k2', 'groups': ['beta'], 'tier': 'gold'}],
   [False, 'excluded'])],
 [('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 6',
   [{'included': ['k4'], 'excluded': [], 'rules': []}, {'key': 'k2', 'region': 'us'}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0'])],
 [('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 11',
   [{'included': ['k1'], 'excluded': ['k3'], 'rules': [{'clauses': []}]},
    {'key': 'k2', 'groups': ['staff', 'eu'], 'tier': 'gold'}],
   [False, 'none']),
  ('segment sample 12',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['staff', '']]]}, {'clauses': []}]},
    {'key': 'k9', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0'])],
 [('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0']),
  ('segment sample 17',
   [{'included': [], 'excluded': ['k4'], 'rules': []},
    {'key': 'k3', 'groups': ['staff', 'eu'], 'region': 'us'}],
   [False, 'none']),
  ('segment sample 18',
   [{'included': ['k3'], 'excluded': [], 'rules': []}, {'key': 'k2', 'tier': None}],
   [False, 'none'])],
 [('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('second rule index',
   [{'included': [],
     'excluded': [],
     'rules': [{'clauses': [['region', ['us']]]}, {'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [True, 'rule:1']),
  ('segment sample 21',
   [{'included': ['k3'], 'excluded': [], 'rules': []}, {'key': 'k9', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 22',
   [{'included': [], 'excluded': ['k1'], 'rules': []}, {'key': 'k2', 'region': 'us'}],
   [False, 'none']),
  ('segment sample 23',
   [{'included': ['k1'], 'excluded': [], 'rules': [{'clauses': []}]},
    {'key': 'k3', 'region': 'us', 'tier': 'gold'}],
   [False, 'none'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(segment, user):
    key = user.get('key')
    def hit(clause):
        attr, values = clause
        if attr not in user:
            return False
        value = user[attr]
        items = value if isinstance(value, list) else [value]
        return all(item in values for item in items)
    if key in segment.get('included', []):
        return [True, 'included']
    if key in segment.get('excluded', []):
        return [False, 'excluded']
    for i, rule in enumerate(segment.get('rules', [])):
        clauses = rule.get('clauses', [])
        if clauses and all(hit(c) for c in clauses):
            return [True, 'rule:%d' % i]
    return [False, 'none']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('explicit inclusion beats exclusion',
   [{'included': ['k1'], 'excluded': ['k1'], 'rules': []}, {'key': 'k1'}],
   [True, 'included']),
  ('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 1',
   [{'included': ['k3'], 'excluded': ['k2', 'k1'], 'rules': [{'clauses': []}, {'clauses': []}]},
    {'key': 'k2', 'groups': ['beta'], 'tier': 'gold'}],
   [False, 'excluded'])],
 [('exclusion blocks a matching rule',
   [{'included': ['k2'], 'excluded': ['k1'], 'rules': [{'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [False, 'excluded']),
  ('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 6',
   [{'included': ['k4'], 'excluded': [], 'rules': []}, {'key': 'k2', 'region': 'us'}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0'])],
 [('empty clause list never matches',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': []}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('segment sample 11',
   [{'included': ['k1'], 'excluded': ['k3'], 'rules': [{'clauses': []}]},
    {'key': 'k2', 'groups': ['staff', 'eu'], 'tier': 'gold'}],
   [False, 'none']),
  ('segment sample 12',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['staff', '']]]}, {'clauses': []}]},
    {'key': 'k9', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0'])],
 [('absent attribute does not match a null value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['tier', [None, 'gold']]]}]}, {'key': 'k3'}],
   [False, 'none']),
  ('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('segment sample 16',
   [{'included': ['k3', 'k1'], 'excluded': [], 'rules': [{'clauses': [['groups', ['gold', 'staff']]]}]},
    {'key': 'k2', 'groups': ['beta', 'staff'], 'region': 'eu'}],
   [True, 'rule:0']),
  ('segment sample 17',
   [{'included': [], 'excluded': ['k4'], 'rules': []},
    {'key': 'k3', 'groups': ['staff', 'eu'], 'region': 'us'}],
   [False, 'none']),
  ('segment sample 18',
   [{'included': ['k3'], 'excluded': [], 'rules': []}, {'key': 'k2', 'tier': None}],
   [False, 'none'])],
 [('absent attribute does not match an empty string value',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['']]]}]}, {'key': 'k4'}],
   [False, 'none']),
  ('list attribute matches through any element',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': ['staff', 'beta']}],
   [True, 'rule:0']),
  ('empty list attribute is not a member',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['groups', ['beta']]]}]},
    {'key': 'k2', 'groups': []}],
   [False, 'none']),
  ('all clauses must match',
   [{'included': [], 'excluded': [], 'rules': [{'clauses': [['region', ['eu']], ['groups', ['beta']]]}]},
    {'key': 'k1', 'region': 'eu', 'groups': ['x']}],
   [False, 'none']),
  ('second rule index',
   [{'included': [],
     'excluded': [],
     'rules': [{'clauses': [['region', ['us']]]}, {'clauses': [['region', ['eu']]]}]},
    {'key': 'k1', 'region': 'eu'}],
   [True, 'rule:1']),
  ('segment sample 21',
   [{'included': ['k3'], 'excluded': [], 'rules': []}, {'key': 'k9', 'groups': 'beta'}],
   [False, 'none']),
  ('segment sample 22',
   [{'included': [], 'excluded': ['k1'], 'rules': []}, {'key': 'k2', 'region': 'us'}],
   [False, 'none']),
  ('segment sample 23',
   [{'included': ['k1'], 'excluded': [], 'rules': [{'clauses': []}]},
    {'key': 'k3', 'region': 'us', 'tier': 'gold'}],
   [False, 'none'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Users whose groups attribute is a list never match group clauses.

A user is in the segment if its key is in included (reason included, which beats excluded); else not if its key is in excluded; else if some rule with a non-empty clause list has every clause matching (reason rule:i). A clause [attr, values] matches only when the attribute is present and its value (or any element of a list value) is in values. Otherwise [False, none].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if value is None:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
        value = int(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693])],
 [('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 46', ['new-nav', 'b', {'key': 'u42', 'org': '0', 'team': True}, 'team'], [None, 0])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 12', ['new-nav', 'b', {'key': '007'}, None], ['007', 68652]),
  ('identity sample 54', ['new-nav', 'a', {'key': '05', 'org': True, 'team': [1]}, 'org'], [None, 0])],
 [('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 22', ['bulk-edit', 'a', {'key': 'u1', 'org': ''}, None], ['u1', 93162]),
  ('identity sample 46', ['new-nav', 'b', {'key': 'u42', 'org': '0', 'team': True}, 'team'], [None, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if value is None or value is False:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
        value = int(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693])],
 [('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 46', ['new-nav', 'b', {'key': 'u42', 'org': '0', 'team': True}, 'team'], [None, 0])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 12', ['new-nav', 'b', {'key': '007'}, None], ['007', 68652]),
  ('identity sample 54', ['new-nav', 'a', {'key': '05', 'org': True, 'team': [1]}, 'org'], [None, 0])],
 [('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 22', ['bulk-edit', 'a', {'key': 'u1', 'org': ''}, None], ['u1', 93162]),
  ('identity sample 46', ['new-nav', 'b', {'key': 'u42', 'org': '0', 'team': True}, 'team'], [None, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
All users with org=True share one bucket named "True".

The bucketing identity is user[bucket_by] when bucket_by is non-empty and present, else user["key"]. Booleans, None and non-scalar values are unbucketable -> [None, 0]; integral floats use their integer form, other floats are unbucketable; ints and strings are used verbatim via str(). Return [identity, crc32(flag_key + "." + salt + "." + identity) % 100000].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693]),
  ('identity sample 3', ['new-nav', 'b', {'key': '007', 'org': 'acme'}, 'org'], ['acme', 9580])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 7', ['new-nav', 'a', {'key': '007', 'team': 'acme'}, 'team'], ['acme', 37026])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 12', ['new-nav', 'b', {'key': '007'}, None], ['007', 68652])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668]),
  ('identity sample 17', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': True}, 'org'], ['12', 46025])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 22', ['bulk-edit', 'a', {'key': 'u1', 'org': ''}, None], ['u1', 93162])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
        value = str(value).rstrip('0')
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693]),
  ('identity sample 3', ['new-nav', 'b', {'key': '007', 'org': 'acme'}, 'org'], ['acme', 9580])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 7', ['new-nav', 'a', {'key': '007', 'team': 'acme'}, 'team'], ['acme', 37026])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 12', ['new-nav', 'b', {'key': '007'}, None], ['007', 68652])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668]),
  ('identity sample 17', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': True}, 'org'], ['12', 46025])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 22', ['bulk-edit', 'a', {'key': 'u1', 'org': ''}, None], ['u1', 93162])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An org id sent as 5.0 by one client and 5 by another lands in different buckets.

The bucketing identity is user[bucket_by] when bucket_by is non-empty and present, else user["key"]. Booleans, None and non-scalar values are unbucketable -> [None, 0]; integral floats use their integer form, other floats are unbucketable; ints and strings are used verbatim via str(). Return [identity, crc32(flag_key + "." + salt + "." + identity) % 100000].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    value = user.get(bucket_by) if bucket_by else user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
        value = int(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 48', ['new-nav', 'b', {'key': 'x0'}, 'team'], ['x0', 76711])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 41', ['new-nav', 'b', {'key': '007', 'org': 0, 'team': [1]}, 'org'], ['0', 81622]),
  ('identity sample 42', ['new-nav', 'a', {'key': '05', 'team': False}, 'org'], ['05', 69931])],
 [('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668]),
  ('identity sample 24', ['bulk-edit', 'b', {'key': 'abc'}, 'org'], ['abc', 50988])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 34', ['bulk-edit', 'a', {'key': '007', 'org': ''}, 'org'], ['', 82099]),
  ('identity sample 55', ['new-nav', 'a', {'key': '05', 'org': 5.0}, 'team'], ['05', 69931])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    value = (user.get(bucket_by) if bucket_by else None) or user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
        value = int(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 48', ['new-nav', 'b', {'key': 'x0'}, 'team'], ['x0', 76711])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 41', ['new-nav', 'b', {'key': '007', 'org': 0, 'team': [1]}, 'org'], ['0', 81622]),
  ('identity sample 42', ['new-nav', 'a', {'key': '05', 'team': False}, 'org'], ['05', 69931])],
 [('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668]),
  ('identity sample 24', ['bulk-edit', 'b', {'key': 'abc'}, 'org'], ['abc', 50988])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 34', ['bulk-edit', 'a', {'key': '007', 'org': ''}, 'org'], ['', 82099]),
  ('identity sample 55', ['new-nav', 'a', {'key': '05', 'org': 5.0}, 'team'], ['05', 69931])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Users without an org attribute are all treated as unbucketable instead of using their key.

The bucketing identity is user[bucket_by] when bucket_by is non-empty and present, else user["key"]. Booleans, None and non-scalar values are unbucketable -> [None, 0]; integral floats use their integer form, other floats are unbucketable; ints and strings are used verbatim via str(). Return [identity, crc32(flag_key + "." + salt + "." + identity) % 100000].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        value = int(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 7', ['new-nav', 'a', {'key': '007', 'team': 'acme'}, 'team'], ['acme', 37026]),
  ('identity sample 32', ['new-nav', 'a', {'key': 'u42', 'org': 3.9}, 'org'], [None, 0])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 12', ['new-nav', 'b', {'key': '007'}, None], ['007', 68652]),
  ('identity sample 45', ['bulk-edit', 'b', {'key': 'u42', 'org': 2.5, 'team': None}, 'org'], [None, 0])],
 [('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668]),
  ('identity sample 17', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': True}, 'org'], ['12', 46025]),
  ('identity sample 31', ['bulk-edit', 'a', {'key': '05', 'org': 2.5}, 'org'], [None, 0])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 22', ['bulk-edit', 'a', {'key': 'u1', 'org': ''}, None], ['u1', 93162]),
  ('identity sample 35', ['bulk-edit', 'b', {'key': 'x0', 'org': 3.9, 'team': '0012'}, 'org'], [None, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        value = round(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 7', ['new-nav', 'a', {'key': '007', 'team': 'acme'}, 'team'], ['acme', 37026]),
  ('identity sample 32', ['new-nav', 'a', {'key': 'u42', 'org': 3.9}, 'org'], [None, 0])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 12', ['new-nav', 'b', {'key': '007'}, None], ['007', 68652]),
  ('identity sample 45', ['bulk-edit', 'b', {'key': 'u42', 'org': 2.5, 'team': None}, 'org'], [None, 0])],
 [('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668]),
  ('identity sample 17', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': True}, 'org'], ['12', 46025]),
  ('identity sample 31', ['bulk-edit', 'a', {'key': '05', 'org': 2.5}, 'org'], [None, 0])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 22', ['bulk-edit', 'a', {'key': 'u1', 'org': ''}, None], ['u1', 93162]),
  ('identity sample 35', ['bulk-edit', 'b', {'key': 'x0', 'org': 3.9, 'team': '0012'}, 'org'], [None, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Values 2.5 and 2 collapse into the same bucketing identity.

The bucketing identity is user[bucket_by] when bucket_by is non-empty and present, else user["key"]. Booleans, None and non-scalar values are unbucketable -> [None, 0]; integral floats use their integer form, other floats are unbucketable; ints and strings are used verbatim via str(). Return [identity, crc32(flag_key + "." + salt + "." + identity) % 100000].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
        value = int(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = str(int(value)) if isinstance(value, str) and value.isdigit() else str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 23', ['new-nav', 'a', {'key': '05', 'org': 3.9, 'team': '05'}, 'team'], ['05', 69931])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 43', ['new-nav', 'a', {'key': '007', 'team': False}, None], ['007', 42108]),
  ('identity sample 44', ['new-nav', 'a', {'key': '05', 'team': [1]}, 'org'], ['05', 69931])],
 [('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693]),
  ('identity sample 5', ['new-nav', 'a', {'key': 'abc', 'team': '05'}, 'team'], ['05', 69931]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 30', ['new-nav', 'a', {'key': '05', 'team': 2.5}, None], ['05', 69931]),
  ('identity sample 33', ['bulk-edit', 'b', {'key': '007', 'org': 'acme', 'team': 0}, None], ['007', 54512])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(flag_key, salt, user, bucket_by):
    if bucket_by and bucket_by in user:
        value = user[bucket_by]
    else:
        value = user.get('key')
    if isinstance(value, bool) or value is None:
        return [None, 0]
    if isinstance(value, float):
        if value != int(value):
            return [None, 0]
        value = int(value)
    if not isinstance(value, (int, str)):
        return [None, 0]
    ident = (value.lstrip('0') or '0') if isinstance(value, str) else str(value)
    return [ident, zlib.crc32((flag_key + '.' + salt + '.' + ident).encode()) % 100000]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean attribute is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': True}, 'org'], [None, 0]),
  ('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 1', ['new-nav', 'b', {'key': '05', 'org': '', 'team': 5.0}, 'team'], ['5', 56729])],
 [('integral float bucketed as integer', ['new-nav', 'a', {'key': 'u1', 'org': 5.0}, 'org'], ['5', 7520]),
  ('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 6', ['new-nav', 'b', {'key': 'u1', 'org': -3.0, 'team': 2.5}, 'org'], ['-3', 33868]),
  ('identity sample 23', ['new-nav', 'a', {'key': '05', 'org': 3.9, 'team': '05'}, 'team'], ['05', 69931])],
 [('integral float matches integer identity', ['new-nav', 'a', {'key': 'u1', 'org': 5}, 'org'], ['5', 7520]),
  ('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('identity sample 11', ['new-nav', 'a', {'key': 'u1', 'org': 12, 'team': 2.5}, None], ['u1', 4562]),
  ('identity sample 43', ['new-nav', 'a', {'key': '007', 'team': False}, None], ['007', 42108]),
  ('identity sample 44', ['new-nav', 'a', {'key': '05', 'team': [1]}, 'org'], ['05', 69931])],
 [('missing bucket attribute falls back to key', ['new-nav', 'a', {'key': 'u1'}, 'org'], ['u1', 4562]),
  ('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('identity sample 2', ['new-nav', 'b', {'key': 'u1', 'org': '05', 'team': [1]}, 'org'], ['05', 58693]),
  ('identity sample 5', ['new-nav', 'a', {'key': 'abc', 'team': '05'}, 'team'], ['05', 69931]),
  ('identity sample 16', ['new-nav', 'b', {'key': 'u1', 'org': '0012', 'team': ''}, None], ['u1', 96668])],
 [('zero attribute is a real identity', ['bulk-edit', 'b', {'key': 'u2', 'org': 0}, 'org'], ['0', 47112]),
  ('fractional float is unbucketable', ['new-nav', 'a', {'key': 'u1', 'org': 2.5}, 'org'], [None, 0]),
  ('leading-zero string kept verbatim', ['new-nav', 'a', {'key': 'u1', 'org': '007'}, 'org'], ['007', 42108]),
  ('leading-zero key kept verbatim', ['bulk-edit', 'b', {'key': '05'}, None], ['05', 9565]),
  ('false attribute is unbucketable', ['bulk-edit', 'b', {'key': 'u1', 'org': False}, 'org'], [None, 0]),
  ('identity sample 21', ['new-nav', 'a', {'key': 'u42', 'org': 12, 'team': False}, 'team'], [None, 0]),
  ('identity sample 30', ['new-nav', 'a', {'key': '05', 'team': 2.5}, None], ['05', 69931]),
  ('identity sample 33', ['bulk-edit', 'b', {'key': '007', 'org': 'acme', 'team': 0}, None], ['007', 54512])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Keys "05" and "5" share a bucket, merging distinct customers.

The bucketing identity is user[bucket_by] when bucket_by is non-empty and present, else user["key"]. Booleans, None and non-scalar values are unbucketable -> [None, 0]; integral floats use their integer form, other floats are unbucketable; ints and strings are used verbatim via str(). Return [identity, crc32(flag_key + "." + salt + "." + identity) % 100000].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at >= now:
            break
        active = i
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 2', [[[20, 0], [30, 50]], 10], [0, -1]),
  ('ramp schedule sample 3', [[[30, 0], [0, None], [60, 100]], 25], [0, 1])],
 [('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('ramp schedule sample 6', [[[60, 0], [30, 50], [60, 75]], 60], [75, 2]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 33', [[[0, 50]], 0], [50, 0]),
  ('ramp schedule sample 36', [[[10, 50], [20, 25], [30, None], [45, 0], [30, 25], [10, 0]], 20], [25, 1])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 4]),
  ('ramp schedule sample 54', [[[60, 0], [20, 50], [20, -10]], 60], [0, 0])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 6', [[[60, 0], [30, 50], [60, 75]], 60], [75, 2]),
  ('ramp schedule sample 15', [[[30, 50], [20, 120], [10, -10], [20, 5]], 30], [50, 0]),
  ('ramp schedule sample 21', [[], 0], [0, -1])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at >= now and pct is not None:
            break
        active = i
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 2', [[[20, 0], [30, 50]], 10], [0, -1]),
  ('ramp schedule sample 3', [[[30, 0], [0, None], [60, 100]], 25], [0, 1])],
 [('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('ramp schedule sample 6', [[[60, 0], [30, 50], [60, 75]], 60], [75, 2]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 33', [[[0, 50]], 0], [50, 0]),
  ('ramp schedule sample 36', [[[10, 50], [20, 25], [30, None], [45, 0], [30, 25], [10, 0]], 20], [25, 1])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 4]),
  ('ramp schedule sample 54', [[[60, 0], [20, 50], [20, -10]], 60], [0, 0])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 6', [[[60, 0], [30, 50], [60, 75]], 60], [75, 2]),
  ('ramp schedule sample 15', [[[30, 50], [20, 120], [10, -10], [20, 5]], 30], [50, 0]),
  ('ramp schedule sample 21', [[], 0], [0, -1])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The ramp stays at the old percentage for the whole second a new step is scheduled.

steps is a possibly unsorted list of [epoch second, percent or None]. Order steps by time, breaking ties by list position (later entries apply later). Every step with time <= now is active in that order; a None percent is a hold that keeps the previous value; numeric percents are clamped to [0, 100]. Before the first step the percentage is 0. Return [percent, original list index of the last active step or -1].

split: open-access