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

N = 1
observations = []
def solve(lines, recorded):
    out = []
    state = None
    o, t = [], []
    unresolved = 0
    for ln in lines:
        if state is None:
            if ln.startswith('<<<<<<<'):
                state = 'o'
                o, t = [], []
            else:
                out.append(ln)
        elif state == 'o' and ln.startswith('|||||||'):
            state = 'b'
        elif state in ('o', 'b') and ln == '=======':
            state = 't'
        elif state == 't' and ln.startswith('>>>>>>>'):
            key = sorted([o, t])
            match = next((r[2] for r in recorded if sorted([r[0], r[1]]) == key), None)
            if match is not None:
                out.extend(match)
            else:
                unresolved += 1
                pass
            state = None
        elif state == 'o':
            o.append(ln)
        elif state == 't':
            t.append(ln)
    return {'lines': out, 'unresolved': unresolved}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic1'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p1', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p1', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    2: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic2'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p2', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p2', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    3: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic3'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p3', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p3', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    4: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic4'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p4', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p4', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    5: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic5'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p5', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p5', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(lines, recorded):
    out = []
    state = None
    o, t = [], []
    unresolved = 0
    for ln in lines:
        if state is None:
            if ln.startswith('<<<<<<<'):
                state = 'o'
                o, t = [], []
            else:
                out.append(ln)
        elif state == 'o' and ln.startswith('|||||||'):
            state = 'b'
        elif state in ('o', 'b') and ln == '=======':
            state = 't'
        elif state == 't' and ln.startswith('>>>>>>>'):
            key = sorted([o, t])
            match = next((r[2] for r in recorded if sorted([r[0], r[1]]) == key), None)
            if match is not None:
                out.extend(match)
            else:
                unresolved += 1
                out.extend(o)
            state = None
        elif state == 'o':
            o.append(ln)
        elif state == 't':
            t.append(ln)
    return {'lines': out, 'unresolved': unresolved}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic1'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p1', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p1', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    2: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic2'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p2', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p2', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    3: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic3'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p3', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p3', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    4: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic4'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p4', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p4', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
    5: [('recorded resolution reused', [['pre', '<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'post'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['pre', 'x = 3', 'post'], 'unresolved': 0}), ('sides swapped still match', [['<<<<<<< HEAD', 'x = 2', '=======', 'x = 1', '>>>>>>> topic5'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0}), ('base section does not affect the fingerprint', [['<<<<<<< ours', 'c', '||||||| base', 'orig', '=======', 'a', 'b', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('unknown conflict stays unresolved', [['<<<<<<< ours', 'p5', '=======', 'q', '>>>>>>> theirs', 'tail'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['<<<<<<<', 'p5', '=======', 'q', '>>>>>>>', 'tail'], 'unresolved': 1}), ('unlabelled markers', [['<<<<<<<', 'a', 'b', '=======', 'c', '>>>>>>>'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['abc'], 'unresolved': 0}), ('two conflicts, one known', [['<<<<<<< ours', 'x = 1', '=======', 'x = 2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', 'm', '=======', 'n', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3', 'mid', '<<<<<<<', 'm', '=======', 'n', '>>>>>>>'], 'unresolved': 1}), ('labelled base marker', [['<<<<<<< ours', 'x = 2', '||||||| base', 'x = 0', '=======', 'x = 1', '>>>>>>> theirs'], [[['x = 1'], ['x = 2'], ['x = 3']], [['a', 'b'], ['c'], ['abc']]]], {'lines': ['x = 3'], 'unresolved': 0})],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Conflicts with no recorded resolution vanish from the file along with both sides.

Scan conflict blocks ("<<<<<<<" optionally followed by a label, optional "|||||||" base section, "=======", ">>>>>>>" optionally labelled). A block matches a recorded [side1, side2, resolution] when its two sides equal the recorded sides in either order; base lines are ignored. Matched blocks are replaced by the resolution; unmatched blocks are re-emitted as bare "<<<<<<<", ours, "=======", theirs, ">>>>>>>" and counted. Return lines and the unresolved count.

split: open-access


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

N = 1
observations = []
def solve(names, width):
    res = []
    for name in names:
        if len(name) < width:
            res.append(name)
            continue
        keep = width - 3
        tail = name[len(name) - keep:] if keep > 0 else ''
        slash = tail.find('/')
        if slash >= 0:
            tail = tail[slash:]
        res.append('...' + tail)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    2: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    3: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    4: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    5: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(names, width):
    res = []
    for name in names:
        if len(name) <= width - 3:
            res.append(name)
            continue
        keep = width - 3
        tail = name[len(name) - keep:] if keep > 0 else ''
        slash = tail.find('/')
        if slash >= 0:
            tail = tail[slash:]
        res.append('...' + tail)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    2: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    3: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    4: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    5: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Paths that would fit are shortened with an ellipsis.

A path longer than width is shown as "..." plus its last width-3 characters, further shortened to start at the first "/" inside that tail when there is one (keeping the slash). Paths not longer than width are unchanged.

split: open-access


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

N = 1
observations = []
def solve(names, width):
    res = []
    for name in names:
        if len(name) <= width:
            res.append(name)
            continue
        keep = width
        tail = name[len(name) - keep:] if keep > 0 else ''
        slash = tail.find('/')
        if slash >= 0:
            tail = tail[slash:]
        res.append('...' + tail)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    2: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    3: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    4: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    5: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(names, width):
    res = []
    for name in names:
        if len(name) <= width:
            res.append(name)
            continue
        keep = width - 2
        tail = name[len(name) - keep:] if keep > 0 else ''
        slash = tail.find('/')
        if slash >= 0:
            tail = tail[slash:]
        res.append('...' + tail)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    2: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    3: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    4: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    5: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Truncated paths are three characters wider than the column.

A path longer than width is shown as "..." plus its last width-3 characters, further shortened to start at the first "/" inside that tail when there is one (keeping the slash). Paths not longer than width are unchanged.

split: open-access


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

N = 1
observations = []
def solve(names, width):
    res = []
    for name in names:
        if len(name) <= width:
            res.append(name)
            continue
        keep = width - 3
        tail = name[len(name) - keep:] if keep > 0 else ''
        slash = tail.find('/')
        if slash >= 0:
            tail = tail[slash + 1:]
        res.append('...' + tail)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    2: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    3: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    4: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    5: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(names, width):
    res = []
    for name in names:
        if len(name) <= width:
            res.append(name)
            continue
        keep = width - 3
        tail = name[len(name) - keep:] if keep > 0 else ''
        slash = tail.rfind('/')
        if slash >= 0:
            tail = tail[slash:]
        res.append('...' + tail)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    2: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    3: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    4: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
    5: [('short name unchanged', [['src/a.c'], 20], ['src/a.c']), ('name exactly the width', [['abcdefghij'], 10], ['abcdefghij']), ('long name cut at a directory boundary', [['src/module/deep/file_name.py'], 18], ['.../file_name.py']), ('no slash in the kept tail', [['averyveryverylongfilename.txt'], 12], ['...ename.txt']), ('several names', [['a/b/c/d/e/f/g/h.txt', 'x.c', 'dir/yyyyyyyyyyyyyyy'], 12], ['.../g/h.txt', 'x.c', '...yyyyyyyyy']), ('tail starts exactly at a slash', [['aaaa/bbbb/cc'], 8], ['.../cc']), ('width just above the name', [['p/q/r.txt'], 10], ['p/q/r.txt'])],
}[N]
for label, args, expected in cases:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Truncated paths read "...file.py" instead of ".../file.py", hiding that a directory was cut.

A path longer than width is shown as "..." plus its last width-3 characters, further shortened to start at the first "/" inside that tail when there is one (keeping the slash). Paths not longer than width are unchanged.

split: open-access


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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: m['ts']):
        key = m['seq']
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['nonce'] for m in rows if m.get('nonce')}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: (p['created'], p['nonce']))
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: (m['ts'], m['seq'])):
        key = m['seq']
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['nonce'] for m in rows if m.get('nonce')}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: (p['created'], p['nonce']))
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Messages relayed by a lagging edge node with an earlier wall-clock stamp jump ahead of messages the server sequenced first.

confirmed holds server messages {id, seq, ts, optional nonce}; the server seq is the only authority for order and a redelivered copy (same seq, possibly another gateway ts) is shown once (first copy kept). pending holds local unsent messages {nonce, created}; a pending message whose nonce was echoed back by any confirmed message is dropped. Result: confirmed ids in seq order, then local:<nonce> for the remaining pending sends ordered by (created, nonce).

split: open-access


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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: m['seq']):
        key = (m['seq'], m['ts'])
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['nonce'] for m in rows if m.get('nonce')}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: (p['created'], p['nonce']))
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: m['seq']):
        key = (m['seq'], m['ts'] // 1000)
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['nonce'] for m in rows if m.get('nonce')}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: (p['created'], p['nonce']))
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A message redelivered through a second gateway, which stamps its own receive time, is rendered twice.

confirmed holds server messages {id, seq, ts, optional nonce}; the server seq is the only authority for order and a redelivered copy (same seq, possibly another gateway ts) is shown once (first copy kept). pending holds local unsent messages {nonce, created}; a pending message whose nonce was echoed back by any confirmed message is dropped. Result: confirmed ids in seq order, then local:<nonce> for the remaining pending sends ordered by (created, nonce).

split: open-access


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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: m['seq']):
        key = m['seq']
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['id'] for m in rows}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: (p['created'], p['nonce']))
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: m['seq']):
        key = m['seq']
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['nonce'] for m in rows[-1:] if m.get('nonce')}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: (p['created'], p['nonce']))
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A local send that the server already echoed back stays visible as a pending duplicate bubble.

confirmed holds server messages {id, seq, ts, optional nonce}; the server seq is the only authority for order and a redelivered copy (same seq, possibly another gateway ts) is shown once (first copy kept). pending holds local unsent messages {nonce, created}; a pending message whose nonce was echoed back by any confirmed message is dropped. Result: confirmed ids in seq order, then local:<nonce> for the remaining pending sends ordered by (created, nonce).

split: open-access


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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: m['seq']):
        key = m['seq']
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['nonce'] for m in rows if m.get('nonce')}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: p['nonce'])
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(confirmed, pending):
    seen = set()
    rows = []
    for m in sorted(confirmed, key=lambda m: m['seq']):
        key = m['seq']
        if key in seen:
            continue
        seen.add(key)
        rows.append(m)
    echoed = {m['nonce'] for m in rows if m.get('nonce')}
    tail = sorted((p for p in pending if p['nonce'] not in echoed), key=lambda p: (p['created'] // 1000, p['nonce']))
    return [m['id'] for m in rows] + ['local:' + p['nonce'] for p in tail]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 1050}, {'id': 'm1', 'seq': 1, 'ts': 1090}, {'id': 'm3', 'seq': 3, 'ts': 1095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 1000}, {'id': 'a', 'seq': 5, 'ts': 2501}, {'id': 'b', 'seq': 6, 'ts': 3600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 1, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 6}], [{'nonce': 'n1', 'created': -4}, {'nonce': 'n2', 'created': 8}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 2100}, {'nonce': 'aa', 'created': 2900}, {'nonce': 'mm', 'created': 2200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c1', 'seq': 1, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c1', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b1', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b1'])], 2: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 2050}, {'id': 'm1', 'seq': 1, 'ts': 2090}, {'id': 'm3', 'seq': 3, 'ts': 2095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 2000}, {'id': 'a', 'seq': 5, 'ts': 3502}, {'id': 'b', 'seq': 6, 'ts': 4600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 2, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 7}], [{'nonce': 'n1', 'created': -3}, {'nonce': 'n2', 'created': 9}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 3100}, {'nonce': 'aa', 'created': 3900}, {'nonce': 'mm', 'created': 3200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c2', 'seq': 2, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c2', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b2', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b2'])], 3: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 3050}, {'id': 'm1', 'seq': 1, 'ts': 3090}, {'id': 'm3', 'seq': 3, 'ts': 3095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 3000}, {'id': 'a', 'seq': 5, 'ts': 4503}, {'id': 'b', 'seq': 6, 'ts': 5600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 3, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 8}], [{'nonce': 'n1', 'created': -2}, {'nonce': 'n2', 'created': 10}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 4100}, {'nonce': 'aa', 'created': 4900}, {'nonce': 'mm', 'created': 4200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c3', 'seq': 3, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c3', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b3', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b3'])], 4: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 4050}, {'id': 'm1', 'seq': 1, 'ts': 4090}, {'id': 'm3', 'seq': 3, 'ts': 4095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 4000}, {'id': 'a', 'seq': 5, 'ts': 5504}, {'id': 'b', 'seq': 6, 'ts': 6600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 4, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 9}], [{'nonce': 'n1', 'created': -1}, {'nonce': 'n2', 'created': 11}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 5100}, {'nonce': 'aa', 'created': 5900}, {'nonce': 'mm', 'created': 5200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c4', 'seq': 4, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c4', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b4', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b4'])], 5: [('skewed edge timestamps', ([{'id': 'm2', 'seq': 2, 'ts': 5050}, {'id': 'm1', 'seq': 1, 'ts': 5090}, {'id': 'm3', 'seq': 3, 'ts': 5095}], []), ['m1', 'm2', 'm3']), ('redelivery through another gateway', ([{'id': 'a', 'seq': 5, 'ts': 5000}, {'id': 'a', 'seq': 5, 'ts': 6505}, {'id': 'b', 'seq': 6, 'ts': 7600}], []), ['a', 'b']), ('echo of an older send', ([{'id': 'x', 'seq': 1, 'ts': 5, 'nonce': 'n1'}, {'id': 'y', 'seq': 2, 'ts': 10}], [{'nonce': 'n1', 'created': 0}, {'nonce': 'n2', 'created': 12}]), ['x', 'y', 'local:n2']), ('pending within one second', ([], [{'nonce': 'zz', 'created': 6100}, {'nonce': 'aa', 'created': 6900}, {'nonce': 'mm', 'created': 6200}]), ['local:zz', 'local:mm', 'local:aa']), ('confirmed then pending', ([{'id': 'c5', 'seq': 5, 'ts': 10}], [{'nonce': 'p', 'created': 3}]), ['c5', 'local:p']), ('empty conversation', ([], []), []), ('equal creation times', ([{'id': 'k', 'seq': 9, 'ts': 1, 'nonce': 'q'}], [{'nonce': 'b5', 'created': 7}, {'nonce': 'a', 'created': 7}]), ['k', 'local:a', 'local:b5'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Unsent messages typed in quick succession appear in random nonce order instead of the order they were written.

confirmed holds server messages {id, seq, ts, optional nonce}; the server seq is the only authority for order and a redelivered copy (same seq, possibly another gateway ts) is shown once (first copy kept). pending holds local unsent messages {nonce, created}; a pending message whose nonce was echoed back by any confirmed message is dropped. Result: confirmed ids in seq order, then local:<nonce> for the remaining pending sends ordered by (created, nonce).

split: open-access