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

N = 1
observations = []
def solve(d):
    owned=d['transaction']==d['current_transaction'] and d['written_version']==d['current_version']
    rollback=owned and not d['success']
    parent=d['old_parent'] if rollback else d['new_parent']
    source=[]
    if rollback: source=source[:d['old_index']]+[d['root']]+source[d['old_index']:]
    target=[x for x in d['target'] if not(rollback and x==d['root'])]
    levels={x:v-d['delta'] if rollback and x in d['closure'] else v for x,v in d['levels'].items()}
    focus=d['old_focus'] if rollback and d['focus']==d['owned_focus'] else d['focus']
    selection=d['selected']
    status='rolled-back' if rollback else ('committed' if owned and d['success'] else 'superseded')
    return [parent,source,target,levels,focus,selection,status]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 2: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 3: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 4: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 5: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 6, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])]}
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):
    owned=d['transaction']==d['current_transaction'] and d['written_version']==d['current_version']
    rollback=owned and not d['success']
    parent=d['old_parent'] if rollback else d['new_parent']
    source=[d['root']]
    if rollback: source=source[:d['old_index']]+[d['root']]+source[d['old_index']:]
    target=[x for x in d['target'] if not(rollback and x==d['root'])]
    levels={x:v-d['delta'] if rollback and x in d['closure'] else v for x,v in d['levels'].items()}
    focus=d['old_focus'] if rollback and d['focus']==d['owned_focus'] else d['focus']
    selection=d['selected']
    status='rolled-back' if rollback else ('committed' if owned and d['success'] else 'superseded')
    return [parent,source,target,levels,focus,selection,status]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 2: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 3: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 4: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 5: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 6, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])]}
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:
Rollback source reconstruction discards surviving siblings produces the wrong hierarchical widget state in a regression fixture.

A failed optimistic move may roll back only while the current parent version and transaction ID match its write. Restore the subtree root at its original sibling position, restore descendant levels by inverse delta, preserve later unrelated selection, and recover focus only if the optimistic move owned it.

split: open-access


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

N = 1
observations = []
def solve(d):
    owned=d['transaction']==d['current_transaction'] and d['written_version']==d['current_version']
    rollback=owned and not d['success']
    parent=d['old_parent'] if rollback else d['new_parent']
    source=list(d['source'])
    if rollback: source=source+[d['root']]
    target=[x for x in d['target'] if not(rollback and x==d['root'])]
    levels={x:v-d['delta'] if rollback and x in d['closure'] else v for x,v in d['levels'].items()}
    focus=d['old_focus'] if rollback and d['focus']==d['owned_focus'] else d['focus']
    selection=d['selected']
    status='rolled-back' if rollback else ('committed' if owned and d['success'] else 'superseded')
    return [parent,source,target,levels,focus,selection,status]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 2: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 3: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 4: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 5: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 6, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])]}
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):
    owned=d['transaction']==d['current_transaction'] and d['written_version']==d['current_version']
    rollback=owned and not d['success']
    parent=d['old_parent'] if rollback else d['new_parent']
    source=list(d['source'])
    if rollback: source=[d['root']]+source
    target=[x for x in d['target'] if not(rollback and x==d['root'])]
    levels={x:v-d['delta'] if rollback and x in d['closure'] else v for x,v in d['levels'].items()}
    focus=d['old_focus'] if rollback and d['focus']==d['owned_focus'] else d['focus']
    selection=d['selected']
    status='rolled-back' if rollback else ('committed' if owned and d['success'] else 'superseded')
    return [parent,source,target,levels,focus,selection,status]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 3, 'c': 4, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 1, 'current_version': 1, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 2, 'closure': ['b', 'c'], 'levels': {'b': 3, 'c': 4, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 2: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 4, 'c': 5, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 2, 'current_version': 2, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 3, 'closure': ['b', 'c'], 'levels': {'b': 4, 'c': 5, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 3: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 5, 'c': 6, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 3, 'current_version': 3, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 4, 'closure': ['b', 'c'], 'levels': {'b': 5, 'c': 6, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 4: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 6, 'c': 7, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 4, 'current_version': 4, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 5, 'closure': ['b', 'c'], 'levels': {'b': 6, 'c': 7, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])], 5: [('owned failure', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('success', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': True, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'committed']), ('new transaction', {'transaction': 't', 'current_transaction': 'new', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('new parent version', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 6, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['q', ['a', 'z'], ['x', 'b', 'y'], {'b': 7, 'c': 8, 'outside': 0}, 'b', ['c', 'outside'], 'superseded']), ('outside focus', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 1, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'outside', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'b', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'outside', ['c', 'outside'], 'rolled-back']), ('original first', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 0, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['b', 'a', 'z'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back']), ('original last', {'transaction': 't', 'current_transaction': 't', 'written_version': 5, 'current_version': 5, 'success': False, 'old_parent': 'r', 'new_parent': 'q', 'source': ['a', 'z'], 'target': ['x', 'b', 'y'], 'root': 'b', 'old_index': 2, 'delta': 6, 'closure': ['b', 'c'], 'levels': {'b': 7, 'c': 8, 'outside': 0}, 'old_focus': 'c', 'focus': 'b', 'owned_focus': 'b', 'selected': ['c', 'outside'], 'old_selected': ['b']}, ['r', ['a', 'z', 'b'], ['x', 'y'], {'b': 1, 'c': 2, 'outside': 0}, 'c', ['c', 'outside'], 'rolled-back'])]}
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:
Rolled-back root returns at wrong sibling index produces the wrong hierarchical widget state in a regression fixture.

A failed optimistic move may roll back only while the current parent version and transaction ID match its write. Restore the subtree root at its original sibling position, restore descendant levels by inverse delta, preserve later unrelated selection, and recover focus only if the optimistic move owned it.

split: open-access