FAILURE MAP
← Case archive

FA-75486 / Text diff and three-way merge / Open access

Conflict marker resolution: an unclosed conflict silently drops its lines · case 01

A truncated file resolves without error and loses the text of the open conflict.

Verified by executionVariant 1 · 10 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The end-of-input check for an open conflict block is missing.

VERIFIED REPAIR

Report an error when input ends inside a conflict block.

Unsuccessful approach: Flushing ours at end of input hides the truncation instead of reporting it.

Case contract

Scan lines for conflict blocks. A marker is exactly seven marker characters, alone or followed by a space and a label: "<" opens, "|" starts the optional base section, a line of exactly seven "=" separates, ">" closes. Each closed block is replaced by ours, theirs, ours followed by theirs (union, no dedupe) or base. An unclosed block yields {"error": "unterminated conflict"}. Return the lines and the number of conflicts.

Why this case matters

Merge drivers and editors resolve conflict blocks by parsing marker lines that must not be confused with file content.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(lines, strategy):
    out = []
    state = None
    o, b, t = [], [], []
    count = 0
    def marker(line, ch):
        return line == ch * 7 or line.startswith(ch * 7 + ' ')
    for line in lines:
        if state is None:
            if marker(line, '<'):
                state = 'o'
                o, b, t = [], [], []
            else:
                out.append(line)
        elif state == 'o' and marker(line, '|'):
            state = 'b'
        elif state in ('o', 'b') and line == '=' * 7:
            state = 't'
        elif state == 't' and marker(line, '>'):
            count += 1
            out.extend({'ours': o, 'theirs': t, 'union': o + t, 'base': b}[strategy])
            state = None
        else:
            {'o': o, 'b': b, 't': t}[state].append(line)
    if False:
        return {'error': 'unterminated conflict', 'conflicts': count}
    return {'lines': out, 'conflicts': count}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z1', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z1'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b1', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b1'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4'], 'conflicts': 2})],
    2: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z2', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z2'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b2', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b2'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4'], 'conflicts': 3})],
    3: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z3', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z3'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b3', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b3'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4'], 'conflicts': 4})],
    4: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z4', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z4'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b4', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b4'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4', '4'], 'conflicts': 5})],
    5: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z5', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z5'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b5', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b5'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4', '4', '4'], 'conflicts': 6})],
}[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)
Boundary fixtureActualExpectedOutcome
take ours{'conflicts': 1, 'lines': ['h', 'o1', 'z']}{'conflicts': 1, 'lines': ['h', 'o1', 'z']}Passed
take theirs with base section{'conflicts': 1, 'lines': ['h', 't1', 't2']}{'conflicts': 1, 'lines': ['h', 't1', 't2']}Passed
union keeps both in order{'conflicts': 1, 'lines': ['x', 'y', 'y', 'z1']}{'conflicts': 1, 'lines': ['x', 'y', 'y', 'z1']}Passed
base strategy{'conflicts': 1, 'lines': ['b1']}{'conflicts': 1, 'lines': ['b1']}Passed
long marker-like content lines{'conflicts': 1, 'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>']}{'conflicts': 1, 'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>']}Passed
marker prefix glued to text{'conflicts': 1, 'lines': ['<<<<<<<x', 'b']}{'conflicts': 1, 'lines': ['<<<<<<<x', 'b']}Passed
setext underline inside ours{'conflicts': 1, 'lines': ['Title', '========']}{'conflicts': 1, 'lines': ['Title', '========']}Passed
indented separator-like line{'conflicts': 1, 'lines': [' =======', 'k', 't']}{'conflicts': 1, 'lines': [' =======', 'k', 't']}Passed
unterminated conflict is an error{'conflicts': 0, 'lines': ['a']}{'conflicts': 0, 'error': 'unterminated conflict'}Failed
two conflicts{'conflicts': 2, 'lines': ['2', 'mid', '4']}{'conflicts': 2, 'lines': ['2', 'mid', '4']}Passed

SHA-256 / 97a6c2b15f3b732498b9e54898ede5a01f91a857995b05b5117f90a1773db681

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(lines, strategy):
    out = []
    state = None
    o, b, t = [], [], []
    count = 0
    def marker(line, ch):
        return line == ch * 7 or line.startswith(ch * 7 + ' ')
    for line in lines:
        if state is None:
            if marker(line, '<'):
                state = 'o'
                o, b, t = [], [], []
            else:
                out.append(line)
        elif state == 'o' and marker(line, '|'):
            state = 'b'
        elif state in ('o', 'b') and line == '=' * 7:
            state = 't'
        elif state == 't' and marker(line, '>'):
            count += 1
            out.extend({'ours': o, 'theirs': t, 'union': o + t, 'base': b}[strategy])
            state = None
        else:
            {'o': o, 'b': b, 't': t}[state].append(line)
    if state is not None:
        out.extend(o)
    return {'lines': out, 'conflicts': count}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z1', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z1'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b1', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b1'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4'], 'conflicts': 2})],
    2: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z2', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z2'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b2', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b2'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4'], 'conflicts': 3})],
    3: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z3', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z3'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b3', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b3'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4'], 'conflicts': 4})],
    4: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z4', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z4'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b4', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b4'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4', '4'], 'conflicts': 5})],
    5: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z5', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z5'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b5', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b5'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4', '4', '4'], 'conflicts': 6})],
}[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)
Boundary fixtureActualExpectedOutcome
take ours{'conflicts': 1, 'lines': ['h', 'o1', 'z']}{'conflicts': 1, 'lines': ['h', 'o1', 'z']}Passed
take theirs with base section{'conflicts': 1, 'lines': ['h', 't1', 't2']}{'conflicts': 1, 'lines': ['h', 't1', 't2']}Passed
union keeps both in order{'conflicts': 1, 'lines': ['x', 'y', 'y', 'z1']}{'conflicts': 1, 'lines': ['x', 'y', 'y', 'z1']}Passed
base strategy{'conflicts': 1, 'lines': ['b1']}{'conflicts': 1, 'lines': ['b1']}Passed
long marker-like content lines{'conflicts': 1, 'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>']}{'conflicts': 1, 'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>']}Passed
marker prefix glued to text{'conflicts': 1, 'lines': ['<<<<<<<x', 'b']}{'conflicts': 1, 'lines': ['<<<<<<<x', 'b']}Passed
setext underline inside ours{'conflicts': 1, 'lines': ['Title', '========']}{'conflicts': 1, 'lines': ['Title', '========']}Passed
indented separator-like line{'conflicts': 1, 'lines': [' =======', 'k', 't']}{'conflicts': 1, 'lines': [' =======', 'k', 't']}Passed
unterminated conflict is an error{'conflicts': 0, 'lines': ['a', 'o']}{'conflicts': 0, 'error': 'unterminated conflict'}Failed
two conflicts{'conflicts': 2, 'lines': ['2', 'mid', '4']}{'conflicts': 2, 'lines': ['2', 'mid', '4']}Passed

SHA-256 / 0f4b52930c8c7f9e1977f9bd0a912bf665a57518369ebaf4b3784b27f0bdd0d8

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(lines, strategy):
    out = []
    state = None
    o, b, t = [], [], []
    count = 0
    def marker(line, ch):
        return line == ch * 7 or line.startswith(ch * 7 + ' ')
    for line in lines:
        if state is None:
            if marker(line, '<'):
                state = 'o'
                o, b, t = [], [], []
            else:
                out.append(line)
        elif state == 'o' and marker(line, '|'):
            state = 'b'
        elif state in ('o', 'b') and line == '=' * 7:
            state = 't'
        elif state == 't' and marker(line, '>'):
            count += 1
            out.extend({'ours': o, 'theirs': t, 'union': o + t, 'base': b}[strategy])
            state = None
        else:
            {'o': o, 'b': b, 't': t}[state].append(line)
    if state is not None:
        return {'error': 'unterminated conflict', 'conflicts': count}
    return {'lines': out, 'conflicts': count}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z1', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z1'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b1', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b1'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4'], 'conflicts': 2})],
    2: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z2', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z2'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b2', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b2'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4'], 'conflicts': 3})],
    3: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z3', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z3'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b3', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b3'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4'], 'conflicts': 4})],
    4: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z4', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z4'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b4', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b4'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4', '4'], 'conflicts': 5})],
    5: [('take ours', [['h', '<<<<<<< ours', 'o1', '=======', 't1', '>>>>>>> theirs', 'z'], 'ours'], {'lines': ['h', 'o1', 'z'], 'conflicts': 1}), ('take theirs with base section', [['h', '<<<<<<< ours', 'o1', '||||||| base', 'b1', '=======', 't1', 't2', '>>>>>>> theirs'], 'theirs'], {'lines': ['h', 't1', 't2'], 'conflicts': 1}), ('union keeps both in order', [['<<<<<<< ours', 'x', 'y', '=======', 'y', 'z5', '>>>>>>> theirs'], 'union'], {'lines': ['x', 'y', 'y', 'z5'], 'conflicts': 1}), ('base strategy', [['<<<<<<<', 'o', '|||||||', 'b5', '=======', 't', '>>>>>>>'], 'base'], {'lines': ['b5'], 'conflicts': 1}), ('long marker-like content lines', [['<<<<<<<<<< banner', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs', '>>>>>>>>'], 'ours'], {'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>'], 'conflicts': 1}), ('marker prefix glued to text', [['<<<<<<<x', '<<<<<<< ours', 'a', '=======', 'b', '>>>>>>> theirs'], 'theirs'], {'lines': ['<<<<<<<x', 'b'], 'conflicts': 1}), ('setext underline inside ours', [['<<<<<<< ours', 'Title', '========', '=======', 'T', '>>>>>>> theirs'], 'ours'], {'lines': ['Title', '========'], 'conflicts': 1}), ('indented separator-like line', [['<<<<<<< ours', '  =======', 'k', '=======', 't', '>>>>>>> theirs'], 'union'], {'lines': ['  =======', 'k', 't'], 'conflicts': 1}), ('unterminated conflict is an error', [['a', '<<<<<<< ours', 'o', '=======', 't'], 'ours'], {'error': 'unterminated conflict', 'conflicts': 0}), ('two conflicts', [['<<<<<<< ours', '1', '=======', '2', '>>>>>>> theirs', 'mid', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs', '<<<<<<< ours', '3', '||||||| base', 'b', '=======', '4', '>>>>>>> theirs'], 'theirs'], {'lines': ['2', 'mid', '4', '4', '4', '4', '4'], 'conflicts': 6})],
}[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)
Boundary fixtureActualExpectedOutcome
take ours{'conflicts': 1, 'lines': ['h', 'o1', 'z']}{'conflicts': 1, 'lines': ['h', 'o1', 'z']}Passed
take theirs with base section{'conflicts': 1, 'lines': ['h', 't1', 't2']}{'conflicts': 1, 'lines': ['h', 't1', 't2']}Passed
union keeps both in order{'conflicts': 1, 'lines': ['x', 'y', 'y', 'z1']}{'conflicts': 1, 'lines': ['x', 'y', 'y', 'z1']}Passed
base strategy{'conflicts': 1, 'lines': ['b1']}{'conflicts': 1, 'lines': ['b1']}Passed
long marker-like content lines{'conflicts': 1, 'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>']}{'conflicts': 1, 'lines': ['<<<<<<<<<< banner', 'a', '>>>>>>>>']}Passed
marker prefix glued to text{'conflicts': 1, 'lines': ['<<<<<<<x', 'b']}{'conflicts': 1, 'lines': ['<<<<<<<x', 'b']}Passed
setext underline inside ours{'conflicts': 1, 'lines': ['Title', '========']}{'conflicts': 1, 'lines': ['Title', '========']}Passed
indented separator-like line{'conflicts': 1, 'lines': [' =======', 'k', 't']}{'conflicts': 1, 'lines': [' =======', 'k', 't']}Passed
unterminated conflict is an error{'conflicts': 0, 'error': 'unterminated conflict'}{'conflicts': 0, 'error': 'unterminated conflict'}Passed
two conflicts{'conflicts': 2, 'lines': ['2', 'mid', '4']}{'conflicts': 2, 'lines': ['2', 'mid', '4']}Passed

SHA-256 / 272d15778f4f1be1a425432da1c61043bb5fa4b9e954f6cb50c73a7260c1648a

Verification & scope

A deterministic, bounded teaching model of one diff, patch or merge rule with stipulated conventions; it is not a production diff or version-control implementation and makes no claim of conformance to any specific tool. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:49:06.915523+00:00.

Case digest / 1530b52ff5814ddbc1146a1688fcf4d8bf3a3baf0531010c7e09c652d7b040c2