FAILURE MAP
← Case archive

FA-38566 / Tree accessibility / Open access

Persisted hierarchical expansion restoration: Restored selection retains disabled or missing rows · case 01

Restored selection retains disabled or missing rows produces the wrong hierarchical widget state in a regression fixture.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The expansion-restore contract is violated at `valid and x in d['present'] and x not in d['disabled']` by replacing it with `valid and x in d['present']`.

VERIFIED REPAIR

Restore `valid and x in d['present'] and x not in d['disabled']` at this fault site while retaining the other tree state decisions.

Unsuccessful approach: The partial repair `valid and x not in d['disabled']` still violates a boundary or preservation case.

Case contract

Only present branch IDs may be restored. Ancestors of restored open branches are opened unless explicitly blocked. Selection and focus restore independently: selection keeps present enabled rows; hidden focus falls back to nearest visible ancestor. The persisted root instance must match.

Why this case matters

Offline executable model of a hierarchical accessibility interaction; inputs are bounded and valid as stipulated. No browser, assistive technology, or normative ARIA conformance is claimed.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(d):
    valid=d['saved_tree']==d['tree']
    wanted=set(d['saved_open']) if valid else set()
    branches=wanted & set(d['branches'])
    ancestors={a for x in branches for a in d['ancestors'].get(x,[])}
    expanded=(branches|ancestors)-set(d['blocked'])
    selected=[x for x in d['saved_selected'] if valid and x in d['present']]
    visible=[x for x in d['present'] if all(a in expanded for a in d['ancestors'].get(x,[]))]
    candidate=d['saved_focus'] if valid else None
    fallback=next((a for a in reversed(d['ancestors'].get(candidate,[])) if a in visible),None)
    focus=candidate if candidate in visible else (fallback if fallback is not None else (visible[0] if visible else None))
    return [sorted(expanded),selected,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'])], 2: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1'], 'leaf'])], 3: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2'], 'leaf'])], 4: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3'], 'leaf'])], 5: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3', 'v4'], 'leaf'])]}
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)
Boundary fixtureActualExpectedOutcome
deep saved[['a', 'b', 'r'], ['leaf', 'a'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']Failed
deep branch alone[['a', 'b', 'r'], ['leaf', 'a'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']Failed
foreign snapshot[[], [], ['r', 'other'], 'r'][[], [], ['r', 'other'], 'r']Passed
blocked middle[['a', 'r'], ['leaf', 'a'], ['r', 'a', 'b', 'other'], 'b'][['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']Failed
blocked root[['a', 'b'], ['leaf', 'a'], ['r', 'other'], 'r'][['a', 'b'], ['leaf'], ['r', 'other'], 'r']Failed
no saved branch[[], ['leaf', 'a'], ['r', 'other'], 'r'][[], ['leaf'], ['r', 'other'], 'r']Failed
missing focus[['a', 'b', 'r'], ['leaf', 'a'], ['r', 'a', 'b', 'leaf', 'other'], 'r'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']Failed
deep varying chain[['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf']Passed

SHA-256 / 0c5f5b70a8c70b7e3817efc51c769b1682f924c467635b5fe644ac49f6832818

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(d):
    valid=d['saved_tree']==d['tree']
    wanted=set(d['saved_open']) if valid else set()
    branches=wanted & set(d['branches'])
    ancestors={a for x in branches for a in d['ancestors'].get(x,[])}
    expanded=(branches|ancestors)-set(d['blocked'])
    selected=[x for x in d['saved_selected'] if valid and x not in d['disabled']]
    visible=[x for x in d['present'] if all(a in expanded for a in d['ancestors'].get(x,[]))]
    candidate=d['saved_focus'] if valid else None
    fallback=next((a for a in reversed(d['ancestors'].get(candidate,[])) if a in visible),None)
    focus=candidate if candidate in visible else (fallback if fallback is not None else (visible[0] if visible else None))
    return [sorted(expanded),selected,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'])], 2: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1'], 'leaf'])], 3: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2'], 'leaf'])], 4: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3'], 'leaf'])], 5: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3', 'v4'], 'leaf'])]}
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)
Boundary fixtureActualExpectedOutcome
deep saved[['a', 'b', 'r'], ['leaf', 'gone'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']Failed
deep branch alone[['a', 'b', 'r'], ['leaf', 'gone'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']Failed
foreign snapshot[[], [], ['r', 'other'], 'r'][[], [], ['r', 'other'], 'r']Passed
blocked middle[['a', 'r'], ['leaf', 'gone'], ['r', 'a', 'b', 'other'], 'b'][['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']Failed
blocked root[['a', 'b'], ['leaf', 'gone'], ['r', 'other'], 'r'][['a', 'b'], ['leaf'], ['r', 'other'], 'r']Failed
no saved branch[[], ['leaf', 'gone'], ['r', 'other'], 'r'][[], ['leaf'], ['r', 'other'], 'r']Failed
missing focus[['a', 'b', 'r'], ['leaf', 'gone'], ['r', 'a', 'b', 'leaf', 'other'], 'r'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']Failed
deep varying chain[['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf']Passed

SHA-256 / 3d4e81dfcb43b684e07cb5e136c73042e62ca39496f18120b06121fdb6777491

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(d):
    valid=d['saved_tree']==d['tree']
    wanted=set(d['saved_open']) if valid else set()
    branches=wanted & set(d['branches'])
    ancestors={a for x in branches for a in d['ancestors'].get(x,[])}
    expanded=(branches|ancestors)-set(d['blocked'])
    selected=[x for x in d['saved_selected'] if valid and x in d['present'] and x not in d['disabled']]
    visible=[x for x in d['present'] if all(a in expanded for a in d['ancestors'].get(x,[]))]
    candidate=d['saved_focus'] if valid else None
    fallback=next((a for a in reversed(d['ancestors'].get(candidate,[])) if a in visible),None)
    focus=candidate if candidate in visible else (fallback if fallback is not None else (visible[0] if visible else None))
    return [sorted(expanded),selected,visible,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'])], 2: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1'], 'leaf'])], 3: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2'], 'leaf'])], 4: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3'], 'leaf'])], 5: [('deep saved', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('deep branch alone', {'saved_tree': 't', 'tree': 't', 'saved_open': ['b'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']), ('foreign snapshot', {'saved_tree': 'other', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'other'}, [[], [], ['r', 'other'], 'r']), ('blocked middle', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['b'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']), ('blocked root', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': ['r'], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b'], ['leaf'], ['r', 'other'], 'r']), ('no saved branch', {'saved_tree': 't', 'tree': 't', 'saved_open': [], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [[], ['leaf'], ['r', 'other'], 'r']), ('missing focus', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf', 'gone', 'a'], 'present': ['r', 'a', 'b', 'leaf', 'other'], 'disabled': ['a'], 'saved_focus': 'gone'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']), ('deep varying chain', {'saved_tree': 't', 'tree': 't', 'saved_open': ['a', 'b', 'leaf', 'gone'], 'branches': ['r', 'a', 'b'], 'ancestors': {'r': [], 'a': ['r'], 'b': ['r', 'a'], 'leaf': ['r', 'a', 'b'], 'other': []}, 'blocked': [], 'saved_selected': ['leaf'], 'present': ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': ['a'], 'saved_focus': 'leaf'}, [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0', 'v1', 'v2', 'v3', 'v4'], 'leaf'])]}
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)
Boundary fixtureActualExpectedOutcome
deep saved[['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']Passed
deep branch alone[['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf']Passed
foreign snapshot[[], [], ['r', 'other'], 'r'][[], [], ['r', 'other'], 'r']Passed
blocked middle[['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b'][['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b']Passed
blocked root[['a', 'b'], ['leaf'], ['r', 'other'], 'r'][['a', 'b'], ['leaf'], ['r', 'other'], 'r']Passed
no saved branch[[], ['leaf'], ['r', 'other'], 'r'][[], ['leaf'], ['r', 'other'], 'r']Passed
missing focus[['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r']Passed
deep varying chain[['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'][['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf']Passed

SHA-256 / bc4505aa47e30ddeb3b16427c618a7a81e08add271343ca2484643471ae3d28d

Verification & scope

Synthetic deterministic hierarchical-widget data contract; not an implementation of a browser accessibility tree. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:43:12.537533+00:00.

Case digest / 148b4ab5b2c892547b60eea7e140628cb6960798670b943c84a8fbd841a99319