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

N = 1
observations = []
def solve(d):
    allowed=d['target'] in d['branches'] and d['target'] not in d['disabled']
    siblings=[x for x in d['branches'] if x!=d['target'] and d['parents'].get(x)==d['parents'].get(d['target'])]
    closed_roots=set(siblings) if allowed and d['exclusive'] else set()
    closed={x for x in d['open'] if x in closed_roots or any(a in closed_roots for a in d['ancestors'].get(x,[]))}
    expanded=({d['target']} if allowed else set())
    focusroot=next((a for a in d['ancestors'].get(d['focus'],[]) if a in closed_roots),None)
    focus=focusroot if focusroot is not None else d['focus']
    changed=sorted(expanded^set(d['open']))
    state={x:x in expanded for x in d['branches']}
    leaf_focus=d['focus'] not in d['branches']
    return [sorted(expanded),focus,changed,state,leaf_focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False}, True])], 2: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False}, True])], 3: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False}, True])], 4: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, True])], 5: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    allowed=d['target'] in d['branches'] and d['target'] not in d['disabled']
    siblings=[x for x in d['branches'] if x!=d['target'] and d['parents'].get(x)==d['parents'].get(d['target'])]
    closed_roots=set(siblings) if allowed and d['exclusive'] else set()
    closed={x for x in d['open'] if x in closed_roots or any(a in closed_roots for a in d['ancestors'].get(x,[]))}
    expanded=set(d['open'])|({d['target']} if allowed else set())
    focusroot=next((a for a in d['ancestors'].get(d['focus'],[]) if a in closed_roots),None)
    focus=focusroot if focusroot is not None else d['focus']
    changed=sorted(expanded^set(d['open']))
    state={x:x in expanded for x in d['branches']}
    leaf_focus=d['focus'] not in d['branches']
    return [sorted(expanded),focus,changed,state,leaf_focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False}, True])], 2: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False}, True])], 3: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False}, True])], 4: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, True])], 5: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Exclusive expansion drops unrelated branches or fails to close siblings produces the wrong hierarchical widget state in a regression fixture.

Expanding a branch in exclusive mode closes its sibling branches and their descendants, but leaves ancestor and unrelated branch expansion intact. Expansion of disabled or leaf nodes is ignored. Focus within a newly closed sibling moves to that sibling root. Manual expansion survives later mode-off operation. Report whether pre-operation focus was a terminal row as provenance.

split: open-access


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

N = 1
observations = []
def solve(d):
    allowed=d['target'] in d['branches'] and d['target'] not in d['disabled']
    siblings=[x for x in d['branches'] if x!=d['target'] and d['parents'].get(x)==d['parents'].get(d['target'])]
    closed_roots=set(siblings) if allowed and d['exclusive'] else set()
    closed={x for x in d['open'] if x in closed_roots or any(a in closed_roots for a in d['ancestors'].get(x,[]))}
    expanded=(set(d['open'])-closed)|({d['target']} if allowed else set())
    focusroot=next((a for a in reversed(d['ancestors'].get(d['focus'],[])) if a in closed),None)
    focus=focusroot if focusroot is not None else d['focus']
    changed=sorted(expanded^set(d['open']))
    state={x:x in expanded for x in d['branches']}
    leaf_focus=d['focus'] not in d['branches']
    return [sorted(expanded),focus,changed,state,leaf_focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False}, True])], 2: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False}, True])], 3: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False}, True])], 4: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, True])], 5: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(d):
    allowed=d['target'] in d['branches'] and d['target'] not in d['disabled']
    siblings=[x for x in d['branches'] if x!=d['target'] and d['parents'].get(x)==d['parents'].get(d['target'])]
    closed_roots=set(siblings) if allowed and d['exclusive'] else set()
    closed={x for x in d['open'] if x in closed_roots or any(a in closed_roots for a in d['ancestors'].get(x,[]))}
    expanded=(set(d['open'])-closed)|({d['target']} if allowed else set())
    focusroot=next((a for a in [] if a in closed),None)
    focus=focusroot if focusroot is not None else d['focus']
    changed=sorted(expanded^set(d['open']))
    state={x:x in expanded for x in d['branches']}
    leaf_focus=d['focus'] not in d['branches']
    return [sorted(expanded),focus,changed,state,leaf_focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False}, True])], 2: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False}, True])], 3: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False}, True])], 4: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, True])], 5: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Focus recovery selects a hidden descendant branch produces the wrong hierarchical widget state in a regression fixture.

Expanding a branch in exclusive mode closes its sibling branches and their descendants, but leaves ancestor and unrelated branch expansion intact. Expansion of disabled or leaf nodes is ignored. Focus within a newly closed sibling moves to that sibling root. Manual expansion survives later mode-off operation. Report whether pre-operation focus was a terminal row as provenance.

split: open-access


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

N = 1
observations = []
def solve(d):
    allowed=d['target'] in d['branches'] and d['target'] not in d['disabled']
    siblings=[x for x in d['branches'] if x!=d['target'] and d['parents'].get(x)==d['parents'].get(d['target'])]
    closed_roots=set(siblings) if allowed and d['exclusive'] else set()
    closed={x for x in d['open'] if x in closed_roots or any(a in closed_roots for a in d['ancestors'].get(x,[]))}
    expanded=(set(d['open'])-closed)|({d['target']} if allowed else set())
    focusroot=next((a for a in d['ancestors'].get(d['focus'],[]) if a in closed_roots),None)
    focus=d['target'] if closed else d['focus']
    changed=sorted(expanded^set(d['open']))
    state={x:x in expanded for x in d['branches']}
    leaf_focus=d['focus'] not in d['branches']
    return [sorted(expanded),focus,changed,state,leaf_focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False}, True])], 2: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False}, True])], 3: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False}, True])], 4: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, True])], 5: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    allowed=d['target'] in d['branches'] and d['target'] not in d['disabled']
    siblings=[x for x in d['branches'] if x!=d['target'] and d['parents'].get(x)==d['parents'].get(d['target'])]
    closed_roots=set(siblings) if allowed and d['exclusive'] else set()
    closed={x for x in d['open'] if x in closed_roots or any(a in closed_roots for a in d['ancestors'].get(x,[]))}
    expanded=(set(d['open'])-closed)|({d['target']} if allowed else set())
    focusroot=next((a for a in d['ancestors'].get(d['focus'],[]) if a in closed_roots),None)
    focus=d['focus']
    changed=sorted(expanded^set(d['open']))
    state={x:x in expanded for x in d['branches']}
    leaf_focus=d['focus'] not in d['branches']
    return [sorted(expanded),focus,changed,state,leaf_focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False}, True])], 2: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False}, True])], 3: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False}, True])], 4: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False}, True])], 5: [('close sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('mode off', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': False, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'b', 'bb', 'q', 'r'], 'c', ['a'], {'r': True, 'a': True, 'b': True, 'bb': True, 'q': True}, True]), ('disabled target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': ['a'], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('leaf target', {'target': 'c', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['b', 'bb', 'q', 'r'], 'c', [], {'r': True, 'a': False, 'b': True, 'bb': True, 'q': True}, True]), ('unrelated focus', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'q'}, [['a', 'q', 'r'], 'q', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, False]), ('already open target', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'a', 'b', 'bb', 'q', 'aa'], 'ancestors': {'aa': ['r', 'a'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'aa', 'q', 'r'], 'b', ['b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True}, True]), ('deeper varying sibling', {'target': 'a', 'branches': ['r', 'a', 'b', 'bb', 'q', 'v0', 'v1', 'v2', 'v3', 'v4'], 'disabled': [], 'parents': {'r': None, 'a': 'r', 'b': 'r', 'bb': 'b', 'q': None}, 'exclusive': True, 'open': ['r', 'b', 'bb', 'q'], 'ancestors': {'a': ['r'], 'b': ['r'], 'bb': ['r', 'b'], 'c': ['r', 'b', 'bb']}, 'focus': 'c'}, [['a', 'q', 'r'], 'b', ['a', 'b', 'bb'], {'r': True, 'a': True, 'b': False, 'bb': False, 'q': True, 'v0': False, 'v1': False, 'v2': False, 'v3': False, 'v4': False}, True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Sibling collapse steals focus to newly expanded branch produces the wrong hierarchical widget state in a regression fixture.

Expanding a branch in exclusive mode closes its sibling branches and their descendants, but leaves ancestor and unrelated branch expansion intact. Expansion of disabled or leaf nodes is ignored. Focus within a newly closed sibling moves to that sibling root. Manual expansion survives later mode-off operation. Report whether pre-operation focus was a terminal row as provenance.

split: open-access