FAILURE MAP
← Case archive

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

Unified hunk builder: single-line ranges print an explicit count · case 01

Headers read "-3,1" where the convention is "-3".

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

ROOT CAUSE

The header formatter never omits a count of one.

THE FAILURE

The header formatter never omits a count of one.

Unsuccessful approach: Omitting counts of zero as well turns an empty range into a one-line range.

Case contract

Given a full edit script ([tag, line], tags " ", "-", "+") and a context width C, group changes whose separating equal lines number at most 2C, extend each group by up to C lines on both sides, and emit a header "@@ -a,b +c,d @@" followed by the hunk lines. A range start is the 1-based first line, or the line before when the count is 0; a count of 1 is omitted.

Why this case matters

Unified diff output depends on hunk grouping, context trimming and the header conventions for empty and single-line ranges.

1 / The failure

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

N = 1
observations = []
def solve(ops, context):
    changes = [i for i, op in enumerate(ops) if op[0] != ' ']
    if not changes:
        return []
    groups = []
    start = end = changes[0]
    for i in changes[1:]:
        if i - end - 1 <= 2 * context:
            end = i
        else:
            groups.append((start, end))
            start = end = i
    groups.append((start, end))
    old_no, new_no = [], []
    o = w = 0
    for tag, _ in ops:
        old_no.append(o)
        new_no.append(w)
        if tag != '+':
            o += 1
        if tag != '-':
            w += 1
    def rng(start0, count):
        first = start0 + 1 if count > 0 else start0
        return str(first) if False else '%d,%d' % (first, count)
    out = []
    for s, e in groups:
        lo = max(0, s - context)
        hi = min(len(ops) - 1, e + context)
        body = ops[lo:hi + 1]
        ol = sum(1 for t, _ in body if t != '+')
        nl = sum(1 for t, _ in body if t != '-')
        out.append('@@ -%s +%s @@' % (rng(old_no[lo], ol), rng(new_no[lo], nl)))
        out.extend(t + x for t, x in body)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0']], 3], ['@@ -0,0 +1 @@', '+x0']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 1], ['@@ -1,4 +1,4 @@', '-a', ' c0', ' c1', '+b', ' c0']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 1], ['@@ -1,2 +1 @@', '-a', ' c0', '@@ -4,2 +3,3 @@', ' c2', '+b', ' c0']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    2: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1']], 3], ['@@ -0,0 +1,2 @@', '+x0', '+x1']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 2], ['@@ -1,7 +1,7 @@', '-a', ' c0', ' c1', ' c2', ' c3', '+b', ' c0', ' c1']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 2], ['@@ -1,3 +1,2 @@', '-a', ' c0', ' c1', '@@ -5,4 +4,5 @@', ' c3', ' c4', '+b', ' c0', ' c1']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    3: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1'], ['+', 'x2']], 3], ['@@ -0,0 +1,3 @@', '+x0', '+x1', '+x2']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 3], ['@@ -1,10 +1,10 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', ' c5', '+b', ' c0', ' c1', ' c2']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 3], ['@@ -1,4 +1,3 @@', '-a', ' c0', ' c1', ' c2', '@@ -6,6 +5,7 @@', ' c4', ' c5', ' c6', '+b', ' c0', ' c1', ' c2']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    4: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1'], ['+', 'x2'], ['+', 'x3']], 3], ['@@ -0,0 +1,4 @@', '+x0', '+x1', '+x2', '+x3']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 4], ['@@ -1,12 +1,12 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', ' c5', ' c6', ' c7', '+b', ' c0', ' c1', ' c2']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], [' ', 'c8'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 4], ['@@ -1,5 +1,4 @@', '-a', ' c0', ' c1', ' c2', ' c3', '@@ -7,7 +6,8 @@', ' c5', ' c6', ' c7', ' c8', '+b', ' c0', ' c1', ' c2']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    5: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1'], ['+', 'x2'], ['+', 'x3'], ['+', 'x4']], 3], ['@@ -0,0 +1,5 @@', '+x0', '+x1', '+x2', '+x3', '+x4']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], [' ', 'c8'], [' ', 'c9'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 5], ['@@ -1,14 +1,14 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', ' c5', ' c6', ' c7', ' c8', ' c9', '+b', ' c0', ' c1', ' c2']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], [' ', 'c8'], [' ', 'c9'], [' ', 'c10'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 5], ['@@ -1,6 +1,5 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', '@@ -8,8 +7,9 @@', ' c6', ' c7', ' c8', ' c9', ' c10', '+b', ' c0', ' c1', ' c2']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
}[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
single change in the middle['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']Passed
change at the very start['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']Passed
pure insertion into an empty file['@@ -0,0 +1,1 @@', '+x0']['@@ -0,0 +1 @@', '+x0']Failed
pure deletion of every line['@@ -1,1 +0,0 @@', '-gone']['@@ -1 +0,0 @@', '-gone']Failed
two changes separated by exactly twice the context['@@ -1,4 +1,4 @@', '-a', ' c0', ' c1', '+b', ' c0']['@@ -1,4 +1,4 @@', '-a', ' c0', ' c1', '+b', ' c0']Passed
two changes separated by more than twice the context['@@ -1,2 +1,1 @@', '-a', ' c0', '@@ -4,2 +3,3 @@', ' c2', '+b', ' c0']['@@ -1,2 +1 @@', '-a', ' c0', '@@ -4,2 +3,3 @@', ' c2', '+b', ' c0']Failed
insertion after existing lines['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']Passed
single-line ranges['@@ -4,1 +4,1 @@', '-x', '+y']['@@ -4 +4 @@', '-x', '+y']Failed
no changes[][]Passed
deletion and insertion in separate hunks['@@ -2,1 +1,0 @@', '-b', '@@ -3,0 +3,1 @@', '+d']['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']Failed
deletion near the start with wide context['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2']['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2']Passed

SHA-256 / 679135d2be126892c4461774c12ad9cf3bad40b2b507905a3714fec4a5f81f16

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(ops, context):
    changes = [i for i, op in enumerate(ops) if op[0] != ' ']
    if not changes:
        return []
    groups = []
    start = end = changes[0]
    for i in changes[1:]:
        if i - end - 1 <= 2 * context:
            end = i
        else:
            groups.append((start, end))
            start = end = i
    groups.append((start, end))
    old_no, new_no = [], []
    o = w = 0
    for tag, _ in ops:
        old_no.append(o)
        new_no.append(w)
        if tag != '+':
            o += 1
        if tag != '-':
            w += 1
    def rng(start0, count):
        first = start0 + 1 if count > 0 else start0
        return str(first) if count <= 1 else '%d,%d' % (first, count)
    out = []
    for s, e in groups:
        lo = max(0, s - context)
        hi = min(len(ops) - 1, e + context)
        body = ops[lo:hi + 1]
        ol = sum(1 for t, _ in body if t != '+')
        nl = sum(1 for t, _ in body if t != '-')
        out.append('@@ -%s +%s @@' % (rng(old_no[lo], ol), rng(new_no[lo], nl)))
        out.extend(t + x for t, x in body)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0']], 3], ['@@ -0,0 +1 @@', '+x0']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 1], ['@@ -1,4 +1,4 @@', '-a', ' c0', ' c1', '+b', ' c0']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 1], ['@@ -1,2 +1 @@', '-a', ' c0', '@@ -4,2 +3,3 @@', ' c2', '+b', ' c0']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    2: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1']], 3], ['@@ -0,0 +1,2 @@', '+x0', '+x1']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 2], ['@@ -1,7 +1,7 @@', '-a', ' c0', ' c1', ' c2', ' c3', '+b', ' c0', ' c1']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 2], ['@@ -1,3 +1,2 @@', '-a', ' c0', ' c1', '@@ -5,4 +4,5 @@', ' c3', ' c4', '+b', ' c0', ' c1']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    3: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1'], ['+', 'x2']], 3], ['@@ -0,0 +1,3 @@', '+x0', '+x1', '+x2']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 3], ['@@ -1,10 +1,10 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', ' c5', '+b', ' c0', ' c1', ' c2']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 3], ['@@ -1,4 +1,3 @@', '-a', ' c0', ' c1', ' c2', '@@ -6,6 +5,7 @@', ' c4', ' c5', ' c6', '+b', ' c0', ' c1', ' c2']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    4: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1'], ['+', 'x2'], ['+', 'x3']], 3], ['@@ -0,0 +1,4 @@', '+x0', '+x1', '+x2', '+x3']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 4], ['@@ -1,12 +1,12 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', ' c5', ' c6', ' c7', '+b', ' c0', ' c1', ' c2']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], [' ', 'c8'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 4], ['@@ -1,5 +1,4 @@', '-a', ' c0', ' c1', ' c2', ' c3', '@@ -7,7 +6,8 @@', ' c5', ' c6', ' c7', ' c8', '+b', ' c0', ' c1', ' c2']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
    5: [('single change in the middle', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], ['-', 'old'], ['+', 'new'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7']], 2], ['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']), ('change at the very start', [[['-', 'first'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4']], 3], ['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']), ('pure insertion into an empty file', [[['+', 'x0'], ['+', 'x1'], ['+', 'x2'], ['+', 'x3'], ['+', 'x4']], 3], ['@@ -0,0 +1,5 @@', '+x0', '+x1', '+x2', '+x3', '+x4']), ('pure deletion of every line', [[['-', 'gone']], 1], ['@@ -1 +0,0 @@', '-gone']), ('two changes separated by exactly twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], [' ', 'c8'], [' ', 'c9'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 5], ['@@ -1,14 +1,14 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', ' c5', ' c6', ' c7', ' c8', ' c9', '+b', ' c0', ' c1', ' c2']), ('two changes separated by more than twice the context', [[['-', 'a'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5'], [' ', 'c6'], [' ', 'c7'], [' ', 'c8'], [' ', 'c9'], [' ', 'c10'], ['+', 'b'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 5], ['@@ -1,6 +1,5 @@', '-a', ' c0', ' c1', ' c2', ' c3', ' c4', '@@ -8,8 +7,9 @@', ' c6', ' c7', ' c8', ' c9', ' c10', '+b', ' c0', ' c1', ' c2']), ('insertion after existing lines', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], ['+', 'tail']], 2], ['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']), ('single-line ranges', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], ['-', 'x'], ['+', 'y'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2']], 0], ['@@ -4 +4 @@', '-x', '+y']), ('no changes', [[[' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3']], 3], []), ('deletion and insertion in separate hunks', [[[' ', 'a'], ['-', 'b'], [' ', 'c'], ['+', 'd'], [' ', 'e']], 0], ['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']), ('deletion near the start with wide context', [[[' ', 'c0'], ['-', 'd1'], ['-', 'd2'], [' ', 'c0'], [' ', 'c1'], [' ', 'c2'], [' ', 'c3'], [' ', 'c4'], [' ', 'c5']], 3], ['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2'])],
}[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
single change in the middle['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']['@@ -3,5 +3,5 @@', ' c2', ' c3', '-old', '+new', ' c4', ' c5']Passed
change at the very start['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']['@@ -1,4 +1,3 @@', '-first', ' c0', ' c1', ' c2']Passed
pure insertion into an empty file['@@ -0 +1 @@', '+x0']['@@ -0,0 +1 @@', '+x0']Failed
pure deletion of every line['@@ -1 +0 @@', '-gone']['@@ -1 +0,0 @@', '-gone']Failed
two changes separated by exactly twice the context['@@ -1,4 +1,4 @@', '-a', ' c0', ' c1', '+b', ' c0']['@@ -1,4 +1,4 @@', '-a', ' c0', ' c1', '+b', ' c0']Passed
two changes separated by more than twice the context['@@ -1,2 +1 @@', '-a', ' c0', '@@ -4,2 +3,3 @@', ' c2', '+b', ' c0']['@@ -1,2 +1 @@', '-a', ' c0', '@@ -4,2 +3,3 @@', ' c2', '+b', ' c0']Passed
insertion after existing lines['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']['@@ -4,2 +4,3 @@', ' c3', ' c4', '+tail']Passed
single-line ranges['@@ -4 +4 @@', '-x', '+y']['@@ -4 +4 @@', '-x', '+y']Passed
no changes[][]Passed
deletion and insertion in separate hunks['@@ -2 +1 @@', '-b', '@@ -3 +3 @@', '+d']['@@ -2 +1,0 @@', '-b', '@@ -3,0 +3 @@', '+d']Failed
deletion near the start with wide context['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2']['@@ -1,6 +1,4 @@', ' c0', '-d1', '-d2', ' c0', ' c1', ' c2']Passed

SHA-256 / ebcd53f2fa83f6a95240a8a3b76bf134513c80fa77afd571d94f356e8eb38f2e

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 11 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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.134830+00:00.

Case digest / 62c2bc95bf38787f0978973fe3c5664d5263529b9b9a70cb257c667ef65e33c2