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

N = 1
observations = []
def solve(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if isinstance(v, type(default)) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 14',
   ['dark-mode-v2', 0, {'dark-mode-v2': False}, {}, {'FLAG_DARK-MODE-V2': '+4'}],
   [0, 'default']),
  ('override layer sample 41',
   ['dark-mode-v2', 0, {'dark-mode-v2': False}, {'dark-mode-v2': 'x'}, {'FLAG_DARK-MODE-V2': 'true'}],
   [0, 'default'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 12', ['dark-mode-v2', 'blue', {}, {'dark-mode-v2': 0}, {}], ['blue', 'default']),
  ('override layer sample 18',
   ['dark-mode-v2', 0, {}, {'dark-mode-v2': True}, {'FLAG_DARK_MODE_V2': 'true'}],
   [0, 'default'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 31',
   ['dark-mode-v2', 7, {'dark-mode-v2': True}, {}, {'FLAG_dark_mode_v2': 'true'}],
   [7, 'default'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 41',
   ['dark-mode-v2', 0, {'dark-mode-v2': False}, {'dark-mode-v2': 'x'}, {'FLAG_DARK-MODE-V2': 'true'}],
   [0, 'default']),
  ('override layer sample 51',
   ['dark-mode-v2', 7, {'dark-mode-v2': False}, {'dark-mode-v2': 'x'}, {'FLAG_DARK-MODE-V2': 'FALSE'}],
   [7, 'default'])]]
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(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if isinstance(v, type(default)) and not isinstance(default, bool) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 14',
   ['dark-mode-v2', 0, {'dark-mode-v2': False}, {}, {'FLAG_DARK-MODE-V2': '+4'}],
   [0, 'default']),
  ('override layer sample 41',
   ['dark-mode-v2', 0, {'dark-mode-v2': False}, {'dark-mode-v2': 'x'}, {'FLAG_DARK-MODE-V2': 'true'}],
   [0, 'default'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 12', ['dark-mode-v2', 'blue', {}, {'dark-mode-v2': 0}, {}], ['blue', 'default']),
  ('override layer sample 18',
   ['dark-mode-v2', 0, {}, {'dark-mode-v2': True}, {'FLAG_DARK_MODE_V2': 'true'}],
   [0, 'default'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 31',
   ['dark-mode-v2', 7, {'dark-mode-v2': True}, {}, {'FLAG_dark_mode_v2': 'true'}],
   [7, 'default'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 41',
   ['dark-mode-v2', 0, {'dark-mode-v2': False}, {'dark-mode-v2': 'x'}, {'FLAG_DARK-MODE-V2': 'true'}],
   [0, 'default']),
  ('override layer sample 51',
   ['dark-mode-v2', 7, {'dark-mode-v2': False}, {'dark-mode-v2': 'x'}, {'FLAG_DARK-MODE-V2': 'FALSE'}],
   [7, 'default'])]]
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 remote payload of true for a numeric limit flag is served as 1.

Layers in precedence order: env var FLAG_<KEY uppercased with "-" -> "_">, local overrides[key], remote[key], then the default. A layer is used only if its value is valid for the default's type, else the next layer is tried. Non-env values must have exactly the default's type (bool is not int). Env strings: bool defaults accept "true"/"false" case-insensitively; int defaults accept digits with an optional leading "-"; str defaults accept any string. Return [value, source].

split: open-access


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

N = 1
observations = []
def solve(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('override', overrides, key, False), ('env', env, name, True), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 8',
   ['dark-mode-v2', False, {'dark-mode-v2': False}, {'dark-mode-v2': True}, {'FLAG_dark_mode_v2': 'True'}],
   [True, 'override']),
  ('override layer sample 42',
   ['dark-mode-v2', 7, {'dark-mode-v2': 'red'}, {'dark-mode-v2': 3}, {'FLAG_DARK_MODE_V2': '0'}],
   [0, 'env'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 48', ['beta', 0, {'beta': 3}, {'beta': 3}, {}], [3, 'override'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 4',
   ['dark-mode-v2', 0, {'dark-mode-v2': -2}, {'dark-mode-v2': -2}, {'FLAG_dark_mode_v2': 'yes'}],
   [-2, 'override']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 42',
   ['dark-mode-v2', 7, {'dark-mode-v2': 'red'}, {'dark-mode-v2': 3}, {'FLAG_DARK_MODE_V2': '0'}],
   [0, 'env'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default'])]]
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(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('remote', remote, key, False), ('override', overrides, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 8',
   ['dark-mode-v2', False, {'dark-mode-v2': False}, {'dark-mode-v2': True}, {'FLAG_dark_mode_v2': 'True'}],
   [True, 'override']),
  ('override layer sample 42',
   ['dark-mode-v2', 7, {'dark-mode-v2': 'red'}, {'dark-mode-v2': 3}, {'FLAG_DARK_MODE_V2': '0'}],
   [0, 'env'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 48', ['beta', 0, {'beta': 3}, {'beta': 3}, {}], [3, 'override'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 4',
   ['dark-mode-v2', 0, {'dark-mode-v2': -2}, {'dark-mode-v2': -2}, {'FLAG_dark_mode_v2': 'yes'}],
   [-2, 'override']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 42',
   ['dark-mode-v2', 7, {'dark-mode-v2': 'red'}, {'dark-mode-v2': 3}, {'FLAG_DARK_MODE_V2': '0'}],
   [0, 'env'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An incident responder's environment pin is ignored on hosts with a local override file.

Layers in precedence order: env var FLAG_<KEY uppercased with "-" -> "_">, local overrides[key], remote[key], then the default. A layer is used only if its value is valid for the default's type, else the next layer is tried. Non-env values must have exactly the default's type (bool is not int). Env strings: bool defaults accept "true"/"false" case-insensitively; int defaults accept digits with an optional leading "-"; str defaults accept any string. Return [value, source].

split: open-access


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

N = 1
observations = []
def solve(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper()
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 6', ['beta', True, {}, {'beta': 0}, {'FLAG_beta': '-3'}], [True, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 12', ['dark-mode-v2', 'blue', {}, {'dark-mode-v2': 0}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default'])]]
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(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 6', ['beta', True, {}, {'beta': 0}, {'FLAG_beta': '-3'}], [True, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 12', ['dark-mode-v2', 'blue', {}, {'dark-mode-v2': 0}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default'])]]
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:
FLAG_DARK-MODE-V2 can never be set from a shell, so the env layer is unreachable for dashed keys.

Layers in precedence order: env var FLAG_<KEY uppercased with "-" -> "_">, local overrides[key], remote[key], then the default. A layer is used only if its value is valid for the default's type, else the next layer is tried. Non-env values must have exactly the default's type (bool is not int). Env strings: bool defaults accept "true"/"false" case-insensitively; int defaults accept digits with an optional leading "-"; str defaults accept any string. Return [value, source].

split: open-access


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

N = 1
observations = []
def solve(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
            return [default, 'default']
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 6', ['beta', True, {}, {'beta': 0}, {'FLAG_beta': '-3'}], [True, 'default']),
  ('override layer sample 55', ['beta', False, {'beta': True}, {}, {'FLAG_BETA': 'yes'}], [True, 'remote'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 15',
   ['dark-mode-v2', True, {'dark-mode-v2': 0}, {'dark-mode-v2': 3}, {'FLAG_dark_mode_v2': 'yes'}],
   [True, 'default']),
  ('override layer sample 38',
   ['new-ui', 7, {'new-ui': 'x'}, {'new-ui': 0}, {'FLAG_NEW_UI': 'true'}],
   [0, 'override'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 25',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': True}, {'dark-mode-v2': -2}, {}],
   ['blue', 'default']),
  ('override layer sample 28', ['beta', 7, {'beta': 0}, {'beta': 'x'}, {}], [0, 'remote'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 5',
   ['dark-mode-v2', 7, {'dark-mode-v2': 1}, {}, {'FLAG_DARK_MODE_V2': 'yes'}],
   [1, 'remote']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 32', ['new-ui', False, {'new-ui': -2}, {'new-ui': -2}, {}], [False, 'default'])]]
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(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
            return [table[k], source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 6', ['beta', True, {}, {'beta': 0}, {'FLAG_beta': '-3'}], [True, 'default']),
  ('override layer sample 55', ['beta', False, {'beta': True}, {}, {'FLAG_BETA': 'yes'}], [True, 'remote'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 15',
   ['dark-mode-v2', True, {'dark-mode-v2': 0}, {'dark-mode-v2': 3}, {'FLAG_dark_mode_v2': 'yes'}],
   [True, 'default']),
  ('override layer sample 38',
   ['new-ui', 7, {'new-ui': 'x'}, {'new-ui': 0}, {'FLAG_NEW_UI': 'true'}],
   [0, 'override'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 25',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': True}, {'dark-mode-v2': -2}, {}],
   ['blue', 'default']),
  ('override layer sample 28', ['beta', 7, {'beta': 0}, {'beta': 'x'}, {}], [0, 'remote'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 5',
   ['dark-mode-v2', 7, {'dark-mode-v2': 1}, {}, {'FLAG_DARK_MODE_V2': 'yes'}],
   [1, 'remote']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 32', ['new-ui', False, {'new-ui': -2}, {'new-ui': -2}, {}], [False, 'default'])]]
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 malformed environment value hides a valid remote value.

Layers in precedence order: env var FLAG_<KEY uppercased with "-" -> "_">, local overrides[key], remote[key], then the default. A layer is used only if its value is valid for the default's type, else the next layer is tried. Non-env values must have exactly the default's type (bool is not int). Env strings: bool defaults accept "true"/"false" case-insensitively; int defaults accept digits with an optional leading "-"; str defaults accept any string. Return [value, source].

split: open-access


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

N = 1
observations = []
def solve(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('override layer sample 6', ['beta', True, {}, {'beta': 0}, {'FLAG_beta': '-3'}], [True, 'default']),
  ('override layer sample 7', ['beta', True, {}, {'beta': 3}, {'FLAG_beta': 'True'}], [True, 'default']),
  ('override layer sample 8',
   ['dark-mode-v2', False, {'dark-mode-v2': False}, {'dark-mode-v2': True}, {'FLAG_dark_mode_v2': 'True'}],
   [True, 'override'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 12', ['dark-mode-v2', 'blue', {}, {'dark-mode-v2': 0}, {}], ['blue', 'default']),
  ('override layer sample 13', ['beta', 7, {'beta': -2}, {}, {}], [-2, 'remote'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 18',
   ['dark-mode-v2', 0, {}, {'dark-mode-v2': True}, {'FLAG_DARK_MODE_V2': 'true'}],
   [0, 'default'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default']),
  ('override layer sample 23', ['beta', False, {'beta': 'red'}, {'beta': 1}, {}], [False, 'default'])]]
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(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true') if low in ('true', 'false') else (False, None)
            if isinstance(default, int):
                body = v[1:] if v.startswith(('-', '+')) else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote']),
  ('override layer sample 2', ['new-ui', 'blue', {'new-ui': False}, {}, {}], ['blue', 'default'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('override layer sample 6', ['beta', True, {}, {'beta': 0}, {'FLAG_beta': '-3'}], [True, 'default']),
  ('override layer sample 7', ['beta', True, {}, {'beta': 3}, {'FLAG_beta': 'True'}], [True, 'default']),
  ('override layer sample 8',
   ['dark-mode-v2', False, {'dark-mode-v2': False}, {'dark-mode-v2': True}, {'FLAG_dark_mode_v2': 'True'}],
   [True, 'override'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 12', ['dark-mode-v2', 'blue', {}, {'dark-mode-v2': 0}, {}], ['blue', 'default']),
  ('override layer sample 13', ['beta', 7, {'beta': -2}, {}, {}], [-2, 'remote'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 18',
   ['dark-mode-v2', 0, {}, {'dark-mode-v2': True}, {'FLAG_DARK_MODE_V2': 'true'}],
   [0, 'default'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default']),
  ('override layer sample 23', ['beta', False, {'beta': 'red'}, {'beta': 1}, {}], [False, 'default'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An operator cannot pin an offset flag to -3 via the environment.

Layers in precedence order: env var FLAG_<KEY uppercased with "-" -> "_">, local overrides[key], remote[key], then the default. A layer is used only if its value is valid for the default's type, else the next layer is tried. Non-env values must have exactly the default's type (bool is not int). Env strings: bool defaults accept "true"/"false" case-insensitively; int defaults accept digits with an optional leading "-"; str defaults accept any string. Return [value, source].

split: open-access


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

N = 1
observations = []
def solve(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, v == 'true')
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 49', ['beta', True, {'beta': 'red'}, {}, {'FLAG_BETA': 'yes'}], [True, 'default']),
  ('override layer sample 55', ['beta', False, {'beta': True}, {}, {'FLAG_BETA': 'yes'}], [True, 'remote'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 49', ['beta', True, {'beta': 'red'}, {}, {'FLAG_BETA': 'yes'}], [True, 'default']),
  ('override layer sample 55', ['beta', False, {'beta': True}, {}, {'FLAG_BETA': 'yes'}], [True, 'remote'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 18',
   ['dark-mode-v2', 0, {}, {'dark-mode-v2': True}, {'FLAG_DARK_MODE_V2': 'true'}],
   [0, 'default'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default']),
  ('override layer sample 49', ['beta', True, {'beta': 'red'}, {}, {'FLAG_BETA': 'yes'}], [True, 'default'])]]
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(key, default, remote, overrides, env):
    def coerce(v, from_env):
        if from_env:
            if isinstance(default, bool):
                low = v.lower()
                return (True, low == 'true')
            if isinstance(default, int):
                body = v[1:] if v.startswith('-') else v
                return (True, int(v)) if body.isdigit() else (False, None)
            return (True, v)
        return (True, v) if type(v) is type(default) else (False, None)
    name = 'FLAG_' + key.upper().replace('-', '_')
    layers = [('env', env, name, True), ('override', overrides, key, False), ('remote', remote, key, False)]
    for source, table, k, from_env in layers:
        if k in table:
            ok, value = coerce(table[k], from_env)
            if ok:
                return [value, source]
    return [default, 'default']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('boolean remote value rejected for integer flag', ['beta', 3, {'beta': True}, {}, {}], [3, 'default']),
  ('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 1', ['beta', 7, {'beta': 1}, {}, {}], [1, 'remote'])],
 [('environment beats local override',
   ['new-ui', False, {}, {'new-ui': False}, {'FLAG_NEW_UI': 'true'}],
   [True, 'env']),
  ('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 49', ['beta', True, {'beta': 'red'}, {}, {'FLAG_BETA': 'yes'}], [True, 'default']),
  ('override layer sample 55', ['beta', False, {'beta': True}, {}, {'FLAG_BETA': 'yes'}], [True, 'remote'])],
 [('dashed key maps to underscored env name',
   ['dark-mode-v2', 'blue', {}, {}, {'FLAG_DARK_MODE_V2': 'green'}],
   ['green', 'env']),
  ('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('override layer sample 11', ['beta', True, {'beta': -2}, {'beta': 0}, {}], [True, 'default']),
  ('override layer sample 49', ['beta', True, {'beta': 'red'}, {}, {'FLAG_BETA': 'yes'}], [True, 'default']),
  ('override layer sample 55', ['beta', False, {'beta': True}, {}, {'FLAG_BETA': 'yes'}], [True, 'remote'])],
 [('invalid env value falls through to remote',
   ['beta', 0, {'beta': 5}, {}, {'FLAG_BETA': 'lots'}],
   [5, 'remote']),
  ('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('override layer sample 16', ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {}], ['blue', 'default']),
  ('override layer sample 17',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 'red'}, {'dark-mode-v2': 'red'}, {'FLAG_DARK-MODE-V2': 'yes'}],
   ['red', 'override']),
  ('override layer sample 18',
   ['dark-mode-v2', 0, {}, {'dark-mode-v2': True}, {'FLAG_DARK_MODE_V2': 'true'}],
   [0, 'default'])],
 [('negative integer from env', ['beta', 0, {}, {}, {'FLAG_BETA': '-3'}], [-3, 'env']),
  ('plus sign is not a valid integer', ['beta', 0, {'beta': 9}, {}, {'FLAG_BETA': '+4'}], [9, 'remote']),
  ('env boolean is case-insensitive', ['beta', False, {}, {}, {'FLAG_BETA': 'TRUE'}], [True, 'env']),
  ('non-boolean env text is invalid for boolean flag',
   ['beta', True, {'beta': True}, {}, {'FLAG_BETA': 'yes'}],
   [True, 'remote']),
  ('local override beats remote', ['beta', 'a', {'beta': 'b'}, {'beta': 'c'}, {}], ['c', 'override']),
  ('override layer sample 21',
   ['dark-mode-v2', False, {}, {}, {'FLAG_DARK-MODE-V2': 'true'}],
   [False, 'default']),
  ('override layer sample 22',
   ['dark-mode-v2', 'blue', {'dark-mode-v2': 1}, {}, {'FLAG_dark_mode_v2': 'True'}],
   ['blue', 'default']),
  ('override layer sample 49', ['beta', True, {'beta': 'red'}, {}, {'FLAG_BETA': 'yes'}], [True, 'default'])]]
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:
FLAG_BETA=TRUE disables the flag and FLAG_BETA=yes silently means false.

Layers in precedence order: env var FLAG_<KEY uppercased with "-" -> "_">, local overrides[key], remote[key], then the default. A layer is used only if its value is valid for the default's type, else the next layer is tried. Non-env values must have exactly the default's type (bool is not int). Env strings: bool defaults accept "true"/"false" case-insensitively; int defaults accept digits with an optional leading "-"; str defaults accept any string. Return [value, source].

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]]),
  ('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]])],
 [('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']]),
  ('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 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]])],
 [('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 12',
   [{'version': 3,
     'flags': {'c': {'value': True, 'version': 3},
               'd': {'value': 'x', 'version': 0, 'deleted': True},
               'a': {'value': False, 'version': 0}}},
    {'version': 1,
     'flags': {'b': {'value': False, 'version': 2},
               'd': {'value': True, 'version': 0},
               'a': {'value': True, 'version': 1, 'deleted': True}}}],
   [['a', False], ['c', True]]),
  ('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 5',
   [{'version': 2, 'flags': {'b': {'value': 2, 'version': 3}}},
    {'version': 2,
     'flags': {'c': {'value': False, 'version': 1},
               'b': {'value': True, 'version': 3},
               'a': {'value': False, 'version': 1, 'deleted': True}}}],
   [['b', 2], ['c', False]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 40',
   [{'version': 2,
     'flags': {'d': {'value': 'x', 'version': 0},
               'c': {'value': False, 'version': 1, 'deleted': True},
               'b': {'value': 2, 'version': 2}}},
    {'version': 3,
     'flags': {'b': {'value': True, 'version': 1}, 'c': {'value': False, 'version': 0, 'deleted': True}}}],
   [['b', 2], ['d', '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']]),
  ('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 10',
   [{'version': 3, 'flags': {'d': {'value': True, 'version': 0}, 'c': {'value': 2, 'version': 3}}},
    {'version': 3, 'flags': {'a': {'value': True, 'version': 1}, 'd': {'value': 'x', 'version': 3}}}],
   [['a', True], ['c', 2], ['d', 'x']]),
  ('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 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}}}],
   [])]]
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 is None or incoming['version'] > local['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]])],
 [('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']]),
  ('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 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]])],
 [('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 12',
   [{'version': 3,
     'flags': {'c': {'value': True, 'version': 3},
               'd': {'value': 'x', 'version': 0, 'deleted': True},
               'a': {'value': False, 'version': 0}}},
    {'version': 1,
     'flags': {'b': {'value': False, 'version': 2},
               'd': {'value': True, 'version': 0},
               'a': {'value': True, 'version': 1, 'deleted': True}}}],
   [['a', False], ['c', True]]),
  ('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 5',
   [{'version': 2, 'flags': {'b': {'value': 2, 'version': 3}}},
    {'version': 2,
     'flags': {'c': {'value': False, 'version': 1},
               'b': {'value': True, 'version': 3},
               'a': {'value': False, 'version': 1, 'deleted': True}}}],
   [['b', 2], ['c', False]]),
  ('payload pair sample 16', [{'version': 2, 'flags': {}}, {'version': 3, 'flags': {}}], []),
  ('payload pair sample 40',
   [{'version': 2,
     'flags': {'d': {'value': 'x', 'version': 0},
               'c': {'value': False, 'version': 1, 'deleted': True},
               'b': {'value': 2, 'version': 2}}},
    {'version': 3,
     'flags': {'b': {'value': True, 'version': 1}, 'c': {'value': False, 'version': 0, 'deleted': True}}}],
   [['b', 2], ['d', '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']]),
  ('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 10',
   [{'version': 3, 'flags': {'d': {'value': True, 'version': 0}, 'c': {'value': 2, 'version': 3}}},
    {'version': 3, 'flags': {'a': {'value': True, 'version': 1}, 'd': {'value': 'x', 'version': 3}}}],
   [['a', True], ['c', 2], ['d', 'x']]),
  ('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 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}}}],
   [])]]
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 replayed stream event with the same flag version flips the value back to an older payload.

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