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

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation and measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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 width invalidation queue result violates the stipulated table row height measurement cache contract.

Measured row heights are keyed by stable row ID plus row-data generation and column-width fingerprint. Invalid measurements use an estimate, minimum applies before detail height, positions are ordered prefixes, and stale row measurements are pruned.

split: open-access


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

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if True}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids[:1]}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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 stale measurement prune result violates the stipulated table row height measurement cache contract.

Measured row heights are keyed by stable row ID plus row-data generation and column-width fingerprint. Invalid measurements use an estimate, minimum applies before detail height, positions are ordered prefixes, and stale row measurements are pruned.

split: open-access


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

N = 1
observations = []
def solve(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if False: chosen=anchor
    else:
        following=old_ids[old_ids.index(anchor)+1:] if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in new_columns[:ci])+(max(0,min(column_inset,new_columns[ci]['width']-1)) if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if anchor in new_ids[:1]: chosen=anchor
    else:
        following=old_ids[old_ids.index(anchor)+1:] if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in new_columns[:ci])+(max(0,min(column_inset,new_columns[ci]['width']-1)) if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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 anchor survival result violates the stipulated table viewport anchor restoration contract.

Restore a table viewport by stable row and column anchors after structural changes. A removed row chooses its next surviving former successor or final row, resets its inset, clamps surviving insets to new sizes, and clamps vertical scroll to the viewport extent.

split: open-access


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

N = 1
observations = []
def solve(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if anchor in new_ids: chosen=anchor
    else:
        following=old_ids[:old_ids.index(anchor)] if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in new_columns[:ci])+(max(0,min(column_inset,new_columns[ci]['width']-1)) if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if anchor in new_ids: chosen=anchor
    else:
        following=list(reversed(old_ids)) if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in new_columns[:ci])+(max(0,min(column_inset,new_columns[ci]['width']-1)) if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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 successor fallback result violates the stipulated table viewport anchor restoration contract.

Restore a table viewport by stable row and column anchors after structural changes. A removed row chooses its next surviving former successor or final row, resets its inset, clamps surviving insets to new sizes, and clamps vertical scroll to the viewport extent.

split: open-access