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

N = 1
observations = []
def solve(d):
    current=d['session']==d['reply_session'] and d['incarnation']==d['reply_incarnation']
    label=d['text'].strip()
    nonempty=bool(d['text'])
    duplicate=any(x!=d['row'] and name.casefold()==label.casefold() for x,name in d['siblings'])
    accepted=current and nonempty and not duplicate and d['server_ok']
    labels=dict(d['labels'])
    if accepted: labels[d['row']]=label
    editing=None if accepted else d['editing']
    error=None if accepted else ('invalid' if current and (not nonempty or duplicate) else d['error'])
    focus=d['row'] if accepted and d['focus']==d['editor'] else d['focus']
    return [labels,editing,error,focus,d['expanded'],d['selected']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('rename', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 1, 'reply_session': 0, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 3, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 2: [('rename', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 2, 'reply_session': 1, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 4, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 3: [('rename', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 3, 'reply_session': 2, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 5, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 4: [('rename', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 4, 'reply_session': 3, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 6, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 5: [('rename', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 5, 'reply_session': 4, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 7, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])]}
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):
    current=d['session']==d['reply_session'] and d['incarnation']==d['reply_incarnation']
    label=d['text'].strip()
    nonempty=True
    duplicate=any(x!=d['row'] and name.casefold()==label.casefold() for x,name in d['siblings'])
    accepted=current and nonempty and not duplicate and d['server_ok']
    labels=dict(d['labels'])
    if accepted: labels[d['row']]=label
    editing=None if accepted else d['editing']
    error=None if accepted else ('invalid' if current and (not nonempty or duplicate) else d['error'])
    focus=d['row'] if accepted and d['focus']==d['editor'] else d['focus']
    return [labels,editing,error,focus,d['expanded'],d['selected']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('rename', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 1, 'reply_session': 0, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 3, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 2: [('rename', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 2, 'reply_session': 1, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 4, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 3: [('rename', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 3, 'reply_session': 2, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 5, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 4: [('rename', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 4, 'reply_session': 3, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 6, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 5: [('rename', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 5, 'reply_session': 4, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 7, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])]}
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:
Whitespace-only tree label is accepted produces the wrong hierarchical widget state in a regression fixture.

Rename completion is applied only to the same row incarnation and edit session. Empty trimmed labels are rejected, duplicate sibling labels are rejected case-insensitively, and failure leaves editing active. Successful rename preserves expansion/selection and restores focus to the renamed row only when editing owned focus.

split: open-access


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

N = 1
observations = []
def solve(d):
    current=d['session']==d['reply_session'] and d['incarnation']==d['reply_incarnation']
    label=d['text'].strip()
    nonempty=bool(label)
    duplicate=any(name.casefold()==label.casefold() for x,name in d['siblings'])
    accepted=current and nonempty and not duplicate and d['server_ok']
    labels=dict(d['labels'])
    if accepted: labels[d['row']]=label
    editing=None if accepted else d['editing']
    error=None if accepted else ('invalid' if current and (not nonempty or duplicate) else d['error'])
    focus=d['row'] if accepted and d['focus']==d['editor'] else d['focus']
    return [labels,editing,error,focus,d['expanded'],d['selected']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('rename', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 1, 'reply_session': 0, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 3, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 2: [('rename', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 2, 'reply_session': 1, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 4, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 3: [('rename', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 3, 'reply_session': 2, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 5, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 4: [('rename', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 4, 'reply_session': 3, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 6, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 5: [('rename', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 5, 'reply_session': 4, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 7, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])]}
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):
    current=d['session']==d['reply_session'] and d['incarnation']==d['reply_incarnation']
    label=d['text'].strip()
    nonempty=bool(label)
    duplicate=any(x!=d['row'] and name==label for x,name in d['siblings'])
    accepted=current and nonempty and not duplicate and d['server_ok']
    labels=dict(d['labels'])
    if accepted: labels[d['row']]=label
    editing=None if accepted else d['editing']
    error=None if accepted else ('invalid' if current and (not nonempty or duplicate) else d['error'])
    focus=d['row'] if accepted and d['focus']==d['editor'] else d['focus']
    return [labels,editing,error,focus,d['expanded'],d['selected']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('rename', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 1, 'reply_session': 0, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 3, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 1, 'reply_session': 1, 'incarnation': 4, 'reply_incarnation': 4, 'text': ' New 1  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 1', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 2: [('rename', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 2, 'reply_session': 1, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 4, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 2, 'reply_session': 2, 'incarnation': 5, 'reply_incarnation': 5, 'text': ' New 2  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 2', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 3: [('rename', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 3, 'reply_session': 2, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 5, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 3, 'reply_session': 3, 'incarnation': 6, 'reply_incarnation': 6, 'text': ' New 3  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 3', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 4: [('rename', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 4, 'reply_session': 3, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 6, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 4, 'reply_session': 4, 'incarnation': 7, 'reply_incarnation': 7, 'text': ' New 4  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 4', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])], 5: [('rename', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('stale session', {'session': 5, 'reply_session': 4, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('recycled row', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 7, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('empty draft', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': '   ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('collision', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' taken ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'invalid', 'editor:b', ['b'], ['a']]), ('unchanged label', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': 'Old', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, None, None, 'b', ['b'], ['a']]), ('server failure', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': False, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'editor:b', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'b', 'old', 'editor:b', ['b'], ['a']]), ('outside focus', {'session': 5, 'reply_session': 5, 'incarnation': 8, 'reply_incarnation': 8, 'text': ' New 5  ', 'row': 'b', 'siblings': [['b', 'Old'], ['a', 'Taken']], 'server_ok': True, 'labels': {'a': 'Taken', 'b': 'Old', 'q': 'Other'}, 'editing': 'b', 'error': 'old', 'focus': 'q', 'editor': 'editor:b', 'expanded': ['b'], 'selected': ['a']}, [{'a': 'Taken', 'b': 'New 5', 'q': 'Other'}, None, None, 'q', ['b'], ['a']])]}
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:
Rename duplicate check rejects self or misses case collision produces the wrong hierarchical widget state in a regression fixture.

Rename completion is applied only to the same row incarnation and edit session. Empty trimmed labels are rejected, duplicate sibling labels are rejected case-insensitively, and failure leaves editing active. Successful rename preserves expansion/selection and restores focus to the renamed row only when editing owned focus.

split: open-access