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

N = 1
observations = []
def solve(hunks, lines):
    res = []
    for ln in lines:
        shift = 0
        out = ln
        for os_, ol, ns, nl in hunks:
            s = os_ if ol > 0 else os_ + 1
            if ln < s:
                break
            if ln < s + ol:
                out = None
                break
            shift += ol - nl
        res.append(None if out is None else ln + shift)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 1]], [5, 6, 7]], [5, 7, 8]), ('pure deletion', [[[3, 1, 2, 0]], [2, 3, 3, 4, 10]], [2, None, None, 3, 9]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 1]], [1, 1])],
    2: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 2]], [5, 6, 7]], [5, 8, 9]), ('pure deletion', [[[3, 2, 2, 0]], [2, 3, 4, 5, 10]], [2, None, None, 3, 8]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 2]], [1, 2])],
    3: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 3]], [5, 6, 7]], [5, 9, 10]), ('pure deletion', [[[3, 3, 2, 0]], [2, 3, 5, 6, 10]], [2, None, None, 3, 7]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 3]], [1, 3])],
    4: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 4]], [5, 6, 7]], [5, 10, 11]), ('pure deletion', [[[3, 4, 2, 0]], [2, 3, 6, 7, 10]], [2, None, None, 3, 6]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 4]], [1, 4])],
    5: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 5]], [5, 6, 7]], [5, 11, 12]), ('pure deletion', [[[3, 5, 2, 0]], [2, 3, 7, 8, 10]], [2, None, None, 3, 5]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 5]], [1, 5])],
}[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(hunks, lines):
    res = []
    for ln in lines:
        shift = 0
        out = ln
        for os_, ol, ns, nl in hunks:
            s = os_ if ol > 0 else os_ + 1
            if ln < s:
                break
            if ln < s + ol:
                out = None
                break
            shift += nl
        res.append(None if out is None else ln + shift)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 1]], [5, 6, 7]], [5, 7, 8]), ('pure deletion', [[[3, 1, 2, 0]], [2, 3, 3, 4, 10]], [2, None, None, 3, 9]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 1]], [1, 1])],
    2: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 2]], [5, 6, 7]], [5, 8, 9]), ('pure deletion', [[[3, 2, 2, 0]], [2, 3, 4, 5, 10]], [2, None, None, 3, 8]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 2]], [1, 2])],
    3: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 3]], [5, 6, 7]], [5, 9, 10]), ('pure deletion', [[[3, 3, 2, 0]], [2, 3, 5, 6, 10]], [2, None, None, 3, 7]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 3]], [1, 3])],
    4: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 4]], [5, 6, 7]], [5, 10, 11]), ('pure deletion', [[[3, 4, 2, 0]], [2, 3, 6, 7, 10]], [2, None, None, 3, 6]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 4]], [1, 4])],
    5: [('lines before and after a replacement', [[[5, 2, 5, 3]], [4, 5, 6, 7, 8]], [4, None, None, 8, 9]), ('pure insertion after line five', [[[5, 0, 6, 5]], [5, 6, 7]], [5, 11, 12]), ('pure deletion', [[[3, 5, 2, 0]], [2, 3, 7, 8, 10]], [2, None, None, 3, 5]), ('insertion at the top of the file', [[[0, 0, 1, 2]], [1, 2]], [3, 4]), ('several hunks accumulate', [[[2, 1, 2, 2], [10, 3, 11, 1], [20, 0, 19, 4]], [1, 2, 3, 9, 10, 13, 20, 21]], [1, None, 4, 10, None, 12, 19, 24]), ('line just after a hunk', [[[7, 2, 7, 5]], [8, 9, 10]], [None, 12, 13]), ('last line of a deletion', [[[4, 3, 3, 0]], [6, 7]], [None, 4]), ('no hunks', [[], [1, 5]], [1, 5])],
}[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:
Comments move up after insertions and down after deletions.

Hunks [old_start, old_len, new_start, new_len] use unified conventions (start is the line before when the length is 0) and are sorted. An old line maps to None if it lies in a hunk's old range; otherwise it moves by the sum of new_len - old_len over hunks entirely before it. A zero-length hunk after line s affects lines from s+1 on. Return the mapped line numbers.

split: open-access


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

N = 1
observations = []
def solve(base, ours, theirs):
    MISSING = object()
    merged, conflicts = {}, []
    for k in sorted(set(base) | set(ours) | set(theirs)):
        b = base.get(k)
        o = ours.get(k)
        t = theirs.get(k)
        if o == t:
            r = o
        elif o == b:
            r = t
        elif t == b:
            r = o
        else:
            conflicts.append(k)
            r = o
        if r is not MISSING:
            merged[k] = r
    return {'merged': sorted([k, v] for k, v in merged.items()), 'conflicts': conflicts}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '81', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '81']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z1'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z1'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e1'}], {'merged': [['extra', 'e1'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm1'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm1'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    2: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '82', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '82']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z2'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z2'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e2'}], {'merged': [['extra', 'e2'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm2'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm2'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    3: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '83', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '83']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z3'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z3'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e3'}], {'merged': [['extra', 'e3'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm3'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm3'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    4: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '84', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '84']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z4'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z4'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e4'}], {'merged': [['extra', 'e4'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm4'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm4'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    5: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '85', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '85']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z5'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z5'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e5'}], {'merged': [['extra', 'e5'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm5'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm5'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
}[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(base, ours, theirs):
    MISSING = object()
    merged, conflicts = {}, []
    for k in sorted(set(base) | set(ours) | set(theirs)):
        b = base.get(k, MISSING)
        o = ours.get(k)
        t = theirs.get(k)
        if o == t:
            r = o
        elif o == b:
            r = t
        elif t == b:
            r = o
        else:
            conflicts.append(k)
            r = o
        if r is not MISSING:
            merged[k] = r
    return {'merged': sorted([k, v] for k, v in merged.items()), 'conflicts': conflicts}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '81', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '81']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z1'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z1'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e1'}], {'merged': [['extra', 'e1'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm1'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm1'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    2: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '82', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '82']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z2'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z2'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e2'}], {'merged': [['extra', 'e2'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm2'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm2'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    3: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '83', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '83']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z3'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z3'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e3'}], {'merged': [['extra', 'e3'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm3'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm3'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    4: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '84', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '84']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z4'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z4'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e4'}], {'merged': [['extra', 'e4'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm4'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm4'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    5: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '85', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '85']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z5'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z5'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e5'}], {'merged': [['extra', 'e5'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm5'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm5'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
}[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:
Setting a value to null is merged as a deletion, and a deleted key can come back as null.

Merge base, ours and theirs maps key by key over the union of keys; an absent key and a key holding null are different states. If ours and theirs agree, take that state; else if ours equals base take theirs; else if theirs equals base take ours; otherwise record a conflict and keep ours. Return sorted merged [key, value] pairs and sorted conflicting keys.

split: open-access


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

N = 1
observations = []
def solve(base, ours, theirs):
    MISSING = object()
    merged, conflicts = {}, []
    for k in sorted(set(base) | set(ours) | set(theirs)):
        b = base.get(k, MISSING)
        o = ours.get(k, MISSING)
        t = theirs.get(k, MISSING)
        if o == b:
            r = t
        elif t == b:
            r = o
        else:
            conflicts.append(k)
            r = o
        if r is not MISSING:
            merged[k] = r
    return {'merged': sorted([k, v] for k, v in merged.items()), 'conflicts': conflicts}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '81', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '81']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z1'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z1'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e1'}], {'merged': [['extra', 'e1'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm1'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm1'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    2: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '82', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '82']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z2'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z2'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e2'}], {'merged': [['extra', 'e2'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm2'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm2'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    3: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '83', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '83']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z3'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z3'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e3'}], {'merged': [['extra', 'e3'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm3'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm3'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    4: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '84', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '84']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z4'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z4'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e4'}], {'merged': [['extra', 'e4'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm4'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm4'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    5: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '85', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '85']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z5'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z5'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e5'}], {'merged': [['extra', 'e5'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm5'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm5'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
}[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(base, ours, theirs):
    MISSING = object()
    merged, conflicts = {}, []
    for k in sorted(set(base) | set(ours) | set(theirs)):
        b = base.get(k, MISSING)
        o = ours.get(k, MISSING)
        t = theirs.get(k, MISSING)
        if o == t and o is not MISSING:
            r = o
        elif o == b:
            r = t
        elif t == b:
            r = o
        else:
            conflicts.append(k)
            r = o
        if r is not MISSING:
            merged[k] = r
    return {'merged': sorted([k, v] for k, v in merged.items()), 'conflicts': conflicts}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '81', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '81']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z1'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z1'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e1'}], {'merged': [['extra', 'e1'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm1'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm1'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    2: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '82', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '82']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z2'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z2'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e2'}], {'merged': [['extra', 'e2'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm2'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm2'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    3: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '83', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '83']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z3'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z3'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e3'}], {'merged': [['extra', 'e3'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm3'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm3'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    4: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '84', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '84']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z4'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z4'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e4'}], {'merged': [['extra', 'e4'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm4'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm4'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    5: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '85', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '85']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z5'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z5'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e5'}], {'merged': [['extra', 'e5'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm5'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm5'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
}[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:
Both branches set the same new value and the merge still reports a conflict.

Merge base, ours and theirs maps key by key over the union of keys; an absent key and a key holding null are different states. If ours and theirs agree, take that state; else if ours equals base take theirs; else if theirs equals base take ours; otherwise record a conflict and keep ours. Return sorted merged [key, value] pairs and sorted conflicting keys.

split: open-access


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

N = 1
observations = []
def solve(base, ours, theirs):
    MISSING = object()
    merged, conflicts = {}, []
    for k in sorted(set(base) | set(ours) | set(theirs)):
        b = base.get(k, MISSING)
        o = ours.get(k, MISSING)
        t = theirs.get(k, MISSING)
        if o == t:
            r = o
        elif o == b:
            r = t
        elif t == b:
            r = o
        elif t is MISSING:
            r = t
        else:
            conflicts.append(k)
            r = o
        if r is not MISSING:
            merged[k] = r
    return {'merged': sorted([k, v] for k, v in merged.items()), 'conflicts': conflicts}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '81', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '81']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z1'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z1'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e1'}], {'merged': [['extra', 'e1'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm1'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm1'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    2: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '82', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '82']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z2'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z2'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e2'}], {'merged': [['extra', 'e2'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm2'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm2'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    3: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '83', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '83']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z3'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z3'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e3'}], {'merged': [['extra', 'e3'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm3'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm3'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    4: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '84', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '84']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z4'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z4'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e4'}], {'merged': [['extra', 'e4'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm4'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm4'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    5: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '85', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '85']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z5'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z5'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e5'}], {'merged': [['extra', 'e5'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm5'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm5'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
}[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(base, ours, theirs):
    MISSING = object()
    merged, conflicts = {}, []
    for k in sorted(set(base) | set(ours) | set(theirs)):
        b = base.get(k, MISSING)
        o = ours.get(k, MISSING)
        t = theirs.get(k, MISSING)
        if o == t:
            r = o
        elif o == b:
            r = t
        elif t == b:
            r = o
        elif t is MISSING or o is MISSING:
            r = o if o is not MISSING else t
        else:
            conflicts.append(k)
            r = o
        if r is not MISSING:
            merged[k] = r
    return {'merged': sorted([k, v] for k, v in merged.items()), 'conflicts': conflicts}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '81', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '81']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z1'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z1'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e1'}], {'merged': [['extra', 'e1'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm1'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm1'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    2: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '82', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '82']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z2'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z2'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e2'}], {'merged': [['extra', 'e2'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm2'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm2'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    3: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '83', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '83']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z3'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z3'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e3'}], {'merged': [['extra', 'e3'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm3'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm3'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    4: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '84', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '84']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z4'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z4'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e4'}], {'merged': [['extra', 'e4'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm4'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm4'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
    5: [('each side changes a different key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'b', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '85', 'mode': 'x'}], {'merged': [['host', 'b'], ['mode', 'x'], ['port', '85']], 'conflicts': []}), ('both change a key the same way', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'y'}, {'host': 'a', 'port': '80', 'mode': 'y'}], {'merged': [['host', 'a'], ['mode', 'y'], ['port', '80']], 'conflicts': []}), ('both delete the same key', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['port', '80']], 'conflicts': []}), ('conflicting changes keep ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '1', 'mode': 'x'}, {'host': 'a', 'port': '2', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x'], ['port', '1']], 'conflicts': ['port']}), ('delete versus modify conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'z5'}, {'host': 'a', 'port': '80'}], {'merged': [['host', 'a'], ['mode', 'z5'], ['port', '80']], 'conflicts': ['mode']}), ('explicit null differs from deletion', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': None}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', None], ['port', '80']], 'conflicts': []}), ('key added only by theirs', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'extra': 'e5'}], {'merged': [['extra', 'e5'], ['host', 'a'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('key added only by ours', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'port': '80', 'mode': 'x', 'mine': 'm5'}, {'host': 'a', 'port': '80', 'mode': 'x'}], {'merged': [['host', 'a'], ['mine', 'm5'], ['mode', 'x'], ['port', '80']], 'conflicts': []}), ('modify versus delete conflicts', [{'host': 'a', 'port': '80', 'mode': 'x'}, {'host': 'a', 'mode': 'x'}, {'host': 'a', 'port': '443', 'mode': 'x'}], {'merged': [['host', 'a'], ['mode', 'x']], 'conflicts': ['port']}), ('null in base and deleted by ours', [{'k': None, 'j': '1'}, {'j': '1'}, {'k': None, 'j': '2'}], {'merged': [['j', '2']], 'conflicts': []})],
}[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:
A key modified on our branch and deleted on theirs disappears without a conflict.

Merge base, ours and theirs maps key by key over the union of keys; an absent key and a key holding null are different states. If ours and theirs agree, take that state; else if ours equals base take theirs; else if theirs equals base take ours; otherwise record a conflict and keep ours. Return sorted merged [key, value] pairs and sorted conflicting keys.

split: open-access