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

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

N = 1
observations = []
def solve(d):
    leaves=d['leaves']; disabled=set(d['disabled']); checked=set(d['checked'])
    write=[x for x in leaves if x not in disabled]
    target=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:
Partial branch toggles toward 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(leaves)
    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)

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=set()
    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:
Cascade erases protected or unrelated checks 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(leaves) if target else set()
    after=keep|changed
    count=sum(x in after for x in write)
    complete=bool(write) and count==len(write) and not d['unknown']
    mixed=count>0 and not complete
    state='true' if complete else ('mixed' if mixed else 'false')
    order=[x for x in d['all'] if x in after]
    changed_ids=[x for x in write if (x in checked)!=(x in after)]
    return [order,state,changed_ids,target]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('partial', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2'], 'true', ['c2'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c2'], 'true', ['c0', 'c2'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2'], 'mixed', ['c2'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c1', 'c2'], 'true', ['c0', 'c2'], True])], 2: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'true', ['c2', 'c3'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'mixed', ['c2', 'c3'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True])], 3: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c2', 'c3', 'c4'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'mixed', ['c2', 'c3', 'c4'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True])], 4: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c2', 'c3', 'c4', 'c5'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'mixed', ['c2', 'c3', 'c4', 'c5'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True])], 5: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'mixed', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

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

prompt:
Disabled or already complete branch is recascaded 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 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=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:
Cascaded leaves fail to merge with retained checks 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 checked for x in write)
    complete=bool(write) and count==len(write) and not d['unknown']
    mixed=count>0 and not complete
    state='true' if complete else ('mixed' if mixed else 'false')
    order=[x for x in d['all'] if x in after]
    changed_ids=[x for x in write if (x in checked)!=(x in after)]
    return [order,state,changed_ids,target]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('partial', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2'], 'true', ['c2'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c2'], 'true', ['c0', 'c2'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2'], 'mixed', ['c2'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2'], 'unknown': False}, [['c0', 'c1', 'c2'], 'true', ['c0', 'c2'], True])], 2: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'true', ['c2', 'c3'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3'], 'mixed', ['c2', 'c3'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3'], 'true', ['c0', 'c2', 'c3'], True])], 3: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c2', 'c3', 'c4'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'mixed', ['c2', 'c3', 'c4'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4'], 'true', ['c0', 'c2', 'c3', 'c4'], True])], 4: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c2', 'c3', 'c4', 'c5'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'mixed', ['c2', 'c3', 'c4', 'c5'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5'], True])], 5: [('partial', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('all checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c1'], 'false', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], False]), ('none checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': [], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], True]), ('unknown descendants', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': True}, [['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'mixed', ['c2', 'c3', 'c4', 'c5', 'c6'], True]), ('empty branch', {'leaves': [], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('disabled only', {'leaves': ['c1'], 'disabled': ['c1'], 'checked': ['outside', 'c0', 'c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['outside', 'c0', 'c1'], 'false', [], False]), ('protected checked', {'leaves': ['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'disabled': ['c1'], 'checked': ['c1'], 'all': ['outside', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'unknown': False}, [['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'], 'true', ['c0', 'c2', 'c3', 'c4', 'c5', 'c6'], True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    leaves=d['leaves']; disabled=set(d['disabled']); checked=set(d['checked'])
    write=[x for x in leaves if 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 leaves)
    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:
Parent summary uses stale or protected 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