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

N = 1
observations = []
def solve(d):
    old=d['old']; new=d['new']
    index=old.index(d['anchor']) if d['anchor'] in old else 0
    candidates=[d['anchor']]+old[index+1:]+list(reversed(old[:index]))
    anchor=next((x for x in candidates if x in new),(new[0] if new else None))
    position=sum(d['heights'][x] for x in new[:new.index(anchor)]) if anchor is not None else 0
    inside=min(d['offset'],d['heights'][anchor]-1) if anchor==d['anchor'] else 0
    requested=position+max(0,inside)
    content=sum(d['heights'][x] for x in new)
    scroll=max(0,min(requested,content-d['viewport']))
    active=anchor
    return [anchor,scroll,content,active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 64.5, 100, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 40, 100, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 76, 100, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 69, 'a'])], 2: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 65.5, 102, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 42, 102, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 78, 102, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 70, 'a'])], 3: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 66.5, 104, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 44, 104, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 80, 104, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 71, 'a'])], 4: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 67.5, 106, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 46, 106, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 82, 106, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 72, 'a'])], 5: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 68.5, 108, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 48, 108, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 84, 108, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 73, 'a'])]}
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):
    old=d['old']; new=d['new']
    index=old.index(d['anchor']) if d['anchor'] in old else 0
    candidates=[d['anchor']]+old[index+1:]+list(reversed(old[:index]))
    anchor=next((x for x in candidates if x in new),(new[0] if new else None))
    position=sum(d['heights'][x] for x in new[:new.index(anchor)]) if anchor is not None else 0
    inside=min(d['offset'],d['heights'][anchor]-1) if anchor==d['anchor'] else 0
    requested=position+max(0,inside)
    content=sum(d['heights'][x] for x in new)
    scroll=max(0,min(requested,content-d['viewport']))
    active=new[0] if new else None
    return [anchor,scroll,content,active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 64.5, 100, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 40, 100, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 76, 100, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 69, 'a'])], 2: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 65.5, 102, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 42, 102, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 78, 102, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 70, 'a'])], 3: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 66.5, 104, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 44, 104, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 80, 104, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 71, 'a'])], 4: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 67.5, 106, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 46, 106, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 82, 106, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 72, 'a'])], 5: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 68.5, 108, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 48, 108, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 84, 108, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 73, 'a'])]}
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:
Viewport stabilization moves logical tree focus produces the wrong hierarchical widget state in a regression fixture.

After branch expansion changes row heights/order, preserve the first visible surviving anchor and its pixel offset. If that row is removed, use the next surviving old row, then previous row. Clamp scroll to content extent, include fractional row offsets, and keep active-row identity independent from viewport anchoring.

split: open-access


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

N = 1
observations = []
def solve(d):
    old=d['old']; new=d['new']
    index=old.index(d['anchor']) if d['anchor'] in old else 0
    candidates=[d['anchor']]+old[index+1:]+list(reversed(old[:index]))
    anchor=next((x for x in candidates if x in new),(new[0] if new else None))
    position=sum(d['heights'][x] for x in new[:new.index(anchor)]) if anchor is not None else 0
    inside=min(d['offset'],d['heights'][anchor]-1) if anchor is not None else 0
    requested=position+max(0,inside)
    content=sum(d['heights'][x] for x in new)
    scroll=max(0,min(requested,content-d['viewport']))
    active=d['active']
    return [anchor,scroll,content,active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 64.5, 100, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 40, 100, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 76, 100, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 69, 'a'])], 2: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 65.5, 102, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 42, 102, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 78, 102, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 70, 'a'])], 3: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 66.5, 104, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 44, 104, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 80, 104, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 71, 'a'])], 4: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 67.5, 106, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 46, 106, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 82, 106, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 72, 'a'])], 5: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 68.5, 108, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 48, 108, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 84, 108, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 73, 'a'])]}
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):
    old=d['old']; new=d['new']
    index=old.index(d['anchor']) if d['anchor'] in old else 0
    candidates=[d['anchor']]+old[index+1:]+list(reversed(old[:index]))
    anchor=next((x for x in candidates if x in new),(new[0] if new else None))
    position=sum(d['heights'][x] for x in new[:new.index(anchor)]) if anchor is not None else 0
    inside=min(d['offset'],d['heights'][anchor]-1) if anchor==d['anchor'] and anchor in old[:index] else 0
    requested=position+max(0,inside)
    content=sum(d['heights'][x] for x in new)
    scroll=max(0,min(requested,content-d['viewport']))
    active=d['active']
    return [anchor,scroll,content,active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 64.5, 100, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 40, 100, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 76, 100, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 16, 'c': 11, 'z': 12, 'x': 31, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 69, 'a'])], 2: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 65.5, 102, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 42, 102, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 78, 102, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 17, 'c': 11, 'z': 12, 'x': 32, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 70, 'a'])], 3: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 66.5, 104, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 44, 104, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 80, 104, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 18, 'c': 11, 'z': 12, 'x': 33, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 71, 'a'])], 4: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 67.5, 106, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 46, 106, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 82, 106, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 19, 'c': 11, 'z': 12, 'x': 34, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 72, 'a'])], 5: [('insert before anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 68.5, 108, 'a']), ('deleted anchor', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['c', 30, 53, 'a']), ('previous fallback', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'a'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['a', 10, 30, 'a']), ('new-only tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['q'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['q', 0, 5, 'a']), ('empty tree', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': [], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, [None, 0, 0, 'a']), ('bottom clamp', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 60, 'active': 'a'}, ['b', 48, 108, 'a']), ('oversized offset', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['r', 'x', 'a', 'b', 'c', 'z'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 100, 'viewport': 20, 'active': 'a'}, ['b', 84, 108, 'a']), ('reordered', {'old': ['r', 'a', 'b', 'c', 'z'], 'new': ['z', 'c', 'b', 'a', 'r'], 'anchor': 'b', 'heights': {'r': 10, 'a': 20, 'b': 20, 'c': 11, 'z': 12, 'x': 35, 'q': 5}, 'offset': 3.5, 'viewport': 20, 'active': 'a'}, ['b', 26.5, 73, 'a'])]}
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:
Replacement viewport anchor inherits deleted row offset produces the wrong hierarchical widget state in a regression fixture.

After branch expansion changes row heights/order, preserve the first visible surviving anchor and its pixel offset. If that row is removed, use the next surviving old row, then previous row. Clamp scroll to content extent, include fractional row offsets, and keep active-row identity independent from viewport anchoring.

split: open-access


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

N = 1
observations = []
def solve(d):
    errors=[]; rows=d['rows']; ids=[r['id'] for r in rows]; table={r['id']:r for r in rows}
    if False: errors.append('duplicate-id')
    if any(r['level']<1 for r in rows): errors.append('invalid-level')
    if any(r['pos']<1 or (r['size']!=-1 and r['pos']>r['size']) for r in rows): errors.append('invalid-position')
    if any(r['parent'] is not None and r['parent'] not in table for r in rows): errors.append('missing-parent')
    if any(r['parent'] in table and r['level']!=table[r['parent']]['level']+1 for r in rows): errors.append('parent-level')
    if any(not r['branch'] and r['expanded'] is not None for r in rows): errors.append('leaf-expanded')
    if d['active'] is not None and d['active'] not in ids: errors.append('missing-active')
    if any(x not in table or not table[x]['selectable'] for x in d['selected']): errors.append('invalid-selection')
    if any(r['busy'] and not r['branch'] for r in rows): errors.append('busy-leaf')
    if any(r['parent'] is None and r['level']!=1 for r in rows): errors.append('root-level')
    return errors
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 2: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 6, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 3: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 7, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 4: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 8, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 5: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 9, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])]}
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):
    errors=[]; rows=d['rows']; ids=[r['id'] for r in rows]; table={r['id']:r for r in rows}
    if len(ids)==len(set(ids)): errors.append('duplicate-id')
    if any(r['level']<1 for r in rows): errors.append('invalid-level')
    if any(r['pos']<1 or (r['size']!=-1 and r['pos']>r['size']) for r in rows): errors.append('invalid-position')
    if any(r['parent'] is not None and r['parent'] not in table for r in rows): errors.append('missing-parent')
    if any(r['parent'] in table and r['level']!=table[r['parent']]['level']+1 for r in rows): errors.append('parent-level')
    if any(not r['branch'] and r['expanded'] is not None for r in rows): errors.append('leaf-expanded')
    if d['active'] is not None and d['active'] not in ids: errors.append('missing-active')
    if any(x not in table or not table[x]['selectable'] for x in d['selected']): errors.append('invalid-selection')
    if any(r['busy'] and not r['branch'] for r in rows): errors.append('busy-leaf')
    if any(r['parent'] is None and r['level']!=1 for r in rows): errors.append('root-level')
    return errors
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 1, 'size': 3, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 2: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 6, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 2, 'size': 4, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 3: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 7, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 3, 'size': 5, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 4: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 8, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 4, 'size': 6, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])], 5: [('valid', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'a', 'selected': ['a']}, []), ('duplicate', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'r', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'r', 'selected': []}, ['duplicate-id', 'parent-level']), ('zero level', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 0, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-level', 'parent-level']), ('zero position', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 0, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('position overflow', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 9, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['invalid-position']), ('unknown size', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': -1, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, []), ('orphan', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'missing', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['missing-parent']), ('level jump', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 4, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['parent-level']), ('leaf expanded false', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': False, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['leaf-expanded']), ('missing active', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': 'gone', 'selected': []}, ['missing-active']), ('protected selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': False, 'busy': False}], 'active': None, 'selected': ['a']}, ['invalid-selection']), ('missing selection', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': ['gone']}, ['invalid-selection']), ('busy leaf', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': 'r', 'branch': False, 'expanded': None, 'selectable': True, 'busy': True}], 'active': None, 'selected': []}, ['busy-leaf']), ('indented root', {'rows': [{'id': 'r', 'level': 1, 'pos': 1, 'size': 1, 'parent': None, 'branch': True, 'expanded': True, 'selectable': True, 'busy': True}, {'id': 'a', 'level': 2, 'pos': 5, 'size': 7, 'parent': None, 'branch': False, 'expanded': None, 'selectable': True, 'busy': False}], 'active': None, 'selected': []}, ['root-level'])]}
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:
Duplicate row IDs are not rejected produces the wrong hierarchical widget state in a regression fixture.

Validate a bounded already-resolved widget snapshot. IDs are unique; each row has positive level, positive position no greater than a known set size, a live parent at prior level, leaves omit expansion, and the single active ID must be exposed. Selected IDs must be selectable; busy leaf rows are invalid. Return ordered error codes.

split: open-access