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

N = 1
observations = []
def solve(d):
    accept=d['target']!=d['root'] and not d['readonly']
    parent=d['target'] if accept else d['old_parent']
    delta=d['target_depth']+1-d['depths'][d['root']]
    depths={x:(v+delta if accept and x in d['closure'] else v) for x,v in d['depths'].items()}
    old_children=[x for x in d['old_children'] if not(accept and x==d['root'])]
    new_children=d['new_children'][:d['position']]+[d['root']]+d['new_children'][d['position']:] if accept else d['new_children']
    invalid=sorted(set([d['old_parent'],d['target']])) if accept else []
    versions={x:v+(1 if accept and x in invalid else 0) for x,v in d['versions'].items()}
    focus=d['focus']
    selected=d['selected']
    expanded=sorted(set(d['expanded'])|({d['target']} if accept and d['reveal'] else set()))
    return [parent,depths,old_children,new_children,invalid,versions,focus,selected,expanded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 2: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 3: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 4: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 5: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])]}
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):
    accept=d['target'] not in d['closure']
    parent=d['target'] if accept else d['old_parent']
    delta=d['target_depth']+1-d['depths'][d['root']]
    depths={x:(v+delta if accept and x in d['closure'] else v) for x,v in d['depths'].items()}
    old_children=[x for x in d['old_children'] if not(accept and x==d['root'])]
    new_children=d['new_children'][:d['position']]+[d['root']]+d['new_children'][d['position']:] if accept else d['new_children']
    invalid=sorted(set([d['old_parent'],d['target']])) if accept else []
    versions={x:v+(1 if accept and x in invalid else 0) for x,v in d['versions'].items()}
    focus=d['focus']
    selected=d['selected']
    expanded=sorted(set(d['expanded'])|({d['target']} if accept and d['reveal'] else set()))
    return [parent,depths,old_children,new_children,invalid,versions,focus,selected,expanded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 2: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 3: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 4: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 5: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])]}
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:
Drop validation permits descendant cycles or protected parents produces the wrong hierarchical widget state in a regression fixture.

The closure contains a moved subtree and the source and destination are distinct parents. Reject drops into that closure or a read-only destination. Accepted moves replace the root parent, shift every descendant level by the parent-depth delta, invalidate sibling metadata, retain ID-based selection and focus, and increment only affected parent versions.

split: open-access


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

N = 1
observations = []
def solve(d):
    accept=d['target'] not in d['closure'] and not d['readonly']
    parent=d['old_parent']
    delta=d['target_depth']+1-d['depths'][d['root']]
    depths={x:(v+delta if accept and x in d['closure'] else v) for x,v in d['depths'].items()}
    old_children=[x for x in d['old_children'] if not(accept and x==d['root'])]
    new_children=d['new_children'][:d['position']]+[d['root']]+d['new_children'][d['position']:] if accept else d['new_children']
    invalid=sorted(set([d['old_parent'],d['target']])) if accept else []
    versions={x:v+(1 if accept and x in invalid else 0) for x,v in d['versions'].items()}
    focus=d['focus']
    selected=d['selected']
    expanded=sorted(set(d['expanded'])|({d['target']} if accept and d['reveal'] else set()))
    return [parent,depths,old_children,new_children,invalid,versions,focus,selected,expanded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 2: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 3: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 4: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 5: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])]}
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):
    accept=d['target'] not in d['closure'] and not d['readonly']
    parent=d['target']
    delta=d['target_depth']+1-d['depths'][d['root']]
    depths={x:(v+delta if accept and x in d['closure'] else v) for x,v in d['depths'].items()}
    old_children=[x for x in d['old_children'] if not(accept and x==d['root'])]
    new_children=d['new_children'][:d['position']]+[d['root']]+d['new_children'][d['position']:] if accept else d['new_children']
    invalid=sorted(set([d['old_parent'],d['target']])) if accept else []
    versions={x:v+(1 if accept and x in invalid else 0) for x,v in d['versions'].items()}
    focus=d['focus']
    selected=d['selected']
    expanded=sorted(set(d['expanded'])|({d['target']} if accept and d['reveal'] else set()))
    return [parent,depths,old_children,new_children,invalid,versions,focus,selected,expanded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 2, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 2, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 3, 'c': 4, 'q': 2, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 2: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 3, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 3, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 4, 'c': 5, 'q': 3, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 3: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 4, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 4, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 5, 'c': 6, 'q': 4, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 4: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 5, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 5, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 6, 'c': 7, 'q': 5, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])], 5: [('accepted', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('descendant target', {'target': 'c', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('protected target', {'target': 'q', 'closure': ['b', 'c'], 'readonly': True, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['r', {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, ['a', 'b', 'z'], ['x', 'y'], [], {'r': 3, 'q': 7, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('no reveal', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 1, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': False}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'b', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['r']]), ('insert first', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 0, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'c', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['b', 'x', 'y'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'c', ['c', 'a'], ['q', 'r']]), ('insert last', {'target': 'q', 'closure': ['b', 'c'], 'readonly': False, 'root': 'b', 'old_parent': 'r', 'target_depth': 6, 'depths': {'r': 0, 'b': 1, 'c': 2, 'q': 6, 'outside': 0}, 'old_children': ['a', 'b', 'z'], 'new_children': ['x', 'y'], 'position': 2, 'versions': {'r': 3, 'q': 7, 'outside': 8}, 'focus': 'outside', 'selected': ['c', 'a'], 'expanded': ['r'], 'reveal': True}, ['q', {'r': 0, 'b': 7, 'c': 8, 'q': 6, 'outside': 0}, ['a', 'z'], ['x', 'y', 'b'], ['q', 'r'], {'r': 4, 'q': 8, 'outside': 8}, 'outside', ['c', 'a'], ['q', 'r']])]}
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:
Moved root retains its old accessible parent produces the wrong hierarchical widget state in a regression fixture.

The closure contains a moved subtree and the source and destination are distinct parents. Reject drops into that closure or a read-only destination. Accepted moves replace the root parent, shift every descendant level by the parent-depth delta, invalidate sibling metadata, retain ID-based selection and focus, and increment only affected parent versions.

split: open-access