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

N = 1
observations = []
def solve(d):
    accept=d['cursor']==d['expected_cursor'] and d['revision']==d['expected_revision']
    order=list(dict.fromkeys(d['order']+[r[0] for r in d['page']])) if accept else d['order']
    records=dict(d['records'])
    if accept: records={**dict(d['page']),**records}
    new=[r[0] for r in d['page'] if r[0] not in d['order']] if accept else []
    new=list(dict.fromkeys(new))
    nextcursor=d['next'] if accept else d['expected_cursor']
    more=nextcursor is not None
    size=d['total'] if accept and d['total'] is not None else d['size']
    focus=(new[0] if new else (d['parent'] if not more else d['focus'])) if accept and d['focus']=='more' else d['focus']
    positions={x:i+1 for i,x in enumerate(order)}
    return [order,records,new,nextcursor,more,size,focus,positions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 0, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': '', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], '', True, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 9, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 2: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': '', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], '', True, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 10, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 3: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': '', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], '', True, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 11, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 4: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': '', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], '', True, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 12, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 5: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': '', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], '', True, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 13, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])]}
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):
    accept=d['cursor']==d['expected_cursor'] and d['revision']==d['expected_revision']
    order=list(dict.fromkeys(d['order']+[r[0] for r in d['page']])) if accept else d['order']
    records=dict(d['records'])
    records.update(dict(d['page']))
    new=[r[0] for r in d['page'] if r[0] not in d['order']] if accept else []
    new=list(dict.fromkeys(new))
    nextcursor=d['next'] if accept else d['expected_cursor']
    more=nextcursor is not None
    size=d['total'] if accept and d['total'] is not None else d['size']
    focus=(new[0] if new else (d['parent'] if not more else d['focus'])) if accept and d['focus']=='more' else d['focus']
    positions={x:i+1 for i,x in enumerate(order)}
    return [order,records,new,nextcursor,more,size,focus,positions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 0, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': '', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], '', True, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 9, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 2: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': '', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], '', True, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 10, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 3: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': '', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], '', True, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 11, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 4: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': '', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], '', True, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 12, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 5: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': '', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], '', True, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 13, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])]}
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:
Overlapping child refresh loses newest record produces the wrong hierarchical widget state in a regression fixture.

Only the expected cursor and branch revision admit a page. Repeated child IDs preserve their first position but update their record. An empty string is a valid next cursor. Logical count is authoritative when supplied; otherwise unknown. Focus on the load-more row moves to first newly inserted child, or parent if no continuation.

split: open-access


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

N = 1
observations = []
def solve(d):
    accept=d['cursor']==d['expected_cursor'] and d['revision']==d['expected_revision']
    order=list(dict.fromkeys(d['order']+[r[0] for r in d['page']])) if accept else d['order']
    records=dict(d['records'])
    if accept: records.update(dict(d['page']))
    new=[r[0] for r in d['page'] if True] if accept else []
    new=list(dict.fromkeys(new))
    nextcursor=d['next'] if accept else d['expected_cursor']
    more=nextcursor is not None
    size=d['total'] if accept and d['total'] is not None else d['size']
    focus=(new[0] if new else (d['parent'] if not more else d['focus'])) if accept and d['focus']=='more' else d['focus']
    positions={x:i+1 for i,x in enumerate(order)}
    return [order,records,new,nextcursor,more,size,focus,positions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 0, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': '', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], '', True, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 9, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 2: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': '', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], '', True, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 10, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 3: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': '', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], '', True, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 11, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 4: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': '', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], '', True, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 12, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 5: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': '', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], '', True, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 13, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])]}
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):
    accept=d['cursor']==d['expected_cursor'] and d['revision']==d['expected_revision']
    order=list(dict.fromkeys(d['order']+[r[0] for r in d['page']])) if accept else d['order']
    records=dict(d['records'])
    if accept: records.update(dict(d['page']))
    new=[r[0] for r in d['page'] if r[0] in d['order']] if accept else []
    new=list(dict.fromkeys(new))
    nextcursor=d['next'] if accept else d['expected_cursor']
    more=nextcursor is not None
    size=d['total'] if accept and d['total'] is not None else d['size']
    focus=(new[0] if new else (d['parent'] if not more else d['focus'])) if accept and d['focus']=='more' else d['focus']
    positions={x:i+1 for i,x in enumerate(order)}
    return [order,records,new,nextcursor,more,size,focus,positions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 0, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': '', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], '', True, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 9, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 2: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': '', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], '', True, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 10, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 3: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': '', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], '', True, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 11, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 4: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': '', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], '', True, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 12, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 5: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': '', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], '', True, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 13, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])]}
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:
Existing child is mistaken for a new focus target produces the wrong hierarchical widget state in a regression fixture.

Only the expected cursor and branch revision admit a page. Repeated child IDs preserve their first position but update their record. An empty string is a valid next cursor. Logical count is authoritative when supplied; otherwise unknown. Focus on the load-more row moves to first newly inserted child, or parent if no continuation.

split: open-access


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

N = 1
observations = []
def solve(d):
    accept=d['cursor']==d['expected_cursor'] and d['revision']==d['expected_revision']
    order=list(dict.fromkeys(d['order']+[r[0] for r in d['page']])) if accept else d['order']
    records=dict(d['records'])
    if accept: records.update(dict(d['page']))
    new=[r[0] for r in d['page'] if r[0] not in d['order']] if accept else []
    new=new
    nextcursor=d['next'] if accept else d['expected_cursor']
    more=nextcursor is not None
    size=d['total'] if accept and d['total'] is not None else d['size']
    focus=(new[0] if new else (d['parent'] if not more else d['focus'])) if accept and d['focus']=='more' else d['focus']
    positions={x:i+1 for i,x in enumerate(order)}
    return [order,records,new,nextcursor,more,size,focus,positions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 0, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': '', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], '', True, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 9, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 2: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': '', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], '', True, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 10, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 3: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': '', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], '', True, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 11, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 4: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': '', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], '', True, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 12, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 5: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': '', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], '', True, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 13, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])]}
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):
    accept=d['cursor']==d['expected_cursor'] and d['revision']==d['expected_revision']
    order=list(dict.fromkeys(d['order']+[r[0] for r in d['page']])) if accept else d['order']
    records=dict(d['records'])
    if accept: records.update(dict(d['page']))
    new=[r[0] for r in d['page'] if r[0] not in d['order']] if accept else []
    new=sorted(set(new))
    nextcursor=d['next'] if accept else d['expected_cursor']
    more=nextcursor is not None
    size=d['total'] if accept and d['total'] is not None else d['size']
    focus=(new[0] if new else (d['parent'] if not more else d['focus'])) if accept and d['focus']=='more' else d['focus']
    positions={x:i+1 for i,x in enumerate(order)}
    return [order,records,new,nextcursor,more,size,focus,positions]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 0, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': '', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], '', True, 9, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 9, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 9, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 1, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 1], ['b', 8], ['y', 2]], 'next': None, 'total': 9, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 2, 'b': 8}, ['y', 'b'], None, False, 9, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 2: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 1, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': '', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], '', True, 10, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 10, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 10, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 2, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 2], ['b', 8], ['y', 3]], 'next': None, 'total': 10, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 3, 'b': 8}, ['y', 'b'], None, False, 10, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 3: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 2, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': '', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], '', True, 11, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 11, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 11, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 3, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 3], ['b', 8], ['y', 4]], 'next': None, 'total': 11, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 4, 'b': 8}, ['y', 'b'], None, False, 11, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 4: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 3, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': '', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], '', True, 12, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 12, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 12, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 4, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 4], ['b', 8], ['y', 5]], 'next': None, 'total': 12, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 5, 'b': 8}, ['y', 'b'], None, False, 12, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])], 5: [('overlap page', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('stale cursor', {'cursor': 'old', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('stale revision', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 4, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'c', True, -1, 'more', {'z': 1, 'a': 2}]), ('empty cursor', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': '', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], '', True, 13, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('empty terminal', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': None, 'total': 0, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], None, False, 0, 'p', {'z': 1, 'a': 2}]), ('empty continued', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [], 'next': 'x', 'total': 13, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a'], {'z': 1, 'a': 2}, [], 'x', True, 13, 'more', {'z': 1, 'a': 2}]), ('unknown total', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': None, 'size': -1, 'focus': 'more', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, -1, 'y', {'z': 1, 'a': 2, 'y': 3, 'b': 4}]), ('focus elsewhere', {'cursor': 'c', 'expected_cursor': 'c', 'revision': 5, 'expected_revision': 5, 'order': ['z', 'a'], 'records': {'z': 1, 'a': 2}, 'page': [['a', 3], ['y', 5], ['b', 8], ['y', 6]], 'next': None, 'total': 13, 'size': -1, 'focus': 'z', 'parent': 'p'}, [['z', 'a', 'y', 'b'], {'z': 1, 'a': 3, 'y': 6, 'b': 8}, ['y', 'b'], None, False, 13, 'z', {'z': 1, 'a': 2, 'y': 3, 'b': 4}])]}
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:
Repeated page entry corrupts newly loaded child order produces the wrong hierarchical widget state in a regression fixture.

Only the expected cursor and branch revision admit a page. Repeated child IDs preserve their first position but update their record. An empty string is a valid next cursor. Logical count is authoritative when supplied; otherwise unknown. Focus on the load-more row moves to first newly inserted child, or parent if no continuation.

split: open-access