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

N = 1
observations = []
def solve(d):
    valid=bool(d['journal']) and d['journal'][-1]['generation']==d['generation']
    entry=d['journal'][-1] if valid else None
    restored=set(entry['before'])&set(d['branches']) if valid else set(d['open'])
    forced=set(d['filter_open'])|set(d['load_open'])
    effective=restored|forced
    journal=d['journal'][1:]
    redo=d['redo']+[entry] if valid else d['redo']
    visible=[x for x in d['rows'] if all(a in effective for a in d['ancestors'].get(x,[]))]
    candidate=entry['focus'] if valid else d['focus']
    focus=candidate if candidate in visible else (visible[0] if visible else None)
    return [sorted(restored),sorted(effective),journal,redo,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('undo latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 0, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 1, 'journal': [{'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 2: [('undo latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 2, 'journal': [{'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 3: [('undo latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 3, 'journal': [{'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 4: [('undo latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 4, 'journal': [{'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 5: [('undo latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 5, 'journal': [{'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])]}
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):
    valid=bool(d['journal']) and d['journal'][-1]['generation']==d['generation']
    entry=d['journal'][-1] if valid else None
    restored=set(entry['before'])&set(d['branches']) if valid else set(d['open'])
    forced=set(d['filter_open'])|set(d['load_open'])
    effective=restored|forced
    journal=d['journal']
    redo=d['redo']+[entry] if valid else d['redo']
    visible=[x for x in d['rows'] if all(a in effective for a in d['ancestors'].get(x,[]))]
    candidate=entry['focus'] if valid else d['focus']
    focus=candidate if candidate in visible else (visible[0] if visible else None)
    return [sorted(restored),sorted(effective),journal,redo,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('undo latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 0, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 1, 'journal': [{'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 2: [('undo latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 2, 'journal': [{'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 3: [('undo latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 3, 'journal': [{'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 4: [('undo latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 4, 'journal': [{'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 5: [('undo latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 5, 'journal': [{'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])]}
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:
Undo pops the wrong journal end produces the wrong hierarchical widget state in a regression fixture.

Undo restores the prior expansion set only for surviving branches. Non-undoable loading and filter expansions remain separate. Journal entries belong to a tree generation; stale generations are discarded. Focus restored from journal must be visible under restored expansion.

split: open-access


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

N = 1
observations = []
def solve(d):
    valid=bool(d['journal']) and d['journal'][-1]['generation']==d['generation']
    entry=d['journal'][-1] if valid else None
    restored=set(entry['before'])&set(d['branches']) if valid else set(d['open'])
    forced=set(d['filter_open'])|set(d['load_open'])
    effective=restored|forced
    journal=d['journal'][:-1] if d['journal'] else []
    redo=[entry] if valid else d['redo']
    visible=[x for x in d['rows'] if all(a in effective for a in d['ancestors'].get(x,[]))]
    candidate=entry['focus'] if valid else d['focus']
    focus=candidate if candidate in visible else (visible[0] if visible else None)
    return [sorted(restored),sorted(effective),journal,redo,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('undo latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 0, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 1, 'journal': [{'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 2: [('undo latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 2, 'journal': [{'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 3: [('undo latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 3, 'journal': [{'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 4: [('undo latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 4, 'journal': [{'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 5: [('undo latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 5, 'journal': [{'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])]}
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):
    valid=bool(d['journal']) and d['journal'][-1]['generation']==d['generation']
    entry=d['journal'][-1] if valid else None
    restored=set(entry['before'])&set(d['branches']) if valid else set(d['open'])
    forced=set(d['filter_open'])|set(d['load_open'])
    effective=restored|forced
    journal=d['journal'][:-1] if d['journal'] else []
    redo=d['redo']
    visible=[x for x in d['rows'] if all(a in effective for a in d['ancestors'].get(x,[]))]
    candidate=entry['focus'] if valid else d['focus']
    focus=candidate if candidate in visible else (visible[0] if visible else None)
    return [sorted(restored),sorted(effective),journal,redo,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('undo latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 0, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 1, 'journal': [{'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 2: [('undo latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 2, 'journal': [{'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 3: [('undo latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 3, 'journal': [{'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 4: [('undo latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 4, 'journal': [{'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 5: [('undo latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 5, 'journal': [{'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])]}
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:
Undo loses existing redo transactions produces the wrong hierarchical widget state in a regression fixture.

Undo restores the prior expansion set only for surviving branches. Non-undoable loading and filter expansions remain separate. Journal entries belong to a tree generation; stale generations are discarded. Focus restored from journal must be visible under restored expansion.

split: open-access


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

N = 1
observations = []
def solve(d):
    valid=bool(d['journal']) and d['journal'][-1]['generation']==d['generation']
    entry=d['journal'][-1] if valid else None
    restored=set(entry['before'])&set(d['branches']) if valid else set(d['open'])
    forced=set(d['filter_open'])|set(d['load_open'])
    effective=restored|forced
    journal=d['journal'][:-1] if d['journal'] else []
    redo=d['redo']+[entry] if valid else d['redo']
    visible=[x for x in d['rows'] if all(a in restored for a in d['ancestors'].get(x,[]))]
    candidate=entry['focus'] if valid else d['focus']
    focus=candidate if candidate in visible else (visible[0] if visible else None)
    return [sorted(restored),sorted(effective),journal,redo,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('undo latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 0, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 1, 'journal': [{'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 2: [('undo latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 2, 'journal': [{'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 3: [('undo latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 3, 'journal': [{'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 4: [('undo latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 4, 'journal': [{'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 5: [('undo latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 5, 'journal': [{'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])]}
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):
    valid=bool(d['journal']) and d['journal'][-1]['generation']==d['generation']
    entry=d['journal'][-1] if valid else None
    restored=set(entry['before'])&set(d['branches']) if valid else set(d['open'])
    forced=set(d['filter_open'])|set(d['load_open'])
    effective=restored|forced
    journal=d['journal'][:-1] if d['journal'] else []
    redo=d['redo']+[entry] if valid else d['redo']
    visible=[x for x in d['rows'] if True]
    candidate=entry['focus'] if valid else d['focus']
    focus=candidate if candidate in visible else (visible[0] if visible else None)
    return [sorted(restored),sorted(effective),journal,redo,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('undo latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 0, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 1, 'journal': [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 1, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 1, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 1, 'journal': [{'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 1, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 1, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 2: [('undo latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 1, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 2, 'journal': [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 2, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 2, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 2, 'journal': [{'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 2, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 2, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 3: [('undo latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 2, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 3, 'journal': [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 3, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 3, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 3, 'journal': [{'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 3, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 3, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 4: [('undo latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 3, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 4, 'journal': [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 4, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 4, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 4, 'journal': [{'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 4, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 4, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])], 5: [('undo latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'q', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q', 's'], 'b']), ('stale latest', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 4, 'before': ['a'], 'after': [], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}], ['r', 'q', 's'], 's']), ('no journal', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 's']), ('no forced', {'generation': 5, 'journal': [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [['a', 'r'], ['a', 'r'], [{'generation': 5, 'before': ['r'], 'after': ['a'], 'focus': 'r'}], [{'old': True}, {'generation': 5, 'before': ['r', 'a', 'gone'], 'after': ['r'], 'focus': 'b'}], ['r', 'a', 'b', 'q'], 'b']), ('hidden journal focus', {'generation': 5, 'journal': [{'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': [], 'load_open': [], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 's'}, [[], [], [], [{'old': True}, {'generation': 5, 'before': [], 'after': ['r'], 'focus': 'b'}], ['r', 'q'], 'r']), ('outside focus', {'generation': 5, 'journal': [], 'branches': ['r', 'a', 'q'], 'open': ['q'], 'filter_open': ['q'], 'load_open': ['a'], 'redo': [{'old': True}], 'rows': ['r', 'a', 'b', 'q', 's'], 'ancestors': {'a': ['r'], 'b': ['r', 'a'], 's': ['q']}, 'focus': 'q'}, [['q'], ['a', 'q'], [], [{'old': True}], ['r', 'q', 's'], 'q'])]}
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:
Undo focus visibility ignores forced or closed ancestry produces the wrong hierarchical widget state in a regression fixture.

Undo restores the prior expansion set only for surviving branches. Non-undoable loading and filter expansions remain separate. Journal entries belong to a tree generation; stale generations are discarded. Focus restored from journal must be visible under restored expansion.

split: open-access