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

N = 1
observations = []
def solve(d):
    new=list(dict.fromkeys(d['incoming']))
    removed_roots=set(d['old'])
    removed={x for x in d['rows'] if x in removed_roots or any(a in removed_roots for a in d['ancestors'].get(x,[]))}
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    cache={x:v for x,v in d['cache'].items() if x not in removed}
    focus=d['parent'] if d['focus'] in removed else d['focus']
    edit=None if d['edit'] in removed else d['edit']
    added=[x for x in new if x not in d['old']]
    versions={x:(d['revision'] if x==d['parent'] else v) for x,v in d['versions'].items()}
    return [new,sorted(removed),selected,expanded,cache,focus,edit,added,versions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('removed child', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0'], {'r': 6, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 6, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 6, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 6, 'outside': 2}])], 2: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 7, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 7, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 7, 'outside': 2}])], 3: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 8, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 8, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 8, 'outside': 2}])], 4: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 9, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 9, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 9, 'outside': 2}])], 5: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 10, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 10, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 10, 'outside': 2}])]}
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):
    new=list(dict.fromkeys(d['incoming']))
    removed_roots=set(new)-set(d['old'])
    removed={x for x in d['rows'] if x in removed_roots or any(a in removed_roots for a in d['ancestors'].get(x,[]))}
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    cache={x:v for x,v in d['cache'].items() if x not in removed}
    focus=d['parent'] if d['focus'] in removed else d['focus']
    edit=None if d['edit'] in removed else d['edit']
    added=[x for x in new if x not in d['old']]
    versions={x:(d['revision'] if x==d['parent'] else v) for x,v in d['versions'].items()}
    return [new,sorted(removed),selected,expanded,cache,focus,edit,added,versions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('removed child', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0'], {'r': 6, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 6, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 6, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 6, 'outside': 2}])], 2: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 7, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 7, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 7, 'outside': 2}])], 3: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 8, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 8, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 8, 'outside': 2}])], 4: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 9, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 9, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 9, 'outside': 2}])], 5: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 10, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 10, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 10, 'outside': 2}])]}
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:
Refresh removal set includes surviving or newly added children produces the wrong hierarchical widget state in a regression fixture.

A refresh replaces one branch child list while preserving child identity state for survivors. Removed child closures lose selection, expansion, cached data and edit sessions; descendants of surviving children remain. Fresh child order wins. Focus removed by refresh recovers to the parent; unrelated focus remains.

split: open-access


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

N = 1
observations = []
def solve(d):
    new=list(dict.fromkeys(d['incoming']))
    removed_roots=set(d['old'])-set(new)
    removed={x for x in d['rows'] if x in removed_roots}
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    cache={x:v for x,v in d['cache'].items() if x not in removed}
    focus=d['parent'] if d['focus'] in removed else d['focus']
    edit=None if d['edit'] in removed else d['edit']
    added=[x for x in new if x not in d['old']]
    versions={x:(d['revision'] if x==d['parent'] else v) for x,v in d['versions'].items()}
    return [new,sorted(removed),selected,expanded,cache,focus,edit,added,versions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('removed child', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0'], {'r': 6, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 6, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 6, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 6, 'outside': 2}])], 2: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 7, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 7, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 7, 'outside': 2}])], 3: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 8, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 8, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 8, 'outside': 2}])], 4: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 9, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 9, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 9, 'outside': 2}])], 5: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 10, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 10, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 10, 'outside': 2}])]}
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):
    new=list(dict.fromkeys(d['incoming']))
    removed_roots=set(d['old'])-set(new)
    removed={x for x in d['rows'] if any(a in removed_roots for a in d['ancestors'].get(x,[]))}
    selected=[x for x in d['selected'] if x not in removed]
    expanded=[x for x in d['expanded'] if x not in removed]
    cache={x:v for x,v in d['cache'].items() if x not in removed}
    focus=d['parent'] if d['focus'] in removed else d['focus']
    edit=None if d['edit'] in removed else d['edit']
    added=[x for x in new if x not in d['old']]
    versions={x:(d['revision'] if x==d['parent'] else v) for x,v in d['versions'].items()}
    return [new,sorted(removed),selected,expanded,cache,focus,edit,added,versions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('removed child', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0'], {'r': 6, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z', 'a', 'v0'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0'], {'r': 6, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 6, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 6, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 6}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 6, 'outside': 2}])], 2: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z', 'a', 'v0', 'v1'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1'], {'r': 7, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 7, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 7, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 7}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 7, 'outside': 2}])], 3: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z', 'a', 'v0', 'v1', 'v2'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2'], {'r': 8, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 8, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 8, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 8}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 8, 'outside': 2}])], 4: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z', 'a', 'v0', 'v1', 'v2', 'v3'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3'], {'r': 9, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 9, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 9, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 9}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 9, 'outside': 2}])], 5: [('removed child', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'r', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('surviving focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'aa', 'edit': 'aa', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'aa', 'aa', ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('outside focus', {'incoming': ['z', 'a', 'z', 'v0', 'v1', 'v2', 'v3', 'v4'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'outside', 'edit': None, 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z', 'a', 'v0', 'v1', 'v2', 'v3', 'v4'], ['b', 'bb'], ['aa', 'outside'], ['a'], {'aa': 1, 'outside': 3}, 'outside', None, ['z', 'v0', 'v1', 'v2', 'v3', 'v4'], {'r': 10, 'outside': 2}]), ('empty refresh', {'incoming': [], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [[], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, [], {'r': 10, 'outside': 2}]), ('same children', {'incoming': ['b', 'a'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['b', 'a'], [], ['aa', 'bb', 'outside'], ['a', 'b', 'bb'], {'aa': 1, 'bb': 2, 'outside': 3}, 'bb', 'bb', [], {'r': 10, 'outside': 2}]), ('only new children', {'incoming': ['z'], 'old': ['a', 'b'], 'rows': ['r', 'a', 'aa', 'b', 'bb', 'outside'], 'ancestors': {'a': ['r'], 'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b']}, 'selected': ['aa', 'bb', 'outside'], 'expanded': ['a', 'b', 'bb'], 'cache': {'aa': 1, 'bb': 2, 'outside': 3}, 'focus': 'bb', 'edit': 'bb', 'parent': 'r', 'versions': {'r': 1, 'outside': 2}, 'revision': 10}, [['z'], ['a', 'aa', 'b', 'bb'], ['outside'], [], {'outside': 3}, 'r', None, ['z'], {'r': 10, 'outside': 2}])]}
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:
Refresh cleanup misses removed roots or their descendants produces the wrong hierarchical widget state in a regression fixture.

A refresh replaces one branch child list while preserving child identity state for survivors. Removed child closures lose selection, expansion, cached data and edit sessions; descendants of surviving children remain. Fresh child order wins. Focus removed by refresh recovers to the parent; unrelated focus remains.

split: open-access