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

N = 1
observations = []
def solve(d):
    selected=set(d['selected'])&set(d['rows'])
    roots=[x for x in d['rows'] if x in selected and not any(a in selected for a in d['ancestors'].get(x,[]))]
    allowed=[x for x in roots if d['mode']=='copy' or x not in d['readonly']]
    closure=[x for x in d['rows'] if x in allowed or any(a in allowed for a in d['ancestors'].get(x,[]))]
    paths={x:d['ancestors'].get(x,[])+[x] for x in allowed}
    cut=allowed if d['mode']=='cut' else []
    valid=d['clipboard_generation']==d['generation']
    effect='move' if cut and valid and d['same_tree'] else ('copy' if allowed else 'none')
    remaining=[x for x in d['selected'] if x not in closure] if effect=='move' else d['selected']
    focus=allowed[-1] if allowed else d['focus']
    return [allowed,closure,paths,cut,effect,remaining,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 0, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 2: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 3: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 4: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 5: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])]}
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):
    selected=set(d['selected'])&set(d['rows'])
    roots=[x for x in d['rows'] if x in selected and not any(a in selected for a in d['ancestors'].get(x,[]))]
    allowed=[x for x in roots if d['mode']=='copy' or x not in d['readonly']]
    closure=[x for x in d['rows'] if x in allowed or any(a in allowed for a in d['ancestors'].get(x,[]))]
    paths={x:d['ancestors'].get(x,[])+[x] for x in allowed}
    cut=allowed if d['mode']=='cut' else []
    valid=d['clipboard_generation']==d['generation']
    effect='move' if cut and valid and d['same_tree'] else ('copy' if allowed else 'none')
    remaining=[x for x in d['selected'] if x not in closure] if effect=='move' else d['selected']
    focus=d['focus']
    return [allowed,closure,paths,cut,effect,remaining,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 0, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 1, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 2: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 1, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 2, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 3: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 2, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 3, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 4: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 3, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 4, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])], 5: [('cut normalized', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'move', ['q'], 'a']), ('copy protected', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'copy', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, [], 'copy', ['a', 'b', 'q'], 'a']), ('several roots', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': [], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a', 'q'], ['a', 'b', 'c', 'q'], {'a': ['z', 'a'], 'q': ['q']}, ['a', 'q'], 'move', [], 'a']), ('stale cut', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 4, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('cross tree', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['a', 'b', 'q'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': False, 'focus': 'c'}, [['a'], ['a', 'b', 'c'], {'a': ['z', 'a']}, ['a'], 'copy', ['a', 'b', 'q'], 'a']), ('no selection', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': [], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [[], [], {}, [], 'none', [], 'c']), ('descendant alone', {'rows': ['z', 'a', 'b', 'c', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'selected': ['b'], 'ancestors': {'a': ['z'], 'b': ['z', 'a'], 'c': ['z', 'a', 'b']}, 'mode': 'cut', 'readonly': ['q'], 'clipboard_generation': 5, 'generation': 5, 'same_tree': True, 'focus': 'c'}, [['b'], ['b', 'c'], {'b': ['z', 'a', 'b']}, ['b'], 'move', [], 'b'])]}
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:
Clipboard operation focuses the wrong normalized root produces the wrong hierarchical widget state in a regression fixture.

Copy or cut operates on selected topmost roots only, excluding descendants of a selected root. Roots follow tree order. Cut excludes read-only roots, retains protected selection, and advertises a move only within the same tree generation. Clipboard payload carries selected root paths and descendants once.

split: open-access


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

N = 1
observations = []
def solve(d):
    visible=d['visible']
    logical=d['active']
    slot=next((slot for slot,row in d['slots'].items() if row==logical),None)
    ack=slot is not None and d['acks'].get(slot)==[logical,d['generation']]
    aria=(d['tree']+':'+logical) if ack else None
    request=logical if logical is not None and not ack else None
    scroll=visible.index(logical) if logical in visible and slot is None else None
    selection=d['selection']
    lease=[logical,d['generation']] if request is not None else None
    pinned=[logical] if ack else []
    return [logical,aria,request,scroll,selection,lease,pinned]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 0]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 1], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 1], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []])], 2: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 1]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 2], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 2], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []])], 3: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 2]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 3], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 3], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []])], 4: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 3]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 4], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 4], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []])], 5: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 4]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 5], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 5], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []])]}
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):
    visible=d['visible']
    logical=visible[0] if visible else None
    slot=next((slot for slot,row in d['slots'].items() if row==logical),None)
    ack=slot is not None and d['acks'].get(slot)==[logical,d['generation']]
    aria=(d['tree']+':'+logical) if ack else None
    request=logical if logical is not None and not ack else None
    scroll=visible.index(logical) if logical in visible and slot is None else None
    selection=d['selection']
    lease=[logical,d['generation']] if request is not None else None
    pinned=[logical] if ack else []
    return [logical,aria,request,scroll,selection,lease,pinned]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 0]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 1], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 1], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []])], 2: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 1]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 2], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 2], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []])], 3: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 2]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 3], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 3], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []])], 4: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 3]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 4], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 4], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []])], 5: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 4]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 5], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 5], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []])]}
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:
Logical active row is not repaired after branch collapse produces the wrong hierarchical widget state in a regression fixture.

A virtualized active row keeps its identity while offscreen. Expose an active descendant only after a matching mount generation acknowledges the row; scrolling requests mount without changing selection. A recycled slot must not satisfy an old lease. Collapse repairs the logical active row to the closest visible ancestor before mounting.

split: open-access


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

N = 1
observations = []
def solve(d):
    visible=d['visible']
    logical=d['active'] if d['active'] in visible else next((a for a in d['ancestors'] if a in visible),(visible[0] if visible else None))
    slot=next((slot for slot,row in d['slots'].items() if row==logical),None)
    ack=slot is not None and d['acks'].get(slot)==[logical,d['generation']]
    aria=(d['tree']+':'+logical) if ack else None
    request=logical if logical is not None and not ack else None
    scroll=visible.index(logical) if logical in visible and slot is None else None
    selection=d['selection']
    lease=[logical,d['generation']] if request is not None else None
    pinned=[logical] if ack else []
    return [logical,aria,request,scroll,selection,lease,pinned]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 0]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 1], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 1], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []])], 2: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 1]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 2], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 2], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []])], 3: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 2]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 3], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 3], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []])], 4: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 3]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 4], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 4], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []])], 5: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 4]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 5], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 5], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []])]}
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):
    visible=d['visible']
    logical=d['active'] if d['active'] in visible else next((a for a in [] if a in visible),(visible[0] if visible else None))
    slot=next((slot for slot,row in d['slots'].items() if row==logical),None)
    ack=slot is not None and d['acks'].get(slot)==[logical,d['generation']]
    aria=(d['tree']+':'+logical) if ack else None
    request=logical if logical is not None and not ack else None
    scroll=visible.index(logical) if logical in visible and slot is None else None
    selection=d['selection']
    lease=[logical,d['generation']] if request is not None else None
    pinned=[logical] if ack else []
    return [logical,aria,request,scroll,selection,lease,pinned]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 0]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 1], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 1], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 1], 'slot1': ['b', 1]}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 1, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 1], []])], 2: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 1]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 2], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 2], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 2], 'slot1': ['b', 2]}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 2, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 2], []])], 3: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 2]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 3], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 3], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 3], 'slot1': ['b', 3]}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 3, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 3], []])], 4: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 3]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 4], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 4], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 4], 'slot1': ['b', 4]}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 4, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 4], []])], 5: [('mounted lease', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', 'tree:b', None, None, ['a'], None, ['b']]), ('old ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['b', 4]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('recycled ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot1': ['gone', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []]), ('offscreen', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'r'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', 2, ['a'], ['b', 5], []]), ('collapse', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', 'tree:a', None, None, ['a'], None, ['a']]), ('collapse offscreen', {'visible': ['r', 'a'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['a', None, 'a', 1, ['a'], ['a', 5], []]), ('empty tree', {'visible': [], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {}, 'acks': {'slot0': ['a', 5], 'slot1': ['b', 5]}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, [None, None, None, None, ['a'], None, []]), ('no ack', {'visible': ['r', 'a', 'b', 'x0', 'x1', 'x2', 'x3', 'x4'], 'active': 'b', 'ancestors': ['r', 'a'], 'slots': {'slot0': 'a', 'slot1': 'b'}, 'acks': {}, 'generation': 5, 'tree': 'tree', 'selection': ['a']}, ['b', None, 'b', None, ['a'], ['b', 5], []])]}
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:
Active lease chooses outermost instead of nearest ancestor produces the wrong hierarchical widget state in a regression fixture.

A virtualized active row keeps its identity while offscreen. Expose an active descendant only after a matching mount generation acknowledges the row; scrolling requests mount without changing selection. A recycled slot must not satisfy an old lease. Collapse repairs the logical active row to the closest visible ancestor before mounting.

split: open-access