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

N = 1
observations = []
def solve(p):
    to_km = {1: (0, 0), 2: (0, 1), 3: (2, 0), 4: (2, 1), 5: (3, 1), 6: (1, 0), 7: (1, 1), 8: (3, 0)}
    from_km = {v: t for t, v in to_km.items()}
    def compose(first, second):
        k1, m1 = to_km[first]
        k2, m2 = to_km[second]
        k = (k2 + (-k1 if m2 else k1)) % 4
        return from_km[(k, m1 ^ m2)]
    tag = p['tag'] if p['tag'] in to_km else 1
    pixels = tag if p['baked'] else 1
    if p['stripped']:
        meta = 1
    elif p['baked'] and p['reset']:
        meta = 1
    else:
        meta = tag
    honored = p['css'] == 'from-image' or p['cross_origin']
    shown = compose(compose(pixels, meta if honored else 1), p.get('extra', 1))
    return [shown, shown == p['tag']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [7, False]], [{'tag': 2, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [4, False]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 7}, [5, False]], [{'tag': 7, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 4, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [7, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 3, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [6, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [3, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, True]], [{'tag': 8, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [5, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 6, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [5, False]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 1, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 5}, [5, False]], [{'tag': 6, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 1}, [6, True]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [1, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 3}, [3, False]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]]]
labels = ["regression: upright comparison reference", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    to_km = {1: (0, 0), 2: (0, 1), 3: (2, 0), 4: (2, 1), 5: (3, 1), 6: (1, 0), 7: (1, 1), 8: (3, 0)}
    from_km = {v: t for t, v in to_km.items()}
    def compose(first, second):
        k1, m1 = to_km[first]
        k2, m2 = to_km[second]
        k = (k2 + (-k1 if m2 else k1)) % 4
        return from_km[(k, m1 ^ m2)]
    tag = p['tag'] if p['tag'] in to_km else 1
    pixels = tag if p['baked'] else 1
    if p['stripped']:
        meta = 1
    elif p['baked'] and p['reset']:
        meta = 1
    else:
        meta = tag
    honored = p['css'] == 'from-image' or p['cross_origin']
    shown = compose(compose(pixels, meta if honored else 1), p.get('extra', 1))
    return [shown, pixels == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [7, False]], [{'tag': 2, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [4, False]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 7}, [5, False]], [{'tag': 7, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 4, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [7, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 3, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [6, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [3, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, True]], [{'tag': 8, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [5, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 6, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [5, False]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 1, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]], [[{'tag': 0, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 5}, [5, False]], [{'tag': 6, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 1}, [6, True]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [1, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 3}, [3, False]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]]]]
labels = ["regression: upright comparison reference", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Photos with a corrupt tag of 0 are flagged as mis-rotated even when they display normally.

Predict what a browser shows for a photo that went through an upload pipeline. Input {tag, baked, reset, stripped, css, cross_origin}. Baking applies the tag to the pixels; the remaining tag is 1 if metadata was stripped or if baking also reset the tag, else the original tag. The renderer applies the remaining tag when css is "from-image" or the image is cross-origin (image-orientation: none is ignored cross-origin). Finally the viewer applies its own extra orientation (default 1). Orientations are (k clockwise quarter turns after m mirrors), with applying B after A giving k = k2 + (-k1 if m2 else k1). Invalid tags count as 1. Return [shown_tag, shown == tag].

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
Tap-to-focus on portrait photos selects a point mirrored across the diagonal.

A viewer letterboxes the displayed image (contain fit, centred) inside a view [vw, vh]. Map a tap [tx, ty] in view coordinates to the stored pixel [x, y] of an image of stored size [w, h] with orientation tag 1..8 (invalid -> 1); tags 5..8 swap displayed axes. Taps in the letterbox bars or on the far edge return None; the displayed pixel is floor of the exact position, then mapped back through the inverse of the orientation.

split: open-access


prompt:
Taps on rotated photos land a band away from where the user touched.

A viewer letterboxes the displayed image (contain fit, centred) inside a view [vw, vh]. Map a tap [tx, ty] in view coordinates to the stored pixel [x, y] of an image of stored size [w, h] with orientation tag 1..8 (invalid -> 1); tags 5..8 swap displayed axes. Taps in the letterbox bars or on the far edge return None; the displayed pixel is floor of the exact position, then mapped back through the inverse of the orientation.

split: open-access


prompt:
Taps near the letterbox bars map to pixels that are not on screen.

A viewer letterboxes the displayed image (contain fit, centred) inside a view [vw, vh]. Map a tap [tx, ty] in view coordinates to the stored pixel [x, y] of an image of stored size [w, h] with orientation tag 1..8 (invalid -> 1); tags 5..8 swap displayed axes. Taps in the letterbox bars or on the far edge return None; the displayed pixel is floor of the exact position, then mapped back through the inverse of the orientation.

split: open-access


prompt:
Tapping the right or bottom boundary returns a stored coordinate one past the last pixel.

A viewer letterboxes the displayed image (contain fit, centred) inside a view [vw, vh]. Map a tap [tx, ty] in view coordinates to the stored pixel [x, y] of an image of stored size [w, h] with orientation tag 1..8 (invalid -> 1); tags 5..8 swap displayed axes. Taps in the letterbox bars or on the far edge return None; the displayed pixel is floor of the exact position, then mapped back through the inverse of the orientation.

split: open-access


prompt:
Taps in the right half of a pixel select its neighbour.

A viewer letterboxes the displayed image (contain fit, centred) inside a view [vw, vh]. Map a tap [tx, ty] in view coordinates to the stored pixel [x, y] of an image of stored size [w, h] with orientation tag 1..8 (invalid -> 1); tags 5..8 swap displayed axes. Taps in the letterbox bars or on the far edge return None; the displayed pixel is floor of the exact position, then mapped back through the inverse of the orientation.

split: open-access


prompt:
On tag 5 and 7 photos the fit and bounds use the stored aspect ratio.

A viewer letterboxes the displayed image (contain fit, centred) inside a view [vw, vh]. Map a tap [tx, ty] in view coordinates to the stored pixel [x, y] of an image of stored size [w, h] with orientation tag 1..8 (invalid -> 1); tags 5..8 swap displayed axes. Taps in the letterbox bars or on the far edge return None; the displayed pixel is floor of the exact position, then mapped back through the inverse of the orientation.

split: open-access


prompt:
Symmetric logos are stored with a different canonical tag on each upload, breaking dedup provenance.

For duplicate detection, bring a pixel grid into a canonical orientation: of the eight orientations (tags 1..8, same pixel mapping as EXIF baking), pick the one whose key (height, width, row-major pixels) is smallest; ties go to the lowest tag. Return [tag, inverse_tag, canonical_grid] where the inverse tag restores the original (6 and 8 are mutual inverses, every other tag is self-inverse).

split: open-access


prompt:
A 2x3 image and its 3x2 rotation compare by raw pixel order, so different aspect ratios canonicalise inconsistently.

For duplicate detection, bring a pixel grid into a canonical orientation: of the eight orientations (tags 1..8, same pixel mapping as EXIF baking), pick the one whose key (height, width, row-major pixels) is smallest; ties go to the lowest tag. Return [tag, inverse_tag, canonical_grid] where the inverse tag restores the original (6 and 8 are mutual inverses, every other tag is self-inverse).

split: open-access


prompt:
Transposed copies of a square image are not recognised as duplicates.

For duplicate detection, bring a pixel grid into a canonical orientation: of the eight orientations (tags 1..8, same pixel mapping as EXIF baking), pick the one whose key (height, width, row-major pixels) is smallest; ties go to the lowest tag. Return [tag, inverse_tag, canonical_grid] where the inverse tag restores the original (6 and 8 are mutual inverses, every other tag is self-inverse).

split: open-access


prompt:
Two services computing the canonical form disagree because one flattens column-major.

For duplicate detection, bring a pixel grid into a canonical orientation: of the eight orientations (tags 1..8, same pixel mapping as EXIF baking), pick the one whose key (height, width, row-major pixels) is smallest; ties go to the lowest tag. Return [tag, inverse_tag, canonical_grid] where the inverse tag restores the original (6 and 8 are mutual inverses, every other tag is self-inverse).

split: open-access


prompt:
Restoring a deduplicated photo turns it a half turn away from the upload.

For duplicate detection, bring a pixel grid into a canonical orientation: of the eight orientations (tags 1..8, same pixel mapping as EXIF baking), pick the one whose key (height, width, row-major pixels) is smallest; ties go to the lowest tag. Return [tag, inverse_tag, canonical_grid] where the inverse tag restores the original (6 and 8 are mutual inverses, every other tag is self-inverse).

split: open-access


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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] > d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': 3, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'latest'}, 8], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': '06', 'sidecar': None, 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 1], [{'embedded': '6', 'sidecar': 5, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': None}, 5]], [[{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': None}, 5], [{'embedded': 5, 'sidecar': ' 8', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'newest'}, 8], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 3, 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'latest'}, 8]], [[{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': None}, 3], [{'embedded': 8, 'sidecar': '6', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': None}, 6], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1], [{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1]], [[{'embedded': 6, 'sidecar': ' 8', 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': 1, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': '6', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': None}, 6], [{'embedded': 1, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'newest'}, 1], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 8, 'sidecar': 3, 'file_mtime': 107, 'sidecar_mtime': 107, 'policy': None}, 3]], [[{'embedded': '6', 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': 1, 'sidecar': 5, 'file_mtime': 107, 'sidecar_mtime': 108, 'policy': None}, 5], [{'embedded': 5, 'sidecar': '6', 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'latest'}, 6], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8], [{'embedded': 6, 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 103, 'policy': 'latest'}, 8]]]
labels = ["regression: equal modification times", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] - d['file_mtime'] > 1 else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': 3, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'latest'}, 8], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': '06', 'sidecar': None, 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 1], [{'embedded': '6', 'sidecar': 5, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': None}, 5]], [[{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': None}, 5], [{'embedded': 5, 'sidecar': ' 8', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'newest'}, 8], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 3, 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'latest'}, 8]], [[{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': None}, 3], [{'embedded': 8, 'sidecar': '6', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': None}, 6], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1], [{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1]], [[{'embedded': 6, 'sidecar': ' 8', 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': 1, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': '6', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': None}, 6], [{'embedded': 1, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'newest'}, 1], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 8, 'sidecar': 3, 'file_mtime': 107, 'sidecar_mtime': 107, 'policy': None}, 3]], [[{'embedded': '6', 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': 1, 'sidecar': 5, 'file_mtime': 107, 'sidecar_mtime': 108, 'policy': None}, 5], [{'embedded': 5, 'sidecar': '6', 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'latest'}, 6], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8], [{'embedded': 6, 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 103, 'policy': 'latest'}, 8]]]
labels = ["regression: equal modification times", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Rotations made in the manager revert after an export that touched both files within one second.

A photo manager reconciles the embedded orientation with an XMP sidecar. Values are valid if they are integers 1..8 or strings that are exactly one digit 1..8 after trimming. Policy "sidecar" prefers the sidecar, "embedded" prefers the file, and "newest" (also used for unknown policies) prefers the sidecar when both are valid and sidecar_mtime >= file_mtime; the other valid value is the fallback, then 1.

split: open-access


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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = d.get('sidecar')
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': None}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': '06', 'sidecar': None, 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 1], [{'embedded': 9, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': None}, 6], [{'embedded': 3, 'sidecar': None, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'embedded'}, 3], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1]], [[{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': None, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 'x', 'sidecar': 5, 'file_mtime': 107, 'sidecar_mtime': 102, 'policy': None}, 5], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 109, 'policy': 'newest'}, 5], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 106, 'sidecar_mtime': 107, 'policy': None}, 8]], [[{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'newest'}, 5], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1], [{'embedded': 3, 'sidecar': '6', 'file_mtime': 109, 'sidecar_mtime': 104, 'policy': 'latest'}, 3], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'sidecar'}, 8], [{'embedded': None, 'sidecar': None, 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'latest'}, 1], [{'embedded': 8, 'sidecar': 6, 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 8], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1]], [[{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 6, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': 'sidecar'}, 6], [{'embedded': 6, 'sidecar': '6', 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'sidecar'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': ' 8', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 108, 'policy': None}, 8], [{'embedded': '6', 'sidecar': 5, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'sidecar'}, 5], [{'embedded': None, 'sidecar': 6, 'file_mtime': 103, 'sidecar_mtime': 98, 'policy': 'embedded'}, 6], [{'embedded': '+3', 'sidecar': 'x', 'file_mtime': 101, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1]], [[{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 103, 'policy': 'sidecar'}, 6], [{'embedded': '6', 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': 'newest'}, 6], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'embedded'}, 5], [{'embedded': 9, 'sidecar': 3, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 3], [{'embedded': 8, 'sidecar': 0, 'file_mtime': 107, 'sidecar_mtime': 106, 'policy': None}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1]]]
labels = ["regression: sidecar value validation", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = d.get('sidecar') or None
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': None}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': '06', 'sidecar': None, 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 1], [{'embedded': 9, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': None}, 6], [{'embedded': 3, 'sidecar': None, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'embedded'}, 3], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1]], [[{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': None, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 'x', 'sidecar': 5, 'file_mtime': 107, 'sidecar_mtime': 102, 'policy': None}, 5], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 109, 'policy': 'newest'}, 5], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 106, 'sidecar_mtime': 107, 'policy': None}, 8]], [[{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'newest'}, 5], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1], [{'embedded': 3, 'sidecar': '6', 'file_mtime': 109, 'sidecar_mtime': 104, 'policy': 'latest'}, 3], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'sidecar'}, 8], [{'embedded': None, 'sidecar': None, 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'latest'}, 1], [{'embedded': 8, 'sidecar': 6, 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 8], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1]], [[{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 6, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': 'sidecar'}, 6], [{'embedded': 6, 'sidecar': '6', 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'sidecar'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': ' 8', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 108, 'policy': None}, 8], [{'embedded': '6', 'sidecar': 5, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'sidecar'}, 5], [{'embedded': None, 'sidecar': 6, 'file_mtime': 103, 'sidecar_mtime': 98, 'policy': 'embedded'}, 6], [{'embedded': '+3', 'sidecar': 'x', 'file_mtime': 101, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1]], [[{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 103, 'policy': 'sidecar'}, 6], [{'embedded': '6', 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': 'newest'}, 6], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'embedded'}, 5], [{'embedded': 9, 'sidecar': 3, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 3], [{'embedded': 8, 'sidecar': 0, 'file_mtime': 107, 'sidecar_mtime': 106, 'policy': None}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1]]]
labels = ["regression: sidecar value validation", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A sidecar with orientation 0 or text garbage overrides a valid embedded tag.

A photo manager reconciles the embedded orientation with an XMP sidecar. Values are valid if they are integers 1..8 or strings that are exactly one digit 1..8 after trimming. Policy "sidecar" prefers the sidecar, "embedded" prefers the file, and "newest" (also used for unknown policies) prefers the sidecar when both are valid and sidecar_mtime >= file_mtime; the other valid value is the fallback, then 1.

split: open-access


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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'embedded'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': '6', 'sidecar': 5, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': None}, 5], [{'embedded': 8, 'sidecar': '6', 'file_mtime': 107, 'sidecar_mtime': 102, 'policy': 'latest'}, 8], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': ' 8', 'sidecar': 1, 'file_mtime': 103, 'sidecar_mtime': 103, 'policy': None}, 1]], [[{'embedded': 3, 'sidecar': 6, 'file_mtime': 109, 'sidecar_mtime': 110, 'policy': 'latest'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 105, 'policy': 'latest'}, 5], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 6, 'sidecar': 3, 'file_mtime': 106, 'sidecar_mtime': 111, 'policy': None}, 3]], [[{'embedded': 3, 'sidecar': 8, 'file_mtime': 101, 'sidecar_mtime': 106, 'policy': 'latest'}, 8], [{'embedded': 3, 'sidecar': 5, 'file_mtime': 102, 'sidecar_mtime': 97, 'policy': None}, 3], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1], [{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1]], [[{'embedded': ' 8', 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': None}, 6], [{'embedded': '6', 'sidecar': 8, 'file_mtime': 108, 'sidecar_mtime': 103, 'policy': 'latest'}, 6], [{'embedded': 1, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'newest'}, 1], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': ' 8', 'sidecar': '6', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': None}, 6]], [[{'embedded': 1, 'sidecar': 5, 'file_mtime': 102, 'sidecar_mtime': 107, 'policy': None}, 5], [{'embedded': 3, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 107, 'policy': None}, 3], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8], [{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 8, 'sidecar': 3, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': 'latest'}, 3]]]
labels = ["regression: unknown policy default", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'sidecar'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': '6', 'sidecar': 5, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': None}, 5], [{'embedded': 8, 'sidecar': '6', 'file_mtime': 107, 'sidecar_mtime': 102, 'policy': 'latest'}, 8], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': ' 8', 'sidecar': 1, 'file_mtime': 103, 'sidecar_mtime': 103, 'policy': None}, 1]], [[{'embedded': 3, 'sidecar': 6, 'file_mtime': 109, 'sidecar_mtime': 110, 'policy': 'latest'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 105, 'policy': 'latest'}, 5], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 6, 'sidecar': 3, 'file_mtime': 106, 'sidecar_mtime': 111, 'policy': None}, 3]], [[{'embedded': 3, 'sidecar': 8, 'file_mtime': 101, 'sidecar_mtime': 106, 'policy': 'latest'}, 8], [{'embedded': 3, 'sidecar': 5, 'file_mtime': 102, 'sidecar_mtime': 97, 'policy': None}, 3], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1], [{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1]], [[{'embedded': ' 8', 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': None}, 6], [{'embedded': '6', 'sidecar': 8, 'file_mtime': 108, 'sidecar_mtime': 103, 'policy': 'latest'}, 6], [{'embedded': 1, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'newest'}, 1], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': ' 8', 'sidecar': '6', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': None}, 6]], [[{'embedded': 1, 'sidecar': 5, 'file_mtime': 102, 'sidecar_mtime': 107, 'policy': None}, 5], [{'embedded': 3, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 107, 'policy': None}, 3], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8], [{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 8, 'sidecar': 3, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': 'latest'}, 3]]]
labels = ["regression: unknown policy default", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Libraries migrated from an older config with policy "latest" ignore newer sidecar edits.

A photo manager reconciles the embedded orientation with an XMP sidecar. Values are valid if they are integers 1..8 or strings that are exactly one digit 1..8 after trimming. Policy "sidecar" prefers the sidecar, "embedded" prefers the file, and "newest" (also used for unknown policies) prefers the sidecar when both are valid and sidecar_mtime >= file_mtime; the other valid value is the fallback, then 1.

split: open-access


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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': 'x', 'sidecar': 6, 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'embedded'}, 6], [{'embedded': None, 'sidecar': 5, 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'embedded'}, 5], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': 9, 'sidecar': 3, 'file_mtime': 106, 'sidecar_mtime': 111, 'policy': 'embedded'}, 3]], [[{'embedded': 'x', 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'embedded'}, 6], [{'embedded': 9, 'sidecar': ' 8', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 9, 'sidecar': ' 8', 'file_mtime': 110, 'sidecar_mtime': 105, 'policy': 'embedded'}, 8]], [[{'embedded': None, 'sidecar': 6, 'file_mtime': 104, 'sidecar_mtime': 109, 'policy': 'embedded'}, 6], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1], [{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'latest'}, 3], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1], [{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': 'x', 'sidecar': 5, 'file_mtime': 103, 'sidecar_mtime': 98, 'policy': 'embedded'}, 5]], [[{'embedded': 0, 'sidecar': 3, 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 3], [{'embedded': '06', 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 95, 'policy': 'embedded'}, 6], [{'embedded': 1, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'newest'}, 1], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': 9, 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 105, 'policy': 'embedded'}, 8]], [[{'embedded': 9, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 95, 'policy': 'embedded'}, 6], [{'embedded': 9, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 104, 'policy': 'embedded'}, 8], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8], [{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 0, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 113, 'policy': 'embedded'}, 6]]]
labels = ["regression: embedded policy fallback", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip() in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v.strip())
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, None]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': 'x', 'sidecar': 6, 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'embedded'}, 6], [{'embedded': None, 'sidecar': 5, 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'embedded'}, 5], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': 9, 'sidecar': 3, 'file_mtime': 106, 'sidecar_mtime': 111, 'policy': 'embedded'}, 3]], [[{'embedded': 'x', 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'embedded'}, 6], [{'embedded': 9, 'sidecar': ' 8', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': 1, 'sidecar': '06', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 1], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 9, 'sidecar': ' 8', 'file_mtime': 110, 'sidecar_mtime': 105, 'policy': 'embedded'}, 8]], [[{'embedded': None, 'sidecar': 6, 'file_mtime': 104, 'sidecar_mtime': 109, 'policy': 'embedded'}, 6], [{'embedded': None, 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'newest'}, 1], [{'embedded': 3, 'sidecar': '+3', 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': None}, 3], [{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'latest'}, 3], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1], [{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': 'x', 'sidecar': 5, 'file_mtime': 103, 'sidecar_mtime': 98, 'policy': 'embedded'}, 5]], [[{'embedded': 0, 'sidecar': 3, 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 3], [{'embedded': '06', 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 95, 'policy': 'embedded'}, 6], [{'embedded': 1, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'newest'}, 1], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': 9, 'sidecar': 8, 'file_mtime': 106, 'sidecar_mtime': 105, 'policy': 'embedded'}, 8]], [[{'embedded': 9, 'sidecar': '6', 'file_mtime': 100, 'sidecar_mtime': 95, 'policy': 'embedded'}, 6], [{'embedded': 9, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 104, 'policy': 'embedded'}, 8], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8], [{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': 0, 'sidecar': '6', 'file_mtime': 108, 'sidecar_mtime': 113, 'policy': 'embedded'}, 6]]]
labels = ["regression: embedded policy fallback", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Files without an embedded tag display unrotated even though the sidecar holds a valid orientation.

A photo manager reconciles the embedded orientation with an XMP sidecar. Values are valid if they are integers 1..8 or strings that are exactly one digit 1..8 after trimming. Policy "sidecar" prefers the sidecar, "embedded" prefers the file, and "newest" (also used for unknown policies) prefers the sidecar when both are valid and sidecar_mtime >= file_mtime; the other valid value is the fallback, then 1.

split: open-access


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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v in ('1', '2', '3', '4', '5', '6', '7', '8'):
            return int(v)
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 106, 'sidecar_mtime': 105, 'policy': 'latest'}, 8], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': '06', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 8], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': 3, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'latest'}, 8]], [[{'embedded': 5, 'sidecar': ' 8', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'newest'}, 8], [{'embedded': 0, 'sidecar': '+3', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 1], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 103, 'sidecar_mtime': 103, 'policy': 'sidecar'}, 8], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 6, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 106, 'policy': 'latest'}, 8]], [[{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'latest'}, 3], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': 3, 'sidecar': '6', 'file_mtime': 109, 'sidecar_mtime': 104, 'policy': 'latest'}, 3], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'sidecar'}, 8], [{'embedded': 0, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 100, 'policy': None}, 8]], [[{'embedded': ' 8', 'sidecar': None, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 8], [{'embedded': '06', 'sidecar': None, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': '+3', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'sidecar'}, 8], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': 6, 'sidecar': ' 8', 'file_mtime': 103, 'sidecar_mtime': 104, 'policy': 'sidecar'}, 8]], [[{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 104, 'sidecar_mtime': 99, 'policy': 'embedded'}, 8], [{'embedded': '06', 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 105, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 101, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8]]]
labels = ["regression: text orientation parsing", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    def ok(v):
        if isinstance(v, str) and v.strip().lstrip('+0').isdigit():
            v = int(v)
        if isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 8:
            return v
        return None
    e = ok(d.get('embedded'))
    s = ok(d.get('sidecar'))
    pol = d.get('policy')
    if pol not in ('newest', 'sidecar', 'embedded'):
        pol = 'newest'
    if pol == 'sidecar':
        order = [s, e]
    elif pol == 'embedded':
        order = [e, s]
    elif s is not None and e is not None:
        order = [s, e] if d['sidecar_mtime'] >= d['file_mtime'] else [e, s]
    else:
        order = [s, e]
    for v in order:
        if v is not None:
            return v
    return 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'embedded': 'x', 'sidecar': ' 8', 'file_mtime': 106, 'sidecar_mtime': 105, 'policy': 'latest'}, 8], [{'embedded': 5, 'sidecar': '+3', 'file_mtime': 103, 'sidecar_mtime': 108, 'policy': 'newest'}, 5], [{'embedded': '06', 'sidecar': ' 8', 'file_mtime': 101, 'sidecar_mtime': 100, 'policy': 'embedded'}, 8], [{'embedded': 'x', 'sidecar': 'x', 'file_mtime': 109, 'sidecar_mtime': 109, 'policy': 'embedded'}, 1], [{'embedded': 8, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': 9, 'sidecar': 9, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 1], [{'embedded': ' 8', 'sidecar': 5, 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'newest'}, 5], [{'embedded': 3, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 105, 'policy': 'latest'}, 8]], [[{'embedded': 5, 'sidecar': ' 8', 'file_mtime': 104, 'sidecar_mtime': 105, 'policy': 'newest'}, 8], [{'embedded': 0, 'sidecar': '+3', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 1], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 103, 'sidecar_mtime': 103, 'policy': 'sidecar'}, 8], [{'embedded': 3, 'sidecar': None, 'file_mtime': 106, 'sidecar_mtime': 106, 'policy': 'embedded'}, 3], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 107, 'sidecar_mtime': 112, 'policy': 'embedded'}, 8], [{'embedded': 3, 'sidecar': 6, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'sidecar'}, 6], [{'embedded': 3, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 103, 'policy': 'newest'}, 3], [{'embedded': 6, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 106, 'policy': 'latest'}, 8]], [[{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 101, 'sidecar_mtime': 96, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 100, 'sidecar_mtime': 101, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': 3, 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'latest'}, 3], [{'embedded': 8, 'sidecar': 1, 'file_mtime': 108, 'sidecar_mtime': 108, 'policy': None}, 1], [{'embedded': 5, 'sidecar': 9, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'latest'}, 5], [{'embedded': 3, 'sidecar': '6', 'file_mtime': 109, 'sidecar_mtime': 104, 'policy': 'latest'}, 3], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 105, 'sidecar_mtime': 110, 'policy': 'sidecar'}, 8], [{'embedded': 0, 'sidecar': ' 8', 'file_mtime': 105, 'sidecar_mtime': 100, 'policy': None}, 8]], [[{'embedded': ' 8', 'sidecar': None, 'file_mtime': 108, 'sidecar_mtime': 109, 'policy': None}, 8], [{'embedded': '06', 'sidecar': None, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': '+3', 'file_mtime': 110, 'sidecar_mtime': 115, 'policy': 'sidecar'}, 8], [{'embedded': 6, 'sidecar': 6, 'file_mtime': 100, 'sidecar_mtime': 105, 'policy': 'sidecar'}, 6], [{'embedded': 5, 'sidecar': 8, 'file_mtime': 109, 'sidecar_mtime': 114, 'policy': 'newest'}, 8], [{'embedded': None, 'sidecar': '6', 'file_mtime': 104, 'sidecar_mtime': 104, 'policy': 'latest'}, 6], [{'embedded': 'x', 'sidecar': 8, 'file_mtime': 103, 'sidecar_mtime': 102, 'policy': None}, 8], [{'embedded': 6, 'sidecar': ' 8', 'file_mtime': 103, 'sidecar_mtime': 104, 'policy': 'sidecar'}, 8]], [[{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 104, 'sidecar_mtime': 99, 'policy': 'embedded'}, 8], [{'embedded': '06', 'sidecar': '06', 'file_mtime': 110, 'sidecar_mtime': 105, 'policy': 'latest'}, 1], [{'embedded': ' 8', 'sidecar': '06', 'file_mtime': 101, 'sidecar_mtime': 106, 'policy': 'newest'}, 8], [{'embedded': ' 8', 'sidecar': 8, 'file_mtime': 110, 'sidecar_mtime': 110, 'policy': 'embedded'}, 8], [{'embedded': 0, 'sidecar': 'x', 'file_mtime': 102, 'sidecar_mtime': 102, 'policy': 'embedded'}, 1], [{'embedded': 0, 'sidecar': 9, 'file_mtime': 100, 'sidecar_mtime': 99, 'policy': 'latest'}, 1], [{'embedded': 8, 'sidecar': 9, 'file_mtime': 102, 'sidecar_mtime': 101, 'policy': 'sidecar'}, 8], [{'embedded': ' 8', 'sidecar': 0, 'file_mtime': 100, 'sidecar_mtime': 100, 'policy': None}, 8]]]
labels = ["regression: text orientation parsing", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Sidecars written with a leading space are ignored.

A photo manager reconciles the embedded orientation with an XMP sidecar. Values are valid if they are integers 1..8 or strings that are exactly one digit 1..8 after trimming. Policy "sidecar" prefers the sidecar, "embedded" prefers the file, and "newest" (also used for unknown policies) prefers the sidecar when both are valid and sidecar_mtime >= file_mtime; the other valid value is the fallback, then 1.

split: open-access


prompt:
Labels whose leading digit is not 0 scan as invalid because every G-coded digit starts with a bar.

Encode a 13-character string of ASCII digits (the check digit is taken as given, not verified) as the 95-module EAN-13 pattern: start guard 101, six left digits in L or G sets chosen by the parity row of the leading digit, centre guard 01010, six right digits in the R set, end guard 101. R is the bitwise complement of L and G is R reversed. Anything else returns None.

split: open-access


prompt:
Codes starting with 7 decode as starting with 8 and vice versa, silently changing the country prefix.

Encode a 13-character string of ASCII digits (the check digit is taken as given, not verified) as the 95-module EAN-13 pattern: start guard 101, six left digits in L or G sets chosen by the parity row of the leading digit, centre guard 01010, six right digits in the R set, end guard 101. R is the bitwise complement of L and G is R reversed. Anything else returns None.

split: open-access


prompt:
The encoded symbol repeats the first digit and drops the seventh.

Encode a 13-character string of ASCII digits (the check digit is taken as given, not verified) as the 95-module EAN-13 pattern: start guard 101, six left digits in L or G sets chosen by the parity row of the leading digit, centre guard 01010, six right digits in the R set, end guard 101. R is the bitwise complement of L and G is R reversed. Anything else returns None.

split: open-access


prompt:
Scanners reject every symbol because the centre guard pattern is inverted.

Encode a 13-character string of ASCII digits (the check digit is taken as given, not verified) as the 95-module EAN-13 pattern: start guard 101, six left digits in L or G sets chosen by the parity row of the leading digit, centre guard 01010, six right digits in the R set, end guard 101. R is the bitwise complement of L and G is R reversed. Anything else returns None.

split: open-access


prompt:
The seventh digit is encoded twice and the check digit is missing.

Encode a 13-character string of ASCII digits (the check digit is taken as given, not verified) as the 95-module EAN-13 pattern: start guard 101, six left digits in L or G sets chosen by the parity row of the leading digit, centre guard 01010, six right digits in the R set, end guard 101. R is the bitwise complement of L and G is R reversed. Anything else returns None.

split: open-access


prompt:
Full-width or Arabic-Indic digits pasted from documents are encoded as if they were ASCII.

Encode a 13-character string of ASCII digits (the check digit is taken as given, not verified) as the 95-module EAN-13 pattern: start guard 101, six left digits in L or G sets chosen by the parity row of the leading digit, centre guard 01010, six right digits in the R set, end guard 101. R is the bitwise complement of L and G is R reversed. Anything else returns None.

split: open-access


prompt:
Compressed codes ending in 3 expand to a different manufacturer number.

Expand an 8-digit zero-suppressed UPC-E string (number system 0 or 1, six digits d1..d6, check digit passed through) into 12-digit UPC-A: d6 in 0-2 -> d1 d2 d6 0000 d3 d4 d5; d6 = 3 -> d1 d2 d3 00000 d4 d5; d6 = 4 -> d1 d2 d3 d4 00000 d5; d6 in 5-9 -> d1..d5 0000 d6. Invalid input returns None.

split: open-access


prompt:
Items whose code ends in 3 are looked up under the wrong product.

Expand an 8-digit zero-suppressed UPC-E string (number system 0 or 1, six digits d1..d6, check digit passed through) into 12-digit UPC-A: d6 in 0-2 -> d1 d2 d6 0000 d3 d4 d5; d6 = 3 -> d1 d2 d3 00000 d4 d5; d6 = 4 -> d1 d2 d3 d4 00000 d5; d6 in 5-9 -> d1..d5 0000 d6. Invalid input returns None.

split: open-access


prompt:
Codes ending in 4 collide with codes ending in 3.

Expand an 8-digit zero-suppressed UPC-E string (number system 0 or 1, six digits d1..d6, check digit passed through) into 12-digit UPC-A: d6 in 0-2 -> d1 d2 d6 0000 d3 d4 d5; d6 = 3 -> d1 d2 d3 00000 d4 d5; d6 = 4 -> d1 d2 d3 d4 00000 d5; d6 in 5-9 -> d1..d5 0000 d6. Invalid input returns None.

split: open-access


prompt:
Codes ending in 5 through 9 expand to six-digit manufacturer prefixes.

Expand an 8-digit zero-suppressed UPC-E string (number system 0 or 1, six digits d1..d6, check digit passed through) into 12-digit UPC-A: d6 in 0-2 -> d1 d2 d6 0000 d3 d4 d5; d6 = 3 -> d1 d2 d3 00000 d4 d5; d6 = 4 -> d1 d2 d3 d4 00000 d5; d6 in 5-9 -> d1..d5 0000 d6. Invalid input returns None.

split: open-access


prompt:
Mistyped codes with a leading 2 are expanded to UPC-A instead of being rejected.

Expand an 8-digit zero-suppressed UPC-E string (number system 0 or 1, six digits d1..d6, check digit passed through) into 12-digit UPC-A: d6 in 0-2 -> d1 d2 d6 0000 d3 d4 d5; d6 = 3 -> d1 d2 d3 00000 d4 d5; d6 = 4 -> d1 d2 d3 d4 00000 d5; d6 in 5-9 -> d1..d5 0000 d6. Invalid input returns None.

split: open-access


prompt:
Data such as "A1B2C3D4" starts in set C and immediately needs a switch, producing a longer symbol.

Plan Code 128 code sets for printable ASCII data (other characters -> None) as a list of [set, text] segments. Start in C when the data begins with at least 4 digits or is entirely digits of even length >= 2, else B. In C consume digit pairs and fall back to B when fewer than two digits remain in the run. In B switch to C before a run of at least 6 digits, or at least 4 digits that reach the end of the data; an odd run first encodes one digit in B. Empty data yields [["B", ""]].

split: open-access


prompt:
A three-digit quantity is encoded as a pair in C plus a switch to B for its last digit.

Plan Code 128 code sets for printable ASCII data (other characters -> None) as a list of [set, text] segments. Start in C when the data begins with at least 4 digits or is entirely digits of even length >= 2, else B. In C consume digit pairs and fall back to B when fewer than two digits remain in the run. In B switch to C before a run of at least 6 digits, or at least 4 digits that reach the end of the data; an odd run first encodes one digit in B. Empty data yields [["B", ""]].

split: open-access


prompt:
Symbols grow when a four-digit run sits between letters, because two switch characters cost more than the pairs save.

Plan Code 128 code sets for printable ASCII data (other characters -> None) as a list of [set, text] segments. Start in C when the data begins with at least 4 digits or is entirely digits of even length >= 2, else B. In C consume digit pairs and fall back to B when fewer than two digits remain in the run. In B switch to C before a run of at least 6 digits, or at least 4 digits that reach the end of the data; an odd run first encodes one digit in B. Empty data yields [["B", ""]].

split: open-access


prompt:
Serial numbers ending in four or five digits produce longer symbols than necessary.

Plan Code 128 code sets for printable ASCII data (other characters -> None) as a list of [set, text] segments. Start in C when the data begins with at least 4 digits or is entirely digits of even length >= 2, else B. In C consume digit pairs and fall back to B when fewer than two digits remain in the run. In B switch to C before a run of at least 6 digits, or at least 4 digits that reach the end of the data; an odd run first encodes one digit in B. Empty data yields [["B", ""]].

split: open-access


prompt:
A seven-digit run ends with a lone digit that forces another switch back to B.

Plan Code 128 code sets for printable ASCII data (other characters -> None) as a list of [set, text] segments. Start in C when the data begins with at least 4 digits or is entirely digits of even length >= 2, else B. In C consume digit pairs and fall back to B when fewer than two digits remain in the run. In B switch to C before a run of at least 6 digits, or at least 4 digits that reach the end of the data; an odd run first encodes one digit in B. Empty data yields [["B", ""]].

split: open-access


prompt:
Data such as "1234567A" produces a set C segment containing "7A".

Plan Code 128 code sets for printable ASCII data (other characters -> None) as a list of [set, text] segments. Start in C when the data begins with at least 4 digits or is entirely digits of even length >= 2, else B. In C consume digit pairs and fall back to B when fewer than two digits remain in the run. In B switch to C before a run of at least 6 digits, or at least 4 digits that reach the end of the data; an odd run first encodes one digit in B. Empty data yields [["B", ""]].

split: open-access


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

N = 1
observations = []
def solve(segs):
    out = []
    cur = None
    starts = {'A': 103, 'B': 104, 'C': 105}
    switch = {'A': 101, 'B': 100, 'C': 99}
    def val(s, ch):
        o = ord(ch)
        if s == 'A':
            if 32 <= o <= 95:
                return o - 32
            if 0 <= o <= 31:
                return o + 32
            return None
        if 32 <= o <= 127:
            return o - 32
        return None
    for seg in segs:
        kind = seg[0]
        if kind == 'FNC1':
            if cur is None:
                return {'error': 'no-start'}
            out.append(102)
            continue
        if kind == 'SHIFT':
            if cur not in ('A', 'B'):
                return {'error': 'bad-shift'}
            other = 'B' if cur == 'A' else 'A'
            v = val(other, seg[1])
            if v is None:
                return {'error': 'unencodable', 'char': seg[1]}
            out += [98, v]
            continue
        s, text = seg
        if cur is None:
            out.append(starts[s])
        elif s != cur:
            out.append(switch[s])
        cur = s
        if s == 'C':
            if len(text) % 2 or not all(c in '0123456789' for c in text):
                return {'error': 'bad-c'}
            out += [int(text[j:j + 2]) for j in range(0, len(text), 2)]
        else:
            for ch in text:
                v = val(s, ch)
                if v is None:
                    return {'error': 'unencodable', 'char': ch}
                out.append(v)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['B', 'Lot 7'], ['A', '\x00Q'], ['FNC1'], ['C', '4711']], [104, 44, 79, 84, 0, 23, 101, 64, 49, 102, 99, 47, 11]], [[['C', '4711'], ['A', 'X\x1d1'], ['B', 'ab']], [105, 47, 11, 101, 56, 93, 17, 100, 65, 66]], [[['C', '12'], ['A', 'HELLO']], [105, 12, 101, 40, 37, 44, 44, 47]], [[['B', 'Q'], ['B', '{x}'], ['C', '123']], {'error': 'bad-c'}], [[['B', '{x}'], ['SHIFT', '\t'], ['C', '1'], ['A', '\x00Q']], {'error': 'bad-c'}], [[['B', 'ab'], ['A', '\x00Q'], ['SHIFT', '\t'], ['FNC1']], {'error': 'unencodable', 'char': '\t'}], [[['C', '123'], ['FNC1']], {'error': 'bad-c'}], [[['A', 'X\x1d1']], [103, 56, 93, 17]]], [[[['A', '\x00Q'], ['B', '{x}'], ['A', 'X\x1d1'], ['SHIFT', 'z']], [103, 64, 49, 100, 91, 88, 93, 101, 56, 93, 17, 98, 90]], [[['A', 'X\x1d1']], [103, 56, 93, 17]], [[['A', 'AB'], ['B', 'Q'], ['B', 'z~']], [103, 33, 34, 100, 49, 90, 94]], [[['A', 'AB'], ['FNC1']], [103, 33, 34, 102]], [[['B', 'z~'], ['SHIFT', 'z'], ['FNC1']], {'error': 'unencodable', 'char': 'z'}], [[['C', ' 1'], ['C', '0099'], ['FNC1'], ['SHIFT', '\x1d']], {'error': 'bad-c'}], [[['B', '{x}'], ['A', '_^']], [104, 91, 88, 93, 101, 63, 62]], [[['A', 'AB'], ['A', '\x00Q'], ['A', '\x00Q'], ['B', 'z~']], [103, 33, 34, 64, 49, 64, 49, 100, 90, 94]]], [[[['C', '12'], ['FNC1'], ['C', '4711'], ['A', '\x00Q']], [105, 12, 102, 47, 11, 101, 64, 49]], [[['A', '\t'], ['C', '4711'], ['B', 'Q'], ['B', 'ab']], [103, 73, 99, 47, 11, 100, 49, 65, 66]], [[['B', 'Lot 7']], [104, 44, 79, 84, 0, 23]], [[['C', '0099']], [105, 0, 99]], [[['A', 'AB']], [103, 33, 34]], [[['FNC1'], ['FNC1'], ['A', 'HELLO'], ['C', '4711']], {'error': 'no-start'}], [[['C', '12']], [105, 12]], [[['A', 'X\x1d1']], [103, 56, 93, 17]]], [[[['A', 'X\x1d1'], ['A', 'HELLO']], [103, 56, 93, 17, 40, 37, 44, 44, 47]], [[['C', '4711'], ['A', '\t'], ['B', '{x}']], [105, 47, 11, 101, 73, 100, 91, 88, 93]], [[['B', 'z~']], [104, 90, 94]], [[['C', ' 1'], ['FNC1'], ['C', ' 1'], ['A', '_^']], {'error': 'bad-c'}], [[['C', ' 1'], ['C', '0099']], {'error': 'bad-c'}], [[['C', '4711']], [105, 47, 11]], [[['A', 'HELLO'], ['A', '_^'], ['A', '_^']], [103, 40, 37, 44, 44, 47, 63, 62, 63, 62]], [[['C', '4711'], ['B', 'ab'], ['A', 'X\x1d1']], [105, 47, 11, 100, 65, 66, 101, 56, 93, 17]]], [[[['A', 'X\x1d1'], ['FNC1'], ['A', '_^'], ['B', '{x}']], [103, 56, 93, 17, 102, 63, 62, 100, 91, 88, 93]], [[['C', '4711'], ['B', '{x}'], ['A', 'X\x1d1']], [105, 47, 11, 100, 91, 88, 93, 101, 56, 93, 17]], [[['C', '4711'], ['B', 'Q'], ['B', '{x}']], [105, 47, 11, 100, 49, 91, 88, 93]], [[['B', '{x}'], ['B', 'Q']], [104, 91, 88, 93, 49]], [[['A', 'AB']], [103, 33, 34]], [[['FNC1'], ['A', 'X\x1d1']], {'error': 'no-start'}], [[['B', 'Lot 7']], [104, 44, 79, 84, 0, 23]], [[['A', '\t'], ['FNC1']], [103, 73, 102]]]]
labels = ["regression: set A control character offset", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(segs):
    out = []
    cur = None
    starts = {'A': 103, 'B': 104, 'C': 105}
    switch = {'A': 101, 'B': 100, 'C': 99}
    def val(s, ch):
        o = ord(ch)
        if s == 'A':
            if 32 <= o <= 95:
                return o - 32
            if 0 <= o <= 31:
                return o + 96
            return None
        if 32 <= o <= 127:
            return o - 32
        return None
    for seg in segs:
        kind = seg[0]
        if kind == 'FNC1':
            if cur is None:
                return {'error': 'no-start'}
            out.append(102)
            continue
        if kind == 'SHIFT':
            if cur not in ('A', 'B'):
                return {'error': 'bad-shift'}
            other = 'B' if cur == 'A' else 'A'
            v = val(other, seg[1])
            if v is None:
                return {'error': 'unencodable', 'char': seg[1]}
            out += [98, v]
            continue
        s, text = seg
        if cur is None:
            out.append(starts[s])
        elif s != cur:
            out.append(switch[s])
        cur = s
        if s == 'C':
            if len(text) % 2 or not all(c in '0123456789' for c in text):
                return {'error': 'bad-c'}
            out += [int(text[j:j + 2]) for j in range(0, len(text), 2)]
        else:
            for ch in text:
                v = val(s, ch)
                if v is None:
                    return {'error': 'unencodable', 'char': ch}
                out.append(v)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['B', 'Lot 7'], ['A', '\x00Q'], ['FNC1'], ['C', '4711']], [104, 44, 79, 84, 0, 23, 101, 64, 49, 102, 99, 47, 11]], [[['C', '4711'], ['A', 'X\x1d1'], ['B', 'ab']], [105, 47, 11, 101, 56, 93, 17, 100, 65, 66]], [[['C', '12'], ['A', 'HELLO']], [105, 12, 101, 40, 37, 44, 44, 47]], [[['B', 'Q'], ['B', '{x}'], ['C', '123']], {'error': 'bad-c'}], [[['B', '{x}'], ['SHIFT', '\t'], ['C', '1'], ['A', '\x00Q']], {'error': 'bad-c'}], [[['B', 'ab'], ['A', '\x00Q'], ['SHIFT', '\t'], ['FNC1']], {'error': 'unencodable', 'char': '\t'}], [[['C', '123'], ['FNC1']], {'error': 'bad-c'}], [[['A', 'X\x1d1']], [103, 56, 93, 17]]], [[[['A', '\x00Q'], ['B', '{x}'], ['A', 'X\x1d1'], ['SHIFT', 'z']], [103, 64, 49, 100, 91, 88, 93, 101, 56, 93, 17, 98, 90]], [[['A', 'X\x1d1']], [103, 56, 93, 17]], [[['A', 'AB'], ['B', 'Q'], ['B', 'z~']], [103, 33, 34, 100, 49, 90, 94]], [[['A', 'AB'], ['FNC1']], [103, 33, 34, 102]], [[['B', 'z~'], ['SHIFT', 'z'], ['FNC1']], {'error': 'unencodable', 'char': 'z'}], [[['C', ' 1'], ['C', '0099'], ['FNC1'], ['SHIFT', '\x1d']], {'error': 'bad-c'}], [[['B', '{x}'], ['A', '_^']], [104, 91, 88, 93, 101, 63, 62]], [[['A', 'AB'], ['A', '\x00Q'], ['A', '\x00Q'], ['B', 'z~']], [103, 33, 34, 64, 49, 64, 49, 100, 90, 94]]], [[[['C', '12'], ['FNC1'], ['C', '4711'], ['A', '\x00Q']], [105, 12, 102, 47, 11, 101, 64, 49]], [[['A', '\t'], ['C', '4711'], ['B', 'Q'], ['B', 'ab']], [103, 73, 99, 47, 11, 100, 49, 65, 66]], [[['B', 'Lot 7']], [104, 44, 79, 84, 0, 23]], [[['C', '0099']], [105, 0, 99]], [[['A', 'AB']], [103, 33, 34]], [[['FNC1'], ['FNC1'], ['A', 'HELLO'], ['C', '4711']], {'error': 'no-start'}], [[['C', '12']], [105, 12]], [[['A', 'X\x1d1']], [103, 56, 93, 17]]], [[[['A', 'X\x1d1'], ['A', 'HELLO']], [103, 56, 93, 17, 40, 37, 44, 44, 47]], [[['C', '4711'], ['A', '\t'], ['B', '{x}']], [105, 47, 11, 101, 73, 100, 91, 88, 93]], [[['B', 'z~']], [104, 90, 94]], [[['C', ' 1'], ['FNC1'], ['C', ' 1'], ['A', '_^']], {'error': 'bad-c'}], [[['C', ' 1'], ['C', '0099']], {'error': 'bad-c'}], [[['C', '4711']], [105, 47, 11]], [[['A', 'HELLO'], ['A', '_^'], ['A', '_^']], [103, 40, 37, 44, 44, 47, 63, 62, 63, 62]], [[['C', '4711'], ['B', 'ab'], ['A', 'X\x1d1']], [105, 47, 11, 100, 65, 66, 101, 56, 93, 17]]], [[[['A', 'X\x1d1'], ['FNC1'], ['A', '_^'], ['B', '{x}']], [103, 56, 93, 17, 102, 63, 62, 100, 91, 88, 93]], [[['C', '4711'], ['B', '{x}'], ['A', 'X\x1d1']], [105, 47, 11, 100, 91, 88, 93, 101, 56, 93, 17]], [[['C', '4711'], ['B', 'Q'], ['B', '{x}']], [105, 47, 11, 100, 49, 91, 88, 93]], [[['B', '{x}'], ['B', 'Q']], [104, 91, 88, 93, 49]], [[['A', 'AB']], [103, 33, 34]], [[['FNC1'], ['A', 'X\x1d1']], {'error': 'no-start'}], [[['B', 'Lot 7']], [104, 44, 79, 84, 0, 23]], [[['A', '\t'], ['FNC1']], [103, 73, 102]]]]
labels = ["regression: set A control character offset", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A GS separator encoded in set A decodes as "=", corrupting GS1 data.

Turn planned Code 128 segments into symbol values (without the checksum). Segments are [set, text], ["FNC1"] or ["SHIFT", char]. The first set segment emits its start (A 103, B 104, C 105); later set changes emit Code A 101, Code B 100 or Code C 99. Set A encodes 32..95 as ord-32 and 0..31 as ord+64; set B encodes 32..127 as ord-32; set C encodes even-length ASCII digit text as pair values. FNC1 is 102 and needs a prior start; SHIFT (98) is only valid in A or B and encodes one character in the other of A/B. Errors: no-start, bad-shift, bad-c, unencodable.

split: open-access