{"abstract":"The plain-text alternative is shown although a richer supported alternative follows it.","category":"Email MIME structure","checks":7,"contract":"Alternatives are ordered by increasing fidelity, so the LAST part whose effective type is in `supported` wins. A multipart/related alternative counts as its root type: the child whose cid equals the start parameter (which carries angle brackets, cids are stored bare) or else the first child. A text/* part is only renderable when its charset (default us-ascii, case-insensitive) is us-ascii, utf-8 or iso-8859-1. With nothing renderable the first part is shown as a fallback. Result {index, type, fallback}.","evaluation_group":"w2-email_mime_structure-alternative-pick","failed_approach":"Preferring HTML specifically still ignores a later, richer supported format. The attempted `best = i if t == 'text/html' or best is None else best` still disagrees with a fixture.","family":"w2-email_mime_structure-alternative-pick-last-supported-wins","id":"FA-76341","implementations":{"attempt":{"sha256":"27f8995e4215a169be9ed15ac990b505a4558db9610f980fa3316be6f909c1a0","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(part, supported):\n    def effective(p):\n        if p['type'] == 'multipart/related':\n            start = p.get('params', {}).get('start')\n            for c in p['parts']:\n                if start is not None and c.get('cid') == start.strip('<>'):\n                    return c['type']\n            return p['parts'][0]['type'] if p['parts'] else None\n        return p['type']\n    ok_charsets = ('us-ascii', 'utf-8', 'iso-8859-1')\n    best = None\n    for i, p in enumerate(part['parts']):\n        t = effective(p)\n        cs = p.get('params', {}).get('charset', 'us-ascii').lower()\n        if t in supported and (not t.startswith('text/') or cs in ok_charsets):\n            best = i if t == 'text/html' or best is None else best\n    if best is None:\n        return {'index': 0, 'type': effective(part['parts'][0]), 'fallback': True}\n    return {'index': best, 'type': effective(part['parts'][best]), 'fallback': False}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\n_CASES = {1: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown1'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root1@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root1@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 2: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown2'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root2@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root2@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'UTF-8'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 3: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown3'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root3@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root3@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 4: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown4'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root4@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root4@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'UTF-8'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 5: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown5'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root5@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root5@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})]}\nfor _label, _args, _expected in _CASES[N]:\n    check(_label, solve(*_args), _expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"2a83109c62c434cad3a867bbb64b452547a9420af04fb07d50e976cfde0eaf83","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(part, supported):\n    def effective(p):\n        if p['type'] == 'multipart/related':\n            start = p.get('params', {}).get('start')\n            for c in p['parts']:\n                if start is not None and c.get('cid') == start.strip('<>'):\n                    return c['type']\n            return p['parts'][0]['type'] if p['parts'] else None\n        return p['type']\n    ok_charsets = ('us-ascii', 'utf-8', 'iso-8859-1')\n    best = None\n    for i, p in enumerate(part['parts']):\n        t = effective(p)\n        cs = p.get('params', {}).get('charset', 'us-ascii').lower()\n        if t in supported and (not t.startswith('text/') or cs in ok_charsets):\n            best = i if best is None else best\n    if best is None:\n        return {'index': 0, 'type': effective(part['parts'][0]), 'fallback': True}\n    return {'index': best, 'type': effective(part['parts'][best]), 'fallback': False}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\n_CASES = {1: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown1'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root1@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root1@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 2: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown2'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root2@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root2@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'UTF-8'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 3: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown3'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root3@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root3@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 4: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown4'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root4@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root4@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'UTF-8'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 5: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown5'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root5@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root5@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})]}\nfor _label, _args, _expected in _CASES[N]:\n    check(_label, solve(*_args), _expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"2aedc2c63759913515e0d457a408af5dfedb8aa56be4c947e76fe1d6860e4b29","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(part, supported):\n    def effective(p):\n        if p['type'] == 'multipart/related':\n            start = p.get('params', {}).get('start')\n            for c in p['parts']:\n                if start is not None and c.get('cid') == start.strip('<>'):\n                    return c['type']\n            return p['parts'][0]['type'] if p['parts'] else None\n        return p['type']\n    ok_charsets = ('us-ascii', 'utf-8', 'iso-8859-1')\n    best = None\n    for i, p in enumerate(part['parts']):\n        t = effective(p)\n        cs = p.get('params', {}).get('charset', 'us-ascii').lower()\n        if t in supported and (not t.startswith('text/') or cs in ok_charsets):\n            best = i\n    if best is None:\n        return {'index': 0, 'type': effective(part['parts'][0]), 'fallback': True}\n    return {'index': best, 'type': effective(part['parts'][best]), 'fallback': False}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\n_CASES = {1: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown1'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root1@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root1@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 2: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown2'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root2@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root2@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'UTF-8'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 3: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown3'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root3@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root3@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 4: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown4'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root4@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root4@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'UTF-8'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})], 5: [('richest supported last', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-amp-html'}]}, ['text/plain', 'text/html', 'text/x-amp-html']), {'fallback': False, 'index': 2, 'type': 'text/x-amp-html'}), ('unsupported last part', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}, {'type': 'text/x-unknown5'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('related root via start', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'multipart/related', 'params': {'start': '<root5@x>'}, 'parts': [{'type': 'image/png', 'cid': 'img@x'}, {'type': 'text/html', 'cid': 'root5@x'}]}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('upper-case charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'params': {'charset': 'UTF-8'}}, {'type': 'text/html', 'params': {'charset': 'ISO-8859-1'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('missing charset', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 1, 'type': 'text/html'}), ('unknown charset html', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html', 'params': {'charset': 'x-klingon'}}]}, ['text/plain', 'text/html']), {'fallback': False, 'index': 0, 'type': 'text/plain'}), ('nothing supported', ({'type': 'multipart/alternative', 'parts': [{'type': 'application/x-foo'}, {'type': 'text/x-bar'}]}, ['text/plain']), {'fallback': True, 'index': 0, 'type': 'application/x-foo'})]}\nfor _label, _args, _expected in _CASES[N]:\n    check(_label, solve(*_args), _expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"Stipulated offline model over pre-parsed MIME dictionaries; not a conforming MIME parser, generator or mail client. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-email_mime_structure-alternative-pick-last-supported-wins","generated_at":"2026-09-29T14:49:15.435869+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Choosing the wrong alternative shows raw markup, a degraded body or an unreadable charset to the reader.","repair":"Use `best = i` for the last supported wins decision and keep every other rule of the model unchanged.","root_cause":"The last supported wins decision evaluates `best = i if best is None else best` where the contract requires `best = i`.","sha256":"2a3d7770a5633898f4be0f60bfa57d1ed1d4bf55364a977da954601656ed8dae","title":"Pick the part to render from multipart/alternative: last supported wins · case 01","variant":1,"variant_policy":"N selects a different enumerated fixture set (renamed identifiers, part counts and sizes); boundary fixtures recur across variants.","verification":{"attempt":{"elapsed_ms":38.818,"exit_code":1,"observations":[{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"richest supported last","expected":{"fallback":false,"index":2,"type":"text/x-amp-html"},"passed":false},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"unsupported last part","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"related root via start","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"upper-case charset","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"missing charset","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"unknown charset html","expected":{"fallback":false,"index":0,"type":"text/plain"},"passed":true},{"actual":{"fallback":true,"index":0,"type":"application/x-foo"},"check":"nothing supported","expected":{"fallback":true,"index":0,"type":"application/x-foo"},"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"richest supported last\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 2, \"type\": \"text/x-amp-html\"}, \"passed\": false}, {\"check\": \"unsupported last part\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"related root via start\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"upper-case charset\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"missing charset\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"unknown charset html\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 0, \"type\": \"text/plain\"}, \"passed\": true}, {\"check\": \"nothing supported\", \"actual\": {\"index\": 0, \"type\": \"application/x-foo\", \"fallback\": true}, \"expected\": {\"fallback\": true, \"index\": 0, \"type\": \"application/x-foo\"}, \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":38.845,"exit_code":1,"observations":[{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"richest supported last","expected":{"fallback":false,"index":2,"type":"text/x-amp-html"},"passed":false},{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"unsupported last part","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":false},{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"related root via start","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":false},{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"upper-case charset","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":false},{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"missing charset","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":false},{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"unknown charset html","expected":{"fallback":false,"index":0,"type":"text/plain"},"passed":true},{"actual":{"fallback":true,"index":0,"type":"application/x-foo"},"check":"nothing supported","expected":{"fallback":true,"index":0,"type":"application/x-foo"},"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"richest supported last\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 2, \"type\": \"text/x-amp-html\"}, \"passed\": false}, {\"check\": \"unsupported last part\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": false}, {\"check\": \"related root via start\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": false}, {\"check\": \"upper-case charset\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": false}, {\"check\": \"missing charset\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": false}, {\"check\": \"unknown charset html\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 0, \"type\": \"text/plain\"}, \"passed\": true}, {\"check\": \"nothing supported\", \"actual\": {\"index\": 0, \"type\": \"application/x-foo\", \"fallback\": true}, \"expected\": {\"fallback\": true, \"index\": 0, \"type\": \"application/x-foo\"}, \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":41.274,"exit_code":0,"observations":[{"actual":{"fallback":false,"index":2,"type":"text/x-amp-html"},"check":"richest supported last","expected":{"fallback":false,"index":2,"type":"text/x-amp-html"},"passed":true},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"unsupported last part","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"related root via start","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"upper-case charset","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":1,"type":"text/html"},"check":"missing charset","expected":{"fallback":false,"index":1,"type":"text/html"},"passed":true},{"actual":{"fallback":false,"index":0,"type":"text/plain"},"check":"unknown charset html","expected":{"fallback":false,"index":0,"type":"text/plain"},"passed":true},{"actual":{"fallback":true,"index":0,"type":"application/x-foo"},"check":"nothing supported","expected":{"fallback":true,"index":0,"type":"application/x-foo"},"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"richest supported last\", \"actual\": {\"index\": 2, \"type\": \"text/x-amp-html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 2, \"type\": \"text/x-amp-html\"}, \"passed\": true}, {\"check\": \"unsupported last part\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"related root via start\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"upper-case charset\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"missing charset\", \"actual\": {\"index\": 1, \"type\": \"text/html\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 1, \"type\": \"text/html\"}, \"passed\": true}, {\"check\": \"unknown charset html\", \"actual\": {\"index\": 0, \"type\": \"text/plain\", \"fallback\": false}, \"expected\": {\"fallback\": false, \"index\": 0, \"type\": \"text/plain\"}, \"passed\": true}, {\"check\": \"nothing supported\", \"actual\": {\"index\": 0, \"type\": \"application/x-foo\", \"fallback\": true}, \"expected\": {\"fallback\": true, \"index\": 0, \"type\": \"application/x-foo\"}, \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}