FA-75471 / Text diff and three-way merge / Open access
Conflict marker resolution: the base section is read as part of ours · case 01
Resolving to ours includes the base marker and the original text.
ROOT CAUSE
The base marker is not recognized, so it and the base lines stay in the ours section.
VERIFIED REPAIR
Switch to the base section at the base marker and collect base lines separately.
Unsuccessful approach: Swallowing the base marker without switching sections still leaves base lines inside ours.
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 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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': []} | {'conflicts': 1, 'lines': ['b1']} | Failed |
| 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 / 7646dba09dee55eb2718bdf5a2cf6b3f4a9435fb308cc5fa8aca1073f0a8bfd1
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, '|'):
pass
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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': []} | {'conflicts': 1, 'lines': ['b1']} | Failed |
| 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 / e22980cd5a60e0faa07b48124f9fed2fd8c651bc34c6fff30372e2ad554dc53a
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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.791120+00:00.
Case digest / 66f3aa5019b97b8a061dce832ec7cefd0adc911d117c493ad2f368370889430d