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

N = 1
observations = []
def solve(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            va, vb = m.pop(a, None), m.pop(b, None)
            if vb is not None:
                m[a] = vb
            if va is not None:
                m[b] = va
    if 'Orientation' in m:
        m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = '1'
    if 'ThumbOrientation' in m:
        m['ThumbOrientation'] = 1
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'Orientation': 0, 'PixelXDimension': 426, 'PixelYDimension': 2753, 'ImageLength': 1686, 'XResolution': 268, 'YResolution': 397, 'ThumbOrientation': 1}, [['ImageLength', 1686], ['Orientation', 1], ['PixelXDimension', 426], ['PixelYDimension', 2753], ['XResolution', 268], ['YResolution', 397]]], [{'Orientation': 1, 'ImageLength': 3874, 'XResolution': 212, 'YResolution': 218, 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 3874], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 212], ['YResolution', 218]]], [{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]], [{'Orientation': 8, 'PixelXDimension': 3494, 'PixelYDimension': 3689, 'ImageLength': 3230, 'XResolution': 115, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageWidth', 3230], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3689], ['PixelYDimension', 3494], ['XMP:Orientation', '1'], ['YResolution', 115]]]], [[{'PixelXDimension': 611, 'PixelYDimension': 1679, 'ImageWidth': 4933, 'ImageLength': 565, 'XMP:Orientation': '1', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 565], ['ImageWidth', 4933], ['Make', 'Acme'], ['PixelXDimension', 611], ['PixelYDimension', 1679], ['XMP:Orientation', '1']]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'Orientation': 0, 'PixelXDimension': 4667, 'PixelYDimension': 3674, 'ImageWidth': 196, 'ImageLength': 1876, 'XResolution': 272, 'YResolution': 257, 'ThumbOrientation': 6}, [['ImageLength', 1876], ['ImageWidth', 196], ['Orientation', 1], ['PixelXDimension', 4667], ['PixelYDimension', 3674], ['XResolution', 272], ['YResolution', 257]]], [{'Orientation': 4, 'PixelXDimension': 3641, 'PixelYDimension': 200, 'ImageWidth': 281, 'ImageLength': 2394, 'XResolution': 180, 'YResolution': 93, 'XMP:Orientation': '3'}, [['ImageLength', 2394], ['ImageWidth', 281], ['Orientation', 1], ['PixelXDimension', 3641], ['PixelYDimension', 200], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 93]]], [{'Orientation': 9, 'PixelXDimension': 2878, 'PixelYDimension': 2483, 'ImageWidth': 468, 'XResolution': 118, 'YResolution': 200, 'Make': 'Acme'}, [['ImageWidth', 468], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2878], ['PixelYDimension', 2483], ['XResolution', 118], ['YResolution', 200]]], [{'Orientation': 8, 'PixelXDimension': 2357, 'ImageWidth': 4348, 'ImageLength': 2027, 'XResolution': 114, 'XMP:Orientation': '3', 'Make': 'Acme'}, [['ImageLength', 4348], ['ImageWidth', 2027], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 2357], ['XMP:Orientation', '1'], ['YResolution', 114]]], [{'Orientation': 4, 'PixelXDimension': 3161, 'PixelYDimension': 4563, 'XResolution': 307, 'YResolution': 370, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3161], ['PixelYDimension', 4563], ['XResolution', 307], ['YResolution', 370]]], [{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]]], [[{'PixelXDimension': 2001, 'ImageWidth': 642, 'YResolution': 161, 'ThumbOrientation': 8}, [['ImageWidth', 642], ['PixelXDimension', 2001], ['YResolution', 161]]], [{'Orientation': 0, 'PixelXDimension': 3600, 'PixelYDimension': 835, 'ImageWidth': 3858, 'ImageLength': 3199, 'XResolution': 283, 'YResolution': 299, 'XMP:Orientation': '3', 'ThumbOrientation': 1}, [['ImageLength', 3199], ['ImageWidth', 3858], ['Orientation', 1], ['PixelXDimension', 3600], ['PixelYDimension', 835], ['XMP:Orientation', '1'], ['XResolution', 283], ['YResolution', 299]]], [{'Orientation': 1, 'XResolution': 312, 'YResolution': 385, 'XMP:Orientation': '1', 'ThumbOrientation': 1}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 312], ['YResolution', 385]]], [{'Orientation': 1, 'PixelYDimension': 4637, 'ImageWidth': 844, 'ImageLength': 4281, 'XResolution': 123, 'XMP:Orientation': '1'}, [['ImageLength', 4281], ['ImageWidth', 844], ['Orientation', 1], ['PixelYDimension', 4637], ['XMP:Orientation', '1'], ['XResolution', 123]]], [{'Orientation': 9, 'PixelXDimension': 2099, 'PixelYDimension': 2710, 'XResolution': 330, 'YResolution': 270, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2099], ['PixelYDimension', 2710], ['XResolution', 330], ['YResolution', 270]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]], [{'Orientation': 6, 'PixelXDimension': 1678, 'PixelYDimension': 2248, 'ImageWidth': 1422, 'ImageLength': 2871, 'YResolution': 243, 'XMP:Orientation': '1'}, [['ImageLength', 1422], ['ImageWidth', 2871], ['Orientation', 1], ['PixelXDimension', 2248], ['PixelYDimension', 1678], ['XMP:Orientation', '1'], ['XResolution', 243]]], [{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]]], [[{'Orientation': 3, 'PixelXDimension': 1081, 'PixelYDimension': 160, 'ImageWidth': 4451, 'ImageLength': 4974, 'XResolution': 180, 'YResolution': 379, 'XMP:Orientation': '8', 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4974], ['ImageWidth', 4451], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1081], ['PixelYDimension', 160], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 379]]], [{'Orientation': 1, 'PixelXDimension': 2164, 'ImageWidth': 2071, 'ImageLength': 4508, 'XResolution': 101, 'ThumbOrientation': 1}, [['ImageLength', 4508], ['ImageWidth', 2071], ['Orientation', 1], ['PixelXDimension', 2164], ['XResolution', 101]]], [{'Orientation': 1, 'PixelXDimension': 4642, 'PixelYDimension': 4169, 'ImageWidth': 1567, 'XResolution': 144, 'YResolution': 331, 'XMP:Orientation': '6', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageWidth', 1567], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4642], ['PixelYDimension', 4169], ['XMP:Orientation', '1'], ['XResolution', 144], ['YResolution', 331]]], [{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]], [{'Orientation': 6, 'PixelXDimension': 2290, 'ImageWidth': 1257, 'ImageLength': 2949, 'XResolution': 142, 'YResolution': 251, 'XMP:Orientation': '8'}, [['ImageLength', 1257], ['ImageWidth', 2949], ['Orientation', 1], ['PixelYDimension', 2290], ['XMP:Orientation', '1'], ['XResolution', 251], ['YResolution', 142]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'PixelXDimension': 491, 'PixelYDimension': 1510, 'ImageWidth': 3083, 'ImageLength': 4807, 'XResolution': 307, 'YResolution': 118, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4807], ['ImageWidth', 3083], ['Make', 'Acme'], ['PixelXDimension', 491], ['PixelYDimension', 1510], ['XResolution', 307], ['YResolution', 118]]]], [[{'Orientation': 4, 'PixelYDimension': 1209, 'ImageWidth': 3039, 'ImageLength': 4709, 'XResolution': 133, 'YResolution': 298, 'XMP:Orientation': '3', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 4709], ['ImageWidth', 3039], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 1209], ['XMP:Orientation', '1'], ['XResolution', 133], ['YResolution', 298]]], [{'PixelXDimension': 2095, 'PixelYDimension': 4143, 'ImageWidth': 3622, 'ImageLength': 1172, 'XResolution': 182, 'ThumbOrientation': 6}, [['ImageLength', 1172], ['ImageWidth', 3622], ['PixelXDimension', 2095], ['PixelYDimension', 4143], ['XResolution', 182]]], [{'PixelYDimension': 1895, 'ImageWidth': 4671, 'ImageLength': 985, 'XResolution': 348, 'ThumbOrientation': 6}, [['ImageLength', 985], ['ImageWidth', 4671], ['PixelYDimension', 1895], ['XResolution', 348]]], [{'Orientation': 8, 'PixelXDimension': 522, 'XResolution': 367, 'XMP:Orientation': '3'}, [['Orientation', 1], ['PixelYDimension', 522], ['XMP:Orientation', '1'], ['YResolution', 367]]], [{'Orientation': 5, 'ImageWidth': 837, 'ImageLength': 4624, 'XResolution': 268, 'YResolution': 385}, [['ImageLength', 837], ['ImageWidth', 4624], ['Orientation', 1], ['XResolution', 385], ['YResolution', 268]]], [{'Orientation': 9, 'ImageWidth': 4790, 'ImageLength': 4004, 'XResolution': 219, 'YResolution': 340, 'Make': 'Acme'}, [['ImageLength', 4004], ['ImageWidth', 4790], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 219], ['YResolution', 340]]], [{'Orientation': 2, 'PixelXDimension': 2789, 'PixelYDimension': 663, 'ImageWidth': 2446, 'ImageLength': 1685, 'XResolution': 229, 'YResolution': 275, 'XMP:Orientation': '6'}, [['ImageLength', 1685], ['ImageWidth', 2446], ['Orientation', 1], ['PixelXDimension', 2789], ['PixelYDimension', 663], ['XMP:Orientation', '1'], ['XResolution', 229], ['YResolution', 275]]], [{'Orientation': 0, 'PixelXDimension': 1747, 'PixelYDimension': 1995, 'ImageWidth': 3753, 'ImageLength': 2338, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 2338], ['ImageWidth', 3753], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1747], ['PixelYDimension', 1995], ['XMP:Orientation', '1']]]]]
labels = ["regression: thumbnail orientation removal", "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(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            va, vb = m.pop(a, None), m.pop(b, None)
            if vb is not None:
                m[a] = vb
            if va is not None:
                m[b] = va
    if 'Orientation' in m:
        m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = '1'
    if t != 1:
        m.pop('ThumbOrientation', None)
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'Orientation': 0, 'PixelXDimension': 426, 'PixelYDimension': 2753, 'ImageLength': 1686, 'XResolution': 268, 'YResolution': 397, 'ThumbOrientation': 1}, [['ImageLength', 1686], ['Orientation', 1], ['PixelXDimension', 426], ['PixelYDimension', 2753], ['XResolution', 268], ['YResolution', 397]]], [{'Orientation': 1, 'ImageLength': 3874, 'XResolution': 212, 'YResolution': 218, 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 3874], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 212], ['YResolution', 218]]], [{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]], [{'Orientation': 8, 'PixelXDimension': 3494, 'PixelYDimension': 3689, 'ImageLength': 3230, 'XResolution': 115, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageWidth', 3230], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3689], ['PixelYDimension', 3494], ['XMP:Orientation', '1'], ['YResolution', 115]]]], [[{'PixelXDimension': 611, 'PixelYDimension': 1679, 'ImageWidth': 4933, 'ImageLength': 565, 'XMP:Orientation': '1', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 565], ['ImageWidth', 4933], ['Make', 'Acme'], ['PixelXDimension', 611], ['PixelYDimension', 1679], ['XMP:Orientation', '1']]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'Orientation': 0, 'PixelXDimension': 4667, 'PixelYDimension': 3674, 'ImageWidth': 196, 'ImageLength': 1876, 'XResolution': 272, 'YResolution': 257, 'ThumbOrientation': 6}, [['ImageLength', 1876], ['ImageWidth', 196], ['Orientation', 1], ['PixelXDimension', 4667], ['PixelYDimension', 3674], ['XResolution', 272], ['YResolution', 257]]], [{'Orientation': 4, 'PixelXDimension': 3641, 'PixelYDimension': 200, 'ImageWidth': 281, 'ImageLength': 2394, 'XResolution': 180, 'YResolution': 93, 'XMP:Orientation': '3'}, [['ImageLength', 2394], ['ImageWidth', 281], ['Orientation', 1], ['PixelXDimension', 3641], ['PixelYDimension', 200], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 93]]], [{'Orientation': 9, 'PixelXDimension': 2878, 'PixelYDimension': 2483, 'ImageWidth': 468, 'XResolution': 118, 'YResolution': 200, 'Make': 'Acme'}, [['ImageWidth', 468], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2878], ['PixelYDimension', 2483], ['XResolution', 118], ['YResolution', 200]]], [{'Orientation': 8, 'PixelXDimension': 2357, 'ImageWidth': 4348, 'ImageLength': 2027, 'XResolution': 114, 'XMP:Orientation': '3', 'Make': 'Acme'}, [['ImageLength', 4348], ['ImageWidth', 2027], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 2357], ['XMP:Orientation', '1'], ['YResolution', 114]]], [{'Orientation': 4, 'PixelXDimension': 3161, 'PixelYDimension': 4563, 'XResolution': 307, 'YResolution': 370, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3161], ['PixelYDimension', 4563], ['XResolution', 307], ['YResolution', 370]]], [{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]]], [[{'PixelXDimension': 2001, 'ImageWidth': 642, 'YResolution': 161, 'ThumbOrientation': 8}, [['ImageWidth', 642], ['PixelXDimension', 2001], ['YResolution', 161]]], [{'Orientation': 0, 'PixelXDimension': 3600, 'PixelYDimension': 835, 'ImageWidth': 3858, 'ImageLength': 3199, 'XResolution': 283, 'YResolution': 299, 'XMP:Orientation': '3', 'ThumbOrientation': 1}, [['ImageLength', 3199], ['ImageWidth', 3858], ['Orientation', 1], ['PixelXDimension', 3600], ['PixelYDimension', 835], ['XMP:Orientation', '1'], ['XResolution', 283], ['YResolution', 299]]], [{'Orientation': 1, 'XResolution': 312, 'YResolution': 385, 'XMP:Orientation': '1', 'ThumbOrientation': 1}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 312], ['YResolution', 385]]], [{'Orientation': 1, 'PixelYDimension': 4637, 'ImageWidth': 844, 'ImageLength': 4281, 'XResolution': 123, 'XMP:Orientation': '1'}, [['ImageLength', 4281], ['ImageWidth', 844], ['Orientation', 1], ['PixelYDimension', 4637], ['XMP:Orientation', '1'], ['XResolution', 123]]], [{'Orientation': 9, 'PixelXDimension': 2099, 'PixelYDimension': 2710, 'XResolution': 330, 'YResolution': 270, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2099], ['PixelYDimension', 2710], ['XResolution', 330], ['YResolution', 270]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]], [{'Orientation': 6, 'PixelXDimension': 1678, 'PixelYDimension': 2248, 'ImageWidth': 1422, 'ImageLength': 2871, 'YResolution': 243, 'XMP:Orientation': '1'}, [['ImageLength', 1422], ['ImageWidth', 2871], ['Orientation', 1], ['PixelXDimension', 2248], ['PixelYDimension', 1678], ['XMP:Orientation', '1'], ['XResolution', 243]]], [{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]]], [[{'Orientation': 3, 'PixelXDimension': 1081, 'PixelYDimension': 160, 'ImageWidth': 4451, 'ImageLength': 4974, 'XResolution': 180, 'YResolution': 379, 'XMP:Orientation': '8', 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4974], ['ImageWidth', 4451], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1081], ['PixelYDimension', 160], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 379]]], [{'Orientation': 1, 'PixelXDimension': 2164, 'ImageWidth': 2071, 'ImageLength': 4508, 'XResolution': 101, 'ThumbOrientation': 1}, [['ImageLength', 4508], ['ImageWidth', 2071], ['Orientation', 1], ['PixelXDimension', 2164], ['XResolution', 101]]], [{'Orientation': 1, 'PixelXDimension': 4642, 'PixelYDimension': 4169, 'ImageWidth': 1567, 'XResolution': 144, 'YResolution': 331, 'XMP:Orientation': '6', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageWidth', 1567], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4642], ['PixelYDimension', 4169], ['XMP:Orientation', '1'], ['XResolution', 144], ['YResolution', 331]]], [{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]], [{'Orientation': 6, 'PixelXDimension': 2290, 'ImageWidth': 1257, 'ImageLength': 2949, 'XResolution': 142, 'YResolution': 251, 'XMP:Orientation': '8'}, [['ImageLength', 1257], ['ImageWidth', 2949], ['Orientation', 1], ['PixelYDimension', 2290], ['XMP:Orientation', '1'], ['XResolution', 251], ['YResolution', 142]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'PixelXDimension': 491, 'PixelYDimension': 1510, 'ImageWidth': 3083, 'ImageLength': 4807, 'XResolution': 307, 'YResolution': 118, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4807], ['ImageWidth', 3083], ['Make', 'Acme'], ['PixelXDimension', 491], ['PixelYDimension', 1510], ['XResolution', 307], ['YResolution', 118]]]], [[{'Orientation': 4, 'PixelYDimension': 1209, 'ImageWidth': 3039, 'ImageLength': 4709, 'XResolution': 133, 'YResolution': 298, 'XMP:Orientation': '3', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 4709], ['ImageWidth', 3039], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 1209], ['XMP:Orientation', '1'], ['XResolution', 133], ['YResolution', 298]]], [{'PixelXDimension': 2095, 'PixelYDimension': 4143, 'ImageWidth': 3622, 'ImageLength': 1172, 'XResolution': 182, 'ThumbOrientation': 6}, [['ImageLength', 1172], ['ImageWidth', 3622], ['PixelXDimension', 2095], ['PixelYDimension', 4143], ['XResolution', 182]]], [{'PixelYDimension': 1895, 'ImageWidth': 4671, 'ImageLength': 985, 'XResolution': 348, 'ThumbOrientation': 6}, [['ImageLength', 985], ['ImageWidth', 4671], ['PixelYDimension', 1895], ['XResolution', 348]]], [{'Orientation': 8, 'PixelXDimension': 522, 'XResolution': 367, 'XMP:Orientation': '3'}, [['Orientation', 1], ['PixelYDimension', 522], ['XMP:Orientation', '1'], ['YResolution', 367]]], [{'Orientation': 5, 'ImageWidth': 837, 'ImageLength': 4624, 'XResolution': 268, 'YResolution': 385}, [['ImageLength', 837], ['ImageWidth', 4624], ['Orientation', 1], ['XResolution', 385], ['YResolution', 268]]], [{'Orientation': 9, 'ImageWidth': 4790, 'ImageLength': 4004, 'XResolution': 219, 'YResolution': 340, 'Make': 'Acme'}, [['ImageLength', 4004], ['ImageWidth', 4790], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 219], ['YResolution', 340]]], [{'Orientation': 2, 'PixelXDimension': 2789, 'PixelYDimension': 663, 'ImageWidth': 2446, 'ImageLength': 1685, 'XResolution': 229, 'YResolution': 275, 'XMP:Orientation': '6'}, [['ImageLength', 1685], ['ImageWidth', 2446], ['Orientation', 1], ['PixelXDimension', 2789], ['PixelYDimension', 663], ['XMP:Orientation', '1'], ['XResolution', 229], ['YResolution', 275]]], [{'Orientation': 0, 'PixelXDimension': 1747, 'PixelYDimension': 1995, 'ImageWidth': 3753, 'ImageLength': 2338, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 2338], ['ImageWidth', 3753], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1747], ['PixelYDimension', 1995], ['XMP:Orientation', '1']]]]]
labels = ["regression: thumbnail orientation removal", "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:
Viewers that trust the thumbnail tag show a stale value for the regenerated thumbnail.

After pixels have been baked upright, rewrite the metadata dictionary. When the (valid) Orientation is 5..8, exchange PixelXDimension/PixelYDimension, ImageWidth/ImageLength and XResolution/YResolution, moving a lone member of a pair to its partner key. Invalid or missing Orientation values mean no swap. Orientation is set to 1 only if the key exists; XMP:Orientation, if present, becomes the string "1"; ThumbOrientation is removed because the thumbnail is regenerated. Return sorted [key, value] pairs.

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
Byte sequences after the start of scan are misread as an Exif segment in some files.

Input: JPEG segments as [marker, payload] with the payload as a latin-1 string. The stream must start with SOI (0xD8) or the result is "not-jpeg". Scan segments after SOI until SOS (0xDA) or EOI (0xD9); a payload longer than 65533 bytes cannot be encoded in the 16-bit length and yields "corrupt". Return the index of the first APP1 (0xE1) segment whose payload starts with "Exif\0\0", or None.

split: open-access


prompt:
A malformed APP1 whose identifier lacks the null padding shadows the real Exif segment.

Input: JPEG segments as [marker, payload] with the payload as a latin-1 string. The stream must start with SOI (0xD8) or the result is "not-jpeg". Scan segments after SOI until SOS (0xDA) or EOI (0xD9); a payload longer than 65533 bytes cannot be encoded in the 16-bit length and yields "corrupt". Return the index of the first APP1 (0xE1) segment whose payload starts with "Exif\0\0", or None.

split: open-access


prompt:
A JFIF extension that embeds an Exif-looking blob in APP0 is used as the orientation source.

Input: JPEG segments as [marker, payload] with the payload as a latin-1 string. The stream must start with SOI (0xD8) or the result is "not-jpeg". Scan segments after SOI until SOS (0xDA) or EOI (0xD9); a payload longer than 65533 bytes cannot be encoded in the 16-bit length and yields "corrupt". Return the index of the first APP1 (0xE1) segment whose payload starts with "Exif\0\0", or None.

split: open-access


prompt:
The writer rewrites the segment before the Exif block when updating orientation.

Input: JPEG segments as [marker, payload] with the payload as a latin-1 string. The stream must start with SOI (0xD8) or the result is "not-jpeg". Scan segments after SOI until SOS (0xDA) or EOI (0xD9); a payload longer than 65533 bytes cannot be encoded in the 16-bit length and yields "corrupt". Return the index of the first APP1 (0xE1) segment whose payload starts with "Exif\0\0", or None.

split: open-access


prompt:
A 65534-byte APP1 payload is accepted although its length field would overflow.

Input: JPEG segments as [marker, payload] with the payload as a latin-1 string. The stream must start with SOI (0xD8) or the result is "not-jpeg". Scan segments after SOI until SOS (0xDA) or EOI (0xD9); a payload longer than 65533 bytes cannot be encoded in the 16-bit length and yields "corrupt". Return the index of the first APP1 (0xE1) segment whose payload starts with "Exif\0\0", or None.

split: open-access


prompt:
Streams whose first segment is not SOI are scanned as JPEG.

Input: JPEG segments as [marker, payload] with the payload as a latin-1 string. The stream must start with SOI (0xD8) or the result is "not-jpeg". Scan segments after SOI until SOS (0xDA) or EOI (0xD9); a payload longer than 65533 bytes cannot be encoded in the 16-bit length and yields "corrupt". Return the index of the first APP1 (0xE1) segment whose payload starts with "Exif\0\0", or None.

split: open-access


prompt:
Clockwise-rotated photos are drawn partly outside the canvas on non-square images.

Input [w, h, tag]. Produce the canvas size and the 2D affine [a, b, c, d, e, f] (x' = a*x + c*y + e, y' = b*x + d*y + f, continuous coordinates, so mirroring an extent e maps x to e - x) that draws the stored image upright. Tags 5..8 use a [h, w] canvas; invalid tags are treated as 1.

split: open-access


prompt:
Counter-clockwise photos are cut off at the bottom of the canvas.

Input [w, h, tag]. Produce the canvas size and the 2D affine [a, b, c, d, e, f] (x' = a*x + c*y + e, y' = b*x + d*y + f, continuous coordinates, so mirroring an extent e maps x to e - x) that draws the stored image upright. Tags 5..8 use a [h, w] canvas; invalid tags are treated as 1.

split: open-access


prompt:
Mirrored images are drawn one pixel to the left with a transparent column on the right.

Input [w, h, tag]. Produce the canvas size and the 2D affine [a, b, c, d, e, f] (x' = a*x + c*y + e, y' = b*x + d*y + f, continuous coordinates, so mirroring an extent e maps x to e - x) that draws the stored image upright. Tags 5..8 use a [h, w] canvas; invalid tags are treated as 1.

split: open-access


prompt:
Tag-7 photos are shifted out of the canvas when width and height differ.

Input [w, h, tag]. Produce the canvas size and the 2D affine [a, b, c, d, e, f] (x' = a*x + c*y + e, y' = b*x + d*y + f, continuous coordinates, so mirroring an extent e maps x to e - x) that draws the stored image upright. Tags 5..8 use a [h, w] canvas; invalid tags are treated as 1.

split: open-access


prompt:
Tag 5 and 7 images are clipped into a canvas with the stored aspect ratio.

Input [w, h, tag]. Produce the canvas size and the 2D affine [a, b, c, d, e, f] (x' = a*x + c*y + e, y' = b*x + d*y + f, continuous coordinates, so mirroring an extent e maps x to e - x) that draws the stored image upright. Tags 5..8 use a [h, w] canvas; invalid tags are treated as 1.

split: open-access


prompt:
Top-bottom mirrored scans are drawn partly outside the canvas.

Input [w, h, tag]. Produce the canvas size and the 2D affine [a, b, c, d, e, f] (x' = a*x + c*y + e, y' = b*x + d*y + f, continuous coordinates, so mirroring an extent e maps x to e - x) that draws the stored image upright. Tags 5..8 use a [h, w] canvas; invalid tags are treated as 1.

split: open-access


prompt:
Rotated fax and scanner images with different X and Y resolutions print with the wrong physical size.

Input {w, h, tag?, unit?, xres: [num, den], yres?: [num, den]}. ResolutionUnit 2 is inches (25.4 mm), 3 is centimetres (10 mm), a missing unit defaults to 2 and any other unit has no physical size (None). A missing yres equals xres; non-positive rational parts give None. For tags 5..8 the displayed width comes from the stored height at YResolution. Return displayed [width, height] in tenths of a millimetre, each rounded half up from the exact value.

split: open-access


prompt:
Images whose resolution is in dots per centimetre print about four times too small.

Input {w, h, tag?, unit?, xres: [num, den], yres?: [num, den]}. ResolutionUnit 2 is inches (25.4 mm), 3 is centimetres (10 mm), a missing unit defaults to 2 and any other unit has no physical size (None). A missing yres equals xres; non-positive rational parts give None. For tags 5..8 the displayed width comes from the stored height at YResolution. Return displayed [width, height] in tenths of a millimetre, each rounded half up from the exact value.

split: open-access


prompt:
Most camera JPEGs, which omit the unit, report no physical print size.

Input {w, h, tag?, unit?, xres: [num, den], yres?: [num, den]}. ResolutionUnit 2 is inches (25.4 mm), 3 is centimetres (10 mm), a missing unit defaults to 2 and any other unit has no physical size (None). A missing yres equals xres; non-positive rational parts give None. For tags 5..8 the displayed width comes from the stored height at YResolution. Return displayed [width, height] in tenths of a millimetre, each rounded half up from the exact value.

split: open-access


prompt:
A 300 dpi scan without a YResolution prints with a stretched height.

Input {w, h, tag?, unit?, xres: [num, den], yres?: [num, den]}. ResolutionUnit 2 is inches (25.4 mm), 3 is centimetres (10 mm), a missing unit defaults to 2 and any other unit has no physical size (None). A missing yres equals xres; non-positive rational parts give None. For tags 5..8 the displayed width comes from the stored height at YResolution. Return displayed [width, height] in tenths of a millimetre, each rounded half up from the exact value.

split: open-access


prompt:
Scans at 333 1/3 dpi or 72.00 stored as 7200/100 get slightly wrong printed widths.

Input {w, h, tag?, unit?, xres: [num, den], yres?: [num, den]}. ResolutionUnit 2 is inches (25.4 mm), 3 is centimetres (10 mm), a missing unit defaults to 2 and any other unit has no physical size (None). A missing yres equals xres; non-positive rational parts give None. For tags 5..8 the displayed width comes from the stored height at YResolution. Return displayed [width, height] in tenths of a millimetre, each rounded half up from the exact value.

split: open-access


prompt:
A corrupt negative resolution yields a negative physical width in the print dialog.

Input {w, h, tag?, unit?, xres: [num, den], yres?: [num, den]}. ResolutionUnit 2 is inches (25.4 mm), 3 is centimetres (10 mm), a missing unit defaults to 2 and any other unit has no physical size (None). A missing yres equals xres; non-positive rational parts give None. For tags 5..8 the displayed width comes from the stored height at YResolution. Return displayed [width, height] in tenths of a millimetre, each rounded half up from the exact value.

split: open-access


prompt:
Exact half tenths such as 2.5 are rounded down on some sizes and up on others.

Input {w, h, tag?, unit?, xres: [num, den], yres?: [num, den]}. ResolutionUnit 2 is inches (25.4 mm), 3 is centimetres (10 mm), a missing unit defaults to 2 and any other unit has no physical size (None). A missing yres equals xres; non-positive rational parts give None. For tags 5..8 the displayed width comes from the stored height at YResolution. Return displayed [width, height] in tenths of a millimetre, each rounded half up from the exact value.

split: open-access


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 = (k1 + (-k2 if m1 else k2)) % 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 == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [8, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [7, False]]], [[{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 2}, [7, False]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [1, False]], [{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'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': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]]], [[{'tag': 2, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 6}, [7, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [6, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 3}, [3, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [3, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]]], [[{'tag': 4, 'baked': True, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 7}, [8, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [5, True]], [{'tag': 8, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [7, False]], [{'tag': 7, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 2}, [2, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [2, False]]], [[{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [4, False]], [{'tag': 7, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 7}, [1, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [6, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]]]]
labels = ["regression: composition order", "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) % 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 == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [8, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [7, False]]], [[{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 2}, [7, False]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [1, False]], [{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'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': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]]], [[{'tag': 2, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 6}, [7, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [6, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 3}, [3, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [3, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]]], [[{'tag': 4, 'baked': True, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 7}, [8, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [5, True]], [{'tag': 8, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [7, False]], [{'tag': 7, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 2}, [2, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [2, False]]], [[{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [4, False]], [{'tag': 7, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 7}, [1, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [6, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]]]]
labels = ["regression: composition order", "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:
The upload checker mispredicts mirrored photos that were baked and then rotated again by the browser.

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


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'
    shown = compose(compose(pixels, meta if honored else 1), p.get('extra', 1))
    return [shown, shown == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [1, False]]], [[{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [1, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [6, True]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [1, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [2, True]]], [[{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [8, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, True]], [{'tag': 2, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [5, False]], [{'tag': 3, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [6, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [8, False]]], [[{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [6, False]], [{'tag': 4, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 2, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 7}, [6, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [1, False]]], [[{'tag': 2, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [4, False]], [{'tag': 7, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [7, True]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [4, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [5, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [7, False]]]]
labels = ["regression: cross-origin opt-out rule", "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' and not p['cross_origin']
    shown = compose(compose(pixels, meta if honored else 1), p.get('extra', 1))
    return [shown, shown == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [1, False]]], [[{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [1, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]], [{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [6, True]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [1, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [2, True]]], [[{'tag': 6, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [8, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, True]], [{'tag': 2, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [5, False]], [{'tag': 3, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [6, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [8, False]]], [[{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [6, False]], [{'tag': 4, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 2, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 7}, [6, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [1, False]]], [[{'tag': 2, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [4, False]], [{'tag': 7, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [7, True]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 2}, [4, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [5, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 3}, [7, False]]]]
labels = ["regression: cross-origin opt-out rule", "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:
CDN-hosted photos are predicted to render unrotated while browsers actually rotate them.

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


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'] and p['baked']:
        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 == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 2, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [5, True]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]]], [[{'tag': 4, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]]], [[{'tag': 5, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [5, True]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 5}, [1, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, False]]], [[{'tag': 8, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [6, False]], [{'tag': 7, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 2}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 6}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, False]]], [[{'tag': 6, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 5}, [7, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [5, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 5}, [5, False]]]]
labels = ["regression: stripped metadata", "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'] and not p['baked']:
        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 == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 2, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [5, True]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]]], [[{'tag': 4, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, False]]], [[{'tag': 5, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [5, True]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 5}, [1, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 5, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, False]]], [[{'tag': 8, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [6, False]], [{'tag': 7, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 2}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 6}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [8, True]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 5}, [7, False]], [{'tag': 3, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, False]]], [[{'tag': 6, 'baked': False, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 5}, [7, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [5, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 5}, [5, False]]]]
labels = ["regression: stripped metadata", "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:
Stripped but unbaked uploads are predicted to rotate even though no tag survives.

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


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['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 == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 3, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 5}, [7, False]]], [[{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [1, False]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 2}, [8, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]]], [[{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 3, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [6, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]]], [[{'tag': 2, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [2, True]], [{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, True]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 1, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 3}, [3, False]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 7, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [5, False]]], [[{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [4, True]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [5, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [3, False]]]]
labels = ["regression: reset flag scope", "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']:
        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 == tag]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'tag': 8, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [7, False]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 6}, [6, False]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 3}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [2, True]], [{'tag': 1, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 3, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 5}, [7, False]]], [[{'tag': 6, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [1, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 7}, [4, False]], [{'tag': 8, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [2, False]], [{'tag': 6, 'baked': True, 'reset': False, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [1, False]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 1}, [1, True]], [{'tag': 7, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 2}, [8, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 2}, [3, False]]], [[{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 3, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 3, 'baked': True, 'reset': True, 'stripped': True, 'css': 'none', 'cross_origin': False, 'extra': 8}, [6, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [1, False]], [{'tag': 4, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [2, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 6}, [2, False]]], [[{'tag': 2, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [2, True]], [{'tag': 7, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, True]], [{'tag': 0, 'baked': True, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 8}, [8, False]], [{'tag': 5, 'baked': False, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 1, 'baked': False, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 3}, [3, False]], [{'tag': 0, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [1, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 1}, [1, False]], [{'tag': 7, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 3}, [5, False]]], [[{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': True, 'extra': 1}, [4, True]], [{'tag': 2, 'baked': True, 'reset': False, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 7}, [7, False]], [{'tag': 2, 'baked': True, 'reset': True, 'stripped': True, 'css': 'from-image', 'cross_origin': False, 'extra': 8}, [5, False]], [{'tag': 5, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 6}, [2, False]], [{'tag': 0, 'baked': True, 'reset': False, 'stripped': False, 'css': 'none', 'cross_origin': False, 'extra': 5}, [5, False]], [{'tag': 5, 'baked': True, 'reset': True, 'stripped': False, 'css': 'none', 'cross_origin': True, 'extra': 1}, [5, True]], [{'tag': 8, 'baked': False, 'reset': False, 'stripped': True, 'css': 'none', 'cross_origin': True, 'extra': 2}, [2, False]], [{'tag': 4, 'baked': False, 'reset': True, 'stripped': False, 'css': 'from-image', 'cross_origin': False, 'extra': 2}, [3, False]]]]
labels = ["regression: reset flag scope", "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:
An upload that only reset the tag is predicted to be upright although its pixels were never rotated.

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