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

N = 1
observations = []
def solve(d):
    r=d['row']
    position=r['index']+1
    size=r['count'] if r['known'] else -1
    level=r['depth']+1
    owner=r['parent'] if r['parent'] is not None else d['tree']
    expanded=r['open'] if r['branch'] else None
    selected=r['id'] in d['selected']
    active=r['id']==d['active']
    dom=d['tree']+':'+r['id']
    rowindex=d['offset']+d['slot']+1
    busy=r['loading']
    return [position,size,level,owner,expanded,selected,active,dom,rowindex,busy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, True, True, 'tree:b', 5, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'tree', True, False, False, 'tree:b', 5, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', None, True, False, 'tree:b', 5, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': False, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, -1, 2, 'p', True, False, True, 'tree:b', 5, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, False, False, 'tree:b', 5, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 9, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [1, 9, 1, 'p', False, False, True, 'tree:b', 5, True])], 2: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, True, True, 'tree:b', 8, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'tree', True, False, False, 'tree:b', 8, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', None, True, False, 'tree:b', 8, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': False, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, -1, 3, 'p', True, False, True, 'tree:b', 8, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, False, False, 'tree:b', 8, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 10, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [1, 10, 1, 'p', False, False, True, 'tree:b', 8, True])], 3: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, True, True, 'tree:b', 11, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'tree', True, False, False, 'tree:b', 11, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', None, True, False, 'tree:b', 11, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': False, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, -1, 4, 'p', True, False, True, 'tree:b', 11, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, False, False, 'tree:b', 11, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 11, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [1, 11, 1, 'p', False, False, True, 'tree:b', 11, True])], 4: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, True, True, 'tree:b', 14, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'tree', True, False, False, 'tree:b', 14, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', None, True, False, 'tree:b', 14, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': False, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, -1, 5, 'p', True, False, True, 'tree:b', 14, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, False, False, 'tree:b', 14, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 12, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [1, 12, 1, 'p', False, False, True, 'tree:b', 14, True])], 5: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, True, True, 'tree:b', 17, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'tree', True, False, False, 'tree:b', 17, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', None, True, False, 'tree:b', 17, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': False, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, -1, 6, 'p', True, False, True, 'tree:b', 17, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, False, False, 'tree:b', 17, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 13, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [1, 13, 1, 'p', False, False, True, 'tree:b', 17, True])]}
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):
    r=d['row']
    position=r['index']+1
    size=r['count'] if r['known'] else -1
    level=r['depth']+1
    owner=r['parent'] if r['parent'] is not None else d['tree']
    expanded=r['open'] if r['branch'] else None
    selected=r['id'] in d['selected']
    active=r['id']==d['active']
    dom=d['tree']+':'+r['id']
    rowindex=d['offset']+d['slot']+1
    busy=r['branch']
    return [position,size,level,owner,expanded,selected,active,dom,rowindex,busy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, True, True, 'tree:b', 5, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'tree', True, False, False, 'tree:b', 5, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', None, True, False, 'tree:b', 5, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': False, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, -1, 2, 'p', True, False, True, 'tree:b', 5, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, False, False, 'tree:b', 5, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 9, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [1, 9, 1, 'p', False, False, True, 'tree:b', 5, True])], 2: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, True, True, 'tree:b', 8, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'tree', True, False, False, 'tree:b', 8, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', None, True, False, 'tree:b', 8, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': False, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, -1, 3, 'p', True, False, True, 'tree:b', 8, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, False, False, 'tree:b', 8, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 10, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [1, 10, 1, 'p', False, False, True, 'tree:b', 8, True])], 3: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, True, True, 'tree:b', 11, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'tree', True, False, False, 'tree:b', 11, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', None, True, False, 'tree:b', 11, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': False, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, -1, 4, 'p', True, False, True, 'tree:b', 11, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, False, False, 'tree:b', 11, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 11, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [1, 11, 1, 'p', False, False, True, 'tree:b', 11, True])], 4: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, True, True, 'tree:b', 14, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'tree', True, False, False, 'tree:b', 14, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', None, True, False, 'tree:b', 14, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': False, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, -1, 5, 'p', True, False, True, 'tree:b', 14, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, False, False, 'tree:b', 14, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 12, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [1, 12, 1, 'p', False, False, True, 'tree:b', 14, True])], 5: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, True, True, 'tree:b', 17, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'tree', True, False, False, 'tree:b', 17, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', None, True, False, 'tree:b', 17, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': False, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, -1, 6, 'p', True, False, True, 'tree:b', 17, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, False, False, 'tree:b', 17, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 13, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [1, 13, 1, 'p', False, False, True, 'tree:b', 17, True])]}
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:
Leaf or idle branch is exposed as busy produces the wrong hierarchical widget state in a regression fixture.

Rows carry id,parent,logical sibling index,known sibling count,depth. The viewport must expose global sibling positions and counts, one-based depth, root ownership, expandable state only for branches, and stable identity independent of recycled slots.

split: open-access


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

N = 1
observations = []
def solve(d):
    match=d['reply_token']==d['token']
    accept=match and d['live'] and d['open']
    children=list(dict.fromkeys(d['reply'])) if accept else d['children']
    busy=False if accept else d['busy']
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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):
    match=d['reply_epoch']==d['epoch']
    accept=match and d['live'] and d['open']
    children=list(dict.fromkeys(d['reply'])) if accept else d['children']
    busy=False if accept else d['busy']
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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:
Branch request identity omits an epoch or token produces the wrong hierarchical widget state in a regression fixture.

A request is accepted only for a live open branch with matching epoch and token. Accepted pages replace a placeholder with deduplicated child IDs, clear busy/error state, and derive completeness from a next cursor. Rejected responses preserve all branch state.

split: open-access


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

N = 1
observations = []
def solve(d):
    match=d['reply_epoch']==d['epoch'] and d['reply_token']==d['token']
    accept=match and d['live']
    children=list(dict.fromkeys(d['reply'])) if accept else d['children']
    busy=False if accept else d['busy']
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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):
    match=d['reply_epoch']==d['epoch'] and d['reply_token']==d['token']
    accept=match and d['open']
    children=list(dict.fromkeys(d['reply'])) if accept else d['children']
    busy=False if accept else d['busy']
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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:
Closed or removed branch accepts a page produces the wrong hierarchical widget state in a regression fixture.

A request is accepted only for a live open branch with matching epoch and token. Accepted pages replace a placeholder with deduplicated child IDs, clear busy/error state, and derive completeness from a next cursor. Rejected responses preserve all branch state.

split: open-access