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

N = 1
observations = []
def solve(d):
    removed=set(d['removed'])
    rows=[x for x in d['rows'] if x not in removed]
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    pending={x:v for x,v in d['pending'].items() if x not in removed}
    nextrow=next((x for x in d['next'] if x in rows),None)
    prevrow=next((x for x in reversed(d['previous']) if x in rows),None)
    fallback=next((x for x in [nextrow,prevrow,d['parent']]+d['roots'] if x in rows),None)
    focus=fallback
    anchor=None if d['anchor'] in removed else d['anchor']
    edit=None if d['edit'] in removed else d['edit']
    return [rows,selected,expanded,pending,focus,anchor,edit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 2: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 3: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 4: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 5: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None])]}
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):
    removed=set(d['removed'])
    rows=[x for x in d['rows'] if x not in removed]
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    pending={x:v for x,v in d['pending'].items() if x not in removed}
    nextrow=next((x for x in d['next'] if x in rows),None)
    prevrow=next((x for x in reversed(d['previous']) if x in rows),None)
    fallback=next((x for x in [nextrow,prevrow,d['parent']]+d['roots'] if x in rows),None)
    focus=d['focus']
    anchor=None if d['anchor'] in removed else d['anchor']
    edit=None if d['edit'] in removed else d['edit']
    return [rows,selected,expanded,pending,focus,anchor,edit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 2: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 3: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 4: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 5: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None])]}
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:
Deletion steals unaffected focus or strands removed focus produces the wrong hierarchical widget state in a regression fixture.

Remove a supplied subtree closure atomically. Focus inside the deleted subtree recovers to surviving next sibling, previous sibling, then parent, then first root. Preserve unrelated state; clear only removed anchor, edits, expansion, selection and pending loads.

split: open-access


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

N = 1
observations = []
def solve(d):
    removed=set(d['removed'])
    rows=[x for x in d['rows'] if x not in removed]
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    pending={x:v for x,v in d['pending'].items() if x not in removed}
    nextrow=next((x for x in d['next'] if x in rows),None)
    prevrow=next((x for x in reversed(d['previous']) if x in rows),None)
    fallback=next((x for x in [nextrow,prevrow,d['parent']]+d['roots'] if x in rows),None)
    focus=fallback if d['focus'] in removed else d['focus']
    anchor=d['anchor']
    edit=None if d['edit'] in removed else d['edit']
    return [rows,selected,expanded,pending,focus,anchor,edit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 2: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 3: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 4: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 5: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None])]}
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):
    removed=set(d['removed'])
    rows=[x for x in d['rows'] if x not in removed]
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    pending={x:v for x,v in d['pending'].items() if x not in removed}
    nextrow=next((x for x in d['next'] if x in rows),None)
    prevrow=next((x for x in reversed(d['previous']) if x in rows),None)
    fallback=next((x for x in [nextrow,prevrow,d['parent']]+d['roots'] if x in rows),None)
    focus=fallback if d['focus'] in removed else d['focus']
    anchor=None
    edit=None if d['edit'] in removed else d['edit']
    return [rows,selected,expanded,pending,focus,anchor,edit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 2: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 3: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 4: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 5: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None])]}
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:
Range anchor cleanup crosses subtree boundary produces the wrong hierarchical widget state in a regression fixture.

Remove a supplied subtree closure atomically. Focus inside the deleted subtree recovers to surviving next sibling, previous sibling, then parent, then first root. Preserve unrelated state; clear only removed anchor, edits, expansion, selection and pending loads.

split: open-access


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

N = 1
observations = []
def solve(d):
    removed=set(d['removed'])
    rows=[x for x in d['rows'] if x not in removed]
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    pending={x:v for x,v in d['pending'].items() if x not in removed}
    nextrow=next((x for x in d['next'] if x in rows),None)
    prevrow=next((x for x in reversed(d['previous']) if x in rows),None)
    fallback=next((x for x in [nextrow,prevrow,d['parent']]+d['roots'] if x in rows),None)
    focus=fallback if d['focus'] in removed else d['focus']
    anchor=None if d['anchor'] in removed else d['anchor']
    edit=d['edit']
    return [rows,selected,expanded,pending,focus,anchor,edit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 2: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 3: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 4: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 5: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None])]}
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):
    removed=set(d['removed'])
    rows=[x for x in d['rows'] if x not in removed]
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    pending={x:v for x,v in d['pending'].items() if x not in removed}
    nextrow=next((x for x in d['next'] if x in rows),None)
    prevrow=next((x for x in reversed(d['previous']) if x in rows),None)
    fallback=next((x for x in [nextrow,prevrow,d['parent']]+d['roots'] if x in rows),None)
    focus=fallback if d['focus'] in removed else d['focus']
    anchor=None if d['anchor'] in removed else d['anchor']
    edit=None
    return [rows,selected,expanded,pending,focus,anchor,edit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 2: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 3: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 4: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3'], ['a'], ['r'], {'a': 1}, 'x', None, None])], 5: [('next recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'z', None, None]), ('previous recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None]), ('parent recovery', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['a'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'r', None, None]), ('unrelated focus', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'previous': ['a', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'a', 'anchor': 'a', 'edit': 'a'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'a', 'a', 'a']), ('last root', {'removed': ['b', 'c'], 'rows': ['b', 'c'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': [], 'previous': [], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [[], ['a'], ['r'], {'a': 1}, None, None, None]), ('stale neighbors', {'removed': ['b', 'c'], 'rows': ['r', 'a', 'x', 'b', 'c', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], 'selected': ['a', 'c'], 'expanded': ['r', 'b'], 'pending': {'a': 1, 'c': 2}, 'next': ['c'], 'previous': ['a', 'c', 'x'], 'parent': 'r', 'roots': ['r'], 'focus': 'c', 'anchor': 'c', 'edit': 'c'}, [['r', 'a', 'x', 'z', 'q0', 'q1', 'q2', 'q3', 'q4'], ['a'], ['r'], {'a': 1}, 'x', None, None])]}
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:
Inline edit remains bound to removed row produces the wrong hierarchical widget state in a regression fixture.

Remove a supplied subtree closure atomically. Focus inside the deleted subtree recovers to surviving next sibling, previous sibling, then parent, then first root. Preserve unrelated state; clear only removed anchor, edits, expansion, selection and pending loads.

split: open-access