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

N = 1
observations = []
def solve(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=anchor
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', 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):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=rows[0]
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', 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:
Range selection leaves focus at the anchor produces the wrong hierarchical widget state in a regression fixture.

Selectable rows are the ordered visible preorder supplied in rows; disabled rows cannot be selected. A hidden anchor falls back to focus. Preserve outside selections only for additive ranges. Report focus, anchor, ordered selection, and branch coverage.

split: open-access


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

N = 1
observations = []
def solve(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=d['target']
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', 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):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=rows[0]
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', 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:
Extending a range moves its stable anchor produces the wrong hierarchical widget state in a regression fixture.

Selectable rows are the ordered visible preorder supplied in rows; disabled rows cannot be selected. A hidden anchor falls back to focus. Preserve outside selections only for additive ranges. Report focus, anchor, ordered selection, and branch coverage.

split: open-access


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

N = 1
observations = []
def solve(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=any(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', 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):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', 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:
Empty or partially selected branch is marked covered produces the wrong hierarchical widget state in a regression fixture.

Selectable rows are the ordered visible preorder supplied in rows; disabled rows cannot be selected. A hidden anchor falls back to focus. Preserve outside selections only for additive ranges. Report focus, anchor, ordered selection, and branch coverage.

split: open-access


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

N = 1
observations = []
def solve(d):
    leaves=d['leaves']; disabled=set(d['disabled']); checked=set(d['checked'])
    write=[x for x in leaves if x in disabled]
    target=not all(x in checked for x in write) if write else False
    keep=checked-set(write)
    changed=set(write) if target else set()
    after=keep|changed
    count=sum(x in after for x in write)
    complete=bool(write) and count==len(write) and not d['unknown']
    mixed=count>0 and not complete
    state='true' if complete else ('mixed' if mixed else 'false')
    order=[x for x in d['all'] if x in after]
    changed_ids=[x for x in write if (x in checked)!=(x in after)]
    return [order,state,changed_ids,target]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('partial', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2'], 'true', ['c2'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c2'], 'true', ['c0', 'c2'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2'], 'mixed', ['c2'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c1', 'c2'], 'true', ['c0', 'c2'], True])], 2: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'true', ['c2', 'c3'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'mixed', ['c2', 'c3'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True])], 3: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c2', 'c3', 'c4'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'mixed', ['c2', 'c3', 'c4'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True])], 4: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c2', 'c3', 'c4', 'c5'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'mixed', ['c2', 'c3', 'c4', 'c5'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True])], 5: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'mixed', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 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):
    leaves=d['leaves']; disabled=set(d['disabled']); checked=set(d['checked'])
    write=[x for x in leaves if True]
    target=not all(x in checked for x in write) if write else False
    keep=checked-set(write)
    changed=set(write) if target else set()
    after=keep|changed
    count=sum(x in after for x in write)
    complete=bool(write) and count==len(write) and not d['unknown']
    mixed=count>0 and not complete
    state='true' if complete else ('mixed' if mixed else 'false')
    order=[x for x in d['all'] if x in after]
    changed_ids=[x for x in write if (x in checked)!=(x in after)]
    return [order,state,changed_ids,target]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('partial', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2'], 'true', ['c2'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c2'], 'true', ['c0', 'c2'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2'], 'mixed', ['c2'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c1', 'c2'], 'true', ['c0', 'c2'], True])], 2: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'true', ['c2', 'c3'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'mixed', ['c2', 'c3'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True])], 3: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c2', 'c3', 'c4'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'mixed', ['c2', 'c3', 'c4'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True])], 4: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c2', 'c3', 'c4', 'c5'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'mixed', ['c2', 'c3', 'c4', 'c5'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True])], 5: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'mixed', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 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:
Disabled descendants become writable produces the wrong hierarchical widget state in a regression fixture.

Descendants and leaves are supplied for one branch, without cycles. Toggle writable leaves only. Preserve disabled and unrelated checks; derive parent state from writable leaves; unknown children force mixed unless no leaves are checked.

split: open-access