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

N = 1
observations = []
def solve(row, column, draft, event, value, editable, validator, revision):
    key=(row['id'],column)
    state=dict(draft)
    if event=='begin' and editable: state={'key':key,'base':row[column],'value':row[column],'revision':revision,'error':None}
    if state.get('key')!=key: return {'draft':state,'write':None}
    if event=='input' and editable: state['value']=value
    if event=='cancel': return {'draft':{},'write':None}
    if event!='commit': return {'draft':state,'write':None}
    if not editable: return {'draft':state,'write':None}
    if state['revision']!=revision: state['error']='conflict'; return {'draft':state,'write':None}
    if validator=='required' and state['value']=='': state['error']='required'; return {'draft':state,'write':None}
    if False: return {'draft':{},'write':None}
    return {'draft':{},'write':{'row':row['id'],'column':column,'value':state['value'],'expected_revision':revision}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('begin snapshot', solve({'id':'r','x':1}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 1, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 2:
    check('begin snapshot', solve({'id':'r','x':2}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 2, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 3:
    check('begin snapshot', solve({'id':'r','x':3}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 3, 'value': 3, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 4:
    check('begin snapshot', solve({'id':'r','x':4}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 4, 'value': 4, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 5:
    check('begin snapshot', solve({'id':'r','x':5}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 5, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

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(row, column, draft, event, value, editable, validator, revision):
    key=(row['id'],column)
    state=dict(draft)
    if event=='begin' and editable: state={'key':key,'base':row[column],'value':row[column],'revision':revision,'error':None}
    if state.get('key')!=key: return {'draft':state,'write':None}
    if event=='input' and editable: state['value']=value
    if event=='cancel': return {'draft':{},'write':None}
    if event!='commit': return {'draft':state,'write':None}
    if not editable: return {'draft':state,'write':None}
    if state['revision']!=revision: state['error']='conflict'; return {'draft':state,'write':None}
    if validator=='required' and state['value']=='': state['error']='required'; return {'draft':state,'write':None}
    if state['value'] is None: return {'draft':{},'write':None}
    return {'draft':{},'write':{'row':row['id'],'column':column,'value':state['value'],'expected_revision':revision}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('begin snapshot', solve({'id':'r','x':1}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 1, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 2:
    check('begin snapshot', solve({'id':'r','x':2}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 2, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 3:
    check('begin snapshot', solve({'id':'r','x':3}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 3, 'value': 3, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 4:
    check('begin snapshot', solve({'id':'r','x':4}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 4, 'value': 4, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

if N == 5:
    check('begin snapshot', solve({'id':'r','x':5}, 'x', {}, 'begin', 'placeholder', True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 5, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('cancel draft', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'cancel', None, True, '', 3), {'draft': {}, 'write': None})
    check('wrong column', solve({'id':'r','x':1}, 'x', {'key':('r','y'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'y'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('readonly input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 4, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('stale revision', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':2,'error':None}, 'commit', None, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 2, 'error': 'conflict'}, 'write': None})
    check('required empty', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':'','revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': '', 'revision': 3, 'error': 'required'}, 'write': None})
    check('zero valid', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':0,'revision':3,'error':None}, 'commit', None, True, 'required', 3), {'draft': {}, 'write': {'row': 'r', 'column': 'x', 'value': 0, 'expected_revision': 3}})
    check('unchanged', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':1,'revision':3,'error':None}, 'commit', None, True, '', 3), {'draft': {}, 'write': None})
    check('readonly commit', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'commit', None, False, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 2, 'revision': 3, 'error': None}, 'write': None})
    check('normal input', solve({'id':'r','x':1}, 'x', {'key':('r','x'),'base':1,'value':2,'revision':3,'error':None}, 'input', 5, True, '', 3), {'draft': {'key': ('r', 'x'), 'base': 1, 'value': 5, 'revision': 3, 'error': None}, 'write': None})
    check('readonly begin', solve({'id':'r','x':1}, 'x', {}, 'begin', None, False, '', 3), {'draft': {}, 'write': None})

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:
The table unchanged write result violates the stipulated table cell draft lifecycle contract.

Cell drafts belong to a stable row-column pair and snapshot the original value and revision. Readonly cells cannot start/input/commit edits, cancellation discards the draft, commits validate required empty strings, reject stale revisions, and suppress unchanged writes.

split: open-access


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

N = 1
observations = []
def solve(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if True}
    unknown=sorted(set(draft)-{c['id'] for c in schema})
    changes={k:v for k,v in draft.items() if k in allowed and row.get(k)!=v}
    errors={c['id']:'required' for c in schema if c.get('required') and draft.get(c['id'],row.get(c['id'])) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if c.get('editable',False)}
    unknown=sorted(set(draft)-{c['id'] for c in schema})
    changes={k:v for k,v in draft.items() if k in allowed and row.get(k)!=v}
    errors={c['id']:'required' for c in schema if c.get('required') and draft.get(c['id'],row.get(c['id'])) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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:
The table editable schema result violates the stipulated atomic table row editing contract.

Row commits validate the merged draft atomically, reject unknown schema fields, ignore readonly fields, preserve untouched cells and stable identity, reject revision conflicts, suppress no-ops, and increment the revision only after actual changes.

split: open-access


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

N = 1
observations = []
def solve(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if c.get('editable',True)}
    unknown=sorted(set())
    changes={k:v for k,v in draft.items() if k in allowed and row.get(k)!=v}
    errors={c['id']:'required' for c in schema if c.get('required') and draft.get(c['id'],row.get(c['id'])) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if c.get('editable',True)}
    unknown=sorted(set(draft)-allowed)
    changes={k:v for k,v in draft.items() if k in allowed and row.get(k)!=v}
    errors={c['id']:'required' for c in schema if c.get('required') and draft.get(c['id'],row.get(c['id'])) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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:
The table unknown field difference result violates the stipulated atomic table row editing contract.

Row commits validate the merged draft atomically, reject unknown schema fields, ignore readonly fields, preserve untouched cells and stable identity, reject revision conflicts, suppress no-ops, and increment the revision only after actual changes.

split: open-access


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

N = 1
observations = []
def solve(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if c.get('editable',True)}
    unknown=sorted(set(draft)-{c['id'] for c in schema})
    changes={k:v for k,v in draft.items() if k in allowed and True}
    errors={c['id']:'required' for c in schema if c.get('required') and draft.get(c['id'],row.get(c['id'])) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if c.get('editable',True)}
    unknown=sorted(set(draft)-{c['id'] for c in schema})
    changes={k:v for k,v in draft.items() if k in allowed and bool(v)}
    errors={c['id']:'required' for c in schema if c.get('required') and draft.get(c['id'],row.get(c['id'])) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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:
The table unchanged cell elision result violates the stipulated atomic table row editing contract.

Row commits validate the merged draft atomically, reject unknown schema fields, ignore readonly fields, preserve untouched cells and stable identity, reject revision conflicts, suppress no-ops, and increment the revision only after actual changes.

split: open-access


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

N = 1
observations = []
def solve(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if c.get('editable',True)}
    unknown=sorted(set(draft)-{c['id'] for c in schema})
    changes={k:v for k,v in draft.items() if k in allowed and row.get(k)!=v}
    errors={c['id']:'required' for c in schema if c.get('required') and draft.get(c['id']) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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(row, draft, schema, revision, base_revision):
    allowed={c['id'] for c in schema if c.get('editable',True)}
    unknown=sorted(set(draft)-{c['id'] for c in schema})
    changes={k:v for k,v in draft.items() if k in allowed and row.get(k)!=v}
    errors={c['id']:'required' for c in schema if c.get('required') and row.get(c['id']) in ('',None)}
    if unknown: return {'status':'unknown','fields':unknown,'row':row}
    if errors: return {'status':'invalid','fields':errors,'row':row}
    if base_revision!=revision: return {'status':'conflict','fields':[],'row':row}
    if not changes: return {'status':'unchanged','fields':[],'row':row}
    updated=dict(row); updated.update(changes)
    return {'status':'saved','fields':sorted(changes),'row':updated,'revision':revision+1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':1+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 4, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 2:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':2+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 5, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 3:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':3+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 6, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 4:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':4+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 7, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

if N == 5:
    check('partial draft', solve({'id':'r','a':1,'b':2}, {'a':5+3}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'saved', 'fields': ['a'], 'row': {'id': 'r', 'a': 8, 'b': 2}, 'revision': 5})
    check('readonly draft', solve({'id':'r','a':1,'b':2}, {'b':9}, [{'id':'a'},{'id':'b','editable':False}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1, 'b': 2}})
    check('unknown draft', solve({'id':'r','a':1}, {'missing':2}, [{'id':'a'}], 4, 4), {'status': 'unknown', 'fields': ['missing'], 'row': {'id': 'r', 'a': 1}})
    check('required clear', solve({'id':'r','a':'ok','b':2}, {'a':''}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'invalid', 'fields': {'a': 'required'}, 'row': {'id': 'r', 'a': 'ok', 'b': 2}})
    check('required untouched', solve({'id':'r','a':'ok','b':2}, {'b':0}, [{'id':'a','required':True},{'id':'b'}], 4, 4), {'status': 'saved', 'fields': ['b'], 'row': {'id': 'r', 'a': 'ok', 'b': 0}, 'revision': 5})
    check('stale row', solve({'id':'r','a':1}, {'a':2}, [{'id':'a'}], 4, 3), {'status': 'conflict', 'fields': [], 'row': {'id': 'r', 'a': 1}})
    check('same value', solve({'id':'r','a':1}, {'a':1}, [{'id':'a'}], 4, 4), {'status': 'unchanged', 'fields': [], 'row': {'id': 'r', 'a': 1}})

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:
The table required merged row result violates the stipulated atomic table row editing contract.

Row commits validate the merged draft atomically, reject unknown schema fields, ignore readonly fields, preserve untouched cells and stable identity, reject revision conflicts, suppress no-ops, and increment the revision only after actual changes.

split: open-access