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]
    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[0] 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 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[0] 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)

prompt:
Subtree clipboard omits root or descendants 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):
    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,[]) 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[0] 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)

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):
    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:[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[0] 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)

prompt:
Clipboard path loses self or ancestor identity 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):
    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
    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[0] 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=[]
    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[0] 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)

prompt:
Copied branches are exposed as pending cut 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