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

N = 1
observations = []
def solve(local, incoming):
    merged = dict(local['flags'])
    if incoming['version'] >= local['version']:
        for k, f in incoming['flags'].items():
            cur = merged.get(k)
            if cur is None or f['version'] > cur['version']:
                merged[k] = f
    return sorted([k, f['value']] for k, f in merged.items())
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('payload pair sample 1',
   [{'version': 3, 'flags': {'d': {'value': 'x', 'version': 1}, 'a': {'value': True, 'version': 0}}},
    {'version': 1,
     'flags': {'d': {'value': False, 'version': 1}, 'a': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', True], ['d', 'x']]),
  ('payload pair sample 2', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 3',
   [{'version': 3, 'flags': {'a': {'value': 2, 'version': 3}}},
    {'version': 2,
     'flags': {'b': {'value': False, 'version': 0, 'deleted': True},
               'd': {'value': 2, 'version': 3, 'deleted': True},
               'c': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', 2]])],
 [('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('payload pair sample 6',
   [{'version': 3,
     'flags': {'c': {'value': True, 'version': 1},
               'd': {'value': False, 'version': 1},
               'a': {'value': 'x', 'version': 2}}},
    {'version': 3, 'flags': {}}],
   [['a', 'x'], ['c', True], ['d', False]]),
  ('payload pair sample 19',
   [{'version': 3,
     'flags': {'d': {'value': False, 'version': 0}, 'a': {'value': False, 'version': 0, 'deleted': True}}},
    {'version': 2, 'flags': {'d': {'value': True, 'version': 1}}}],
   [['d', False]]),
  ('payload pair sample 53',
   [{'version': 3,
     'flags': {'d': {'value': True, 'version': 3},
               'b': {'value': 2, 'version': 0},
               'a': {'value': 'x', 'version': 3}}},
    {'version': 3, 'flags': {'a': {'value': 'x', 'version': 0, 'deleted': True}}}],
   [['a', 'x'], ['b', 2], ['d', True]])],
 [('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 11',
   [{'version': 2,
     'flags': {'d': {'value': 2, 'version': 2, 'deleted': True},
               'b': {'value': 'x', 'version': 2},
               'a': {'value': False, 'version': 1}}},
    {'version': 3,
     'flags': {'d': {'value': 2, 'version': 2},
               'a': {'value': 2, 'version': 2},
               'b': {'value': False, 'version': 0}}}],
   [['a', 2], ['b', 'x']]),
  ('payload pair sample 36',
   [{'version': 2, 'flags': {}},
    {'version': 2,
     'flags': {'c': {'value': 'x', 'version': 0},
               'd': {'value': 2, 'version': 3},
               'a': {'value': False, 'version': 1, 'deleted': True}}}],
   [['c', 'x'], ['d', 2]]),
  ('payload pair sample 60',
   [{'version': 1, 'flags': {'c': {'value': 2, 'version': 3}, 'b': {'value': 2, 'version': 2}}},
    {'version': 1,
     'flags': {'c': {'value': 2, 'version': 2},
               'b': {'value': 2, 'version': 2, 'deleted': True},
               'd': {'value': False, 'version': 2}}}],
   [['b', 2], ['c', 2], ['d', False]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 22',
   [{'version': 1,
     'flags': {'b': {'value': 2, 'version': 1}, 'a': {'value': 2, 'version': 1, 'deleted': True}}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 0, 'deleted': True}, 'c': {'value': True, 'version': 3}}}],
   [['b', 2], ['c', True]]),
  ('payload pair sample 48',
   [{'version': 3,
     'flags': {'c': {'value': True, 'version': 0, 'deleted': True},
               'a': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 0}}},
    {'version': 3, 'flags': {}}],
   [['a', False], ['b', True]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 21',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 2, 'deleted': True},
               'b': {'value': False, 'version': 1, 'deleted': True}}},
    {'version': 1,
     'flags': {'d': {'value': True, 'version': 0},
               'c': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 3}}}],
   []),
  ('payload pair sample 22',
   [{'version': 1,
     'flags': {'b': {'value': 2, 'version': 1}, 'a': {'value': 2, 'version': 1, 'deleted': True}}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 0, 'deleted': True}, 'c': {'value': True, 'version': 3}}}],
   [['b', 2], ['c', True]]),
  ('payload pair sample 54',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 1}}},
    {'version': 2, 'flags': {'b': {'value': True, 'version': 0, 'deleted': True}}}],
   [['b', 'x']])]]
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(local, incoming):
    merged = dict(local['flags'])
    if incoming['version'] >= local['version']:
        for k, f in incoming['flags'].items():
            cur = merged.get(k)
            if f.get('deleted'):
                merged.pop(k, None)
                continue
            if cur is None or f['version'] > cur['version']:
                merged[k] = f
    return sorted([k, f['value']] for k, f in merged.items() if not f.get('deleted'))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('payload pair sample 1',
   [{'version': 3, 'flags': {'d': {'value': 'x', 'version': 1}, 'a': {'value': True, 'version': 0}}},
    {'version': 1,
     'flags': {'d': {'value': False, 'version': 1}, 'a': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', True], ['d', 'x']]),
  ('payload pair sample 2', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 3',
   [{'version': 3, 'flags': {'a': {'value': 2, 'version': 3}}},
    {'version': 2,
     'flags': {'b': {'value': False, 'version': 0, 'deleted': True},
               'd': {'value': 2, 'version': 3, 'deleted': True},
               'c': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', 2]])],
 [('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('payload pair sample 6',
   [{'version': 3,
     'flags': {'c': {'value': True, 'version': 1},
               'd': {'value': False, 'version': 1},
               'a': {'value': 'x', 'version': 2}}},
    {'version': 3, 'flags': {}}],
   [['a', 'x'], ['c', True], ['d', False]]),
  ('payload pair sample 19',
   [{'version': 3,
     'flags': {'d': {'value': False, 'version': 0}, 'a': {'value': False, 'version': 0, 'deleted': True}}},
    {'version': 2, 'flags': {'d': {'value': True, 'version': 1}}}],
   [['d', False]]),
  ('payload pair sample 53',
   [{'version': 3,
     'flags': {'d': {'value': True, 'version': 3},
               'b': {'value': 2, 'version': 0},
               'a': {'value': 'x', 'version': 3}}},
    {'version': 3, 'flags': {'a': {'value': 'x', 'version': 0, 'deleted': True}}}],
   [['a', 'x'], ['b', 2], ['d', True]])],
 [('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 11',
   [{'version': 2,
     'flags': {'d': {'value': 2, 'version': 2, 'deleted': True},
               'b': {'value': 'x', 'version': 2},
               'a': {'value': False, 'version': 1}}},
    {'version': 3,
     'flags': {'d': {'value': 2, 'version': 2},
               'a': {'value': 2, 'version': 2},
               'b': {'value': False, 'version': 0}}}],
   [['a', 2], ['b', 'x']]),
  ('payload pair sample 36',
   [{'version': 2, 'flags': {}},
    {'version': 2,
     'flags': {'c': {'value': 'x', 'version': 0},
               'd': {'value': 2, 'version': 3},
               'a': {'value': False, 'version': 1, 'deleted': True}}}],
   [['c', 'x'], ['d', 2]]),
  ('payload pair sample 60',
   [{'version': 1, 'flags': {'c': {'value': 2, 'version': 3}, 'b': {'value': 2, 'version': 2}}},
    {'version': 1,
     'flags': {'c': {'value': 2, 'version': 2},
               'b': {'value': 2, 'version': 2, 'deleted': True},
               'd': {'value': False, 'version': 2}}}],
   [['b', 2], ['c', 2], ['d', False]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 22',
   [{'version': 1,
     'flags': {'b': {'value': 2, 'version': 1}, 'a': {'value': 2, 'version': 1, 'deleted': True}}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 0, 'deleted': True}, 'c': {'value': True, 'version': 3}}}],
   [['b', 2], ['c', True]]),
  ('payload pair sample 48',
   [{'version': 3,
     'flags': {'c': {'value': True, 'version': 0, 'deleted': True},
               'a': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 0}}},
    {'version': 3, 'flags': {}}],
   [['a', False], ['b', True]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 21',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 2, 'deleted': True},
               'b': {'value': False, 'version': 1, 'deleted': True}}},
    {'version': 1,
     'flags': {'d': {'value': True, 'version': 0},
               'c': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 3}}}],
   []),
  ('payload pair sample 22',
   [{'version': 1,
     'flags': {'b': {'value': 2, 'version': 1}, 'a': {'value': 2, 'version': 1, 'deleted': True}}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 0, 'deleted': True}, 'c': {'value': True, 'version': 3}}}],
   [['b', 2], ['c', True]]),
  ('payload pair sample 54',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 1}}},
    {'version': 2, 'flags': {'b': {'value': True, 'version': 0, 'deleted': True}}}],
   [['b', 'x']])]]
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:
Flags archived on the server keep appearing in the client flag list.

Payloads are {version, flags: {key: {value, version, deleted?}}}. An incoming payload with a lower payload version than local is ignored entirely. Otherwise each incoming flag replaces the local entry only when the key is new or its flag version is strictly higher; deleted tombstones follow the same rule. Return sorted [key, value] pairs for merged flags that are not deleted.

split: open-access


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

N = 1
observations = []
def solve(local, incoming):
    merged = dict(local['flags'])
    if incoming['version'] > local['version']:
        for k, f in incoming['flags'].items():
            cur = merged.get(k)
            if cur is None or f['version'] > cur['version']:
                merged[k] = f
    return sorted([k, f['value']] for k, f in merged.items() if not f.get('deleted'))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 1',
   [{'version': 3, 'flags': {'d': {'value': 'x', 'version': 1}, 'a': {'value': True, 'version': 0}}},
    {'version': 1,
     'flags': {'d': {'value': False, 'version': 1}, 'a': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', True], ['d', 'x']])],
 [('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 15',
   [{'version': 1,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 1},
               'd': {'value': 2, 'version': 3}}},
    {'version': 1,
     'flags': {'d': {'value': 'x', 'version': 3},
               'a': {'value': False, 'version': 2},
               'b': {'value': True, 'version': 2}}}],
   [['a', False], ['b', True], ['c', True], ['d', 2]]),
  ('payload pair sample 38',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 0},
               'b': {'value': True, 'version': 0}}}],
   [['a', True], ['b', 'x'], ['c', True]])],
 [('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 11',
   [{'version': 2,
     'flags': {'d': {'value': 2, 'version': 2, 'deleted': True},
               'b': {'value': 'x', 'version': 2},
               'a': {'value': False, 'version': 1}}},
    {'version': 3,
     'flags': {'d': {'value': 2, 'version': 2},
               'a': {'value': 2, 'version': 2},
               'b': {'value': False, 'version': 0}}}],
   [['a', 2], ['b', 'x']]),
  ('payload pair sample 23',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 1},
               'b': {'value': True, 'version': 0},
               'd': {'value': 2, 'version': 0}}},
    {'version': 1, 'flags': {'d': {'value': False, 'version': 2}, 'a': {'value': 'x', 'version': 3}}}],
   [['a', False], ['b', True], ['d', 2]]),
  ('payload pair sample 38',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 0},
               'b': {'value': True, 'version': 0}}}],
   [['a', True], ['b', 'x'], ['c', True]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 17',
   [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {'d': {'value': 2, 'version': 2, 'deleted': True}}}],
   []),
  ('payload pair sample 51',
   [{'version': 3,
     'flags': {'b': {'value': True, 'version': 1, 'deleted': True}, 'a': {'value': True, 'version': 0}}},
    {'version': 3, 'flags': {'a': {'value': False, 'version': 2}, 'c': {'value': False, 'version': 0}}}],
   [['a', False], ['c', False]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 20',
   [{'version': 2, 'flags': {'b': {'value': 2, 'version': 3}, 'd': {'value': 2, 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': False, 'version': 0},
               'b': {'value': False, 'version': 2},
               'd': {'value': 2, 'version': 2}}}],
   [['a', False], ['b', 2], ['d', 2]]),
  ('payload pair sample 21',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 2, 'deleted': True},
               'b': {'value': False, 'version': 1, 'deleted': True}}},
    {'version': 1,
     'flags': {'d': {'value': True, 'version': 0},
               'c': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 3}}}],
   []),
  ('payload pair sample 35',
   [{'version': 2, 'flags': {'c': {'value': 2, 'version': 1}}},
    {'version': 1, 'flags': {'b': {'value': 'x', 'version': 3}, 'c': {'value': False, 'version': 1}}}],
   [['c', 2]])]]
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(local, incoming):
    merged = dict(local['flags'])
    if max([f['version'] for f in incoming['flags'].values()] or [0]) >= local['version']:
        for k, f in incoming['flags'].items():
            cur = merged.get(k)
            if cur is None or f['version'] > cur['version']:
                merged[k] = f
    return sorted([k, f['value']] for k, f in merged.items() if not f.get('deleted'))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 1',
   [{'version': 3, 'flags': {'d': {'value': 'x', 'version': 1}, 'a': {'value': True, 'version': 0}}},
    {'version': 1,
     'flags': {'d': {'value': False, 'version': 1}, 'a': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', True], ['d', 'x']])],
 [('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 15',
   [{'version': 1,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 1},
               'd': {'value': 2, 'version': 3}}},
    {'version': 1,
     'flags': {'d': {'value': 'x', 'version': 3},
               'a': {'value': False, 'version': 2},
               'b': {'value': True, 'version': 2}}}],
   [['a', False], ['b', True], ['c', True], ['d', 2]]),
  ('payload pair sample 38',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 0},
               'b': {'value': True, 'version': 0}}}],
   [['a', True], ['b', 'x'], ['c', True]])],
 [('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 11',
   [{'version': 2,
     'flags': {'d': {'value': 2, 'version': 2, 'deleted': True},
               'b': {'value': 'x', 'version': 2},
               'a': {'value': False, 'version': 1}}},
    {'version': 3,
     'flags': {'d': {'value': 2, 'version': 2},
               'a': {'value': 2, 'version': 2},
               'b': {'value': False, 'version': 0}}}],
   [['a', 2], ['b', 'x']]),
  ('payload pair sample 23',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 1},
               'b': {'value': True, 'version': 0},
               'd': {'value': 2, 'version': 0}}},
    {'version': 1, 'flags': {'d': {'value': False, 'version': 2}, 'a': {'value': 'x', 'version': 3}}}],
   [['a', False], ['b', True], ['d', 2]]),
  ('payload pair sample 38',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 0},
               'b': {'value': True, 'version': 0}}}],
   [['a', True], ['b', 'x'], ['c', True]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 17',
   [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {'d': {'value': 2, 'version': 2, 'deleted': True}}}],
   []),
  ('payload pair sample 51',
   [{'version': 3,
     'flags': {'b': {'value': True, 'version': 1, 'deleted': True}, 'a': {'value': True, 'version': 0}}},
    {'version': 3, 'flags': {'a': {'value': False, 'version': 2}, 'c': {'value': False, 'version': 0}}}],
   [['a', False], ['c', False]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 20',
   [{'version': 2, 'flags': {'b': {'value': 2, 'version': 3}, 'd': {'value': 2, 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': False, 'version': 0},
               'b': {'value': False, 'version': 2},
               'd': {'value': 2, 'version': 2}}}],
   [['a', False], ['b', 2], ['d', 2]]),
  ('payload pair sample 21',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 2, 'deleted': True},
               'b': {'value': False, 'version': 1, 'deleted': True}}},
    {'version': 1,
     'flags': {'d': {'value': True, 'version': 0},
               'c': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 3}}}],
   []),
  ('payload pair sample 35',
   [{'version': 2, 'flags': {'c': {'value': 2, 'version': 1}}},
    {'version': 1, 'flags': {'b': {'value': 'x', 'version': 3}, 'c': {'value': False, 'version': 1}}}],
   [['c', 2]])]]
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:
A second payload with the same version but newer per-flag versions is discarded.

Payloads are {version, flags: {key: {value, version, deleted?}}}. An incoming payload with a lower payload version than local is ignored entirely. Otherwise each incoming flag replaces the local entry only when the key is new or its flag version is strictly higher; deleted tombstones follow the same rule. Return sorted [key, value] pairs for merged flags that are not deleted.

split: open-access


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

N = 1
observations = []
def solve(local, incoming):
    merged = dict(local['flags'])
    if incoming['version'] >= local['version']:
        for k, f in incoming['flags'].items():
            cur = merged.get(k)
            if cur is not None and f['version'] > cur['version']:
                merged[k] = f
    return sorted([k, f['value']] for k, f in merged.items() if not f.get('deleted'))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 1',
   [{'version': 3, 'flags': {'d': {'value': 'x', 'version': 1}, 'a': {'value': True, 'version': 0}}},
    {'version': 1,
     'flags': {'d': {'value': False, 'version': 1}, 'a': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', True], ['d', 'x']])],
 [('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 15',
   [{'version': 1,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 1},
               'd': {'value': 2, 'version': 3}}},
    {'version': 1,
     'flags': {'d': {'value': 'x', 'version': 3},
               'a': {'value': False, 'version': 2},
               'b': {'value': True, 'version': 2}}}],
   [['a', False], ['b', True], ['c', True], ['d', 2]]),
  ('payload pair sample 38',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 0},
               'b': {'value': True, 'version': 0}}}],
   [['a', True], ['b', 'x'], ['c', True]])],
 [('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 11',
   [{'version': 2,
     'flags': {'d': {'value': 2, 'version': 2, 'deleted': True},
               'b': {'value': 'x', 'version': 2},
               'a': {'value': False, 'version': 1}}},
    {'version': 3,
     'flags': {'d': {'value': 2, 'version': 2},
               'a': {'value': 2, 'version': 2},
               'b': {'value': False, 'version': 0}}}],
   [['a', 2], ['b', 'x']]),
  ('payload pair sample 25',
   [{'version': 2, 'flags': {'b': {'value': False, 'version': 1}}},
    {'version': 2,
     'flags': {'b': {'value': 'x', 'version': 3},
               'c': {'value': 2, 'version': 0},
               'a': {'value': 'x', 'version': 1, 'deleted': True}}}],
   [['b', 'x'], ['c', 2]]),
  ('payload pair sample 32',
   [{'version': 2, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 3, 'flags': {'b': {'value': 'x', 'version': 3}}}],
   [['a', True], ['b', 'x']])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 50',
   [{'version': 1, 'flags': {'b': {'value': True, 'version': 1}}},
    {'version': 1,
     'flags': {'b': {'value': True, 'version': 1},
               'c': {'value': True, 'version': 2, 'deleted': True},
               'a': {'value': False, 'version': 3}}}],
   [['a', False], ['b', True]]),
  ('payload pair sample 51',
   [{'version': 3,
     'flags': {'b': {'value': True, 'version': 1, 'deleted': True}, 'a': {'value': True, 'version': 0}}},
    {'version': 3, 'flags': {'a': {'value': False, 'version': 2}, 'c': {'value': False, 'version': 0}}}],
   [['a', False], ['c', False]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 21',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 2, 'deleted': True},
               'b': {'value': False, 'version': 1, 'deleted': True}}},
    {'version': 1,
     'flags': {'d': {'value': True, 'version': 0},
               'c': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 3}}}],
   []),
  ('payload pair sample 22',
   [{'version': 1,
     'flags': {'b': {'value': 2, 'version': 1}, 'a': {'value': 2, 'version': 1, 'deleted': True}}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 0, 'deleted': True}, 'c': {'value': True, 'version': 3}}}],
   [['b', 2], ['c', True]]),
  ('payload pair sample 37',
   [{'version': 2, 'flags': {}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 3, 'deleted': True},
               'a': {'value': 2, 'version': 1},
               'd': {'value': True, 'version': 0}}}],
   [['a', 2], ['d', True]])]]
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(local, incoming):
    merged = dict(local['flags'])
    if incoming['version'] >= local['version']:
        for k, f in incoming['flags'].items():
            cur = merged.get(k)
            if (cur or {}).get('version', 0) < f['version']:
                merged[k] = f
    return sorted([k, f['value']] for k, f in merged.items() if not f.get('deleted'))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 1',
   [{'version': 3, 'flags': {'d': {'value': 'x', 'version': 1}, 'a': {'value': True, 'version': 0}}},
    {'version': 1,
     'flags': {'d': {'value': False, 'version': 1}, 'a': {'value': 2, 'version': 2, 'deleted': True}}}],
   [['a', True], ['d', 'x']])],
 [('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 15',
   [{'version': 1,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 1},
               'd': {'value': 2, 'version': 3}}},
    {'version': 1,
     'flags': {'d': {'value': 'x', 'version': 3},
               'a': {'value': False, 'version': 2},
               'b': {'value': True, 'version': 2}}}],
   [['a', False], ['b', True], ['c', True], ['d', 2]]),
  ('payload pair sample 38',
   [{'version': 2, 'flags': {'b': {'value': 'x', 'version': 2}}},
    {'version': 2,
     'flags': {'a': {'value': True, 'version': 0},
               'c': {'value': True, 'version': 0},
               'b': {'value': True, 'version': 0}}}],
   [['a', True], ['b', 'x'], ['c', True]])],
 [('older tombstone is ignored',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 2, 'flags': {'a': {'value': None, 'version': 1, 'deleted': True}}}],
   [['a', True]]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 11',
   [{'version': 2,
     'flags': {'d': {'value': 2, 'version': 2, 'deleted': True},
               'b': {'value': 'x', 'version': 2},
               'a': {'value': False, 'version': 1}}},
    {'version': 3,
     'flags': {'d': {'value': 2, 'version': 2},
               'a': {'value': 2, 'version': 2},
               'b': {'value': False, 'version': 0}}}],
   [['a', 2], ['b', 'x']]),
  ('payload pair sample 25',
   [{'version': 2, 'flags': {'b': {'value': False, 'version': 1}}},
    {'version': 2,
     'flags': {'b': {'value': 'x', 'version': 3},
               'c': {'value': 2, 'version': 0},
               'a': {'value': 'x', 'version': 1, 'deleted': True}}}],
   [['b', 'x'], ['c', 2]]),
  ('payload pair sample 32',
   [{'version': 2, 'flags': {'a': {'value': True, 'version': 3}}},
    {'version': 3, 'flags': {'b': {'value': 'x', 'version': 3}}}],
   [['a', True], ['b', 'x']])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('equal payload version still merges',
   [{'version': 2, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 2}}}],
   [['a', 2]]),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 50',
   [{'version': 1, 'flags': {'b': {'value': True, 'version': 1}}},
    {'version': 1,
     'flags': {'b': {'value': True, 'version': 1},
               'c': {'value': True, 'version': 2, 'deleted': True},
               'a': {'value': False, 'version': 3}}}],
   [['a', False], ['b', True]]),
  ('payload pair sample 51',
   [{'version': 3,
     'flags': {'b': {'value': True, 'version': 1, 'deleted': True}, 'a': {'value': True, 'version': 0}}},
    {'version': 3, 'flags': {'a': {'value': False, 'version': 2}, 'c': {'value': False, 'version': 0}}}],
   [['a', False], ['c', False]])],
 [('equal flag version keeps the local value',
   [{'version': 1, 'flags': {'a': {'value': 'local', 'version': 2}}},
    {'version': 2, 'flags': {'a': {'value': 'remote', 'version': 2}}}],
   [['a', 'local']]),
  ('newer tombstone deletes the flag',
   [{'version': 1, 'flags': {'a': {'value': True, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': None, 'version': 2, 'deleted': True}}}],
   []),
  ('stale payload is ignored',
   [{'version': 3, 'flags': {'a': {'value': 1, 'version': 1}}},
    {'version': 2, 'flags': {'a': {'value': 2, 'version': 5}}}],
   [['a', 1]]),
  ('new flag with version zero is adopted',
   [{'version': 1, 'flags': {}}, {'version': 1, 'flags': {'b': {'value': 'on', 'version': 0}}}],
   [['b', 'on']]),
  ('output is sorted by key',
   [{'version': 1, 'flags': {'c': {'value': 3, 'version': 1}}},
    {'version': 1, 'flags': {'a': {'value': 1, 'version': 1}, 'b': {'value': 2, 'version': 1}}}],
   [['a', 1], ['b', 2], ['c', 3]]),
  ('payload pair sample 21',
   [{'version': 2,
     'flags': {'a': {'value': False, 'version': 2, 'deleted': True},
               'b': {'value': False, 'version': 1, 'deleted': True}}},
    {'version': 1,
     'flags': {'d': {'value': True, 'version': 0},
               'c': {'value': False, 'version': 3},
               'b': {'value': True, 'version': 3}}}],
   []),
  ('payload pair sample 22',
   [{'version': 1,
     'flags': {'b': {'value': 2, 'version': 1}, 'a': {'value': 2, 'version': 1, 'deleted': True}}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 0, 'deleted': True}, 'c': {'value': True, 'version': 3}}}],
   [['b', 2], ['c', True]]),
  ('payload pair sample 37',
   [{'version': 2, 'flags': {}},
    {'version': 2,
     'flags': {'b': {'value': True, 'version': 3, 'deleted': True},
               'a': {'value': 2, 'version': 1},
               'd': {'value': True, 'version': 0}}}],
   [['a', 2], ['d', True]])]]
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:
Newly created flags never reach clients until a full reload.

Payloads are {version, flags: {key: {value, version, deleted?}}}. An incoming payload with a lower payload version than local is ignored entirely. Otherwise each incoming flag replaces the local entry only when the key is new or its flag version is strictly higher; deleted tombstones follow the same rule. Return sorted [key, value] pairs for merged flags that are not deleted.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(salt, user, traffic, weights):
    t = zlib.crc32((salt + ':traffic:' + user).encode()) % 100
    if t >= traffic:
        return [False, None]
    v = t
    acc = 0
    for arm, w in weights:
        acc += w
        if v < acc:
            return [True, arm]
    return [True, weights[-1][0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('allocation sample 1', ['exp2', 'u3390', 9, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 2', ['exp2', 'u2292', 50, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 3', ['exp2', 'u2623', 67, [['control', 20], ['treatment', 80]]], [True, 'control'])],
 [('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 13', ['exp2', 'u3641', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 20', ['exp1', 'u1715', 57, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 11', ['exp1', 'u2908', 30, [['a', 34], ['b', 33], ['c', 33]]], [False, None]),
  ('allocation sample 12', ['exp1', 'u1733', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 50', ['exp1', 'u2120', 100, [['control', 50], ['treatment', 50]]], [True, 'control'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 3', ['exp2', 'u2623', 67, [['control', 20], ['treatment', 80]]], [True, 'control']),
  ('allocation sample 9', ['exp1', 'u3147', 77, [['a', 34], ['b', 33], ['c', 33]]], [True, 'a']),
  ('allocation sample 16', ['exp2', 'u2262', 53, [['control', 20], ['treatment', 80]]], [True, 'treatment'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 21', ['exp1', 'u843', 100, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 33', ['exp1', 'u1247', 50, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('allocation sample 41', ['exp2', 'u3401', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])]]
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(salt, user, traffic, weights):
    t = zlib.crc32((salt + ':traffic:' + user).encode()) % 100
    if t >= traffic:
        return [False, None]
    v = t * 100 // traffic
    acc = 0
    for arm, w in weights:
        acc += w
        if v < acc:
            return [True, arm]
    return [True, weights[-1][0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('allocation sample 1', ['exp2', 'u3390', 9, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 2', ['exp2', 'u2292', 50, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 3', ['exp2', 'u2623', 67, [['control', 20], ['treatment', 80]]], [True, 'control'])],
 [('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 13', ['exp2', 'u3641', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 20', ['exp1', 'u1715', 57, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 11', ['exp1', 'u2908', 30, [['a', 34], ['b', 33], ['c', 33]]], [False, None]),
  ('allocation sample 12', ['exp1', 'u1733', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 50', ['exp1', 'u2120', 100, [['control', 50], ['treatment', 50]]], [True, 'control'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 3', ['exp2', 'u2623', 67, [['control', 20], ['treatment', 80]]], [True, 'control']),
  ('allocation sample 9', ['exp1', 'u3147', 77, [['a', 34], ['b', 33], ['c', 33]]], [True, 'a']),
  ('allocation sample 16', ['exp2', 'u2262', 53, [['control', 20], ['treatment', 80]]], [True, 'treatment'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 21', ['exp1', 'u843', 100, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 33', ['exp1', 'u1247', 50, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('allocation sample 41', ['exp2', 'u3401', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])]]
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:
At 20 percent traffic every allocated user lands in the first arm.

Stage 1: t = crc32(salt + ":traffic:" + user) % 100; users with t >= traffic (1..100) are not in the experiment. Stage 2 uses an independent v = crc32(salt + ":variant:" + user) % 100 and walks weights ([arm, percent of allocated users], summing to 100) cumulatively, half-open. Return [in_experiment, arm or None].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(salt, user, traffic, weights):
    t = zlib.crc32((salt + ':traffic:' + user).encode()) % 100
    if t >= traffic:
        return [False, None]
    v = zlib.crc32((salt + ':variant:' + user).encode()) % 100
    acc = 0
    for arm, w in weights:
        acc += w * traffic / 100
        if v < acc:
            return [True, arm]
    return [True, weights[-1][0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('allocation sample 1', ['exp2', 'u3390', 9, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 2', ['exp2', 'u2292', 50, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 7', ['exp1', 'u3237', 10, [['control', 50], ['treatment', 50]]], [False, None]),
  ('allocation sample 40', ['exp2', 'u3484', 50, [['control', 50], ['treatment', 50]]], [True, 'treatment'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 11', ['exp1', 'u2908', 30, [['a', 34], ['b', 33], ['c', 33]]], [False, None]),
  ('allocation sample 13', ['exp2', 'u3641', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 16', ['exp2', 'u2262', 53, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 17', ['exp2', 'u276', 10, [['a', 34], ['b', 33], ['c', 33]]], [False, None])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 21', ['exp1', 'u843', 100, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 44', ['exp2', 'u1337', 52, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])]]
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(salt, user, traffic, weights):
    t = zlib.crc32((salt + ':traffic:' + user).encode()) % 100
    if t >= traffic:
        return [False, None]
    v = zlib.crc32((salt + ':variant:' + user).encode()) % 100
    acc = 0
    for arm, w in weights:
        acc += w * 100 / traffic
        if v < acc:
            return [True, arm]
    return [True, weights[-1][0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('allocation sample 1', ['exp2', 'u3390', 9, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 2', ['exp2', 'u2292', 50, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 7', ['exp1', 'u3237', 10, [['control', 50], ['treatment', 50]]], [False, None]),
  ('allocation sample 40', ['exp2', 'u3484', 50, [['control', 50], ['treatment', 50]]], [True, 'treatment'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 11', ['exp1', 'u2908', 30, [['a', 34], ['b', 33], ['c', 33]]], [False, None]),
  ('allocation sample 13', ['exp2', 'u3641', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 16', ['exp2', 'u2262', 53, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 17', ['exp2', 'u276', 10, [['a', 34], ['b', 33], ['c', 33]]], [False, None])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 21', ['exp1', 'u843', 100, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 44', ['exp2', 'u1337', 52, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])]]
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:
At partial traffic most allocated users fall through to the last arm.

Stage 1: t = crc32(salt + ":traffic:" + user) % 100; users with t >= traffic (1..100) are not in the experiment. Stage 2 uses an independent v = crc32(salt + ":variant:" + user) % 100 and walks weights ([arm, percent of allocated users], summing to 100) cumulatively, half-open. Return [in_experiment, arm or None].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import zlib
N = 1
observations = []
def solve(salt, user, traffic, weights):
    t = zlib.crc32((salt + ':traffic:' + user).encode()) % 100
    if t > traffic:
        return [False, None]
    v = zlib.crc32((salt + ':variant:' + user).encode()) % 100
    acc = 0
    for arm, w in weights:
        acc += w
        if v < acc:
            return [True, arm]
    return [True, weights[-1][0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('allocation sample 1', ['exp2', 'u3390', 9, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 2', ['exp2', 'u2292', 50, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 3', ['exp2', 'u2623', 67, [['control', 20], ['treatment', 80]]], [True, 'control'])],
 [('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 22', ['exp2', 'u568', 88, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 49', ['exp1', 'u586', 13, [['control', 50], ['treatment', 50]]], [False, None])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 9', ['exp1', 'u3147', 77, [['a', 34], ['b', 33], ['c', 33]]], [True, 'a']),
  ('allocation sample 11', ['exp1', 'u2908', 30, [['a', 34], ['b', 33], ['c', 33]]], [False, None]),
  ('allocation sample 39', ['exp2', 'u1649', 12, [['control', 50], ['treatment', 50]]], [False, None])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 16', ['exp2', 'u2262', 53, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 38', ['exp1', 'u1107', 59, [['control', 50], ['treatment', 50]]], [False, None]),
  ('allocation sample 44', ['exp2', 'u1337', 52, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 18', ['exp1', 'u1356', 18, [['control', 50], ['treatment', 50]]], [False, None]),
  ('allocation sample 20', ['exp1', 'u1715', 57, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 21', ['exp1', 'u843', 100, [['control', 20], ['treatment', 80]]], [True, 'treatment'])]]
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(salt, user, traffic, weights):
    t = zlib.crc32((salt + ':traffic:' + user).encode()) % 100
    if t >= traffic - 1:
        return [False, None]
    v = zlib.crc32((salt + ':variant:' + user).encode()) % 100
    acc = 0
    for arm, w in weights:
        acc += w
        if v < acc:
            return [True, arm]
    return [True, weights[-1][0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('allocation sample 1', ['exp2', 'u3390', 9, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 2', ['exp2', 'u2292', 50, [['control', 20], ['treatment', 80]]], [False, None]),
  ('allocation sample 3', ['exp2', 'u2623', 67, [['control', 20], ['treatment', 80]]], [True, 'control'])],
 [('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 6', ['exp1', 'u2423', 50, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 22', ['exp2', 'u568', 88, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 49', ['exp1', 'u586', 13, [['control', 50], ['treatment', 50]]], [False, None])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 9', ['exp1', 'u3147', 77, [['a', 34], ['b', 33], ['c', 33]]], [True, 'a']),
  ('allocation sample 11', ['exp1', 'u2908', 30, [['a', 34], ['b', 33], ['c', 33]]], [False, None]),
  ('allocation sample 39', ['exp2', 'u1649', 12, [['control', 50], ['treatment', 50]]], [False, None])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('traffic boundary excludes t equal to traffic', ['exp1', 'm0', 14, [['a', 50], ['b', 50]]], [False, None]),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 16', ['exp2', 'u2262', 53, [['control', 20], ['treatment', 80]]], [True, 'treatment']),
  ('allocation sample 38', ['exp1', 'u1107', 59, [['control', 50], ['treatment', 50]]], [False, None]),
  ('allocation sample 44', ['exp2', 'u1337', 52, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b'])],
 [('low traffic still fills every arm',
   ['exp1', 'm0', 20, [['control', 50], ['treatment', 50]]],
   [True, 'treatment']),
  ('low traffic second user', ['exp1', 'm5', 20, [['control', 50], ['treatment', 50]]], [True, 'treatment']),
  ('arm weights are relative to allocated users',
   ['exp1', 'm8', 20, [['control', 20], ['treatment', 80]]],
   [True, 'control']),
  ('traffic boundary includes t just below', ['exp1', 'm5', 6, [['a', 50], ['b', 50]]], [True, 'b']),
  ('full traffic control', ['exp2', 'n1', 100, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 18', ['exp1', 'u1356', 18, [['control', 50], ['treatment', 50]]], [False, None]),
  ('allocation sample 20', ['exp1', 'u1715', 57, [['a', 34], ['b', 33], ['c', 33]]], [True, 'b']),
  ('allocation sample 21', ['exp1', 'u843', 100, [['control', 20], ['treatment', 80]]], [True, 'treatment'])]]
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:
A 10 percent experiment enrols 11 percent of users.

Stage 1: t = crc32(salt + ":traffic:" + user) % 100; users with t >= traffic (1..100) are not in the experiment. Stage 2 uses an independent v = crc32(salt + ":variant:" + user) % 100 and walks weights ([arm, percent of allocated users], summing to 100) cumulatively, half-open. Return [in_experiment, arm or None].

split: open-access