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

N = 1
observations = []
def solve(s):
    return {
        'oldest': s['queue'][-s['capacity']:] if s['capacity'] else [],
        'newest': s['queue'][:s['capacity']],
        'append': list(s['queue'])+([s['incoming']] if s['incoming'] is not None else []),
        'next': s['queue'][0] if s['queue'] and s['deliver'] and not s['cancel'] else None,
        'after_delivery': s['queue'][1:] if s['deliver'] and s['queue'] else list(s['queue']),
        'cancelled_queue': [] if s['cancel'] else list(s['queue']),
        'overflow_error': len(s['queue'])>s['capacity'],
        'complete_now': [r[1] for r in s['notifications'][:next((i for i,r in enumerate(s['notifications']) if r[0] in ('complete','error')),len(s['notifications']))] if r[0]=='value'],
        'dropped': max(0,len(s['queue'])-s['capacity']),
        'errors': s['errors']+int(len(s['queue'])>s['capacity'] and s['policy']=='error'),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 2}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 2}), ({'queue': [], 'incoming': 'new', 'capacity': 3, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 2}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 3, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 2})], 2: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 4}), ({'queue': ['a'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 1, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': [], 'dropped': 2, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 6, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 4})], 3: [({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 6}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 9, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6})], 4: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 8}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 1}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 12, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 8})], 5: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 10}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 11}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 15, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 15, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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(s):
    return {
        'oldest': s['queue'][-s['capacity']:] if s['capacity'] else [],
        'newest': s['queue'][:s['capacity']],
        'append': list(s['queue'])+([s['incoming']] if s['incoming'] is not None else []),
        'next': s['queue'][0] if s['queue'] and s['deliver'] and not s['cancel'] else None,
        'after_delivery': s['queue'][1:] if s['deliver'] and s['queue'] else list(s['queue']),
        'cancelled_queue': [] if s['cancel'] else list(s['queue']),
        'overflow_error': len(s['queue'])>=s['capacity'] and s['policy']=='error',
        'complete_now': [r[1] for r in s['notifications'][:next((i for i,r in enumerate(s['notifications']) if r[0] in ('complete','error')),len(s['notifications']))] if r[0]=='value'],
        'dropped': max(0,len(s['queue'])-s['capacity']),
        'errors': s['errors']+int(len(s['queue'])>s['capacity'] and s['policy']=='error'),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 2}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 2}), ({'queue': [], 'incoming': 'new', 'capacity': 3, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 2}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 3, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 2})], 2: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 4}), ({'queue': ['a'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 1, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': [], 'dropped': 2, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 6, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 4})], 3: [({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 6}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 9, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6})], 4: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 8}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 1}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 12, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 8})], 5: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 10}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 11}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 15, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 15, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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:
Drop policies incorrectly emit observer overflow errors; the returned lifecycle plan violates the stated transition contract.

Plan a local subscription callback buffer. Input queue is arrival ordered. Drop-oldest keeps the newest capacity records; drop-newest keeps the oldest. Capacity zero retains nothing. Delivery removes at most one item, cancellation clears all items, completion waits for a nonempty buffer, and overflow errors are signaled only under error policy. Notification storage may contain stale records after termination. Deliver values only before the first complete or error marker. Inputs are finite state snapshots, including transitional and stale states; output fields are the exact independent actions/metadata defined by the corrected expression table. Numeric fixture capacities and counts vary with N.
Field definitions, each independently computed from the input snapshot: oldest = s['queue'][-s['capacity']:] if s['capacity'] else []; newest = s['queue'][:s['capacity']]; append = list(s['queue'])+([s['incoming']] if s['incoming'] is not None else []); next = s['queue'][0] if s['queue'] and s['deliver'] and not s['cancel'] else None; after_delivery = s['queue'][1:] if s['deliver'] and s['queue'] else list(s['queue']); cancelled_queue = [] if s['cancel'] else list(s['queue']); overflow_error = len(s['queue'])>s['capacity'] and s['policy']=='error'; complete_now = [r[1] for r in s['notifications'][:next((i for i,r in enumerate(s['notifications']) if r[0] in ('complete','error')),len(s['notifications']))] if r[0]=='value']; dropped = max(0,len(s['queue'])-s['capacity']); errors = s['errors']+int(len(s['queue'])>s['capacity'] and s['policy']=='error')

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'oldest': s['queue'][-s['capacity']:] if s['capacity'] else [],
        'newest': s['queue'][:s['capacity']],
        'append': list(s['queue'])+([s['incoming']] if s['incoming'] is not None else []),
        'next': s['queue'][0] if s['queue'] and s['deliver'] and not s['cancel'] else None,
        'after_delivery': s['queue'][1:] if s['deliver'] and s['queue'] else list(s['queue']),
        'cancelled_queue': [] if s['cancel'] else list(s['queue']),
        'overflow_error': len(s['queue'])>s['capacity'] and s['policy']=='error',
        'complete_now': [r[1] for r in s['notifications'] if r[0]=='value'],
        'dropped': max(0,len(s['queue'])-s['capacity']),
        'errors': s['errors']+int(len(s['queue'])>s['capacity'] and s['policy']=='error'),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 2}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 2}), ({'queue': [], 'incoming': 'new', 'capacity': 3, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 2}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 3, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 2})], 2: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 4}), ({'queue': ['a'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 1, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': [], 'dropped': 2, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 6, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 4})], 3: [({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 6}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 9, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6})], 4: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 8}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 1}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 12, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 8})], 5: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 10}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 11}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 15, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 15, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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(s):
    return {
        'oldest': s['queue'][-s['capacity']:] if s['capacity'] else [],
        'newest': s['queue'][:s['capacity']],
        'append': list(s['queue'])+([s['incoming']] if s['incoming'] is not None else []),
        'next': s['queue'][0] if s['queue'] and s['deliver'] and not s['cancel'] else None,
        'after_delivery': s['queue'][1:] if s['deliver'] and s['queue'] else list(s['queue']),
        'cancelled_queue': [] if s['cancel'] else list(s['queue']),
        'overflow_error': len(s['queue'])>s['capacity'] and s['policy']=='error',
        'complete_now': [r[1] for r in s['notifications'][:next((i for i,r in enumerate(s['notifications']) if r[0]=='complete'),len(s['notifications']))] if r[0]=='value'],
        'dropped': max(0,len(s['queue'])-s['capacity']),
        'errors': s['errors']+int(len(s['queue'])>s['capacity'] and s['policy']=='error'),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 2}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 2}), ({'queue': [], 'incoming': 'new', 'capacity': 3, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 2, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 2}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 3, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 2, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 2})], 2: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 4}), ({'queue': ['a'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 1, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 2, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 4, 'notifications': []}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': [], 'dropped': 2, 'errors': 5}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 6, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 4, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 4})], 3: [({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 6}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6}), ({'queue': ['a'], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a', 'new'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': [], 'dropped': 3, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 9, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 6, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 6})], 4: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 1, 'policy': 'newest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 8}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': [], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 1}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': True, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': None, 'after_delivery': ['a'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 0, 'policy': 'newest', 'cancel': False, 'deliver': True, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 12, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 8, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 8})], 5: [({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 0, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 3, 'errors': 10}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 1, 'policy': 'newest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['c'], 'newest': ['a'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['a', 'b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 2, 'errors': 0}), ({'queue': [], 'incoming': 'new', 'capacity': 1, 'policy': 'oldest', 'cancel': True, 'deliver': False, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['new'], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': ['a'], 'incoming': None, 'capacity': 1, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 0, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a'], 'newest': ['a'], 'append': ['a'], 'next': 'a', 'after_delivery': [], 'cancelled_queue': ['a'], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 0, 'policy': 'error', 'cancel': False, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': [], 'newest': [], 'append': ['a', 'b', 'c'], 'next': 'a', 'after_delivery': ['b', 'c'], 'cancelled_queue': ['a', 'b', 'c'], 'overflow_error': True, 'complete_now': ['a'], 'dropped': 3, 'errors': 11}), ({'queue': ['a', 'b', 'c'], 'incoming': None, 'capacity': 15, 'policy': 'oldest', 'cancel': True, 'deliver': True, 'complete': False, 'errors': 10, 'notifications': [['value', 'a'], ['complete', None], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10}), ({'queue': [], 'incoming': None, 'capacity': 0, 'policy': 'oldest', 'cancel': False, 'deliver': False, 'complete': False, 'errors': 0, 'notifications': []}, {'oldest': [], 'newest': [], 'append': [], 'next': None, 'after_delivery': [], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': [], 'dropped': 0, 'errors': 0}), ({'queue': ['a', 'b', 'c'], 'incoming': 'new', 'capacity': 15, 'policy': 'error', 'cancel': True, 'deliver': True, 'complete': True, 'errors': 10, 'notifications': [['value', 'a'], ['error', 'bad'], ['value', 'late']]}, {'oldest': ['a', 'b', 'c'], 'newest': ['a', 'b', 'c'], 'append': ['a', 'b', 'c', 'new'], 'next': None, 'after_delivery': ['b', 'c'], 'cancelled_queue': [], 'overflow_error': False, 'complete_now': ['a'], 'dropped': 0, 'errors': 10})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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:
Buffered observer values after a terminal marker are incorrectly delivered; the returned lifecycle plan violates the stated transition contract.

Plan a local subscription callback buffer. Input queue is arrival ordered. Drop-oldest keeps the newest capacity records; drop-newest keeps the oldest. Capacity zero retains nothing. Delivery removes at most one item, cancellation clears all items, completion waits for a nonempty buffer, and overflow errors are signaled only under error policy. Notification storage may contain stale records after termination. Deliver values only before the first complete or error marker. Inputs are finite state snapshots, including transitional and stale states; output fields are the exact independent actions/metadata defined by the corrected expression table. Numeric fixture capacities and counts vary with N.
Field definitions, each independently computed from the input snapshot: oldest = s['queue'][-s['capacity']:] if s['capacity'] else []; newest = s['queue'][:s['capacity']]; append = list(s['queue'])+([s['incoming']] if s['incoming'] is not None else []); next = s['queue'][0] if s['queue'] and s['deliver'] and not s['cancel'] else None; after_delivery = s['queue'][1:] if s['deliver'] and s['queue'] else list(s['queue']); cancelled_queue = [] if s['cancel'] else list(s['queue']); overflow_error = len(s['queue'])>s['capacity'] and s['policy']=='error'; complete_now = [r[1] for r in s['notifications'][:next((i for i,r in enumerate(s['notifications']) if r[0] in ('complete','error')),len(s['notifications']))] if r[0]=='value']; dropped = max(0,len(s['queue'])-s['capacity']); errors = s['errors']+int(len(s['queue'])>s['capacity'] and s['policy']=='error')

split: open-access