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

N = 1
observations = []
def solve(tree):
    methods = []
    ics = 0
    def walk(n):
        nonlocal ics
        t = n['type'].lower()
        if t.startswith('multipart/'):
            for c in n['parts']:
                walk(c)
            return
        if t == 'message/rfc822':
            return
        disp = (n.get('disp') or '').lower()
        if t == 'text/calendar' or False:
            if disp == 'attachment':
                ics += 1
                return
            if t == 'text/calendar':
                params = {k.lower(): v for k, v in n.get('params', {}).items()}
                if params.get('method'):
                    methods.append(params['method'].strip().upper())
    walk(tree)
    distinct = sorted(set(methods))
    method = None if not distinct else (distinct[0] if len(distinct) == 1 else 'AMBIGUOUS')
    return {'method': method, 'count': len(methods), 'attachments_ics': ics}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e1.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE1.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 2: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e2.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE2.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 3: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e3.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE3.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 4: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e4.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE4.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 5: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e5.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE5.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(tree):
    methods = []
    ics = 0
    def walk(n):
        nonlocal ics
        t = n['type'].lower()
        if t.startswith('multipart/'):
            for c in n['parts']:
                walk(c)
            return
        if t == 'message/rfc822':
            return
        disp = (n.get('disp') or '').lower()
        if t == 'text/calendar' or (n.get('filename') or '').endswith('.ics'):
            if disp == 'attachment':
                ics += 1
                return
            if t == 'text/calendar':
                params = {k.lower(): v for k, v in n.get('params', {}).items()}
                if params.get('method'):
                    methods.append(params['method'].strip().upper())
    walk(tree)
    distinct = sorted(set(methods))
    method = None if not distinct else (distinct[0] if len(distinct) == 1 else 'AMBIGUOUS')
    return {'method': method, 'count': len(methods), 'attachments_ics': ics}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e1.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE1.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 2: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e2.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE2.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 3: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e3.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE3.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 4: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e4.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE4.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})], 5: [('forwarded invitation', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'text/calendar', 'params': {'method': 'REQUEST'}}}]},), {'attachments_ics': 0, 'count': 0, 'method': None}), ('attached calendar with method', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'PUBLISH'}, 'disp': 'attachment', 'filename': 'e5.ics'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('padded lower-case method', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'Method': ' request '}}]},), {'attachments_ics': 0, 'count': 1, 'method': 'REQUEST'}), ('conflicting methods', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/calendar', 'params': {'method': 'REQUEST'}}, {'type': 'text/calendar', 'params': {'method': 'CANCEL'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'AMBIGUOUS'}), ('same method twice', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/calendar', 'params': {'method': 'REPLY'}}, {'type': 'text/calendar', 'params': {'method': 'reply'}}]},), {'attachments_ics': 0, 'count': 2, 'method': 'REPLY'}), ('upper-case ics attachment', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream', 'filename': 'INVITE5.ICS', 'disp': 'attachment'}]},), {'attachments_ics': 1, 'count': 0, 'method': None}), ('plain message', ({'type': 'text/plain'},), {'attachments_ics': 0, 'count': 0, 'method': None})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An .ics attachment sent as application/octet-stream is not counted.

Walk multiparts but never descend into message/rfc822 parts. A text/calendar part, or any part whose filename ends in ".ics" (case-insensitive), with an attachment disposition only counts as an attached .ics file. Other text/calendar parts with a method parameter contribute their method (trimmed, upper-cased; parameter names case-insensitive). Result {method: the single distinct method, "AMBIGUOUS" for several, None for none; count: contributing parts; attachments_ics}.

split: open-access


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

N = 1
observations = []
def solve(tree, base):
    out = []
    counter = [0]
    def contents(n):
        if 'parts' in n:
            return [x for c in n['parts'] for x in contents(c)]
        return [n.get('text', '')]
    def assign(n, ancestors):
        if 'parts' not in n:
            return
        texts = [c.get('text', '') for c in n['parts']]
        while True:
            counter[0] += 1
            cand = base + '_' + str(counter[0])
            if len(cand) > 70:
                out.append(None)
                return
            if any(cand in t for t in texts):
                continue
            if any(a.startswith(cand) or cand.startswith(a) for a in ancestors):
                continue
            break
        out.append(cand)
        for c in n['parts']:
            assign(c, ancestors + [cand])
    assign(tree, [])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b1_1 and b1_2'}]}]}, 'b1'), ['b1_3', 'b1_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q1_2 q1_3 q1_4 q1_5 q1_6 q1_7 q1_8 q1_9'}]}]}, 'q1'), ['q1_1', 'q1_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm1'), ['m1_1', 'm1_2', 'm1_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 2: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b2_1 and b2_2'}]}]}, 'b2'), ['b2_3', 'b2_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q2_2 q2_3 q2_4 q2_5 q2_6 q2_7 q2_8 q2_9'}]}]}, 'q2'), ['q2_1', 'q2_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm2'), ['m2_1', 'm2_2', 'm2_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 3: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b3_1 and b3_2'}]}]}, 'b3'), ['b3_3', 'b3_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8 q3_9'}]}]}, 'q3'), ['q3_1', 'q3_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm3'), ['m3_1', 'm3_2', 'm3_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 4: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b4_1 and b4_2'}]}]}, 'b4'), ['b4_3', 'b4_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8 q4_9'}]}]}, 'q4'), ['q4_1', 'q4_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm4'), ['m4_1', 'm4_2', 'm4_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 5: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b5_1 and b5_2'}]}]}, 'b5'), ['b5_3', 'b5_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q5_2 q5_3 q5_4 q5_5 q5_6 q5_7 q5_8 q5_9'}]}]}, 'q5'), ['q5_1', 'q5_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm5'), ['m5_1', 'm5_2', 'm5_3']), ('single leaf', ({'text': 'only'}, 'n'), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(tree, base):
    out = []
    counter = [0]
    def contents(n):
        if 'parts' in n:
            return [x for c in n['parts'] for x in contents(c)]
        return [n.get('text', '')]
    def assign(n, ancestors):
        if 'parts' not in n:
            return
        texts = contents(n['parts'][0])
        while True:
            counter[0] += 1
            cand = base + '_' + str(counter[0])
            if len(cand) > 70:
                out.append(None)
                return
            if any(cand in t for t in texts):
                continue
            if any(a.startswith(cand) or cand.startswith(a) for a in ancestors):
                continue
            break
        out.append(cand)
        for c in n['parts']:
            assign(c, ancestors + [cand])
    assign(tree, [])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b1_1 and b1_2'}]}]}, 'b1'), ['b1_3', 'b1_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q1_2 q1_3 q1_4 q1_5 q1_6 q1_7 q1_8 q1_9'}]}]}, 'q1'), ['q1_1', 'q1_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm1'), ['m1_1', 'm1_2', 'm1_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 2: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b2_1 and b2_2'}]}]}, 'b2'), ['b2_3', 'b2_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q2_2 q2_3 q2_4 q2_5 q2_6 q2_7 q2_8 q2_9'}]}]}, 'q2'), ['q2_1', 'q2_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm2'), ['m2_1', 'm2_2', 'm2_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 3: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b3_1 and b3_2'}]}]}, 'b3'), ['b3_3', 'b3_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8 q3_9'}]}]}, 'q3'), ['q3_1', 'q3_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm3'), ['m3_1', 'm3_2', 'm3_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 4: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b4_1 and b4_2'}]}]}, 'b4'), ['b4_3', 'b4_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8 q4_9'}]}]}, 'q4'), ['q4_1', 'q4_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm4'), ['m4_1', 'm4_2', 'm4_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 5: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b5_1 and b5_2'}]}]}, 'b5'), ['b5_3', 'b5_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q5_2 q5_3 q5_4 q5_5 q5_6 q5_7 q5_8 q5_9'}]}]}, 'q5'), ['q5_1', 'q5_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm5'), ['m5_1', 'm5_2', 'm5_3']), ('single leaf', ({'text': 'only'}, 'n'), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A boundary string that occurs inside a nested part is chosen for the outer multipart.

Multipart nodes have "parts", leaves have "text". Nodes are visited depth-first (pre-order) and a single counter produces candidates base_1, base_2, ... A candidate is rejected when it occurs in any text anywhere below the node, when it is a prefix of an ancestor boundary or an ancestor boundary is a prefix of it, and a candidate longer than 70 characters makes that node's boundary None (its subtree gets none). Result: boundaries in visiting order.

split: open-access


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

N = 1
observations = []
def solve(tree, base):
    out = []
    counter = [0]
    def contents(n):
        if 'parts' in n:
            return [x for c in n['parts'] for x in contents(c)]
        return [n.get('text', '')]
    def assign(n, ancestors):
        if 'parts' not in n:
            return
        texts = contents(n)
        while True:
            counter[0] += 1
            cand = base + '_' + str(counter[0])
            if len(cand) > 70:
                out.append(None)
                return
            if any(cand in t for t in texts):
                continue
            if any(a == cand for a in ancestors):
                continue
            break
        out.append(cand)
        for c in n['parts']:
            assign(c, ancestors + [cand])
    assign(tree, [])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b1_1 and b1_2'}]}]}, 'b1'), ['b1_3', 'b1_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q1_2 q1_3 q1_4 q1_5 q1_6 q1_7 q1_8 q1_9'}]}]}, 'q1'), ['q1_1', 'q1_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm1'), ['m1_1', 'm1_2', 'm1_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 2: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b2_1 and b2_2'}]}]}, 'b2'), ['b2_3', 'b2_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q2_2 q2_3 q2_4 q2_5 q2_6 q2_7 q2_8 q2_9'}]}]}, 'q2'), ['q2_1', 'q2_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm2'), ['m2_1', 'm2_2', 'm2_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 3: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b3_1 and b3_2'}]}]}, 'b3'), ['b3_3', 'b3_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8 q3_9'}]}]}, 'q3'), ['q3_1', 'q3_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm3'), ['m3_1', 'm3_2', 'm3_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 4: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b4_1 and b4_2'}]}]}, 'b4'), ['b4_3', 'b4_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8 q4_9'}]}]}, 'q4'), ['q4_1', 'q4_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm4'), ['m4_1', 'm4_2', 'm4_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 5: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b5_1 and b5_2'}]}]}, 'b5'), ['b5_3', 'b5_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q5_2 q5_3 q5_4 q5_5 q5_6 q5_7 q5_8 q5_9'}]}]}, 'q5'), ['q5_1', 'q5_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm5'), ['m5_1', 'm5_2', 'm5_3']), ('single leaf', ({'text': 'only'}, 'n'), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(tree, base):
    out = []
    counter = [0]
    def contents(n):
        if 'parts' in n:
            return [x for c in n['parts'] for x in contents(c)]
        return [n.get('text', '')]
    def assign(n, ancestors):
        if 'parts' not in n:
            return
        texts = contents(n)
        while True:
            counter[0] += 1
            cand = base + '_' + str(counter[0])
            if len(cand) > 70:
                out.append(None)
                return
            if any(cand in t for t in texts):
                continue
            if any(a.startswith(cand) for a in ancestors):
                continue
            break
        out.append(cand)
        for c in n['parts']:
            assign(c, ancestors + [cand])
    assign(tree, [])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b1_1 and b1_2'}]}]}, 'b1'), ['b1_3', 'b1_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q1_2 q1_3 q1_4 q1_5 q1_6 q1_7 q1_8 q1_9'}]}]}, 'q1'), ['q1_1', 'q1_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm1'), ['m1_1', 'm1_2', 'm1_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 2: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b2_1 and b2_2'}]}]}, 'b2'), ['b2_3', 'b2_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q2_2 q2_3 q2_4 q2_5 q2_6 q2_7 q2_8 q2_9'}]}]}, 'q2'), ['q2_1', 'q2_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm2'), ['m2_1', 'm2_2', 'm2_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 3: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b3_1 and b3_2'}]}]}, 'b3'), ['b3_3', 'b3_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8 q3_9'}]}]}, 'q3'), ['q3_1', 'q3_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm3'), ['m3_1', 'm3_2', 'm3_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 4: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b4_1 and b4_2'}]}]}, 'b4'), ['b4_3', 'b4_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8 q4_9'}]}]}, 'q4'), ['q4_1', 'q4_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm4'), ['m4_1', 'm4_2', 'm4_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 5: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b5_1 and b5_2'}]}]}, 'b5'), ['b5_3', 'b5_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q5_2 q5_3 q5_4 q5_5 q5_6 q5_7 q5_8 q5_9'}]}]}, 'q5'), ['q5_1', 'q5_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm5'), ['m5_1', 'm5_2', 'm5_3']), ('single leaf', ({'text': 'only'}, 'n'), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A nested boundary such as b_10 extends the outer boundary b_1, so the outer delimiter matches inside the inner one.

Multipart nodes have "parts", leaves have "text". Nodes are visited depth-first (pre-order) and a single counter produces candidates base_1, base_2, ... A candidate is rejected when it occurs in any text anywhere below the node, when it is a prefix of an ancestor boundary or an ancestor boundary is a prefix of it, and a candidate longer than 70 characters makes that node's boundary None (its subtree gets none). Result: boundaries in visiting order.

split: open-access


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

N = 1
observations = []
def solve(tree, base):
    out = []
    counter = [0]
    def contents(n):
        if 'parts' in n:
            return [x for c in n['parts'] for x in contents(c)]
        return [n.get('text', '')]
    def assign(n, ancestors):
        if 'parts' not in n:
            return
        texts = contents(n)
        while True:
            counter[0] += 1
            cand = base + '_' + str(counter[0])
            if len(cand) > 76:
                out.append(None)
                return
            if any(cand in t for t in texts):
                continue
            if any(a.startswith(cand) or cand.startswith(a) for a in ancestors):
                continue
            break
        out.append(cand)
        for c in n['parts']:
            assign(c, ancestors + [cand])
    assign(tree, [])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b1_1 and b1_2'}]}]}, 'b1'), ['b1_3', 'b1_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q1_2 q1_3 q1_4 q1_5 q1_6 q1_7 q1_8 q1_9'}]}]}, 'q1'), ['q1_1', 'q1_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm1'), ['m1_1', 'm1_2', 'm1_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 2: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b2_1 and b2_2'}]}]}, 'b2'), ['b2_3', 'b2_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q2_2 q2_3 q2_4 q2_5 q2_6 q2_7 q2_8 q2_9'}]}]}, 'q2'), ['q2_1', 'q2_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm2'), ['m2_1', 'm2_2', 'm2_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 3: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b3_1 and b3_2'}]}]}, 'b3'), ['b3_3', 'b3_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8 q3_9'}]}]}, 'q3'), ['q3_1', 'q3_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm3'), ['m3_1', 'm3_2', 'm3_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 4: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b4_1 and b4_2'}]}]}, 'b4'), ['b4_3', 'b4_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8 q4_9'}]}]}, 'q4'), ['q4_1', 'q4_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm4'), ['m4_1', 'm4_2', 'm4_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 5: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b5_1 and b5_2'}]}]}, 'b5'), ['b5_3', 'b5_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q5_2 q5_3 q5_4 q5_5 q5_6 q5_7 q5_8 q5_9'}]}]}, 'q5'), ['q5_1', 'q5_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm5'), ['m5_1', 'm5_2', 'm5_3']), ('single leaf', ({'text': 'only'}, 'n'), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(tree, base):
    out = []
    counter = [0]
    def contents(n):
        if 'parts' in n:
            return [x for c in n['parts'] for x in contents(c)]
        return [n.get('text', '')]
    def assign(n, ancestors):
        if 'parts' not in n:
            return
        texts = contents(n)
        while True:
            counter[0] += 1
            cand = base + '_' + str(counter[0])
            if len(cand) >= 70:
                out.append(None)
                return
            if any(cand in t for t in texts):
                continue
            if any(a.startswith(cand) or cand.startswith(a) for a in ancestors):
                continue
            break
        out.append(cand)
        for c in n['parts']:
            assign(c, ancestors + [cand])
    assign(tree, [])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b1_1 and b1_2'}]}]}, 'b1'), ['b1_3', 'b1_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q1_2 q1_3 q1_4 q1_5 q1_6 q1_7 q1_8 q1_9'}]}]}, 'q1'), ['q1_1', 'q1_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm1'), ['m1_1', 'm1_2', 'm1_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 2: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b2_1 and b2_2'}]}]}, 'b2'), ['b2_3', 'b2_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q2_2 q2_3 q2_4 q2_5 q2_6 q2_7 q2_8 q2_9'}]}]}, 'q2'), ['q2_1', 'q2_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm2'), ['m2_1', 'm2_2', 'm2_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 3: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b3_1 and b3_2'}]}]}, 'b3'), ['b3_3', 'b3_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8 q3_9'}]}]}, 'q3'), ['q3_1', 'q3_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm3'), ['m3_1', 'm3_2', 'm3_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 4: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b4_1 and b4_2'}]}]}, 'b4'), ['b4_3', 'b4_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8 q4_9'}]}]}, 'q4'), ['q4_1', 'q4_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm4'), ['m4_1', 'm4_2', 'm4_3']), ('single leaf', ({'text': 'only'}, 'n'), [])], 5: [('collision deep in a later child', ({'parts': [{'text': 'x'}, {'parts': [{'text': 'has b5_1 and b5_2'}]}]}, 'b5'), ['b5_3', 'b5_4']), ('counter passes ten', ({'parts': [{'parts': [{'text': 'q5_2 q5_3 q5_4 q5_5 q5_6 q5_7 q5_8 q5_9'}]}]}, 'q5'), ['q5_1', 'q5_20']), ('exactly seventy characters', ({'parts': [{'text': 'x'}]}, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5'), ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz5_1']), ('seventy-one characters', ({'parts': [{'text': 'x'}]}, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), [None]), ('plain nesting', ({'parts': [{'parts': [{'text': 'a'}]}, {'parts': [{'text': 'b'}]}]}, 'm5'), ['m5_1', 'm5_2', 'm5_3']), ('single leaf', ({'text': 'only'}, 'n'), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Boundaries longer than the 70-character limit are generated.

Multipart nodes have "parts", leaves have "text". Nodes are visited depth-first (pre-order) and a single counter produces candidates base_1, base_2, ... A candidate is rejected when it occurs in any text anywhere below the node, when it is a prefix of an ancestor boundary or an ancestor boundary is a prefix of it, and a candidate longer than 70 characters makes that node's boundary None (its subtree gets none). Result: boundaries in visiting order.

split: open-access


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

N = 1
observations = []
def solve(node):
    t = node['type'].lower()
    cte = (node.get('cte') or '7bit').lower()
    if t == 'text/plain' and cte != 'binary':
        return 'text+footer'
    if t == 'multipart/mixed':
        return 'mixed(' + ','.join(c['type'].lower() for c in node['parts']) + ',text/plain)'
    return 'mixed(' + t + ',text/plain)'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,text/plain)')], 2: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,text/plain)')], 3: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,text/plain)')], 4: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,text/plain)')], 5: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,image/png,text/plain)')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(node):
    t = node['type'].lower()
    cte = (node.get('cte') or '7bit').lower()
    if t == 'text/plain' and cte in ('7bit', '8bit'):
        return 'text+footer'
    if t == 'multipart/mixed':
        return 'mixed(' + ','.join(c['type'].lower() for c in node['parts']) + ',text/plain)'
    return 'mixed(' + t + ',text/plain)'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,text/plain)')], 2: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,text/plain)')], 3: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,text/plain)')], 4: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,text/plain)')], 5: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,image/png,text/plain)')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A footer is appended as plain text to a base64-encoded body, corrupting its last block.

A top-level text/plain body in 7bit, 8bit or quoted-printable (default 7bit, case-insensitive) gets the footer appended in place ("text+footer"). A multipart/mixed gets a text/plain footer part appended after its children. Everything else (alternative, signed, encrypted, html, base64 text) is wrapped: mixed(<type>,text/plain). Output is a compact structure string.

split: open-access


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

N = 1
observations = []
def solve(node):
    t = node['type'].lower()
    cte = (node.get('cte') or '7bit').lower()
    if t == 'text/plain' and cte in ('7bit', '8bit', 'quoted-printable'):
        return 'text+footer'
    if t.startswith('multipart/') and t != 'multipart/alternative':
        return 'mixed(' + ','.join(c['type'].lower() for c in node['parts']) + ',text/plain)'
    return 'mixed(' + t + ',text/plain)'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,text/plain)')], 2: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,text/plain)')], 3: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,text/plain)')], 4: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,text/plain)')], 5: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,image/png,text/plain)')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(node):
    t = node['type'].lower()
    cte = (node.get('cte') or '7bit').lower()
    if t == 'text/plain' and cte in ('7bit', '8bit', 'quoted-printable'):
        return 'text+footer'
    if t.startswith('multipart/') and t not in ('multipart/alternative', 'multipart/signed'):
        return 'mixed(' + ','.join(c['type'].lower() for c in node['parts']) + ',text/plain)'
    return 'mixed(' + t + ',text/plain)'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,text/plain)')], 2: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,text/plain)')], 3: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,text/plain)')], 4: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,text/plain)')], 5: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,image/png,text/plain)')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Signed or encrypted containers get an extra part inserted, invalidating their structure.

A top-level text/plain body in 7bit, 8bit or quoted-printable (default 7bit, case-insensitive) gets the footer appended in place ("text+footer"). A multipart/mixed gets a text/plain footer part appended after its children. Everything else (alternative, signed, encrypted, html, base64 text) is wrapped: mixed(<type>,text/plain). Output is a compact structure string.

split: open-access


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

N = 1
observations = []
def solve(node):
    t = node['type'].lower()
    cte = (node.get('cte') or '7bit').lower()
    if t.startswith('text/') and cte in ('7bit', '8bit', 'quoted-printable'):
        return 'text+footer'
    if t == 'multipart/mixed':
        return 'mixed(' + ','.join(c['type'].lower() for c in node['parts']) + ',text/plain)'
    return 'mixed(' + t + ',text/plain)'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,text/plain)')], 2: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,text/plain)')], 3: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,text/plain)')], 4: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,text/plain)')], 5: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,image/png,text/plain)')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(node):
    t = node['type'].lower()
    cte = (node.get('cte') or '7bit').lower()
    if t in ('text/plain', 'text/enriched') and cte in ('7bit', '8bit', 'quoted-printable'):
        return 'text+footer'
    if t == 'multipart/mixed':
        return 'mixed(' + ','.join(c['type'].lower() for c in node['parts']) + ',text/plain)'
    return 'mixed(' + t + ',text/plain)'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,text/plain)')], 2: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,text/plain)')], 3: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,text/plain)')], 4: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,text/plain)')], 5: [('base64 text body', ({'type': 'text/plain', 'cte': 'BASE64'},), 'mixed(text/plain,text/plain)'), ('quoted-printable text body', ({'type': 'text/plain', 'cte': 'quoted-printable'},), 'text+footer'), ('signed message', ({'type': 'multipart/signed', 'parts': [{'type': 'text/plain'}, {'type': 'application/pgp-signature'}]},), 'mixed(multipart/signed,text/plain)'), ('encrypted message', ({'type': 'multipart/encrypted', 'parts': [{'type': 'application/pgp-encrypted'}, {'type': 'application/octet-stream'}]},), 'mixed(multipart/encrypted,text/plain)'), ('html body', ({'type': 'text/html'},), 'mixed(text/html,text/plain)'), ('enriched body', ({'type': 'text/enriched', 'cte': '7bit'},), 'mixed(text/enriched,text/plain)'), ('mixed message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}, {'type': 'image/png'}]},), 'mixed(text/plain,image/png,image/png,image/png,image/png,image/png,text/plain)')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Plain-text footers are appended inside HTML bodies.

A top-level text/plain body in 7bit, 8bit or quoted-printable (default 7bit, case-insensitive) gets the footer appended in place ("text+footer"). A multipart/mixed gets a text/plain footer part appended after its children. Everything else (alternative, signed, encrypted, html, base64 text) is wrapped: mixed(<type>,text/plain). Output is a compact structure string.

split: open-access