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

N = 1
observations = []
def solve(d):
    intent=dict(d['intent'])
    if d['toggle'] is not None: intent[d['branch']]=d['toggle']
    if d['complete'] and not d['descendants']: intent.pop(d['branch'],None)
    result={}
    for x in d['descendants']:
        nearest=next((a for a in reversed(d['ancestors'][x]) if a in intent),None)
        inherited=intent[nearest] if nearest is not None else d['stored'].get(x,False)
        value=d['overrides'].get(x,inherited)
        result[x]=d['stored'].get(x,False) if x in d['disabled'] else value
    pending={x:v for x,v in intent.items() if x in d['unknown']}
    checked=sorted(x for x in d['descendants'] if result[x])
    return [intent,result,pending,checked]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 2: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 3: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 4: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 5: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True, 'v4': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True, 'v4': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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(d):
    intent=dict(d['intent'])
    if d['toggle'] is not None: intent[d['branch']]=d['toggle']
    if d['complete'] and not d['descendants']: intent.pop(d['branch'],None)
    result={}
    for x in d['descendants']:
        nearest=next((a for a in reversed(d['ancestors'][x]) if a in intent),None)
        inherited=intent[nearest] if nearest is not None else d['stored'].get(x,False)
        value=d['overrides'].get(x,inherited)
        result[x]=d['stored'].get(x,False) if x in d['disabled'] else value
    pending={x:v for x,v in intent.items() if x in d['unknown']}
    checked=[x for x in d['descendants'] if d['stored'].get(x,False)]
    return [intent,result,pending,checked]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 2: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 3: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 4: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])], 5: [('inherit', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True, 'v4': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4']]), ('no toggle', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': None, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('uncheck', {'intent': {'r': True, 'b': True, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, {'b': False, 'q': True}, ['c', 'd', 'e']]), ('empty unknown', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': False, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {}, {'b': True, 'q': True}, []]), ('empty complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': [], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'q': True}, {}, {'q': True}, []]), ('loaded complete', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': True, 'branch': 'b', 'complete': True, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': True, 'q': True}, {'z': True, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': True, 'v1': True, 'v2': True, 'v3': True, 'v4': True}, {'b': True, 'q': True}, ['z', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4']]), ('disabled uncheck', {'intent': {'r': True, 'b': False, 'q': True}, 'toggle': False, 'branch': 'b', 'complete': False, 'descendants': ['z', 'a', 'c', 'd', 'e', 'v0', 'v1', 'v2', 'v3', 'v4'], 'ancestors': {'z': ['r', 'b'], 'a': ['r', 'b'], 'c': ['r', 'b'], 'd': [], 'e': ['r'], 'v0': ['r', 'b'], 'v1': ['r', 'b'], 'v2': ['r', 'b'], 'v3': ['r', 'b'], 'v4': ['r', 'b']}, 'stored': {'c': True, 'd': True}, 'overrides': {'a': False}, 'disabled': ['c'], 'unknown': ['b', 'q']}, [{'r': True, 'b': False, 'q': True}, {'z': False, 'a': False, 'c': True, 'd': True, 'e': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, {'b': False, 'q': True}, ['c', 'd', 'e']])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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:
Checked leaf projection loses tree order or uses stale state produces the wrong hierarchical widget state in a regression fixture.

Checking an incompletely loaded branch stores inherited intent. Loaded writable descendants receive nearest ancestor intent unless they have an explicit override. Disabled descendants keep stored state. A fully loaded empty branch removes obsolete intent; pending intent remains for unknown descendants.

split: open-access


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

N = 1
observations = []
def solve(d):
    new=d['incoming']
    removed_roots=set(d['old'])-set(new)
    removed={x for x in d['rows'] if x in removed_roots or any(a in removed_roots for a in d['ancestors'].get(x,[]))}
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    cache={x:v for x,v in d['cache'].items() if x not in removed}
    focus=d['parent'] if d['focus'] in removed else d['focus']
    edit=None if d['edit'] in removed else d['edit']
    added=[x for x in new if x not in d['old']]
    versions={x:(d['revision'] if x==d['parent'] else v) for x,v in d['versions'].items()}
    return [new,sorted(removed),selected,expanded,cache,focus,edit,added,versions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('removed child', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0'], {'r': 6, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 6, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 6, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 6, 'outside': 2}])], 2: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 7, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 7, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 7, 'outside': 2}])], 3: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 8, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 8, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 8, 'outside': 2}])], 4: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 9, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 9, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 9, 'outside': 2}])], 5: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 10, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 10, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 10, 'outside': 2}])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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(d):
    new=sorted(set(d['incoming']))
    removed_roots=set(d['old'])-set(new)
    removed={x for x in d['rows'] if x in removed_roots or any(a in removed_roots for a in d['ancestors'].get(x,[]))}
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    cache={x:v for x,v in d['cache'].items() if x not in removed}
    focus=d['parent'] if d['focus'] in removed else d['focus']
    edit=None if d['edit'] in removed else d['edit']
    added=[x for x in new if x not in d['old']]
    versions={x:(d['revision'] if x==d['parent'] else v) for x,v in d['versions'].items()}
    return [new,sorted(removed),selected,expanded,cache,focus,edit,added,versions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('removed child', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0'], {'r': 6, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 6, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 6, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 6, 'outside': 2}])], 2: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 7, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 7, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 7, 'outside': 2}])], 3: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 8, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 8, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 8, 'outside': 2}])], 4: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 9, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 9, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 9, 'outside': 2}])], 5: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 10, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 10, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 10, 'outside': 2}])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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:
Refresh changes server child order or duplicates child IDs produces the wrong hierarchical widget state in a regression fixture.

A refresh replaces one branch child list while preserving child identity state for survivors. Removed child closures lose selection, expansion, cached data and edit sessions; descendants of surviving children remain. Fresh child order wins. Focus removed by refresh recovers to the parent; unrelated focus remains.

split: open-access