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 not 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=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 x not 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)
    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:
Empty or unloaded branch reports fully checked 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


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 not 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<len(write)
    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)

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):
    leaves=d['leaves']; disabled=set(d['disabled']); checked=set(d['checked'])
    write=[x for x in leaves if x not 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)

prompt:
Mixed state ignores branch completeness 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


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 not 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 ('false' if mixed else 'mixed')
    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 x not 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 '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:
Indeterminate parent state is serialized as unchecked 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


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 not 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 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 x not 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 not 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:
Change notification reports final membership rather than changed leaves 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


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

N = 1
observations = []
def solve(d):
    r=d['row']
    position=d['slot']+1
    size=r['count'] if r['known'] else -1
    level=r['depth']+1
    owner=r['parent'] if r['parent'] is not None else d['tree']
    expanded=r['open'] if r['branch'] else None
    selected=r['id'] in d['selected']
    active=r['id']==d['active']
    dom=d['tree']+':'+r['id']
    rowindex=d['offset']+d['slot']+1
    busy=r['loading'] and r['branch']
    return [position,size,level,owner,expanded,selected,active,dom,rowindex,busy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, True, True, 'tree:b', 5, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'tree', True, False, False, 'tree:b', 5, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', None, True, False, 'tree:b', 5, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': False, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, -1, 2, 'p', True, False, True, 'tree:b', 5, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, False, False, 'tree:b', 5, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 9, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [1, 9, 1, 'p', False, False, True, 'tree:b', 5, True])], 2: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, True, True, 'tree:b', 8, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'tree', True, False, False, 'tree:b', 8, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', None, True, False, 'tree:b', 8, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': False, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, -1, 3, 'p', True, False, True, 'tree:b', 8, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, False, False, 'tree:b', 8, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 10, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [1, 10, 1, 'p', False, False, True, 'tree:b', 8, True])], 3: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, True, True, 'tree:b', 11, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'tree', True, False, False, 'tree:b', 11, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', None, True, False, 'tree:b', 11, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': False, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, -1, 4, 'p', True, False, True, 'tree:b', 11, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, False, False, 'tree:b', 11, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 11, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [1, 11, 1, 'p', False, False, True, 'tree:b', 11, True])], 4: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, True, True, 'tree:b', 14, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'tree', True, False, False, 'tree:b', 14, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', None, True, False, 'tree:b', 14, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': False, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, -1, 5, 'p', True, False, True, 'tree:b', 14, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, False, False, 'tree:b', 14, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 12, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [1, 12, 1, 'p', False, False, True, 'tree:b', 14, True])], 5: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, True, True, 'tree:b', 17, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'tree', True, False, False, 'tree:b', 17, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', None, True, False, 'tree:b', 17, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': False, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, -1, 6, 'p', True, False, True, 'tree:b', 17, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, False, False, 'tree:b', 17, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 13, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [1, 13, 1, 'p', False, False, True, 'tree:b', 17, 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):
    r=d['row']
    position=r['index']
    size=r['count'] if r['known'] else -1
    level=r['depth']+1
    owner=r['parent'] if r['parent'] is not None else d['tree']
    expanded=r['open'] if r['branch'] else None
    selected=r['id'] in d['selected']
    active=r['id']==d['active']
    dom=d['tree']+':'+r['id']
    rowindex=d['offset']+d['slot']+1
    busy=r['loading'] and r['branch']
    return [position,size,level,owner,expanded,selected,active,dom,rowindex,busy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, True, True, 'tree:b', 5, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'tree', True, False, False, 'tree:b', 5, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', None, True, False, 'tree:b', 5, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': False, 'depth': 1, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, -1, 2, 'p', True, False, True, 'tree:b', 5, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 3, 'count': 9, 'known': True, 'depth': 1, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 3, 'slot': 1, 'mounted': 3}, [4, 9, 2, 'p', True, False, False, 'tree:b', 5, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 9, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 3, 'slot': 1, 'mounted': 3}, [1, 9, 1, 'p', False, False, True, 'tree:b', 5, True])], 2: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, True, True, 'tree:b', 8, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'tree', True, False, False, 'tree:b', 8, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', None, True, False, 'tree:b', 8, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': False, 'depth': 2, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, -1, 3, 'p', True, False, True, 'tree:b', 8, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 4, 'count': 10, 'known': True, 'depth': 2, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 6, 'slot': 1, 'mounted': 3}, [5, 10, 3, 'p', True, False, False, 'tree:b', 8, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 10, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 6, 'slot': 1, 'mounted': 3}, [1, 10, 1, 'p', False, False, True, 'tree:b', 8, True])], 3: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, True, True, 'tree:b', 11, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'tree', True, False, False, 'tree:b', 11, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', None, True, False, 'tree:b', 11, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': False, 'depth': 3, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, -1, 4, 'p', True, False, True, 'tree:b', 11, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 5, 'count': 11, 'known': True, 'depth': 3, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 9, 'slot': 1, 'mounted': 3}, [6, 11, 4, 'p', True, False, False, 'tree:b', 11, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 11, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 9, 'slot': 1, 'mounted': 3}, [1, 11, 1, 'p', False, False, True, 'tree:b', 11, True])], 4: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, True, True, 'tree:b', 14, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'tree', True, False, False, 'tree:b', 14, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', None, True, False, 'tree:b', 14, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': False, 'depth': 4, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, -1, 5, 'p', True, False, True, 'tree:b', 14, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 6, 'count': 12, 'known': True, 'depth': 4, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 12, 'slot': 1, 'mounted': 3}, [7, 12, 5, 'p', True, False, False, 'tree:b', 14, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 12, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 12, 'slot': 1, 'mounted': 3}, [1, 12, 1, 'p', False, False, True, 'tree:b', 14, True])], 5: [('branch', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': ['b'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, True, True, 'tree:b', 17, True]), ('root', {'tree': 'tree', 'row': {'id': 'b', 'parent': None, 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'tree', True, False, False, 'tree:b', 17, True]), ('leaf', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': False, 'loading': True}, 'selected': ['b'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', None, True, False, 'tree:b', 17, False]), ('unknown', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': False, 'depth': 5, 'open': True, 'branch': True, 'loading': True}, 'selected': [], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, -1, 6, 'p', True, False, True, 'tree:b', 17, True]), ('idle', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 7, 'count': 13, 'known': True, 'depth': 5, 'open': True, 'branch': True, 'loading': False}, 'selected': ['x'], 'active': 'x', 'offset': 15, 'slot': 1, 'mounted': 3}, [8, 13, 6, 'p', True, False, False, 'tree:b', 17, False]), ('collapsed', {'tree': 'tree', 'row': {'id': 'b', 'parent': 'p', 'index': 0, 'count': 13, 'known': True, 'depth': 0, 'open': False, 'branch': True, 'loading': True}, 'selected': ['x'], 'active': 'b', 'offset': 15, 'slot': 1, 'mounted': 3}, [1, 13, 1, 'p', False, False, True, 'tree:b', 17, 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:
Logical sibling position becomes recycled slot number produces the wrong hierarchical widget state in a regression fixture.

Rows carry id,parent,logical sibling index,known sibling count,depth. The viewport must expose global sibling positions and counts, one-based depth, root ownership, expandable state only for branches, and stable identity independent of recycled slots.

split: open-access