FA-38546 / Tree accessibility / Open access
Persisted hierarchical expansion restoration: Restoration reads selection or only first expansion · case 01
Restoration reads selection or only first expansion produces the wrong hierarchical widget state in a regression fixture.
ROOT CAUSE
The expansion-restore contract is violated at `set(d['saved_open']) if valid else set()` by replacing it with `set(d['saved_selected']) if valid else set()`.
VERIFIED REPAIR
Restore `set(d['saved_open']) if valid else set()` at this fault site while retaining the other tree state decisions.
Unsuccessful approach: The partial repair `set(d['saved_open'][:1]) if valid else set()` 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_selected']) 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| deep saved | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b'] | [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'] | Failed |
| deep branch alone | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b'] | [['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'], ['r', 'a', 'b', 'other'], 'b'] | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b'] | Passed |
| blocked root | [['a'], ['leaf'], ['r', 'other'], 'r'] | [['a', 'b'], ['leaf'], ['r', 'other'], 'r'] | Failed |
| no saved branch | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b'] | [[], ['leaf'], ['r', 'other'], 'r'] | Failed |
| missing focus | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'r'] | [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r'] | Failed |
| deep varying chain | [[], ['leaf'], ['r', 'other', 'v0'], 'r'] | [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'] | Failed |
SHA-256 / db6ea32a8aef33c6796777019512220797527245e699b57e12151bcff4a3f8b5
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'][:1]) 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| deep saved | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'b'] | [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'leaf'] | Failed |
| 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'], ['leaf'], ['r', 'other'], 'r'] | [['a', 'b'], ['leaf'], ['r', 'other'], 'r'] | Failed |
| no saved branch | [[], ['leaf'], ['r', 'other'], 'r'] | [[], ['leaf'], ['r', 'other'], 'r'] | Passed |
| missing focus | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other'], 'r'] | [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other'], 'r'] | Failed |
| deep varying chain | [['a', 'r'], ['leaf'], ['r', 'a', 'b', 'other', 'v0'], 'b'] | [['a', 'b', 'r'], ['leaf'], ['r', 'a', 'b', 'leaf', 'other', 'v0'], 'leaf'] | Failed |
SHA-256 / 015f7eefb1a237387c15c449f983d58cca73a908fd7b622d07f51b150f576ac7
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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.278871+00:00.
Case digest / ffb807c6fba2d1d4f6d17231260dc0253c060894af439a255dd59aa8fd9766a1