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': 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']==state['base']: 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 False: 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']==state['base']: 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 begin editability 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, column, draft, event, value, editable, validator, revision):
    key=(row['id'],column)
    state=dict(draft)
    if event=='begin' and editable: state={'key':key,'base':None,'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']==state['base']: 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)

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, column, draft, event, value, editable, validator, revision):
    key=(row['id'],column)
    state=dict(draft)
    if event=='begin' and editable: state={'key':key,'base':value,'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']==state['base']: 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 draft original 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, 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 False: 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']==state['base']: 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',('',''))[0]!=key[0]: 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']==state['base']: 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 draft cell owner 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