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

N = 1
observations = []
def solve(old, new, aliases, view, drafts, selected, anchor):
    ids=[c['id'] for c in new]
    def remap(k):
        if k in ids: return k
        return aliases.get(k) if aliases.get(k) in ids else None
    order=[]
    for k in view['order']:
        mapped=remap(k)
        if mapped is not None and mapped not in order: order.append(mapped)
    order += [k for k in ids if k not in order]
    widths={}
    for k,v in view['widths'].items():
        mapped=remap(k)
        if mapped is not None and (mapped not in widths or k==mapped): widths[mapped]=v
    hidden=[k for k in order if any(remap(x)==k for x in view['hidden']) and not next(c for c in new if c['id']==k).get('required')]
    newdraft=[]
    oldtypes={c['id']:c['type'] for c in old}; newtypes={c['id']:c['type'] for c in new}
    for r,c,value in drafts:
        mapped=remap(c)
        if mapped is not None and True: newdraft.append((r,mapped,value))
    newsel=[]
    for r,c in selected:
        mapped=remap(c)
        if mapped is not None and (r,mapped) not in newsel: newsel.append((r,mapped))
    return {'order':order,'widths':widths,'hidden':hidden,'drafts':newdraft,'selected':newsel,'anchor':(anchor[0],remap(anchor[1])) if anchor is not None and remap(anchor[1]) is not None else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':1+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 8}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 2:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':2+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 9}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 3:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':3+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 10}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 4:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':4+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 11}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 5:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':5+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 12}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': 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(old, new, aliases, view, drafts, selected, anchor):
    ids=[c['id'] for c in new]
    def remap(k):
        if k in ids: return k
        return aliases.get(k) if aliases.get(k) in ids else None
    order=[]
    for k in view['order']:
        mapped=remap(k)
        if mapped is not None and mapped not in order: order.append(mapped)
    order += [k for k in ids if k not in order]
    widths={}
    for k,v in view['widths'].items():
        mapped=remap(k)
        if mapped is not None and (mapped not in widths or k==mapped): widths[mapped]=v
    hidden=[k for k in order if any(remap(x)==k for x in view['hidden']) and not next(c for c in new if c['id']==k).get('required')]
    newdraft=[]
    oldtypes={c['id']:c['type'] for c in old}; newtypes={c['id']:c['type'] for c in new}
    for r,c,value in drafts:
        mapped=remap(c)
        if mapped is not None and c==mapped: newdraft.append((r,mapped,value))
    newsel=[]
    for r,c in selected:
        mapped=remap(c)
        if mapped is not None and (r,mapped) not in newsel: newsel.append((r,mapped))
    return {'order':order,'widths':widths,'hidden':hidden,'drafts':newdraft,'selected':newsel,'anchor':(anchor[0],remap(anchor[1])) if anchor is not None and remap(anchor[1]) is not None else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':1+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 8}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 2:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':2+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 9}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 3:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':3+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 10}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 4:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':4+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 11}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 5:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':5+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 12}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': 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 type compatibility result violates the stipulated table column schema migration contract.

Schema migration gives surviving IDs precedence over aliases, validates alias targets, deduplicates migrated order/selection and appends new columns. Direct widths override alias widths, required columns stay visible, drafts migrate only across equal types, and deleted anchors clear.

split: open-access


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

N = 1
observations = []
def solve(old, new, aliases, view, drafts, selected, anchor):
    ids=[c['id'] for c in new]
    def remap(k):
        if k in ids: return k
        return aliases.get(k) if aliases.get(k) in ids else None
    order=[]
    for k in view['order']:
        mapped=remap(k)
        if mapped is not None and mapped not in order: order.append(mapped)
    order += [k for k in ids if k not in order]
    widths={}
    for k,v in view['widths'].items():
        mapped=remap(k)
        if mapped is not None and (mapped not in widths or k==mapped): widths[mapped]=v
    hidden=[k for k in order if any(remap(x)==k for x in view['hidden']) and not next(c for c in new if c['id']==k).get('required')]
    newdraft=[]
    oldtypes={c['id']:c['type'] for c in old}; newtypes={c['id']:c['type'] for c in new}
    for r,c,value in drafts:
        mapped=remap(c)
        if mapped is not None and oldtypes.get(c)==newtypes[mapped]: newdraft.append((r,c,value))
    newsel=[]
    for r,c in selected:
        mapped=remap(c)
        if mapped is not None and (r,mapped) not in newsel: newsel.append((r,mapped))
    return {'order':order,'widths':widths,'hidden':hidden,'drafts':newdraft,'selected':newsel,'anchor':(anchor[0],remap(anchor[1])) if anchor is not None and remap(anchor[1]) is not None else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':1+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 8}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 2:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':2+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 9}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 3:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':3+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 10}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 4:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':4+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 11}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 5:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':5+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 12}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': 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(old, new, aliases, view, drafts, selected, anchor):
    ids=[c['id'] for c in new]
    def remap(k):
        if k in ids: return k
        return aliases.get(k) if aliases.get(k) in ids else None
    order=[]
    for k in view['order']:
        mapped=remap(k)
        if mapped is not None and mapped not in order: order.append(mapped)
    order += [k for k in ids if k not in order]
    widths={}
    for k,v in view['widths'].items():
        mapped=remap(k)
        if mapped is not None and (mapped not in widths or k==mapped): widths[mapped]=v
    hidden=[k for k in order if any(remap(x)==k for x in view['hidden']) and not next(c for c in new if c['id']==k).get('required')]
    newdraft=[]
    oldtypes={c['id']:c['type'] for c in old}; newtypes={c['id']:c['type'] for c in new}
    for r,c,value in drafts:
        mapped=remap(c)
        if mapped is not None and oldtypes.get(c)==newtypes[mapped]: newdraft.append((r,mapped,None))
    newsel=[]
    for r,c in selected:
        mapped=remap(c)
        if mapped is not None and (r,mapped) not in newsel: newsel.append((r,mapped))
    return {'order':order,'widths':widths,'hidden':hidden,'drafts':newdraft,'selected':newsel,'anchor':(anchor[0],remap(anchor[1])) if anchor is not None and remap(anchor[1]) is not None else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':1+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 8}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 2:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':2+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 9}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 3:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':3+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 10}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 4:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':4+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 11}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 5:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':5+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 12}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': 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 renamed coordinate result violates the stipulated table column schema migration contract.

Schema migration gives surviving IDs precedence over aliases, validates alias targets, deduplicates migrated order/selection and appends new columns. Direct widths override alias widths, required columns stay visible, drafts migrate only across equal types, and deleted anchors clear.

split: open-access


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

N = 1
observations = []
def solve(old, new, aliases, view, drafts, selected, anchor):
    ids=[c['id'] for c in new]
    def remap(k):
        if k in ids: return k
        return aliases.get(k) if aliases.get(k) in ids else None
    order=[]
    for k in view['order']:
        mapped=remap(k)
        if mapped is not None and mapped not in order: order.append(mapped)
    order += [k for k in ids if k not in order]
    widths={}
    for k,v in view['widths'].items():
        mapped=remap(k)
        if mapped is not None and (mapped not in widths or k==mapped): widths[mapped]=v
    hidden=[k for k in order if any(remap(x)==k for x in view['hidden']) and not next(c for c in new if c['id']==k).get('required')]
    newdraft=[]
    oldtypes={c['id']:c['type'] for c in old}; newtypes={c['id']:c['type'] for c in new}
    for r,c,value in drafts:
        mapped=remap(c)
        if mapped is not None and oldtypes.get(c)==newtypes[mapped]: newdraft.append((r,mapped,value))
    newsel=[]
    for r,c in selected:
        mapped=remap(c)
        if mapped is not None and True: newsel.append((r,mapped))
    return {'order':order,'widths':widths,'hidden':hidden,'drafts':newdraft,'selected':newsel,'anchor':(anchor[0],remap(anchor[1])) if anchor is not None and remap(anchor[1]) is not None else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':1+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 8}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 2:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':2+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 9}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 3:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':3+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 10}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 4:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':4+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 11}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 5:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':5+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 12}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': 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(old, new, aliases, view, drafts, selected, anchor):
    ids=[c['id'] for c in new]
    def remap(k):
        if k in ids: return k
        return aliases.get(k) if aliases.get(k) in ids else None
    order=[]
    for k in view['order']:
        mapped=remap(k)
        if mapped is not None and mapped not in order: order.append(mapped)
    order += [k for k in ids if k not in order]
    widths={}
    for k,v in view['widths'].items():
        mapped=remap(k)
        if mapped is not None and (mapped not in widths or k==mapped): widths[mapped]=v
    hidden=[k for k in order if any(remap(x)==k for x in view['hidden']) and not next(c for c in new if c['id']==k).get('required')]
    newdraft=[]
    oldtypes={c['id']:c['type'] for c in old}; newtypes={c['id']:c['type'] for c in new}
    for r,c,value in drafts:
        mapped=remap(c)
        if mapped is not None and oldtypes.get(c)==newtypes[mapped]: newdraft.append((r,mapped,value))
    newsel=[]
    for r,c in selected:
        mapped=remap(c)
        if mapped is not None and not newsel: newsel.append((r,mapped))
    return {'order':order,'widths':widths,'hidden':hidden,'drafts':newdraft,'selected':newsel,'anchor':(anchor[0],remap(anchor[1])) if anchor is not None and remap(anchor[1]) is not None else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':1+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 8}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 2:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':2+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 9}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 3:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':3+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 10}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 4:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':4+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 11}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': None})

if N == 5:
    check('renamed numeric column', solve([{'id':'old','type':'number'},{'id':'b','type':'text'}], [{'id':'new','type':'number'},{'id':'b','type':'text'},{'id':'fresh','type':'text'}], {'old':'new'}, {'order':['old','b'],'widths':{'old':5+7},'hidden':['old']}, [('r','old',3),('r','b','x')], [('r','old'),('r','b')], ('r','old')), {'order': ['new', 'b', 'fresh'], 'widths': {'new': 12}, 'hidden': ['new'], 'drafts': [('r', 'new', 3), ('r', 'b', 'x')], 'selected': [('r', 'new'), ('r', 'b')], 'anchor': ('r', 'new')})
    check('direct id wins alias', solve([{'id':'a','type':'text'},{'id':'b','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'}], {'a':'b'}, {'order':['a','b'],'widths':{'a':4,'b':5},'hidden':[]}, [], [], ('r','a')), {'order': ['a', 'b'], 'widths': {'a': 4, 'b': 5}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': ('r', 'a')})
    check('merged aliases direct widths last', solve([{'id':'x','type':'text'},{'id':'y','type':'text'},{'id':'a','type':'text'}], [{'id':'a','type':'text'}], {'x':'a','y':'a'}, {'order':['x','y','a'],'widths':{'x':4,'a':8,'y':6},'hidden':[]}, [], [('r','x'),('r','y')], None), {'order': ['a'], 'widths': {'a': 8}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': None})
    check('type-changed draft', solve([{'id':'a','type':'text'}], [{'id':'a','type':'number'}], {}, {'order':['a'],'widths':{},'hidden':[]}, [('r','a','1')], [('r','a')], ('r','a')), {'order': ['a'], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [('r', 'a')], 'anchor': ('r', 'a')})
    check('removed schema key', solve([{'id':'gone','type':'text'}], [], {'gone':'also-gone'}, {'order':['gone'],'widths':{'gone':9},'hidden':['gone']}, [('r','gone','v')], [('r','gone')], ('r','gone')), {'order': [], 'widths': {}, 'hidden': [], 'drafts': [], 'selected': [], 'anchor': None})
    check('reverse saved order', solve([{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], [{'id':'a','type':'text'},{'id':'b','type':'text'},{'id':'c','type':'text'}], {}, {'order':['c','b','a'],'widths':{},'hidden':['b']}, [], [], None), {'order': ['c', 'b', 'a'], 'widths': {}, 'hidden': ['b'], 'drafts': [], 'selected': [], 'anchor': None})
    check('required renamed column', solve([{'id':'old','type':'text'}], [{'id':'a','type':'text'},{'id':'new','type':'text','required':True}], {'old':'new'}, {'order':['a','old'],'widths':{},'hidden':['old','a']}, [], [], None), {'order': ['a', 'new'], 'widths': {}, 'hidden': ['a'], 'drafts': [], 'selected': [], 'anchor': 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 selection migration dedupe result violates the stipulated table column schema migration contract.

Schema migration gives surviving IDs precedence over aliases, validates alias targets, deduplicates migrated order/selection and appends new columns. Direct widths override alias widths, required columns stay visible, drafts migrate only across equal types, and deleted anchors clear.

split: open-access