FA-75786 / Text diff and three-way merge / Open access
Hunk function context: the hunk's own first line can be its heading · case 01
A hunk that starts on a definition shows that definition instead of the enclosing one.
ROOT CAUSE
The backward search starts at the hunk start line rather than the line before it.
VERIFIED REPAIR
Start searching at the line immediately before the hunk start.
Unsuccessful approach: Starting two lines before skips a heading directly above the hunk.
Case contract
For each hunk whose old range starts at 1-based line s, search the old lines strictly before s, nearest first, for a line whose first character is a letter, "_" or "$". The heading is that line with trailing whitespace removed, truncated to limit characters; "" if none.
Why this case matters
The text after the @@ header helps reviewers locate a hunk; choosing the wrong line or including the hunk itself misleads.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(old, starts, limit):
res = []
for s in starts:
found = ''
for k in range(s - 1, -1, -1):
ln = old[k]
if ln[:1].isalpha() or ln[:1] in ('_', '$'):
found = ln.rstrip()[:limit]
break
res.append(found)
return res
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
1: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 11], ['def xxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
2: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 12], ['def xxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
3: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 13], ['def xxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
4: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 14], ['def xxxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
5: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 15], ['def xxxxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
}[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 |
|---|---|---|---|
| nearest preceding definition | ['int main(void)'] | ['int main(void)'] | Passed |
| the hunk start line itself is not searched | ['int main(void)', 'int main(void)'] | ['', 'int main(void)'] | Failed |
| indented lines are not headings | ['int main(void)'] | ['int main(void)'] | Passed |
| dollar and underscore headings | ['$macro', '_private:'] | ['$macro', '_private:'] | Passed |
| nothing before the first line | [''] | [''] | Passed |
| long heading is truncated | ['def xxxxxxx'] | ['def xxxxxxx'] | Passed |
| digits do not start a heading | ['y'] | ['label:'] | Failed |
| trailing whitespace trimmed | ['more'] | ['text'] | Failed |
SHA-256 / bdf4769a7a10a7f881793cddb0992b0ffbeea0967aef76323264be7a0e3140f4
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(old, starts, limit):
res = []
for s in starts:
found = ''
for k in range(s - 3, -1, -1):
ln = old[k]
if ln[:1].isalpha() or ln[:1] in ('_', '$'):
found = ln.rstrip()[:limit]
break
res.append(found)
return res
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
1: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 11], ['def xxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
2: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 12], ['def xxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
3: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 13], ['def xxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
4: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 14], ['def xxxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
5: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 15], ['def xxxxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
}[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 |
|---|---|---|---|
| nearest preceding definition | ['int main(void)'] | ['int main(void)'] | Passed |
| the hunk start line itself is not searched | ['', ''] | ['', 'int main(void)'] | Failed |
| indented lines are not headings | ['int main(void)'] | ['int main(void)'] | Passed |
| dollar and underscore headings | ['int main(void)', '$macro'] | ['$macro', '_private:'] | Failed |
| nothing before the first line | [''] | [''] | Passed |
| long heading is truncated | ['def xxxxxxx'] | ['def xxxxxxx'] | Passed |
| digits do not start a heading | ['label:'] | ['label:'] | Passed |
| trailing whitespace trimmed | ['Section'] | ['text'] | Failed |
SHA-256 / d3dff726c62bb49dd7c30405e93947375123f9c901e4dcaf86cea94c6ffa6878
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(old, starts, limit):
res = []
for s in starts:
found = ''
for k in range(s - 2, -1, -1):
ln = old[k]
if ln[:1].isalpha() or ln[:1] in ('_', '$'):
found = ln.rstrip()[:limit]
break
res.append(found)
return res
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
1: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 11], ['def xxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
2: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 12], ['def xxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
3: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 13], ['def xxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
4: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 14], ['def xxxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
5: [('nearest preceding definition', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [5], 40], ['int main(void)']), ('the hunk start line itself is not searched', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [2, 3], 40], ['', 'int main(void)']), ('indented lines are not headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [6], 40], ['int main(void)']), ('dollar and underscore headings', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [10, 12], 40], ['$macro', '_private:']), ('nothing before the first line', [['#include <x>', 'int main(void)', '{', ' int a;', ' helper();', ' return 0;', '}', '', '$macro', ' body', '_private:', ' x = 1'], [1], 40], ['']), ('long heading is truncated', [['def xxxxxxxxxxxxxxxxxxxxxxxxx(): ', ' pass', ' pass'], [3], 15], ['def xxxxxxxxxxx']), ('digits do not start a heading', [['label:', '42 items', 'y'], [3], 40], ['label:']), ('trailing whitespace trimmed', [['Section ', 'text', 'more'], [3], 40], ['text'])],
}[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 |
|---|---|---|---|
| nearest preceding definition | ['int main(void)'] | ['int main(void)'] | Passed |
| the hunk start line itself is not searched | ['', 'int main(void)'] | ['', 'int main(void)'] | Passed |
| indented lines are not headings | ['int main(void)'] | ['int main(void)'] | Passed |
| dollar and underscore headings | ['$macro', '_private:'] | ['$macro', '_private:'] | Passed |
| nothing before the first line | [''] | [''] | Passed |
| long heading is truncated | ['def xxxxxxx'] | ['def xxxxxxx'] | Passed |
| digits do not start a heading | ['label:'] | ['label:'] | Passed |
| trailing whitespace trimmed | ['text'] | ['text'] | Passed |
SHA-256 / 901da1a275d0f58e8736851aa5793dfd12de27b10320289125820fbedb2270c5
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:10.197133+00:00.
Case digest / 8a7a3353338a6ee1c2ef043291099a47e680c38b3662c7cab77f7da6c141820d