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

N = 1
observations = []
def solve(d):
    match=d['reply_epoch']==d['epoch'] and d['reply_token']==d['token']
    accept=match and d['live'] and d['open']
    children=d['reply'] if accept else d['children']
    busy=False if accept else d['busy']
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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):
    match=d['reply_epoch']==d['epoch'] and d['reply_token']==d['token']
    accept=match and d['live'] and d['open']
    children=sorted(set(d['reply'])) if accept else d['children']
    busy=False if accept else d['busy']
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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:
Page deduplication scrambles child order produces the wrong hierarchical widget state in a regression fixture.

A request is accepted only for a live open branch with matching epoch and token. Accepted pages replace a placeholder with deduplicated child IDs, clear busy/error state, and derive completeness from a next cursor. Rejected responses preserve all branch state.

split: open-access


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

N = 1
observations = []
def solve(d):
    match=d['reply_epoch']==d['epoch'] and d['reply_token']==d['token']
    accept=match and d['live'] and d['open']
    children=list(dict.fromkeys(d['reply'])) if accept else d['children']
    busy=d['busy']
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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):
    match=d['reply_epoch']==d['epoch'] and d['reply_token']==d['token']
    accept=match and d['live'] and d['open']
    children=list(dict.fromkeys(d['reply'])) if accept else d['children']
    busy=False
    error=None if accept else d['error']
    cursor=d['next'] if accept else d['cursor']
    complete=(d['next'] is None) if accept else d['complete']
    placeholder=False if accept else d['placeholder']
    token=None if accept else d['token']
    focus=(children[0] if children else d['parent']) if accept and d['focus']=='placeholder' else d['focus']
    return [children,busy,error,cursor,complete,placeholder,token,focus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('accepted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 0, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 1, 'epoch': 1, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0'], False, None, None, True, False, None, 'outside'])], 2: [('accepted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 1, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 2, 'epoch': 2, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1'], False, None, None, True, False, None, 'outside'])], 3: [('accepted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 2, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 3, 'epoch': 3, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2'], False, None, None, True, False, None, 'outside'])], 4: [('accepted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 3, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 4, 'epoch': 4, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3'], False, None, None, True, False, None, 'outside'])], 5: [('accepted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'z']), ('old epoch', {'reply_epoch': 4, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('old token', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 'old', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('collapsed', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': False, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('deleted', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': False, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['old'], True, 'old-error', 'oldcursor', False, True, 't', 'placeholder']), ('empty terminal', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': [], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [[], False, None, None, True, False, None, 'p']), ('empty cursor', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': '', 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'placeholder'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, '', False, False, None, 'z']), ('focus elsewhere', {'reply_epoch': 5, 'epoch': 5, 'reply_token': 't', 'token': 't', 'live': True, 'open': True, 'reply': ['z', 'c0', 'c1', 'c2', 'c3', 'c4', 'z'], 'children': ['old'], 'busy': True, 'error': 'old-error', 'next': None, 'cursor': 'oldcursor', 'complete': False, 'placeholder': True, 'parent': 'p', 'focus': 'outside'}, [['z', 'c0', 'c1', 'c2', 'c3', 'c4'], False, None, None, True, False, None, 'outside'])]}
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:
Busy state clears for a rejected page produces the wrong hierarchical widget state in a regression fixture.

A request is accepted only for a live open branch with matching epoch and token. Accepted pages replace a placeholder with deduplicated child IDs, clear busy/error state, and derive completeness from a next cursor. Rejected responses preserve all branch state.

split: open-access