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

N = 1
observations = []
def solve(fragments):
    groups = {}
    for f in fragments:
        g = groups.setdefault(f['id'], {'totals': [], 'parts': {}})
        if f.get('total') is not None:
            g['totals'].append(f['total'])
        g['parts'].setdefault(f['number'], f['body'])
    out = []
    for pid in sorted(groups):
        g = groups[pid]
        if len(set(g['totals'])) > 1:
            out.append([pid, 'conflict', None])
            continue
        if not g['totals']:
            out.append([pid, 'incomplete', None])
            continue
        total = g['totals'][0]
        if all(n in g['parts'] for n in range(total)):
            out.append([pid, 'complete', ''.join(g['parts'].get(n, '') for n in range(1, total + 1))])
        else:
            out.append([pid, 'incomplete', None])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD1'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD1']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b1'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '11'}],), [['r', 'complete', '1123']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z1'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one1'}],), [['t', 'complete', 'one1two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z1'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w1', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w1', 'complete', 'solo']])], 2: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD2'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD2']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b2'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '12'}],), [['r', 'complete', '1223']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z2'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one2'}],), [['t', 'complete', 'one2two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z2'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w2', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w2', 'complete', 'solo']])], 3: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD3'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD3']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b3'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '13'}],), [['r', 'complete', '1323']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z3'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one3'}],), [['t', 'complete', 'one3two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z3'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w3', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w3', 'complete', 'solo']])], 4: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD4'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD4']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b4'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '14'}],), [['r', 'complete', '1423']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z4'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one4'}],), [['t', 'complete', 'one4two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z4'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w4', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w4', 'complete', 'solo']])], 5: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD5'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD5']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b5'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '15'}],), [['r', 'complete', '1523']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z5'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one5'}],), [['t', 'complete', 'one5two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z5'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w5', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w5', 'complete', 'solo']])]}
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(fragments):
    groups = {}
    for f in fragments:
        g = groups.setdefault(f['id'], {'totals': [], 'parts': {}})
        if f.get('total') is not None:
            g['totals'].append(f['total'])
        g['parts'].setdefault(f['number'], f['body'])
    out = []
    for pid in sorted(groups):
        g = groups[pid]
        if len(set(g['totals'])) > 1:
            out.append([pid, 'conflict', None])
            continue
        if not g['totals']:
            out.append([pid, 'incomplete', None])
            continue
        total = g['totals'][0]
        if len(g['parts']) >= total:
            out.append([pid, 'complete', ''.join(g['parts'].get(n, '') for n in range(1, total + 1))])
        else:
            out.append([pid, 'incomplete', None])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD1'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD1']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b1'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '11'}],), [['r', 'complete', '1123']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z1'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one1'}],), [['t', 'complete', 'one1two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z1'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w1', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w1', 'complete', 'solo']])], 2: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD2'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD2']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b2'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '12'}],), [['r', 'complete', '1223']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z2'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one2'}],), [['t', 'complete', 'one2two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z2'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w2', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w2', 'complete', 'solo']])], 3: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD3'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD3']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b3'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '13'}],), [['r', 'complete', '1323']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z3'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one3'}],), [['t', 'complete', 'one3two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z3'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w3', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w3', 'complete', 'solo']])], 4: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD4'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD4']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b4'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '14'}],), [['r', 'complete', '1423']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z4'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one4'}],), [['t', 'complete', 'one4two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z4'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w4', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w4', 'complete', 'solo']])], 5: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD5'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD5']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b5'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '15'}],), [['r', 'complete', '1523']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z5'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one5'}],), [['t', 'complete', 'one5two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z5'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w5', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w5', 'complete', 'solo']])]}
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:
Complete messages are never recognised because fragment 0 is required.

fragments {id, number, total (optional), body}. Per id: the first fragment with a given number wins; totals seen on fragments must all agree (otherwise "conflict"); without any total the message is "incomplete"; it is "complete" when every number 1..total is present, and its text joins those numbers in order (other numbers are ignored). Result rows [id, status, text or None] sorted by id.

split: open-access


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':
            walk(n['body'])
            return
        disp = (n.get('disp') or '').lower()
        if t == 'text/calendar' or (n.get('filename') or '').lower().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)

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):
    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':
            if (n.get('disp') or '').lower() != 'attachment':
                walk(n['body'])
            return
        disp = (n.get('disp') or '').lower()
        if t == 'text/calendar' or (n.get('filename') or '').lower().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 invitation inside a forwarded message is offered to the reader as if it were addressed to them.

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):
    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 '').lower().endswith('.ics'):
            if disp == 'attachment' and t != 'text/calendar':
                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 '').lower().endswith('.ics'):
            if disp == 'attachment' and not (n.get('params') or {}).get('method'):
                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 attached calendar file is treated as a live invitation.

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):
    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 '').lower().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'])
    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 '').lower().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'].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:
Methods written in lower case or padded are not recognised as the same method.

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):
    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 '').lower().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])
    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 '').lower().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(methods) == 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:
Conflicting REQUEST and CANCEL parts are resolved silently to one of them.

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